bool CMusicInfoTagLoaderFlac::Load(const CStdString& strFileName, CMusicInfoTag& tag) { try { // retrieve the Flac Tag info from strFileName // and put it in tag CFlacTag myTag; if (myTag.Read(strFileName)) { myTag.GetMusicInfoTag(tag); } return tag.Loaded(); } catch (...) { CLog::Log(LOGERROR, "Tag loader flac: exception in file %s", strFileName.c_str()); } tag.SetLoaded(false); return false; }
bool FLACCodec::Init(const CStdString &strFile, unsigned int filecache) { if (!m_dll.Load()) return false; if (!m_file.Open(strFile, READ_CACHED)) return false; m_pFlacDecoder=m_dll.FLAC__stream_decoder_new(); if (!m_pFlacDecoder) { CLog::Log(LOGERROR, "FLACCodec: Error creating decoder"); return false; } if (m_dll.FLAC__stream_decoder_init_stream(m_pFlacDecoder, DecoderReadCallback, DecoderSeekCallback, DecoderTellCallback, DecoderLengthCallback, DecoderEofCallback, DecoderWriteCallback, DecoderMetadataCallback, DecoderErrorCallback, this) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { CLog::Log(LOGERROR, "FLACCodec: Error initializing decoder"); FreeDecoder(); return false; } // Process metadata like number of channels... if (!m_dll.FLAC__stream_decoder_process_until_end_of_metadata(m_pFlacDecoder)) { CLog::Log(LOGERROR, "FLACCodec: Error while processing metadata"); FreeDecoder(); return false; } // These are filled by the metadata callback if (m_SampleRate==0 || m_Channels==0 || m_BitsPerSample==0 || m_TotalTime==0 || m_MaxFrameSize==0) { CLog::Log(LOGERROR, "FLACCodec: Can't get stream info, SampleRate=%i, Channels=%i, BitsPerSample=%i, TotalTime=%llu, MaxFrameSize=%i", m_SampleRate, m_Channels, m_BitsPerSample, m_TotalTime, m_MaxFrameSize); FreeDecoder(); return false; } // Extract ReplayGain info CFlacTag tag; if (tag.Read(strFile)) m_replayGain=tag.GetReplayGain(); m_Bitrate = (int)((m_file.GetLength() * 8) / (m_TotalTime/1000)); if (m_pBuffer) { delete[] m_pBuffer; m_pBuffer=NULL; } // allocate the buffer to hold the audio data, // it is 5 times bigger then a single decoded frame m_pBuffer=new BYTE[m_MaxFrameSize*5]; return true; }