/**
* BDACardCollection.cpp
* Copyright (C) 2004 Nate
*
* This file is part of DigitalWatch, a free DTV watching and recording
* program for the VisionPlus DVB-T.
*
* DigitalWatch is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DigitalWatch is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DigitalWatch; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//this is a file from DigitalWatch 2 that i've hacked up to work here.
#include "BDACardCollection.h"
#include "StdAfx.h"
#include "ParseLine.h"
#include "GlobalFunctions.h"
#include <dshow.h>
#include <ks.h> // Must be included before ksmedia.h
#include <ksmedia.h> // Must be included before bdamedia.h
#include <bdatypes.h> // Must be included before bdamedia.h
#include <bdamedia.h>
#include "XMLDocument.h"
BDACardCollection::BDACardCollection()
{
m_filename = NULL;
}
BDACardCollection::~BDACardCollection()
{
std::vector<BDACard *>::iterator it = cards.begin();
for ( ; it != cards.end() ; it++ )
{
delete *it;
}
cards.clear();
}
void BDACardCollection::SetLogCallback(LogMessageCallback *callback)
{
LogMessageCaller::SetLogCallback(callback);
graphTools.SetLogCallback(callback);
std::vector<BDACard *>::iterator it = cards.begin();
for ( ; it != cards.end() ; it++ )
{
BDACard *card = *it;
card->SetLogCallback(callback);
}
}
LogMessage BDACardCollection::get_Logger()
{
return log;
}
BOOL BDACardCollection::LoadCards()
{
if (m_filename)
delete m_filename;
m_filename = NULL;
return LoadCardsFromHardware();
}
BOOL BDACardCollection::LoadCards(LPWSTR filename)
{
LoadCardsFromFile(filename);
return LoadCardsFromHardware();
}
BOOL BDACardCollection::LoadCardsFromFile(LPWSTR filename)
{
(log << "Loading BDA DVB-T Cards file: " << filename << "\n").Write();
LogMessageIndent indent(&log);
strCopy(m_filename, filename);
XMLDocument file;
file.SetLogCallback(m_pLogCallback);
if (file.Load(m_filename) != S_OK)
{
return (log << "Could not load cards file: " << m_filename << "\n").Write(false);
}
BDACard* currCard = NULL;
int elementCount = file.Elements.Count();
for ( int item=0 ; item<elementCount ; item++ )
{
XMLElement *element = file.Elements.Item(item);
if (_wcsicmp(element->name, L"card") != 0)
continue;
currCard = new BDACard();
currCard->SetLogCallback(m_pLogCallback);
if (currCard->LoadFromXML(element) == S_OK)
AddCardToList(currCard);
else
delete currCard;
}
indent.Release();
(log << "Finished Loading BDA DVB-T Cards file\n").Write();
return (cards.size() > 0);
}
void BDACardCollection::AddCardToList(BDACard* currCard)
{
//check if currCard is present and check that all it's values got set before pushing it into the cards vector
if (currCard)
{
if ((currCard->tunerDevice.strDevicePath == NULL) ||
(currCard->tunerDevice.strFriendlyName == NULL))
{
(log << "Error in " << m_filename << ": Cannot add device without setting tuner name and device path\n").Write();
return;
}
cards.push_back(currCard);
}
}
BOOL BDACardCollection::SaveCards(LPWSTR filename)
{
XMLDocument file;
file.SetLogCallback(m_pLogCallback);
std::vector<BDACard *>::iterator it = cards.begin();
for ( ; it < cards.end() ; it++ )
{
XMLElement *pElement = new XMLElement(L"Card");
BDACard *pCard = *it;
pCard->SaveToXML(pElement);
file.Elements.Add(pElement);
}
if (filename)
file.Save(filename);
else
file.Save(m_filename);
return TRUE;
}
BOOL BDACardCollection::LoadCardsFromHardware()
{
HRESULT hr = S_OK;
(log << "Checking for new BDA DVB-T Cards\n").Write();
LogMessageIndent indent(&log);
DirectShowSystemDevice* pTunerDevice;
DirectShowSystemDeviceEnumerator enumerator(KSCATEGORY_BDA_NETWORK_TUNER);
enumerator.SetLogCallback(m_pLogCallback);
while (enumerator.Next(&pTunerDevice) == S_OK)
{
(log << "Tuner - " << pTunerDevice->strFriendlyName << "\n").Write();
LogMessageIndent indentB(&log);
(log << pTunerDevice->strDevicePath << "\n").Write();
LogMessageIndent indentC(&log);
BDACard *bdaCard = NULL;
std::vector<BDACard *>::iterator it = cards.begin();
for ( ; it != cards.end() ; it++ )
{
bdaCard = *it;
if (_wcsicmp(pTunerDevice->strDevicePath, bdaCard->tunerDevice.strDevicePath) == 0)
break;
bdaCard = NULL;
}
if (bdaCard)
{
(log << "This tuner was loaded from file\n").Write();
bdaCard->bDetected = TRUE;
//TODO: maybe?? verify tuner can connect to the capture filter.
}
else
{
DirectShowSystemDevice* pDemodDevice;
DirectShowSystemDevice* pCaptureDevice;
if (FindCaptureDevice(pTunerDevice, &pDemodDevice, &pCaptureDevice))
{
bdaCard = new BDACard();
bdaCard->SetLogCallback(m_pLogCallback);
bdaCard->bActive = TRUE;
bdaCard->bNew = TRUE;
bdaCard->bDetected = TRUE;
bdaCard->tunerDevice = *pTunerDevice;
if (pDemodDevice)
{
(log << "Demod - " << pDemodDevice->strFriendlyName << "\n").Write();
LogMessageIndent indentD(&log);
(log << pDemodDevice->strDevicePath << "\n").Write();
bdaCard->demodDevice = *pDemodDevice;
}
if (pCaptureDevice)
{
(log << "Capture - " << pCaptureDevice->strFriendlyName << "\n").Write();
LogMessageIndent indentD(&log);
(log << pCaptureDevice->strDevicePath << "\n").Write();
bdaCard->captureDevice = *pCaptureDevice;
}
cards.push_back(bdaCard);
}
}
delete pTunerDevice;
pTunerDevice = NULL;
}
if (cards.size() == 0)
return (log << "No cards found\n").Show(FALSE);
indent.Release();
(log << "Finished Checking for new BDA DVB-T Cards\n").Write();
return TRUE;
}
BOOL BDACardCollection::FindCaptureDevice(DirectShowSystemDevice* pTunerDevice, DirectShowSystemDevice** ppDemodDevice, DirectShowSystemDevice** ppCaptureDevice)
{
HRESULT hr = S_OK;
CComPtr <IGraphBuilder> piGraphBuilder;
CComPtr <IBaseFilter> piBDANetworkProvider;
CComPtr <ITuningSpace> piTuningSpace;
CComPtr <ITuneRequest> pTuneRequest;
CComPtr <IBaseFilter> piBDATuner;
CComPtr <IBaseFilter> piBDADemod;
CComPtr <IBaseFilter> piBDACapture;
BOOL bRemoveNP = FALSE;
BOOL bRemoveTuner = FALSE;
BOOL bFoundDemod = FALSE;
BOOL bFoundCapture = FALSE;
(log << "Finding Demod and Capture filters\n").Write();
do
{
//--- Create Graph ---
if FAILED(hr = piGraphBuilder.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER))
{
//(log << "Failed Creating DVB-T Graph Builder\n").Write();
break;
}
//--- Initialise Tune Request ---
if FAILED(hr = graphTools.InitDVBTTuningSpace(piTuningSpace))
{
//(log << "Failed to initialise the Tune Request\n").Write();
break;
}
//--- Get NetworkType CLSID ---
CComBSTR bstrNetworkType;
CLSID CLSIDNetworkType;
if FAILED(hr = piTuningSpace->get_NetworkType(&bstrNetworkType))
{
//(log << "Failed to get TuningSpace Network Type\n").Write();
break;
}
if FAILED(hr = CLSIDFromString(bstrNetworkType, &CLSIDNetworkType))
{
//(log << "Could not convert Network Type to CLSID\n").Write();
break;
}
//--- Create Network Provider ---
if FAILED(hr = graphTools.AddFilter(piGraphBuilder, CLSIDNetworkType, &piBDANetworkProvider, L"Network Provider"))
{
//(l
name__unwinding.rar_android开发
版权申诉
62 浏览量
2022-09-24
08:51:16
上传
评论
收藏 3KB RAR 举报
alvarocfc
- 粉丝: 108
- 资源: 1万+
最新资源
- 基于JavaScript开发的智慧养老微信小程序源码(毕设项目).zip
- kmp算法-基于C语言kmp算法实现的字符串匹配.zip
- kmp算法-使用kmp算法在Golang中实现字符串匹配.zip
- LTC2756 +LTC6244+LTC6655 设计18位乘法串行输入电流输出DAC数模转换器模块硬件(原理图+PCB)工程
- kmp算法-基于C语言实现KMP算法.zip
- DMS智能座舱项目-Python基于深度学习实现驾驶员分心行为监测系统源码.zip
- 2023年数控机床与编程知识点总结归纳(精选试题附答案).docx
- 2023年数控机床与编程考点总结.pdf
- 2023年数控机床与编程考点题型与解题方法(精选试题附答案).docx
- 3CHISS统计软件介绍(Master).pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈