Skip to content

Commit 2915022

Browse files
authored
Merge pull request #4 from giuliocarot0/mthread_video
check if threads are joinable
2 parents bf4b12c + e7f0bfe commit 2915022

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

include/SRRecorder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
#ifdef __APPLE__
1919
#define VIDEO_SRC "avfoundation"
2020
#define VIDEO_URL "1:none"
21-
#define VIDEO_FPS 30
21+
#define VIDEO_FPS -1 //automagical detection
2222
#define VIDEO_CODEC AV_CODEC_ID_MPEG4
2323
#define CODEC_NULL AV_CODEC_ID_NONE
2424

2525
#define AUDIO_SRC "avfoundation"
26-
#define AUDIO_URL "none:1"
26+
#define AUDIO_URL "none:0"
2727
#define AUDIO_CODEC AV_CODEC_ID_AAC
2828
#endif
2929

lib/SRRecorder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void SRRecorder::stopCaputure() {
237237

238238

239239
SRRecorder::~SRRecorder() {
240-
if(configuration.enable_video) videoThread.join();
241-
if(configuration.enable_audio) audioThread.join();
240+
if(configuration.enable_video && videoThread.joinable()) videoThread.join();
241+
if(configuration.enable_audio && audioThread.joinable()) audioThread.join();
242242

243243
}

lib/SRVideoInput.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ void SRVideoInput::set(char *video_src, char *video_url, SRResolution _res,int _
4040
throw openSourceParameterException("Found capture_cursor value wrong while opening video input");
4141
}
4242
#endif
43-
value = av_dict_set(&options, "framerate", s, 0);
44-
if (value < 0) {
45-
throw openSourceParameterException("Found framerate value wrong while opening video input");
43+
if(fps > 0) {
44+
value = av_dict_set(&options, "framerate", s, 0);
45+
if (value < 0) {
46+
throw openSourceParameterException("Found framerate value wrong while opening video input");
47+
}
4648
}
4749
if(_res.width != 0 && _res.height != 0 ) {
4850
s[0] = '\0';
@@ -118,8 +120,11 @@ AVFormatContext* SRVideoInput::open(){
118120
inCodecContext = avcodec_alloc_context3(inVCodec);
119121

120122
avcodec_parameters_to_context(inCodecContext, params);
121-
inCodecContext->time_base = AVRational{1, fps};
122-
inCodecContext->framerate = AVRational{fps,1};
123+
AVRational r_fps;
124+
if(fps>0) r_fps = {fps, 1};
125+
else r_fps = AVRational{inFormatContext->streams[streamIndex]->r_frame_rate};
126+
inCodecContext->framerate = AVRational{r_fps};
127+
inCodecContext->time_base = AVRational{r_fps.den, r_fps.num};
123128
value = avcodec_open2(inCodecContext, inVCodec, nullptr);
124129
if (value < 0) {
125130
throw openAVCodecException("Cannot instantiate a codec for the device stream");

main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ int main(){
1515
SRRecorder recorder(configuration);
1616
/*before setting crop the recorder must be initialized to retrieve capabilities from the devices*/
1717
recorder.initCapture();
18-
lock_thread_for(8);
18+
lock_thread_for(2);
1919
recorder.startCapture();
20-
lock_thread_for(4);
20+
lock_thread_for(10);
2121
recorder.pauseCapture();
22-
lock_thread_for(3);
22+
lock_thread_for(1);
2323
recorder.startCapture();
2424
lock_thread_for(5);
2525
recorder.stopCaputure();

0 commit comments

Comments
 (0)