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 "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 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVOption.
Definition: opt.h:255
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1187
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:4006
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: g729dec.c:67
static AVPacket pkt
static const AVOption g729_options[]
Definition: g729dec.c:82
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2022
Format I/O context.
Definition: avformat.h:1272
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:94
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3672
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1340
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:241
#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:175
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
ret
Definition: avfilter.c:974
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:620
Stream structure.
Definition: avformat.h:842
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
enum AVMediaType codec_type
Definition: avcodec.h:1249
enum AVCodecID codec_id
Definition: avcodec.h:1258
int sample_rate
samples per second
Definition: avcodec.h:1985
AVIOContext * pb
I/O context.
Definition: avformat.h:1314
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:473
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:286
#define s1
Definition: regdef.h:38
static int flags
Definition: cpu.c:47
Main libavformat public API header.
int channels
number of audio channels
Definition: avcodec.h:1986
void * priv_data
Format private data.
Definition: avformat.h:1300
static const AVClass g729_demuxer_class
Definition: g729dec.c:87
static int g729_read_header(AVFormatContext *s)
Definition: g729dec.c:32
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1161
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1374
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:628
int stream_index
Definition: avcodec.h:1164
This structure stores compressed data.
Definition: avcodec.h:1139
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1155