]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Apple ALAC decoder not working -- magic cookie contents are faulty.
authorMike Brady <mikebrady@eircom.net>
Tue, 30 Aug 2016 22:33:08 +0000 (23:33 +0100)
committerMike Brady <mikebrady@eircom.net>
Tue, 30 Aug 2016 22:33:08 +0000 (23:33 +0100)
apple_alac.cpp
apple_alac.h
player.c
shairport.c

index 5c633fb9005ace777053e59c297a22c71d658a93..3996cfe36d8438f6507cb27357fbde5c66d8b086 100644 (file)
@@ -16,25 +16,23 @@ typedef struct magicCookie {
 magicCookie cookie;
 ALACDecoder * theDecoder;
 
-extern "C" int apple_alac_init(int frame_size,int sample_size,int sample_rate) {
+extern "C" int apple_alac_init(int32_t fmtp[12]) {
 
   memset(&cookie,0,sizeof(magicCookie));
   
-  #define CHANNELS_PER_FRAME  2
-
-  //create a magic cookie for the decoder
+  //create a magic cookie for the decoder from the fmtp information. It seems to be in the same format as a simple magic cookie
   
-  cookie.config.frameLength = Swap32NtoB(frame_size);
-  cookie.config.compatibleVersion = 0;
-  cookie.config.bitDepth = sample_size;
-  cookie.config.pb = 40;
-  cookie.config.mb = 10;
-  cookie.config.kb = 14;
-  cookie.config.numChannels = CHANNELS_PER_FRAME;
-  cookie.config.maxRun = Swap16NtoB(255);
-  cookie.config.maxFrameBytes = 0;
-  cookie.config.avgBitRate = 0;
-  cookie.config.sampleRate = Swap32NtoB(sample_rate);
+  cookie.config.frameLength = Swap32NtoB(352);
+  cookie.config.compatibleVersion = fmtp[2]; // should be zero, uint8_t
+  cookie.config.bitDepth = fmtp[3]; // uint8_t expected to be 16
+  cookie.config.pb = fmtp[4]; // uint8_t should be 40;
+  cookie.config.mb = fmtp[5]; // uint8_t should be 10;
+  cookie.config.kb = fmtp[6]; // uint8_t should be 14;
+  cookie.config.numChannels = fmtp[7]; // uint8_t expected to be 2
+  cookie.config.maxRun = Swap16NtoB(fmtp[8]); // uint16_t expected to be 255
+  cookie.config.maxFrameBytes = Swap32NtoB(fmtp[9]); // uint32_t should be 0;
+  cookie.config.avgBitRate = Swap32NtoB(fmtp[10]); // uint32_t should be 0;;
+  cookie.config.sampleRate = Swap32NtoB(fmtp[11]); // uint32_t expected to be 44100;
   
   theDecoder = new ALACDecoder;
   theDecoder->Init(&cookie, sizeof(magicCookie));  
@@ -47,7 +45,7 @@ extern "C" int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t buf
   uint32_t numFrames = 0;
   BitBuffer theInputBuffer;
   BitBufferInit(&theInputBuffer, sampleBuffer, bufferLength);
-  theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength), CHANNELS_PER_FRAME, &numFrames);
+  theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength), cookie.config.numChannels, &numFrames);
   *outsize = numFrames;
   return 0;
 }
index 61eb685c52bc79c7dfc94883efb46adeafb84bb4..11ed4ded11a51a589b6fed5b2508448c976c1a9f 100644 (file)
@@ -11,7 +11,7 @@
 #endif
 
 
-EXTERNC int apple_alac_init(int frame_size,int sample_size,int sample_rate);
+EXTERNC int apple_alac_init(int32_t fmtp[12]);
 EXTERNC int apple_alac_terminate();
 EXTERNC int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength, unsigned char *dest, int *outsize);
 
index 9cfda6d16b0228213647e3586cd8bd09c032bae9..933ee1bcb605fcfe75ac7e46577eeec3da12ec52 100644 (file)
--- a/player.c
+++ b/player.c
@@ -365,7 +365,7 @@ static int init_decoder(int32_t fmtp[12]) {
   input_num_channels = fmtp[7];
   input_bit_depth = fmtp[3];
   
-  input_bytes_per_frame = input_num_channels*(input_bit_depth+7)/8;
+  input_bytes_per_frame = input_num_channels*((input_bit_depth+7)/8);
 
   alac = alac_create(input_bit_depth, input_num_channels);
   if (!alac)
@@ -386,7 +386,7 @@ static int init_decoder(int32_t fmtp[12]) {
   alac_allocate_buffers(alac);
 
 #ifdef HAVE_APPLE_ALAC
-  apple_alac_init(max_frames_per_packet,input_bit_depth,input_sample_rate);
+  apple_alac_init(fmtp);
 #endif
 
   return 0;
index 219f95e125d01dc8234b3068bd7def6a388ccddd..afcccac362f4f62a671174c51de0f44a8bd5d012 100644 (file)
@@ -442,7 +442,7 @@ int parse_options(int argc, char **argv) {
       }
 
       /* Get the alac_decoder setting. */
-      if (config_lookup_string(config.cfg, "alac_decoder", &str)) {
+      if (config_lookup_string(config.cfg, "general.alac_decoder", &str)) {
         if (strcasecmp(str, "hammerton") == 0)
           config.use_apple_decoder = 0;
         else if (strcasecmp(str, "apple") == 0) {