diff movenc.c @ 2771:d52c718e83f9 libavformat

Use dynamically allocated ByteIOContext in AVFormatContext patch by: Bj«Órn Axelsson, bjorn d axelsson a intinor d se thread: [PATCH] Remove static ByteIOContexts, 06 nov 2007
author andoma
date Wed, 21 Nov 2007 07:41:00 +0000
parents 09eb62fa2a0e
children ef333b18b760
line wrap: on
line diff
--- a/movenc.c	Mon Nov 19 20:28:11 2007 +0000
+++ b/movenc.c	Wed Nov 21 07:41:00 2007 +0000
@@ -442,24 +442,27 @@
     return end + 3;
 }
 
-static void avc_parse_nal_units(uint8_t **buf, int *size)
+static int avc_parse_nal_units(uint8_t **buf, int *size)
 {
-    ByteIOContext pb;
+    ByteIOContext *pb;
     uint8_t *p = *buf;
     uint8_t *end = p + *size;
     uint8_t *nal_start, *nal_end;
+    int ret = url_open_dyn_buf(&pb);
+    if(ret < 0)
+        return ret;
 
-    url_open_dyn_buf(&pb);
     nal_start = avc_find_startcode(p, end);
     while (nal_start < end) {
         while(!*(nal_start++));
         nal_end = avc_find_startcode(nal_start, end);
-        put_be32(&pb, nal_end - nal_start);
-        put_buffer(&pb, nal_start, nal_end - nal_start);
+        put_be32(pb, nal_end - nal_start);
+        put_buffer(pb, nal_start, nal_end - nal_start);
         nal_start = nal_end;
     }
     av_freep(buf);
-    *size = url_close_dyn_buf(&pb, buf);
+    *size = url_close_dyn_buf(pb, buf);
+    return 0;
 }
 
 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track)
@@ -1508,11 +1511,11 @@
 
 static int mov_write_header(AVFormatContext *s)
 {
-    ByteIOContext *pb = &s->pb;
+    ByteIOContext *pb = s->pb;
     MOVContext *mov = s->priv_data;
     int i;
 
-    if (url_is_streamed(&s->pb)) {
+    if (url_is_streamed(s->pb)) {
         av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
         return -1;
     }
@@ -1579,13 +1582,13 @@
 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MOVContext *mov = s->priv_data;
-    ByteIOContext *pb = &s->pb;
+    ByteIOContext *pb = s->pb;
     MOVTrack *trk = &mov->tracks[pkt->stream_index];
     AVCodecContext *enc = trk->enc;
     unsigned int samplesInChunk = 0;
     int size= pkt->size;
 
-    if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
+    if (url_is_streamed(s->pb)) return 0; /* Can't handle that */
     if (!size) return 0; /* Discard 0 sized packets */
 
     if (enc->codec_id == CODEC_ID_AMR_NB) {
@@ -1663,7 +1666,7 @@
 static int mov_write_trailer(AVFormatContext *s)
 {
     MOVContext *mov = s->priv_data;
-    ByteIOContext *pb = &s->pb;
+    ByteIOContext *pb = s->pb;
     int res = 0;
     int i;