Mercurial > mplayer.hg
annotate libmpdemux/parse_mp4.c @ 5336:3cc26c4e662b
no native support for I420 in G200
author | arpi |
---|---|
date | Mon, 25 Mar 2002 16:22:15 +0000 |
parents | c4f6ab72300a |
children | dba4cecbb4d1 |
rev | line source |
---|---|
5301 | 1 /* parse_mp4.c - MP4 file format parser code |
2 * This file is part of MPlayer, see http://mplayerhq.hu/ for info. | |
3 * (c)2002 by Felix Buenemann <atmosfear at users.sourceforge.net> | |
4 * File licensed under the GPL, see http://www.fsf.org/ for more info. | |
5 * Code inspired by libmp4 from http://mpeg4ip.sourceforge.net/. | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <inttypes.h> | |
10 #include <malloc.h> | |
11 #include "parse_mp4.h" | |
12 #include "mp_msg.h" | |
13 #include "stream.h" | |
14 | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
15 //#define MP4_DUMPATOM |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
16 |
5301 | 17 #define MP4_DL MSGL_V |
5303 | 18 #define freereturn(a,b) free(a); return b |
5301 | 19 |
20 int mp4_read_descr_len(stream_t *s) { | |
21 uint8_t b; | |
22 uint8_t numBytes = 0; | |
23 uint32_t length = 0; | |
24 | |
25 do { | |
26 b = stream_read_char(s); | |
27 numBytes++; | |
28 length = (length << 7) | (b & 0x7F); | |
29 } while ((b & 0x80) && numBytes < 4); | |
30 | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
31 //printf("MP4 read desc len: %d\n", length); |
5301 | 32 return length; |
33 } | |
34 | |
5305 | 35 /* parse the data part of MP4 esds atoms */ |
5301 | 36 int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) { |
37 /* create memory stream from data */ | |
38 stream_t *s = new_memory_stream(data, datalen); | |
39 uint8_t len; | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
40 #ifdef MP4_DUMPATOM |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
41 {int i; |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
42 printf("ESDS Dump (%dbyte):\n", datalen); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
43 for(i = 0; i < datalen; i++) |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
44 printf("%02X ", data[i]); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
45 printf("\nESDS Dumped\n");} |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
46 #endif |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
47 memset(esds, 0, sizeof(esds_t)); |
5301 | 48 |
49 esds->version = stream_read_char(s); | |
50 esds->flags = stream_read_int24(s); | |
51 mp_msg(MSGT_DEMUX, MP4_DL, | |
52 "ESDS MPEG4 version: %d flags: 0x%06X\n", | |
53 esds->version, esds->flags); | |
54 | |
55 /* get and verify ES_DescrTag */ | |
5305 | 56 if (stream_read_char(s) == MP4ESDescrTag) { |
5301 | 57 /* read length */ |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
58 len = mp4_read_descr_len(s); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
59 |
5301 | 60 esds->ESId = stream_read_word(s); |
61 esds->streamPriority = stream_read_char(s); | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
62 mp_msg(MSGT_DEMUX, MP4_DL, |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
63 "ESDS MPEG4 ES Descriptor (%dBytes):\n" |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
64 " -> ESId: %d\n" |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
65 " -> streamPriority: %d\n", |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
66 len, esds->ESId, esds->streamPriority); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
67 |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
68 if (len < (5 + 15)) { |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
69 freereturn(s,1); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
70 } |
5301 | 71 } else { |
72 esds->ESId = stream_read_word(s); | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
73 mp_msg(MSGT_DEMUX, MP4_DL, |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
74 "ESDS MPEG4 ES Descriptor (%dBytes):\n" |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
75 " -> ESId: %d\n", 2, esds->ESId); |
5301 | 76 } |
77 | |
78 /* get and verify DecoderConfigDescrTab */ | |
79 if (stream_read_char(s) != MP4DecConfigDescrTag) { | |
5303 | 80 freereturn(s,1); |
5301 | 81 } |
82 | |
83 /* read length */ | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
84 len = mp4_read_descr_len(s); |
5301 | 85 |
86 esds->objectTypeId = stream_read_char(s); | |
87 esds->streamType = stream_read_char(s); | |
88 esds->bufferSizeDB = stream_read_int24(s); | |
89 esds->maxBitrate = stream_read_dword(s); | |
90 esds->avgBitrate = stream_read_dword(s); | |
91 mp_msg(MSGT_DEMUX, MP4_DL, | |
92 "ESDS MPEG4 Decoder Config Descriptor (%dBytes):\n" | |
93 " -> objectTypeId: %d\n" | |
94 " -> streamType: 0x%02X\n" | |
95 " -> bufferSizeDB: 0x%06X\n" | |
96 " -> maxBitrate: %.3fkbit/s\n" | |
97 " -> avgBitrate: %.3fkbit/s\n", | |
98 len, esds->objectTypeId, esds->streamType, | |
99 esds->bufferSizeDB, esds->maxBitrate/1000.0, | |
100 esds->avgBitrate/1000.0); | |
101 | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
102 if (len < 15) { |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
103 freereturn(s,1); |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
104 } |
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
105 |
5301 | 106 /* get and verify DecSpecificInfoTag */ |
107 if (stream_read_char(s) != MP4DecSpecificDescrTag) { | |
5303 | 108 freereturn(s,1); |
5301 | 109 } |
110 | |
111 /* read length */ | |
112 esds->decoderConfigLen = len = mp4_read_descr_len(s); | |
113 | |
114 esds->decoderConfig = malloc(esds->decoderConfigLen); | |
115 if (esds->decoderConfig) { | |
116 stream_read(s, esds->decoderConfig, esds->decoderConfigLen); | |
117 } else { | |
118 esds->decoderConfigLen = 0; | |
119 } | |
120 mp_msg(MSGT_DEMUX, MP4_DL, | |
121 "ESDS MPEG4 Decoder Specific Descriptor (%dBytes)\n", len); | |
122 | |
5305 | 123 /* get and verify SLConfigDescrTag */ |
124 if(stream_read_char(s) != MP4SLConfigDescrTag) { | |
125 freereturn(s,1); | |
126 } | |
127 | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
128 /* Note: SLConfig is usually constant value 2, size 1Byte */ |
5333 | 129 esds->SLConfigLen = len = mp4_read_descr_len(s); |
5305 | 130 esds->SLConfig = malloc(esds->SLConfigLen); |
131 if (esds->SLConfig) { | |
132 stream_read(s, esds->SLConfig, esds->SLConfigLen); | |
133 } else { | |
134 esds->SLConfigLen = 0; | |
135 } | |
136 mp_msg(MSGT_DEMUX, MP4_DL, | |
137 "ESDS MPEG4 Sync Layer Config Descriptor (%dBytes)\n" | |
138 " -> predefined: %d\n", len, esds->SLConfig[0]); | |
139 | |
5301 | 140 /* will skip the remainder of the atom */ |
5303 | 141 freereturn(s,0); |
5301 | 142 |
143 } | |
144 | |
5305 | 145 /* cleanup all mem occupied by mp4_parse_esds */ |
146 void mp4_free_esds(esds_t *esds) { | |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
147 if(esds->decoderConfigLen) |
5305 | 148 free(esds->decoderConfig); |
5332
a3874da21700
Fix some silly logical bugs and fix memory cleanup in case mp4_parse_es returned with an error by memsetting the esds struct to 0 on init.
atmos4
parents:
5305
diff
changeset
|
149 if(esds->SLConfigLen) |
5305 | 150 free(esds->SLConfig); |
151 } | |
152 | |
5303 | 153 #undef freereturn |
154 #undef MP4_DL | |
155 |