Merge commit '6f19bbcf8532d018d8d6d82e000738d0ac2385c9'
authorJames Almer <jamrial@gmail.com>
Wed, 28 Sep 2016 16:26:12 +0000 (13:26 -0300)
committerJames Almer <jamrial@gmail.com>
Wed, 28 Sep 2016 16:26:12 +0000 (13:26 -0300)
* commit '6f19bbcf8532d018d8d6d82e000738d0ac2385c9':
  qsvdec: move reading the user-provided session to qsv_decode_init()

Conflicts:
    libavcodec/qsvdec.c

Merged-by: James Almer <jamrial@gmail.com>
1  2 
libavcodec/qsvdec.c

@@@ -49,67 -49,70 +49,82 @@@ int ff_qsv_map_pixfmt(enum AVPixelForma
      }
  }
  
 -        if (!q->internal_session) {
 -            int ret = ff_qsv_init_internal_session(avctx, &q->internal_session,
 -                                                   q->load_plugins);
+ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession session)
+ {
+     if (!session) {
 -        q->session = q->internal_session;
++        if (!q->internal_qs.session) {
++           int ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
++                                                  q->load_plugins);
+             if (ret < 0)
+                 return ret;
+         }
 -    /* make sure the decoder is uninitialized */
 -    MFXVideoDECODE_Close(q->session);
 -
 -    return 0;
++        q->session = q->internal_qs.session;
+     } else {
+         q->session = session;
+     }
 -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
++   return 0;
+ }
 +static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt)
  {
+     mfxSession session = NULL;
      mfxVideoParam param = { { 0 } };
 +    mfxBitstream bs   = { { { 0 } } };
      int ret;
 +    enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
 +                                       AV_PIX_FMT_NV12,
 +                                       AV_PIX_FMT_NONE };
  
 -    if (!q->async_fifo) {
 -        q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
 -                                      (sizeof(mfxSyncPoint*) + sizeof(QSVFrame*)));
 -        if (!q->async_fifo)
 -            return AVERROR(ENOMEM);
 -    }
 +    ret = ff_get_format(avctx, pix_fmts);
 +    if (ret < 0)
 +        return ret;
 +
 +    avctx->pix_fmt      = ret;
  
 +    q->iopattern  = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
      if (avctx->hwaccel_context) {
 -        AVQSVContext *user_ctx = avctx->hwaccel_context;
 -        session           = user_ctx->session;
 -        q->iopattern      = user_ctx->iopattern;
 -        q->ext_buffers    = user_ctx->ext_buffers;
 -        q->nb_ext_buffers = user_ctx->nb_ext_buffers;
 +        AVQSVContext *qsv = avctx->hwaccel_context;
 +
-         q->session        = qsv->session;
++        session           = qsv->session;
 +        q->iopattern      = qsv->iopattern;
 +        q->ext_buffers    = qsv->ext_buffers;
 +        q->nb_ext_buffers = qsv->nb_ext_buffers;
      }
-     if (!q->session) {
-         if (!q->internal_qs.session) {
-             ret = ff_qsv_init_internal_session(avctx, &q->internal_qs,
-                                                q->load_plugins);
-             if (ret < 0)
-                 return ret;
-         }
  
-         q->session = q->internal_qs.session;
+     ret = qsv_init_session(avctx, q, session);
+     if (ret < 0) {
+         av_log(avctx, AV_LOG_ERROR, "Error initializing an MFX session\n");
+         return ret;
      }
  
 +    if (avpkt->size) {
 +        bs.Data       = avpkt->data;
 +        bs.DataLength = avpkt->size;
 +        bs.MaxLength  = bs.DataLength;
 +        bs.TimeStamp  = avpkt->pts;
 +    } else
 +        return AVERROR_INVALIDDATA;
 +
      ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
 -    if (ret < 0)
 +    if (ret < 0) {
 +        av_log(avctx, AV_LOG_ERROR, "Unsupported codec_id %08x\n", avctx->codec_id);
          return ret;
 +    }
  
 -    param.mfx.CodecId      = ret;
 -    param.mfx.CodecProfile = avctx->profile;
 -    param.mfx.CodecLevel   = avctx->level;
 -
 -    param.mfx.FrameInfo.BitDepthLuma   = 8;
 -    param.mfx.FrameInfo.BitDepthChroma = 8;
 -    param.mfx.FrameInfo.Shift          = 0;
 -    param.mfx.FrameInfo.FourCC         = MFX_FOURCC_NV12;
 -    param.mfx.FrameInfo.Width          = avctx->coded_width;
 -    param.mfx.FrameInfo.Height         = avctx->coded_height;
 -    param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
 +    param.mfx.CodecId = ret;
  
 +    ret = MFXVideoDECODE_DecodeHeader(q->session, &bs, &param);
 +    if (MFX_ERR_MORE_DATA==ret) {
 +        /* this code means that header not found so we return packet size to skip
 +           a current packet
 +         */
 +        return avpkt->size;
 +    } else if (ret < 0) {
 +        av_log(avctx, AV_LOG_ERROR, "Decode header error %d\n", ret);
 +        return ff_qsv_error(ret);
 +    }
      param.IOPattern   = q->iopattern;
      param.AsyncDepth  = q->async_depth;
      param.ExtParam    = q->ext_buffers;