Commit 5954730b authored by Clément Bœsch's avatar Clément Bœsch

Merge commit 'd621b2f7'

* commit 'd621b2f7':
  lavf: Raw G.729 demuxer
Merged-by: 's avatarClément Bœsch <clement@stupeflix.com>
parents 28dac0dc d621b2f7
...@@ -19,13 +19,15 @@ ...@@ -19,13 +19,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "avformat.h"
#include "internal.h"
#include "libavutil/log.h" #include "libavutil/log.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
typedef struct G729DemuxerContext { typedef struct G729DemuxerContext {
AVClass *class; AVClass *class;
int bit_rate; int bit_rate;
} G729DemuxerContext; } G729DemuxerContext;
...@@ -38,49 +40,49 @@ static int g729_read_header(AVFormatContext *s) ...@@ -38,49 +40,49 @@ static int g729_read_header(AVFormatContext *s)
if (!st) if (!st)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_G729; st->codecpar->codec_id = AV_CODEC_ID_G729;
st->codecpar->sample_rate = 8000; 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; 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; st->codecpar->block_align = 8;
} else if (s->bit_rate == 8000) { break;
case 8000:
st->codecpar->block_align = 10; st->codecpar->block_align = 10;
} else { break;
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); default:
return AVERROR_INVALIDDATA; 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; return 0;
} }
static int g729_read_packet(AVFormatContext *s, AVPacket *pkt) static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
int ret; AVStream *st = s->streams[0];
int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align);
ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
pkt->stream_index = 0;
if (ret < 0) if (ret < 0)
return ret; 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[] = { 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 }, { NULL },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment