ffmpeg/libavformat/g729dec.c

107 lines
3.0 KiB
C
Raw Normal View History

/*
* G.729 raw format demuxer
* Copyright (c) 2011 Vladimir Voroshilov
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avformat.h"
#include "demux.h"
#include "internal.h"
typedef struct G729DemuxerContext {
AVClass *class;
int bit_rate;
} G729DemuxerContext;
Merge remote-tracking branch 'qatar/master' * qatar/master: (71 commits) movenc: Allow writing to a non-seekable output if using empty moov movenc: Support adding isml (smooth streaming live) metadata libavcodec: Don't crash in avcodec_encode_audio if time_base isn't set sunrast: Document the different Sun Raster file format types. sunrast: Add a check for experimental type. libspeexenc: use AVSampleFormat instead of deprecated/removed SampleFormat lavf: remove disabled FF_API_SET_PTS_INFO cruft lavf: remove disabled FF_API_OLD_INTERRUPT_CB cruft lavf: remove disabled FF_API_REORDER_PRIVATE cruft lavf: remove disabled FF_API_SEEK_PUBLIC cruft lavf: remove disabled FF_API_STREAM_COPY cruft lavf: remove disabled FF_API_PRELOAD cruft lavf: remove disabled FF_API_NEW_STREAM cruft lavf: remove disabled FF_API_RTSP_URL_OPTIONS cruft lavf: remove disabled FF_API_MUXRATE cruft lavf: remove disabled FF_API_FILESIZE cruft lavf: remove disabled FF_API_TIMESTAMP cruft lavf: remove disabled FF_API_LOOP_OUTPUT cruft lavf: remove disabled FF_API_LOOP_INPUT cruft lavf: remove disabled FF_API_AVSTREAM_QUALITY cruft ... Conflicts: doc/APIchanges libavcodec/8bps.c libavcodec/avcodec.h libavcodec/libx264.c libavcodec/mjpegbdec.c libavcodec/options.c libavcodec/sunrast.c libavcodec/utils.c libavcodec/version.h libavcodec/x86/h264_deblock.asm libavdevice/libdc1394.c libavdevice/v4l2.c libavformat/avformat.h libavformat/avio.c libavformat/avio.h libavformat/aviobuf.c libavformat/dv.c libavformat/mov.c libavformat/utils.c libavformat/version.h libavformat/wtv.c libavutil/Makefile libavutil/file.c libswscale/x86/input.asm libswscale/x86/swscale_mmx.c libswscale/x86/swscale_template.c tests/ref/lavf/ffm Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-01-28 04:23:26 +01:00
static int g729_read_header(AVFormatContext *s)
{
AVStream* st;
G729DemuxerContext *s1 = s->priv_data;
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_G729;
st->codecpar->sample_rate = 8000;
st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
if (s1 && s1->bit_rate)
s->bit_rate = s1->bit_rate;
switch(s->bit_rate) {
case 6400:
st->codecpar->block_align = 8;
break;
case 8000:
st->codecpar->block_align = 10;
break;
default:
av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %"PRId64". "
"Only 6400 and 8000 b/s are supported.", s->bit_rate);
return AVERROR(EINVAL);
}
avpriv_set_pts_info(st, 64, 80, st->codecpar->sample_rate);
return 0;
}
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
{
AVStream *st = s->streams[0];
int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
if (ret < 0)
return ret;
pkt->stream_index = 0;
pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
pkt->duration = 1;
return 0;
}
#define OFFSET(x) offsetof(G729DemuxerContext, x)
static const AVOption g729_options[] = {
{ "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
static const AVClass g729_demuxer_class = {
.class_name = "g729 demuxer",
.item_name = av_default_item_name,
.option = g729_options,
.version = LIBAVUTIL_VERSION_INT,
};
const FFInputFormat ff_g729_demuxer = {
.p.name = "g729",
.p.long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
.p.flags = AVFMT_GENERIC_INDEX,
.p.extensions = "g729",
.p.priv_class = &g729_demuxer_class,
.priv_data_size = sizeof(G729DemuxerContext),
.read_header = g729_read_header,
.read_packet = g729_read_packet,
};