changeset 30842:482aa22c785e

Support extradata format of the speex.acm windows codec formerly available from openacm.org.
author reimar
date Fri, 12 Mar 2010 18:19:51 +0000
parents a1bf34d75484
children 72281d3a78e8
files libmpcodecs/ad_speex.c
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/ad_speex.c	Fri Mar 12 17:29:48 2010 +0000
+++ b/libmpcodecs/ad_speex.c	Fri Mar 12 18:19:51 2010 +0000
@@ -52,8 +52,15 @@
   return 1;
 }
 
+static int read_le32(const uint8_t **src) {
+    const uint8_t *p = *src;
+    *src += 4;
+    return p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
+}
+
 static int init(sh_audio_t *sh) {
   context_t *ctx = calloc(1, sizeof(context_t));
+  const uint8_t *hdr = (const uint8_t *)(sh->wf + 1);
   const SpeexMode *spx_mode;
   const SpeexStereoState st_st = SPEEX_STEREO_STATE_INIT; // hack
   if (!sh->wf || sh->wf->cbSize < 80) {
@@ -61,6 +68,23 @@
     return 0;
   }
   ctx->hdr = speex_packet_to_header((char *)&sh->wf[1], sh->wf->cbSize);
+  if (!ctx->hdr && sh->wf->cbSize == 0x72 && hdr[0] == 1 && hdr[1] == 0) {
+    // speex.acm format: raw SpeexHeader dump
+    ctx->hdr = calloc(1, sizeof(*ctx->hdr));
+    hdr += 2;
+    hdr += 8; // identifier string
+    hdr += 20; // version string
+    ctx->hdr->speex_version_id = read_le32(&hdr);
+    ctx->hdr->header_size = read_le32(&hdr);
+    ctx->hdr->rate = read_le32(&hdr);
+    ctx->hdr->mode = read_le32(&hdr);
+    ctx->hdr->mode_bitstream_version = read_le32(&hdr);
+    ctx->hdr->nb_channels = read_le32(&hdr);
+    ctx->hdr->bitrate = read_le32(&hdr);
+    ctx->hdr->frame_size = read_le32(&hdr);
+    ctx->hdr->vbr = read_le32(&hdr);
+    ctx->hdr->frames_per_packet = read_le32(&hdr);
+  }
   if (!ctx->hdr) {
     mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Invalid extradata!\n");
     return 0;