FFmpeg
Loading...
Searching...
No Matches
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 AVBufferRef *buffer_ref,
67 const uint8_t *buffer,
68 uint32_t size)
69{
70 return 0;
71}
72
74 const uint8_t *buffer,
75 uint32_t size)
76{
77 return 0;
78}
79
81{
82 const AV1DecContext *s = avctx->priv_data;
83 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
84 AVFrame *frame = s->cur_frame.f;
85
86 vtctx->bitstream_size = 0;
87 for (int i = s->start_unit; i < s->nb_unit; i++)
88 ff_videotoolbox_buffer_append(vtctx, s->current_obu.units[i].data,
89 s->current_obu.units[i].data_size);
91}
92
94 .p.name = "av1_videotoolbox",
95 .p.type = AVMEDIA_TYPE_VIDEO,
96 .p.id = AV_CODEC_ID_AV1,
97 .p.pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX,
98 .alloc_frame = ff_videotoolbox_alloc_frame,
99 .start_frame = videotoolbox_av1_start_frame,
100 .decode_slice = videotoolbox_av1_decode_slice,
101 .end_frame = videotoolbox_av1_end_frame,
102 .frame_params = ff_videotoolbox_frame_params,
104 .uninit = ff_videotoolbox_uninit,
105 .priv_data_size = sizeof(VTContext),
106};
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVFrame * frame
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
const struct FFHWAccel ff_av1_videotoolbox_hwaccel
common internal api header.
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
@ 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
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
int bitstream_size
Definition vt_internal.h:30
#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_append(VTContext *vtctx, const uint8_t *buffer, uint32_t size)
static int videotoolbox_av1_end_frame(AVCodecContext *avctx)
static int videotoolbox_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
CFDataRef ff_videotoolbox_av1c_extradata_create(AVCodecContext *avctx)
static int videotoolbox_av1_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, const uint8_t *buffer, uint32_t size)
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)