summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMatthieu Bouron <matthieu.bouron@gmail.com>2018-02-19 16:13:00 +0100
committerMatthieu Bouron <matthieu.bouron@gmail.com>2018-03-03 21:17:21 +0100
commita079eaba8ee20bc3869852df658f2f6cc11875e3 (patch)
tree1476e65c3ca1766fc80094ecdf833b318e03e775 /libavcodec
parente45d55756188186f065fa23fcab7b7d9026ddf41 (diff)
avcodec/mediacodecdec_common: refactor mediacodec_dec_parse_format()
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/mediacodecdec_common.c82
1 files changed, 30 insertions, 52 deletions
diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index b44abaef7f..ab26df04bd 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -339,11 +339,22 @@ done:
return ret;
}
+#define AMEDIAFORMAT_GET_INT32(name, key, mandatory) do { \
+ int32_t value = 0; \
+ if (ff_AMediaFormat_getInt32(s->format, key, &value)) { \
+ (name) = value; \
+ } else if (mandatory) { \
+ av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", key, format); \
+ ret = AVERROR_EXTERNAL; \
+ goto fail; \
+ } \
+} while (0) \
+
static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecContext *s)
{
+ int ret = 0;
int width = 0;
int height = 0;
- int32_t value = 0;
char *format = NULL;
if (!s->format) {
@@ -356,40 +367,16 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
return AVERROR_EXTERNAL;
}
av_log(avctx, AV_LOG_DEBUG, "Parsing MediaFormat %s\n", format);
- av_freep(&format);
/* Mandatory fields */
- if (!ff_AMediaFormat_getInt32(s->format, "width", &value)) {
- format = ff_AMediaFormat_toString(s->format);
- av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "width", format);
- av_freep(&format);
- return AVERROR_EXTERNAL;
- }
- s->width = value;
+ AMEDIAFORMAT_GET_INT32(s->width, "width", 1);
+ AMEDIAFORMAT_GET_INT32(s->height, "height", 1);
- if (!ff_AMediaFormat_getInt32(s->format, "height", &value)) {
- format = ff_AMediaFormat_toString(s->format);
- av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "height", format);
- av_freep(&format);
- return AVERROR_EXTERNAL;
- }
- s->height = value;
+ AMEDIAFORMAT_GET_INT32(s->stride, "stride", 1);
+ s->stride = s->stride > 0 ? s->stride : s->width;
- if (!ff_AMediaFormat_getInt32(s->format, "stride", &value)) {
- format = ff_AMediaFormat_toString(s->format);
- av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "stride", format);
- av_freep(&format);
- return AVERROR_EXTERNAL;
- }
- s->stride = value > 0 ? value : s->width;
-
- if (!ff_AMediaFormat_getInt32(s->format, "slice-height", &value)) {
- format = ff_AMediaFormat_toString(s->format);
- av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "slice-height", format);
- av_freep(&format);
- return AVERROR_EXTERNAL;
- }
- s->slice_height = value > 0 ? value : s->height;
+ AMEDIAFORMAT_GET_INT32(s->slice_height, "slice-height", 1);
+ s->slice_height = s->slice_height > 0 ? s->slice_height : s->height;
if (strstr(s->codec_name, "OMX.Nvidia.")) {
s->slice_height = FFALIGN(s->height, 16);
@@ -398,32 +385,19 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
s->stride = avctx->width;
}
- if (!ff_AMediaFormat_getInt32(s->format, "color-format", &value)) {
- format = ff_AMediaFormat_toString(s->format);
- av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "color-format", format);
- av_freep(&format);
- return AVERROR_EXTERNAL;
- }
- s->color_format = value;
-
- s->pix_fmt = avctx->pix_fmt = mcdec_map_color_format(avctx, s, value);
+ AMEDIAFORMAT_GET_INT32(s->color_format, "color-format", 1);
+ s->pix_fmt = avctx->pix_fmt = mcdec_map_color_format(avctx, s, s->color_format);
if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR, "Output color format is not supported\n");
- return AVERROR(EINVAL);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
/* Optional fields */
- if (ff_AMediaFormat_getInt32(s->format, "crop-top", &value))
- s->crop_top = value;
-
- if (ff_AMediaFormat_getInt32(s->format, "crop-bottom", &value))
- s->crop_bottom = value;
-
- if (ff_AMediaFormat_getInt32(s->format, "crop-left", &value))
- s->crop_left = value;
-
- if (ff_AMediaFormat_getInt32(s->format, "crop-right", &value))
- s->crop_right = value;
+ AMEDIAFORMAT_GET_INT32(s->crop_top, "crop-top", 0);
+ AMEDIAFORMAT_GET_INT32(s->crop_bottom, "crop-bottom", 0);
+ AMEDIAFORMAT_GET_INT32(s->crop_left, "crop-left", 0);
+ AMEDIAFORMAT_GET_INT32(s->crop_right, "crop-right", 0);
width = s->crop_right + 1 - s->crop_left;
height = s->crop_bottom + 1 - s->crop_top;
@@ -434,7 +408,11 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
s->crop_top, s->crop_bottom, s->crop_left, s->crop_right,
width, height);
+ av_freep(&format);
return ff_set_dimensions(avctx, width, height);
+fail:
+ av_freep(&format);
+ return ret;
}