00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "libavutil/channel_layout.h"
00027 #include "libavutil/intreadwrite.h"
00028 #include "avformat.h"
00029 #include "internal.h"
00030 #include "pcm.h"
00031
00032
00033 #define AU_UNKNOWN_SIZE ((uint32_t)(~0))
00034
00035 static int sol_probe(AVProbeData *p)
00036 {
00037
00038 uint16_t magic = AV_RL32(p->buf);
00039 if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) &&
00040 p->buf[2] == 'S' && p->buf[3] == 'O' &&
00041 p->buf[4] == 'L' && p->buf[5] == 0)
00042 return AVPROBE_SCORE_MAX;
00043 else
00044 return 0;
00045 }
00046
00047 #define SOL_DPCM 1
00048 #define SOL_16BIT 4
00049 #define SOL_STEREO 16
00050
00051 static enum AVCodecID sol_codec_id(int magic, int type)
00052 {
00053 if (magic == 0x0B8D)
00054 {
00055 if (type & SOL_DPCM) return AV_CODEC_ID_SOL_DPCM;
00056 else return AV_CODEC_ID_PCM_U8;
00057 }
00058 if (type & SOL_DPCM)
00059 {
00060 if (type & SOL_16BIT) return AV_CODEC_ID_SOL_DPCM;
00061 else if (magic == 0x0C8D) return AV_CODEC_ID_SOL_DPCM;
00062 else return AV_CODEC_ID_SOL_DPCM;
00063 }
00064 if (type & SOL_16BIT) return AV_CODEC_ID_PCM_S16LE;
00065 return AV_CODEC_ID_PCM_U8;
00066 }
00067
00068 static int sol_codec_type(int magic, int type)
00069 {
00070 if (magic == 0x0B8D) return 1;
00071 if (type & SOL_DPCM)
00072 {
00073 if (type & SOL_16BIT) return 3;
00074 else if (magic == 0x0C8D) return 1;
00075 else return 2;
00076 }
00077 return -1;
00078 }
00079
00080 static int sol_channels(int magic, int type)
00081 {
00082 if (magic == 0x0B8D || !(type & SOL_STEREO)) return 1;
00083 return 2;
00084 }
00085
00086 static int sol_read_header(AVFormatContext *s)
00087 {
00088 unsigned int magic,tag;
00089 AVIOContext *pb = s->pb;
00090 unsigned int id, channels, rate, type;
00091 enum AVCodecID codec;
00092 AVStream *st;
00093
00094
00095 magic = avio_rl16(pb);
00096 tag = avio_rl32(pb);
00097 if (tag != MKTAG('S', 'O', 'L', 0))
00098 return -1;
00099 rate = avio_rl16(pb);
00100 type = avio_r8(pb);
00101 avio_skip(pb, 4);
00102 if (magic != 0x0B8D)
00103 avio_r8(pb);
00104
00105 codec = sol_codec_id(magic, type);
00106 channels = sol_channels(magic, type);
00107
00108 if (codec == AV_CODEC_ID_SOL_DPCM)
00109 id = sol_codec_type(magic, type);
00110 else id = 0;
00111
00112
00113 st = avformat_new_stream(s, NULL);
00114 if (!st)
00115 return -1;
00116 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00117 st->codec->codec_tag = id;
00118 st->codec->codec_id = codec;
00119 st->codec->channels = channels;
00120 st->codec->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO :
00121 AV_CH_LAYOUT_STEREO;
00122 st->codec->sample_rate = rate;
00123 avpriv_set_pts_info(st, 64, 1, rate);
00124 return 0;
00125 }
00126
00127 #define MAX_SIZE 4096
00128
00129 static int sol_read_packet(AVFormatContext *s,
00130 AVPacket *pkt)
00131 {
00132 int ret;
00133
00134 if (url_feof(s->pb))
00135 return AVERROR(EIO);
00136 ret= av_get_packet(s->pb, pkt, MAX_SIZE);
00137 if (ret < 0)
00138 return ret;
00139 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
00140 pkt->stream_index = 0;
00141 return 0;
00142 }
00143
00144 AVInputFormat ff_sol_demuxer = {
00145 .name = "sol",
00146 .long_name = NULL_IF_CONFIG_SMALL("Sierra SOL"),
00147 .read_probe = sol_probe,
00148 .read_header = sol_read_header,
00149 .read_packet = sol_read_packet,
00150 .read_seek = ff_pcm_read_seek,
00151 };