[vlc-commits] [Git][videolan/vlc][master] codec: videotoolbox: add VP9 hardware decoding

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat Nov 7 06:50:05 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
b53d8f02 by François Cartegnie at 2026-11-07T07:32:38+01:00
codec: videotoolbox: add VP9 hardware decoding

This works on recent Intel Macs, Apple Silicon Macs and
on some iOS devices running iOS 26.2 or newer.

Co-authored-by: Marvin Scholz <epirat07 at gmail.com>
Co-authored-by: Felix Paul Kühne <fkuehne at videolan.org>

- - - - -


7 changed files:

- modules/codec/Makefile.am
- modules/codec/meson.build
- modules/codec/videotoolbox/decoder.c
- + modules/codec/videotoolbox/vp9_repack.c
- + modules/codec/videotoolbox/vp9_repack.h
- + modules/packetizer/vp9_frame.c
- + modules/packetizer/vp9_frame.h


Changes:

=====================================
modules/codec/Makefile.am
=====================================
@@ -347,7 +347,11 @@ libvideotoolbox_plugin_la_SOURCES = codec/videotoolbox/decoder.c \
                                     codec/videotoolbox/dpb.c \
                                     codec/videotoolbox/dpb.h \
                                     codec/videotoolbox/pacer.c \
-                                    codec/videotoolbox/pacer.h
+                                    codec/videotoolbox/pacer.h \
+                                    codec/videotoolbox/vp9_repack.c \
+                                    codec/videotoolbox/vp9_repack.h \
+                                    packetizer/vp9_frame.c \
+                                    packetizer/vp9_frame.h
 libvideotoolbox_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) # Trigger MODULE_NAME declaration
 libvideotoolbox_plugin_la_LIBADD = libchroma_copy.la libvlc_hxxxhelper.la libvlc_vtutils.la
 libvideotoolbox_plugin_la_LDFLAGS = $(AM_LDFLAGS) -Wl,-framework,CoreFoundation -Wl,-framework,VideoToolbox -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo -Wl,-framework,Metal


=====================================
modules/codec/meson.build
=====================================
@@ -595,6 +595,10 @@ if host_system == 'darwin'
             'videotoolbox/dpb.h',
             'videotoolbox/pacer.c',
             'videotoolbox/pacer.h',
+            'videotoolbox/vp9_repack.c',
+            'videotoolbox/vp9_repack.h',
+            '../packetizer/vp9_frame.c',
+            '../packetizer/vp9_frame.h'
         ),
         'dependencies' : [
             frameworks['VideoToolbox'],


=====================================
modules/codec/videotoolbox/decoder.c
=====================================
@@ -37,6 +37,8 @@
 #import "../../packetizer/h264_slice.h"
 #import "../../packetizer/hxxx_nal.h"
 #import "../../packetizer/hxxx_sei.h"
+#import "../../packetizer/vp9_frame.h"
+#import "vp9_repack.h"
 #import "pacer.h"
 #import "dpb.h"
 
@@ -53,6 +55,14 @@
 #define VT_ALIGNMENT 16
 #define VT_RESTART_MAX 1
 
+#pragma mark - Compat
+
+#if (!TARGET_OS_OSX    || __MAC_OS_X_VERSION_MAX_ALLOWED   < 110000) && \
+    (!TARGET_OS_IPHONE || __IPHONE_OS_VERSION_MAX_ALLOWED  < 140000) && \
+    (!TARGET_OS_TV     || __TV_OS_VERSION_MAX_ALLOWED      < 140000)
+enum { kCMVideoCodecType_VP9 = 'vp09' };
+#endif
+
 #pragma mark - local prototypes
 
 enum vtsession_status
@@ -872,6 +882,139 @@ static CFDictionaryRef CopyDecoderExtradataMPEG4(decoder_t *p_dec)
         return NULL; /* MPEG4 without esds ? */
 }
 
+/** VP9 Specific */
+
+struct vt_vp9_context
+{
+    struct vp9_uncompressed_header vp9_header;
+    struct vp9_repacker vp9_repacker;
+};
+
+static void CleanVP9(void *p_codec_context)
+{
+    struct vt_vp9_context *vp9ctx = p_codec_context;
+    vp9_repacker_Clean(&vp9ctx->vp9_repacker);
+    free(vp9ctx);
+}
+
+static bool InitVP9(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+#if (TARGET_OS_OSX && defined(MAC_OS_VERSION_11_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0) || \
+    (TARGET_OS_IOS && defined(__IPHONE_26_2) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_2) || \
+    (TARGET_OS_TV && defined(__TVOS_26_2) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_26_2)
+    if(__builtin_available(macOS 11.0, iOS 26.2, tvOS 26.2, *))
+        VTRegisterSupplementalVideoDecoderIfAvailable(kCMVideoCodecType_VP9);
+#endif
+
+    if(__builtin_available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
+        if (!VTIsHardwareDecodeSupported(kCMVideoCodecType_VP9))
+            return false;
+    } else {
+        return false;
+    }
+
+    struct vt_vp9_context *ctx = malloc(sizeof(*ctx));
+    if(!ctx)
+        return false;
+    p_sys->p_codec_context = ctx;
+    vp9_repacker_Init(&ctx->vp9_repacker);
+    memset(&ctx->vp9_header, 0, sizeof(ctx->vp9_header));
+    return true;
+}
+
+static bool CodecSupportedVP9(decoder_t *p_dec)
+{
+    return p_dec->fmt_in->i_profile == 0 ||
+           p_dec->fmt_in->i_profile == 2;
+}
+
+static CFDictionaryRef CopyDecoderExtradataVP9(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    struct vt_vp9_context *vp9ctx = p_sys->p_codec_context;
+
+    CFDictionaryRef extradata = NULL;
+    if (p_dec->fmt_in->i_extra)
+    {
+        /* copy DecoderConfiguration */
+        extradata = ExtradataInfoCreate(CFSTR("vpcC"),
+                                        p_dec->fmt_in->p_extra,
+                                        p_dec->fmt_in->i_extra);
+    }
+    else
+    {
+        uint8_t dcr[VP9_DECODER_CONFIG_SIZE];
+        int level = p_dec->fmt_in->i_level;
+        if (es_format_HasVpxAlpha(p_dec->fmt_in))
+            level = level & ~0x1000;
+
+        if(vp9_fill_decoder_config(&vp9ctx->vp9_header,
+                                   level,
+                                   p_dec->fmt_in->video.chroma_location,
+                                   dcr))
+            extradata = ExtradataInfoCreate(CFSTR("vpcC"),
+                                            dcr, VP9_DECODER_CONFIG_SIZE);
+    }
+    return extradata;
+}
+
+static bool LateStartVP9(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    struct vt_vp9_context *vp9ctx = p_sys->p_codec_context;
+    return (p_dec->fmt_in->i_extra == 0 && vp9ctx->vp9_header.bit_depth == 0);
+}
+
+static block_t *ProcessBlockVP9(decoder_t *p_dec, block_t *p_block, bool *pb_config_changed)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    struct vt_vp9_context *vp9ctx = p_sys->p_codec_context;
+
+    *pb_config_changed = false;
+
+    struct vp9_uncompressed_header hdr = {0};
+    if(!vp9_parse_uncompressed_header(p_block->p_buffer, p_block->i_buffer, &hdr))
+    {
+        block_Release(p_block);
+        return NULL;
+    }
+
+    if(hdr.frame_type == VP9_KEY_FRAME || hdr.intra_only)
+    {
+        *pb_config_changed = !vp9_configs_equals(&hdr, &vp9ctx->vp9_header);
+        if(*pb_config_changed)
+        {
+            vp9ctx->vp9_header = hdr;
+        }
+    }
+
+    return vp9_repacker_Push(&vp9ctx->vp9_repacker, p_block, hdr.show_frame);
+}
+
+static bool ConfigureVoutVP9(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    struct vt_vp9_context *vp9ctx = p_sys->p_codec_context;
+    const struct vp9_uncompressed_header *h = &vp9ctx->vp9_header;
+    video_format_t *fmt = &p_dec->fmt_out.video;
+
+    if (p_dec->fmt_in->video.primaries == COLOR_PRIMARIES_UNDEF)
+        vp9_get_colorimetry(h, &fmt->primaries, &fmt->transfer,
+                            &fmt->space, &fmt->color_range);
+
+    if (!p_dec->fmt_in->video.i_visible_width ||
+        !p_dec->fmt_in->video.i_visible_height)
+    {
+        fmt->i_visible_width = h->render_width_minus1 + 1;
+        fmt->i_width = vlc_align(h->frame_width_minus1 + 1, VT_ALIGNMENT);
+        fmt->i_visible_height = h->render_height_minus1 + 1;
+        fmt->i_height = vlc_align(h->frame_height_minus1 + 1, VT_ALIGNMENT);
+    }
+
+    return true;
+}
+
 /* !Codec Specific */
 
 static void DrainDPBLocked(decoder_t *p_dec, bool flush)
@@ -1016,6 +1159,9 @@ static CMVideoCodecType CodecPrecheck(decoder_t *p_dec)
             msg_Dbg(p_dec, "Will decode MP4V with original FourCC '%4.4s'", (char *)&p_dec->fmt_in->i_original_fourcc);
             return kCMVideoCodecType_MPEG4Video;
         }
+
+        case VLC_CODEC_VP9:
+            return kCMVideoCodecType_VP9;
 #if !TARGET_OS_IPHONE
         case VLC_CODEC_H263:
             return kCMVideoCodecType_H263;
@@ -1501,6 +1647,21 @@ static int OpenDecoder(vlc_object_t *p_this)
             p_sys->start_sync_state = STATE_BITSTREAM_WAITING_RAP;
             break;
 
+        case kCMVideoCodecType_VP9:
+            p_sys->pf_codec_init = InitVP9;
+            p_sys->pf_codec_clean = CleanVP9;
+            p_sys->pf_codec_supported = CodecSupportedVP9;
+            p_sys->pf_late_start = LateStartVP9;
+            p_sys->pf_process_block = ProcessBlockVP9;
+            p_sys->pf_need_restart = NULL;
+            p_sys->pf_configure_vout = ConfigureVoutVP9;
+            p_sys->pf_copy_extradata = CopyDecoderExtradataVP9;
+            p_sys->pf_fill_reorder_info = NULL;
+            p_sys->dpb.b_strict_reorder = true;
+            p_sys->dpb.b_poc_based_reorder = false;
+            p_sys->start_sync_state = STATE_BITSTREAM_WAITING_RAP;
+            break;
+
         case kCMVideoCodecType_MPEG4Video:
             p_sys->pf_copy_extradata = CopyDecoderExtradataMPEG4;
             break;


=====================================
modules/codec/videotoolbox/vp9_repack.c
=====================================
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * vp9_repack.c: VP9 superframe repacker
+ *****************************************************************************
+ * Copyright (C) 2023-2026 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_block.h>
+
+#include "vp9_repack.h"
+
+void vp9_repacker_Clean(struct vp9_repacker *r)
+{
+    block_ChainRelease(r->p_head);
+}
+
+void vp9_repacker_Init(struct vp9_repacker *r)
+{
+    r->p_head = NULL;
+    r->pp_append = &r->p_head;
+    r->count = 0;
+    r->maxsize = 0;
+    r->total = 0;
+}
+
+block_t * vp9_repacker_Push(struct vp9_repacker *r, block_t *block,
+                            bool show_frame)
+{
+    if(block->p_buffer[block->i_buffer - 1] >> 5 == 0x06)
+    {
+        /* discard aggregated */
+        vp9_repacker_Clean(r);
+        vp9_repacker_Init(r);
+        return block;
+    }
+
+    if(show_frame && r->p_head == NULL)
+        return block;
+
+    if(r->count == 8 || /* max possible index reached. something is wrong */
+       SIZE_MAX - r->total < block->i_buffer)
+    {
+        vp9_repacker_Clean(r);
+        vp9_repacker_Init(r);
+    }
+
+    r->count++;
+    r->total += block->i_buffer;
+    if(block->i_buffer > r->maxsize)
+        r->maxsize = block->i_buffer;
+    block_ChainLastAppend(&r->pp_append, block);
+
+    if(show_frame)
+    {
+        /* make superframe from aggregated content B.2 */
+        uint8_t bpf = 1;
+        for(size_t maxsize = r->maxsize >> 8; maxsize; maxsize >>= 8)
+            bpf++;
+        block_t *idxblock = block_Alloc(1 + r->count * bpf + 1);
+        if(!idxblock)
+        {
+            vp9_repacker_Clean(r);
+            vp9_repacker_Init(r);
+            return NULL;
+        }
+        /* create index B.2.1 */
+        /* set superframe headers B.2.2 */
+        idxblock->p_buffer[0] = 0xC0 | ((bpf - 1) << 3) | (r->count - 1);
+        idxblock->p_buffer[idxblock->i_buffer - 1] = idxblock->p_buffer[0];
+        /* fill frames size index */
+        uint8_t *p = &idxblock->p_buffer[1];
+        for(block = r->p_head; block; block = block->p_next)
+        {
+            uint8_t buf[8];
+            SetQWLE(buf, block->i_buffer);
+            memcpy(p, buf, bpf);
+            p += bpf;
+        }
+        /* merge */
+        block_ChainLastAppend(&r->pp_append, idxblock);
+        block = block_ChainGather(r->p_head);
+        if(!block)
+            vp9_repacker_Clean(r);
+        vp9_repacker_Init(r);
+        return block;
+    }
+
+    return NULL;
+}


=====================================
modules/codec/videotoolbox/vp9_repack.h
=====================================
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * vp9_repack.h: VP9 superframe repacker
+ *****************************************************************************
+ * Copyright (C) 2023-2026 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef VIDEOTOOLBOX_VP9_REPACK_H
+#define VIDEOTOOLBOX_VP9_REPACK_H
+
+#include <vlc_common.h>
+#include <vlc_block.h>
+
+struct vp9_repacker
+{
+    block_t *p_head;
+    block_t **pp_append;
+    uint8_t count;
+    size_t maxsize;
+    size_t total;
+};
+
+void vp9_repacker_Clean(struct vp9_repacker *);
+
+void vp9_repacker_Init(struct vp9_repacker *);
+
+block_t * vp9_repacker_Push(struct vp9_repacker *, block_t *, bool show_frame);
+
+#endif // VIDEOTOOLBOX_VP9_REPACK_H


=====================================
modules/packetizer/vp9_frame.c
=====================================
@@ -0,0 +1,207 @@
+/*****************************************************************************
+ * vp9_frame.c: VP9 uncompressed header parser
+ *****************************************************************************
+ * Copyright (C) 2023-2026 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_bits.h>
+#include <vlc_es.h>
+
+#include "vp9_frame.h"
+#include "iso_color_tables.h"
+
+struct
+{
+    video_color_primaries_t prim;
+    video_transfer_func_t xfer;
+    video_color_space_t mc;
+} static const vp9color_space_tovlc[8] = {
+    { COLOR_PRIMARIES_UNDEF, TRANSFER_FUNC_UNDEF, COLOR_SPACE_UNDEF },
+    { COLOR_PRIMARIES_BT601_525, TRANSFER_FUNC_BT709, COLOR_SPACE_BT601 },
+    { COLOR_PRIMARIES_BT709, TRANSFER_FUNC_BT709, COLOR_SPACE_BT709 },
+    { COLOR_PRIMARIES_SMTPE_170, TRANSFER_FUNC_SMPTE_170, COLOR_SPACE_SMPTE_170 },
+    { COLOR_PRIMARIES_SMTPE_240, TRANSFER_FUNC_SMPTE_240, COLOR_SPACE_SMPTE_240 },
+    { COLOR_PRIMARIES_BT2020, TRANSFER_FUNC_BT2020, COLOR_SPACE_BT2020 },
+    { COLOR_PRIMARIES_UNDEF, TRANSFER_FUNC_UNDEF, COLOR_SPACE_UNDEF },
+    { COLOR_PRIMARIES_SRGB, TRANSFER_FUNC_SRGB, COLOR_SPACE_SRGB },
+};
+
+bool vp9_configs_equals(const struct vp9_uncompressed_header *a,
+                        const struct vp9_uncompressed_header *b)
+{
+    return a->profile == b->profile &&
+           a->bit_depth == b->bit_depth &&
+           a->color_space == b->color_space &&
+           a->color_range == b->color_range &&
+           a->subsampling_xy == b->subsampling_xy &&
+           a->frame_width_minus1 == b->frame_width_minus1 &&
+           a->frame_height_minus1 == b->frame_height_minus1 &&
+           a->render_width_minus1 == b->render_width_minus1 &&
+           a->render_height_minus1 == b->render_height_minus1;
+}
+
+bool vp9_fill_decoder_config(const struct vp9_uncompressed_header *hdr,
+                             int level,
+                             video_chroma_location_t chromaloc,
+                             uint8_t dcr[VP9_DECODER_CONFIG_SIZE])
+{
+    memset(dcr, 0, VP9_DECODER_CONFIG_SIZE);
+    dcr[0] = 0x01;
+    dcr[4] = hdr->profile;
+    dcr[5] = level > 0 ? level : 0;
+    /* There is no mapping from YUV440 to DCR */
+    uint8_t chroma;
+    if(hdr->subsampling_xy == VP9_YUV_440)
+        return false;
+    else if(hdr->subsampling_xy == VP9_YUV_420)
+        chroma = (chromaloc == CHROMA_LOCATION_LEFT) ? 0 : 1;
+    else
+        chroma = hdr->subsampling_xy == VP9_YUV_422 ? 2 : 3;
+    dcr[6] = (hdr->bit_depth << 4)
+           | (chroma << 1)
+           | hdr->color_range;
+    dcr[7] = vlc_primaries_to_iso_23001_8_cp( vp9color_space_tovlc[hdr->color_space].prim );
+    dcr[8] = vlc_xfer_to_iso_23001_8_tc( vp9color_space_tovlc[hdr->color_space].xfer );
+    dcr[9] = vlc_coeffs_to_iso_23001_8_mc( vp9color_space_tovlc[hdr->color_space].mc );
+    return true;
+}
+
+void vp9_get_colorimetry(const struct vp9_uncompressed_header *h,
+                         video_color_primaries_t *p_primaries,
+                         video_transfer_func_t *p_transfer,
+                         video_color_space_t *p_colorspace,
+                         video_color_range_t *p_full_range)
+{
+    *p_primaries = vp9color_space_tovlc[h->color_space].prim;
+    *p_transfer = vp9color_space_tovlc[h->color_space].xfer;
+    *p_colorspace = vp9color_space_tovlc[h->color_space].mc;
+    *p_full_range = h->color_range ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
+}
+
+static bool vp9_parse_frame_sync_code(bs_t *bs)
+{
+    return bs_read(bs, 8) == 0x49 &&
+           bs_read(bs, 8) == 0x83 &&
+           bs_read(bs, 8) == 0x42;
+}
+
+static void vp9_parse_color_config(bs_t *bs,
+                                   struct vp9_uncompressed_header *h)
+{
+    if(h->profile >= 2)
+        h->bit_depth = bs_read1(bs) ? 12 : 10;
+    else
+        h->bit_depth = 8;
+    h->color_space = bs_read(bs, 3);
+    if(h->color_space != VP9_CS_RGB)
+    {
+        h->color_range = bs_read1(bs);
+        if(h->profile == 1 || h->profile == 3)
+        {
+            h->subsampling_xy = bs_read(bs, 2);
+            bs_skip(bs, 1);
+        }
+        else
+            h->subsampling_xy = VP9_YUV_420;
+    }
+    else
+    {
+        h->color_range = 1;
+        if(h->profile == 1 || h->profile == 3)
+        {
+            h->subsampling_xy = VP9_YUV_444;
+            bs_skip(bs, 1);
+        }
+    }
+}
+
+static void vp9_parse_frame_render_sizes(bs_t *bs,
+                                         struct vp9_uncompressed_header *h)
+{
+    /* frame size */
+    h->frame_width_minus1 = bs_read(bs, 16);
+    h->frame_height_minus1 = bs_read(bs, 16);
+    /* render size */
+    if(bs_read1(bs))
+    {
+        h->render_width_minus1 = bs_read(bs, 16);
+        h->render_height_minus1 = bs_read(bs, 16);
+    }
+    else
+    {
+        h->render_width_minus1 = h->frame_width_minus1;
+        h->render_height_minus1 = h->frame_height_minus1;
+    }
+}
+
+bool vp9_parse_uncompressed_header(const uint8_t *p, size_t sz,
+                                   struct vp9_uncompressed_header *h)
+{
+    bs_t bs;
+    bs_init(&bs, p, sz);
+    bs_skip(&bs, 2);
+    h->profile = bs_read1(&bs) | (bs_read1(&bs) << 1);
+    if(h->profile == 3)
+        bs_skip(&bs, 1);
+    h->show_existing_frame = bs_read1(&bs);
+    if(h->show_existing_frame)
+    {
+        bs_skip(&bs, 3); /* frame to show idx */
+        return bs_error(&bs) ? false : true;
+    }
+    h->frame_type = bs_read1(&bs);
+    h->show_frame = bs_read1(&bs);
+    uint8_t error_resilient_mode = bs_read(&bs, 1);
+    if(h->frame_type == VP9_KEY_FRAME)
+    {
+        if(!vp9_parse_frame_sync_code(&bs))
+            return false;
+        vp9_parse_color_config(&bs, h);
+        vp9_parse_frame_render_sizes(&bs, h);
+    }
+    else
+    {
+        if(h->show_frame == 0)
+            h->intra_only = bs_read1(&bs);
+        else
+            h->intra_only = 0;
+        if(error_resilient_mode == 0)
+            bs_skip(&bs, 2);
+        if(h->intra_only == 1)
+        {
+            if(!vp9_parse_frame_sync_code(&bs))
+                return false;
+            if(h->profile > 0)
+            {
+                vp9_parse_color_config(&bs, h);
+            }
+            else
+            {
+                h->color_space = VP9_CS_BT_601;
+                h->subsampling_xy = VP9_YUV_420;
+                h->bit_depth = 8;
+            }
+            bs_skip(&bs, 8);
+            vp9_parse_frame_render_sizes(&bs, h);
+        }
+    }
+    return (bs_eof(&bs) || bs_error(&bs)) ? false : true;
+}


=====================================
modules/packetizer/vp9_frame.h
=====================================
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * vp9_frame.h: VP9 uncompressed header parser
+ *****************************************************************************
+ * Copyright (C) 2023-2026 VideoLabs, VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef VLC_VP9_FRAME_H
+#define VLC_VP9_FRAME_H
+
+#include <vlc_common.h>
+#include <vlc_es.h>
+
+struct vp9_uncompressed_header
+{
+    uint8_t profile;
+    uint8_t show_existing_frame;
+    enum
+    {
+        VP9_KEY_FRAME = 0,
+        VP9_NON_KEY_FRAME = 1,
+    } frame_type;
+    uint8_t show_frame;
+    uint8_t intra_only;
+    uint8_t bit_depth;
+    enum
+    {
+        VP9_CS_UNKNOWN = 0,
+        VP9_CS_BT_601  = 1,
+        VP9_CS_BT_709  = 2,
+        VP9_CS_SMPTE_170 = 3,
+        VP9_CS_SMPTE_240 = 4,
+        VP9_CS_BT_2020  = 5,
+        VP9_CS_RESERVED = 6,
+        VP9_CS_RGB = 7,
+    } color_space;
+    uint8_t color_range;
+    enum
+    {
+        VP9_YUV_444 = (0 << 1) | 0,
+        VP9_YUV_440 = (0 << 1) | 1,
+        VP9_YUV_422 = (1 << 1) | 0,
+        VP9_YUV_420 = (1 << 1) | 1,
+    } subsampling_xy;
+    uint16_t frame_width_minus1;
+    uint16_t frame_height_minus1;
+    uint16_t render_width_minus1;
+    uint16_t render_height_minus1;
+};
+
+#define VP9_DECODER_CONFIG_SIZE 12
+
+bool vp9_parse_uncompressed_header(const uint8_t *p, size_t sz,
+                                   struct vp9_uncompressed_header *h);
+
+bool vp9_configs_equals(const struct vp9_uncompressed_header *a,
+                        const struct vp9_uncompressed_header *b);
+
+bool vp9_fill_decoder_config(const struct vp9_uncompressed_header *hdr,
+                             int level,
+                             video_chroma_location_t chromaloc,
+                             uint8_t dcr[VP9_DECODER_CONFIG_SIZE]);
+
+void vp9_get_colorimetry(const struct vp9_uncompressed_header *h,
+                         video_color_primaries_t *p_primaries,
+                         video_transfer_func_t *p_transfer,
+                         video_color_space_t *p_colorspace,
+                         video_color_range_t *p_full_range);
+
+#endif



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b53d8f021745ddf5eef14530710078edf20ce914

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b53d8f021745ddf5eef14530710078edf20ce914
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list