mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
* fixed initialization and some memleak
* filling more avcodecs variables * extending/improving mov parsing (unfinished) Originally committed as revision 1812 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
693feac556
commit
5cd62665f0
@ -1081,6 +1081,14 @@ typedef struct AVCodecContext {
|
|||||||
*/
|
*/
|
||||||
int inter_quant_bias;
|
int inter_quant_bias;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* color table ID.
|
||||||
|
* - encoding: unused.
|
||||||
|
* - decoding: which clrtable should be used for 8bit RGB images
|
||||||
|
* table have to be stored somewhere FIXME
|
||||||
|
*/
|
||||||
|
int color_table_id;
|
||||||
|
|
||||||
} AVCodecContext;
|
} AVCodecContext;
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ void print_atom(const char *str, uint32_t type, uint64_t offset, uint64_t size)
|
|||||||
(tag >> 24) & 0xff,
|
(tag >> 24) & 0xff,
|
||||||
(unsigned int)offset,
|
(unsigned int)offset,
|
||||||
(unsigned int)size);
|
(unsigned int)size);
|
||||||
|
assert((unsigned int)size < 0x7fffffff);// catching errors
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ static const CodecTag mov_audio_tags[] = {
|
|||||||
/* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
|
/* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
|
||||||
{ CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
|
{ CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
|
||||||
{ CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') }, /* 8 bits */
|
{ CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') }, /* 8 bits */
|
||||||
{ CODEC_ID_PCM_U8, 0x20776172 }, /* 8 bits unsigned */
|
{ CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */
|
||||||
{ CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
|
{ CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
|
||||||
{ CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
|
{ CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
|
||||||
{ CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
|
{ CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
|
||||||
@ -148,6 +149,54 @@ typedef struct MOV_sample_to_chunk_tbl {
|
|||||||
long id;
|
long id;
|
||||||
} MOV_sample_to_chunk_tbl;
|
} MOV_sample_to_chunk_tbl;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t version;
|
||||||
|
uint32_t flags; // 24bit
|
||||||
|
|
||||||
|
/* 0x03 ESDescrTag */
|
||||||
|
uint16_t es_id;
|
||||||
|
#define MP4ODescrTag 0x01
|
||||||
|
#define MP4IODescrTag 0x02
|
||||||
|
#define MP4ESDescrTag 0x03
|
||||||
|
#define MP4DecConfigDescrTag 0x04
|
||||||
|
#define MP4DecSpecificDescrTag 0x05
|
||||||
|
#define MP4SLConfigDescrTag 0x06
|
||||||
|
#define MP4ContentIdDescrTag 0x07
|
||||||
|
#define MP4SupplContentIdDescrTag 0x08
|
||||||
|
#define MP4IPIPtrDescrTag 0x09
|
||||||
|
#define MP4IPMPPtrDescrTag 0x0A
|
||||||
|
#define MP4IPMPDescrTag 0x0B
|
||||||
|
#define MP4RegistrationDescrTag 0x0D
|
||||||
|
#define MP4ESIDIncDescrTag 0x0E
|
||||||
|
#define MP4ESIDRefDescrTag 0x0F
|
||||||
|
#define MP4FileIODescrTag 0x10
|
||||||
|
#define MP4FileODescrTag 0x11
|
||||||
|
#define MP4ExtProfileLevelDescrTag 0x13
|
||||||
|
#define MP4ExtDescrTagsStart 0x80
|
||||||
|
#define MP4ExtDescrTagsEnd 0xFE
|
||||||
|
uint8_t stream_priority;
|
||||||
|
|
||||||
|
/* 0x04 DecConfigDescrTag */
|
||||||
|
uint8_t object_type_id;
|
||||||
|
uint8_t stream_type;
|
||||||
|
/* XXX: really streamType is
|
||||||
|
* only 6bit, followed by:
|
||||||
|
* 1bit upStream
|
||||||
|
* 1bit reserved
|
||||||
|
*/
|
||||||
|
uint32_t buffer_size_db; // 24
|
||||||
|
uint32_t max_bitrate;
|
||||||
|
uint32_t avg_bitrate;
|
||||||
|
|
||||||
|
/* 0x05 DecSpecificDescrTag */
|
||||||
|
uint8_t decoder_cfg_len;
|
||||||
|
uint8_t *decoder_cfg;
|
||||||
|
|
||||||
|
/* 0x06 SLConfigDescrTag */
|
||||||
|
uint8_t sl_config_len;
|
||||||
|
uint8_t *sl_config;
|
||||||
|
} MOV_esds_t;
|
||||||
|
|
||||||
typedef struct MOVStreamContext {
|
typedef struct MOVStreamContext {
|
||||||
int ffindex; /* the ffmpeg stream id */
|
int ffindex; /* the ffmpeg stream id */
|
||||||
int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
|
int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
|
||||||
@ -160,18 +209,20 @@ typedef struct MOVStreamContext {
|
|||||||
long sample_size;
|
long sample_size;
|
||||||
long sample_count;
|
long sample_count;
|
||||||
long *sample_sizes;
|
long *sample_sizes;
|
||||||
long time_scale;
|
int time_scale;
|
||||||
long current_sample;
|
long current_sample;
|
||||||
long left_in_chunk; /* how many samples before next chunk */
|
long left_in_chunk; /* how many samples before next chunk */
|
||||||
/* specific MPEG4 header which is added at the beginning of the stream */
|
/* specific MPEG4 header which is added at the beginning of the stream */
|
||||||
int header_len;
|
int header_len;
|
||||||
|
MOV_esds_t esds;
|
||||||
uint8_t *header_data;
|
uint8_t *header_data;
|
||||||
} MOVStreamContext;
|
} MOVStreamContext;
|
||||||
|
|
||||||
typedef struct MOVContext {
|
typedef struct MOVContext {
|
||||||
int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
|
int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
|
||||||
AVFormatContext *fc;
|
AVFormatContext *fc;
|
||||||
long time_scale;
|
int time_scale;
|
||||||
|
int duration; /* duration of the longest track */
|
||||||
int found_moov; /* when both 'moov' and 'mdat' sections has been found */
|
int found_moov; /* when both 'moov' and 'mdat' sections has been found */
|
||||||
int found_mdat; /* we suppose we have enough data to read the file */
|
int found_mdat; /* we suppose we have enough data to read the file */
|
||||||
int64_t mdat_size;
|
int64_t mdat_size;
|
||||||
@ -183,7 +234,7 @@ typedef struct MOVContext {
|
|||||||
MOVStreamContext *streams[MAX_STREAMS];
|
MOVStreamContext *streams[MAX_STREAMS];
|
||||||
|
|
||||||
int64_t next_chunk_offset;
|
int64_t next_chunk_offset;
|
||||||
int partial; /* != 0 : there is still to read in the current chunk (=id of the stream + 1) */
|
MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */
|
||||||
} MOVContext;
|
} MOVContext;
|
||||||
|
|
||||||
|
|
||||||
@ -209,6 +260,7 @@ typedef struct MOVParseTableEntry {
|
|||||||
uint32_t type;
|
uint32_t type;
|
||||||
mov_parse_function func;
|
mov_parse_function func;
|
||||||
} MOVParseTableEntry;
|
} MOVParseTableEntry;
|
||||||
|
static const MOVParseTableEntry mov_default_parse_table[];
|
||||||
|
|
||||||
static int parse_leaf(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
static int parse_leaf(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
||||||
{
|
{
|
||||||
@ -239,7 +291,7 @@ static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *p
|
|||||||
|
|
||||||
if(atom_size < 0)
|
if(atom_size < 0)
|
||||||
atom_size = 0x0FFFFFFFFFFFFFFF;
|
atom_size = 0x0FFFFFFFFFFFFFFF;
|
||||||
while((total_size < atom_size) && !url_feof(pb) && !err) {
|
while(((total_size + 8) < atom_size) && !url_feof(pb) && !err) {
|
||||||
size=atom_size;
|
size=atom_size;
|
||||||
type=0L;
|
type=0L;
|
||||||
if(atom_size >= 8) {
|
if(atom_size >= 8) {
|
||||||
@ -248,18 +300,21 @@ static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *p
|
|||||||
}
|
}
|
||||||
total_size += 8;
|
total_size += 8;
|
||||||
offset += 8;
|
offset += 8;
|
||||||
// printf("type: %08lx sz: %08lx", type, size);
|
//printf("type: %08x %.4s sz: %Lx %Lx %Lx\n", type, (char*)&type, size, atom_size, total_size);
|
||||||
if(size == 1) { /* 64 bit extended size */
|
if(size == 1) { /* 64 bit extended size */
|
||||||
size = get_be64(pb);
|
size = get_be64(pb) - 8;
|
||||||
offset+=8;
|
offset+=8;
|
||||||
total_size+=8;
|
total_size+=8;
|
||||||
size-=8;
|
|
||||||
}
|
}
|
||||||
if(size == 0)
|
if(size == 0) {
|
||||||
size = atom_size - total_size;
|
size = atom_size - total_size;
|
||||||
size-=8;
|
if (size <= 8)
|
||||||
for(i=0; parse_table[i].type != 0L && parse_table[i].type != type; i++);
|
break;
|
||||||
|
}
|
||||||
|
for (i=0; parse_table[i].type != 0L && parse_table[i].type != type; i++)
|
||||||
|
/* empty */;
|
||||||
|
|
||||||
|
size -= 8;
|
||||||
// printf(" i=%ld\n", i);
|
// printf(" i=%ld\n", i);
|
||||||
if (parse_table[i].type == 0) { /* skip leaf atoms data */
|
if (parse_table[i].type == 0) { /* skip leaf atoms data */
|
||||||
// url_seek(pb, atom_offset+atom_size, SEEK_SET);
|
// url_seek(pb, atom_offset+atom_size, SEEK_SET);
|
||||||
@ -274,12 +329,23 @@ static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *p
|
|||||||
total_size+=size;
|
total_size+=size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!err && total_size < atom_size && atom_size < 0x7ffff) {
|
||||||
|
printf("RESET %Ld %Ld err:%d\n", atom_size, total_size, err);
|
||||||
|
url_fskip(pb, atom_size - total_size);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug_indent--;
|
debug_indent--;
|
||||||
#endif
|
#endif
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int parse_ctab(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
||||||
|
{
|
||||||
|
url_fskip(pb, atom_size); // for now
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
||||||
{
|
{
|
||||||
MOVContext *c;
|
MOVContext *c;
|
||||||
@ -295,9 +361,9 @@ static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
get_be32(pb); /* modification time */
|
get_be32(pb); /* modification time */
|
||||||
c->time_scale = get_be32(pb); /* time scale */
|
c->time_scale = get_be32(pb); /* time scale */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("time scale = %li\n", c->time_scale);
|
printf("time scale = %i\n", c->time_scale);
|
||||||
#endif
|
#endif
|
||||||
get_be32(pb); /* duration */
|
c->duration = get_be32(pb); /* duration */
|
||||||
get_be32(pb); /* preferred scale */
|
get_be32(pb); /* preferred scale */
|
||||||
|
|
||||||
get_be16(pb); /* preferred volume */
|
get_be16(pb); /* preferred volume */
|
||||||
@ -398,9 +464,11 @@ static int parse_trak(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
st = av_new_stream(c->fc, c->fc->nb_streams);
|
st = av_new_stream(c->fc, c->fc->nb_streams);
|
||||||
if (!st) return -2;
|
if (!st) return -2;
|
||||||
sc = av_malloc(sizeof(MOVStreamContext));
|
sc = av_malloc(sizeof(MOVStreamContext));
|
||||||
|
memset(sc, 0, sizeof(MOVStreamContext));
|
||||||
sc->sample_to_chunk_index = -1;
|
sc->sample_to_chunk_index = -1;
|
||||||
st->priv_data = sc;
|
st->priv_data = sc;
|
||||||
st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
|
st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
|
||||||
|
st->time_length = (c->duration * 1000) / c->time_scale; // time in miliseconds
|
||||||
c->streams[c->fc->nb_streams-1] = sc;
|
c->streams[c->fc->nb_streams-1] = sc;
|
||||||
return parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
|
return parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
|
||||||
}
|
}
|
||||||
@ -431,7 +499,7 @@ static int parse_tkhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
get_be32(pb); /* modification time */
|
get_be32(pb); /* modification time */
|
||||||
st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
|
st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
|
||||||
get_be32(pb); /* reserved */
|
get_be32(pb); /* reserved */
|
||||||
get_be32(pb); /* duration */
|
st->time_length = get_be32(pb) * 1000 / c->time_scale; /* duration */
|
||||||
get_be32(pb); /* reserved */
|
get_be32(pb); /* reserved */
|
||||||
get_be32(pb); /* reserved */
|
get_be32(pb); /* reserved */
|
||||||
|
|
||||||
@ -471,7 +539,7 @@ static int parse_mdhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
c->streams[c->total_streams]->time_scale = get_be32(pb);
|
c->streams[c->total_streams]->time_scale = get_be32(pb);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("track[%i].time_scale = %li\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
|
printf("track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
|
||||||
#endif
|
#endif
|
||||||
get_be32(pb); /* duration */
|
get_be32(pb); /* duration */
|
||||||
|
|
||||||
@ -590,12 +658,10 @@ static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
|
|
||||||
static int mp4_read_descr_len(ByteIOContext *pb)
|
static int mp4_read_descr_len(ByteIOContext *pb)
|
||||||
{
|
{
|
||||||
int c, len, count;
|
int len = 0;
|
||||||
|
int count = 0;
|
||||||
len = 0;
|
|
||||||
count = 0;
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
c = get_byte(pb);
|
int c = get_byte(pb);
|
||||||
len = (len << 7) | (c & 0x7f);
|
len = (len << 7) | (c & 0x7f);
|
||||||
if ((c & 0x80) == 0)
|
if ((c & 0x80) == 0)
|
||||||
break;
|
break;
|
||||||
@ -616,10 +682,65 @@ static int mp4_read_descr(ByteIOContext *pb, int *tag)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline unsigned int get_be24(ByteIOContext *s)
|
||||||
|
{
|
||||||
|
unsigned int val;
|
||||||
|
val = get_byte(s) << 16;
|
||||||
|
val |= get_byte(s) << 8;
|
||||||
|
val |= get_byte(s);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_esds(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
||||||
|
{
|
||||||
|
|
||||||
|
int64_t start_pos = url_ftell(pb);
|
||||||
|
MOVContext *c = (MOVContext *)param;
|
||||||
|
AVStream *st = c->fc->streams[c->fc->nb_streams-1];
|
||||||
|
MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
|
||||||
|
int tag, len;
|
||||||
|
#ifdef DEBUG
|
||||||
|
print_atom("esds", atom_type, atom_offset, atom_size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Well, broken but suffisant for some MP4 streams */
|
||||||
|
get_be32(pb); /* version + flags */
|
||||||
|
len = mp4_read_descr(pb, &tag);
|
||||||
|
if (tag == MP4ESDescrTag) {
|
||||||
|
get_be16(pb); /* ID */
|
||||||
|
get_byte(pb); /* priority */
|
||||||
|
} else
|
||||||
|
get_be16(pb); /* ID */
|
||||||
|
|
||||||
|
len = mp4_read_descr(pb, &tag);
|
||||||
|
if (tag == MP4DecConfigDescrTag) {
|
||||||
|
sc->esds.object_type_id = get_byte(pb);
|
||||||
|
sc->esds.stream_type = get_be24(pb);
|
||||||
|
sc->esds.max_bitrate = get_be32(pb);
|
||||||
|
sc->esds.avg_bitrate = get_be32(pb);
|
||||||
|
|
||||||
|
len = mp4_read_descr(pb, &tag);
|
||||||
|
printf("LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate);
|
||||||
|
if (tag == MP4DecSpecificDescrTag) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("Specific MPEG4 header len=%d\n", len);
|
||||||
|
#endif
|
||||||
|
sc->header_data = av_mallocz(len);
|
||||||
|
if (sc->header_data) {
|
||||||
|
get_buffer(pb, sc->header_data, len);
|
||||||
|
sc->header_len = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* in any case, skip garbage */
|
||||||
|
url_fskip(pb, (atom_size - 8) - ((url_ftell(pb) - start_pos)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, uint32_t atom_type, int64_t atom_offset, int64_t atom_size, void *param)
|
||||||
{
|
{
|
||||||
MOVContext *c;
|
MOVContext *c;
|
||||||
int entries, size, samp_sz, frames_per_sample, id;
|
int entries, size, frames_per_sample, id;
|
||||||
uint32_t format;
|
uint32_t format;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
MOVStreamContext *sc;
|
MOVStreamContext *sc;
|
||||||
@ -660,8 +781,8 @@ static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
(format >> 24) & 0xff,
|
(format >> 24) & 0xff,
|
||||||
st->codec.codec_type);
|
st->codec.codec_type);
|
||||||
#endif
|
#endif
|
||||||
if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
|
|
||||||
st->codec.codec_tag = format;
|
st->codec.codec_tag = format;
|
||||||
|
if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
|
||||||
st->codec.codec_id = codec_get_id(mov_video_tags, format);
|
st->codec.codec_id = codec_get_id(mov_video_tags, format);
|
||||||
get_be16(pb); /* version */
|
get_be16(pb); /* version */
|
||||||
get_be16(pb); /* revision level */
|
get_be16(pb); /* revision level */
|
||||||
@ -681,19 +802,20 @@ static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
get_be32(pb); /* horiz resolution */
|
get_be32(pb); /* horiz resolution */
|
||||||
get_be32(pb); /* vert resolution */
|
get_be32(pb); /* vert resolution */
|
||||||
get_be32(pb); /* data size, always 0 */
|
get_be32(pb); /* data size, always 0 */
|
||||||
frames_per_sample = get_be16(pb); /* frame per samples */
|
frames_per_sample = get_be16(pb); /* frames per samples */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("frames/samples = %d\n", frames_per_sample);
|
printf("frames/samples = %d\n", frames_per_sample);
|
||||||
#endif
|
#endif
|
||||||
url_fskip(pb, 32); /* codec name */
|
get_buffer(pb, st->codec.codec_name, 32); /* codec name */
|
||||||
|
|
||||||
get_be16(pb); /* depth */
|
st->codec.bits_per_sample = get_be16(pb); /* depth */
|
||||||
get_be16(pb); /* colortable id */
|
st->codec.color_table_id = get_be16(pb); /* colortable id */
|
||||||
|
|
||||||
st->codec.frame_rate = 25;
|
st->codec.frame_rate = 25;
|
||||||
st->codec.frame_rate_base = 1;
|
st->codec.frame_rate_base = 1;
|
||||||
|
|
||||||
size -= (16+8*4+2+32+2*2);
|
size -= (16+8*4+2+32+2*2);
|
||||||
|
#if 0
|
||||||
while (size >= 8) {
|
while (size >= 8) {
|
||||||
int atom_size, atom_type;
|
int atom_size, atom_type;
|
||||||
int64_t start_pos;
|
int64_t start_pos;
|
||||||
@ -701,6 +823,7 @@ static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
atom_size = get_be32(pb);
|
atom_size = get_be32(pb);
|
||||||
atom_type = get_le32(pb);
|
atom_type = get_le32(pb);
|
||||||
size -= 8;
|
size -= 8;
|
||||||
|
printf("NEWSIZE %d\n", size);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("VIDEO: atom_type=%c%c%c%c atom_size=%d size_left=%d\n",
|
printf("VIDEO: atom_type=%c%c%c%c atom_size=%d size_left=%d\n",
|
||||||
(atom_type >> 0) & 0xff,
|
(atom_type >> 0) & 0xff,
|
||||||
@ -750,47 +873,62 @@ static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
|
printf("ATOMENEWSIZE %d %d\n", atom_size, url_ftell(pb) - start_pos);
|
||||||
|
if (atom_size > 8) {
|
||||||
url_fskip(pb, (atom_size - 8) -
|
url_fskip(pb, (atom_size - 8) -
|
||||||
((url_ftell(pb) - start_pos)));
|
((url_ftell(pb) - start_pos)));
|
||||||
size -= atom_size - 8;
|
size -= atom_size - 8;
|
||||||
|
printf("NEWSIZE %d\n", size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
/* unknown extension */
|
/* unknown extension */
|
||||||
url_fskip(pb, size);
|
url_fskip(pb, size);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
parse_default(mov_default_parse_table, pb, 0L, 0LL, size, param);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
st->codec.codec_tag = format;
|
|
||||||
|
|
||||||
get_be16(pb); /* version */
|
get_be16(pb); /* version */
|
||||||
get_be16(pb); /* revision level */
|
get_be16(pb); /* revision level */
|
||||||
get_be32(pb); /* vendor */
|
get_be32(pb); /* vendor */
|
||||||
|
|
||||||
st->codec.channels = get_be16(pb);/* channel count */
|
st->codec.channels = get_be16(pb);/* channel count */
|
||||||
samp_sz = get_be16(pb); /* sample size */
|
st->codec.bits_per_sample = get_be16(pb); /* sample size */
|
||||||
#ifdef DEBUG
|
|
||||||
if(samp_sz != 16)
|
|
||||||
puts("!!! stsd: audio sample size is not 16 bit !");
|
|
||||||
#endif
|
|
||||||
st->codec.codec_id = codec_get_id(mov_audio_tags, format);
|
st->codec.codec_id = codec_get_id(mov_audio_tags, format);
|
||||||
/* handle specific s8 codec */
|
/* handle specific s8 codec */
|
||||||
if (st->codec.codec_id == CODEC_ID_PCM_S16BE && samp_sz == 8)
|
|
||||||
st->codec.codec_id = CODEC_ID_PCM_S8;
|
|
||||||
|
|
||||||
get_be16(pb); /* compression id = 0*/
|
get_be16(pb); /* compression id = 0*/
|
||||||
get_be16(pb); /* packet size = 0 */
|
get_be16(pb); /* packet size = 0 */
|
||||||
|
|
||||||
st->codec.sample_rate = ((get_be32(pb) >> 16));
|
st->codec.sample_rate = ((get_be32(pb) >> 16));
|
||||||
st->codec.bit_rate = 0;
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
get_be16(pb); get_be16(pb); /* */
|
if (st->codec.codec_id == CODEC_ID_PCM_S16BE) {
|
||||||
get_be16(pb); /* */
|
if (st->codec.bits_per_sample == 8)
|
||||||
get_be16(pb); /* */
|
st->codec.codec_id = CODEC_ID_PCM_S8;
|
||||||
get_be16(pb); /* */
|
st->codec.bit_rate = st->codec.sample_rate;
|
||||||
get_be16(pb); /* */
|
}
|
||||||
|
get_be32(pb); /* samples per packet */
|
||||||
|
get_be32(pb); /* bytes per packet */
|
||||||
|
get_be32(pb); /* bytes per frame */
|
||||||
|
get_be32(pb); /* bytes per sample */
|
||||||
|
|
||||||
|
//if (size > 16) url_fskip(pb, size-(16+20));
|
||||||
|
#if 1
|
||||||
|
if (size >= 44 + 8) {
|
||||||
|
int fcc;
|
||||||
|
st->codec.extradata_size = get_be32(pb) - 8;
|
||||||
|
fcc = get_le32(pb); // evaw
|
||||||
|
//printf("%x %.4s %d\n", fcc, (char*)&fcc, st->codec.extradata_size);
|
||||||
|
st->codec.extradata = av_mallocz(st->codec.extradata_size);
|
||||||
|
get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
|
||||||
|
url_fskip(pb, size-(16 + 20 + 16 + 8 + st->codec.extradata_size));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
url_fskip(pb, size-(16 + 20 + 16));
|
||||||
|
#else
|
||||||
|
parse_default(mov_default_parse_table, pb, 0L, 0LL, size - (16 + 20 + 16 + 8), param);
|
||||||
#endif
|
#endif
|
||||||
if(size > 16)
|
|
||||||
url_fskip(pb, size-(16+20));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -1013,7 +1151,6 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
|
|||||||
{ MKTAG( 'd', 'i', 'n', 'f' ), parse_default },
|
{ MKTAG( 'd', 'i', 'n', 'f' ), parse_default },
|
||||||
{ MKTAG( 'd', 'r', 'e', 'f' ), parse_leaf },
|
{ MKTAG( 'd', 'r', 'e', 'f' ), parse_leaf },
|
||||||
{ MKTAG( 's', 't', 'd', 'p' ), parse_default },
|
{ MKTAG( 's', 't', 'd', 'p' ), parse_default },
|
||||||
{ MKTAG( 'e', 's', 'd', 's' ), parse_default },
|
|
||||||
{ MKTAG( 'e', 'd', 't', 's' ), parse_default },
|
{ MKTAG( 'e', 'd', 't', 's' ), parse_default },
|
||||||
{ MKTAG( 'e', 'l', 's', 't' ), parse_leaf },
|
{ MKTAG( 'e', 'l', 's', 't' ), parse_leaf },
|
||||||
{ MKTAG( 'u', 'u', 'i', 'd' ), parse_default },
|
{ MKTAG( 'u', 'u', 'i', 'd' ), parse_default },
|
||||||
@ -1067,6 +1204,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
|
|||||||
{ MKTAG( 's', 's', 'r', 'c' ), parse_leaf },
|
{ MKTAG( 's', 's', 'r', 'c' ), parse_leaf },
|
||||||
{ MKTAG( 't', 'c', 'm', 'd' ), parse_leaf },
|
{ MKTAG( 't', 'c', 'm', 'd' ), parse_leaf },
|
||||||
{ MKTAG( 'w', 'i', 'd', 'e' ), parse_wide }, /* place holder */
|
{ MKTAG( 'w', 'i', 'd', 'e' ), parse_wide }, /* place holder */
|
||||||
|
{ MKTAG( 'c', 't', 'a', 'b' ), parse_ctab },
|
||||||
|
{ MKTAG( 'e', 's', 'd', 's' ), parse_esds },
|
||||||
#ifdef CONFIG_ZLIB
|
#ifdef CONFIG_ZLIB
|
||||||
{ MKTAG( 'c', 'm', 'o', 'v' ), parse_cmov },
|
{ MKTAG( 'c', 'm', 'o', 'v' ), parse_cmov },
|
||||||
#else
|
#else
|
||||||
@ -1080,17 +1219,18 @@ static void mov_free_stream_context(MOVStreamContext *sc)
|
|||||||
if(sc) {
|
if(sc) {
|
||||||
av_free(sc->chunk_offsets);
|
av_free(sc->chunk_offsets);
|
||||||
av_free(sc->sample_to_chunk);
|
av_free(sc->sample_to_chunk);
|
||||||
|
av_free(sc->sample_sizes);
|
||||||
av_free(sc->header_data);
|
av_free(sc->header_data);
|
||||||
av_free(sc);
|
av_free(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t to_tag(uint8_t *buf)
|
static inline uint32_t to_tag(uint8_t *buf)
|
||||||
{
|
{
|
||||||
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t to_be32(uint8_t *buf)
|
static inline uint32_t to_be32(uint8_t *buf)
|
||||||
{
|
{
|
||||||
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||||
}
|
}
|
||||||
@ -1206,7 +1346,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
MOVStreamContext *sc;
|
MOVStreamContext *sc;
|
||||||
int64_t offset = 0x0FFFFFFFFFFFFFFF;
|
int64_t offset = 0x0FFFFFFFFFFFFFFF;
|
||||||
int i;
|
int i;
|
||||||
int st_id = 0, size;
|
int size;
|
||||||
size = 0x0FFFFFFF;
|
size = 0x0FFFFFFF;
|
||||||
|
|
||||||
#ifdef MOV_SPLIT_CHUNKS
|
#ifdef MOV_SPLIT_CHUNKS
|
||||||
@ -1214,15 +1354,16 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
|
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
st_id = mov->partial - 1;
|
sc = mov->partial;
|
||||||
idx = mov->streams[st_id]->sample_to_chunk_index;
|
idx = sc->sample_to_chunk_index;
|
||||||
|
|
||||||
if (idx < 0) return 0;
|
if (idx < 0) return 0;
|
||||||
size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
|
size = sc->sample_sizes[sc->current_sample];
|
||||||
|
|
||||||
mov->streams[st_id]->current_sample++;
|
sc->current_sample++;
|
||||||
mov->streams[st_id]->left_in_chunk--;
|
sc->left_in_chunk--;
|
||||||
|
|
||||||
if(mov->streams[st_id]->left_in_chunk <= 0)
|
if (sc->left_in_chunk <= 0)
|
||||||
mov->partial = 0;
|
mov->partial = 0;
|
||||||
offset = mov->next_chunk_offset;
|
offset = mov->next_chunk_offset;
|
||||||
/* extract the sample */
|
/* extract the sample */
|
||||||
@ -1232,24 +1373,29 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
again:
|
again:
|
||||||
|
sc = 0;
|
||||||
for(i=0; i<mov->total_streams; i++) {
|
for(i=0; i<mov->total_streams; i++) {
|
||||||
if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
|
MOVStreamContext *msc = mov->streams[i];
|
||||||
&& (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) {
|
//printf("MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb));
|
||||||
st_id = i;
|
if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0
|
||||||
offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];
|
&& (msc->chunk_offsets[msc->next_chunk] < offset)) {
|
||||||
|
sc = msc;
|
||||||
|
offset = msc->chunk_offsets[msc->next_chunk];
|
||||||
|
//printf("SELETED %Ld i:%d\n", offset, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mov->streams[st_id]->next_chunk++;
|
if (!sc || offset==0x0FFFFFFFFFFFFFFF)
|
||||||
if(offset==0x0FFFFFFFFFFFFFFF)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
sc->next_chunk++;
|
||||||
|
|
||||||
if(mov->next_chunk_offset < offset) { /* some meta data */
|
if(mov->next_chunk_offset < offset) { /* some meta data */
|
||||||
url_fskip(&s->pb, (offset - mov->next_chunk_offset));
|
url_fskip(&s->pb, (offset - mov->next_chunk_offset));
|
||||||
mov->next_chunk_offset = offset;
|
mov->next_chunk_offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
|
//printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
|
||||||
if(!mov->streams[st_id]->is_ff_stream) {
|
if(!sc->is_ff_stream) {
|
||||||
url_fskip(&s->pb, (offset - mov->next_chunk_offset));
|
url_fskip(&s->pb, (offset - mov->next_chunk_offset));
|
||||||
mov->next_chunk_offset = offset;
|
mov->next_chunk_offset = offset;
|
||||||
offset = 0x0FFFFFFFFFFFFFFF;
|
offset = 0x0FFFFFFFFFFFFFFF;
|
||||||
@ -1259,28 +1405,27 @@ again:
|
|||||||
/* now get the chunk size... */
|
/* now get the chunk size... */
|
||||||
|
|
||||||
for(i=0; i<mov->total_streams; i++) {
|
for(i=0; i<mov->total_streams; i++) {
|
||||||
if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
|
MOVStreamContext *msc = mov->streams[i];
|
||||||
&& ((mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset) < size)) {
|
if ((msc->next_chunk < msc->chunk_count)
|
||||||
size = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset;
|
&& ((msc->chunk_offsets[msc->next_chunk] - offset) < size))
|
||||||
}
|
size = msc->chunk_offsets[msc->next_chunk] - offset;
|
||||||
}
|
}
|
||||||
#ifdef MOV_SPLIT_CHUNKS
|
#ifdef MOV_SPLIT_CHUNKS
|
||||||
/* split chunks into samples */
|
/* split chunks into samples */
|
||||||
if(mov->streams[st_id]->sample_size == 0) {
|
if (sc->sample_size == 0) {
|
||||||
int idx;
|
int idx = sc->sample_to_chunk_index;
|
||||||
idx = mov->streams[st_id]->sample_to_chunk_index;
|
if ((idx + 1 < sc->sample_to_chunk_sz)
|
||||||
if ((idx + 1 < mov->streams[st_id]->sample_to_chunk_sz)
|
&& (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first))
|
||||||
&& (mov->streams[st_id]->next_chunk >= mov->streams[st_id]->sample_to_chunk[idx + 1].first))
|
|
||||||
idx++;
|
idx++;
|
||||||
mov->streams[st_id]->sample_to_chunk_index = idx;
|
sc->sample_to_chunk_index = idx;
|
||||||
if(idx >= 0 && mov->streams[st_id]->sample_to_chunk[idx].count != 1) {
|
if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) {
|
||||||
mov->partial = st_id+1;
|
mov->partial = sc;
|
||||||
/* we'll have to get those samples before next chunk */
|
/* we'll have to get those samples before next chunk */
|
||||||
mov->streams[st_id]->left_in_chunk = (mov->streams[st_id]->sample_to_chunk[idx].count) - 1;
|
sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1;
|
||||||
size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
|
size = sc->sample_sizes[sc->current_sample];
|
||||||
}
|
}
|
||||||
|
|
||||||
mov->streams[st_id]->current_sample++;
|
sc->current_sample++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1293,7 +1438,8 @@ readchunk:
|
|||||||
if(size == 0)
|
if(size == 0)
|
||||||
return -1;
|
return -1;
|
||||||
url_fseek(&s->pb, offset, SEEK_SET);
|
url_fseek(&s->pb, offset, SEEK_SET);
|
||||||
sc = mov->streams[st_id];
|
|
||||||
|
//printf("READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb));
|
||||||
if (sc->header_len > 0) {
|
if (sc->header_len > 0) {
|
||||||
av_new_packet(pkt, size + sc->header_len);
|
av_new_packet(pkt, size + sc->header_len);
|
||||||
memcpy(pkt->data, sc->header_data, sc->header_len);
|
memcpy(pkt->data, sc->header_data, sc->header_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user