26#include "config_components.h"
28#define VPX_CODEC_DISABLE_COMPAT 1
29#include <vpx/vpx_decoder.h>
30#include <vpx/vpx_frame_buffer.h>
43typedef struct VPxDecoderContext {
44 const struct vpx_codec_iface *
iface;
58 if (min_size >
ctx->pool_size) {
66 ctx->pool_size = min_size;
91 struct vpx_codec_dec_cfg deccfg = {
98 if (vpx_codec_dec_init(
decoder,
ctx->iface, &deccfg, 0) != VPX_CODEC_OK) {
105 if (vpx_codec_get_caps(
ctx->iface) & VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER) {
118 int has_alpha_channel)
124#if VPX_IMAGE_ABI_VERSION >= 4
134 case VPX_IMG_FMT_I420:
140#if CONFIG_LIBVPX_VP9_DECODER
141 case VPX_IMG_FMT_I422:
146 case VPX_IMG_FMT_I440:
151 case VPX_IMG_FMT_I444:
157 case VPX_IMG_FMT_I42016:
159 if (
img->bit_depth == 10) {
163 }
else if (
img->bit_depth == 12) {
170 case VPX_IMG_FMT_I42216:
172 if (
img->bit_depth == 10) {
176 }
else if (
img->bit_depth == 12) {
183 case VPX_IMG_FMT_I44016:
186 if (
img->bit_depth == 10) {
189 }
else if (
img->bit_depth == 12) {
195 case VPX_IMG_FMT_I44416:
197 if (
img->bit_depth == 10) {
202 }
else if (
img->bit_depth == 12) {
217 const uint8_t *
data, uint32_t data_sz)
219 if (vpx_codec_decode(
decoder,
data, data_sz,
NULL, 0) != VPX_CODEC_OK) {
221 const char *detail = vpx_codec_error_detail(
decoder);
237 const void *iter =
NULL;
238 const void *iter_alpha =
NULL;
239 struct vpx_image *
img, *img_alpha;
241 uint8_t *side_data =
NULL;
242 size_t side_data_size;
251 if (side_data_size >= 8) {
252 const uint64_t additional_id =
AV_RB64(side_data);
255 if (additional_id == 1) {
256 if (!
ctx->has_alpha_channel) {
257 ctx->has_alpha_channel = 1;
269 if ((
img = vpx_codec_get_frame(&
ctx->decoder, &iter)) &&
270 (!
ctx->has_alpha_channel ||
271 (img_alpha = vpx_codec_get_frame(&
ctx->decoder_alpha, &iter_alpha)))) {
283 img->fmt,
img->bit_depth);
295 if (
ctx->has_alpha_channel &&
296 (
img->d_w != img_alpha->d_w ||
297 img->d_h != img_alpha->d_h ||
298 img->bit_depth != img_alpha->bit_depth)) {
300 "Video dimensions %dx%d@%dbpc differ from alpha dimensions %dx%d@%dbpc\n",
302 img_alpha->d_w, img_alpha->d_h, img_alpha->bit_depth);
310 ctx->has_alpha_channel ? img_alpha->planes[VPX_PLANE_Y] :
NULL;
311 linesizes[0] =
img->stride[VPX_PLANE_Y];
312 linesizes[1] =
img->stride[VPX_PLANE_U];
313 linesizes[2] =
img->stride[VPX_PLANE_V];
315 ctx->has_alpha_channel ? img_alpha->stride[VPX_PLANE_Y] : 0;
317 if (vpx_codec_get_caps(
ctx->iface) & VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER) {
322 if (!picture->
buf[0])
324 if (
ctx->has_alpha_channel) {
326 if (!picture->
buf[1])
329 for (
int i = 0;
i < 4;
i++) {
347 vpx_codec_destroy(&
ctx->decoder);
348 if (
ctx->has_alpha_channel)
349 vpx_codec_destroy(&
ctx->decoder_alpha);
354#if CONFIG_LIBVPX_VP8_DECODER
358 ctx->iface = vpx_codec_vp8_dx();
368 .p.wrapper_name =
"libvpx",
378#if CONFIG_LIBVPX_VP9_DECODER
382 ctx->iface = vpx_codec_vp9_dx();
387 .p.name =
"libvpx-vp9",
393 .p.wrapper_name =
"libvpx",
const FFCodec ff_libvpx_vp8_decoder
const FFCodec ff_libvpx_vp9_decoder
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal and external API header
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.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
#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.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
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(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(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.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
static const chunk_decoder decoder[8]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int vpx_init(AVCodecContext *avctx, struct vpx_codec_ctx *decoder)
static int release_frame_buffer(void *priv, vpx_codec_frame_buffer_t *fb)
static av_cold int vpx_free(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, vpx_codec_ctx_t *decoder, const uint8_t *data, uint32_t data_sz)
static int vpx_decode(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img, int has_alpha_channel)
static int get_frame_buffer(void *priv, size_t min_size, vpx_codec_frame_buffer_t *fb)
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define AV_PIX_FMT_GBRAP12
#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_YUVA444P10
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUVA422P10
@ 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_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P10
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 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), YZX and ST 428-1
@ 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 / functionally identical to above
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
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.
size_t size
Size of data in bytes.
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()
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, a positive or negative value, which is typically indicating the size in bytes of each pict...
This structure stores compressed data.
struct vpx_codec_ctx decoder
const struct vpx_codec_iface * iface
struct vpx_codec_ctx decoder_alpha
static void error(const char *err)