2

我使用 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 小部件?

4

2 回答 2

0

您必须在 Qt 中实现视频渲染器。子类 webrtc::ExternalRenderer 并绘制框架

于 2014-02-07T06:15:59.010 回答
0
#include <QApplication>
#include <QUrl>
#include <QWebEngineView>

class WebEnginePage: public QWebEnginePage{
    Q_OBJECT
public:
    WebEnginePage(QObject *parent = Q_NULLPTR):QWebEnginePage(parent){
        connect(this, &WebEnginePage::featurePermissionRequested, this, &WebEnginePage::onFeaturePermissionRequested);
    }
private Q_SLOTS:
    void onFeaturePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature){

        if(feature  == QWebEnginePage::MediaAudioCapture
                || feature == QWebEnginePage::MediaVideoCapture
                || feature == QWebEnginePage::MediaAudioVideoCapture)
            setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
        else
            setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
    }
};


int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QWebEngineView view;
    view.setPage(new WebEnginePage);

    QUrl url = "https://appr.tc/r/386424467";

//    view.setUrl(commandLineUrlArgument());
    view.setUrl(url);
    view.resize(1024, 750);
    view.show();

    return app.exec();
}

#include "main.moc"
于 2019-05-13T18:27:47.080 回答