WebRTC视频解析-PJSIP

正在看一些有关PJSIP的东西,发现它的代码里有个webrtc.videoengine文件夹,所以学习了一下webrtc。也正应了它的名字(web),它主要是用于网页实现实时通信。

WebRTC(Web Real Time Communication)并不是Google原来自己的技术。在2010年,Google以大约6820万美元收购了VoIP软件开发商Global IP Solutions公司,并因此获得了该公司拥有的WebRTC技术。如今,互联网的音频、视频通信服务技术一般都是私有技术,如Skype, 需要通过安装插件或者桌面客户端来实现通信功能。

Google希望Web开发人员能够直接在浏览器中创建视频或语音聊天应用,Global IP Solutions公司之前已经针对Android、Windows Mobile、iPhone制作了基于WebRTC的移动客户端。Google此次将WebRTC开源出来,就是希望浏览器厂商能够将该技术直接内嵌到浏 览器中,从而方便Web开发人员。

其实它并不局限于web开发,很多地方都用到它,现在移动端也有用它的。我看到它是在PJSIP的android代码中,所以我主要说一下它在pjsip包含的东西。至于它的原理等东西,在我转载的一篇文章里有:WebRTC整体架构分析

videoengine这个包中主要是创建SurfaceHolder和SurfaceTexture,然后将Camera获取到的图像信息展示给用户。根据它的README,说在pjsip中修复了一些webrtc的bug,所以pjsip中的代码与webrtc的源码可能有些出入。

VideoCaptureAndroid类主要是控制图像采集的开启和结束。

	//开始捕抓图像
	public int StartCapture(int width, int height, int frameRate) {
        Logger.d(LogType.LOG_FOR_CLOUD, TAG, "StartCapture width " + width +
                " height " + height +" frame rate " + frameRate);
        // Get the local preview SurfaceHolder from the static render class
        localPreview = ViERenderer.GetLocalRenderer();
        if (localPreview != null) {
            if (localPreview.getSurface() != null) {
                surfaceCreated(localPreview);
            }
            localPreview.addCallback(this);
        } else {
            // No local renderer. Camera won't capture without
            // setPreview{Texture,Display}, so we create a dummy SurfaceTexture
            // and hand it over to Camera, but never listen for frame-ready
            // callbacks, and never call updateTexImage on it.
            captureLock.lock();
            cameraUtils.setDummyTexture(camera);
            captureLock.unlock();
        }
        captureLock.lock();
        isCaptureStarted = true;
        mCaptureWidth = width;
        mCaptureHeight = height;
        mCaptureFPS = frameRate;

        int res = tryStartCapture(mCaptureWidth, mCaptureHeight, mCaptureFPS);

        captureLock.unlock();
        return res;
    }

	//停止捕抓图像
    public int StopCapture() {
        Logger.d(LogType.LOG_FOR_CLOUD, TAG, "StopCapture");
        try {
            previewBufferLock.lock();
            isCaptureRunning = false;
            previewBufferLock.unlock();
            camera.stopPreview();
            cameraUtils.unsetCallback(camera);
        }
        catch (RuntimeException ex) {
            Logger.e(LogType.LOG_FOR_CLOUD, TAG, "Failed to stop camera");
            return -1;
        }
        isCaptureStarted = false;
        return 0;
    }

ViEAndroidGLES20类主要是配置GLSurfaceView的一些属性,比如透明、渲染的方式等。
还有surfaceview的render类啊等。我就先写到这吧,大家想细看的话建议下个源码看看。

文章目录
|