FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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;
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, st->codecpar->block_align << 3, 1,
65  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 
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 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
AVOption.
Definition: opt.h:245
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1600
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.
Definition: utils.c:4427
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3922
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1427
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: g729dec.c:70
static AVPacket pkt
static const AVOption g729_options[]
Definition: g729dec.c:84
Format I/O context.
Definition: avformat.h:1325
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:72
AVOptions.
AVInputFormat ff_g729_demuxer
Definition: g729dec.c:96
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4065
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1393
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:260
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3918
int block_align
Audio only.
Definition: avcodec.h:4039
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:638
Stream structure.
Definition: avformat.h:876
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVIOContext * pb
I/O context.
Definition: avformat.h:1367
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:485
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:276
#define OFFSET(x)
Definition: g729dec.c:83
#define s1
Definition: regdef.h:38
static int flags
Definition: cpu.c:47
int sample_rate
Audio only.
Definition: avcodec.h:4032
Main libavformat public API header.
void * priv_data
Format private data.
Definition: avformat.h:1353
static const AVClass g729_demuxer_class
Definition: g729dec.c:89
static int g729_read_header(AVFormatContext *s)
Definition: g729dec.c:34
int channels
Audio only.
Definition: avcodec.h:4028
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1579
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:660
AVCodecParameters * codecpar
Definition: avformat.h:1006
int stream_index
Definition: avcodec.h:1582
This structure stores compressed data.
Definition: avcodec.h:1557
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1573