Merge commit 'd621b2f795684f7119057f986066060adbe84220'

* commit 'd621b2f795684f7119057f986066060adbe84220':
  lavf: Raw G.729 demuxer

Merged-by: Clément Bœsch <clement@stupeflix.com>
pull/221/head
Clément Bœsch 9 years ago
commit 5954730ba3
  1. 54
      libavformat/g729dec.c

@ -19,13 +19,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "internal.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
typedef struct G729DemuxerContext {
AVClass *class;
int bit_rate;
} G729DemuxerContext;
@ -38,49 +40,49 @@ static int g729_read_header(AVFormatContext *s)
if (!st)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_G729;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_G729;
st->codecpar->sample_rate = 8000;
st->codecpar->channels = 1;
st->codecpar->channels = 1;
if (s1 && s1->bit_rate) {
if (s1 && s1->bit_rate)
s->bit_rate = s1->bit_rate;
}
if (s->bit_rate == 0) {
av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
s->bit_rate = 8000;
}
if (s->bit_rate == 6400) {
switch(s->bit_rate) {
case 6400:
st->codecpar->block_align = 8;
} else if (s->bit_rate == 8000) {
break;
case 8000:
st->codecpar->block_align = 10;
} else {
av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %"PRId64" b/s\n", (int64_t)s->bit_rate);
return AVERROR_INVALIDDATA;
break;
default:
av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %d. "
"Only 6400 and 8000 b/s are supported.", s->bit_rate);
return AVERROR(EINVAL);
}
avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1, st->codecpar->sample_rate);
avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1,
st->codecpar->sample_rate);
return 0;
}
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret;
ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
pkt->stream_index = 0;
AVStream *st = s->streams[0];
int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
if (ret < 0)
return ret;
pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codecpar->block_align;
pkt->stream_index = 0;
pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align;
return ret;
return 0;
}
#define OFFSET(x) offsetof(G729DemuxerContext, x)
static const AVOption g729_options[] = {
{ "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};

Loading…
Cancel
Save