FFmpeg
Loading...
Searching...
No Matches
api-vc1-parser-test.c
Go to the documentation of this file.
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 <stdio.h>
20#include <string.h>
21
22#include "libavcodec/avcodec.h"
23#include "libavutil/avutil.h"
24
25/* Synthetic advanced-profile headers for a progressive 16x16 sequence,
26 * with pulldown enabled and no optional display or HRD information.
27 * Macroblock data is unnecessary: the parser only reads frame headers. */
28static const uint8_t sequence[] = {
29 0, 0, 1, 0x0f, 0xc2, 0, 0, 0x70, 0x07, 0x88, 0x80,
30 0, 0, 1, 0x0e, 0, 0, 0x80,
31};
32
34 const char *name, int init, uint8_t header,
35 int payload_size, int trailing_zeros)
36{
37 uint8_t buf[128 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
38 uint8_t *out;
39 int size = 0, out_size;
40
41 if (init) {
42 memcpy(buf, sequence, sizeof(sequence));
43 size += sizeof(sequence);
44 }
45 buf[size++] = 0;
46 buf[size++] = 0;
47 buf[size++] = 1;
48 buf[size++] = 0x0d;
49 memset(buf + size, 0xff, payload_size);
50 buf[size] = header;
51 if (payload_size > 1)
52 buf[size + 1] = header == 0x80 ? 0x80 : 0;
53 size += payload_size;
54 memset(buf + size - trailing_zeros, 0, trailing_zeros);
55
56 av_parser_parse2(parser, ctx, &out, &out_size, buf, size,
58 printf("%s: %c\n", name, av_get_picture_type_char(parser->pict_type));
59}
60
61int main(void)
62{
65
66 if (!parser || !ctx) {
67 av_parser_close(parser);
69 return 1;
70 }
72 ctx->codec_id = AV_CODEC_ID_VC1;
73 ctx->codec_type = AVMEDIA_TYPE_VIDEO;
74
75 parse(parser, ctx, "initial I", 1, 0xc1, 37, 0);
76 parse(parser, ctx, "skipped P", 0, 0xf2, 1, 0);
77 parse(parser, ctx, "B after skipped P", 0, 0x80, 2, 0);
78 parse(parser, ctx, "I ending in zeros", 0, 0xc1, 37, 2);
79 parse(parser, ctx, "P starting in 01", 0, 0x01, 37, 0);
80 parse(parser, ctx, "I after P", 0, 0xc1, 37, 0);
81
82 av_parser_close(parser);
84 return 0;
85}
static FILE * out
static int out_size
static AVFormatContext * ctx
static const uint8_t sequence[]
int main(void)
static void parse(AVCodecParserContext *parser, AVCodecContext *ctx, const char *name, int init, uint8_t header, int payload_size, int trailing_zeros)
Libavcodec external API header.
#define PARSER_FLAG_COMPLETE_FRAMES
Definition avcodec.h:2672
Convenience header that includes libavutil's core.
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition options.c:168
@ AV_CODEC_ID_VC1
Definition codec_id.h:120
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
AVCodecParserContext * av_parser_init(enum AVCodecID codec_id)
Definition parser.c:35
void av_parser_close(AVCodecParserContext *s)
Definition parser.c:203
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
Definition parser.c:120
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition utils.c:40
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
const char * name
Definition qsvenc.c:142
static const uint8_t header[24]
Definition sdr2.c:68
main external API structure.
Definition avcodec.h:443
int size