Create recorder streams from packet sinks ops

Previously, the packet sink push() implementation just set the codec and
notified a wait condition. Then the recorder thread read the codec and
created the AVStream.

But this was racy: an AVFrame could be pushed before the creation of the
AVStream, causing its video_stream_index or audio_stream_index to be
initialized to -1.

Also, in the future, the AVStream initialization might need data
provided by the packet sink open(), so initialize it there (with a
mutex).
This commit is contained in:
Romain Vimont
2023-03-10 21:50:34 +01:00
parent 4bdf632dfa
commit 5052e15f7f
2 changed files with 57 additions and 78 deletions

View File

@@ -43,11 +43,8 @@ struct sc_recorder {
// wake up the recorder thread once the video or audio codec is known
sc_cond stream_cond;
const AVCodec *video_codec;
const AVCodec *audio_codec;
// Instead of providing an audio_codec, the demuxer may notify that the
// stream is disabled if the device could not capture audio
bool audio_disabled;
bool video_init;
bool audio_init;
int video_stream_index;
int audio_stream_index;