Merge remote-tracking branch 'cigaes/master'

* cigaes/master:
  lavc/mjpegenc: use proper error codes.
  lavc/mjpegenc: check av_frame_alloc() failure.
  lavc/libopenjpegenc: check av_frame_alloc() failure.
  lavc/diracdec: check av_frame_alloc() failure.
  lavc/utils: check av_frame_alloc() failure.
  ffprobe: check av_frame_alloc() failure.
  lavc/ffwavesynth: fix dependency sizeof(AVFrame).

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-12-30 13:29:47 +01:00
commit 905bac2cd3
6 changed files with 26 additions and 11 deletions

View File

@ -1887,6 +1887,10 @@ static int read_interval_packets(WriterContext *w, AVFormatContext *fmt_ctx,
} }
frame = av_frame_alloc(); frame = av_frame_alloc();
if (!frame) {
ret = AVERROR(ENOMEM);
goto end;
}
while (!av_read_frame(fmt_ctx, &pkt)) { while (!av_read_frame(fmt_ctx, &pkt)) {
if (selected_streams[pkt.stream_index]) { if (selected_streams[pkt.stream_index]) {
AVRational tb = fmt_ctx->streams[pkt.stream_index]->time_base; AVRational tb = fmt_ctx->streams[pkt.stream_index]->time_base;

View File

@ -406,8 +406,14 @@ static av_cold int dirac_decode_init(AVCodecContext *avctx)
ff_dsputil_init(&s->dsp, avctx); ff_dsputil_init(&s->dsp, avctx);
ff_diracdsp_init(&s->diracdsp); ff_diracdsp_init(&s->diracdsp);
for (i = 0; i < MAX_FRAMES; i++) for (i = 0; i < MAX_FRAMES; i++) {
s->all_frames[i].avframe = av_frame_alloc(); s->all_frames[i].avframe = av_frame_alloc();
if (!s->all_frames[i].avframe) {
while (i > 0)
av_frame_free(&s->all_frames[--i].avframe);
return AVERROR(ENOMEM);
}
}
return 0; return 0;
} }

View File

@ -93,7 +93,6 @@ struct wavesynth_context {
int64_t cur_ts; int64_t cur_ts;
int64_t next_ts; int64_t next_ts;
int32_t *sin; int32_t *sin;
AVFrame frame;
struct ws_interval *inter; struct ws_interval *inter;
uint32_t dither_state; uint32_t dither_state;
uint32_t pink_state; uint32_t pink_state;
@ -341,8 +340,6 @@ static av_cold int wavesynth_init(AVCodecContext *avc)
ws->pink_need += ws->inter[i].type == WS_NOISE; ws->pink_need += ws->inter[i].type == WS_NOISE;
ws->pink_state = MKTAG('P','I','N','K'); ws->pink_state = MKTAG('P','I','N','K');
ws->pink_pos = PINK_UNIT; ws->pink_pos = PINK_UNIT;
avcodec_get_frame_defaults(&ws->frame);
avc->coded_frame = &ws->frame;
wavesynth_seek(ws, 0); wavesynth_seek(ws, 0);
avc->sample_fmt = AV_SAMPLE_FMT_S16; avc->sample_fmt = AV_SAMPLE_FMT_S16;
return 0; return 0;
@ -428,6 +425,7 @@ static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame,
AVPacket *packet) AVPacket *packet)
{ {
struct wavesynth_context *ws = avc->priv_data; struct wavesynth_context *ws = avc->priv_data;
AVFrame *frame = rframe;
int64_t ts; int64_t ts;
int duration; int duration;
int s, c, r; int s, c, r;
@ -443,11 +441,11 @@ static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame,
duration = AV_RL32(packet->data + 8); duration = AV_RL32(packet->data + 8);
if (duration <= 0) if (duration <= 0)
return AVERROR(EINVAL); return AVERROR(EINVAL);
ws->frame.nb_samples = duration; frame->nb_samples = duration;
r = ff_get_buffer(avc, &ws->frame, 0); r = ff_get_buffer(avc, frame, 0);
if (r < 0) if (r < 0)
return r; return r;
pcm = (int16_t *)ws->frame.data[0]; pcm = (int16_t *)frame->data[0];
for (s = 0; s < duration; s++, ts++) { for (s = 0; s < duration; s++, ts++) {
memset(channels, 0, avc->channels * sizeof(*channels)); memset(channels, 0, avc->channels * sizeof(*channels));
if (ts >= ws->next_ts) if (ts >= ws->next_ts)
@ -458,7 +456,6 @@ static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame,
} }
ws->cur_ts += duration; ws->cur_ts += duration;
*rgot_frame = 1; *rgot_frame = 1;
*(AVFrame *)rframe = ws->frame;
return packet->size; return packet->size;
} }

View File

@ -502,6 +502,8 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
case AV_PIX_FMT_GBRP14: case AV_PIX_FMT_GBRP14:
case AV_PIX_FMT_GBRP16: case AV_PIX_FMT_GBRP16:
gbrframe = av_frame_alloc(); gbrframe = av_frame_alloc();
if (!gbrframe)
return AVERROR(ENOMEM);
av_frame_ref(gbrframe, frame); av_frame_ref(gbrframe, frame);
gbrframe->data[0] = frame->data[2]; // swap to be rgb gbrframe->data[0] = frame->data[2]; // swap to be rgb
gbrframe->data[1] = frame->data[0]; gbrframe->data[1] = frame->data[0];

View File

@ -48,12 +48,12 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
if (s->width > 65500 || s->height > 65500) { if (s->width > 65500 || s->height > 65500) {
av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n"); av_log(s, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
return -1; return AVERROR(EINVAL);
} }
m = av_malloc(sizeof(MJpegContext)); m = av_malloc(sizeof(MJpegContext));
if (!m) if (!m)
return -1; return AVERROR(ENOMEM);
s->min_qcoeff=-1023; s->min_qcoeff=-1023;
s->max_qcoeff= 1023; s->max_qcoeff= 1023;
@ -545,9 +545,11 @@ static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
//CODEC_FLAG_EMU_EDGE have to be cleared //CODEC_FLAG_EMU_EDGE have to be cleared
if(s->avctx->flags & CODEC_FLAG_EMU_EDGE) if(s->avctx->flags & CODEC_FLAG_EMU_EDGE)
return -1; return AVERROR(EINVAL);
pic = av_frame_alloc(); pic = av_frame_alloc();
if (!pic)
return AVERROR(ENOMEM);
av_frame_ref(pic, pic_arg); av_frame_ref(pic, pic_arg);
//picture should be flipped upside-down //picture should be flipped upside-down
for(i=0; i < 3; i++) { for(i=0; i < 3; i++) {

View File

@ -1721,6 +1721,8 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
if (samples) { if (samples) {
frame = av_frame_alloc(); frame = av_frame_alloc();
if (!frame)
return AVERROR(ENOMEM);
if (avctx->frame_size) { if (avctx->frame_size) {
frame->nb_samples = avctx->frame_size; frame->nb_samples = avctx->frame_size;
@ -2158,6 +2160,8 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
AVFrame *frame = av_frame_alloc(); AVFrame *frame = av_frame_alloc();
int ret, got_frame = 0; int ret, got_frame = 0;
if (!frame)
return AVERROR(ENOMEM);
if (avctx->get_buffer != avcodec_default_get_buffer) { if (avctx->get_buffer != avcodec_default_get_buffer) {
av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with" av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
"avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n"); "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");