]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libaomdec.c
Merge commit '8629149816930a43bf5a66b11c6224446cabd044'
[ffmpeg] / libavcodec / libaomdec.c
index 1352b421d9c2653fc38dd49439700598d340200c..a72ac984e72a9f7ea24227d79c1d9ce9f66e975c 100644 (file)
@@ -42,8 +42,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
 {
     AV1DecodeContext *ctx           = avctx->priv_data;
     struct aom_codec_dec_cfg deccfg = {
-        /* token partitions+1 would be a decent choice */
-        .threads = FFMIN(avctx->thread_count, 16)
+        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16)
     };
 
     av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str());
@@ -61,9 +60,10 @@ static av_cold int aom_init(AVCodecContext *avctx,
 
 static void image_copy_16_to_8(AVFrame *pic, struct aom_image *img)
 {
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format);
     int i;
 
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < desc->nb_components; i++) {
         int w = img->d_w;
         int h = img->d_h;
         int x, y;
@@ -95,34 +95,26 @@ static int set_pix_fmt(AVCodecContext *avctx, struct aom_image *img)
 
     switch (img->fmt) {
     case AOM_IMG_FMT_I420:
-        avctx->pix_fmt = AV_PIX_FMT_YUV420P;
-        avctx->profile = FF_PROFILE_AV1_MAIN;
-        return 0;
-    case AOM_IMG_FMT_I422:
-        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
-        avctx->profile = FF_PROFILE_AV1_PROFESSIONAL;
-        return 0;
-    case AOM_IMG_FMT_I444:
-        avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
-                         AV_PIX_FMT_GBRP : AV_PIX_FMT_YUV444P;
-        avctx->profile = FF_PROFILE_AV1_HIGH;
-        return 0;
     case AOM_IMG_FMT_I42016:
         if (img->bit_depth == 8) {
-            avctx->pix_fmt = AV_PIX_FMT_YUV420P;
+            avctx->pix_fmt = img->monochrome ?
+                             AV_PIX_FMT_GRAY8 : AV_PIX_FMT_YUV420P;
             avctx->profile = FF_PROFILE_AV1_MAIN;
             return 0;
         } else if (img->bit_depth == 10) {
-            avctx->pix_fmt = AV_PIX_FMT_YUV420P10;
+            avctx->pix_fmt = img->monochrome ?
+                             AV_PIX_FMT_GRAY10 : AV_PIX_FMT_YUV420P10;
             avctx->profile = FF_PROFILE_AV1_MAIN;
             return 0;
         } else if (img->bit_depth == 12) {
-            avctx->pix_fmt = AV_PIX_FMT_YUV420P12;
+            avctx->pix_fmt = img->monochrome ?
+                             AV_PIX_FMT_GRAY12 : AV_PIX_FMT_YUV420P12;
             avctx->profile = FF_PROFILE_AV1_PROFESSIONAL;
             return 0;
         } else {
             return AVERROR_INVALIDDATA;
         }
+    case AOM_IMG_FMT_I422:
     case AOM_IMG_FMT_I42216:
         if (img->bit_depth == 8) {
             avctx->pix_fmt = AV_PIX_FMT_YUV422P;
@@ -139,20 +131,18 @@ static int set_pix_fmt(AVCodecContext *avctx, struct aom_image *img)
         } else {
             return AVERROR_INVALIDDATA;
         }
+    case AOM_IMG_FMT_I444:
     case AOM_IMG_FMT_I44416:
         if (img->bit_depth == 8) {
-            avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
-                             AV_PIX_FMT_GBRP : AV_PIX_FMT_YUV444P;
+            avctx->pix_fmt = AV_PIX_FMT_YUV444P;
             avctx->profile = FF_PROFILE_AV1_HIGH;
             return 0;
         } else if (img->bit_depth == 10) {
-            avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
-                             AV_PIX_FMT_GBRP10 : AV_PIX_FMT_YUV444P10;
+            avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
             avctx->profile = FF_PROFILE_AV1_HIGH;
             return 0;
         } else if (img->bit_depth == 12) {
-            avctx->pix_fmt = avctx->colorspace == AVCOL_SPC_RGB ?
-                             AV_PIX_FMT_GBRP12 : AV_PIX_FMT_YUV444P12;
+            avctx->pix_fmt = AV_PIX_FMT_YUV444P12;
             avctx->profile = FF_PROFILE_AV1_PROFESSIONAL;
             return 0;
         } else {