FFmpeg
Loading...
Searching...
No Matches
auenc.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 License
6 * 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
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * 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 "libavutil/mem.h"
26
27#define AU_PAYLOAD 80
28
29static int run_case(int channels, int bps, int64_t bit_rate)
30{
31 AVFormatContext *out = NULL, *in = NULL;
32 AVIOContext *pb = NULL;
33 FFIOContext in_pb;
34 AVStream *st;
35 AVPacket *pkt = NULL;
36 uint8_t *buf = NULL;
37 int ret, size;
38
40 if (ret < 0)
41 return 1;
42 if (avio_open_dyn_buf(&pb) < 0) {
43 ret = 1;
44 goto done;
45 }
46 out->pb = pb;
47
49 if (!st) {
50 ret = 1;
51 goto done;
52 }
55 st->codecpar->sample_rate = 8000;
57 st->codecpar->bit_rate = bit_rate;
59
61 if (ret < 0) {
62 printf("channels=%d bps=%d bit_rate=%"PRId64" rejected\n",
63 channels, bps, bit_rate);
64 ret = 0;
65 goto done;
66 }
67
69 if (!pkt || (ret = av_new_packet(pkt, AU_PAYLOAD)) < 0) {
70 ret = 1;
71 goto done;
72 }
73 memset(pkt->data, 0, pkt->size);
74 pkt->stream_index = 0;
75 pkt->pts = pkt->dts = 0;
76 if ((ret = av_write_frame(out, pkt)) < 0 ||
77 (ret = av_write_trailer(out)) < 0) {
78 ret = 1;
79 goto done;
80 }
81
82 size = avio_close_dyn_buf(pb, &buf);
83 pb = NULL;
84 if (size < 16) {
85 ret = 1;
86 goto done;
87 }
88
89 ffio_init_read_context(&in_pb, buf, size);
91 if (!in) {
92 ret = 1;
93 goto done;
94 }
95 in->pb = &in_pb.pub;
96 if ((ret = avformat_open_input(&in, NULL, av_find_input_format("au"), NULL)) < 0 ||
97 !in->nb_streams) {
98 ret = 1;
99 goto done;
100 }
101
102 st = in->streams[0];
103 printf("channels=%d bps=%d bit_rate=%"PRId64" tag=%02x %02x %02x %02x "
104 "read_bps=%d read_bit_rate=%"PRId64" duration=%"PRId64"\n",
105 channels, bps, bit_rate, buf[12], buf[13], buf[14], buf[15],
107 st->duration);
108 ret = 0;
109
110done:
113 if (pb) {
114 uint8_t *tmp = NULL;
116 av_free(tmp);
117 }
118 av_free(buf);
120 return ret < 0 ? 1 : ret;
121}
122
123int main(void)
124{
125 static const int cases[][3] = {
126 { 1, 2, 0 },
127 { 1, 3, 0 },
128 { 1, 4, 0 },
129 { 1, 5, 0 },
130 { 1, 0, 16000 },
131 { 1, 0, 40000 },
132 { 1, 1, 0 },
133 { 1, 0, 0 },
134 { 2, 2, 32000 },
135 { 2, 0, 32000 },
136 { 2, 4, 64000 },
137 { 2, 0, 64000 },
138 };
139 int i, ret = 0;
140
141 for (i = 0; i < FF_ARRAY_ELEMS(cases); i++)
142 ret |= run_case(cases[i][0], cases[i][1], cases[i][2]);
143 return ret;
144}
static FILE * out
channels
Definition aptx.h:31
#define AU_PAYLOAD
Definition auenc.c:27
static int run_case(int channels, int bps, int64_t bit_rate)
Definition auenc.c:29
int main(void)
Definition auenc.c:123
Main libavformat public API header.
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition mux.c:95
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition aviobuf.c:1378
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition aviobuf.c:1333
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
Definition aviobuf.c:99
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
static AVPacket * pkt
int ret
Definition ffplay.c:391
SDL_atomic_t done
Definition ffplay.c:392
@ AV_CODEC_ID_ADPCM_G726LE
Definition codec_id.h:408
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:165
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition format.c:146
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:400
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
Definition mux.c:505
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition mux.c:1276
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Definition mux.c:1214
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
Memory handling functions.
unsigned bps
Definition movenc.c:2129
#define FF_ARRAY_ELEMS(a)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1401
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:587
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:827
AVIOContext pub
#define av_free(p)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int size