Skip to content

Commit

Permalink
Simplify recorder
Browse files Browse the repository at this point in the history
After the refactor performed by the previous commit, the functions to
wait the video stream and the audio stream could be inlined.
  • Loading branch information
rom1v committed Mar 11, 2023
1 parent 5052e15 commit a9f6001
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions app/src/recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,6 @@ sc_recorder_close_output_file(struct sc_recorder *recorder) {
avformat_free_context(recorder->ctx);
}

static void
sc_recorder_wait_video_stream(struct sc_recorder *recorder) {
sc_mutex_lock(&recorder->mutex);
while (!recorder->video_init && !recorder->stopped) {
sc_cond_wait(&recorder->stream_cond, &recorder->mutex);
}
sc_mutex_unlock(&recorder->mutex);
}

static void
sc_recorder_wait_audio_stream(struct sc_recorder *recorder) {
sc_mutex_lock(&recorder->mutex);
while (!recorder->audio_init && !recorder->stopped) {
sc_cond_wait(&recorder->stream_cond, &recorder->mutex);
}
sc_mutex_unlock(&recorder->mutex);
}

static inline bool
sc_recorder_has_empty_queues(struct sc_recorder *recorder) {
if (sc_vecdeque_is_empty(&recorder->video_queue)) {
Expand All @@ -188,8 +170,10 @@ static bool
sc_recorder_process_header(struct sc_recorder *recorder) {
sc_mutex_lock(&recorder->mutex);

while (!recorder->stopped && sc_recorder_has_empty_queues(recorder)) {
sc_cond_wait(&recorder->queue_cond, &recorder->mutex);
while (!recorder->stopped && (!recorder->video_init
|| !recorder->audio_init
|| sc_recorder_has_empty_queues(recorder))) {
sc_cond_wait(&recorder->stream_cond, &recorder->mutex);
}

if (sc_vecdeque_is_empty(&recorder->video_queue)) {
Expand Down Expand Up @@ -432,14 +416,6 @@ sc_recorder_record(struct sc_recorder *recorder) {
return false;
}

sc_recorder_wait_video_stream(recorder);

if (recorder->audio) {
sc_recorder_wait_audio_stream(recorder);
}

// If recorder->stopped, process any queued packet anyway

ok = sc_recorder_process_packets(recorder);
sc_recorder_close_output_file(recorder);
return ok;
Expand Down

0 comments on commit a9f6001

Please sign in to comment.