FFmpeg
videotoolbox_av1.c
Go to the documentation of this file.
1 /*
2  * Videotoolbox hardware acceleration for AV1
3  * Copyright (c) 2023 Jan Ekström
4  * Copyright (c) 2024 Ruslan Chernenko
5  * Copyright (c) 2024 Martin Storsjö
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/mem.h"
25 
26 #include "av1dec.h"
27 #include "hwaccel_internal.h"
28 #include "internal.h"
29 #include "vt_internal.h"
30 
32 {
33  AV1DecContext *s = avctx->priv_data;
34  uint8_t *buf;
35  CFDataRef data;
36  if (!s->raw_seq)
37  return NULL;
38 
39  buf = av_malloc(s->seq_data_ref->size + 4);
40  if (!buf)
41  return NULL;
42  buf[0] = 0x81; // version and marker (constant)
43  buf[1] = s->raw_seq->seq_profile << 5 | s->raw_seq->seq_level_idx[0];
44  buf[2] = s->raw_seq->seq_tier[0] << 7 |
45  s->raw_seq->color_config.high_bitdepth << 6 |
46  s->raw_seq->color_config.twelve_bit << 5 |
47  s->raw_seq->color_config.mono_chrome << 4 |
48  s->raw_seq->color_config.subsampling_x << 3 |
49  s->raw_seq->color_config.subsampling_y << 2 |
50  s->raw_seq->color_config.chroma_sample_position;
51 
52  if (s->raw_seq->initial_display_delay_present_flag)
53  buf[3] = 0 << 5 |
54  s->raw_seq->initial_display_delay_present_flag << 4 |
55  s->raw_seq->initial_display_delay_minus_1[0];
56  else
57  buf[3] = 0x00;
58  memcpy(buf + 4, s->seq_data_ref->data, s->seq_data_ref->size);
59  data = CFDataCreate(kCFAllocatorDefault, buf, s->seq_data_ref->size + 4);
60  av_free(buf);
61  return data;
62 };
63 
64 
66  const uint8_t *buffer,
67  uint32_t size)
68 {
69  return 0;
70 }
71 
73  const uint8_t *buffer,
74  uint32_t size)
75 {
76  return 0;
77 }
78 
80 {
81  const AV1DecContext *s = avctx->priv_data;
82  VTContext *vtctx = avctx->internal->hwaccel_priv_data;
83  AVFrame *frame = s->cur_frame.f;
84 
85  vtctx->bitstream_size = 0;
86  for (int i = s->start_unit; i < s->nb_unit; i++)
87  ff_videotoolbox_buffer_append(vtctx, s->current_obu.units[i].data,
88  s->current_obu.units[i].data_size);
90 }
91 
93  .p.name = "av1_videotoolbox",
94  .p.type = AVMEDIA_TYPE_VIDEO,
95  .p.id = AV_CODEC_ID_AV1,
96  .p.pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX,
97  .alloc_frame = ff_videotoolbox_alloc_frame,
98  .start_frame = videotoolbox_av1_start_frame,
99  .decode_slice = videotoolbox_av1_decode_slice,
100  .end_frame = videotoolbox_av1_end_frame,
101  .frame_params = ff_videotoolbox_frame_params,
103  .uninit = ff_videotoolbox_uninit,
104  .priv_data_size = sizeof(VTContext),
105 };
ff_videotoolbox_common_end_frame
int ff_videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
ff_av1_videotoolbox_hwaccel
const FFHWAccel ff_av1_videotoolbox_hwaccel
Definition: videotoolbox_av1.c:92
ff_videotoolbox_uninit
int ff_videotoolbox_uninit(AVCodecContext *avctx)
videotoolbox_av1_start_frame
static int videotoolbox_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: videotoolbox_av1.c:65
ff_videotoolbox_buffer_append
int ff_videotoolbox_buffer_append(VTContext *vtctx, const uint8_t *buffer, uint32_t size)
Definition: videotoolbox.c:99
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
internal.h
data
const char data[16]
Definition: mxf.c:149
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
FFHWAccel
Definition: hwaccel_internal.h:34
ff_videotoolbox_common_init
int ff_videotoolbox_common_init(AVCodecContext *avctx)
vt_internal.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
av1dec.h
VTContext::bitstream_size
int bitstream_size
Definition: vt_internal.h:30
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
hwaccel_internal.h
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:486
ff_videotoolbox_frame_params
int ff_videotoolbox_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:130
size
int size
Definition: twinvq_data.h:10344
AV1DecContext
Definition: av1dec.h:85
videotoolbox_av1_decode_slice
static int videotoolbox_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: videotoolbox_av1.c:72
ff_videotoolbox_av1c_extradata_create
CFDataRef ff_videotoolbox_av1c_extradata_create(AVCodecContext *avctx)
Definition: videotoolbox_av1.c:31
VTContext
Definition: vt_internal.h:25
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2105
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_videotoolbox_alloc_frame
int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: videotoolbox.c:150
AVCodecContext
main external API structure.
Definition: avcodec.h:451
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
videotoolbox_av1_end_frame
static int videotoolbox_av1_end_frame(AVCodecContext *avctx)
Definition: videotoolbox_av1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478