Add start() function for recorder

For consistency with the other components, do not start the internal
thread from an init() function.
This commit is contained in:
Romain Vimont 2023-02-23 11:00:34 +01:00
parent a039124d5d
commit 3c407773e9
3 changed files with 26 additions and 11 deletions

View file

@ -444,17 +444,8 @@ sc_recorder_init(struct sc_recorder *recorder, const char *filename,
recorder->packet_sink.ops = &ops; recorder->packet_sink.ops = &ops;
ok = sc_thread_create(&recorder->thread, run_recorder, "scrcpy-recorder",
recorder);
if (!ok) {
LOGE("Could not start recorder thread");
goto error_stream_cond_destroy;
}
return true; return true;
error_stream_cond_destroy:
sc_cond_destroy(&recorder->stream_cond);
error_queue_cond_destroy: error_queue_cond_destroy:
sc_cond_destroy(&recorder->queue_cond); sc_cond_destroy(&recorder->queue_cond);
error_mutex_destroy: error_mutex_destroy:
@ -465,6 +456,18 @@ error_free_filename:
return false; return false;
} }
bool
sc_recorder_start(struct sc_recorder *recorder) {
bool ok = sc_thread_create(&recorder->thread, run_recorder,
"scrcpy-recorder", recorder);
if (!ok) {
LOGE("Could not start recorder thread");
return false;
}
return true;
}
void void
sc_recorder_stop(struct sc_recorder *recorder) { sc_recorder_stop(struct sc_recorder *recorder) {
sc_mutex_lock(&recorder->mutex); sc_mutex_lock(&recorder->mutex);

View file

@ -54,6 +54,9 @@ sc_recorder_init(struct sc_recorder *recorder, const char *filename,
struct sc_size declared_frame_size, struct sc_size declared_frame_size,
const struct sc_recorder_callbacks *cbs, void *cbs_userdata); const struct sc_recorder_callbacks *cbs, void *cbs_userdata);
bool
sc_recorder_start(struct sc_recorder *recorder);
void void
sc_recorder_stop(struct sc_recorder *recorder); sc_recorder_stop(struct sc_recorder *recorder);

View file

@ -277,6 +277,7 @@ scrcpy(struct scrcpy_options *options) {
bool server_started = false; bool server_started = false;
bool file_pusher_initialized = false; bool file_pusher_initialized = false;
bool recorder_initialized = false; bool recorder_initialized = false;
bool recorder_started = false;
#ifdef HAVE_V4L2 #ifdef HAVE_V4L2
bool v4l2_sink_initialized = false; bool v4l2_sink_initialized = false;
#endif #endif
@ -401,8 +402,14 @@ scrcpy(struct scrcpy_options *options) {
&recorder_cbs, NULL)) { &recorder_cbs, NULL)) {
goto end; goto end;
} }
rec = &s->recorder;
recorder_initialized = true; recorder_initialized = true;
if (!sc_recorder_start(&s->recorder)) {
goto end;
}
recorder_started = true;
rec = &s->recorder;
} }
static const struct sc_demuxer_callbacks demuxer_cbs = { static const struct sc_demuxer_callbacks demuxer_cbs = {
@ -708,8 +715,10 @@ end:
sc_controller_destroy(&s->controller); sc_controller_destroy(&s->controller);
} }
if (recorder_initialized) { if (recorder_started) {
sc_recorder_join(&s->recorder); sc_recorder_join(&s->recorder);
}
if (recorder_initialized) {
sc_recorder_destroy(&s->recorder); sc_recorder_destroy(&s->recorder);
} }