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

libavformat/vocdec.c

Go to the documentation of this file.
00001 /*
00002  * Creative Voice File demuxer.
00003  * Copyright (c) 2006  Aurelien Jacobs <aurel@gnuage.org>
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 
00022 #include "libavutil/intreadwrite.h"
00023 #include "voc.h"
00024 
00025 
00026 static int voc_probe(AVProbeData *p)
00027 {
00028     int version, check;
00029 
00030     if (memcmp(p->buf, ff_voc_magic, sizeof(ff_voc_magic) - 1))
00031         return 0;
00032     version = AV_RL16(p->buf + 22);
00033     check = AV_RL16(p->buf + 24);
00034     if (~version + 0x1234 != check)
00035         return 10;
00036 
00037     return AVPROBE_SCORE_MAX;
00038 }
00039 
00040 static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap)
00041 {
00042     VocDecContext *voc = s->priv_data;
00043     ByteIOContext *pb = s->pb;
00044     int header_size;
00045     AVStream *st;
00046 
00047     url_fskip(pb, 20);
00048     header_size = get_le16(pb) - 22;
00049     if (header_size != 4) {
00050         av_log(s, AV_LOG_ERROR, "unknown header size: %d\n", header_size);
00051         return AVERROR(ENOSYS);
00052     }
00053     url_fskip(pb, header_size);
00054     st = av_new_stream(s, 0);
00055     if (!st)
00056         return AVERROR(ENOMEM);
00057     st->codec->codec_type = CODEC_TYPE_AUDIO;
00058 
00059     voc->remaining_size = 0;
00060     return 0;
00061 }
00062 
00063 int
00064 voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
00065 {
00066     VocDecContext *voc = s->priv_data;
00067     AVCodecContext *dec = st->codec;
00068     ByteIOContext *pb = s->pb;
00069     VocType type;
00070     int size;
00071     int sample_rate = 0;
00072     int channels = 1;
00073 
00074     while (!voc->remaining_size) {
00075         type = get_byte(pb);
00076         if (type == VOC_TYPE_EOF)
00077             return AVERROR(EIO);
00078         voc->remaining_size = get_le24(pb);
00079         max_size -= 4;
00080 
00081         switch (type) {
00082         case VOC_TYPE_VOICE_DATA:
00083             dec->sample_rate = 1000000 / (256 - get_byte(pb));
00084             if (sample_rate)
00085                 dec->sample_rate = sample_rate;
00086             dec->channels = channels;
00087             dec->codec_id = codec_get_id(ff_voc_codec_tags, get_byte(pb));
00088             dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id);
00089             voc->remaining_size -= 2;
00090             max_size -= 2;
00091             channels = 1;
00092             break;
00093 
00094         case VOC_TYPE_VOICE_DATA_CONT:
00095             break;
00096 
00097         case VOC_TYPE_EXTENDED:
00098             sample_rate = get_le16(pb);
00099             get_byte(pb);
00100             channels = get_byte(pb) + 1;
00101             sample_rate = 256000000 / (channels * (65536 - sample_rate));
00102             voc->remaining_size = 0;
00103             max_size -= 4;
00104             break;
00105 
00106         case VOC_TYPE_NEW_VOICE_DATA:
00107             dec->sample_rate = get_le32(pb);
00108             dec->bits_per_coded_sample = get_byte(pb);
00109             dec->channels = get_byte(pb);
00110             dec->codec_id = codec_get_id(ff_voc_codec_tags, get_le16(pb));
00111             url_fskip(pb, 4);
00112             voc->remaining_size -= 12;
00113             max_size -= 12;
00114             break;
00115 
00116         default:
00117             url_fskip(pb, voc->remaining_size);
00118             max_size -= voc->remaining_size;
00119             voc->remaining_size = 0;
00120             break;
00121         }
00122     }
00123 
00124     dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample;
00125 
00126     if (max_size <= 0)
00127         max_size = 2048;
00128     size = FFMIN(voc->remaining_size, max_size);
00129     voc->remaining_size -= size;
00130     return av_get_packet(pb, pkt, size);
00131 }
00132 
00133 static int voc_read_packet(AVFormatContext *s, AVPacket *pkt)
00134 {
00135     return voc_get_packet(s, pkt, s->streams[0], 0);
00136 }
00137 
00138 AVInputFormat voc_demuxer = {
00139     "voc",
00140     NULL_IF_CONFIG_SMALL("Creative Voice file format"),
00141     sizeof(VocDecContext),
00142     voc_probe,
00143     voc_read_header,
00144     voc_read_packet,
00145     .codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0},
00146 };

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1