X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmediacodecdec_common.c;h=cb18aed401a051f1bfe59b0f2d463d7f442c692c;hb=6e30b35b85b81c802e52a1078ec7a3097e353c6d;hp=7c2661f6726b41c99b6838e9cf79d1456146a43f;hpb=1b98bfb932ad36667ea7f18e24c54978623f6654;p=ffmpeg diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 7c2661f6726..cb18aed401a 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -85,6 +85,85 @@ #define OUTPUT_DEQUEUE_TIMEOUT_US 8000 #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 1000000 +enum { + COLOR_RANGE_FULL = 0x1, + COLOR_RANGE_LIMITED = 0x2, +}; + +static enum AVColorRange mcdec_get_color_range(int color_range) +{ + switch (color_range) { + case COLOR_RANGE_FULL: + return AVCOL_RANGE_JPEG; + case COLOR_RANGE_LIMITED: + return AVCOL_RANGE_MPEG; + default: + return AVCOL_RANGE_UNSPECIFIED; + } +} + +enum { + COLOR_STANDARD_BT709 = 0x1, + COLOR_STANDARD_BT601_PAL = 0x2, + COLOR_STANDARD_BT601_NTSC = 0x4, + COLOR_STANDARD_BT2020 = 0x6, +}; + +static enum AVColorSpace mcdec_get_color_space(int color_standard) +{ + switch (color_standard) { + case COLOR_STANDARD_BT709: + return AVCOL_SPC_BT709; + case COLOR_STANDARD_BT601_PAL: + return AVCOL_SPC_BT470BG; + case COLOR_STANDARD_BT601_NTSC: + return AVCOL_SPC_SMPTE170M; + case COLOR_STANDARD_BT2020: + return AVCOL_SPC_BT2020_NCL; + default: + return AVCOL_SPC_UNSPECIFIED; + } +} + +static enum AVColorPrimaries mcdec_get_color_pri(int color_standard) +{ + switch (color_standard) { + case COLOR_STANDARD_BT709: + return AVCOL_PRI_BT709; + case COLOR_STANDARD_BT601_PAL: + return AVCOL_PRI_BT470BG; + case COLOR_STANDARD_BT601_NTSC: + return AVCOL_PRI_SMPTE170M; + case COLOR_STANDARD_BT2020: + return AVCOL_PRI_BT2020; + default: + return AVCOL_PRI_UNSPECIFIED; + } +} + +enum { + COLOR_TRANSFER_LINEAR = 0x1, + COLOR_TRANSFER_SDR_VIDEO = 0x3, + COLOR_TRANSFER_ST2084 = 0x6, + COLOR_TRANSFER_HLG = 0x7, +}; + +static enum AVColorTransferCharacteristic mcdec_get_color_trc(int color_transfer) +{ + switch (color_transfer) { + case COLOR_TRANSFER_LINEAR: + return AVCOL_TRC_LINEAR; + case COLOR_TRANSFER_SDR_VIDEO: + return AVCOL_TRC_SMPTE170M; + case COLOR_TRANSFER_ST2084: + return AVCOL_TRC_SMPTEST2084; + case COLOR_TRANSFER_HLG: + return AVCOL_TRC_ARIB_STD_B67; + default: + return AVCOL_TRC_UNSPECIFIED; + } +} + enum { COLOR_FormatYUV420Planar = 0x13, COLOR_FormatYUV420SemiPlanar = 0x15, @@ -214,12 +293,11 @@ static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx, } else { frame->pts = info->presentationTimeUs; } -#if FF_API_PKT_PTS -FF_DISABLE_DEPRECATION_WARNINGS - frame->pkt_pts = frame->pts; -FF_ENABLE_DEPRECATION_WARNINGS -#endif frame->pkt_dts = AV_NOPTS_VALUE; + frame->color_range = avctx->color_range; + frame->color_primaries = avctx->color_primaries; + frame->color_trc = avctx->color_trc; + frame->colorspace = avctx->colorspace; buffer = av_mallocz(sizeof(AVMediaCodecBuffer)); if (!buffer) { @@ -303,11 +381,6 @@ static int mediacodec_wrap_sw_buffer(AVCodecContext *avctx, } else { frame->pts = info->presentationTimeUs; } -#if FF_API_PKT_PTS -FF_DISABLE_DEPRECATION_WARNINGS - frame->pkt_pts = frame->pts; -FF_ENABLE_DEPRECATION_WARNINGS -#endif frame->pkt_dts = AV_NOPTS_VALUE; av_log(avctx, AV_LOG_TRACE, @@ -368,6 +441,9 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte int ret = 0; int width = 0; int height = 0; + int color_range = 0; + int color_standard = 0; + int color_transfer = 0; char *format = NULL; if (!s->format) { @@ -426,6 +502,20 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte ff_set_sar(avctx, sar); } + AMEDIAFORMAT_GET_INT32(color_range, "color-range", 0); + if (color_range) + avctx->color_range = mcdec_get_color_range(color_range); + + AMEDIAFORMAT_GET_INT32(color_standard, "color-standard", 0); + if (color_standard) { + avctx->colorspace = mcdec_get_color_space(color_standard); + avctx->color_primaries = mcdec_get_color_pri(color_standard); + } + + AMEDIAFORMAT_GET_INT32(color_transfer, "color-transfer", 0); + if (color_transfer) + avctx->color_trc = mcdec_get_color_trc(color_transfer); + av_log(avctx, AV_LOG_INFO, "Output crop parameters top=%d bottom=%d left=%d right=%d, " "resulting dimensions width=%d height=%d\n", @@ -525,8 +615,8 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, if (status < 0) { char *desc = ff_AMediaFormat_toString(format); av_log(avctx, AV_LOG_ERROR, - "Failed to configure codec (status = %d) with format %s\n", - status, desc); + "Failed to configure codec %s (status = %d) with format %s\n", + s->codec_name, status, desc); av_freep(&desc); ret = AVERROR_EXTERNAL; @@ -537,8 +627,8 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, if (status < 0) { char *desc = ff_AMediaFormat_toString(format); av_log(avctx, AV_LOG_ERROR, - "Failed to start codec (status = %d) with format %s\n", - status, desc); + "Failed to start codec %s (status = %d) with format %s\n", + s->codec_name, status, desc); av_freep(&desc); ret = AVERROR_EXTERNAL; goto fail; @@ -569,7 +659,6 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, int offset = 0; int need_draining = 0; uint8_t *data; - ssize_t index = s->current_input_buffer; size_t size; FFAMediaCodec *codec = s->codec; int status; @@ -591,6 +680,7 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, } while (offset < pkt->size || (need_draining && !s->draining)) { + ssize_t index = s->current_input_buffer; if (index < 0) { index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us); if (ff_AMediaCodec_infoTryAgainLater(codec, index)) { @@ -612,7 +702,11 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, } pts = pkt->pts; - if (pts != AV_NOPTS_VALUE && avctx->pkt_timebase.num && avctx->pkt_timebase.den) { + if (pts == AV_NOPTS_VALUE) { + av_log(avctx, AV_LOG_WARNING, "Input packet is missing PTS\n"); + pts = 0; + } + if (pts && avctx->pkt_timebase.num && avctx->pkt_timebase.den) { pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q); } @@ -628,24 +722,24 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, } av_log(avctx, AV_LOG_TRACE, - "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, size, pts); + "Queued empty EOS input buffer %zd with flags=%d\n", index, flags); s->draining = 1; - break; - } else { - size = FFMIN(pkt->size - offset, size); - memcpy(data, pkt->data + offset, size); - offset += size; + return 0; + } - status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, size, pts, 0); - if (status < 0) { - av_log(avctx, AV_LOG_ERROR, "Failed to queue input buffer (status = %d)\n", status); - return AVERROR_EXTERNAL; - } + size = FFMIN(pkt->size - offset, size); + memcpy(data, pkt->data + offset, size); + offset += size; - av_log(avctx, AV_LOG_TRACE, - "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, size, pts); + status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, size, pts, 0); + if (status < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to queue input buffer (status = %d)\n", status); + return AVERROR_EXTERNAL; } + + av_log(avctx, AV_LOG_TRACE, + "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, size, pts); } if (offset == 0)