X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2Fffmpeg%2Flibavcodec%2Flibvpxenc.c;h=163d12aca6cfb52ae28aa9f0c8b103fc9dfef2a5;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=3dddffd88ea3c8006b794fe7a7d7938c6b53c6a7;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/ffmpeg/libavcodec/libvpxenc.c b/src/third_party/ffmpeg/libavcodec/libvpxenc.c index 3dddffd..163d12a 100644 --- a/src/third_party/ffmpeg/libavcodec/libvpxenc.c +++ b/src/third_party/ffmpeg/libavcodec/libvpxenc.c @@ -96,6 +96,7 @@ typedef struct VP8EncoderContext { int tile_columns; int tile_rows; int frame_parallel; + int aq_mode; } VP8Context; /** String mappings for enum vp8e_enc_control_id */ @@ -123,6 +124,7 @@ static const char *const ctlidstr[] = { [VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS", [VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS", [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING", + [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE", #endif }; @@ -196,7 +198,7 @@ static void coded_frame_add(void *list, struct FrameListData *cx_frame) { struct FrameListData **p = list; - while (*p != NULL) + while (*p) p = &(*p)->next; *p = cx_frame; cx_frame->next = NULL; @@ -300,14 +302,22 @@ static av_cold int vpx_init(AVCodecContext *avctx, enccfg.g_pass = VPX_RC_ONE_PASS; if (avctx->rc_min_rate == avctx->rc_max_rate && - avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) + avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) { enccfg.rc_end_usage = VPX_CBR; - else if (ctx->crf) + } else if (ctx->crf >= 0) { enccfg.rc_end_usage = VPX_CQ; +#if CONFIG_LIBVPX_VP9_ENCODER + if (!avctx->bit_rate && avctx->codec_id == AV_CODEC_ID_VP9) + enccfg.rc_end_usage = VPX_Q; +#endif + } if (avctx->bit_rate) { enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000, - AV_ROUND_NEAR_INF); + AV_ROUND_NEAR_INF); +#if CONFIG_LIBVPX_VP9_ENCODER + } else if (enccfg.rc_end_usage == VPX_Q) { +#endif } else { if (enccfg.rc_end_usage == VPX_CQ) { enccfg.rc_target_bitrate = 1000000; @@ -324,11 +334,15 @@ static av_cold int vpx_init(AVCodecContext *avctx, if (avctx->qmax >= 0) enccfg.rc_max_quantizer = avctx->qmax; - if (enccfg.rc_end_usage == VPX_CQ) { + if (enccfg.rc_end_usage == VPX_CQ +#if CONFIG_LIBVPX_VP9_ENCODER + || enccfg.rc_end_usage == VPX_Q +#endif + ) { if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) { av_log(avctx, AV_LOG_ERROR, - "CQ level must be between minimum and maximum quantizer value (%d-%d)\n", - enccfg.rc_min_quantizer, enccfg.rc_max_quantizer); + "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n", + ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer); return AVERROR(EINVAL); } } @@ -430,7 +444,8 @@ static av_cold int vpx_init(AVCodecContext *avctx, if (avctx->codec_id == AV_CODEC_ID_VP8) codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices)); codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, avctx->mb_threshold); - codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf); + if (ctx->crf >= 0) + codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf); if (ctx->max_intra_rate >= 0) codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, ctx->max_intra_rate); @@ -444,6 +459,8 @@ static av_cold int vpx_init(AVCodecContext *avctx, codecctl_int(avctx, VP9E_SET_TILE_ROWS, ctx->tile_rows); if (ctx->frame_parallel >= 0) codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel); + if (ctx->aq_mode >= 0) + codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode); } #endif @@ -542,7 +559,7 @@ static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, cx_frame->sz_alpha + 8); - if(side_data == NULL) { + if(!side_data) { av_free_packet(pkt); av_free(pkt); return AVERROR(ENOMEM); @@ -775,7 +792,7 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt, "by the bool decoder, meaning that partitions can be decoded even " \ "though earlier partitions have been lost. Note that intra predicition" \ " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \ - { "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE }, \ + { "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \ #define LEGACY_OPTIONS \ {"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \ @@ -803,6 +820,11 @@ static const AVOption vp9_options[] = { { "tile-columns", "Number of tile columns to use, log2", OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE}, { "tile-rows", "Number of tile rows to use, log2", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE}, + { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3, VE, "aq_mode"}, + { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" }, \ + { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" }, \ + { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" }, \ + { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" }, \ LEGACY_OPTIONS { NULL } };