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
1414 - CENC AV1 support in MP4 muxer
1515 - pngenc: set default prediction method to PAETH
1616 - APV decoder and APV raw bitstream muxing and demuxing
17+- APV parser
1718
1819
1920 version 7.1:
configure+1−0
@@ -3483,6 +3483,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec" · 3482 unmodified lines
34833483
34843484 # parsers
34853485 aac_parser_select="adts_header mpeg4audio"
3486+apv_parser_select="cbs_apv"
34863487 av1_parser_select="cbs_av1"
34873488 evc_parser_select="evcparse"
34883489 ffv1_parser_select="rangecoder"
libavcodec/Makefile+1−0
@@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \ · 1197 unmodified lines
11981198 ac3_channel_layout_tab.o
11991199 OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
12001200 OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
1201+OBJS-$(CONFIG_APV_PARSER) += apv_parser.o
12011202 OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
12021203 OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
12031204 OBJS-$(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+
24+typedef struct APVParseContext {
25+ CodedBitstreamContext *cbc;
26+ CodedBitstreamFragment au;
27+} APVParseContext;
28+
29+static 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+
37+static 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+
93+end:
94+ ff_cbs_fragment_reset(au);
95+ p->cbc->log_ctx = NULL;
96+
97+ return buf_size;
98+}
99+
100+static const CodedBitstreamUnitType decompose_unit_types[] = {
101+ APV_PBU_PRIMARY_FRAME,
102+};
103+
104+static 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+
119+static 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+
127+const 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
2525 extern const AVCodecParser ff_ac3_parser;
2626 extern const AVCodecParser ff_adx_parser;
2727 extern const AVCodecParser ff_amr_parser;
28+extern const AVCodecParser ff_apv_parser;
2829 extern const AVCodecParser ff_av1_parser;
2930 extern const AVCodecParser ff_avs2_parser;
3031 extern const AVCodecParser ff_avs3_parser;
libavcodec/version.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929
3030 #include "version_major.h"
3131
32−#define LIBAVCODEC_VERSION_MINOR 1
33−#define LIBAVCODEC_VERSION_MICRO 102
32+#define LIBAVCODEC_VERSION_MINOR 2
33+#define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636 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