FFmpeg: libavformat/codec2.c Source File
Go to the documentation of this file. 1 /*
2 * codec2 muxer and demuxers
3 * Copyright (c) 2017 Tomas Härdin
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config_components.h"
23
34
35 #define CODEC2_HEADER_SIZE 7
36 #define CODEC2_MAGIC 0xC0DEC2
37
38 //the lowest version we should ever run across is 0.8
39 //we may run across later versions as the format evolves
40 #define EXPECTED_CODEC2_MAJOR_VERSION 0
41 #define EXPECTED_CODEC2_MINOR_VERSION 8
42
48
50 {
51 //must start wih C0 DE C2
53 return 0;
54 }
55
56 //no .c2 files prior to 0.8
57 //be strict about major version while we're at it
60 return 0;
61 }
62
63 //32 bits of identification -> low score
65 }
66
67 //Mimics codec2_samples_per_frame()
69 {
71 160, // 3200
72 160, // 2400
73 320, // 1600
74 320, // 1400
75 320, // 1300
76 320, // 1200
77 320, // 700
78 320, // 700B
79 320, // 700C
80 };
81
84 return 0;
85 } else {
86 return frame_size_table[
mode];
87 }
88 }
89
90 //Mimics (codec2_bits_per_frame()+7)/8
92 {
94 8, // 3200
95 6, // 2400
96 8, // 1600
97 7, // 1400
98 7, // 1300
99 6, // 1200
100 4, // 700
101 4, // 700B
102 4, // 700C
103 };
104
107 return 0;
108 } else {
109 return block_align_table[
mode];
110 }
111 }
112
113 //Computes bitrate from mode, with frames rounded up to the nearest octet.
114 //So 700 bit/s (28 bits/frame) becomes 800 bits/s (32 bits/frame).
116 {
119
121 return 0;
122 }
123
125 }
126
128 {
130
139
144 }
145
147
148 return 0;
149 }
150
152 {
155
156 if (!st) {
158 }
159
163 }
164
168 }
169
173 }
174
179 }
180
182
184 }
185
187 {
191
194
195 if (block_align <= 0 || frame_size <= 0 || c2->frames_per_packet <= 0) {
197 }
198
199 //try to read desired number of frames, compute n from to actual number of bytes read
200 size =
c2->frames_per_packet * block_align;
204 }
205
206 //only set duration - compute_pkt_fields() and ff_pcm_read_seek() takes care of everything else
207 //tested by spamming the seek functionality in ffplay
208 n =
ret / block_align;
210
212 }
213
215 {
217
221 }
222
224
229 }
230
233
234 return 0;
235 }
236
238 {
242
244 //FIXME: using a default value of -1 for mandatory options is an incredibly ugly hack
247 }
248
250 if (!st) {
252 }
253
257 }
258
260
262 }
263
264 //transcoding report2074.c2 to wav went from 7.391s to 5.322s with -frames_per_packet 1000 compared to default, same sha1sum
265 #define FRAMES_PER_PACKET \
266 { "frames_per_packet", "Number of frames to read at a time. Higher = faster decoding, lower granularity", \
267 offsetof(Codec2Context, frames_per_packet), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}
268
272 };
273
278 };
279
286 };
287
294 };
295
296 #if CONFIG_CODEC2_DEMUXER
301 .extensions = "c2",
309 };
310 #endif
311
312 #if CONFIG_CODEC2_MUXER
316 .p.extensions = "c2",
323 };
324 #endif
325
326 #if CONFIG_CODEC2RAW_DEMUXER
337 };
338 #endif
#define CODEC2_EXTRADATA_SIZE
static const AVOption codec2_options[]
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
#define EXPECTED_CODEC2_MINOR_VERSION
static int codec2_read_packet(AVFormatContext *s, AVPacket *pkt)
static int codec2_write_header(AVFormatContext *s)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
static int codec2_mode_bit_rate(AVFormatContext *s, int mode)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int frame_size
Audio only.
static void codec2_make_extradata(uint8_t *ptr, int mode)
#define EXPECTED_CODEC2_MAJOR_VERSION
static int codec2_read_header(AVFormatContext *s)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int64_t data_offset
offset of the first packet
@ AV_CLASS_CATEGORY_DEMUXER
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int codec2raw_read_header(AVFormatContext *s)
const char * av_default_item_name(void *ptr)
Return the context name.
This structure contains the data a format has to probe a file.
AVChannelLayout ch_layout
Audio only.
int sample_rate
Audio only.
int extradata_size
Size of the extradata content in bytes.
unsigned int avio_rb24(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static uint8_t codec2_mode_from_extradata(uint8_t *ptr)
static const AVClass codec2raw_demux_class
#define CODEC2_AVOPTIONS(desc, classname, min_val, default_val, option_flags)
int block_align
Audio only.
static int codec2_mode_block_align(AVFormatContext *s, int mode)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define FRAMES_PER_PACKET
static const AVOption codec2raw_options[]
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static int codec2_mode_frame_size(AVFormatContext *s, int mode)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const AVClass codec2_demux_class
static int read_probe(const AVProbeData *p)
void avio_wb24(AVIOContext *s, unsigned int val)
#define AV_CHANNEL_LAYOUT_MONO
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
static int codec2_probe(const AVProbeData *p)
This structure stores compressed data.
#define flags(name, subs,...)
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define CODEC2_HEADER_SIZE
static void write_header(FFV1Context *f)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Generated on Tue Feb 28 2023 21:34:03 for FFmpeg by
doxygen
1.8.17