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

libavformat/g723_1.c

Go to the documentation of this file.
00001 /*
00002  * G.723.1 demuxer
00003  * Copyright (c) 2010 Mohamed Naufal Basheer
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #include "avformat.h"
00028 #include "internal.h"
00029 
00030 static const uint8_t frame_size[4] = {24, 20, 4, 1};
00031 
00032 static int g723_1_init(AVFormatContext *s, AVFormatParameters *ap)
00033 {
00034     AVStream *st;
00035 
00036     st = avformat_new_stream(s, NULL);
00037     if (!st)
00038         return AVERROR(ENOMEM);
00039 
00040     st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
00041     st->codec->codec_id    = CODEC_ID_G723_1;
00042     st->codec->channels    = 1;
00043     st->codec->sample_rate = 8000;
00044 
00045     avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
00046 
00047     return 0;
00048 }
00049 
00050 static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
00051 {
00052     int size, byte, ret;
00053 
00054     pkt->pos = avio_tell(s->pb);
00055     byte     = avio_r8(s->pb);
00056     size     = frame_size[byte & 3];
00057 
00058     ret = av_new_packet(pkt, size);
00059     if (ret < 0)
00060         return ret;
00061 
00062     pkt->data[0]      = byte;
00063     pkt->duration     = 240;
00064     pkt->stream_index = 0;
00065 
00066     ret = avio_read(s->pb, pkt->data + 1, size - 1);
00067     if (ret < size - 1) {
00068         av_free_packet(pkt);
00069         return ret < 0 ? ret : AVERROR_EOF;
00070     }
00071 
00072     return pkt->size;
00073 }
00074 
00075 AVInputFormat ff_g723_1_demuxer = {
00076     .name        = "g723_1",
00077     .long_name   = NULL_IF_CONFIG_SMALL("G.723.1 format"),
00078     .read_header = g723_1_init,
00079     .read_packet = g723_1_read_packet,
00080     .extensions = "tco,rco",
00081     .flags = AVFMT_GENERIC_INDEX
00082 };
Generated on Fri Feb 1 2013 14:34:35 for FFmpeg by doxygen 1.7.1