WebRTC 使用 Qt 播放网络摄像头
我使用 WebRTC 进行网络摄像头播放(用于在视频通话之前在我的应用程序中测试网络摄像头)。我接下来执行一些 WebRTC 功能:
////////////////////////
//initialization
{
webrtc::VoiceEngine* voe = VoiceEngine::Create();
webrtc::VoEBase* voeBase = VoEBase::GetInterface( voe );
voeBase->Init();
webrtc::VideoEngine* vie = VideoEngine::Create();
webrtc::ViEBase* vieBase = ViEBase::GetInterface( vie );
vieBase->Init();
webrtc::ViECapture* vieCapture = ViECapture::GetInterface( vie );
}
////////////////////////
// start webcam playing
void MainWindow::StartWebcamTest()
{
// creating window for playing webcam video
videoWidget = new Phonon::VideoWidget();
videoWidget->setFixedSize( 640, 480 );
videoWidget->setWindowTitle( "Test Webcam" );
char captDevName[1024], captGuidName[1024];
VoEEngineSingleton::Instance()->GetViECapture()->GetCaptureDevice( 0, captDevName, 1024, captGuidName, 1024 );
VoEEngineSingleton::Instance()->GetViECapture()->AllocateCaptureDevice( captGuidName, 1024, captureID );
testVideoChannel = VoEEngineSingleton::Instance()->GetViEBase()->CreateChannel( testVideoChannel );
if( testVideoChannel == -1 )
LOGERR << "Creating video channel error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGDEBUG << "Video channel created, ID = " << testVideoChannel << endl;
testAudioChannel = VoEEngineSingleton::Instance()->GetVoEBase()->CreateChannel();
if( testAudioChannel == -1 )
LOGERR << "Creating audio channel error: " << VoEEngineSingleton::Instance()->GetVoEBase()->LastError() << endl;
else LOGDEBUG << "Audio channel created, ID = " << testAudioChannel << endl;
if( VoEEngineSingleton::Instance()->GetViEBase()->ConnectAudioChannel( testVideoChannel, testAudioChannel ) != 0 )
LOGERR << "ConnectAudioChannel() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "Audio channel connected successful " << endl;
if( VoEEngineSingleton::Instance()->GetViECapture()->ConnectCaptureDevice( captureID, testVideoChannel ) != 0 )
LOGERR << "ConnectCaptureDevice() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "Capture device connected successful " << endl;
if( VoEEngineSingleton::Instance()->GetViERender()->StartRender( testVideoChannel ) != 0 )
LOGERR << "StartRender() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO "StartRender() successed " << endl;
if( VoEEngineSingleton::Instance()->GetViECapture()->StartCapture( captureID ) != 0 )
LOGERR << "StartCapture() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "StartCapture() successed " << endl;
videoWidget->show();
}
当我单击播放视频按钮时 - 网络摄像头开始播放,但 videoWidget
窗口是黑色的空的。
我做什么不真实?也许我必须使用其他 Qt 小部件?
I use WebRTC for webcam playing (it's for testing webcam at my application before video calling). I do these next some WebRTC function:
////////////////////////
//initialization
{
webrtc::VoiceEngine* voe = VoiceEngine::Create();
webrtc::VoEBase* voeBase = VoEBase::GetInterface( voe );
voeBase->Init();
webrtc::VideoEngine* vie = VideoEngine::Create();
webrtc::ViEBase* vieBase = ViEBase::GetInterface( vie );
vieBase->Init();
webrtc::ViECapture* vieCapture = ViECapture::GetInterface( vie );
}
////////////////////////
// start webcam playing
void MainWindow::StartWebcamTest()
{
// creating window for playing webcam video
videoWidget = new Phonon::VideoWidget();
videoWidget->setFixedSize( 640, 480 );
videoWidget->setWindowTitle( "Test Webcam" );
char captDevName[1024], captGuidName[1024];
VoEEngineSingleton::Instance()->GetViECapture()->GetCaptureDevice( 0, captDevName, 1024, captGuidName, 1024 );
VoEEngineSingleton::Instance()->GetViECapture()->AllocateCaptureDevice( captGuidName, 1024, captureID );
testVideoChannel = VoEEngineSingleton::Instance()->GetViEBase()->CreateChannel( testVideoChannel );
if( testVideoChannel == -1 )
LOGERR << "Creating video channel error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGDEBUG << "Video channel created, ID = " << testVideoChannel << endl;
testAudioChannel = VoEEngineSingleton::Instance()->GetVoEBase()->CreateChannel();
if( testAudioChannel == -1 )
LOGERR << "Creating audio channel error: " << VoEEngineSingleton::Instance()->GetVoEBase()->LastError() << endl;
else LOGDEBUG << "Audio channel created, ID = " << testAudioChannel << endl;
if( VoEEngineSingleton::Instance()->GetViEBase()->ConnectAudioChannel( testVideoChannel, testAudioChannel ) != 0 )
LOGERR << "ConnectAudioChannel() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "Audio channel connected successful " << endl;
if( VoEEngineSingleton::Instance()->GetViECapture()->ConnectCaptureDevice( captureID, testVideoChannel ) != 0 )
LOGERR << "ConnectCaptureDevice() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "Capture device connected successful " << endl;
if( VoEEngineSingleton::Instance()->GetViERender()->StartRender( testVideoChannel ) != 0 )
LOGERR << "StartRender() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO "StartRender() successed " << endl;
if( VoEEngineSingleton::Instance()->GetViECapture()->StartCapture( captureID ) != 0 )
LOGERR << "StartCapture() error: " << VoEEngineSingleton::Instance()->GetViEBase()->LastError() << endl;
else LOGINFO << "StartCapture() successed " << endl;
videoWidget->show();
}
When I click button for playing video - webcam starts playing but videoWidget
window is black empty.
What am I doing not true? And maybe I must use other Qt widget for it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 Qt 中实现视频渲染器。子类 webrtc::ExternalRenderer 并绘制框架
You have to implement video renderer in Qt. subclass webrtc::ExternalRenderer and draw the frame