view isom.h @ 4723:a2390c6a35e6 libavformat

Fix index generation in the way that it was supposed to be used. See the discussion in the ML thread "[PATCH] rmdec.c: merge old/new packet reading code". Over time, this code broke somewhat, e.g. seq was never actually written into (and was thus always 1, therefore the seq condition was always true), whereas it was supposed to be set to the sequence number of the video slice in case the video frame is divided over multiple RM packets (slices). The problem of this is that packets other than those containing the beginning of a video frame would be indexed as well. Secondly, flags&2 is supposed to be true for video keyframes and for these audio packets containing the start of a block. For some codecs (e.g. AAC), that is every single packet, whereas for others (e.g. cook), that is the packet containing the first of a series of scrambled packets that are to be descrambled together. Indexing any of the following would lead to incomplete and thus useless frames. Problem here is that flags would be reset to 2 to indicate that the first packet is ready to be returned, and in addition if no data was left to be returned (which is always true for the first packet), then we wouldn't actually write the index entry anyway. All in all, the idea was good and it probably worked at some point, but that is long ago. This patch should at the very least make it likely for this code to be executed again at the right times, i.e. the way it was originally intended to be used.
author rbultje
date Sun, 15 Mar 2009 20:14:25 +0000
parents 5dd75af88ade
children 1f151bcb0b27
line wrap: on
line source

/*
 * ISO Media common code
 * copyright (c) 2001 Fabrice Bellard
 * copyright (c) 2002 Francois Revol <revol@free.fr>
 * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef AVFORMAT_ISOM_H
#define AVFORMAT_ISOM_H

#include "avio.h"
#include "riff.h"
#include "dv.h"

/* isom.c */
extern const AVCodecTag ff_mp4_obj_type[];
extern const AVCodecTag codec_movvideo_tags[];
extern const AVCodecTag codec_movaudio_tags[];
extern const AVCodecTag ff_codec_movsubtitle_tags[];

int ff_mov_iso639_to_lang(const char *lang, int mp4);
int ff_mov_lang_to_iso639(unsigned code, char *to);

/* the QuickTime file format is quite convoluted...
 * it has lots of index tables, each indexing something in another one...
 * Here we just use what is needed to read the chunks
 */

typedef struct {
    int count;
    int duration;
} MOVStts;

typedef struct {
    int first;
    int count;
    int id;
} MOVStsc;

typedef struct {
    uint32_t type;
    char *path;
} MOVDref;

typedef struct {
    uint32_t type;
    int64_t offset;
    int64_t size; /* total size (excluding the size and type fields) */
} MOVAtom;

struct MOVParseTableEntry;

typedef struct {
    unsigned track_id;
    uint64_t base_data_offset;
    uint64_t moof_offset;
    unsigned stsd_id;
    unsigned duration;
    unsigned size;
    unsigned flags;
} MOVFragment;

typedef struct {
    unsigned track_id;
    unsigned stsd_id;
    unsigned duration;
    unsigned size;
    unsigned flags;
} MOVTrackExt;

typedef struct MOVStreamContext {
    ByteIOContext *pb;
    int ffindex; /* the ffmpeg stream id */
    int next_chunk;
    unsigned int chunk_count;
    int64_t *chunk_offsets;
    unsigned int stts_count;
    MOVStts *stts_data;
    unsigned int ctts_count;
    MOVStts *ctts_data;
    unsigned int stsc_count;
    MOVStsc *stsc_data;
    int ctts_index;
    int ctts_sample;
    unsigned int sample_size;
    unsigned int sample_count;
    int *sample_sizes;
    unsigned int keyframe_count;
    int *keyframes;
    int time_scale;
    int time_rate;
    int time_offset; ///< time offset of the first edit list entry
    int current_sample;
    unsigned int bytes_per_frame;
    unsigned int samples_per_frame;
    int dv_audio_container;
    int pseudo_stream_id; ///< -1 means demux all ids
    int16_t audio_cid; ///< stsd audio compression id
    unsigned drefs_count;
    MOVDref *drefs;
    int dref_id;
    int wrong_dts; ///< dts are wrong due to negative ctts
    int width;  ///< tkhd width
    int height; ///< tkhd height
} MOVStreamContext;

typedef struct MOVContext {
    AVFormatContext *fc;
    int time_scale;
    int64_t duration; /* duration of the longest track */
    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 */
    DVDemuxContext *dv_demux;
    AVFormatContext *dv_fctx;
    int isom; /* 1 if file is ISO Media (mp4/3gp) */
    MOVFragment fragment; ///< current fragment in moof atom
    MOVTrackExt *trex_data;
    unsigned trex_count;
    int itunes_metadata; ///< metadata are itunes style
} MOVContext;

#endif /* AVFORMAT_ISOM_H */