annotate ffmpeg/libavformat/gsmdec.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RAW GSM demuxer
yading@11 3 * Copyright (c) 2011 Justin Ruggles
yading@11 4 *
yading@11 5 * This file is part of Libav.
yading@11 6 *
yading@11 7 * Libav is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * Libav is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with Libav; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include "libavutil/channel_layout.h"
yading@11 23 #include "libavutil/mathematics.h"
yading@11 24 #include "libavutil/opt.h"
yading@11 25 #include "avformat.h"
yading@11 26 #include "internal.h"
yading@11 27
yading@11 28 #define GSM_BLOCK_SIZE 33
yading@11 29 #define GSM_BLOCK_SAMPLES 160
yading@11 30 #define GSM_SAMPLE_RATE 8000
yading@11 31
yading@11 32 typedef struct {
yading@11 33 AVClass *class;
yading@11 34 int sample_rate;
yading@11 35 } GSMDemuxerContext;
yading@11 36
yading@11 37 static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 38 {
yading@11 39 int ret, size;
yading@11 40
yading@11 41 size = GSM_BLOCK_SIZE;
yading@11 42
yading@11 43 pkt->pos = avio_tell(s->pb);
yading@11 44 pkt->stream_index = 0;
yading@11 45
yading@11 46 ret = av_get_packet(s->pb, pkt, size);
yading@11 47 if (ret < GSM_BLOCK_SIZE) {
yading@11 48 av_free_packet(pkt);
yading@11 49 return ret < 0 ? ret : AVERROR(EIO);
yading@11 50 }
yading@11 51 pkt->duration = 1;
yading@11 52 pkt->pts = pkt->pos / GSM_BLOCK_SIZE;
yading@11 53
yading@11 54 return 0;
yading@11 55 }
yading@11 56
yading@11 57 static int gsm_read_header(AVFormatContext *s)
yading@11 58 {
yading@11 59 GSMDemuxerContext *c = s->priv_data;
yading@11 60 AVStream *st = avformat_new_stream(s, NULL);
yading@11 61 if (!st)
yading@11 62 return AVERROR(ENOMEM);
yading@11 63
yading@11 64 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 65 st->codec->codec_id = s->iformat->raw_codec_id;
yading@11 66 st->codec->channels = 1;
yading@11 67 st->codec->channel_layout = AV_CH_LAYOUT_MONO;
yading@11 68 st->codec->sample_rate = c->sample_rate;
yading@11 69 st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES;
yading@11 70
yading@11 71 avpriv_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE);
yading@11 72
yading@11 73 return 0;
yading@11 74 }
yading@11 75
yading@11 76 static const AVOption options[] = {
yading@11 77 { "sample_rate", "", offsetof(GSMDemuxerContext, sample_rate),
yading@11 78 AV_OPT_TYPE_INT, {.i64 = GSM_SAMPLE_RATE}, 1, INT_MAX / GSM_BLOCK_SIZE,
yading@11 79 AV_OPT_FLAG_DECODING_PARAM },
yading@11 80 { NULL },
yading@11 81 };
yading@11 82
yading@11 83 static const AVClass class = {
yading@11 84 .class_name = "gsm demuxer",
yading@11 85 .item_name = av_default_item_name,
yading@11 86 .option = options,
yading@11 87 .version = LIBAVUTIL_VERSION_INT,
yading@11 88 };
yading@11 89
yading@11 90 AVInputFormat ff_gsm_demuxer = {
yading@11 91 .name = "gsm",
yading@11 92 .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
yading@11 93 .priv_data_size = sizeof(GSMDemuxerContext),
yading@11 94 .read_header = gsm_read_header,
yading@11 95 .read_packet = gsm_read_packet,
yading@11 96 .flags = AVFMT_GENERIC_INDEX,
yading@11 97 .extensions = "gsm",
yading@11 98 .raw_codec_id = AV_CODEC_ID_GSM,
yading@11 99 .priv_class = &class,
yading@11 100 };