summaryrefslogtreecommitdiff
path: root/libavformat/mov.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-09-20 21:46:35 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-09-20 21:46:35 +0200
commit5864ce13d188260998bbf49a2a774fa9bd445c10 (patch)
tree149cc5b73142b5a876068d33ec1c127c65e6f37f /libavformat/mov.c
parent8c51ea54897c2d8671b38efecc1422ad4ad344f9 (diff)
parent50d1f4437be88a4b7e412e90d71153cae68017cc (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: mp3dec: read Xing frame TOC index mp3dec: use named constants for Xing header flags libx264: add support for nal-hrd, required for Blu-ray streams. mov: support random access point grouping matroskadec: properly support BlockDuration Conflicts: libavcodec/libx264.c libavformat/isom.h libavformat/matroskadec.c libavformat/mov.c libavformat/mp3dec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r--libavformat/mov.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c937174ba3..84565c8696 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1879,6 +1879,46 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
+static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ AVStream *st;
+ MOVStreamContext *sc;
+ unsigned int i, entries;
+ uint8_t version;
+ uint32_t grouping_type;
+
+ if (c->fc->nb_streams < 1)
+ return 0;
+ st = c->fc->streams[c->fc->nb_streams-1];
+ sc = st->priv_data;
+
+ version = avio_r8(pb); /* version */
+ avio_rb24(pb); /* flags */
+ grouping_type = avio_rl32(pb);
+ if (grouping_type != MKTAG( 'r','a','p',' '))
+ return 0; /* only support 'rap ' grouping */
+ if (version == 1)
+ avio_rb32(pb); /* grouping_type_parameter */
+
+ entries = avio_rb32(pb);
+ if (!entries)
+ return 0;
+ if (entries >= UINT_MAX / sizeof(*sc->rap_group))
+ return AVERROR_INVALIDDATA;
+ sc->rap_group = av_malloc(entries * sizeof(*sc->rap_group));
+ if (!sc->rap_group)
+ return AVERROR(ENOMEM);
+
+ for (i = 0; i < entries && !pb->eof_reached; i++) {
+ sc->rap_group[i].count = avio_rb32(pb); /* sample_count */
+ sc->rap_group[i].index = avio_rb32(pb); /* group_description_index */
+ }
+
+ sc->rap_group_count = i;
+
+ return pb->eof_reached ? AVERROR_EOF : 0;
+}
+
static void mov_build_index(MOVContext *mov, AVStream *st)
{
MOVStreamContext *sc = st->priv_data;
@@ -1914,6 +1954,9 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
unsigned int stts_sample = 0;
unsigned int sample_size;
unsigned int distance = 0;
+ unsigned int rap_group_index = 0;
+ unsigned int rap_group_sample = 0;
+ int rap_group_present = sc->rap_group_count && sc->rap_group;
int key_off = (sc->keyframe_count && sc->keyframes[0] > 0) || (sc->stps_data && sc->stps_data[0] > 0);
current_dts -= sc->dts_shift;
@@ -1949,6 +1992,14 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
if (stps_index + 1 < sc->stps_count)
stps_index++;
}
+ if (rap_group_present && rap_group_index < sc->rap_group_count) {
+ if (sc->rap_group[rap_group_index].index > 0)
+ keyframe = 1;
+ if (++rap_group_sample == sc->rap_group[rap_group_index].count) {
+ rap_group_sample = 0;
+ rap_group_index++;
+ }
+ }
if (keyframe)
distance = 0;
sample_size = sc->alt_sample_size > 0 ? sc->alt_sample_size : sc->sample_sizes[current_sample];
@@ -2204,6 +2255,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_freep(&sc->keyframes);
av_freep(&sc->stts_data);
av_freep(&sc->stps_data);
+ av_freep(&sc->rap_group);
return 0;
}
@@ -2704,6 +2756,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('c','m','o','v'), mov_read_cmov },
{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */
{ MKTAG('d','v','c','1'), mov_read_dvc1 },
+{ MKTAG('s','b','g','p'), mov_read_sbgp },
{ 0, NULL }
};