FFmpeg
g729dec.c
Go to the documentation of this file.
1 /*
2  * G.729 raw format demuxer
3  * Copyright (c) 2011 Vladimir Voroshilov
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 "libavutil/log.h"
23 #include "libavutil/opt.h"
24 
25 #include "avformat.h"
26 #include "internal.h"
27 
28 typedef struct G729DemuxerContext {
29  AVClass *class;
30 
31  int bit_rate;
33 
35 {
36  AVStream* st;
37  G729DemuxerContext *s1 = s->priv_data;
38 
39  st = avformat_new_stream(s, NULL);
40  if (!st)
41  return AVERROR(ENOMEM);
42 
45  st->codecpar->sample_rate = 8000;
46  st->codecpar->channels = 1;
47 
48  if (s1 && s1->bit_rate)
49  s->bit_rate = s1->bit_rate;
50 
51  switch(s->bit_rate) {
52  case 6400:
53  st->codecpar->block_align = 8;
54  break;
55  case 8000:
56  st->codecpar->block_align = 10;
57  break;
58  default:
59  av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %"PRId64". "
60  "Only 6400 and 8000 b/s are supported.", s->bit_rate);
61  return AVERROR(EINVAL);
62  }
63 
64  avpriv_set_pts_info(st, 64, 80, st->codecpar->sample_rate);
65 
66  return 0;
67 }
68 
70 {
71  AVStream *st = s->streams[0];
72  int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
73  if (ret < 0)
74  return ret;
75 
76  pkt->stream_index = 0;
77  pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
78  pkt->duration = 1;
79 
80  return 0;
81 }
82 
83 #define OFFSET(x) offsetof(G729DemuxerContext, x)
84 static const AVOption g729_options[] = {
85  { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
86  { NULL },
87 };
88 
89 static const AVClass g729_demuxer_class = {
90  .class_name = "g729 demuxer",
91  .item_name = av_default_item_name,
92  .option = g729_options,
93  .version = LIBAVUTIL_VERSION_INT,
94 };
95 
97  .name = "g729",
98  .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
99  .priv_data_size = sizeof(G729DemuxerContext),
103  .extensions = "g729",
104  .priv_class = &g729_demuxer_class,
105 };
AVERROR
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
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:768
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
AVOption
AVOption.
Definition: opt.h:247
g729_read_packet
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: g729dec.c:69
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:391
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
g729_demuxer_class
static const AVClass g729_demuxer_class
Definition: g729dec.c:89
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:476
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:650
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:655
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
s1
#define s1
Definition: regdef.h:38
ff_g729_demuxer
const AVInputFormat ff_g729_demuxer
Definition: g729dec.c:96
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
OFFSET
#define OFFSET(x)
Definition: g729dec.c:83
g729_options
static const AVOption g729_options[]
Definition: g729dec.c:84
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:372
G729DemuxerContext::bit_rate
int bit_rate
Definition: g729dec.c:31
log.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:177
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:278
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:197
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:935
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
avformat.h
G729DemuxerContext
Definition: g729dec.c:28
AV_CODEC_ID_G729
@ AV_CODEC_ID_G729
Definition: codec_id.h:476
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:1196
AVPacket::stream_index
int stream_index
Definition: packet.h:375
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
g729_read_header
static int g729_read_header(AVFormatContext *s)
Definition: g729dec.c:34
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28