HRESULT CWavPackDSSplitterInputPin::BreakConnect(void) { DebugLog("CWavPackDSSplitterInputPin::BreakConnect 0x%08X", GetCurrentThreadId()); HRESULT hr = CBaseInputPin::BreakConnect(); if (FAILED(hr)) return hr; if(m_pIACBW) { IAsyncCallBackWrapper_free(m_pIACBW); m_pIACBW = NULL; } if (m_pReader) { m_pReader->Release(); m_pReader = NULL; } if(m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } m_pParentFilter->CleanupOnInputBreakConnect(); return S_OK; }
HRESULT CWavPackDSSplitterInputPin::CompleteConnect(IPin *pReceivePin) { DebugLog("CWavPackDSSplitterInputPin::CompleteConnect 0x%08X", GetCurrentThreadId()); HRESULT hr = CBaseInputPin::CompleteConnect(pReceivePin); if (FAILED(hr)) return hr; if(m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } m_pWavPackParser = wavpack_parser_new((WavpackStreamReader*)m_pIACBW, FALSE); if(!m_pWavPackParser) { DebugLog("CWavPackDSSplitterInputPin::CompleteConnect wavpack_parser_new failed 0x%08X", GetCurrentThreadId()); return E_FAIL; } // Compute total duration REFERENCE_TIME rtDuration; rtDuration = m_pWavPackParser->first_wphdr.total_samples; rtDuration = (rtDuration * 10000000) / m_pWavPackParser->sample_rate; m_pParentFilter->SetDuration(rtDuration); m_pParentFilter->CreateCorrectionFilePin(); return S_OK; }
CWavPackSplitterFilterInputPin::~CWavPackSplitterFilterInputPin() { if (m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } }
CWavPackDSSplitterCorrectionInputPin::~CWavPackDSSplitterCorrectionInputPin() { if(m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } }
HRESULT CWavPackSplitterFilterInputPin::CheckMediaType(const CMediaType *pmt) { if (*pmt->Type() == MEDIATYPE_Stream && m_pIACBW) { if (m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } m_pWavPackParser = wavpack_parser_new((stream_reader*)m_pIACBW, FALSE); if (!m_pWavPackParser) { return VFW_E_TYPE_NOT_ACCEPTED; } return S_OK; } else { return VFW_E_TYPE_NOT_ACCEPTED; } }
HRESULT CWavPackDSSplitterCorrectionInputPin::CompleteConnect(IPin *pReceivePin) { DebugLog("CWavPackDSSplitterCorrectionInputPin::CompleteConnect 0x%08X", GetCurrentThreadId()); HRESULT hr = CBaseInputPin::CompleteConnect(pReceivePin); if (FAILED(hr)) return hr; if(m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } m_pWavPackParser = wavpack_parser_new((WavpackStreamReader*)m_pIACBW, TRUE); if(!m_pWavPackParser) { return E_FAIL; } m_bDiscontinuity = TRUE; return S_OK; }
HRESULT CWavPackSplitterFilterInputPin::CompleteConnect(IPin *pReceivePin) { HRESULT hr = CBaseInputPin::CompleteConnect(pReceivePin); if (FAILED(hr)) { return hr; } if (m_pWavPackParser) { wavpack_parser_free(m_pWavPackParser); m_pWavPackParser = NULL; } m_pWavPackParser = wavpack_parser_new((stream_reader*)m_pIACBW, FALSE); if (!m_pWavPackParser) { return E_FAIL; } // Compute total duration REFERENCE_TIME rtDuration; rtDuration = m_pWavPackParser->first_wphdr.total_samples; rtDuration = (rtDuration * 10000000) / m_pWavPackParser->sample_rate; m_pParentFilter->SetDuration(rtDuration); // parse APE Tag Header stream_reader* io = m_pWavPackParser->io; char buf[APE_TAG_FOOTER_BYTES]; memset(buf, 0, sizeof(buf)); uint32_t cur_pos = io->get_pos(io); DWORD file_size = io->get_length(io); if (cur_pos + APE_TAG_FOOTER_BYTES <= file_size) { io->set_pos_rel(io, -APE_TAG_FOOTER_BYTES, SEEK_END); if (io->read_bytes(io, buf, APE_TAG_FOOTER_BYTES) == APE_TAG_FOOTER_BYTES) { CAPETag* APETag = DNew CAPETag; if (APETag->ReadFooter((BYTE*)buf, APE_TAG_FOOTER_BYTES) && APETag->GetTagSize()) { size_t tag_size = APETag->GetTagSize(); io->set_pos_rel(io, file_size - tag_size, SEEK_SET); BYTE *p = DNew BYTE[tag_size]; if (io->read_bytes(io, p, tag_size) == tag_size) { if (APETag->ReadTags(p, tag_size)) { POSITION pos = APETag->TagItems.GetHeadPosition(); while (pos) { CApeTagItem* item = APETag->TagItems.GetAt(pos); CString TagKey = item->GetKey(); TagKey.MakeLower(); if (item->GetType() == CApeTagItem::APE_TYPE_BINARY) { m_CoverMime = _T(""); if (!TagKey.IsEmpty()) { CString ext = TagKey.Mid(TagKey.ReverseFind('.')+1); if (ext == _T("jpeg") || ext == _T("jpg")) { m_CoverMime = _T("image/jpeg"); } else if (ext == _T("png")) { m_CoverMime = _T("image/png"); } } if (!m_Cover.GetCount() && !m_CoverMime.IsEmpty()) { m_CoverFileName = TagKey; m_Cover.SetCount(tag_size); memcpy(m_Cover.GetData(), item->GetData(), item->GetDataLen()); } } else { CString TagValue = item->GetValue(); if (TagKey == _T("cuesheet")) { CAtlList<Chapters> ChaptersList; if (ParseCUESheet(TagValue, ChaptersList)) { m_pParentFilter->ChapRemoveAll(); while (ChaptersList.GetCount()) { Chapters cp = ChaptersList.RemoveHead(); m_pParentFilter->ChapAppend(cp.rt, cp.name); } } } if (TagKey == _T("artist")) { m_pParentFilter->SetProperty(L"AUTH", TagValue); } else if (TagKey == _T("comment")) { m_pParentFilter->SetProperty(L"DESC", TagValue); } else if (TagKey == _T("title")) { m_pParentFilter->SetProperty(L"TITL", TagValue); } else if (TagKey == _T("year")) { m_pParentFilter->SetProperty(L"YEAR", TagValue); } else if (TagKey == _T("album")) { m_pParentFilter->SetProperty(L"ALBUM", TagValue); } } APETag->TagItems.GetNext(pos); } } } delete [] p; } delete APETag; } io->set_pos_rel(io, cur_pos, SEEK_SET); } return S_OK; }