Commit 990ffe00 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

video: lrc video threading adaptation

Change-Id: I43f95c462de4ea762686e74dc7e38676fdd44467
parent ab2d19a4
......@@ -400,8 +400,9 @@ CppImpl::drawVideoDevices()
gtk_widget_show(widgets->video_channel_row);
gtk_widget_show(widgets->video_resolution_row);
gtk_widget_show(widgets->video_framerate_row);
if (widgets->video_widget)
if (widgets->video_widget) {
avModel_->startPreview();
}
}
active = 0;
......@@ -833,10 +834,8 @@ media_settings_view_show_preview(MediaSettingsView *self, gboolean show_preview)
gtk_widget_set_size_request(priv->video_widget, 400, -1);
try {
const lrc::api::video::Renderer* previewRenderer =
&priv->cpp->avModel_->getRenderer(
lrc::api::video::PREVIEW_RENDERER_ID);
priv->video_started_by_settings = previewRenderer->isRendering();
const lrc::api::video::Renderer* previewRenderer = video_widget_get_renderer(VIDEO_WIDGET(priv->video_widget), VIDEO_RENDERER_REMOTE);
priv->video_started_by_settings = previewRenderer && previewRenderer->isRendering();
if (priv->video_started_by_settings) {
video_widget_add_new_renderer(VIDEO_WIDGET(priv->video_widget),
priv->cpp->avModel_, previewRenderer, VIDEO_RENDERER_REMOTE);
......@@ -855,16 +854,33 @@ media_settings_view_show_preview(MediaSettingsView *self, gboolean show_preview)
[=](const QString& id) {
if (id != lrc::api::video::PREVIEW_RENDERER_ID)
return;
const auto* prenderer = &priv->cpp->avModel_->getRenderer(id);
video_widget_add_new_renderer(
VIDEO_WIDGET(priv->video_widget),
priv->cpp->avModel_,
previewRenderer, VIDEO_RENDERER_REMOTE);
prenderer, VIDEO_RENDERER_REMOTE);
});
priv->cpp->avModel_->startPreview();
}
} catch (const std::out_of_range& e) {
g_warning("Cannot start preview");
}
// check if the local render has already activated by others
const lrc::api::video::Renderer* prenderer = nullptr;
try {
prenderer = &priv->cpp->avModel_->getRenderer(
lrc::api::video::PREVIEW_RENDERER_ID);
} catch (const std::out_of_range& e) {
}
if (prenderer){
video_widget_add_new_renderer(
VIDEO_WIDGET(priv->video_widget),
priv->cpp->avModel_,
prenderer, VIDEO_RENDERER_REMOTE);
}
else
priv->cpp->avModel_->startPreview();
priv->cpp->avModel_->startAudioDevice();
priv->cpp->avModel_->setAudioMeterState(true);
} else {
......
......@@ -1044,6 +1044,9 @@ check_frame_queue(VideoWidget *self)
g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
VideoWidgetPrivate *priv = VIDEO_WIDGET_GET_PRIVATE(self);
if (!clutter_actor_get_paint_visibility(priv->video_container))
return TRUE;
/* display renderer's frames */
if (priv->show_preview)
clutter_render_image(priv->local);
......@@ -1088,6 +1091,7 @@ renderer_stop(VideoWidgetRenderer *renderer)
/* must do this under lock, in case the rendering is taking place when
* this signal is received */
std::lock_guard<std::mutex> lock(renderer->run_mutex);
renderer->v_renderer = nullptr;
renderer->running = false;
}
/* ask to show a black frame */
......@@ -1210,11 +1214,13 @@ video_widget_add_new_renderer(VideoWidget* self, lrc::api::AVModel* avModel,
if (renderer->isRendering())
renderer_start(new_video_renderer);
auto currentId = renderer->getId();
new_video_renderer->render_stop = QObject::connect(
&*avModel,
&lrc::api::AVModel::rendererStopped,
[=](const QString& id) {
if (renderer->getId() == id)
if (currentId == id)
renderer_stop(new_video_renderer);
});
......@@ -1222,13 +1228,24 @@ video_widget_add_new_renderer(VideoWidget* self, lrc::api::AVModel* avModel,
&*avModel,
&lrc::api::AVModel::rendererStarted,
[=](const QString& id) {
if (renderer->getId() == id)
if (currentId == id)
renderer_start(new_video_renderer);
});
g_async_queue_push(priv->new_renderer_queue, new_video_renderer);
}
const lrc::api::video::Renderer*
video_widget_get_renderer(VideoWidget* self, VideoRendererType type)
{
g_return_val_if_fail(IS_VIDEO_WIDGET(self), nullptr);
VideoWidgetPrivate *priv = VIDEO_WIDGET_GET_PRIVATE(self);
if (type == VIDEO_RENDERER_REMOTE)
return priv->remote->v_renderer;
return priv->local->v_renderer;
}
void
video_widget_take_snapshot(VideoWidget *self)
{
......
......@@ -56,6 +56,7 @@ typedef enum {
GType video_widget_get_type (void) G_GNUC_CONST;
GtkWidget* video_widget_new (void);
void video_widget_add_new_renderer (VideoWidget*, lrc::api::AVModel* avModel, const lrc::api::video::Renderer*, VideoRendererType);
const lrc::api::video::Renderer* video_widget_get_renderer (VideoWidget*, VideoRendererType);
void video_widget_on_drag_data_received (GtkWidget *self,
GdkDragContext *context,
gint x,
......
Supports Markdown
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