libavformat/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 "avformat.h"
23 #include "internal.h"
24 #include "libavutil/log.h"
25 #include "libavutil/opt.h"
26 
27 typedef struct G729DemuxerContext {
28  AVClass *class;
29  int bit_rate;
31 
33 {
34  AVStream* st;
36 
37  st = avformat_new_stream(s, NULL);
38  if (!st)
39  return AVERROR(ENOMEM);
40 
43  st->codec->sample_rate = 8000;
44  st->codec->channels = 1;
45 
46  if (s1 && s1->bit_rate) {
47  s->bit_rate = s1->bit_rate;
48  }
49 
50  if (s->bit_rate == 0) {
51  av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
52  s->bit_rate = 8000;
53  }
54 
55  if (s->bit_rate == 6400) {
56  st->codec->block_align = 8;
57  } else if (s->bit_rate == 8000) {
58  st->codec->block_align = 10;
59  } else {
60  av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %d b/s\n", s->bit_rate);
61  return AVERROR_INVALIDDATA;
62  }
63 
64  avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate);
65  return 0;
66 }
68 {
69  int ret;
70 
71  ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
72 
73  pkt->stream_index = 0;
74  if (ret < 0)
75  return ret;
76 
77  pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align;
78 
79  return ret;
80 }
81 
82 static const AVOption g729_options[] = {
83  { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
84  { NULL },
85 };
86 
87 static const AVClass g729_demuxer_class = {
88  .class_name = "g729 demuxer",
89  .item_name = av_default_item_name,
90  .option = g729_options,
91  .version = LIBAVUTIL_VERSION_INT,
92 };
93 
95  .name = "g729",
96  .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
97  .priv_data_size = sizeof(G729DemuxerContext),
101  .extensions = "g729",
102  .priv_class = &g729_demuxer_class,
103 };
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVOption.
Definition: opt.h:251
av_default_item_name
int64_t pos
byte position in stream, -1 if unknown
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
static const AVOption g729_options[]
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Format I/O context.
Definition: avformat.h:944
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:55
AVOptions.
static AVPacket pkt
Definition: demuxing.c:56
AVInputFormat ff_g729_demuxer
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
struct G729DemuxerContext G729DemuxerContext
ret
Definition: avfilter.c:821
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
Describe the class of an AVClass context structure.
Definition: log.h:50
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
#define s1
Definition: regdef.h:38
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
static int flags
Definition: cpu.c:23
Main libavformat public API header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
static const AVClass g729_demuxer_class
static int g729_read_header(AVFormatContext *s)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int bit_rate
Decoding: total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1016
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...