From 7cc5c65c46414f7dac5ba9e6c2f012e740445fee Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 31 Jan 2017 13:57:55 +0100 Subject: [PATCH] feat(app): video in progress --- .../src/components/call/CallModel.hpp | 4 + .../src/components/camera/Camera.cpp | 130 ++++++++---------- .../src/components/camera/Camera.hpp | 43 +++--- .../src/components/core/CoreManager.cpp | 3 + linphone-desktop/src/main.cpp | 5 + .../ui/views/App/Calls/Incall.qml | 4 + submodules/linphone | 2 +- 7 files changed, 96 insertions(+), 95 deletions(-) diff --git a/linphone-desktop/src/components/call/CallModel.hpp b/linphone-desktop/src/components/call/CallModel.hpp index caae3537a..ae0280616 100644 --- a/linphone-desktop/src/components/call/CallModel.hpp +++ b/linphone-desktop/src/components/call/CallModel.hpp @@ -34,6 +34,10 @@ public: CallModel (std::shared_ptr linphone_call); ~CallModel () = default; + std::shared_ptr getLinphoneCall () const { + return m_linphone_call; + } + Q_INVOKABLE void accept (); Q_INVOKABLE void acceptWithVideo (); Q_INVOKABLE void terminate (); diff --git a/linphone-desktop/src/components/camera/Camera.cpp b/linphone-desktop/src/components/camera/Camera.cpp index b7a53eb0d..258912fc8 100644 --- a/linphone-desktop/src/components/camera/Camera.cpp +++ b/linphone-desktop/src/components/camera/Camera.cpp @@ -1,30 +1,11 @@ #include +#include +#include #include "Camera.hpp" -#define ATTRIBUTE_VERTEX 0 - // ============================================================================= -static const char *_vertex_shader = "attribute vec2 vertex;" - "uniform mat4 projection;" - "void main() {" - " gl_Position = projection * vec4(vertex.xy, 0, 1);" - "}"; - -static const char *_fragment_shader = "void main() {" - " gl_FragColor = vec4(vec3(1.0, 0.0, 0.0), 1.0);" - "}"; - -static const GLfloat _camera_vertices[] = { - 0.0f, 0.0f, - 50.0f, 0.0f, - 0.0f, 50.0f, - 50.0f, 50.0f -}; - -// ----------------------------------------------------------------------------- - struct CameraStateBinder { CameraStateBinder (CameraRenderer *renderer) : m_renderer(renderer) { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); @@ -35,14 +16,11 @@ struct CameraStateBinder { f->glDepthFunc(GL_LESS); f->glFrontFace(GL_CCW); f->glCullFace(GL_BACK); - - m_renderer->m_program->bind(); } ~CameraStateBinder () { - m_renderer->m_program->release(); - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glDisable(GL_CULL_FACE); f->glDisable(GL_DEPTH_TEST); } @@ -52,72 +30,44 @@ struct CameraStateBinder { // ----------------------------------------------------------------------------- -QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &size) { - m_projection.setToIdentity(); - m_projection.ortho( - 0, size.width(), - 0, size.height(), - -1, 1 - ); +struct ContextInfo { + GLuint width; + GLuint height; +}; +// ----------------------------------------------------------------------------- + +CameraRenderer::CameraRenderer (const Camera *camera) : m_camera(camera) {} + +QOpenGLFramebufferObject *CameraRenderer::createFramebufferObject (const QSize &size) { QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(4); + ContextInfo *context_info = m_camera->m_context_info; + context_info->width = size.width(); + context_info->height = size.height(); + + shared_ptr linphone_call = m_camera->m_call->getLinphoneCall(); + linphone::CallState state = linphone_call->getState(); + + if (state == linphone::CallStateConnected || state == linphone::CallStateStreamsRunning) + linphone_call->setNativeVideoWindowId(context_info); + return new QOpenGLFramebufferObject(size, format); } void CameraRenderer::render () { - init(); - - m_vao.bind(); - CameraStateBinder state(this); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); + f->glClearColor(0.f, 0.f, 0.f, 1.f); f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_program->setUniformValue(m_projection_loc, m_projection); + m_camera->getCall()->getLinphoneCall()->oglRender(); - // Draw. - f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - m_vao.release(); -} - -void CameraRenderer::init () { - if (m_inited) - return; - - m_inited = true; - - initProgram(); - initBuffer(); -} - -void CameraRenderer::initBuffer () { - QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao); - - m_vbo.create(); - m_vbo.bind(); - m_vbo.allocate(&_camera_vertices, sizeof _camera_vertices); - - m_vbo.bind(); - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glEnableVertexAttribArray(ATTRIBUTE_VERTEX); - f->glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, 0); - m_vbo.release(); -} - -void CameraRenderer::initProgram () { - m_program.reset(new QOpenGLShaderProgram()); - m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, _vertex_shader); - m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, _fragment_shader); - m_program->bindAttributeLocation("vertex", ATTRIBUTE_VERTEX); - m_program->link(); - - m_projection_loc = m_program->uniformLocation("projection"); + update(); } // ----------------------------------------------------------------------------- @@ -125,10 +75,16 @@ void CameraRenderer::initProgram () { Camera::Camera (QQuickItem *parent) : QQuickFramebufferObject(parent) { setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); + + m_context_info = new ContextInfo(); +} + +Camera::~Camera () { + delete m_context_info; } QQuickFramebufferObject::Renderer *Camera::createRenderer () const { - return new CameraRenderer(); + return new CameraRenderer(this); } void Camera::hoverMoveEvent (QHoverEvent *) {} @@ -138,3 +94,25 @@ void Camera::mousePressEvent (QMouseEvent *) { } void Camera::keyPressEvent (QKeyEvent *) {} + +// ----------------------------------------------------------------------------- + +CallModel *Camera::getCall () const { + return m_call; +} + +void Camera::setCall (CallModel *call) { + if (m_call != call) { + if (call) { + shared_ptr linphone_call = call->getLinphoneCall(); + linphone::CallState state = linphone_call->getState(); + + if (state == linphone::CallStateConnected || state == linphone::CallStateStreamsRunning) + linphone_call->setNativeVideoWindowId(m_context_info); + } + + m_call = call; + + emit callChanged(call); + } +} diff --git a/linphone-desktop/src/components/camera/Camera.hpp b/linphone-desktop/src/components/camera/Camera.hpp index 8d717ae37..666438ba0 100644 --- a/linphone-desktop/src/components/camera/Camera.hpp +++ b/linphone-desktop/src/components/camera/Camera.hpp @@ -1,53 +1,60 @@ #ifndef CAMERA_H_ #define CAMERA_H_ -#include #include -#include -#include #include +#include "../call/CallModel.hpp" + // ============================================================================= -class CameraRenderer : public QQuickFramebufferObject::Renderer { - friend struct CameraStateBinder; +class Camera; +struct ContextInfo; +class CameraRenderer : public QQuickFramebufferObject::Renderer { public: + CameraRenderer (const Camera *camera); + ~CameraRenderer () = default; + QOpenGLFramebufferObject *createFramebufferObject (const QSize &size) override; void render () override; private: - void init (); - void initBuffer (); - void initProgram (); - - bool m_inited = false; - - QMatrix4x4 m_projection; - int m_projection_loc; - - QOpenGLVertexArrayObject m_vao; - QOpenGLBuffer m_vbo; - QScopedPointer m_program; + const Camera *m_camera; }; // ----------------------------------------------------------------------------- class Camera : public QQuickFramebufferObject { + friend class CameraRenderer; + Q_OBJECT; + Q_PROPERTY(CallModel * call READ getCall WRITE setCall NOTIFY callChanged); + public: Camera (QQuickItem *parent = Q_NULLPTR); - ~Camera () = default; + ~Camera (); QQuickFramebufferObject::Renderer *createRenderer () const override; +signals: + void callChanged (CallModel *call); + protected: void hoverMoveEvent (QHoverEvent *event) override; void mousePressEvent (QMouseEvent *event) override; void keyPressEvent (QKeyEvent *event) override; + +private: + CallModel *getCall () const; + void setCall (CallModel *call); + + CallModel *m_call = nullptr; + + ContextInfo *m_context_info; }; #endif // CAMERA_H_ diff --git a/linphone-desktop/src/components/core/CoreManager.cpp b/linphone-desktop/src/components/core/CoreManager.cpp index 183ded8fd..ceadd68e7 100644 --- a/linphone-desktop/src/components/core/CoreManager.cpp +++ b/linphone-desktop/src/components/core/CoreManager.cpp @@ -12,6 +12,9 @@ CoreManager *CoreManager::m_instance = nullptr; CoreManager::CoreManager (QObject *parent) : QObject(parent), m_handlers(make_shared()) { m_core = linphone::Factory::get()->createCore(m_handlers, Paths::getConfigFilepath(), ""); + + m_core->setVideoDisplayFilter("MSOGL"); + setDatabasesPaths(); } diff --git a/linphone-desktop/src/main.cpp b/linphone-desktop/src/main.cpp index 442d2e946..db91c3587 100644 --- a/linphone-desktop/src/main.cpp +++ b/linphone-desktop/src/main.cpp @@ -6,6 +6,11 @@ int main (int argc, char *argv[]) { Logger::init(); + // Force shader version 2.0. + QSurfaceFormat fmt; + fmt.setVersion(2, 0); + QSurfaceFormat::setDefaultFormat(fmt); + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); App::init(argc, argv); diff --git a/linphone-desktop/ui/views/App/Calls/Incall.qml b/linphone-desktop/ui/views/App/Calls/Incall.qml index 76cf841f3..ba44f712b 100644 --- a/linphone-desktop/ui/views/App/Calls/Incall.qml +++ b/linphone-desktop/ui/views/App/Calls/Incall.qml @@ -128,6 +128,8 @@ Rectangle { Item { id: container + property var _call: call + Layout.fillWidth: true Layout.fillHeight: true Layout.margins: CallStyle.container.margins @@ -180,11 +182,13 @@ Rectangle { Camera { height: container.height width: container.width + call: container._call } } Loader { anchors.centerIn: parent + sourceComponent: call.videoInputEnabled ? camera : avatar } } diff --git a/submodules/linphone b/submodules/linphone index 94bbd0636..75cd64d0b 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 94bbd063687d7ace6d441dc2b9f1365514d1bf3c +Subproject commit 75cd64d0bc04a8b38dfae2b2b6cdd0299607deef