26 #define VPX_CODEC_DISABLE_COMPAT 1
27 #include <vpx/vpx_decoder.h>
28 #include <vpx/vpx_frame_buffer.h>
29 #include <vpx/vp8dx.h>
40 typedef struct VPxDecoderContext {
42 struct vpx_codec_ctx decoder_alpha;
54 if (min_size >
ctx->pool_size) {
62 ctx->pool_size = min_size;
70 fb->size =
ctx->pool_size;
85 const struct vpx_codec_iface *iface)
87 struct vpx_codec_dec_cfg deccfg = {
94 if (vpx_codec_dec_init(
decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
109 int has_alpha_channel)
115 #if VPX_IMAGE_ABI_VERSION >= 4
125 case VPX_IMG_FMT_I420:
131 #if CONFIG_LIBVPX_VP9_DECODER
132 case VPX_IMG_FMT_I422:
136 case VPX_IMG_FMT_I440:
140 case VPX_IMG_FMT_I444:
145 case VPX_IMG_FMT_I42016:
147 if (
img->bit_depth == 10) {
150 }
else if (
img->bit_depth == 12) {
156 case VPX_IMG_FMT_I42216:
158 if (
img->bit_depth == 10) {
161 }
else if (
img->bit_depth == 12) {
167 case VPX_IMG_FMT_I44016:
169 if (
img->bit_depth == 10) {
172 }
else if (
img->bit_depth == 12) {
178 case VPX_IMG_FMT_I44416:
180 if (
img->bit_depth == 10) {
184 }
else if (
img->bit_depth == 12) {
200 if (vpx_codec_decode(
decoder,
data, data_sz,
NULL, 0) != VPX_CODEC_OK) {
202 const char *detail = vpx_codec_error_detail(
decoder);
219 const void *iter =
NULL;
220 const void *iter_alpha =
NULL;
221 struct vpx_image *
img, *img_alpha;
233 if (side_data_size >= 8) {
234 const uint64_t additional_id =
AV_RB64(side_data);
237 if (additional_id == 1) {
238 if (!
ctx->has_alpha_channel) {
239 ctx->has_alpha_channel = 1;
244 &vpx_codec_vp8_dx_algo : &vpx_codec_vp9_dx_algo
246 &vpx_codec_vp8_dx_algo
248 &vpx_codec_vp9_dx_algo
261 if ((
img = vpx_codec_get_frame(&
ctx->decoder, &iter)) &&
262 (!
ctx->has_alpha_channel ||
263 (img_alpha = vpx_codec_get_frame(&
ctx->decoder_alpha, &iter_alpha)))) {
275 img->fmt,
img->bit_depth);
287 if (
ctx->has_alpha_channel &&
288 (
img->d_w != img_alpha->d_w ||
289 img->d_h != img_alpha->d_h ||
290 img->bit_depth != img_alpha->bit_depth)) {
292 "Video dimensions %dx%d@%dbpc differ from alpha dimensions %dx%d@%dbpc\n",
294 img_alpha->d_w, img_alpha->d_h, img_alpha->bit_depth);
302 ctx->has_alpha_channel ? img_alpha->planes[VPX_PLANE_Y] :
NULL;
303 linesizes[0] =
img->stride[VPX_PLANE_Y];
304 linesizes[1] =
img->stride[VPX_PLANE_U];
305 linesizes[2] =
img->stride[VPX_PLANE_V];
307 ctx->has_alpha_channel ? img_alpha->stride[VPX_PLANE_Y] : 0;
309 if (
img->fb_priv && (!
ctx->has_alpha_channel || img_alpha->fb_priv)) {
314 if (!picture->
buf[0])
316 if (
ctx->has_alpha_channel) {
318 if (!picture->
buf[1]) {
323 for (
int i = 0;
i < 4;
i++) {
341 vpx_codec_destroy(&
ctx->decoder);
342 if (
ctx->has_alpha_channel)
343 vpx_codec_destroy(&
ctx->decoder_alpha);
348 #if CONFIG_LIBVPX_VP8_DECODER
352 return vpx_init(avctx, &
ctx->decoder, &vpx_codec_vp8_dx_algo);
366 .wrapper_name =
"libvpx",
370 #if CONFIG_LIBVPX_VP9_DECODER
374 return vpx_init(avctx, &
ctx->decoder, &vpx_codec_vp9_dx_algo);
378 .
name =
"libvpx-vp9",
390 .wrapper_name =
"libvpx",
AVCodec ff_libvpx_vp8_decoder
AVCodec ff_libvpx_vp9_decoder
Libavcodec external API header.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
static av_cold int init(AVCodecContext *avctx)
common internal and external API header
#define CONFIG_LIBVPX_VP9_DECODER
#define CONFIG_LIBVPX_VP8_DECODER
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_allocz(buffer_size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferPool * av_buffer_pool_init(buffer_size_t size, AVBufferRef *(*alloc)(buffer_size_t size))
Allocate and initialize a buffer pool.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
static const chunk_decoder decoder[8]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVProfile profiles[]
av_cold void ff_vp9_init_static(AVCodec *codec)
static int release_frame_buffer(void *priv, vpx_codec_frame_buffer_t *fb)
static int decode_frame(AVCodecContext *avctx, vpx_codec_ctx_t *decoder, uint8_t *data, uint32_t data_sz)
static av_cold int vpx_free(AVCodecContext *avctx)
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img, int has_alpha_channel)
static int vpx_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int vpx_init(AVCodecContext *avctx, struct vpx_codec_ctx *decoder, const struct vpx_codec_iface *iface)
static int get_frame_buffer(void *priv, size_t min_size, vpx_codec_frame_buffer_t *fb)
static const struct @322 planes[]
static av_cold void init_static_data(void)
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV444P10
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
@ AVCOL_SPC_SMPTE240M
functionally identical to above
const AVProfile ff_vp9_profiles[]
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
A reference to a data buffer.
uint8_t * data
The data buffer.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
This structure stores compressed data.
static void error(const char *err)