diff options
author | Clément Bœsch | 2016-06-23 12:26:16 +0200 |
---|---|---|
committer | Clément Bœsch | 2016-06-23 12:26:25 +0200 |
commit | 5954730ba35ca223e7ba520ade9d589e158c1ede (patch) | |
tree | 9aad0ba953eefee2e645d5affffd730d60aaabf3 | |
parent | 28dac0dc061fa85fe671f43e78059fbc9f1eccac (diff) | |
parent | d621b2f795684f7119057f986066060adbe84220 (diff) |
Merge commit 'd621b2f795684f7119057f986066060adbe84220'
* commit 'd621b2f795684f7119057f986066060adbe84220':
lavf: Raw G.729 demuxer
Merged-by: Clément Bœsch <clement@stupeflix.com>
-rw-r--r-- | libavformat/g729dec.c | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/libavformat/g729dec.c b/libavformat/g729dec.c index ee855d22d9..337681bb0a 100644 --- a/libavformat/g729dec.c +++ b/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 }, }; |