paplayer: fix hang in flac codec, ticket 12056
[vuplus_xbmc] / xbmc / cores / paplayer / FLACcodec.cpp
index 6650095..2c4d93f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *      Copyright (C) 2005-2013 Team XBMC
- *      http://www.xbmc.org
+ *      http://xbmc.org
  *
  *  This Program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -56,7 +56,7 @@ bool FLACCodec::Init(const CStdString &strFile, unsigned int filecache)
 
   //  Extract ReplayGain info
   CTagLoaderTagLib tagLoaderTagLib;
-  tagLoaderTagLib.Load(strFile, m_tag);
+  tagLoaderTagLib.Load(strFile, m_tag, "flac");
 
   m_pFlacDecoder=m_dll.FLAC__stream_decoder_new();
 
@@ -208,7 +208,10 @@ FLAC__StreamDecoderReadStatus FLACCodec::DecoderReadCallback(const FLAC__StreamD
 
   *bytes=pThis->m_file.Read(buffer, *bytes);
 
-  return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+  if (*bytes==0)
+    return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+  else
+    return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
 }
 
 FLAC__StreamDecoderSeekStatus FLACCodec::DecoderSeekCallback(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
@@ -311,17 +314,19 @@ void FLACCodec::DecoderMetadataCallback(const FLAC__StreamDecoder *decoder, cons
 
   if (metadata->type==FLAC__METADATA_TYPE_STREAMINFO)
   {
-    static enum AEChannel map[6][7] = {
+    static enum AEChannel map[8][9] = {
       {AE_CH_FC, AE_CH_NULL},
       {AE_CH_FL, AE_CH_FR, AE_CH_NULL},
       {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_NULL},
       {AE_CH_FL, AE_CH_FR, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
       {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
-      {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_NULL}
+      {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_NULL}, // 6 channels
+      {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BC, AE_CH_BL, AE_CH_BR, AE_CH_NULL}, // 7 channels
+      {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_SL, AE_CH_SR, AE_CH_NULL} // 8 channels
     };
 
     /* channel counts greater then 6 are undefined */
-    if (metadata->data.stream_info.channels > 6)
+    if (metadata->data.stream_info.channels > 8)
       pThis->m_ChannelInfo = CAEUtil::GuessChLayout(metadata->data.stream_info.channels);
     else
       pThis->m_ChannelInfo = CAEChannelInfo(map[metadata->data.stream_info.channels - 1]);