xref: /haiku/src/add-ons/media/media-add-ons/dvb/MediaFormat.cpp (revision fcb9bdc0c90a4dd4d1011fce41856e532dbd0226)
1b2859abeSMarcus Overhagen /*
2b2859abeSMarcus Overhagen  * Copyright (c) 2004-2007 Marcus Overhagen <marcus@overhagen.de>
3b2859abeSMarcus Overhagen  *
4b2859abeSMarcus Overhagen  * Permission is hereby granted, free of charge, to any person
5b2859abeSMarcus Overhagen  * obtaining a copy of this software and associated documentation
6b2859abeSMarcus Overhagen  * files (the "Software"), to deal in the Software without restriction,
7b2859abeSMarcus Overhagen  * including without limitation the rights to use, copy, modify,
8b2859abeSMarcus Overhagen  * merge, publish, distribute, sublicense, and/or sell copies of
9b2859abeSMarcus Overhagen  * the Software, and to permit persons to whom the Software is
10b2859abeSMarcus Overhagen  * furnished to do so, subject to the following conditions:
11b2859abeSMarcus Overhagen  *
12b2859abeSMarcus Overhagen  * The above copyright notice and this permission notice shall be
13b2859abeSMarcus Overhagen  * included in all copies or substantial portions of the Software.
14b2859abeSMarcus Overhagen  *
15b2859abeSMarcus Overhagen  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16b2859abeSMarcus Overhagen  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17b2859abeSMarcus Overhagen  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18b2859abeSMarcus Overhagen  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19b2859abeSMarcus Overhagen  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20b2859abeSMarcus Overhagen  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21b2859abeSMarcus Overhagen  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22b2859abeSMarcus Overhagen  * OTHER DEALINGS IN THE SOFTWARE.
23b2859abeSMarcus Overhagen  */
24b2859abeSMarcus Overhagen 
25b2859abeSMarcus Overhagen #include <media/MediaFormats.h>
26*fcb9bdc0SMarcus Overhagen #include <media/MediaNode.h>
27b2859abeSMarcus Overhagen #include <stdio.h>
28b2859abeSMarcus Overhagen #include "MediaFormat.h"
29b2859abeSMarcus Overhagen 
30b2859abeSMarcus Overhagen void
31b2859abeSMarcus Overhagen PrintFormat(const media_output &output)
32b2859abeSMarcus Overhagen {
33b2859abeSMarcus Overhagen 	PrintFormat(output.format);
34b2859abeSMarcus Overhagen }
35b2859abeSMarcus Overhagen 
36b2859abeSMarcus Overhagen 
37b2859abeSMarcus Overhagen void
38b2859abeSMarcus Overhagen PrintFormat(const media_format &format)
39b2859abeSMarcus Overhagen {
40b2859abeSMarcus Overhagen 	char s[200];
41b2859abeSMarcus Overhagen 	string_for_format(format, s, sizeof(s));
42b2859abeSMarcus Overhagen 	printf("%s\n", s);
43b2859abeSMarcus Overhagen }
44b2859abeSMarcus Overhagen 
45b2859abeSMarcus Overhagen 
46b2859abeSMarcus Overhagen status_t
47b2859abeSMarcus Overhagen GetHeaderFormat(media_format *out_format, const void *header, size_t size, int stream_id)
48b2859abeSMarcus Overhagen {
49b2859abeSMarcus Overhagen 
50b2859abeSMarcus Overhagen 	const uint8 *d = (const uint8 *)header;
51b2859abeSMarcus Overhagen 	printf("GetHeaderFormat: stream_id %02x\n", stream_id);
52b2859abeSMarcus Overhagen 	printf("frame header: "
53b2859abeSMarcus Overhagen 		   "%02x %02x %02x %02x %02x %02x %02x %02x "
54b2859abeSMarcus Overhagen 		   "%02x %02x %02x %02x %02x %02x %02x %02x\n",
55b2859abeSMarcus Overhagen 		   d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
56b2859abeSMarcus Overhagen 		   d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
57b2859abeSMarcus Overhagen 
58b2859abeSMarcus Overhagen 	if (d[0] == 0xff && d[1] == 0xfc) {
59b2859abeSMarcus Overhagen 
60b2859abeSMarcus Overhagen 		printf("GetHeaderFormat: assuming mepeg audio\n");
61b2859abeSMarcus Overhagen 
62b2859abeSMarcus Overhagen 		status_t err;
63b2859abeSMarcus Overhagen 
64b2859abeSMarcus Overhagen 		media_format_description desc;
65b2859abeSMarcus Overhagen 		desc.family = B_MPEG_FORMAT_FAMILY;
66b2859abeSMarcus Overhagen 		desc.u.mpeg.id = B_MPEG_1_AUDIO_LAYER_3;
67b2859abeSMarcus Overhagen 
68b2859abeSMarcus Overhagen 		BMediaFormats formats;
69b2859abeSMarcus Overhagen 		media_format format;
70b2859abeSMarcus Overhagen 
71b2859abeSMarcus Overhagen 		err = formats.InitCheck();
72b2859abeSMarcus Overhagen 		if (err)
73b2859abeSMarcus Overhagen 			return err;
74b2859abeSMarcus Overhagen 
75b2859abeSMarcus Overhagen 		err = formats.GetFormatFor(desc, out_format);
76b2859abeSMarcus Overhagen 		if (err)
77b2859abeSMarcus Overhagen 			return err;
78b2859abeSMarcus Overhagen 
79b2859abeSMarcus Overhagen 		out_format->u.encoded_audio.output.frame_rate = 48000;
80b2859abeSMarcus Overhagen 		out_format->u.encoded_audio.output.channel_count = 2;
81b2859abeSMarcus Overhagen 		out_format->u.encoded_audio.output.buffer_size = 1024;
82b2859abeSMarcus Overhagen 
83b2859abeSMarcus Overhagen 		printf("GetHeaderFormat: ");
84b2859abeSMarcus Overhagen 		PrintFormat(*out_format);
85b2859abeSMarcus Overhagen 	} else {
86b2859abeSMarcus Overhagen 
87b2859abeSMarcus Overhagen 		printf("GetHeaderFormat: assuming mepeg video\n");
88b2859abeSMarcus Overhagen 
89b2859abeSMarcus Overhagen 		status_t err;
90b2859abeSMarcus Overhagen 
91b2859abeSMarcus Overhagen 		media_format_description desc;
92b2859abeSMarcus Overhagen 		desc.family = B_MPEG_FORMAT_FAMILY;
93b2859abeSMarcus Overhagen 		desc.u.mpeg.id = B_MPEG_1_VIDEO;
94b2859abeSMarcus Overhagen 
95b2859abeSMarcus Overhagen 		BMediaFormats formats;
96b2859abeSMarcus Overhagen 		media_format format;
97b2859abeSMarcus Overhagen 
98b2859abeSMarcus Overhagen 		err = formats.InitCheck();
99b2859abeSMarcus Overhagen 		if (err)
100b2859abeSMarcus Overhagen 			return err;
101b2859abeSMarcus Overhagen 
102b2859abeSMarcus Overhagen 		err = formats.GetFormatFor(desc, out_format);
103b2859abeSMarcus Overhagen 		if (err)
104b2859abeSMarcus Overhagen 			return err;
105b2859abeSMarcus Overhagen 
106b2859abeSMarcus Overhagen 	}
107b2859abeSMarcus Overhagen 
108b2859abeSMarcus Overhagen 	return B_OK;
109b2859abeSMarcus Overhagen }
110