* commit 'd621b2f795684f7119057f986066060adbe84220': lavf: Raw G.729 demuxer
Unified · Split
| @@ -19,13 +19,15 @@ · 18 unmodified lines | ||
| 19 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | −#include "avformat.h" | |
| 23 | −#include "internal.h" | |
| 24 | 22 | #include "libavutil/log.h" |
| 25 | 23 | #include "libavutil/opt.h" |
| 26 | 24 | |
| 25 | +#include "avformat.h" | |
| 26 | +#include "internal.h" | |
| 27 | + | |
| 27 | 28 | typedef struct G729DemuxerContext { |
| 28 | 29 | AVClass *class; |
| 30 | + | |
| 29 | 31 | int bit_rate; |
| 30 | 32 | } G729DemuxerContext; |
| 31 | 33 | |
| @@ -38,49 +40,49 @@ static int g729_read_header(AVFormatContext *s) · 6 unmodified lines | ||
| 38 | 40 | if (!st) |
| 39 | 41 | return AVERROR(ENOMEM); |
| 40 | 42 | |
| 41 | − st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 42 | − st->codecpar->codec_id = AV_CODEC_ID_G729; | |
| 43 | + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 44 | + st->codecpar->codec_id = AV_CODEC_ID_G729; | |
| 43 | 45 | st->codecpar->sample_rate = 8000; |
| 44 | − st->codecpar->channels = 1; | |
| 46 | + st->codecpar->channels = 1; | |
| 45 | 47 | |
| 46 | − if (s1 && s1->bit_rate) { | |
| 48 | + if (s1 && s1->bit_rate) | |
| 47 | 49 | s->bit_rate = s1->bit_rate; |
| 48 | − } | |
| 49 | − | |
| 50 | − if (s->bit_rate == 0) { | |
| 51 | − av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n"); | |
| 52 | − s->bit_rate = 8000; | |
| 53 | − } | |
| 54 | 50 | |
| 55 | − if (s->bit_rate == 6400) { | |
| 51 | + switch(s->bit_rate) { | |
| 52 | + case 6400: | |
| 56 | 53 | st->codecpar->block_align = 8; |
| 57 | − } else if (s->bit_rate == 8000) { | |
| 54 | + break; | |
| 55 | + case 8000: | |
| 58 | 56 | st->codecpar->block_align = 10; |
| 59 | − } else { | |
| 60 | − 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); | |
| 61 | − return AVERROR_INVALIDDATA; | |
| 57 | + break; | |
| 58 | + default: | |
| 59 | + av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %d. " | |
| 60 | + "Only 6400 and 8000 b/s are supported.", s->bit_rate); | |
| 61 | + return AVERROR(EINVAL); | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | − avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1, st->codecpar->sample_rate); | |
| 64 | + avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1, | |
| 65 | + st->codecpar->sample_rate); | |
| 66 | + | |
| 65 | 67 | return 0; |
| 66 | 68 | } |
| 69 | + | |
| 67 | 70 | static int g729_read_packet(AVFormatContext *s, AVPacket *pkt) |
| 68 | 71 | { |
| 69 | − int ret; | |
| 70 | − | |
| 71 | − ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align); | |
| 72 | − | |
| 73 | − pkt->stream_index = 0; | |
| 72 | + AVStream *st = s->streams[0]; | |
| 73 | + int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align); | |
| 74 | 74 | if (ret < 0) |
| 75 | 75 | return ret; |
| 76 | 76 | |
| 77 | − pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codecpar->block_align; | |
| 77 | + pkt->stream_index = 0; | |
| 78 | + pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align; | |
| 78 | 79 | |
| 79 | − return ret; | |
| 80 | + return 0; | |
| 80 | 81 | } |
| 81 | 82 | |
| 83 | +#define OFFSET(x) offsetof(G729DemuxerContext, x) | |
| 82 | 84 | static const AVOption g729_options[] = { |
| 83 | − { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, | |
| 85 | + { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, | |
| 84 | 86 | { NULL }, |
| 85 | 87 | }; |
| 86 | 88 | |