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 "demux.h"
27 #include "internal.h"
28 
29 typedef struct G729DemuxerContext {
30  AVClass *class;
31 
32  int bit_rate;
34 
36 {
37  AVStream* st;
38  G729DemuxerContext *s1 = s->priv_data;
39 
40  st = avformat_new_stream(s, NULL);
41  if (!st)
42  return AVERROR(ENOMEM);
43 
46  st->codecpar->sample_rate = 8000;
48 
49  if (s1 && s1->bit_rate)
50  s->bit_rate = s1->bit_rate;
51 
52  switch(s->bit_rate) {
53  case 6400:
54  st->codecpar->block_align = 8;
55  break;
56  case 8000:
57  st->codecpar->block_align = 10;
58  break;
59  default:
60  av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %"PRId64". "
61  "Only 6400 and 8000 b/s are supported.", s->bit_rate);
62  return AVERROR(EINVAL);
63  }
64 
65  avpriv_set_pts_info(st, 64, 80, st->codecpar->sample_rate);
66 
67  return 0;
68 }
69 
71 {
72  AVStream *st = s->streams[0];
73  int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
74  if (ret < 0)
75  return ret;
76 
77  pkt->stream_index = 0;
78  pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
79  pkt->duration = 1;
80 
81  return 0;
82 }
83 
84 #define OFFSET(x) offsetof(G729DemuxerContext, x)
85 static const AVOption g729_options[] = {
86  { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
87  { NULL },
88 };
89 
90 static const AVClass g729_demuxer_class = {
91  .class_name = "g729 demuxer",
92  .item_name = av_default_item_name,
93  .option = g729_options,
94  .version = LIBAVUTIL_VERSION_INT,
95 };
96 
98  .p.name = "g729",
99  .p.long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
100  .p.flags = AVFMT_GENERIC_INDEX,
101  .p.extensions = "g729",
102  .p.priv_class = &g729_demuxer_class,
103  .priv_data_size = sizeof(G729DemuxerContext),
106 };
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
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVOption
AVOption.
Definition: opt.h:429
g729_read_packet
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: g729dec.c:70
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:557
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: avformat.c:867
g729_demuxer_class
static const AVClass g729_demuxer_class
Definition: g729dec.c:90
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:480
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:540
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
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:237
OFFSET
#define OFFSET(x)
Definition: g729dec.c:84
g729_options
static const AVOption g729_options[]
Definition: g729dec.c:85
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
ff_g729_demuxer
const FFInputFormat ff_g729_demuxer
Definition: g729dec.c:97
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:94
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:317
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
G729DemuxerContext::bit_rate
int bit_rate
Definition: g729dec.c:32
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:532
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:191
demux.h
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:91
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
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:80
avformat.h
G729DemuxerContext
Definition: g729dec.c:29
AV_CODEC_ID_G729
@ AV_CODEC_ID_G729
Definition: codec_id.h:499
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVPacket::stream_index
int stream_index
Definition: packet.h:541
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:356
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:392
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:516
g729_read_header
static int g729_read_header(AVFormatContext *s)
Definition: g729dec.c:35
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:559
FFInputFormat
Definition: demux.h:42
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27