181b2cc3fSStephan Aßmus/*
28acd164fSDario Casalinuovo * Copyright 2015, Dario Casalinuovo
381b2cc3fSStephan Aßmus * Copyright 2004, 2006, J��r��me Duval.
481b2cc3fSStephan Aßmus * Copyright 2003-2004, Andrew Bachmann.
581b2cc3fSStephan Aßmus * Copyright 2002-2004, 2006 Marcus Overhagen.
681b2cc3fSStephan Aßmus * Copyright 2002, Eric Jaessler.
781b2cc3fSStephan Aßmus * All rights reserved. Distributed under the terms of the MIT license.
881b2cc3fSStephan Aßmus */
981b2cc3fSStephan Aßmus
1081b2cc3fSStephan Aßmus
1181b2cc3fSStephan Aßmus#include <MediaDefs.h>
128acd164fSDario Casalinuovo
138acd164fSDario Casalinuovo#include <Application.h>
148acd164fSDario Casalinuovo#include <Bitmap.h>
158acd164fSDario Casalinuovo#include <Catalog.h>
16218a8c03SAugustin Cavalier#include <IconUtils.h>
176d63bc5eSDario Casalinuovo#include <LaunchRoster.h>
188acd164fSDario Casalinuovo#include <Locale.h>
1981b2cc3fSStephan Aßmus#include <MediaNode.h>
2041f5b3fcSDario Casalinuovo#include <MediaRoster.h>
218acd164fSDario Casalinuovo#include <Node.h>
22218a8c03SAugustin Cavalier#include <Notification.h>
2381b2cc3fSStephan Aßmus#include <Roster.h>
2481b2cc3fSStephan Aßmus
258acd164fSDario Casalinuovo#include <inttypes.h>
268acd164fSDario Casalinuovo#include <stdio.h>
278acd164fSDario Casalinuovo#include <string.h>
2852a38012Sejakowatz
29218a8c03SAugustin Cavalier#include "AddOnManager.h"
3081b2cc3fSStephan Aßmus#include "DataExchange.h"
31b84955d4SBarrett#include "MediaDebug.h"
3281b2cc3fSStephan Aßmus#include "MediaMisc.h"
3376889670SDario Casalinuovo#include "MediaRosterEx.h"
3481b2cc3fSStephan Aßmus
3581b2cc3fSStephan Aßmus
360a00d23fSMarcus Overhagen#define META_DATA_MAX_SIZE			(16 << 20)
370a00d23fSMarcus Overhagen#define META_DATA_AREA_MIN_SIZE		32000
380a00d23fSMarcus Overhagen
398acd164fSDario Casalinuovo#undef B_TRANSLATION_CONTEXT
408acd164fSDario Casalinuovo#define B_TRANSLATION_CONTEXT "MediaDefs"
418acd164fSDario Casalinuovo
4252a38012Sejakowatz
4381b2cc3fSStephan Aßmus// #pragma mark - media_destination
4481b2cc3fSStephan Aßmus
4581b2cc3fSStephan Aßmus
4681b2cc3fSStephan Aßmusmedia_destination::media_destination(port_id port, int32 id)
4781b2cc3fSStephan Aßmus	:
4881b2cc3fSStephan Aßmus	port(port),
4952a38012Sejakowatz	id(id)
5052a38012Sejakowatz{
5152a38012Sejakowatz}
5252a38012Sejakowatz
5381b2cc3fSStephan Aßmus
5481b2cc3fSStephan Aßmusmedia_destination::media_destination(const media_destination& clone)
5581b2cc3fSStephan Aßmus	:
5681b2cc3fSStephan Aßmus	port(clone.port),
5752a38012Sejakowatz	id(clone.id)
5852a38012Sejakowatz{
5952a38012Sejakowatz}
6052a38012Sejakowatz
6181b2cc3fSStephan Aßmus
6281b2cc3fSStephan Aßmusmedia_destination&
6381b2cc3fSStephan Aßmusmedia_destination::operator=(const media_destination& clone)
6452a38012Sejakowatz{
6552a38012Sejakowatz	port = clone.port;
6652a38012Sejakowatz	id = clone.id;
6752a38012Sejakowatz	return *this;
6852a38012Sejakowatz}
6952a38012Sejakowatz
7081b2cc3fSStephan Aßmus
7152a38012Sejakowatzmedia_destination::media_destination()
7281b2cc3fSStephan Aßmus	:
7381b2cc3fSStephan Aßmus	port(-1),
7452a38012Sejakowatz	id(-1)
7552a38012Sejakowatz{
7652a38012Sejakowatz}
7752a38012Sejakowatz
7881b2cc3fSStephan Aßmus
7952a38012Sejakowatzmedia_destination::~media_destination()
8052a38012Sejakowatz{
8152a38012Sejakowatz}
8252a38012Sejakowatz
8352a38012Sejakowatz
8481b2cc3fSStephan Aßmusmedia_destination media_destination::null(-1, -1);
8581b2cc3fSStephan Aßmus
8681b2cc3fSStephan Aßmus
8781b2cc3fSStephan Aßmus// #pragma mark - media_source
8881b2cc3fSStephan Aßmus
8952a38012Sejakowatz
9052a38012Sejakowatzmedia_source::media_source(port_id port,
9152a38012Sejakowatz						   int32 id)
9281b2cc3fSStephan Aßmus	:
9381b2cc3fSStephan Aßmus	port(port),
9452a38012Sejakowatz	id(id)
9552a38012Sejakowatz{
9652a38012Sejakowatz}
9752a38012Sejakowatz
9881b2cc3fSStephan Aßmus
9981b2cc3fSStephan Aßmusmedia_source::media_source(const media_source& clone)
10081b2cc3fSStephan Aßmus	:
10181b2cc3fSStephan Aßmus	port(clone.port),
10252a38012Sejakowatz	id(clone.id)
10352a38012Sejakowatz{
10452a38012Sejakowatz}
10552a38012Sejakowatz
10681b2cc3fSStephan Aßmus
10781b2cc3fSStephan Aßmusmedia_source&
10881b2cc3fSStephan Aßmusmedia_source::operator=(const media_source& clone)
10952a38012Sejakowatz{
11052a38012Sejakowatz	port = clone.port;
11152a38012Sejakowatz	id = clone.id;
11252a38012Sejakowatz	return *this;
11352a38012Sejakowatz}
11452a38012Sejakowatz
11581b2cc3fSStephan Aßmus
11652a38012Sejakowatzmedia_source::media_source()
11781b2cc3fSStephan Aßmus	:
11881b2cc3fSStephan Aßmus	port(-1),
11952a38012Sejakowatz	id(-1)
12052a38012Sejakowatz{
12152a38012Sejakowatz}
12252a38012Sejakowatz
12381b2cc3fSStephan Aßmus
12452a38012Sejakowatzmedia_source::~media_source()
12552a38012Sejakowatz{
12652a38012Sejakowatz}
12752a38012Sejakowatz
12852a38012Sejakowatz
12981b2cc3fSStephan Aßmusmedia_source media_source::null(-1, -1);
13052a38012Sejakowatz
13181b2cc3fSStephan Aßmus
132332cc6bcSAxel Dörfler// #pragma mark -
13381b2cc3fSStephan Aßmus
13481b2cc3fSStephan Aßmus
13581b2cc3fSStephan Aßmusbool
13681b2cc3fSStephan Aßmusoperator==(const media_destination& a, const media_destination& b)
13752a38012Sejakowatz{
138891446f5SStephan Aßmus	return a.port == b.port && a.id == b.id;
13952a38012Sejakowatz}
14052a38012Sejakowatz
14181b2cc3fSStephan Aßmus
14281b2cc3fSStephan Aßmusbool
14381b2cc3fSStephan Aßmusoperator!=(const media_destination& a, const media_destination& b)
14452a38012Sejakowatz{
145891446f5SStephan Aßmus	return a.port != b.port || a.id != b.id;
14652a38012Sejakowatz}
14752a38012Sejakowatz
14881b2cc3fSStephan Aßmus
14981b2cc3fSStephan Aßmusbool
15081b2cc3fSStephan Aßmusoperator<(const media_destination& a, const media_destination& b)
15152a38012Sejakowatz{
15252a38012Sejakowatz	UNIMPLEMENTED();
15352a38012Sejakowatz	return false;
15452a38012Sejakowatz}
15552a38012Sejakowatz
15681b2cc3fSStephan Aßmus
15781b2cc3fSStephan Aßmusbool
15881b2cc3fSStephan Aßmusoperator==(const media_source& a, const media_source& b)
15952a38012Sejakowatz{
160891446f5SStephan Aßmus	return a.port == b.port && a.id == b.id;
16152a38012Sejakowatz}
16252a38012Sejakowatz
16381b2cc3fSStephan Aßmus
16481b2cc3fSStephan Aßmusbool
16581b2cc3fSStephan Aßmusoperator!=(const media_source& a, const media_source& b)
16652a38012Sejakowatz{
167891446f5SStephan Aßmus	return a.port != b.port || a.id != b.id;
16852a38012Sejakowatz}
16952a38012Sejakowatz
17081b2cc3fSStephan Aßmus
17181b2cc3fSStephan Aßmusbool
17281b2cc3fSStephan Aßmusoperator<(const media_source& a, const media_source& b)
17352a38012Sejakowatz{
17452a38012Sejakowatz	UNIMPLEMENTED();
17552a38012Sejakowatz	return false;
17652a38012Sejakowatz}
17752a38012Sejakowatz
17881b2cc3fSStephan Aßmus
17981b2cc3fSStephan Aßmusbool
18081b2cc3fSStephan Aßmusoperator==(const media_node& a, const media_node& b)
18152a38012Sejakowatz{
182891446f5SStephan Aßmus	return a.node == b.node && a.port == b.port && a.kind == b.kind;
18352a38012Sejakowatz}
18452a38012Sejakowatz
18581b2cc3fSStephan Aßmus
18681b2cc3fSStephan Aßmusbool
18781b2cc3fSStephan Aßmusoperator!=(const media_node& a, const media_node& b)
18852a38012Sejakowatz{
189891446f5SStephan Aßmus	return a.node != b.node || a.port != b.port || a.kind != b.kind;
19052a38012Sejakowatz}
19152a38012Sejakowatz
19281b2cc3fSStephan Aßmus
19381b2cc3fSStephan Aßmusbool
19481b2cc3fSStephan Aßmusoperator<(const media_node& a, const media_node& b)
19552a38012Sejakowatz{
19652a38012Sejakowatz	UNIMPLEMENTED();
19752a38012Sejakowatz	return false;
19852a38012Sejakowatz}
19952a38012Sejakowatz
20052a38012Sejakowatz
201332cc6bcSAxel Dörfler// #pragma mark -
20281b2cc3fSStephan Aßmus
20352a38012Sejakowatz
20452a38012Sejakowatzmedia_multi_audio_format media_raw_audio_format::wildcard;
20552a38012Sejakowatz
20652a38012Sejakowatzmedia_multi_audio_format media_multi_audio_format::wildcard;
20752a38012Sejakowatz
208b6de9d11Sbevelopermedia_encoded_audio_format media_encoded_audio_format::wildcard = {{0}};
20952a38012Sejakowatz
21052a38012Sejakowatzmedia_video_display_info media_video_display_info::wildcard = {(color_space)0};
21152a38012Sejakowatz
21252a38012Sejakowatzmedia_raw_video_format media_raw_video_format::wildcard = {0};
21352a38012Sejakowatz
214b6de9d11Sbevelopermedia_encoded_video_format media_encoded_video_format::wildcard = {{0}};
21552a38012Sejakowatz
21652a38012Sejakowatzmedia_multistream_format media_multistream_format::wildcard = {0};
21752a38012Sejakowatz
21889023839Sbeveloper
219891446f5SStephan Aßmus// #pragma mark - media_format::Matches() support
22081b2cc3fSStephan Aßmus
22189023839Sbeveloper
22289023839Sbeveloperstatic bool
22381b2cc3fSStephan Aßmusraw_audio_format_matches(const media_raw_audio_format& a,
22481b2cc3fSStephan Aßmus	const media_raw_audio_format& b)
22589023839Sbeveloper{
22689023839Sbeveloper	if (a.frame_rate != 0 && b.frame_rate != 0 && a.frame_rate != b.frame_rate)
22789023839Sbeveloper		return false;
22881b2cc3fSStephan Aßmus	if (a.channel_count != 0 && b.channel_count != 0
22981b2cc3fSStephan Aßmus		&& a.channel_count != b.channel_count) {
23089023839Sbeveloper		return false;
23181b2cc3fSStephan Aßmus	}
23289023839Sbeveloper	if (a.format != 0 && b.format != 0 && a.format != b.format)
23389023839Sbeveloper		return false;
23489023839Sbeveloper	if (a.byte_order != 0 && b.byte_order != 0 && a.byte_order != b.byte_order)
23589023839Sbeveloper		return false;
23681b2cc3fSStephan Aßmus	if (a.buffer_size != 0 && b.buffer_size != 0
23781b2cc3fSStephan Aßmus		&& a.buffer_size != b.buffer_size) {
23889023839Sbeveloper		return false;
23981b2cc3fSStephan Aßmus	}
24089023839Sbeveloper	if (a.frame_rate != 0 && b.frame_rate != 0 && a.frame_rate != b.frame_rate)
24189023839Sbeveloper		return false;
24289023839Sbeveloper	return true;
24389023839Sbeveloper}
24489023839Sbeveloper
24581b2cc3fSStephan Aßmus
24689023839Sbeveloperstatic bool
24781b2cc3fSStephan Aßmusmulti_audio_info_matches(const media_multi_audio_info& a,
24881b2cc3fSStephan Aßmus	const media_multi_audio_info& b)
24989023839Sbeveloper{
25081b2cc3fSStephan Aßmus	if (a.channel_mask != 0 && b.channel_mask != 0
25181b2cc3fSStephan Aßmus		&& a.channel_mask != b.channel_mask) {
25289023839Sbeveloper		return false;
25381b2cc3fSStephan Aßmus	}
25489023839Sbeveloper	if (a.valid_bits != 0 && b.valid_bits != 0 && a.valid_bits != b.valid_bits)
25589023839Sbeveloper		return false;
25681b2cc3fSStephan Aßmus	if (a.matrix_mask != 0 && b.matrix_mask != 0
25781b2cc3fSStephan Aßmus		&& a.matrix_mask != b.matrix_mask) {
25889023839Sbeveloper		return false;
25981b2cc3fSStephan Aßmus	}
26089023839Sbeveloper	return true;
26189023839Sbeveloper}
26289023839Sbeveloper
26381b2cc3fSStephan Aßmus
26489023839Sbeveloperstatic bool
26581b2cc3fSStephan Aßmusmulti_audio_format_matches(const media_multi_audio_format& a,
26681b2cc3fSStephan Aßmus	const media_multi_audio_format& b)
26789023839Sbeveloper{
26889023839Sbeveloper	return raw_audio_format_matches(a, b) && multi_audio_info_matches(a, b);
26989023839Sbeveloper}
27089023839Sbeveloper
27181b2cc3fSStephan Aßmus
27289023839Sbeveloperstatic bool
27381b2cc3fSStephan Aßmusraw_video_format_matches(const media_raw_video_format& a,
27481b2cc3fSStephan Aßmus	const media_raw_video_format& b)
27589023839Sbeveloper{
27681b2cc3fSStephan Aßmus	if (a.field_rate != 0 && b.field_rate != 0
27781b2cc3fSStephan Aßmus		&& a.field_rate != b.field_rate) {
27889023839Sbeveloper		return false;
27981b2cc3fSStephan Aßmus	}
28081b2cc3fSStephan Aßmus	if (a.interlace != 0 && b.interlace != 0
28181b2cc3fSStephan Aßmus		&& a.interlace != b.interlace) {
28289023839Sbeveloper		return false;
28381b2cc3fSStephan Aßmus	}
28481b2cc3fSStephan Aßmus	if (a.first_active != 0 && b.first_active != 0
28581b2cc3fSStephan Aßmus		&& a.first_active != b.first_active) {
28689023839Sbeveloper		return false;
28781b2cc3fSStephan Aßmus	}
28881b2cc3fSStephan Aßmus	if (a.last_active != 0 && b.last_active != 0
28981b2cc3fSStephan Aßmus		&& a.last_active != b.last_active) {
29089023839Sbeveloper		return false;
29181b2cc3fSStephan Aßmus	}
29281b2cc3fSStephan Aßmus	if (a.orientation != 0 && b.orientation != 0
29381b2cc3fSStephan Aßmus		&& a.orientation != b.orientation) {
29489023839Sbeveloper		return false;
29581b2cc3fSStephan Aßmus	}
29681b2cc3fSStephan Aßmus	if (a.pixel_width_aspect != 0 && b.pixel_width_aspect != 0
29781b2cc3fSStephan Aßmus		&& a.pixel_width_aspect != b.pixel_width_aspect) {
29889023839Sbeveloper		return false;
29981b2cc3fSStephan Aßmus	}
30081b2cc3fSStephan Aßmus	if (a.pixel_height_aspect != 0 && b.pixel_height_aspect != 0
30181b2cc3fSStephan Aßmus		&& a.pixel_height_aspect != b.pixel_height_aspect) {
30289023839Sbeveloper		return false;
30381b2cc3fSStephan Aßmus	}
30481b2cc3fSStephan Aßmus	if (a.display.format != 0 && b.display.format != 0
30581b2cc3fSStephan Aßmus		&& a.display.format != b.display.format) {
30689023839Sbeveloper		return false;
30781b2cc3fSStephan Aßmus	}
30881b2cc3fSStephan Aßmus	if (a.display.line_width != 0 && b.display.line_width != 0
30981b2cc3fSStephan Aßmus		&& a.display.line_width != b.display.line_width) {
31089023839Sbeveloper		return false;
31181b2cc3fSStephan Aßmus	}
31281b2cc3fSStephan Aßmus	if (a.display.line_count != 0 && b.display.line_count != 0
31381b2cc3fSStephan Aßmus		&& a.display.line_count != b.display.line_count) {
31489023839Sbeveloper		return false;
31581b2cc3fSStephan Aßmus	}
31681b2cc3fSStephan Aßmus	if (a.display.bytes_per_row != 0 && b.display.bytes_per_row != 0
31781b2cc3fSStephan Aßmus		&& a.display.bytes_per_row != b.display.bytes_per_row) {
31889023839Sbeveloper		return false;
31981b2cc3fSStephan Aßmus	}
32081b2cc3fSStephan Aßmus	if (a.display.pixel_offset != 0 && b.display.pixel_offset != 0
32181b2cc3fSStephan Aßmus		&& a.display.pixel_offset != b.display.pixel_offset) {
32289023839Sbeveloper		return false;
32381b2cc3fSStephan Aßmus	}
32481b2cc3fSStephan Aßmus	if (a.display.line_offset != 0 && b.display.line_offset != 0
32581b2cc3fSStephan Aßmus		&& a.display.line_offset != b.display.line_offset) {
32689023839Sbeveloper		return false;
32781b2cc3fSStephan Aßmus	}
32881b2cc3fSStephan Aßmus	if (a.display.flags != 0 && b.display.flags != 0
32981b2cc3fSStephan Aßmus		&& a.display.flags != b.display.flags) {
33089023839Sbeveloper		return false;
33181b2cc3fSStephan Aßmus	}
33281b2cc3fSStephan Aßmus
33389023839Sbeveloper	return true;
33489023839Sbeveloper}
33589023839Sbeveloper
33681b2cc3fSStephan Aßmus
33789023839Sbeveloperstatic bool
33881b2cc3fSStephan Aßmusmultistream_format_matches(const media_multistream_format& a,
33981b2cc3fSStephan Aßmus	const media_multistream_format& b)
34089023839Sbeveloper{
34181b2cc3fSStephan Aßmus	if (a.avg_bit_rate != 0 && b.avg_bit_rate != 0
34281b2cc3fSStephan Aßmus		&& a.avg_bit_rate != b.avg_bit_rate) {
34389023839Sbeveloper		return false;
34481b2cc3fSStephan Aßmus	}
34581b2cc3fSStephan Aßmus	if (a.max_bit_rate != 0 && b.max_bit_rate != 0
34681b2cc3fSStephan Aßmus		&& a.max_bit_rate != b.max_bit_rate) {
34789023839Sbeveloper		return false;
34881b2cc3fSStephan Aßmus	}
34981b2cc3fSStephan Aßmus	if (a.avg_chunk_size != 0 && b.avg_chunk_size != 0
35081b2cc3fSStephan Aßmus		&& a.avg_chunk_size != b.avg_chunk_size) {
35189023839Sbeveloper		return false;
35281b2cc3fSStephan Aßmus	}
35381b2cc3fSStephan Aßmus	if (a.max_chunk_size != 0 && b.max_chunk_size != 0
35481b2cc3fSStephan Aßmus		&& a.max_chunk_size != b.max_chunk_size) {
35589023839Sbeveloper		return false;
35681b2cc3fSStephan Aßmus	}
35789023839Sbeveloper	if (a.flags != 0 && b.flags != 0 && a.flags != b.flags)
35889023839Sbeveloper		return false;
35989023839Sbeveloper	if (a.format != 0 && b.format != 0 && a.format != b.format)
36089023839Sbeveloper		return false;
36189023839Sbeveloper
36281b2cc3fSStephan Aßmus	if (a.format == 0 && b.format == 0) {
36381b2cc3fSStephan Aßmus		// TODO: How do we compare two formats with no type?
36481b2cc3fSStephan Aßmus		return true;
36581b2cc3fSStephan Aßmus	}
36689023839Sbeveloper
36789023839Sbeveloper	switch ((a.format != 0) ? a.format : b.format) {
36889023839Sbeveloper		default:
36981b2cc3fSStephan Aßmus			return true; // TODO: really?
370332cc6bcSAxel Dörfler
37189023839Sbeveloper		case media_multistream_format::B_VID:
37281b2cc3fSStephan Aßmus			if (a.u.vid.frame_rate != 0 && b.u.vid.frame_rate != 0
37381b2cc3fSStephan Aßmus				&& a.u.vid.frame_rate != b.u.vid.frame_rate) {
37489023839Sbeveloper				return false;
37581b2cc3fSStephan Aßmus			}
37681b2cc3fSStephan Aßmus			if (a.u.vid.width != 0 && b.u.vid.width != 0
37781b2cc3fSStephan Aßmus				&& a.u.vid.width != b.u.vid.width) {
37889023839Sbeveloper				return false;
37981b2cc3fSStephan Aßmus			}
38081b2cc3fSStephan Aßmus			if (a.u.vid.height != 0 && b.u.vid.height != 0
38181b2cc3fSStephan Aßmus				&& a.u.vid.height != b.u.vid.height) {
38289023839Sbeveloper				return false;
38381b2cc3fSStephan Aßmus			}
38481b2cc3fSStephan Aßmus			if (a.u.vid.space != 0 && b.u.vid.space != 0
38581b2cc3fSStephan Aßmus				&& a.u.vid.space != b.u.vid.space) {
38689023839Sbeveloper				return false;
38781b2cc3fSStephan Aßmus			}
38881b2cc3fSStephan Aßmus			if (a.u.vid.sampling_rate != 0 && b.u.vid.sampling_rate != 0
38981b2cc3fSStephan Aßmus				&& a.u.vid.sampling_rate != b.u.vid.sampling_rate) {
39089023839Sbeveloper				return false;
39181b2cc3fSStephan Aßmus			}
39281b2cc3fSStephan Aßmus			if (a.u.vid.sample_format != 0 && b.u.vid.sample_format != 0
39381b2cc3fSStephan Aßmus				&& a.u.vid.sample_format != b.u.vid.sample_format) {
39489023839Sbeveloper				return false;
39581b2cc3fSStephan Aßmus			}
39681b2cc3fSStephan Aßmus			if (a.u.vid.byte_order != 0 && b.u.vid.byte_order != 0
39781b2cc3fSStephan Aßmus				&& a.u.vid.byte_order != b.u.vid.byte_order) {
39889023839Sbeveloper				return false;
39981b2cc3fSStephan Aßmus			}
40081b2cc3fSStephan Aßmus			if (a.u.vid.channel_count != 0 && b.u.vid.channel_count != 0
40181b2cc3fSStephan Aßmus				&& a.u.vid.channel_count != b.u.vid.channel_count) {
40289023839Sbeveloper				return false;
40381b2cc3fSStephan Aßmus			}
40489023839Sbeveloper			return true;
405332cc6bcSAxel Dörfler
40689023839Sbeveloper		case media_multistream_format::B_AVI:
40781b2cc3fSStephan Aßmus			if (a.u.avi.us_per_frame != 0 && b.u.avi.us_per_frame != 0
40881b2cc3fSStephan Aßmus				&& a.u.avi.us_per_frame != b.u.avi.us_per_frame) {
40989023839Sbeveloper				return false;
41081b2cc3fSStephan Aßmus			}
41181b2cc3fSStephan Aßmus			if (a.u.avi.width != 0 && b.u.avi.width != 0
41281b2cc3fSStephan Aßmus				&& a.u.avi.width != b.u.avi.width) {
41389023839Sbeveloper				return false;
41481b2cc3fSStephan Aßmus			}
41581b2cc3fSStephan Aßmus			if (a.u.avi.height != 0 && b.u.avi.height != 0
41681b2cc3fSStephan Aßmus				&& a.u.avi.height != b.u.avi.height) {
41789023839Sbeveloper				return false;
41881b2cc3fSStephan Aßmus			}
41981b2cc3fSStephan Aßmus			if (a.u.avi.type_count != 0 && b.u.avi.type_count != 0
42081b2cc3fSStephan Aßmus				&& a.u.avi.type_count != b.u.avi.type_count) {
42189023839Sbeveloper				return false;
42281b2cc3fSStephan Aßmus			}
42381b2cc3fSStephan Aßmus			if (a.u.avi.types[0] != 0 && b.u.avi.types[0] != 0
42481b2cc3fSStephan Aßmus				&& a.u.avi.types[0] != b.u.avi.types[0]) {
42589023839Sbeveloper				return false;
42681b2cc3fSStephan Aßmus			}
42781b2cc3fSStephan Aßmus			if (a.u.avi.types[1] != 0 && b.u.avi.types[1] != 0
42881b2cc3fSStephan Aßmus				&& a.u.avi.types[1] != b.u.avi.types[1]) {
42989023839Sbeveloper				return false;
43081b2cc3fSStephan Aßmus			}
43181b2cc3fSStephan Aßmus			if (a.u.avi.types[2] != 0 && b.u.avi.types[2] != 0
43281b2cc3fSStephan Aßmus				&& a.u.avi.types[2] != b.u.avi.types[2]) {
43389023839Sbeveloper				return false;
43481b2cc3fSStephan Aßmus			}
43581b2cc3fSStephan Aßmus			if (a.u.avi.types[3] != 0 && b.u.avi.types[3] != 0
43681b2cc3fSStephan Aßmus				&& a.u.avi.types[3] != b.u.avi.types[3]) {
43789023839Sbeveloper				return false;
43881b2cc3fSStephan Aßmus			}
43981b2cc3fSStephan Aßmus			if (a.u.avi.types[4] != 0 && b.u.avi.types[4] != 0
44081b2cc3fSStephan Aßmus				&& a.u.avi.types[4] != b.u.avi.types[4]) {
44189023839Sbeveloper				return false;
44281b2cc3fSStephan Aßmus			}
44389023839Sbeveloper			return true;
44489023839Sbeveloper	}
44589023839Sbeveloper}
44689023839Sbeveloper
44781b2cc3fSStephan Aßmus
44889023839Sbeveloperstatic bool
44981b2cc3fSStephan Aßmusencoded_audio_format_matches(const media_encoded_audio_format& a,
45081b2cc3fSStephan Aßmus	const media_encoded_audio_format& b)
45189023839Sbeveloper{
45289023839Sbeveloper	if (!raw_audio_format_matches(a.output, b.output))
45389023839Sbeveloper		return false;
45489023839Sbeveloper	if (a.encoding != 0 && b.encoding != 0 && a.encoding != b.encoding)
45589023839Sbeveloper		return false;
45689023839Sbeveloper	if (a.bit_rate != 0 && b.bit_rate != 0 && a.bit_rate != b.bit_rate)
45789023839Sbeveloper		return false;
45889023839Sbeveloper	if (a.frame_size != 0 && b.frame_size != 0 && a.frame_size != b.frame_size)
45989023839Sbeveloper		return false;
46089023839Sbeveloper	if (!multi_audio_info_matches(a.multi_info, b.multi_info))
46189023839Sbeveloper		return false;
462332cc6bcSAxel Dörfler
46389023839Sbeveloper	if (a.encoding == 0 && b.encoding == 0)
46489023839Sbeveloper		return true; // can't compare
465332cc6bcSAxel Dörfler
46689023839Sbeveloper	switch((a.encoding != 0) ? a.encoding : b.encoding) {
46789023839Sbeveloper		case media_encoded_audio_format::B_ANY:
46889023839Sbeveloper		default:
46989023839Sbeveloper			return true;
47089023839Sbeveloper	}
47189023839Sbeveloper}
47289023839Sbeveloper
47381b2cc3fSStephan Aßmus
47489023839Sbeveloperstatic bool
47581b2cc3fSStephan Aßmusencoded_video_format_matches(const media_encoded_video_format& a,
47681b2cc3fSStephan Aßmus	const media_encoded_video_format& b)
47789023839Sbeveloper{
47889023839Sbeveloper	if (!raw_video_format_matches(a.output, b.output))
47989023839Sbeveloper		return false;
48089023839Sbeveloper	if (a.encoding != 0 && b.encoding != 0 && a.encoding != b.encoding)
48189023839Sbeveloper		return false;
48289023839Sbeveloper
48381b2cc3fSStephan Aßmus	if (a.avg_bit_rate != 0 && b.avg_bit_rate != 0
48481b2cc3fSStephan Aßmus		&& a.avg_bit_rate != b.avg_bit_rate) {
48589023839Sbeveloper		return false;
48681b2cc3fSStephan Aßmus	}
48781b2cc3fSStephan Aßmus	if (a.max_bit_rate != 0 && b.max_bit_rate != 0
48881b2cc3fSStephan Aßmus		&& a.max_bit_rate != b.max_bit_rate) {
48989023839Sbeveloper		return false;
49081b2cc3fSStephan Aßmus	}
49181b2cc3fSStephan Aßmus	if (a.frame_size != 0 && b.frame_size != 0
49281b2cc3fSStephan Aßmus		&& a.frame_size != b.frame_size) {
49389023839Sbeveloper		return false;
49481b2cc3fSStephan Aßmus	}
49581b2cc3fSStephan Aßmus	if (a.forward_history != 0 && b.forward_history != 0
49681b2cc3fSStephan Aßmus		&& a.forward_history != b.forward_history) {
49789023839Sbeveloper		return false;
49881b2cc3fSStephan Aßmus	}
49981b2cc3fSStephan Aßmus	if (a.backward_history != 0 && b.backward_history != 0
50081b2cc3fSStephan Aßmus		&& a.backward_history != b.backward_history) {
50189023839Sbeveloper		return false;
50281b2cc3fSStephan Aßmus	}
50389023839Sbeveloper
50489023839Sbeveloper	if (a.encoding == 0 && b.encoding == 0)
50589023839Sbeveloper		return true; // can't compare
506332cc6bcSAxel Dörfler
50789023839Sbeveloper	switch((a.encoding != 0) ? a.encoding : b.encoding) {
50889023839Sbeveloper		case media_encoded_video_format::B_ANY:
50989023839Sbeveloper		default:
51089023839Sbeveloper			return true;
51189023839Sbeveloper	}
51289023839Sbeveloper}
51389023839Sbeveloper
51489023839Sbeveloper
515891446f5SStephan Aßmus// #pragma mark - media_format::SpecializeTo() support
51689023839Sbeveloper
51789023839Sbeveloper
51889023839Sbeveloperstatic void
51981b2cc3fSStephan Aßmusraw_audio_format_specialize(media_raw_audio_format* format,
52081b2cc3fSStephan Aßmus	const media_raw_audio_format* other)
52189023839Sbeveloper{
52289023839Sbeveloper	if (format->frame_rate == 0)
52389023839Sbeveloper		format->frame_rate = other->frame_rate;
52489023839Sbeveloper	if (format->channel_count == 0)
52589023839Sbeveloper		format->channel_count = other->channel_count;
52689023839Sbeveloper	if (format->format == 0)
52789023839Sbeveloper		format->format = other->format;
52889023839Sbeveloper	if (format->byte_order == 0)
52989023839Sbeveloper		format->byte_order = other->byte_order;
53089023839Sbeveloper	if (format->buffer_size == 0)
53189023839Sbeveloper		format->buffer_size = other->buffer_size;
53289023839Sbeveloper	if (format->frame_rate == 0)
53389023839Sbeveloper		format->frame_rate = other->frame_rate;
53489023839Sbeveloper}
53589023839Sbeveloper
53681b2cc3fSStephan Aßmus
53789023839Sbeveloperstatic void
53881b2cc3fSStephan Aßmusmulti_audio_info_specialize(media_multi_audio_info* format,
53981b2cc3fSStephan Aßmus	const media_multi_audio_info* other)
54089023839Sbeveloper{
54189023839Sbeveloper	if (format->channel_mask == 0)
54289023839Sbeveloper		format->channel_mask = other->channel_mask;
54389023839Sbeveloper	if (format->valid_bits == 0)
54489023839Sbeveloper		format->valid_bits = other->valid_bits;
54589023839Sbeveloper	if (format->matrix_mask == 0)
54689023839Sbeveloper		format->matrix_mask = other->matrix_mask;
54789023839Sbeveloper}
54889023839Sbeveloper
54981b2cc3fSStephan Aßmus
55089023839Sbeveloperstatic void
55181b2cc3fSStephan Aßmusmulti_audio_format_specialize(media_multi_audio_format* format,
55281b2cc3fSStephan Aßmus	const media_multi_audio_format* other)
55389023839Sbeveloper{
55489023839Sbeveloper	raw_audio_format_specialize(format, other);
55589023839Sbeveloper	multi_audio_info_specialize(format, other);
55689023839Sbeveloper}
55789023839Sbeveloper
558891446f5SStephan Aßmus
55989023839Sbeveloperstatic void
56081b2cc3fSStephan Aßmusraw_video_format_specialize(media_raw_video_format* format,
56181b2cc3fSStephan Aßmus	const media_raw_video_format* other)
56289023839Sbeveloper{
56389023839Sbeveloper	if (format->field_rate == 0)
56489023839Sbeveloper		format->field_rate = other->field_rate;
56589023839Sbeveloper	if (format->interlace == 0)
56689023839Sbeveloper		format->interlace = other->interlace;
56789023839Sbeveloper	if (format->first_active == 0)
56889023839Sbeveloper		format->first_active = other->first_active;
56989023839Sbeveloper	if (format->last_active == 0)
57089023839Sbeveloper		format->last_active = other->last_active;
57189023839Sbeveloper	if (format->orientation == 0)
57289023839Sbeveloper		format->orientation = other->orientation;
57389023839Sbeveloper	if (format->pixel_width_aspect == 0)
57489023839Sbeveloper		format->pixel_width_aspect = other->pixel_width_aspect;
57589023839Sbeveloper	if (format->pixel_height_aspect == 0)
57689023839Sbeveloper		format->pixel_height_aspect = other->pixel_height_aspect;
57789023839Sbeveloper	if (format->display.format == 0)
57889023839Sbeveloper		format->display.format = other->display.format;
57989023839Sbeveloper	if (format->display.line_width == 0)
58089023839Sbeveloper		format->display.line_width = other->display.line_width;
58189023839Sbeveloper	if (format->display.line_count == 0)
58289023839Sbeveloper		format->display.line_count = other->display.line_count;
58389023839Sbeveloper	if (format->display.bytes_per_row == 0)
58489023839Sbeveloper		format->display.bytes_per_row = other->display.bytes_per_row;
58589023839Sbeveloper	if (format->display.pixel_offset == 0)
58689023839Sbeveloper		format->display.pixel_offset = other->display.pixel_offset;
58789023839Sbeveloper	if (format->display.line_offset == 0)
58889023839Sbeveloper		format->display.line_offset = other->display.line_offset;
58989023839Sbeveloper	if (format->display.flags == 0)
59089023839Sbeveloper		format->display.flags = other->display.flags;
59189023839Sbeveloper}
59289023839Sbeveloper
59381b2cc3fSStephan Aßmus
59489023839Sbeveloperstatic void
59581b2cc3fSStephan Aßmusmultistream_format_specialize(media_multistream_format* format,
59681b2cc3fSStephan Aßmus	const media_multistream_format* other)
59789023839Sbeveloper{
59889023839Sbeveloper	if (format->avg_bit_rate == 0)
59989023839Sbeveloper		format->avg_bit_rate = other->avg_bit_rate;
60089023839Sbeveloper	if (format->max_bit_rate == 0)
60189023839Sbeveloper		format->max_bit_rate = other->max_bit_rate;
60289023839Sbeveloper	if (format->avg_chunk_size == 0)
60389023839Sbeveloper		format->avg_chunk_size = other->avg_chunk_size;
60489023839Sbeveloper	if (format->max_chunk_size == 0)
60589023839Sbeveloper		format->max_chunk_size = other->max_chunk_size;
60689023839Sbeveloper	if (format->flags == 0)
60789023839Sbeveloper		format->flags = other->flags;
60889023839Sbeveloper	if (format->format == 0)
60989023839Sbeveloper		format->format = other->format;
610332cc6bcSAxel Dörfler
61189023839Sbeveloper	switch (format->format) {
61289023839Sbeveloper		case media_multistream_format::B_VID:
61389023839Sbeveloper			if (format->u.vid.frame_rate == 0)
61489023839Sbeveloper				format->u.vid.frame_rate = other->u.vid.frame_rate;
61589023839Sbeveloper			if (format->u.vid.width == 0)
61689023839Sbeveloper				format->u.vid.width = other->u.vid.width;
61789023839Sbeveloper			if (format->u.vid.height == 0)
61889023839Sbeveloper				format->u.vid.height = other->u.vid.height;
61989023839Sbeveloper			if (format->u.vid.space == 0)
62089023839Sbeveloper				format->u.vid.space = other->u.vid.space;
62189023839Sbeveloper			if (format->u.vid.sampling_rate == 0)
62289023839Sbeveloper				format->u.vid.sampling_rate = other->u.vid.sampling_rate;
62389023839Sbeveloper			if (format->u.vid.sample_format == 0)
62489023839Sbeveloper				format->u.vid.sample_format = other->u.vid.sample_format;
62589023839Sbeveloper			if (format->u.vid.byte_order == 0)
62689023839Sbeveloper				format->u.vid.byte_order = other->u.vid.byte_order;
62789023839Sbeveloper			if (format->u.vid.channel_count == 0)
62889023839Sbeveloper				format->u.vid.channel_count = other->u.vid.channel_count;
62989023839Sbeveloper			break;
63089023839Sbeveloper
63189023839Sbeveloper		case media_multistream_format::B_AVI:
63289023839Sbeveloper			if (format->u.avi.us_per_frame == 0)
63389023839Sbeveloper				format->u.avi.us_per_frame = other->u.avi.us_per_frame;
63489023839Sbeveloper			if (format->u.avi.width == 0)
63589023839Sbeveloper				format->u.avi.width = other->u.avi.width;
63689023839Sbeveloper			if (format->u.avi.height == 0)
63789023839Sbeveloper				format->u.avi.height = other->u.avi.height;
63889023839Sbeveloper			if (format->u.avi.type_count == 0)
63989023839Sbeveloper				format->u.avi.type_count = other->u.avi.type_count;
64089023839Sbeveloper			if (format->u.avi.types[0] == 0)
64189023839Sbeveloper				format->u.avi.types[0] = other->u.avi.types[0];
64289023839Sbeveloper			if (format->u.avi.types[1] == 0)
64389023839Sbeveloper				format->u.avi.types[1] = other->u.avi.types[1];
64489023839Sbeveloper			if (format->u.avi.types[2] == 0)
64589023839Sbeveloper				format->u.avi.types[2] = other->u.avi.types[2];
64689023839Sbeveloper			if (format->u.avi.types[3] == 0)
64789023839Sbeveloper				format->u.avi.types[3] = other->u.avi.types[3];
64889023839Sbeveloper			if (format->u.avi.types[4] == 0)
64989023839Sbeveloper				format->u.avi.types[4] = other->u.avi.types[4];
65089023839Sbeveloper			break;
65189023839Sbeveloper
65289023839Sbeveloper		default:
6534a46d818SStephan Aßmus			ERROR("media_format::SpecializeTo can't specialize "
654332cc6bcSAxel Dörfler				"media_multistream_format of format %" B_PRId32 "\n",
655332cc6bcSAxel Dörfler				format->format);
65689023839Sbeveloper	}
65789023839Sbeveloper}
65889023839Sbeveloper
65981b2cc3fSStephan Aßmus
66089023839Sbeveloperstatic void
66181b2cc3fSStephan Aßmusencoded_audio_format_specialize(media_encoded_audio_format* format,
66281b2cc3fSStephan Aßmus	const media_encoded_audio_format* other)
66389023839Sbeveloper{
66489023839Sbeveloper	raw_audio_format_specialize(&format->output, &other->output);
66589023839Sbeveloper	if (format->encoding == 0)
66689023839Sbeveloper		format->encoding = other->encoding;
66789023839Sbeveloper	if (format->bit_rate == 0)
66889023839Sbeveloper		format->bit_rate = other->bit_rate;
66989023839Sbeveloper	if (format->frame_size == 0)
67089023839Sbeveloper		format->frame_size = other->frame_size;
67189023839Sbeveloper	multi_audio_info_specialize(&format->multi_info, &other->multi_info);
67289023839Sbeveloper}
67389023839Sbeveloper
67481b2cc3fSStephan Aßmus
67589023839Sbeveloperstatic void
67681b2cc3fSStephan Aßmusencoded_video_format_specialize(media_encoded_video_format* format,
67781b2cc3fSStephan Aßmus	const media_encoded_video_format* other)
67889023839Sbeveloper{
67989023839Sbeveloper	raw_video_format_specialize(&format->output, &other->output);
68089023839Sbeveloper	if (format->avg_bit_rate == 0)
68189023839Sbeveloper		format->avg_bit_rate = other->avg_bit_rate;
68289023839Sbeveloper	if (format->max_bit_rate == 0)
68389023839Sbeveloper		format->max_bit_rate = other->max_bit_rate;
68489023839Sbeveloper	if (format->encoding == 0)
68589023839Sbeveloper		format->encoding = other->encoding;
68689023839Sbeveloper	if (format->frame_size == 0)
68789023839Sbeveloper		format->frame_size = other->frame_size;
68889023839Sbeveloper	if (format->forward_history == 0)
68989023839Sbeveloper		format->forward_history = other->forward_history;
69089023839Sbeveloper	if (format->backward_history == 0)
69189023839Sbeveloper		format->backward_history = other->backward_history;
69289023839Sbeveloper}
69389023839Sbeveloper
69489023839Sbeveloper
69581b2cc3fSStephan Aßmus// #pragma mark - media_format
69681b2cc3fSStephan Aßmus
69752a38012Sejakowatz
69852a38012Sejakowatzbool
69981b2cc3fSStephan Aßmusmedia_format::Matches(const media_format* other) const
70052a38012Sejakowatz{
70189023839Sbeveloper	CALLED();
70281b2cc3fSStephan Aßmus
70381b2cc3fSStephan Aßmus	if (type == 0 && other->type == 0) {
70481b2cc3fSStephan Aßmus		// TODO: How do we compare two formats with no type?
70581b2cc3fSStephan Aßmus		return true;
70681b2cc3fSStephan Aßmus	}
707332cc6bcSAxel Dörfler
70889023839Sbeveloper	if (type != 0 && other->type != 0 && type != other->type)
70989023839Sbeveloper		return false;
710332cc6bcSAxel Dörfler
71189023839Sbeveloper	switch ((type != 0) ? type : other->type) {
71289023839Sbeveloper		case B_MEDIA_RAW_AUDIO:
71389023839Sbeveloper			return multi_audio_format_matches(u.raw_audio, other->u.raw_audio);
714332cc6bcSAxel Dörfler
71589023839Sbeveloper		case B_MEDIA_RAW_VIDEO:
71689023839Sbeveloper			return raw_video_format_matches(u.raw_video, other->u.raw_video);
71752a38012Sejakowatz
71889023839Sbeveloper		case B_MEDIA_MULTISTREAM:
71981b2cc3fSStephan Aßmus			return multistream_format_matches(u.multistream,
72081b2cc3fSStephan Aßmus				other->u.multistream);
721332cc6bcSAxel Dörfler
72289023839Sbeveloper		case B_MEDIA_ENCODED_AUDIO:
72381b2cc3fSStephan Aßmus			return encoded_audio_format_matches(u.encoded_audio,
72481b2cc3fSStephan Aßmus				other->u.encoded_audio);
72589023839Sbeveloper
72689023839Sbeveloper		case B_MEDIA_ENCODED_VIDEO:
72781b2cc3fSStephan Aßmus			return encoded_video_format_matches(u.encoded_video,
72881b2cc3fSStephan Aßmus				other->u.encoded_video);
729332cc6bcSAxel Dörfler
73089023839Sbeveloper		default:
73181b2cc3fSStephan Aßmus			return true; // TODO: really?
73289023839Sbeveloper	}
73389023839Sbeveloper}
73452a38012Sejakowatz
73581b2cc3fSStephan Aßmus
73652a38012Sejakowatzvoid
73781b2cc3fSStephan Aßmusmedia_format::SpecializeTo(const media_format* otherFormat)
73852a38012Sejakowatz{
73989023839Sbeveloper	CALLED();
74081b2cc3fSStephan Aßmus
74189023839Sbeveloper	if (type == 0 && otherFormat->type == 0) {
74281b2cc3fSStephan Aßmus		ERROR("media_format::SpecializeTo can't specialize wildcard to other "
74381b2cc3fSStephan Aßmus			"wildcard format\n");
74489023839Sbeveloper		return;
74589023839Sbeveloper	}
746332cc6bcSAxel Dörfler
74789023839Sbeveloper	if (type == 0)
74889023839Sbeveloper		type = otherFormat->type;
749332cc6bcSAxel Dörfler
75089023839Sbeveloper	switch (type) {
75189023839Sbeveloper		case B_MEDIA_RAW_AUDIO:
75281b2cc3fSStephan Aßmus			multi_audio_format_specialize(&u.raw_audio,
75381b2cc3fSStephan Aßmus				&otherFormat->u.raw_audio);
75489023839Sbeveloper			return;
755332cc6bcSAxel Dörfler
75689023839Sbeveloper		case B_MEDIA_RAW_VIDEO:
75781b2cc3fSStephan Aßmus			raw_video_format_specialize(&u.raw_video,
75881b2cc3fSStephan Aßmus				&otherFormat->u.raw_video);
75989023839Sbeveloper			return;
76089023839Sbeveloper
76189023839Sbeveloper		case B_MEDIA_MULTISTREAM:
76281b2cc3fSStephan Aßmus			multistream_format_specialize(&u.multistream,
76381b2cc3fSStephan Aßmus				&otherFormat->u.multistream);
76489023839Sbeveloper			return;
765332cc6bcSAxel Dörfler
76689023839Sbeveloper		case B_MEDIA_ENCODED_AUDIO:
76781b2cc3fSStephan Aßmus			encoded_audio_format_specialize(&u.encoded_audio,
76881b2cc3fSStephan Aßmus				&otherFormat->u.encoded_audio);
76989023839Sbeveloper			return;
77089023839Sbeveloper
77189023839Sbeveloper		case B_MEDIA_ENCODED_VIDEO:
77281b2cc3fSStephan Aßmus			encoded_video_format_specialize(&u.encoded_video,
77381b2cc3fSStephan Aßmus				&otherFormat->u.encoded_video);
77489023839Sbeveloper			return;
775332cc6bcSAxel Dörfler
77689023839Sbeveloper		default:
77781b2cc3fSStephan Aßmus			ERROR("media_format::SpecializeTo can't specialize format "
77881b2cc3fSStephan Aßmus				"type %d\n", type);
77989023839Sbeveloper	}
78052a38012Sejakowatz}
78152a38012Sejakowatz
78252a38012Sejakowatz
78352a38012Sejakowatzstatus_t
78481b2cc3fSStephan Aßmusmedia_format::SetMetaData(const void* data, size_t size)
78552a38012Sejakowatz{
78626c68df8SMurai Takashi	if (!data || size > META_DATA_MAX_SIZE)
7870a00d23fSMarcus Overhagen		return B_BAD_VALUE;
788332cc6bcSAxel Dörfler
78981b2cc3fSStephan Aßmus	void* new_addr;
7900a00d23fSMarcus Overhagen	area_id new_area;
7910a00d23fSMarcus Overhagen	if (size < META_DATA_AREA_MIN_SIZE) {
7920a00d23fSMarcus Overhagen		new_area = B_BAD_VALUE;
7930a00d23fSMarcus Overhagen		new_addr = malloc(size);
7940a00d23fSMarcus Overhagen		if (!new_addr)
7950a00d23fSMarcus Overhagen			return B_NO_MEMORY;
7960a00d23fSMarcus Overhagen	} else {
79781b2cc3fSStephan Aßmus		new_area = create_area("meta_data_area", &new_addr, B_ANY_ADDRESS,
79881b2cc3fSStephan Aßmus			ROUND_UP_TO_PAGE(size), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
7990a00d23fSMarcus Overhagen		if (new_area < 0)
8000a00d23fSMarcus Overhagen			return (status_t)new_area;
801a4f26c7dSshatty	}
8020a00d23fSMarcus Overhagen
8030a00d23fSMarcus Overhagen	if (meta_data_area > 0)
8040a00d23fSMarcus Overhagen		delete_area(meta_data_area);
8050a00d23fSMarcus Overhagen	else
8060a00d23fSMarcus Overhagen		free(meta_data);
8070a00d23fSMarcus Overhagen
8080a00d23fSMarcus Overhagen	meta_data = new_addr;
809ceb9cf7aSshatty	meta_data_size = size;
8100a00d23fSMarcus Overhagen	meta_data_area = new_area;
811332cc6bcSAxel Dörfler
8120a00d23fSMarcus Overhagen	memcpy(meta_data, data, size);
813332cc6bcSAxel Dörfler
8140a00d23fSMarcus Overhagen	if (meta_data_area > 0)
8150a00d23fSMarcus Overhagen		set_area_protection(meta_data_area, B_READ_AREA);
8160a00d23fSMarcus Overhagen
817ceb9cf7aSshatty	return B_OK;
81852a38012Sejakowatz}
81952a38012Sejakowatz
82052a38012Sejakowatz
82181b2cc3fSStephan Aßmusconst void*
82252a38012Sejakowatzmedia_format::MetaData() const
82352a38012Sejakowatz{
824ceb9cf7aSshatty	return meta_data;
82552a38012Sejakowatz}
82652a38012Sejakowatz
82752a38012Sejakowatz
82852a38012Sejakowatzint32
82952a38012Sejakowatzmedia_format::MetaDataSize() const
83052a38012Sejakowatz{
831ceb9cf7aSshatty	return meta_data_size;
83252a38012Sejakowatz}
83352a38012Sejakowatz
8340a00d23fSMarcus Overhagen
83512ed45b6SMurai Takashivoid
83612ed45b6SMurai Takashimedia_format::Unflatten(const char *flatBuffer)
83752a38012Sejakowatz{
83812ed45b6SMurai Takashi	// TODO: we should not!!! make flat copies of media_format
83912ed45b6SMurai Takashi	memcpy(this, flatBuffer, sizeof(*this));
84012ed45b6SMurai Takashi	meta_data = NULL;
841a2d20d9dSshatty	meta_data_area = B_BAD_VALUE;
84252a38012Sejakowatz}
84352a38012Sejakowatz
84452a38012Sejakowatz
84512ed45b6SMurai Takashivoid
84612ed45b6SMurai Takashimedia_format::Clear()
84752a38012Sejakowatz{
8480a00d23fSMarcus Overhagen	memset(this, 0x00, sizeof(*this));
84912ed45b6SMurai Takashi	meta_data = NULL;
8500a00d23fSMarcus Overhagen	meta_data_area = B_BAD_VALUE;
85112ed45b6SMurai Takashi}
85212ed45b6SMurai Takashi
85312ed45b6SMurai Takashi
85412ed45b6SMurai Takashimedia_format::media_format()
85512ed45b6SMurai Takashi{
85612ed45b6SMurai Takashi	this->Clear();
85712ed45b6SMurai Takashi}
85812ed45b6SMurai Takashi
85912ed45b6SMurai Takashi
86012ed45b6SMurai Takashimedia_format::media_format(const media_format& other)
86112ed45b6SMurai Takashi{
86212ed45b6SMurai Takashi	this->Clear();
86352a38012Sejakowatz	*this = other;
86452a38012Sejakowatz}
86552a38012Sejakowatz
8660a00d23fSMarcus Overhagen
86752a38012Sejakowatzmedia_format::~media_format()
86852a38012Sejakowatz{
8690a00d23fSMarcus Overhagen	if (meta_data_area > 0)
8700a00d23fSMarcus Overhagen		delete_area(meta_data_area);
8710a00d23fSMarcus Overhagen	else
8720a00d23fSMarcus Overhagen		free(meta_data);
87352a38012Sejakowatz}
87452a38012Sejakowatz
87552a38012Sejakowatz
87652a38012Sejakowatz// final
87781b2cc3fSStephan Aßmusmedia_format&
87881b2cc3fSStephan Aßmusmedia_format::operator=(const media_format& clone)
87952a38012Sejakowatz{
8800a00d23fSMarcus Overhagen	// get rid of this format's meta data
88181b2cc3fSStephan Aßmus	this->~media_format();
88281b2cc3fSStephan Aßmus		// danger: using only ~media_format() would call the constructor
8830a00d23fSMarcus Overhagen
8840a00d23fSMarcus Overhagen	// make a binary copy
885a2d20d9dSshatty	memcpy(this, &clone, sizeof(*this));
8860a00d23fSMarcus Overhagen	// some binary copies are invalid:
8870a00d23fSMarcus Overhagen	meta_data = NULL;
8880a00d23fSMarcus Overhagen	meta_data_area = B_BAD_VALUE;
8890a00d23fSMarcus Overhagen
8900a00d23fSMarcus Overhagen	// clone or copy the meta data
8910a00d23fSMarcus Overhagen	if (clone.meta_data) {
892e0818886SJérôme Duval		if (clone.meta_data_area != B_BAD_VALUE) {
893332cc6bcSAxel Dörfler			meta_data_area = clone_area("meta_data_clone_area", &meta_data,
89481b2cc3fSStephan Aßmus				B_ANY_ADDRESS, B_READ_AREA, clone.meta_data_area);
8950a00d23fSMarcus Overhagen			if (meta_data_area < 0) {
8960a00d23fSMarcus Overhagen				// whoops, we just lost our meta data
8970a00d23fSMarcus Overhagen				meta_data = NULL;
898c332e7f7SJérôme Duval				meta_data_size = 0;
8990a00d23fSMarcus Overhagen			}
9000a00d23fSMarcus Overhagen		} else {
9010a00d23fSMarcus Overhagen			meta_data = malloc(meta_data_size);
9020a00d23fSMarcus Overhagen			if (meta_data) {
9030a00d23fSMarcus Overhagen				memcpy(meta_data, clone.meta_data, meta_data_size);
9040a00d23fSMarcus Overhagen			} else {
9050a00d23fSMarcus Overhagen				// whoops, we just lost our meta data
906c332e7f7SJérôme Duval				meta_data_size = 0;
9070a00d23fSMarcus Overhagen			}
908a2d20d9dSshatty		}
909a2d20d9dSshatty	}
91052a38012Sejakowatz	return *this;
91152a38012Sejakowatz}
91252a38012Sejakowatz
91352a38012Sejakowatz
91481b2cc3fSStephan Aßmus// #pragma mark -
91552a38012Sejakowatz
91681b2cc3fSStephan Aßmus
91781b2cc3fSStephan Aßmusbool
91881b2cc3fSStephan Aßmusoperator==(const media_raw_audio_format& a, const media_raw_audio_format& b)
91952a38012Sejakowatz{
92081b2cc3fSStephan Aßmus	return a.frame_rate == b.frame_rate
92181b2cc3fSStephan Aßmus		&& a.channel_count == b.channel_count
92281b2cc3fSStephan Aßmus		&& a.format == b.format
92381b2cc3fSStephan Aßmus		&& a.byte_order == b.byte_order
92481b2cc3fSStephan Aßmus		&& a.buffer_size == b.buffer_size;
92552a38012Sejakowatz}
92652a38012Sejakowatz
92781b2cc3fSStephan Aßmus
92881b2cc3fSStephan Aßmusbool
92981b2cc3fSStephan Aßmusoperator==(const media_multi_audio_info& a, const media_multi_audio_info& b)
93052a38012Sejakowatz{
93181b2cc3fSStephan Aßmus	return a.channel_mask == b.channel_mask
93281b2cc3fSStephan Aßmus		&& a.valid_bits == b.valid_bits
93381b2cc3fSStephan Aßmus		&& a.matrix_mask == b.matrix_mask;
93452a38012Sejakowatz}
93552a38012Sejakowatz
93681b2cc3fSStephan Aßmus
93781b2cc3fSStephan Aßmusbool
93881b2cc3fSStephan Aßmusoperator==(const media_multi_audio_format& a,
93981b2cc3fSStephan Aßmus	const media_multi_audio_format& b)
94052a38012Sejakowatz{
94181b2cc3fSStephan Aßmus	return (media_raw_audio_format)a == (media_raw_audio_format)b
94281b2cc3fSStephan Aßmus		&& (media_multi_audio_info)a == (media_multi_audio_info)b;
94352a38012Sejakowatz}
94452a38012Sejakowatz
94581b2cc3fSStephan Aßmus
94681b2cc3fSStephan Aßmusbool
94781b2cc3fSStephan Aßmusoperator==(const media_encoded_audio_format& a,
94881b2cc3fSStephan Aßmus	const media_encoded_audio_format& b)
94952a38012Sejakowatz{
95081b2cc3fSStephan Aßmus	return a.output == b.output
95181b2cc3fSStephan Aßmus		&& a.encoding == b.encoding
95281b2cc3fSStephan Aßmus		&& a.bit_rate == b.bit_rate
95381b2cc3fSStephan Aßmus		&& a.frame_size == b.frame_size
95481b2cc3fSStephan Aßmus		&& a.multi_info == b.multi_info;
95552a38012Sejakowatz}
95652a38012Sejakowatz
95781b2cc3fSStephan Aßmus
95881b2cc3fSStephan Aßmusbool
95981b2cc3fSStephan Aßmusoperator==(const media_video_display_info& a,
96081b2cc3fSStephan Aßmus	const media_video_display_info& b)
96152a38012Sejakowatz{
96281b2cc3fSStephan Aßmus	return a.format == b.format
96381b2cc3fSStephan Aßmus		&& a.line_width == b.line_width
96481b2cc3fSStephan Aßmus		&& a.line_count == b.line_count
96581b2cc3fSStephan Aßmus		&& a.bytes_per_row == b.bytes_per_row
96681b2cc3fSStephan Aßmus		&& a.pixel_offset == b.pixel_offset
96781b2cc3fSStephan Aßmus		&& a.line_offset == b.line_offset
96881b2cc3fSStephan Aßmus		&& a.flags == b.flags;
96952a38012Sejakowatz}
97052a38012Sejakowatz
97181b2cc3fSStephan Aßmus
97281b2cc3fSStephan Aßmusbool
97381b2cc3fSStephan Aßmusoperator==(const media_raw_video_format& a, const media_raw_video_format& b)
97452a38012Sejakowatz{
97581b2cc3fSStephan Aßmus	return a.field_rate == b.field_rate
97681b2cc3fSStephan Aßmus		&& a.interlace == b.interlace
97781b2cc3fSStephan Aßmus		&& a.first_active == b.first_active
97881b2cc3fSStephan Aßmus		&& a.last_active == b.last_active
97981b2cc3fSStephan Aßmus		&& a.orientation == b.orientation
98081b2cc3fSStephan Aßmus		&& a.pixel_width_aspect == b.pixel_width_aspect
98181b2cc3fSStephan Aßmus		&& a.pixel_height_aspect == b.pixel_height_aspect
98281b2cc3fSStephan Aßmus		&& a.display == b.display;
98352a38012Sejakowatz}
98452a38012Sejakowatz
98581b2cc3fSStephan Aßmus
98681b2cc3fSStephan Aßmusbool
98781b2cc3fSStephan Aßmusoperator==(const media_encoded_video_format& a,
98881b2cc3fSStephan Aßmus	const media_encoded_video_format& b)
98952a38012Sejakowatz{
99081b2cc3fSStephan Aßmus	return a.output == b.output
99181b2cc3fSStephan Aßmus		&& a.avg_bit_rate == b.avg_bit_rate
99281b2cc3fSStephan Aßmus		&& a.max_bit_rate == b.max_bit_rate
99381b2cc3fSStephan Aßmus		&& a.encoding == b.encoding
99481b2cc3fSStephan Aßmus		&& a.frame_size == b.frame_size
99581b2cc3fSStephan Aßmus		&& a.forward_history == b.forward_history
99681b2cc3fSStephan Aßmus		&& a.backward_history == b.backward_history;
99752a38012Sejakowatz}
99852a38012Sejakowatz
99981b2cc3fSStephan Aßmus
100081b2cc3fSStephan Aßmusbool
100181b2cc3fSStephan Aßmusoperator==(const media_multistream_format::vid_info& a,
100281b2cc3fSStephan Aßmus	const media_multistream_format::vid_info& b)
100352a38012Sejakowatz{
100481b2cc3fSStephan Aßmus	return a.frame_rate == b.frame_rate
100581b2cc3fSStephan Aßmus		&& a.width == b.width
100681b2cc3fSStephan Aßmus		&& a.height == b.height
100781b2cc3fSStephan Aßmus		&& a.space == b.space
100881b2cc3fSStephan Aßmus		&& a.sampling_rate == b.sampling_rate
100981b2cc3fSStephan Aßmus		&& a.sample_format == b.sample_format
101081b2cc3fSStephan Aßmus		&& a.byte_order == b.byte_order
101181b2cc3fSStephan Aßmus		&& a.channel_count == b.channel_count;
101252a38012Sejakowatz}
101352a38012Sejakowatz
1014