@ -112,7 +112,7 @@ run_v4l2_sink(void *data) {
for ( ; ; ) {
for ( ; ; ) {
sc_mutex_lock ( & vs - > mutex ) ;
sc_mutex_lock ( & vs - > mutex ) ;
while ( ! vs - > stopped & & vs - > vb . pending_frame_consumed ) {
while ( ! vs - > stopped & & ! vs - > has_frame ) {
sc_cond_wait ( & vs - > cond , & vs - > mutex ) ;
sc_cond_wait ( & vs - > cond , & vs - > mutex ) ;
}
}
@ -121,9 +121,11 @@ run_v4l2_sink(void *data) {
break ;
break ;
}
}
video_buffer_consume ( & vs - > vb , vs - > frame ) ;
vs - > has_frame = false ;
sc_mutex_unlock ( & vs - > mutex ) ;
sc_mutex_unlock ( & vs - > mutex ) ;
video_buffer_consume ( & vs - > vb , vs - > frame ) ;
bool ok = encode_and_write_frame ( vs , vs - > frame ) ;
bool ok = encode_and_write_frame ( vs , vs - > frame ) ;
av_frame_unref ( vs - > frame ) ;
av_frame_unref ( vs - > frame ) ;
if ( ! ok ) {
if ( ! ok ) {
@ -241,6 +243,7 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
goto error_av_frame_free ;
goto error_av_frame_free ;
}
}
vs - > has_frame = false ;
vs - > header_written = false ;
vs - > header_written = false ;
vs - > stopped = false ;
vs - > stopped = false ;
@ -299,14 +302,18 @@ sc_v4l2_sink_close(struct sc_v4l2_sink *vs) {
static bool
static bool
sc_v4l2_sink_push ( struct sc_v4l2_sink * vs , const AVFrame * frame ) {
sc_v4l2_sink_push ( struct sc_v4l2_sink * vs , const AVFrame * frame ) {
sc_mutex_lock ( & vs - > mutex ) ;
bool ok = video_buffer_push ( & vs - > vb , frame , NULL ) ;
bool ok = video_buffer_push ( & vs - > vb , frame , NULL ) ;
if ( ! ok ) {
if ( ! ok ) {
return false ;
return false ;
}
}
// signal possible change of vs->vb.pending_frame_consumed
vs - > has_frame = true ;
sc_cond_signal ( & vs - > cond ) ;
sc_cond_signal ( & vs - > cond ) ;
sc_mutex_unlock ( & vs - > mutex ) ;
return true ;
return true ;
}
}