[FFmpeg-devel,1/2,v2] avcodec/libaomenc: support setting chroma sample location

Submitted by James Almer on Sept. 19, 2018, 1:14 a.m.

Details

Message ID 20180919011447.8804-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Sept. 19, 2018, 1:14 a.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libaomenc.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 6a79d9b873..9669e82049 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -76,6 +76,7 @@  static const char *const ctlidstr[] = {
     [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
     [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
     [AV1E_SET_COLOR_RANGE]      = "AV1E_SET_COLOR_RANGE",
+    [AV1E_SET_CHROMA_SAMPLE_POSITION] = "AV1E_SET_CHROMA_SAMPLE_POSITION",
     [AV1E_SET_COLOR_PRIMARIES]  = "AV1E_SET_COLOR_PRIMARIES",
     [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
     [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
@@ -284,6 +285,28 @@  static void set_color_range(AVCodecContext *avctx)
     codecctl_int(avctx, AV1E_SET_COLOR_RANGE, aom_cr);
 }
 
+static void set_chroma_position(AVCodecContext *avctx)
+{
+    enum aom_chroma_sample_position aom_cps;
+
+    if (avctx->pix_fmt != AV_PIX_FMT_YUV420P   &&
+        avctx->pix_fmt != AV_PIX_FMT_YUV420P10 &&
+        avctx->pix_fmt != AV_PIX_FMT_YUV420P12)
+        return;
+
+    switch (avctx->chroma_sample_location) {
+    case AVCHROMA_LOC_UNSPECIFIED: aom_cps = AOM_CSP_UNKNOWN;   break;
+    case AVCHROMA_LOC_LEFT:        aom_cps = AOM_CSP_VERTICAL;  break;
+    case AVCHROMA_LOC_TOPLEFT:     aom_cps = AOM_CSP_COLOCATED; break;
+    default:
+        av_log(avctx, AV_LOG_WARNING, "Unsupported chroma sample location (%d)\n",
+               avctx->chroma_sample_location);
+        return;
+    }
+
+    codecctl_int(avctx, AV1E_SET_CHROMA_SAMPLE_POSITION, aom_cps);
+}
+
 static av_cold int aom_init(AVCodecContext *avctx,
                             const struct aom_codec_iface *iface)
 {
@@ -452,6 +475,7 @@  static av_cold int aom_init(AVCodecContext *avctx,
     codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
     codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
     codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc);
+    set_chroma_position(avctx);
     set_color_range(avctx);
 
     // provide dummy value to initialize wrapper, values will be updated each _encode()