• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/gsmdec.c

Go to the documentation of this file.
00001 /*
00002  * RAW GSM demuxer
00003  * Copyright (c) 2011 Justin Ruggles
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavutil/mathematics.h"
00023 #include "libavutil/opt.h"
00024 #include "avformat.h"
00025 #include "internal.h"
00026 
00027 #define GSM_BLOCK_SIZE    33
00028 #define GSM_BLOCK_SAMPLES 160
00029 #define GSM_SAMPLE_RATE   8000
00030 
00031 typedef struct {
00032     AVClass *class;
00033     int sample_rate;
00034 } GSMDemuxerContext;
00035 
00036 static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
00037 {
00038     int ret, size;
00039 
00040     size = GSM_BLOCK_SIZE;
00041 
00042     pkt->pos = avio_tell(s->pb);
00043     pkt->stream_index = 0;
00044 
00045     ret = av_get_packet(s->pb, pkt, size);
00046     if (ret < GSM_BLOCK_SIZE) {
00047         av_free_packet(pkt);
00048         return ret < 0 ? ret : AVERROR(EIO);
00049     }
00050     pkt->size     = ret;
00051     pkt->duration = 1;
00052     pkt->pts      = pkt->pos / GSM_BLOCK_SIZE;
00053 
00054     return 0;
00055 }
00056 
00057 static int gsm_read_header(AVFormatContext *s, AVFormatParameters *ap)
00058 {
00059     GSMDemuxerContext *c = s->priv_data;
00060     AVStream *st = avformat_new_stream(s, NULL);
00061     if (!st)
00062         return AVERROR(ENOMEM);
00063 
00064     st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
00065     st->codec->codec_id    = s->iformat->value;
00066     st->codec->channels    = 1;
00067     st->codec->sample_rate = c->sample_rate;
00068     st->codec->bit_rate    = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES;
00069 
00070     avpriv_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE);
00071 
00072     return 0;
00073 }
00074 
00075 static const AVOption options[] = {
00076     { "sample_rate", "", offsetof(GSMDemuxerContext, sample_rate),
00077        AV_OPT_TYPE_INT, {.dbl = GSM_SAMPLE_RATE}, 1, INT_MAX / GSM_BLOCK_SIZE,
00078        AV_OPT_FLAG_DECODING_PARAM },
00079     { NULL },
00080 };
00081 
00082 static const AVClass class = {
00083     .class_name = "gsm demuxer",
00084     .item_name  = av_default_item_name,
00085     .option     = options,
00086     .version    = LIBAVUTIL_VERSION_INT,
00087 };
00088 
00089 AVInputFormat ff_gsm_demuxer = {
00090     .name           = "gsm",
00091     .long_name      = NULL_IF_CONFIG_SMALL("raw GSM"),
00092     .priv_data_size = sizeof(GSMDemuxerContext),
00093     .read_header    = gsm_read_header,
00094     .read_packet    = gsm_read_packet,
00095     .flags          = AVFMT_GENERIC_INDEX,
00096     .extensions     = "gsm",
00097     .value          = CODEC_ID_GSM,
00098     .priv_class     = &class,
00099 };
Generated on Fri Feb 1 2013 14:34:35 for FFmpeg by doxygen 1.7.1