FFmpeg
Loading...
Searching...
No Matches
videotoolbox_vp9.c
Go to the documentation of this file.
1/*
2 * Videotoolbox hardware acceleration for VP9
3 *
4 * copyright (c) 2021 rcombs
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "config.h"
24#include "videotoolbox.h"
26#include "libavutil/mem.h"
27#include "vt_internal.h"
28#include "libavutil/avassert.h"
29#include "libavutil/avutil.h"
30#include "libavutil/frame.h"
31#include "libavutil/hwcontext.h"
33#include "libavutil/pixdesc.h"
34#include "decode.h"
35#include "hwaccel_internal.h"
36#include "internal.h"
37#include "vp9shared.h"
38
46
47static int get_vpx_chroma_subsampling(enum AVPixelFormat pixel_format,
48 enum AVChromaLocation chroma_location)
49{
50 int chroma_w, chroma_h;
51 if (av_pix_fmt_get_chroma_sub_sample(pixel_format, &chroma_w, &chroma_h) == 0) {
52 if (chroma_w == 1 && chroma_h == 1) {
53 return (chroma_location == AVCHROMA_LOC_LEFT)
56 } else if (chroma_w == 1 && chroma_h == 0) {
58 } else if (chroma_w == 0 && chroma_h == 0) {
60 }
61 }
62 return -1;
63}
64
66{
67 const VP9SharedContext *h = avctx->priv_data;
68 CFDataRef data = NULL;
69 uint8_t *p;
70 int vt_extradata_size;
71 uint8_t *vt_extradata;
72 int subsampling = get_vpx_chroma_subsampling(avctx->sw_pix_fmt, avctx->chroma_sample_location);
73
74 if (subsampling < 0)
75 return NULL;
76
77 vt_extradata_size = 1 + 3 + 6 + 2;
78 vt_extradata = av_malloc(vt_extradata_size);
79
80 if (!vt_extradata)
81 return NULL;
82
83 p = vt_extradata;
84
85 *p++ = 1; /* version */
86 AV_WB24(p, 0); /* flags */
87 p += 3;
88
89 *p++ = h->h.profile;
90 *p++ = avctx->level;
91 *p++ = (h->h.bpp << 4) | (subsampling << 1) | (avctx->color_range == AVCOL_RANGE_JPEG);
92 *p++ = avctx->color_primaries;
93 *p++ = avctx->color_trc;
94 *p++ = avctx->colorspace;
95
96 AV_WB16(p + 0, 0);
97 p += 2;
98
99 av_assert0(p - vt_extradata == vt_extradata_size);
100
101 data = CFDataCreate(kCFAllocatorDefault, vt_extradata, vt_extradata_size);
102 av_free(vt_extradata);
103 return data;
104}
105
107 const AVBufferRef *buffer_ref,
108 const uint8_t *buffer,
109 uint32_t size)
110{
111 return 0;
112}
113
115 const uint8_t *buffer,
116 uint32_t size)
117{
118 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
119
121}
122
124{
125 const VP9SharedContext *h = avctx->priv_data;
126 AVFrame *frame = h->frames[CUR_FRAME].tf.f;
127
129}
130
132 .p.name = "vp9_videotoolbox",
133 .p.type = AVMEDIA_TYPE_VIDEO,
134 .p.id = AV_CODEC_ID_VP9,
135 .p.pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX,
136 .alloc_frame = ff_videotoolbox_alloc_frame,
137 .start_frame = videotoolbox_vp9_start_frame,
138 .decode_slice = videotoolbox_vp9_decode_slice,
139 .end_frame = videotoolbox_vp9_end_frame,
140 .frame_params = ff_videotoolbox_frame_params,
142 .uninit = ff_videotoolbox_uninit,
143 .priv_data_size = sizeof(VTContext),
144};
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Convenience header that includes libavutil's core.
#define NULL
Definition coverity.c:32
static AVFrame * frame
reference-counted frame API
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
const struct FFHWAccel ff_vp9_videotoolbox_hwaccel
An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
#define AV_WB24(p, d)
#define AV_WB16(p, v)
common internal api header.
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition pixdesc.c:3488
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:802
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:804
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition pixfmt.h:305
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:650
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
int level
Encoding level descriptor.
Definition avcodec.h:1646
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:688
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
void * priv_data
Definition avcodec.h:470
void * hwaccel_priv_data
hwaccel-specific private data
Definition internal.h:130
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
#define av_free(p)
static char buffer[20]
Definition seek.c:32
int size
int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
int ff_videotoolbox_buffer_copy(VTContext *vtctx, const uint8_t *buffer, uint32_t size)
Public libavcodec Videotoolbox header.
VPX_CHROMA_SUBSAMPLING
@ VPX_SUBSAMPLING_422
@ VPX_SUBSAMPLING_444
@ VPX_SUBSAMPLING_420_VERTICAL
@ VPX_SUBSAMPLING_420_COLLOCATED_WITH_LUMA
static int get_vpx_chroma_subsampling(enum AVPixelFormat pixel_format, enum AVChromaLocation chroma_location)
static int videotoolbox_vp9_end_frame(AVCodecContext *avctx)
static int videotoolbox_vp9_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
static int videotoolbox_vp9_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
CFDataRef ff_videotoolbox_vpcc_extradata_create(AVCodecContext *avctx)
#define CUR_FRAME
Definition vp9shared.h:172
int ff_videotoolbox_common_init(AVCodecContext *avctx)
int ff_videotoolbox_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
int ff_videotoolbox_uninit(AVCodecContext *avctx)
int ff_videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)