comparison mov.c @ 4739:436d42e64b52 libavformat

MOV: Support stz2 "Compact Sample Size Box"
author alexc
date Mon, 16 Mar 2009 16:14:36 +0000
parents 18bcd89f5809
children 07ac6d6584a1
comparison
equal deleted inserted replaced
4738:08598e73b959 4739:436d42e64b52
31 #include "avformat.h" 31 #include "avformat.h"
32 #include "riff.h" 32 #include "riff.h"
33 #include "isom.h" 33 #include "isom.h"
34 #include "libavcodec/mpeg4audio.h" 34 #include "libavcodec/mpeg4audio.h"
35 #include "libavcodec/mpegaudiodata.h" 35 #include "libavcodec/mpegaudiodata.h"
36 #include "libavcodec/bitstream.h"
36 37
37 #if CONFIG_ZLIB 38 #if CONFIG_ZLIB
38 #include <zlib.h> 39 #include <zlib.h>
39 #endif 40 #endif
40 41
1125 1126
1126 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom) 1127 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1127 { 1128 {
1128 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; 1129 AVStream *st = c->fc->streams[c->fc->nb_streams-1];
1129 MOVStreamContext *sc = st->priv_data; 1130 MOVStreamContext *sc = st->priv_data;
1130 unsigned int i, entries, sample_size; 1131 unsigned int i, entries, sample_size, field_size, num_bytes;
1132 GetBitContext gb;
1133 unsigned char* buf;
1131 1134
1132 get_byte(pb); /* version */ 1135 get_byte(pb); /* version */
1133 get_be24(pb); /* flags */ 1136 get_be24(pb); /* flags */
1134 1137
1138 if (atom.type == MKTAG('s','t','s','z')) {
1135 sample_size = get_be32(pb); 1139 sample_size = get_be32(pb);
1136 if (!sc->sample_size) /* do not overwrite value computed in stsd */ 1140 if (!sc->sample_size) /* do not overwrite value computed in stsd */
1137 sc->sample_size = sample_size; 1141 sc->sample_size = sample_size;
1142 field_size = 32;
1143 } else {
1144 sample_size = 0;
1145 get_be24(pb); /* reserved */
1146 field_size = get_byte(pb);
1147 }
1138 entries = get_be32(pb); 1148 entries = get_be32(pb);
1139 1149
1140 dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries); 1150 dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries);
1141 1151
1142 sc->sample_count = entries; 1152 sc->sample_count = entries;
1143 if (sample_size) 1153 if (sample_size)
1144 return 0; 1154 return 0;
1145 1155
1156 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
1157 av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size);
1158 return -1;
1159 }
1160
1146 if(entries >= UINT_MAX / sizeof(int)) 1161 if(entries >= UINT_MAX / sizeof(int))
1147 return -1; 1162 return -1;
1148 sc->sample_sizes = av_malloc(entries * sizeof(int)); 1163 sc->sample_sizes = av_malloc(entries * sizeof(int));
1149 if (!sc->sample_sizes) 1164 if (!sc->sample_sizes)
1150 return AVERROR(ENOMEM); 1165 return AVERROR(ENOMEM);
1151 1166
1167 num_bytes = (entries*field_size+4)>>3;
1168
1169 buf = av_malloc(num_bytes);
1170 if (!buf) {
1171 av_freep(&sc->sample_sizes);
1172 return AVERROR(ENOMEM);
1173 }
1174
1175 if (get_buffer(pb, buf, num_bytes) < num_bytes) {
1176 av_freep(&sc->sample_sizes);
1177 av_free(buf);
1178 return -1;
1179 }
1180
1181 init_get_bits(&gb, buf, 8*num_bytes);
1182
1152 for(i=0; i<entries; i++) 1183 for(i=0; i<entries; i++)
1153 sc->sample_sizes[i] = get_be32(pb); 1184 sc->sample_sizes[i] = get_bits_long(&gb, field_size);
1185
1186 av_free(buf);
1154 return 0; 1187 return 0;
1155 } 1188 }
1156 1189
1157 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) 1190 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
1158 { 1191 {
1791 { MKTAG('s','t','s','c'), mov_read_stsc }, 1824 { MKTAG('s','t','s','c'), mov_read_stsc },
1792 { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */ 1825 { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */
1793 { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */ 1826 { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */
1794 { MKTAG('s','t','s','z'), mov_read_stsz }, /* sample size */ 1827 { MKTAG('s','t','s','z'), mov_read_stsz }, /* sample size */
1795 { MKTAG('s','t','t','s'), mov_read_stts }, 1828 { MKTAG('s','t','t','s'), mov_read_stts },
1829 { MKTAG('s','t','z','2'), mov_read_stsz }, /* compact sample size */
1796 { MKTAG('t','k','h','d'), mov_read_tkhd }, /* track header */ 1830 { MKTAG('t','k','h','d'), mov_read_tkhd }, /* track header */
1797 { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */ 1831 { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */
1798 { MKTAG('t','r','a','k'), mov_read_trak }, 1832 { MKTAG('t','r','a','k'), mov_read_trak },
1799 { MKTAG('t','r','a','f'), mov_read_default }, 1833 { MKTAG('t','r','a','f'), mov_read_default },
1800 { MKTAG('t','r','e','x'), mov_read_trex }, 1834 { MKTAG('t','r','e','x'), mov_read_trex },