]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qsvdec.c
avcodec: Constify all the AVCodecParsers
[ffmpeg] / libavcodec / qsvdec.c
index 3ca16dafae8826ac6c3b2506d487311455b83d2a..f543defb1821e756eede49041f4afc8dbfe02199 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdint.h>
 #include <string.h>
 #include <sys/types.h>
 
 #include <mfx/mfxvideo.h>
 
 #include "libavutil/common.h"
+#include "libavutil/fifo.h"
+#include "libavutil/frame.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/hwcontext_qsv.h"
 #include "libavutil/mem.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
-#include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
 #include "libavutil/imgutils.h"
 #include "avcodec.h"
 #include "internal.h"
 #include "decode.h"
+#include "hwconfig.h"
 #include "qsv.h"
 #include "qsv_internal.h"
-#include "qsvdec.h"
 
-const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = {
+typedef struct QSVContext {
+    // the session used for decoding
+    mfxSession session;
+
+    // the session we allocated internally, in case the caller did not provide
+    // one
+    QSVSession internal_qs;
+
+    QSVFramesContext frames_ctx;
+
+    /**
+     * a linked list of frames currently being used by QSV
+     */
+    QSVFrame *work_frames;
+
+    AVFifoBuffer *async_fifo;
+    int zero_consume_run;
+    int buffered_count;
+    int reinit_flag;
+
+    enum AVPixelFormat orig_pix_fmt;
+    uint32_t fourcc;
+    mfxFrameInfo frame_info;
+    AVBufferPool *pool;
+
+    int initialized;
+
+    // options set by the caller
+    int async_depth;
+    int iopattern;
+    int gpu_copy;
+
+    char *load_plugins;
+
+    mfxExtBuffer **ext_buffers;
+    int         nb_ext_buffers;
+} QSVContext;
+
+static const AVCodecHWConfigInternal *const qsv_hw_configs[] = {
     &(const AVCodecHWConfigInternal) {
         .public = {
             .pix_fmt     = AV_PIX_FMT_QSV,
@@ -57,7 +97,8 @@ const AVCodecHWConfigInternal *const ff_qsv_hw_configs[] = {
     NULL
 };
 
-static int ff_qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, AVBufferPool *pool)
+static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame,
+                                     AVBufferPool *pool)
 {
     int ret = 0;
 
@@ -255,7 +296,9 @@ static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide
     return 0;
 }
 
-static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q, AVPacket *avpkt, enum AVPixelFormat pix_fmt, mfxVideoParam *param)
+static int qsv_decode_header(AVCodecContext *avctx, QSVContext *q,
+                             const AVPacket *avpkt, enum AVPixelFormat pix_fmt,
+                             mfxVideoParam *param)
 {
     int ret;
 
@@ -299,7 +342,7 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
     int ret;
 
     if (q->pool)
-        ret = ff_qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
+        ret = qsv_get_continuous_buffer(avctx, frame->frame, q->pool);
     else
         ret = ff_get_buffer(avctx, frame->frame, AV_GET_BUFFER_FLAG_REF);
 
@@ -400,7 +443,7 @@ static QSVFrame *find_frame(QSVContext *q, mfxFrameSurface1 *surf)
 
 static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
                       AVFrame *frame, int *got_frame,
-                      AVPacket *avpkt)
+                      const AVPacket *avpkt)
 {
     QSVFrame *out_frame;
     mfxFrameSurface1 *insurf;
@@ -501,11 +544,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 
         outsurf = &out_frame->surface;
 
-#if FF_API_PKT_PTS
-FF_DISABLE_DEPRECATION_WARNINGS
-        frame->pkt_pts = outsurf->Data.TimeStamp;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
         frame->pts = outsurf->Data.TimeStamp;
 
         frame->repeat_pict =
@@ -531,7 +569,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     return bs.DataOffset;
 }
 
-int ff_qsv_decode_close(QSVContext *q)
+static void qsv_decode_close_qsvcontext(QSVContext *q)
 {
     QSVFrame *cur = q->work_frames;
 
@@ -563,12 +601,10 @@ int ff_qsv_decode_close(QSVContext *q)
     av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
     av_buffer_unref(&q->frames_ctx.mids_buf);
     av_buffer_pool_uninit(&q->pool);
-
-    return 0;
 }
 
-int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
-                        AVFrame *frame, int *got_frame, AVPacket *pkt)
+static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
+                            AVFrame *frame, int *got_frame, const AVPacket *pkt)
 {
     int ret;
     mfxVideoParam param = { 0 };
@@ -629,12 +665,6 @@ reinit_fail:
     return ret;
 }
 
-void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
-{
-    q->orig_pix_fmt = AV_PIX_FMT_NONE;
-    q->initialized = 0;
-}
-
 enum LoadPlugin {
     LOAD_PLUGIN_NONE,
     LOAD_PLUGIN_HEVC_SW,
@@ -669,7 +699,7 @@ static av_cold int qsv_decode_close(AVCodecContext *avctx)
 
     av_freep(&s->qsv.load_plugins);
 
-    ff_qsv_decode_close(&s->qsv);
+    qsv_decode_close_qsvcontext(&s->qsv);
 
     qsv_clear_buffers(s);
 
@@ -682,21 +712,12 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
 {
     QSVDecContext *s = avctx->priv_data;
     int ret;
+    const char *uid = NULL;
 
     if (avctx->codec_id == AV_CODEC_ID_VP8) {
-        static const char *uid_vp8dec_hw = "f622394d8d87452f878c51f2fc9b4131";
-
-        av_freep(&s->qsv.load_plugins);
-        s->qsv.load_plugins = av_strdup(uid_vp8dec_hw);
-        if (!s->qsv.load_plugins)
-            return AVERROR(ENOMEM);
+        uid = "f622394d8d87452f878c51f2fc9b4131";
     } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
-        static const char *uid_vp9dec_hw = "a922394d8d87452f878c51f2fc9b4131";
-
-        av_freep(&s->qsv.load_plugins);
-        s->qsv.load_plugins = av_strdup(uid_vp9dec_hw);
-        if (!s->qsv.load_plugins)
-            return AVERROR(ENOMEM);
+        uid = "a922394d8d87452f878c51f2fc9b4131";
     }
     else if (avctx->codec_id == AV_CODEC_ID_HEVC && s->load_plugin != LOAD_PLUGIN_NONE) {
         static const char * const uid_hevcdec_sw = "15dd936825ad475ea34e35f3f54217a6";
@@ -707,16 +728,18 @@ static av_cold int qsv_decode_init(AVCodecContext *avctx)
                    "load_plugins is not empty, but load_plugin is not set to 'none'."
                    "The load_plugin value will be ignored.\n");
         } else {
-            av_freep(&s->qsv.load_plugins);
-
             if (s->load_plugin == LOAD_PLUGIN_HEVC_SW)
-                s->qsv.load_plugins = av_strdup(uid_hevcdec_sw);
+                uid = uid_hevcdec_sw;
             else
-                s->qsv.load_plugins = av_strdup(uid_hevcdec_hw);
-            if (!s->qsv.load_plugins)
-                return AVERROR(ENOMEM);
+                uid = uid_hevcdec_hw;
         }
     }
+    if (uid) {
+        av_freep(&s->qsv.load_plugins);
+        s->qsv.load_plugins = av_strdup(uid);
+        if (!s->qsv.load_plugins)
+            return AVERROR(ENOMEM);
+    }
 
     s->qsv.orig_pix_fmt = AV_PIX_FMT_NV12;
     s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
@@ -761,7 +784,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
         if (s->buffer_pkt.size <= 0) {
             /* no more data */
             if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
-                return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
+                return avpkt->size ? avpkt->size : qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
             /* in progress of reinit, no read from fifo and keep the buffer_pkt */
             if (!s->qsv.reinit_flag) {
                 av_packet_unref(&s->buffer_pkt);
@@ -769,7 +792,7 @@ static int qsv_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
 
-        ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
+        ret = qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->buffer_pkt);
         if (ret < 0){
             /* Drop buffer_pkt when failed to decode the packet. Otherwise,
                the decoder will keep decoding the failure packet. */
@@ -791,7 +814,9 @@ static void qsv_decode_flush(AVCodecContext *avctx)
     QSVDecContext *s = avctx->priv_data;
 
     qsv_clear_buffers(s);
-    ff_qsv_decode_flush(avctx, &s->qsv);
+
+    s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
+    s->qsv.initialized = 0;
 }
 
 #define OFFSET(x) offsetof(QSVDecContext, x)
@@ -804,7 +829,7 @@ static const AVClass x##_qsv_class = { \
     .option     = opt, \
     .version    = LIBAVUTIL_VERSION_INT, \
 }; \
-AVCodec ff_##x##_qsv_decoder = { \
+const AVCodec ff_##x##_qsv_decoder = { \
     .name           = #x "_qsv", \
     .long_name      = NULL_IF_CONFIG_SMALL(#X " video (Intel Quick Sync Video acceleration)"), \
     .priv_data_size = sizeof(QSVDecContext), \
@@ -821,7 +846,7 @@ AVCodec ff_##x##_qsv_decoder = { \
                                                     AV_PIX_FMT_P010, \
                                                     AV_PIX_FMT_QSV, \
                                                     AV_PIX_FMT_NONE }, \
-    .hw_configs     = ff_qsv_hw_configs, \
+    .hw_configs     = qsv_hw_configs, \
     .wrapper_name   = "qsv", \
 }; \