From: Michael Niedermayer Date: Sun, 17 Nov 2013 12:27:46 +0000 (+0100) Subject: Merge remote-tracking branch 'qatar/master' X-Git-Tag: android-x86-6.0-r1~8944 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=be1e6e7503b2f10b0176201418eb97912cee093f;p=android-x86%2Fexternal-ffmpeg.git Merge remote-tracking branch 'qatar/master' * qatar/master: mpegvideo_enc: use the AVFrame API properly. ffv1: use the AVFrame API properly. jpegls: use the AVFrame API properly. huffyuv: use the AVFrame API properly. Conflicts: libavcodec/ffv1.c libavcodec/ffv1.h libavcodec/ffv1dec.c libavcodec/ffv1enc.c Changes to ffv1 are more redone than merged due to them being based on an ancient codebase and a good part of that having being done already as well. Merged-by: Michael Niedermayer --- be1e6e7503b2f10b0176201418eb97912cee093f diff --cc libavcodec/ffv1.c index aefb70d602,9e7ba2ef19..f8556b01f1 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@@ -49,10 -138,9 +49,11 @@@ av_cold int ffv1_common_init(AVCodecCon s->avctx = avctx; s->flags = avctx->flags; - if (!avctx->width || !avctx->height) - return AVERROR_INVALIDDATA; + s->picture.f = av_frame_alloc(); + s->last_picture.f = av_frame_alloc(); + if (!s->picture.f || !s->last_picture.f) + return AVERROR(ENOMEM); + ff_dsputil_init(&s->dsp, avctx); s->width = avctx->width; diff --cc libavcodec/ffv1dec.c index 0add4ffa57,5edc667db4..166bc259f0 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@@ -933,22 -880,21 +933,22 @@@ static int decode_frame(AVCodecContext for (i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; int j; - if (fs->slice_damaged && f->last_picture->data[0]) { + if (fs->slice_damaged && f->last_picture.f->data[0]) { const uint8_t *src[4]; uint8_t *dst[4]; + ff_thread_await_progress(&f->last_picture, INT_MAX, 0); for (j = 0; j < 4; j++) { - int sh = (j==1 || j==2) ? f->chroma_h_shift : 0; - int sv = (j==1 || j==2) ? f->chroma_v_shift : 0; - dst[j] = p->data[j] + p->linesize[j]* - (fs->slice_y>>sv) + (fs->slice_x>>sh); - src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j]* - (fs->slice_y>>sv) + (fs->slice_x>>sh); + int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0; + int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0; + dst[j] = p->data[j] + p->linesize[j] * + (fs->slice_y >> sv) + (fs->slice_x >> sh); - src[j] = f->last_picture->data[j] + - f->last_picture->linesize[j] * ++ src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] * + (fs->slice_y >> sv) + (fs->slice_x >> sh); } av_image_copy(dst, p->linesize, (const uint8_t **)src, - f->last_picture->linesize, - avctx->pix_fmt, fs->slice_width, + f->last_picture.f->linesize, + avctx->pix_fmt, + fs->slice_width, fs->slice_height); } } diff --cc libavcodec/ffv1enc.c index 246a0b551a,179453db5e..2c87d7ae86 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@@ -830,12 -721,18 +830,18 @@@ static av_cold int encode_init(AVCodecC if ((ret = ffv1_allocate_initial_states(s)) < 0) return ret; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + if (!s->transparency) s->plane_count = 2; + if (!s->chroma_planes && s->version > 3) + s->plane_count--; - av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, - &s->chroma_v_shift); - + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); s->picture_number = 0; if (avctx->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2)) { @@@ -1000,15 -879,12 +1006,15 @@@ static int encode_slice(AVCodecContext int height = fs->slice_height; int x = fs->slice_x; int y = fs->slice_y; - AVFrame *const p = f->picture.f; - const AVFrame *const p = f->frame; - const int ps = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR) - ? (f->bits_per_raw_sample > 8) + 1 - : 4; ++ const AVFrame *const p = f->picture.f; + const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step_minus1 + 1; + int ret; + RangeCoder c_bak = fs->c; + + fs->slice_coding_mode = 0; +retry: - if (p->key_frame) + if (c->coded_frame->key_frame) ffv1_clear_slice_state(f, fs); if (f->version > 2) { encode_slice_header(f, fs); @@@ -1126,19 -949,14 +1132,19 @@@ static int encode_frame(AVCodecContext ff_init_range_encoder(c, pkt->data, pkt->size); ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); + av_frame_unref(p); + if ((ret = av_frame_ref(p, pict)) < 0) + return ret; - p->pict_type = AV_PICTURE_TYPE_I; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + if (avctx->gop_size == 0 || f->picture_number % avctx->gop_size == 0) { put_rac(c, &keystate, 1); -- p->key_frame = 1; ++ avctx->coded_frame->key_frame = 1; f->gob_count++; write_header(f); } else { put_rac(c, &keystate, 0); -- p->key_frame = 0; ++ avctx->coded_frame->key_frame = 0; } if (f->ac > 1) { @@@ -1193,14 -1052,19 +1199,21 @@@ f->picture_number++; pkt->size = buf_p - pkt->data; - pkt->flags |= AV_PKT_FLAG_KEY * p->key_frame; + pkt->pts = + pkt->dts = pict->pts; - pkt->flags |= AV_PKT_FLAG_KEY * p->key_frame; ++ pkt->flags |= AV_PKT_FLAG_KEY * avctx->coded_frame->key_frame; *got_packet = 1; return 0; } -static av_cold int ffv1_encode_close(AVCodecContext *avctx) ++static av_cold int encode_close(AVCodecContext *avctx) + { + av_frame_free(&avctx->coded_frame); + ffv1_close(avctx); + return 0; + } + #define OFFSET(x) offsetof(FFV1Context, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@@ -1226,21 -1091,20 +1239,21 @@@ AVCodec ff_ffv1_encoder = .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_FFV1, .priv_data_size = sizeof(FFV1Context), - .init = ffv1_encode_init, - .encode2 = ffv1_encode_frame, - .close = ffv1_encode_close, - .capabilities = CODEC_CAP_SLICE_THREADS, + .init = encode_init, + .encode2 = encode_frame, - .close = ffv1_close, ++ .close = encode_close, + .capabilities = CODEC_CAP_SLICE_THREADS | CODEC_CAP_DELAY, .pix_fmts = (const enum AVPixelFormat[]) { - AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, - AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, - AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9, - AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, - AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, - AV_PIX_FMT_RGB32, - AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, - AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, - AV_PIX_FMT_GRAY16, AV_PIX_FMT_GRAY8, + AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV444P, + AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV411P, + AV_PIX_FMT_YUV410P, AV_PIX_FMT_0RGB32, AV_PIX_FMT_RGB32, AV_PIX_FMT_YUV420P16, + AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, + AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, + AV_PIX_FMT_YUVA444P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA420P16, + AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10, + AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9, + AV_PIX_FMT_GRAY16, AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, + AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_NONE }, diff --cc libavcodec/huffyuvenc.c index c56e281014,ec07abdcc1..3a55d543a9 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@@ -150,13 -149,14 +150,18 @@@ static av_cold int encode_init(AVCodecC avctx->extradata = av_mallocz(1024*30); // 256*3+4 == 772 avctx->stats_out = av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132 + if (!avctx->extradata || !avctx->stats_out) { + av_freep(&avctx->stats_out); + return AVERROR(ENOMEM); + } s->version = 2; - avctx->coded_frame = &s->picture; + avctx->coded_frame = av_frame_alloc(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; switch (avctx->pix_fmt) { case AV_PIX_FMT_YUV420P: @@@ -446,16 -443,15 +451,12 @@@ static int encode_frame(AVCodecContext const int fake_ystride = s->interlaced ? pict->linesize[0]*2 : pict->linesize[0]; const int fake_ustride = s->interlaced ? pict->linesize[1]*2 : pict->linesize[1]; const int fake_vstride = s->interlaced ? pict->linesize[2]*2 : pict->linesize[2]; - AVFrame * const p = &s->picture; + const AVFrame * const p = pict; int i, j, size = 0, ret; - if (!pkt->data && - (ret = av_new_packet(pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0) { - av_log(avctx, AV_LOG_ERROR, "Error allocating output packet.\n"); + if ((ret = ff_alloc_packet2(avctx, pkt, width * height * 3 * 4 + FF_MIN_BUFFER_SIZE)) < 0) return ret; - } - *p = *pict; - p->pict_type = AV_PICTURE_TYPE_I; - p->key_frame = 1; - if (s->context) { for (i = 0; i < 3; i++) { ff_huff_gen_len_table(s->len[i], s->stats[i]);