avformat/avisynth simplify packet allocation

Reviewed-by: Stephen Hutchinson <qyot27@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/53/head
Michael Niedermayer 11 years ago
parent 8298b54179
commit 4cb9c20136
  1. 38
      libavformat/avisynth.c

@ -401,10 +401,10 @@ static void avisynth_next_stream(AVFormatContext *s, AVStream **st,
{ {
AviSynthContext *avs = s->priv_data; AviSynthContext *avs = s->priv_data;
pkt->stream_index = avs->curr_stream++; avs->curr_stream++;
avs->curr_stream %= s->nb_streams; avs->curr_stream %= s->nb_streams;
*st = s->streams[pkt->stream_index]; *st = s->streams[avs->curr_stream];
if ((*st)->discard == AVDISCARD_ALL) if ((*st)->discard == AVDISCARD_ALL)
*discard = 1; *discard = 1;
else else
@ -421,7 +421,7 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
AVS_VideoFrame *frame; AVS_VideoFrame *frame;
unsigned char *dst_p; unsigned char *dst_p;
const unsigned char *src_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; const char *error;
if (avs->curr_frame >= avs->vi->num_frames) if (avs->curr_frame >= avs->vi->num_frames)
@ -432,10 +432,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
if (discard) if (discard)
return 0; return 0;
pkt->pts = n;
pkt->dts = n;
pkt->duration = 1;
#ifdef USING_AVISYNTH #ifdef USING_AVISYNTH
/* Define the bpp values for the new AviSynth 2.6 colorspaces. /* Define the bpp values for the new AviSynth 2.6 colorspaces.
* Since AvxSynth doesn't have these functions, special-case * 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) if (!pkt->size)
return AVERROR_UNKNOWN; return AVERROR_UNKNOWN;
pkt->data = av_malloc(pkt->size); if (av_new_packet(pkt, pkt->size) < 0)
if (!pkt->data)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) { pkt->pts = n;
av_packet_unref(pkt); pkt->dts = n;
return ret; pkt->duration = 1;
} pkt->stream_index = avs->curr_stream;
frame = avs_library.avs_get_frame(avs->clip, n); frame = avs_library.avs_get_frame(avs->clip, n);
error = avs_library.avs_clip_get_error(avs->clip); 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; AviSynthContext *avs = s->priv_data;
AVRational fps, samplerate; AVRational fps, samplerate;
int samples, ret; int samples;
int64_t n; int64_t n;
const char *error; const char *error;
@ -555,23 +550,18 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt,
if (discard) if (discard)
return 0; return 0;
pkt->pts = n;
pkt->dts = n;
pkt->duration = samples;
pkt->size = avs_bytes_per_channel_sample(avs->vi) * pkt->size = avs_bytes_per_channel_sample(avs->vi) *
samples * avs->vi->nchannels; samples * avs->vi->nchannels;
if (!pkt->size) if (!pkt->size)
return AVERROR_UNKNOWN; return AVERROR_UNKNOWN;
pkt->data = av_malloc(pkt->size); if (av_new_packet(pkt, pkt->size) < 0)
if (!pkt->data)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) { pkt->pts = n;
av_packet_unref(pkt); pkt->dts = n;
return ret; pkt->duration = samples;
} pkt->stream_index = avs->curr_stream;
avs_library.avs_get_audio(avs->clip, pkt->data, n, samples); avs_library.avs_get_audio(avs->clip, pkt->data, n, samples);
error = avs_library.avs_clip_get_error(avs->clip); error = avs_library.avs_clip_get_error(avs->clip);

Loading…
Cancel
Save