History

avcodec: add an APV parser

James Almer committed 1 year ago

Commit c4ea4ab1 parent 8ebccdf6 files · +139 −2Browse files

Unified · Split

6 files
  1. Changelog +1 −0
  2. configure +1 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/apv_parser.c +133 −0
  5. libavcodec/parsers.c +1 −0
  6. libavcodec/version.h +2 −2
Changelog+1−0
@@ -14,6 +14,7 @@ version <next>: · 13 unmodified lines
14- CENC AV1 support in MP4 muxer14- CENC AV1 support in MP4 muxer
15- pngenc: set default prediction method to PAETH15- pngenc: set default prediction method to PAETH
16- APV decoder and APV raw bitstream muxing and demuxing16- APV decoder and APV raw bitstream muxing and demuxing
17- APV parser
17 18
18 19
19version 7.1:20version 7.1:
configure+1−0
@@ -3483,6 +3483,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec" · 3482 unmodified lines
3483 3483
3484# parsers3484# parsers
3485aac_parser_select="adts_header mpeg4audio"3485aac_parser_select="adts_header mpeg4audio"
3486apv_parser_select="cbs_apv"
3486av1_parser_select="cbs_av1"3487av1_parser_select="cbs_av1"
3487evc_parser_select="evcparse"3488evc_parser_select="evcparse"
3488ffv1_parser_select="rangecoder"3489ffv1_parser_select="rangecoder"
libavcodec/Makefile+1−0
@@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \ · 1197 unmodified lines
1198 ac3_channel_layout_tab.o1198 ac3_channel_layout_tab.o
1199OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o1199OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
1200OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o1200OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
1201OBJS-$(CONFIG_APV_PARSER) += apv_parser.o
1201OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o1202OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
1202OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o1203OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
1203OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o1204OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
libavcodec/apv_parser.c+133−0
@@ -0,0 +1,133 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "avcodec.h"
20#include "apv.h"
21#include "cbs.h"
22#include "cbs_apv.h"
23
24typedef struct APVParseContext {
25 CodedBitstreamContext *cbc;
26 CodedBitstreamFragment au;
27} APVParseContext;
28
29static const enum AVPixelFormat apv_format_table[5][5] = {
30 { AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 },
31 { 0 }, // 4:2:0 is not valid.
32 { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV422P16 },
33 { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV444P16 },
34 { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 },
35};
36
37static int parse(AVCodecParserContext *s,
38 AVCodecContext *avctx,
39 const uint8_t **poutbuf, int *poutbuf_size,
40 const uint8_t *buf, int buf_size)
41{
42 APVParseContext *p = s->priv_data;
43 CodedBitstreamFragment *au = &p->au;
44 int ret;
45
46 *poutbuf = buf;
47 *poutbuf_size = buf_size;
48
49 p->cbc->log_ctx = avctx;
50
51 ret = ff_cbs_read(p->cbc, au, buf, buf_size);
52 if (ret < 0) {
53 av_log(avctx, AV_LOG_ERROR, "Failed to parse access unit.\n");
54 goto end;
55 }
56
57 s->key_frame = 1;
58 s->pict_type = AV_PICTURE_TYPE_I;
59 s->field_order = AV_FIELD_UNKNOWN;
60 s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
61
62 for (int i = 0; i < au->nb_units; i++) {
63 const CodedBitstreamUnit *pbu = &au->units[i];
64
65 switch (pbu->type) {
66 case APV_PBU_PRIMARY_FRAME: {
67 const APVRawFrame *frame = pbu->content;
68 const APVRawFrameHeader *header = &frame->frame_header;
69 const APVRawFrameInfo *info = &header->frame_info;
70 int bit_depth = info->bit_depth_minus8 + 8;
71
72 if (bit_depth < 8 || bit_depth > 16 || bit_depth % 2)
73 break;
74
75 s->width = info->frame_width;
76 s->height = info->frame_height;
77 s->format = apv_format_table[info->chroma_format_idc][bit_depth - 4 >> 2];
78 avctx->profile = info->profile_idc;
79 avctx->level = info->level_idc;
80 avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
81 avctx->color_primaries = header->color_primaries;
82 avctx->color_trc = header->transfer_characteristics;
83 avctx->colorspace = header->matrix_coefficients;
84 avctx->color_range = header->full_range_flag ? AVCOL_RANGE_JPEG
85 : AVCOL_RANGE_MPEG;
86 goto end;
87 }
88 default:
89 break;
90 }
91 }
92
93end:
94 ff_cbs_fragment_reset(au);
95 p->cbc->log_ctx = NULL;
96
97 return buf_size;
98}
99
100static const CodedBitstreamUnitType decompose_unit_types[] = {
101 APV_PBU_PRIMARY_FRAME,
102};
103
104static av_cold int init(AVCodecParserContext *s)
105{
106 APVParseContext *p = s->priv_data;
107 int ret;
108
109 ret = ff_cbs_init(&p->cbc, AV_CODEC_ID_APV, NULL);
110 if (ret < 0)
111 return ret;
112
113 p->cbc->decompose_unit_types = decompose_unit_types;
114 p->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
115
116 return 0;
117}
118
119static void close(AVCodecParserContext *s)
120{
121 APVParseContext *p = s->priv_data;
122
123 ff_cbs_fragment_free(&p->au);
124 ff_cbs_close(&p->cbc);
125}
126
127const AVCodecParser ff_apv_parser = {
128 .codec_ids = { AV_CODEC_ID_APV },
129 .priv_data_size = sizeof(APVParseContext),
130 .parser_init = init,
131 .parser_parse = parse,
132 .parser_close = close,
133};
libavcodec/parsers.c+1−0
@@ -25,6 +25,7 @@ extern const AVCodecParser ff_aac_latm_parser; · 24 unmodified lines
25extern const AVCodecParser ff_ac3_parser;25extern const AVCodecParser ff_ac3_parser;
26extern const AVCodecParser ff_adx_parser;26extern const AVCodecParser ff_adx_parser;
27extern const AVCodecParser ff_amr_parser;27extern const AVCodecParser ff_amr_parser;
28extern const AVCodecParser ff_apv_parser;
28extern const AVCodecParser ff_av1_parser;29extern const AVCodecParser ff_av1_parser;
29extern const AVCodecParser ff_avs2_parser;30extern const AVCodecParser ff_avs2_parser;
30extern const AVCodecParser ff_avs3_parser;31extern const AVCodecParser ff_avs3_parser;
libavcodec/version.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
29 29
30#include "version_major.h"30#include "version_major.h"
31 31
32#define LIBAVCODEC_VERSION_MINOR 132#define LIBAVCODEC_VERSION_MINOR 2
33#define LIBAVCODEC_VERSION_MICRO 10233#define LIBAVCODEC_VERSION_MICRO 100
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
36 LIBAVCODEC_VERSION_MINOR, \36 LIBAVCODEC_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t