+ switch (compression_type) {
+ case 0: ea->audio_codec = AV_CODEC_ID_PCM_S16LE; break;
+ case 7: ea->audio_codec = AV_CODEC_ID_ADPCM_EA; break;
+ case -1:
+ switch (revision) {
+ case 1: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R1; break;
+ case 2: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R2; break;
+ case 3: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R3; break;
+ case -1: break;
+ default:
+ av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision);
+ return 0;
+ }
+ switch (revision2) {
+ case 8: ea->audio_codec = AV_CODEC_ID_PCM_S16LE_PLANAR; break;
+ case 10: ea->audio_codec = AV_CODEC_ID_ADPCM_EA_R2; break;
+ case 16: ea->audio_codec = AV_CODEC_ID_MP3; break;
+ case -1: break;
+ default:
+ ea->audio_codec = AV_CODEC_ID_NONE;
+ av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2);
+ return 0;
+ }
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type);
+ return 0;
+ }
+
+ if (ea->sample_rate == -1)
+ ea->sample_rate = revision==3 ? 48000 : 22050;
+
+ return 1;
+}
+
+/*
+ * Process EACS sound header
+ * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
+ */
+static int process_audio_header_eacs(AVFormatContext *s)
+{
+ EaDemuxContext *ea = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int compression_type;
+
+ ea->sample_rate = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
+ ea->bytes = avio_r8(pb); /* 1=8-bit, 2=16-bit */
+ ea->num_channels = avio_r8(pb);
+ compression_type = avio_r8(pb);
+ avio_skip(pb, 13);
+
+ switch (compression_type) {
+ case 0:
+ switch (ea->bytes) {
+ case 1: ea->audio_codec = AV_CODEC_ID_PCM_S8; break;
+ case 2: ea->audio_codec = AV_CODEC_ID_PCM_S16LE; break;
+ }
+ break;
+ case 1: ea->audio_codec = AV_CODEC_ID_PCM_MULAW; ea->bytes = 1; break;
+ case 2: ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_EACS; break;
+ default:
+ av_log (s, AV_LOG_ERROR, "unsupported stream type; audio compression_type=%i\n", compression_type);
+ }
+
+ return 1;
+}
+
+/*
+ * Process SEAD sound header
+ * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
+ */
+static int process_audio_header_sead(AVFormatContext *s)
+{
+ EaDemuxContext *ea = s->priv_data;
+ AVIOContext *pb = s->pb;
+
+ ea->sample_rate = avio_rl32(pb);
+ ea->bytes = avio_rl32(pb); /* 1=8-bit, 2=16-bit */
+ ea->num_channels = avio_rl32(pb);
+ ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_SEAD;
+
+ return 1;
+}