HRESULT tTVPMFPlayer::AddBranchToPartialTopology( IMFTopology *pTopology, IMFMediaSource *pSource, IMFPresentationDescriptor *pPD, DWORD iStream, HWND hVideoWnd ) { CComPtr<IMFStreamDescriptor> pSD; HRESULT hr; BOOL selected = FALSE; if( FAILED(hr = pPD->GetStreamDescriptorByIndex(iStream, &selected, &pSD)) ) { TVPThrowExceptionMessage(L"Faild to get stream desc."); } if( selected ) { // Create the media sink activation object. CComPtr<IMFActivate> pSinkActivate; if( FAILED(hr = CreateMediaSinkActivate(pSD, hVideoWnd, &pSinkActivate)) ) { return S_OK; // video と audio 以外は無視 } // Add a source node for this stream. CComPtr<IMFTopologyNode> pSourceNode; if( FAILED(hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pSourceNode) ) ) { TVPThrowExceptionMessage(L"Faild to add source node."); } // Create the output node for the renderer. CComPtr<IMFTopologyNode> pOutputNode; if( FAILED(hr = AddOutputNode(pTopology, pSinkActivate, 0, &pOutputNode)) ) { TVPThrowExceptionMessage(L"Faild to add output node."); } // Connect the source node to the output node. if( FAILED(hr = pSourceNode->ConnectOutput(0, pOutputNode, 0)) ) { TVPThrowExceptionMessage(L"Faild to connect node."); } } return hr; }
void AddBranchToPartialTopology( IMFTopologyPtr pTopology, // Topology. IMFMediaSourcePtr pSource, // Media source. IMFPresentationDescriptorPtr pPD, // Presentation descriptor. DWORD iStream, // Stream index. HWND hVideoWnd) // Window for video playback. { IMFStreamDescriptorPtr pSD; IMFActivatePtr pSinkActivate; IMFTopologyNodePtr pSourceNode; IMFTopologyNodePtr pOutputNode; BOOL fSelected = FALSE; THROW_IF_ERR(pPD->GetStreamDescriptorByIndex(iStream, &fSelected, &pSD)); if (fSelected) { // Create the media sink activation object. pSinkActivate = CreateMediaSinkActivate(pSD.Get(), hVideoWnd); // Add a source node for this stream. pSourceNode = AddSourceNode(pTopology, pSource, pPD, pSD); // Create the output node for the renderer. pOutputNode = AddOutputNode(pTopology, pSinkActivate, 0); // Connect the source node to the output node. THROW_IF_ERR(pSourceNode->ConnectOutput(0, pOutputNode.Get(), 0)); } // else: If not selected, don't add the branch. }
// Create the topology. HRESULT CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo) { IMFTopology *pTopology = NULL; IMFPresentationDescriptor *pPD = NULL; IMFStreamDescriptor *pSD = NULL; IMFMediaTypeHandler *pHandler = NULL; IMFTopologyNode *pNode1 = NULL; IMFTopologyNode *pNode2 = NULL; HRESULT hr = S_OK; DWORD cStreams = 0; CHECK_HR(hr = MFCreateTopology(&pTopology)); CHECK_HR(hr = pSource->CreatePresentationDescriptor(&pPD)); CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams)); for (DWORD i = 0; i < cStreams; i++) { // In this example, we look for audio streams and connect them to the sink. BOOL fSelected = FALSE; GUID majorType; CHECK_HR(hr = pPD->GetStreamDescriptorByIndex(i, &fSelected, &pSD)); CHECK_HR(hr = pSD->GetMediaTypeHandler(&pHandler)); CHECK_HR(hr = pHandler->GetMajorType(&majorType)); if (majorType == MFMediaType_Video && fSelected) { CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pNode1)); CHECK_HR(hr = AddOutputNode(pTopology, pSinkActivate, 0, &pNode2)); CHECK_HR(hr = pNode1->ConnectOutput(0, pNode2, 0)); break; } else { CHECK_HR(hr = pPD->DeselectStream(i)); } SafeRelease(&pSD); SafeRelease(&pHandler); } *ppTopo = pTopology; (*ppTopo)->AddRef(); done: SafeRelease(&pTopology); SafeRelease(&pNode1); SafeRelease(&pNode2); SafeRelease(&pPD); SafeRelease(&pSD); SafeRelease(&pHandler); return hr; }
SourcesList::SourceRecord *SourcesList::AddEmptySource() { SourceRecord rec; #ifdef HAVE_RPM rec.Type = Rpm; #else rec.Type = Deb; #endif rec.VendorID = ""; rec.SourceFile = _config->FindFile("Dir::Etc::sourcelist"); rec.Dist = ""; rec.NumSections = 0; return AddSourceNode(rec); }
SourcesList::SourceRecord *SourcesList::AddSource(RecType Type, string VendorID, string URI, string Dist, string *Sections, unsigned short count, string SourceFile) { SourceRecord rec; rec.Type = Type; rec.VendorID = VendorID; rec.SourceFile = SourceFile; if (rec.SetURI(URI) == false) { return NULL; } rec.Dist = Dist; rec.NumSections = count; rec.Sections = new string[count]; for (unsigned int i = 0; i < count; ++i) { rec.Sections[i] = Sections[i]; } return AddSourceNode(rec); }
bool SourcesList::ReadSourcePart(string listpath) { //cout << "SourcesList::ReadSourcePart() "<< listpath << endl; char buf[512]; const char *p; ifstream ifs(listpath.c_str(), ios::in); bool record_ok = true; // cannot open file if (!ifs != 0) { return _error->Error("Can't read %s", listpath.c_str()); } while (ifs.eof() == false) { p = buf; SourceRecord rec; string Type; string Section; string VURI; ifs.getline(buf, sizeof(buf)); rec.SourceFile = listpath; while (isspace(*p)) { p++; } if (*p == '#') { rec.Type = Disabled; p++; while (isspace(*p)) p++; } if (*p == '\r' || *p == '\n' || *p == 0) { rec.Type = Comment; rec.Comment = p; AddSourceNode(rec); continue; } bool Failed = true; if (ParseQuoteWord(p, Type) == true && rec.SetType(Type) == true && ParseQuoteWord(p, VURI) == true) { if (VURI[0] == '[') { rec.VendorID = VURI.substr(1, VURI.length() - 2); if (ParseQuoteWord(p, VURI) == true && rec.SetURI(VURI) == true) Failed = false; } else if (rec.SetURI(VURI) == true) { Failed = false; } if (Failed == false && ParseQuoteWord(p, rec.Dist) == false) Failed = true; } if (Failed == true) { if (rec.Type == Disabled) { // treat as a comment field rec.Type = Comment; rec.Comment = buf; } else { // syntax error on line rec.Type = Comment; string s = "#" + string(buf); rec.Comment = s; record_ok = false; //return _error->Error("Syntax error in line %s", buf); } } #ifndef HAVE_RPM // check for absolute dist if (rec.Dist.empty() == false && rec.Dist[rec.Dist.size() - 1] == '/') { // make sure there's no section if (ParseQuoteWord(p, Section) == true) return _error->Error("Syntax error in line %s", buf); rec.Dist = SubstVar(rec.Dist, "$(ARCH)", _config->Find("APT::Architecture")); AddSourceNode(rec); continue; } #endif const char *tmp = p; rec.NumSections = 0; while (ParseQuoteWord(p, Section) == true) rec.NumSections++; if (rec.NumSections > 0) { p = tmp; rec.Sections = new string[rec.NumSections]; rec.NumSections = 0; while (ParseQuoteWord(p, Section) == true) { // comments inside the record are preserved if (Section[0] == '#') { SourceRecord rec; string s = Section + string(p); rec.Type = Comment; rec.Comment = s; rec.SourceFile = listpath; AddSourceNode(rec); break; } else { rec.Sections[rec.NumSections++] = Section; } } } AddSourceNode(rec); } ifs.close(); return record_ok; }