FFmpeg
Loading...
Searching...
No Matches
api-amr-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 <inttypes.h>
20#include <stdio.h>
21#include <string.h>
22
23#include "libavcodec/avcodec.h"
24
26 const char *name, const uint8_t *input, int input_size)
27{
28 uint8_t padded[2 * 2 * 18 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
29 uint8_t *output;
30 int output_size;
31 int ret;
32
33 if (input_size)
34 memcpy(padded, input, input_size);
35 ret = av_parser_parse2(parser, ctx, &output, &output_size,
36 input_size ? padded : NULL, input_size,
38 printf("%s: input %d, consumed %d, output %d", name, input_size, ret, output_size);
39 if (output_size) {
40 printf(", duration %d, bitrate %" PRId64 ", ",
41 parser->duration, ctx->bit_rate);
42 for (int i = 0; i < output_size; i++)
43 printf("%02x", output[i]);
44 }
45 printf("\n");
46}
47
48static int test_parser(enum AVCodecID codec, int channels, int frame_size)
49{
50 AVCodecParserContext *parser = av_parser_init(codec);
52 uint8_t blocks[2 * 2 * 18] = { 0 };
53 const int block_size = channels * frame_size;
54 int ret = 1;
55
56 if (!parser || !ctx)
57 goto end;
58 ctx->codec_id = codec;
60
61 /* Mode 0 headers, with distinct payloads in each speech frame. */
62 for (int i = 0; i < 2 * channels; i++)
63 blocks[i * frame_size + 1] = i + 1;
64
65 printf("%s, channels %d\n", avcodec_get_name(codec), channels);
66 parse(parser, ctx, "exact", blocks, block_size);
67 parse(parser, ctx, "split start", blocks, block_size - 1);
68 parse(parser, ctx, "split end", blocks + block_size - 1, 1);
69 if (channels > 1) {
70 parse(parser, ctx, "first channel", blocks, frame_size);
71 parse(parser, ctx, "last channel", blocks + frame_size, frame_size);
72 }
73 parse(parser, ctx, "combined", blocks, 2 * block_size);
74 parse(parser, ctx, "remainder", blocks + block_size, block_size);
75 if (channels == 1)
76 parse(parser, ctx, "truncated block", blocks, block_size - 1);
77 parse(parser, ctx, "eof", NULL, 0);
78
79 /* New input after EOF needs a new parser. */
80 av_parser_close(parser);
81 parser = av_parser_init(codec);
82 if (!parser)
83 goto end;
85 ctx->bit_rate = 0;
86 parse(parser, ctx, "complete frames", blocks, 2 * block_size);
87 parse(parser, ctx, "complete frames eof", NULL, 0);
88 ret = 0;
89
90end:
91 av_parser_close(parser);
93 return ret;
94}
95
96int main(void)
97{
102 return ret;
103}
static void parse(AVCodecParserContext *parser, AVCodecContext *ctx, const char *name, const uint8_t *input, int input_size)
int main(void)
static int test_parser(enum AVCodecID codec, int channels, int frame_size)
static AVFormatContext * ctx
channels
Definition aptx.h:31
Libavcodec external API header.
#define PARSER_FLAG_COMPLETE_FRAMES
Definition avcodec.h:2672
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
int ret
Definition ffplay.c:391
static const uint8_t frame_size[4]
Definition g723_1.h:222
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
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_AMR_NB
Definition codec_id.h:440
@ AV_CODEC_ID_AMR_WB
Definition codec_id.h:441
#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
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
const char * name
Definition qsvenc.c:142
main external API structure.
Definition avcodec.h:443
int duration
Duration of the current frame.
Definition avcodec.h:2752