FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qsvdec_vc1.c
Go to the documentation of this file.
1 /*
2  * Intel MediaSDK QSV based VC-1 video decoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 #include <string.h>
23 
24 #include <mfx/mfxvideo.h>
25 
26 #include "libavutil/common.h"
27 #include "libavutil/fifo.h"
28 #include "libavutil/opt.h"
29 
30 #include "avcodec.h"
31 #include "internal.h"
32 #include "qsv_internal.h"
33 #include "qsvdec.h"
34 #include "qsv.h"
35 
36 typedef struct QSVVC1Context {
37  AVClass *class;
39 
41 
44 
46 {
47  AVPacket pkt;
48  while (av_fifo_size(s->packet_fifo) >= sizeof(pkt)) {
49  av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL);
50  av_packet_unref(&pkt);
51  }
52 
54 }
55 
57 {
58  QSVVC1Context *s = avctx->priv_data;
59 
61 
63 
65 
66  return 0;
67 }
68 
70 {
71  QSVVC1Context *s = avctx->priv_data;
72  int ret;
73 
74  s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
75  if (!s->packet_fifo) {
76  ret = AVERROR(ENOMEM);
77  goto fail;
78  }
79 
80  return 0;
81 fail:
82  qsv_decode_close(avctx);
83  return ret;
84 }
85 
86 static int qsv_decode_frame(AVCodecContext *avctx, void *data,
87  int *got_frame, AVPacket *avpkt)
88 {
89  QSVVC1Context *s = avctx->priv_data;
90  AVFrame *frame = data;
91  int ret;
92 
93  /* buffer the input packet */
94  if (avpkt->size) {
95  AVPacket input_ref = { 0 };
96 
97  if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) {
99  av_fifo_size(s->packet_fifo) + sizeof(input_ref));
100  if (ret < 0)
101  return ret;
102  }
103 
104  ret = av_packet_ref(&input_ref, avpkt);
105  if (ret < 0)
106  return ret;
107  av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL);
108  }
109 
110  /* process buffered data */
111  while (!*got_frame) {
112  if (s->input_ref.size <= 0) {
113  /* no more data */
114  if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket))
115  return avpkt->size ? avpkt->size : ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, avpkt);
116 
119  }
120 
121  ret = ff_qsv_process_data(avctx, &s->qsv, frame, got_frame, &s->input_ref);
122  if (ret < 0)
123  return ret;
124 
125  s->input_ref.size -= ret;
126  s->input_ref.data += ret;
127  }
128 
129  return avpkt->size;
130 }
131 
132 static void qsv_decode_flush(AVCodecContext *avctx)
133 {
134  QSVVC1Context *s = avctx->priv_data;
135 
137  ff_qsv_decode_flush(avctx, &s->qsv);
138 }
139 
141  .name = "vc1_qsv",
142  .type = AVMEDIA_TYPE_VIDEO,
143  .id = AV_CODEC_ID_VC1,
144  .pix_fmt = AV_PIX_FMT_QSV,
145 };
146 
147 #define OFFSET(x) offsetof(QSVVC1Context, x)
148 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
149 static const AVOption options[] = {
150  { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
151  { NULL },
152 };
153 
154 static const AVClass class = {
155  .class_name = "vc1_qsv",
156  .item_name = av_default_item_name,
157  .option = options,
159 };
160 
162  .name = "vc1_qsv",
163  .long_name = NULL_IF_CONFIG_SMALL("VC-1 video (Intel Quick Sync Video acceleration)"),
164  .priv_data_size = sizeof(QSVVC1Context),
166  .id = AV_CODEC_ID_VC1,
170  .close = qsv_decode_close,
172  .priv_class = &class,
173  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
175  AV_PIX_FMT_NONE },
176 };
#define VD
Definition: qsvdec_vc1.c:148
QSVContext qsv
Definition: qsvdec_vc1.c:38
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
static const AVOption options[]
Definition: qsvdec_vc1.c:149
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVHWAccel ff_vc1_qsv_hwaccel
Definition: qsvdec_vc1.c:140
int size
Definition: avcodec.h:1648
static AVPacket pkt
AVCodec.
Definition: avcodec.h:3671
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
Definition: fifo.c:122
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:1019
#define av_cold
Definition: attributes.h:82
AVOptions.
int ff_qsv_decode_close(QSVContext *q)
Definition: qsvdec.c:402
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
Definition: fifo.c:82
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1647
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
static int qsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: qsvdec_vc1.c:86
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:584
static av_cold int qsv_decode_close(AVCodecContext *avctx)
Definition: qsvdec_vc1.c:56
AVFifoBuffer * packet_fifo
Definition: qsvdec_vc1.c:40
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define OFFSET(x)
Definition: qsvdec_vc1.c:147
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
Definition: fifo.c:213
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:90
const char * name
Name of the codec implementation.
Definition: avcodec.h:3678
#define fail()
Definition: checkasm.h:89
void ff_qsv_decode_flush(AVCodecContext *avctx, QSVContext *q)
Definition: qsvdec.c:517
#define ASYNC_DEPTH_DEFAULT
Definition: qsv_internal.h:33
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3797
static void qsv_clear_buffers(QSVVC1Context *s)
Definition: qsvdec_vc1.c:45
AVPacket input_ref
Definition: qsvdec_vc1.c:42
Libavcodec external API header.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
Definition: fifo.c:77
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Definition: fifo.c:87
main external API structure.
Definition: avcodec.h:1722
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:575
a very simple circular buffer FIFO implementation
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:236
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
AVCodec ff_vc1_qsv_decoder
Definition: qsvdec_vc1.c:161
static av_cold int qsv_decode_init(AVCodecContext *avctx)
Definition: qsvdec_vc1.c:69
common internal api header.
common internal and external API header
void * priv_data
Definition: avcodec.h:1764
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: avcodec.h:1083
static void qsv_decode_flush(AVCodecContext *avctx)
Definition: qsvdec_vc1.c:132
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2246
int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: qsvdec.c:441
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1624
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:994