[FFmpeg-cvslog] avformat/avisynth simplify packet allocation

Michael Niedermayer git at videolan.org
Fri Jan 10 15:45:14 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Jan  9 18:33:39 2014 +0100| [4cb9c2013662b46e8101d6fdf6c69d41668c8b9a] | committer: Michael Niedermayer

avformat/avisynth simplify packet allocation

Reviewed-by: Stephen Hutchinson <qyot27 at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4cb9c2013662b46e8101d6fdf6c69d41668c8b9a
---

 libavformat/avisynth.c |   38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 99fe34c..b837bd9 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -401,10 +401,10 @@ static void avisynth_next_stream(AVFormatContext *s, AVStream **st,
 {
     AviSynthContext *avs = s->priv_data;
 
-    pkt->stream_index = avs->curr_stream++;
+    avs->curr_stream++;
     avs->curr_stream %= s->nb_streams;
 
-    *st = s->streams[pkt->stream_index];
+    *st = s->streams[avs->curr_stream];
     if ((*st)->discard == AVDISCARD_ALL)
         *discard = 1;
     else
@@ -421,7 +421,7 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
     AVS_VideoFrame *frame;
     unsigned char *dst_p;
     const unsigned char *src_p;
-    int n, i, plane, rowsize, planeheight, pitch, bits, ret;
+    int n, i, plane, rowsize, planeheight, pitch, bits;
     const char *error;
 
     if (avs->curr_frame >= avs->vi->num_frames)
@@ -432,10 +432,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
     if (discard)
         return 0;
 
-    pkt->pts      = n;
-    pkt->dts      = n;
-    pkt->duration = 1;
-
 #ifdef USING_AVISYNTH
     /* Define the bpp values for the new AviSynth 2.6 colorspaces.
      * Since AvxSynth doesn't have these functions, special-case
@@ -460,14 +456,13 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
     if (!pkt->size)
         return AVERROR_UNKNOWN;
 
-    pkt->data = av_malloc(pkt->size);
-    if (!pkt->data)
+    if (av_new_packet(pkt, pkt->size) < 0)
         return AVERROR(ENOMEM);
 
-    if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) {
-        av_packet_unref(pkt);
-        return ret;
-    }
+    pkt->pts      = n;
+    pkt->dts      = n;
+    pkt->duration = 1;
+    pkt->stream_index = avs->curr_stream;
 
     frame = avs_library.avs_get_frame(avs->clip, n);
     error = avs_library.avs_clip_get_error(avs->clip);
@@ -517,7 +512,7 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt,
 {
     AviSynthContext *avs = s->priv_data;
     AVRational fps, samplerate;
-    int samples, ret;
+    int samples;
     int64_t n;
     const char *error;
 
@@ -555,23 +550,18 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt,
     if (discard)
         return 0;
 
-    pkt->pts      = n;
-    pkt->dts      = n;
-    pkt->duration = samples;
-
     pkt->size = avs_bytes_per_channel_sample(avs->vi) *
                 samples * avs->vi->nchannels;
     if (!pkt->size)
         return AVERROR_UNKNOWN;
 
-    pkt->data = av_malloc(pkt->size);
-    if (!pkt->data)
+    if (av_new_packet(pkt, pkt->size) < 0)
         return AVERROR(ENOMEM);
 
-    if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) {
-        av_packet_unref(pkt);
-        return ret;
-    }
+    pkt->pts      = n;
+    pkt->dts      = n;
+    pkt->duration = samples;
+    pkt->stream_index = avs->curr_stream;
 
     avs_library.avs_get_audio(avs->clip, pkt->data, n, samples);
     error = avs_library.avs_clip_get_error(avs->clip);



More information about the ffmpeg-cvslog mailing list