Merge commit '8e373fe048812a25b238ea60a7052b8c07639a42'
authorMichael Niedermayer <michael@niedermayer.cc>
Mon, 13 Jul 2015 23:23:39 +0000 (01:23 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 13 Jul 2015 23:23:39 +0000 (01:23 +0200)
* commit '8e373fe048812a25b238ea60a7052b8c07639a42':
  hevc: Factor out the pixel format mapping from the sps parser

Conflicts:
libavcodec/hevc_ps.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
1  2 
libavcodec/hevc_ps.c

@@@ -742,6 -642,38 +742,53 @@@ static int scaling_list_data(GetBitCont
      return 0;
  }
  
 -    if (sps->chroma_format_idc == 1) {
 -        switch (sps->bit_depth) {
 -        case 8:  sps->pix_fmt = AV_PIX_FMT_YUV420P;   break;
 -        case 9:  sps->pix_fmt = AV_PIX_FMT_YUV420P9;  break;
 -        case 10: sps->pix_fmt = AV_PIX_FMT_YUV420P10; break;
 -        default:
 -            av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n",
 -                   sps->bit_depth);
 -            return AVERROR_PATCHWELCOME;
 -        }
 -    } else {
+ static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps)
+ {
+     const AVPixFmtDescriptor *desc;
 -               "non-4:2:0 support is currently unspecified.\n");
 -        return AVERROR_PATCHWELCOME;
++    switch (sps->bit_depth) {
++    case 8:
++        if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
++        if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
++        if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
++        if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
++       break;
++    case 9:
++        if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
++        if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
++        if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
++        if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
++        break;
++    case 10:
++        if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
++        if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
++        if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
++        if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
++        break;
++    case 12:
++        if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
++        if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
++        if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
++        if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
++        break;
++    default:
+         av_log(avctx, AV_LOG_ERROR,
++               "4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n");
++        return AVERROR_INVALIDDATA;
+     }
+     desc = av_pix_fmt_desc_get(sps->pix_fmt);
+     if (!desc)
+         return AVERROR(EINVAL);
+     sps->hshift[0] = sps->vshift[0] = 0;
+     sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
+     sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
+     sps->pixel_shift = sps->bit_depth > 8;
+     return 0;
+ }
  int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
                        int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx)
  {
                 "Luma bit depth (%d) is different from chroma bit depth (%d), "
                 "this is unsupported.\n",
                 sps->bit_depth, bit_depth_chroma);
 -        ret = AVERROR_INVALIDDATA;
 -        goto err;
 +        return AVERROR_INVALIDDATA;
      }
  
-     switch (sps->bit_depth) {
-     case 8:
-         if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
-         if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
-         if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
-         if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
-        break;
-     case 9:
-         if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
-         if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
-         if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
-         if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
-         break;
-     case 10:
-         if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
-         if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
-         if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
-         if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
-         break;
-     case 12:
-         if (sps->chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY16;
-         if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
-         if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
-         if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
-         break;
-     default:
-         av_log(avctx, AV_LOG_ERROR,
-                "4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n");
-         return AVERROR_INVALIDDATA;
-     }
-     desc = av_pix_fmt_desc_get(sps->pix_fmt);
-     if (!desc) {
-         return AVERROR(EINVAL);
-     }
-     sps->hshift[0] = sps->vshift[0] = 0;
-     sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
-     sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
--
-     sps->pixel_shift = sps->bit_depth > 8;
+     ret = map_pixel_format(avctx, sps);
+     if (ret < 0)
 -        goto err;
++        return ret;
  
      sps->log2_max_poc_lsb = get_ue_golomb_long(gb) + 4;
      if (sps->log2_max_poc_lsb > 16) {