FFmpeg
Loading...
Searching...
No Matches
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
29typedef struct G729DemuxerContext {
30 AVClass *class;
31
34
36{
37 AVStream* st;
38 G729DemuxerContext *s1 = s->priv_data;
39
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
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)
85static 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
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};
const FFInputFormat ff_g729_demuxer
Definition g729dec.c:97
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:834
Main libavformat public API header.
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:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_CODEC_ID_G729
Definition codec_id.h:506
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_MONO
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVClass g729_demuxer_class
Definition g729dec.c:90
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition g729dec.c:70
static const AVOption g729_options[]
Definition g729dec.c:85
static int g729_read_header(AVFormatContext *s)
Definition g729dec.c:35
#define OFFSET(x)
Definition g729dec.c:84
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition log.h:76
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
#define av_log(a,...)