aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/vvcdec.c
blob: 0a0e24b71c012be2501a2b85156a8244a9b84d8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * RAW H.266 / VVC video demuxer
 * Copyright (c) 2020 Nuo Mi <nuomi2021@gmail.com>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg 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.
 *
 * FFmpeg 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 FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libavcodec/vvc.h"

#include "avformat.h"
#include "rawdec.h"

static int check_temporal_id(uint8_t nuh_temporal_id_plus1, int type)
{
    if (nuh_temporal_id_plus1 == 0)
        return 0;

    if (nuh_temporal_id_plus1 != 1) {
        if (type >= VVC_IDR_W_RADL && type <= VVC_RSV_IRAP_11
                || type == VVC_DCI_NUT || type == VVC_OPI_NUT
                || type == VVC_VPS_NUT || type == VVC_SPS_NUT
                || type == VVC_EOS_NUT || type == VVC_EOB_NUT)
            return 0;
    }

    return 1;
}

static int vvc_probe(const AVProbeData *p)
{
    uint32_t code = -1;
    int sps = 0, pps = 0, irap = 0;
    int i;

    for (i = 0; i < p->buf_size - 1; i++) {
        code = (code << 8) + p->buf[i];
        if ((code & 0xffffff00) == 0x100) {
            uint8_t nal2 = p->buf[i + 1];
            int type = (nal2 & 0xF8) >> 3;

            if (code & 0x80) // forbidden_zero_bit
                return 0;

            if (!check_temporal_id(nal2 & 0x7, type))
                return 0;

            switch (type) {
            case VVC_SPS_NUT:       sps++;  break;
            case VVC_PPS_NUT:       pps++;  break;
            case VVC_IDR_N_LP:
            case VVC_IDR_W_RADL:
            case VVC_CRA_NUT:
            case VVC_GDR_NUT:       irap++; break;
            }
        }
    }

    if (sps && pps && irap)
        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
    return 0;
}

FF_DEF_RAWVIDEO_DEMUXER(vvc, "raw H.266/VVC video", vvc_probe, "h266,266,vvc", AV_CODEC_ID_VVC)