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

libavformat/sol.c

Go to the documentation of this file.
00001 /*
00002  * Sierra SOL demuxer
00003  * Copyright Konstantin Shishkov
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 /*
00023  * Based on documents from Game Audio Player and own research
00024  */
00025 
00026 #include "libavutil/bswap.h"
00027 #include "avformat.h"
00028 #include "raw.h"
00029 
00030 /* if we don't know the size in advance */
00031 #define AU_UNKNOWN_SIZE ((uint32_t)(~0))
00032 
00033 static int sol_probe(AVProbeData *p)
00034 {
00035     /* check file header */
00036     uint16_t magic;
00037     magic=le2me_16(*((uint16_t*)p->buf));
00038     if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) &&
00039         p->buf[2] == 'S' && p->buf[3] == 'O' &&
00040         p->buf[4] == 'L' && p->buf[5] == 0)
00041         return AVPROBE_SCORE_MAX;
00042     else
00043         return 0;
00044 }
00045 
00046 #define SOL_DPCM    1
00047 #define SOL_16BIT   4
00048 #define SOL_STEREO 16
00049 
00050 static enum CodecID sol_codec_id(int magic, int type)
00051 {
00052     if (magic == 0x0B8D)
00053     {
00054         if (type & SOL_DPCM) return CODEC_ID_SOL_DPCM;
00055         else return CODEC_ID_PCM_U8;
00056     }
00057     if (type & SOL_DPCM)
00058     {
00059         if (type & SOL_16BIT) return CODEC_ID_SOL_DPCM;
00060         else if (magic == 0x0C8D) return CODEC_ID_SOL_DPCM;
00061         else return CODEC_ID_SOL_DPCM;
00062     }
00063     if (type & SOL_16BIT) return CODEC_ID_PCM_S16LE;
00064     return CODEC_ID_PCM_U8;
00065 }
00066 
00067 static int sol_codec_type(int magic, int type)
00068 {
00069     if (magic == 0x0B8D) return 1;//SOL_DPCM_OLD;
00070     if (type & SOL_DPCM)
00071     {
00072         if (type & SOL_16BIT) return 3;//SOL_DPCM_NEW16;
00073         else if (magic == 0x0C8D) return 1;//SOL_DPCM_OLD;
00074         else return 2;//SOL_DPCM_NEW8;
00075     }
00076     return -1;
00077 }
00078 
00079 static int sol_channels(int magic, int type)
00080 {
00081     if (magic == 0x0B8D || !(type & SOL_STEREO)) return 1;
00082     return 2;
00083 }
00084 
00085 static int sol_read_header(AVFormatContext *s,
00086                           AVFormatParameters *ap)
00087 {
00088     int size;
00089     unsigned int magic,tag;
00090     ByteIOContext *pb = s->pb;
00091     unsigned int id, channels, rate, type;
00092     enum CodecID codec;
00093     AVStream *st;
00094 
00095     /* check ".snd" header */
00096     magic = get_le16(pb);
00097     tag = get_le32(pb);
00098     if (tag != MKTAG('S', 'O', 'L', 0))
00099         return -1;
00100     rate = get_le16(pb);
00101     type = get_byte(pb);
00102     size = get_le32(pb);
00103     if (magic != 0x0B8D)
00104         get_byte(pb); /* newer SOLs contain padding byte */
00105 
00106     codec = sol_codec_id(magic, type);
00107     channels = sol_channels(magic, type);
00108 
00109     if (codec == CODEC_ID_SOL_DPCM)
00110         id = sol_codec_type(magic, type);
00111     else id = 0;
00112 
00113     /* now we are ready: build format streams */
00114     st = av_new_stream(s, 0);
00115     if (!st)
00116         return -1;
00117     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00118     st->codec->codec_tag = id;
00119     st->codec->codec_id = codec;
00120     st->codec->channels = channels;
00121     st->codec->sample_rate = rate;
00122     av_set_pts_info(st, 64, 1, rate);
00123     return 0;
00124 }
00125 
00126 #define MAX_SIZE 4096
00127 
00128 static int sol_read_packet(AVFormatContext *s,
00129                           AVPacket *pkt)
00130 {
00131     int ret;
00132 
00133     if (url_feof(s->pb))
00134         return AVERROR(EIO);
00135     ret= av_get_packet(s->pb, pkt, MAX_SIZE);
00136     pkt->stream_index = 0;
00137 
00138     /* note: we need to modify the packet size here to handle the last
00139        packet */
00140     pkt->size = ret;
00141     return 0;
00142 }
00143 
00144 AVInputFormat sol_demuxer = {
00145     "sol",
00146     NULL_IF_CONFIG_SMALL("Sierra SOL format"),
00147     0,
00148     sol_probe,
00149     sol_read_header,
00150     sol_read_packet,
00151     NULL,
00152     pcm_read_seek,
00153 };

Generated on Fri Sep 16 2011 17:17:51 for FFmpeg by  doxygen 1.7.1