Commit 7cc5c65c authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): video in progress

parent cfb70bba
......@@ -34,6 +34,10 @@ public:
CallModel (std::shared_ptr<linphone::Call> linphone_call);
~CallModel () = default;
std::shared_ptr<linphone::Call> getLinphoneCall () const {
return m_linphone_call;
}
Q_INVOKABLE void accept ();
Q_INVOKABLE void acceptWithVideo ();
Q_INVOKABLE void terminate ();
......
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QtMath>
#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> 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);
// 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_camera->getCall()->getLinphoneCall()->oglRender();
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> 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);
}
}
#ifndef CAMERA_H_
#define CAMERA_H_
#include <QOpenGLBuffer>
#include <QOpenGLFramebufferObject>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QQuickFramebufferObject>
#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<QOpenGLShaderProgram> 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_
......@@ -12,6 +12,9 @@ CoreManager *CoreManager::m_instance = nullptr;
CoreManager::CoreManager (QObject *parent) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
m_core = linphone::Factory::get()->createCore(m_handlers, Paths::getConfigFilepath(), "");
m_core->setVideoDisplayFilter("MSOGL");
setDatabasesPaths();
}
......
......@@ -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);
......
......@@ -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
}
}
......
linphone @ 75cd64d0
Subproject commit 94bbd063687d7ace6d441dc2b9f1365514d1bf3c
Subproject commit 75cd64d0bc04a8b38dfae2b2b6cdd0299607deef
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment