xref: /haiku/src/add-ons/media/media-add-ons/misc.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 // misc.cpp
2 //
3 // Andrew Bachmann, 2002
4 //
5 // Some functions for general debugging and
6 // working around be media kit bugs.
7 
8 #include "misc.h"
9 #include <stdio.h>
10 
11 // -------------------------------------------------------- //
12 // lib functions
13 // -------------------------------------------------------- //
14 
15 void print_multistream_format(media_multistream_format * format) {
16 	fprintf(stderr,"[");
17 	switch (format->format) {
18 	case media_multistream_format::B_ANY:			fprintf(stderr,"ANY"); break;
19 	case media_multistream_format::B_VID:			fprintf(stderr,"VID"); break;
20 	case media_multistream_format::B_AVI:			fprintf(stderr,"AVI"); break;
21 	case media_multistream_format::B_MPEG1:		fprintf(stderr,"MPEG1"); break;
22 	case media_multistream_format::B_MPEG2:		fprintf(stderr,"MPEG2"); break;
23 	case media_multistream_format::B_QUICKTIME:	fprintf(stderr,"QUICKTIME"); break;
24 	default:			fprintf(stderr,"????"); break;
25 	}
26 	fprintf(stderr," avg_bit_rate(%f) max_bit_rate(%f)",
27 			format->avg_bit_rate,format->max_bit_rate);
28 	fprintf(stderr," avg_chunk_size(%" B_PRId32
29 			") max_chunk_size(%"  B_PRId32 ")",
30 			format->avg_chunk_size,format->max_chunk_size);
31 }
32 
33 void print_media_format(media_format * format) {
34 	fprintf(stderr,"{");
35 	switch (format->type) {
36 	case B_MEDIA_NO_TYPE:		fprintf(stderr,"NO_TYPE"); break;
37 	case B_MEDIA_UNKNOWN_TYPE:	fprintf(stderr,"UNKNOWN_TYPE"); break;
38 	case B_MEDIA_RAW_AUDIO:		fprintf(stderr,"RAW_AUDIO"); break;
39 	case B_MEDIA_RAW_VIDEO:		fprintf(stderr,"RAW_VIDEO"); break;
40 	case B_MEDIA_VBL:			fprintf(stderr,"VBL"); break;
41 	case B_MEDIA_TIMECODE:		fprintf(stderr,"TIMECODE"); break;
42 	case B_MEDIA_MIDI:			fprintf(stderr,"MIDI"); break;
43 	case B_MEDIA_TEXT:			fprintf(stderr,"TEXT"); break;
44 	case B_MEDIA_HTML:			fprintf(stderr,"HTML"); break;
45 	case B_MEDIA_MULTISTREAM:	fprintf(stderr,"MULTISTREAM"); break;
46 	case B_MEDIA_PARAMETERS:	fprintf(stderr,"PARAMETERS"); break;
47 	case B_MEDIA_ENCODED_AUDIO:	fprintf(stderr,"ENCODED_AUDIO"); break;
48 	case B_MEDIA_ENCODED_VIDEO:	fprintf(stderr,"ENCODED_VIDEO"); break;
49 	default:					fprintf(stderr,"????"); break;
50 	}
51 	fprintf(stderr,":");
52 	switch (format->type) {
53 	case B_MEDIA_RAW_AUDIO:		fprintf(stderr,"RAW_AUDIO"); break;
54 	case B_MEDIA_RAW_VIDEO:		fprintf(stderr,"RAW_VIDEO"); break;
55 	case B_MEDIA_MULTISTREAM:	print_multistream_format(&format->u.multistream); break;
56 	case B_MEDIA_ENCODED_AUDIO:	fprintf(stderr,"ENCODED_AUDIO"); break;
57 	case B_MEDIA_ENCODED_VIDEO:	fprintf(stderr,"ENCODED_VIDEO"); break;
58 	default:					fprintf(stderr,"????"); break;
59 	}
60 	fprintf(stderr,"}");
61 }
62 
63 bool multistream_format_is_acceptible(
64 						const media_multistream_format & producer_format,
65 						const media_multistream_format & consumer_format)
66 {
67 	// first check the format, if necessary
68 	if (consumer_format.format != media_multistream_format::B_ANY) {
69 		if (consumer_format.format != producer_format.format) {
70 			return false;
71 		}
72 	}
73 	// then check the average bit rate
74 	if (consumer_format.avg_bit_rate != media_multistream_format::wildcard.avg_bit_rate) {
75 		if (consumer_format.avg_bit_rate != producer_format.avg_bit_rate) {
76 			// do they have to match exactly?  I don't know.  assume yes.
77 			return false;
78 		}
79 	}
80 	// then check the maximum bit rate
81 	if (consumer_format.max_bit_rate != media_multistream_format::wildcard.max_bit_rate) {
82 		if (consumer_format.max_bit_rate != producer_format.max_bit_rate) {
83 			// do they have to match exactly?  I don't know.  assume yes.
84 			return false;
85 		}
86 	}
87 	// then check the average chunk size
88 	if (consumer_format.avg_chunk_size != media_multistream_format::wildcard.avg_chunk_size) {
89 		if (consumer_format.avg_chunk_size != producer_format.avg_chunk_size) {
90 			// do they have to match exactly?  I don't know.  assume yes.
91 			return false;
92 		}
93 	}
94 	// then check the maximum bit rate
95 	if (consumer_format.max_chunk_size != media_multistream_format::wildcard.max_chunk_size) {
96 		if (consumer_format.max_chunk_size != producer_format.max_chunk_size) {
97 			// do they have to match exactly?  I don't know.  assume yes.
98 			return false;
99 		}
100 	}
101 	// should also check format specific fields, and others?
102 	return true;
103 }
104 
105 bool format_is_acceptible(
106 						const media_format & producer_format,
107 						const media_format & consumer_format)
108 {
109 	// first check the type, if necessary
110 	if (consumer_format.type != B_MEDIA_UNKNOWN_TYPE) {
111 		if (consumer_format.type != producer_format.type) {
112 			return false;
113 		}
114 		switch (consumer_format.type) {
115 			case B_MEDIA_MULTISTREAM:
116 				if (!multistream_format_is_acceptible(producer_format.u.multistream,
117 													  consumer_format.u.multistream)) {
118 					return false;
119 				}
120 				break;
121 			default:
122 				fprintf(stderr,"format_is_acceptible : unimplemented type.\n");
123 				return format_is_compatible(producer_format,consumer_format);
124 				break;
125 		}
126 	}
127 	// should also check non-type fields?
128 	return true;
129 }
130 
131