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> 39 typedef struct VPxDecoderContext {
41 struct vpx_codec_ctx decoder_alpha;
84 const struct vpx_codec_iface *iface)
86 struct vpx_codec_dec_cfg deccfg = {
93 if (vpx_codec_dec_init(decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
94 const char *
error = vpx_codec_error(decoder);
108 int has_alpha_channel)
114 #if VPX_IMAGE_ABI_VERSION >= 4 124 case VPX_IMG_FMT_I420:
130 #if CONFIG_LIBVPX_VP9_DECODER 131 case VPX_IMG_FMT_I422:
135 case VPX_IMG_FMT_I440:
139 case VPX_IMG_FMT_I444:
144 case VPX_IMG_FMT_I42016:
146 if (img->bit_depth == 10) {
149 }
else if (img->bit_depth == 12) {
155 case VPX_IMG_FMT_I42216:
157 if (img->bit_depth == 10) {
160 }
else if (img->bit_depth == 12) {
166 case VPX_IMG_FMT_I44016:
168 if (img->bit_depth == 10) {
171 }
else if (img->bit_depth == 12) {
177 case VPX_IMG_FMT_I44416:
179 if (img->bit_depth == 10) {
183 }
else if (img->bit_depth == 12) {
199 if (vpx_codec_decode(decoder, data, data_sz,
NULL, 0) != VPX_CODEC_OK) {
200 const char *
error = vpx_codec_error(decoder);
201 const char *detail = vpx_codec_error_detail(decoder);
218 const void *iter =
NULL;
219 const void *iter_alpha =
NULL;
220 struct vpx_image *
img, *img_alpha;
223 int side_data_size = 0;
232 if (side_data_size >= 8) {
233 const uint64_t additional_id =
AV_RB64(side_data);
236 if (additional_id == 1) {
243 &vpx_codec_vp8_dx_algo : &vpx_codec_vp9_dx_algo
245 &vpx_codec_vp8_dx_algo
247 &vpx_codec_vp9_dx_algo
260 if ((img = vpx_codec_get_frame(&ctx->
decoder, &iter)) &&
262 (img_alpha = vpx_codec_get_frame(&ctx->
decoder_alpha, &iter_alpha)))) {
266 if (img->d_w > img->w || img->d_h > img->h) {
268 img->d_w, img->d_h, img->w, img->h);
274 img->fmt, img->bit_depth);
278 if ((
int) img->d_w != avctx->
width || (
int) img->d_h != avctx->
height) {
287 (img->d_w != img_alpha->d_w ||
288 img->d_h != img_alpha->d_h ||
289 img->bit_depth != img_alpha->bit_depth)) {
291 "Video dimensions %dx%d@%dbpc differ from alpha dimensions %dx%d@%dbpc\n",
292 img->d_w, img->d_h, img->bit_depth,
293 img_alpha->d_w, img_alpha->d_h, img_alpha->bit_depth);
297 planes[0] = img->planes[VPX_PLANE_Y];
298 planes[1] = img->planes[VPX_PLANE_U];
299 planes[2] = img->planes[VPX_PLANE_V];
302 linesizes[0] = img->stride[VPX_PLANE_Y];
303 linesizes[1] = img->stride[VPX_PLANE_U];
304 linesizes[2] = img->stride[VPX_PLANE_V];
313 if (!picture->
buf[0])
317 if (!picture->
buf[1]) {
322 for (
int i = 0;
i < 4;
i++) {
323 picture->
data[
i] = planes[
i];
330 linesizes, avctx->
pix_fmt, img->d_w, img->d_h);
340 vpx_codec_destroy(&ctx->
decoder);
347 #if CONFIG_LIBVPX_VP8_DECODER 364 .wrapper_name =
"libvpx",
368 #if CONFIG_LIBVPX_VP9_DECODER 376 .
name =
"libvpx-vp9",
387 .wrapper_name =
"libvpx",
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_PIX_FMT_YUV440P10
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
static int get_frame_buffer(void *priv, size_t min_size, vpx_codec_frame_buffer_t *fb)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static av_cold int vpx_free(AVCodecContext *avctx)
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.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_GBRP10
AVCodec ff_libvpx_vp8_decoder
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
static void error(const char *err)
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
functionally identical to above
static av_cold int vpx_init(AVCodecContext *avctx, struct vpx_codec_ctx *decoder, const struct vpx_codec_iface *iface)
#define CONFIG_LIBVPX_VP8_DECODER
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVColorSpace
YUV colorspace type.
#define AV_LOG_VERBOSE
Detailed information.
AVColorRange
MPEG vs JPEG YUV range.
#define AV_PIX_FMT_YUV422P12
static int vpx_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define i(width, name, range_min, range_max)
AVCodec ff_libvpx_vp9_decoder
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
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.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
struct vpx_codec_ctx decoder
struct vpx_codec_ctx decoder_alpha
static const struct @315 planes[]
static const chunk_decoder decoder[8]
int width
picture width / height.
static av_cold void init_static_data(void)
ITU-R BT2020 non-constant luminance system.
#define CONFIG_LIBVPX_VP9_DECODER
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
av_cold void ff_vp9_init_static(AVCodec *codec)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img, int has_alpha_channel)
main external API structure.
uint8_t * data
The data buffer.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Data found in BlockAdditional element of matroska container.
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
#define AV_PIX_FMT_YUV420P10
static const AVProfile profiles[]
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
enum AVColorSpace colorspace
YUV colorspace type.
#define AV_PIX_FMT_YUV440P12
int size
Size of data in bytes.
#define AV_PIX_FMT_GBRP12
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
A reference to a data buffer.
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int decode_frame(AVCodecContext *avctx, vpx_codec_ctx_t *decoder, uint8_t *data, uint32_t data_sz)
common internal api header.
static int release_frame_buffer(void *priv, vpx_codec_frame_buffer_t *fb)
common internal and external API header
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
const AVProfile ff_vp9_profiles[]
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.