Commit 58f10a95 authored by Sébastien Blin's avatar Sébastien Blin

video_record: wait that preview is ready before recording

Change-Id: I87feb5979b5ef858df4fa88e20fc1f18d82babf4
parent 90c367e0
......@@ -109,6 +109,7 @@ struct _ChatViewPrivate
bool ready_ {false};
bool readyToRecord_ {false};
bool useDarkTheme {false};
bool startRecorderWhenReady {false};
std::string background;
CppImpl* cpp;
......@@ -462,12 +463,33 @@ on_timer_duration_timeout(ChatView* view)
return G_SOURCE_CONTINUE;
}
static bool
start_recorder(ChatView* self)
{
g_return_val_if_fail(IS_CHAT_VIEW(self), false);
auto* priv = CHAT_VIEW_GET_PRIVATE(self);
std::string file_name = priv->cpp->avModel_->startLocalRecorder(!priv->is_video_record);
if (file_name.empty()) {
priv->startRecorderWhenReady = true;
g_warning("set_state: failed to start recording, wait preview");
return false;
}
if (!priv->cpp->saveFileName_.empty()) {
std::remove(priv->cpp->saveFileName_.c_str());
}
priv->cpp->saveFileName_ = file_name;
return true;
}
static void
reset_recorder(ChatView *self)
{
g_return_if_fail(IS_CHAT_VIEW(self));
auto* priv = CHAT_VIEW_GET_PRIVATE(self);
auto result = start_recorder(self);
if (result) {
gtk_widget_hide(GTK_WIDGET(priv->button_retry));
std::string rsc = !priv->useDarkTheme && !priv->is_video_record ?
"/net/jami/JamiGnome/stop" : "/net/jami/JamiGnome/stop-white";
......@@ -478,17 +500,8 @@ reset_recorder(ChatView *self)
gtk_label_set_text(GTK_LABEL(priv->label_time), "00:00");
priv->duration = 0;
priv->timer_duration = g_timeout_add(1000, (GSourceFunc)on_timer_duration_timeout, self);
std::string file_name = priv->cpp->avModel_->startLocalRecorder(!priv->is_video_record);
if (file_name.empty()) {
g_warning("set_state: failed to start recording");
return;
}
if (!priv->cpp->saveFileName_.empty()) {
std::remove(priv->cpp->saveFileName_.c_str());
}
priv->cpp->saveFileName_ = file_name;
}
static void
......@@ -1015,6 +1028,7 @@ init_video_widget(ChatView* self)
{
ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(self);
if (priv->video_widget && GTK_IS_WIDGET(priv->video_widget)) gtk_widget_destroy(priv->video_widget);
priv->startRecorderWhenReady = false;
priv->video_widget = video_widget_new();
try {
......@@ -1039,6 +1053,9 @@ init_video_widget(ChatView* self)
VIDEO_WIDGET(priv->video_widget),
priv->cpp->avModel_,
previewRenderer, VIDEO_RENDERER_REMOTE);
// Start recorder
if (priv->startRecorderWhenReady)
reset_recorder(self);
});
}
} catch (const std::out_of_range& e) {
......
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