changeset 4329:bd49910ad4a0 libavformat

use st->priv_data to store per stream context
author bcoudurier
date Sat, 31 Jan 2009 11:06:20 +0000
parents fb0fde31327a
children f59a2165d042
files gxfenc.c
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gxfenc.c	Sat Jan 31 10:51:35 2009 +0000
+++ b/gxfenc.c	Sat Jan 31 11:06:20 2009 +0000
@@ -66,7 +66,6 @@
     int sample_rate;
     int flags;
     AVFormatContext *fc;
-    GXFStreamContext streams[48];
 } GXFContext;
 
 typedef struct GXF_Lines {
@@ -320,7 +319,7 @@
     pos = url_ftell(pb);
     put_be16(pb, 0); /* size */
     for (i = 0; i < ctx->fc->nb_streams; ++i)
-        gxf_write_track_description(pb, &ctx->streams[i]);
+        gxf_write_track_description(pb, ctx->fc->streams[i]->priv_data);
     return updateSize(pb, pos);
 }
 
@@ -411,7 +410,7 @@
     ctx->umf_track_offset = pos - ctx->umf_start_offset;
     for (i = 0; i < ctx->fc->nb_streams; ++i) {
         AVStream *st = ctx->fc->streams[i];
-        GXFStreamContext *sc = &ctx->streams[i];
+        GXFStreamContext *sc = st->priv_data;
         int id = 0;
 
         switch (st->codec->codec_id) {
@@ -506,7 +505,7 @@
     pos = url_ftell(pb);
     ctx->umf_media_offset = pos - ctx->umf_start_offset;
     for (i = 0; i < ctx->fc->nb_streams; ++i) {
-        GXFStreamContext *sc = &ctx->streams[i];
+        GXFStreamContext *sc = ctx->fc->streams[i]->priv_data;
         char buffer[88];
         int64_t startpos, curpos;
         int path_size = strlen(ES_NAME_PATTERN);
@@ -598,7 +597,10 @@
     gxf->flags |= 0x00080000; /* material is simple clip */
     for (i = 0; i < s->nb_streams; ++i) {
         AVStream *st = s->streams[i];
-        GXFStreamContext *sc = &gxf->streams[i];
+        GXFStreamContext *sc = av_mallocz(sizeof(*sc));
+        if (!sc)
+            return AVERROR(ENOMEM);
+        st->priv_data = sc;
 
         sc->codec = st->codec;
         sc->index = i;
@@ -691,8 +693,9 @@
     int i;
 
     for (i = 0; i < s->nb_streams; ++i) {
-        if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO)
-            av_fifo_free(&gxf->streams[i].audio_buffer);
+        AVStream *st = s->streams[i];
+        if (st->codec->codec_type == CODEC_TYPE_AUDIO)
+            av_fifo_free(&((GXFStreamContext*)st->priv_data)->audio_buffer);
     }
 
     gxf_write_eos_packet(pb, gxf);
@@ -720,7 +723,7 @@
 
 static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size)
 {
-    GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
+    GXFStreamContext *sc = ctx->fc->streams[pkt->stream_index]->priv_data;
     int64_t dts = av_rescale_rnd(pkt->dts, ctx->sample_rate, sc->codec->time_base.den, AV_ROUND_UP);
 
     put_byte(pb, sc->media_type);
@@ -755,7 +758,7 @@
 
 static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt)
 {
-    GXFStreamContext *sc = &ctx->streams[pkt->stream_index];
+    GXFStreamContext *sc = ctx->fc->streams[pkt->stream_index]->priv_data;
     int64_t pos = url_ftell(pb);
     int padding = 0;
 
@@ -805,7 +808,7 @@
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        GXFStreamContext *sc = &gxf->streams[i];
+        GXFStreamContext *sc = st->priv_data;
         if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
             if (pkt && pkt->stream_index == i) {
                 av_fifo_generic_write(&sc->audio_buffer, pkt->data, pkt->size, NULL);