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
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  */
22 #include "libavutil/log.h"
23 #include "libavutil/opt.h"
25 #include "avformat.h"
26 #include "internal.h"
28 typedef struct G729DemuxerContext {
29  AVClass *class;
31  int bit_rate;
35 {
36  AVStream* st;
39  st = avformat_new_stream(s, NULL);
40  if (!st)
41  return AVERROR(ENOMEM);
45  st->codecpar->sample_rate = 8000;
46  st->codecpar->channels = 1;
48  if (s1 && s1->bit_rate)
49  s->bit_rate = s1->bit_rate;
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  }
64  avpriv_set_pts_info(st, 64, 80, st->codecpar->sample_rate);
66  return 0;
67 }
70 {
71  AVStream *st = s->streams[0];
72  int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
73  if (ret < 0)
74  return ret;
76  pkt->stream_index = 0;
77  pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
78  pkt->duration = 1;
80  return 0;
81 }
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 };
89 static const AVClass g729_demuxer_class = {
90  .class_name = "g729 demuxer",
91  .item_name = av_default_item_name,
92  .option = g729_options,
94 };
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
Definition: opt.h:248
Definition: version.h:85
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:389
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:4999
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1369
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: g729dec.c:69
AVPacket * pkt
Definition: movenc.c:59
static const AVOption g729_options[]
Definition: g729dec.c:84
Format I/O context.
Definition: avformat.h:1247
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
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
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:4553
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1315
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:310
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
int block_align
Audio only.
Definition: codec_par.h:177
#define s(width, name)
Definition: cbs_vp9.c:257
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
Stream structure.
Definition: avformat.h:884
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:1289
Describe the class of an AVClass context structure.
Definition: log.h:67
Use generic index building code.
Definition: avformat.h:463
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:279
#define OFFSET(x)
Definition: g729dec.c:83
#define s1
Definition: regdef.h:38
#define flags(name, subs,...)
Definition: cbs_av1.c:561
int sample_rate
Audio only.
Definition: codec_par.h:170
Main libavformat public API header.
void * priv_data
Format private data.
Definition: avformat.h:1275
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: codec_par.h:166
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:368
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:654
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1049
int stream_index
Definition: packet.h:371
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
This structure stores compressed data.
Definition: packet.h:346
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362