bool HDevice::SetupEncodedVideoCapture(IBaseFilter *filter, VideoConfig &config, const EncodedDevice &info) { CComPtr<IBaseFilter> crossbar; CComPtr<IBaseFilter> encoder; CComPtr<IBaseFilter> demuxer; MediaType mtVideo; MediaType mtAudio; if (!CreateFilters(filter, &crossbar, &encoder, &demuxer)) return false; if (!CreateDemuxVideoPin(demuxer, mtVideo, info.width, info.height, info.frameInterval, info.videoFormat)) return false; if (!CreateDemuxAudioPin(demuxer, mtAudio, info.samplesPerSec, 16, 2, info.audioFormat)) return false; config.cx = info.width; config.cy = info.height; config.frameInterval = info.frameInterval; config.format = info.videoFormat; config.internalFormat = info.videoFormat; PinCaptureInfo pci; pci.callback = [this] (IMediaSample *s) {Receive(true, s);}; pci.expectedMajorType = mtVideo->majortype; pci.expectedSubType = mtVideo->subtype; videoCapture = new CaptureFilter(pci); videoFilter = demuxer; if (!!encoder && config.name.find(L"IT9910") != std::string::npos) { rocketEncoder = encoder; if (!SetRocketEnabled(rocketEncoder, true)) return false; } graph->AddFilter(crossbar, L"Crossbar"); graph->AddFilter(filter, L"Device"); graph->AddFilter(demuxer, L"Demuxer"); graph->AddFilter(videoCapture, L"Capture Filter"); if (!!encoder) graph->AddFilter(encoder, L"Encoder"); bool success = ConnecEncodedtFilters(graph, filter, crossbar, encoder, demuxer); if (success) success = MapPacketIDs(demuxer, info.videoPacketID, info.audioPacketID); return success; }
HDevice::~HDevice() { if (active) Stop(); DisconnectFilters(); /* * the sleeps for the rocket are required. It seems that you cannot * simply start/stop the stream right away after/before you enable or * disable the rocket. If you start it too fast after enabling, it * won't return any data. If you try to turn off the rocket too * quickly after stopping, then it'll be perpetually stuck on, and then * you'll have to unplug/replug the device to get it working again. */ if (!!rocketEncoder) { Sleep(ROCKET_WAIT_TIME_MS); SetRocketEnabled(rocketEncoder, false); } }