diff options
-rw-r--r-- | recordmydesktop/include/recordmydesktop.h | 1 | ||||
-rw-r--r-- | recordmydesktop/src/encode_image_buffer.c | 2 | ||||
-rw-r--r-- | recordmydesktop/src/encode_sound_buffer.c | 5 | ||||
-rw-r--r-- | recordmydesktop/src/flush_to_ogg.c | 4 | ||||
-rw-r--r-- | recordmydesktop/src/recordmydesktop.c | 1 |
5 files changed, 12 insertions, 1 deletions
diff --git a/recordmydesktop/include/recordmydesktop.h b/recordmydesktop/include/recordmydesktop.h index 56eed77..4533b87 100644 --- a/recordmydesktop/include/recordmydesktop.h +++ b/recordmydesktop/include/recordmydesktop.h @@ -216,6 +216,7 @@ typedef struct _ProgData{ frametime; pthread_mutex_t list_mutex[2],//mutexes for concurrency protection of the lists sound_buffer_mutex, + libogg_mutex,//libogg is not thread safe yuv_mutex;//this might not be needed since we only have //one read-only and one write-only thread //also on previous versions, y component was looped separately diff --git a/recordmydesktop/src/encode_image_buffer.c b/recordmydesktop/src/encode_image_buffer.c index c360488..38a1d77 100644 --- a/recordmydesktop/src/encode_image_buffer.c +++ b/recordmydesktop/src/encode_image_buffer.c @@ -42,7 +42,9 @@ void *EncodeImageBuffer(void *pdata){ else{ pthread_mutex_unlock(&((ProgData *)pdata)->yuv_mutex); if(theora_encode_packetout(&((ProgData *)pdata)->enc_data->m_th_st,0,&((ProgData *)pdata)->enc_data->m_ogg_pckt1)==1){ + pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_ts,&((ProgData *)pdata)->enc_data->m_ogg_pckt1); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); ((ProgData *)pdata)->avd+=((ProgData *)pdata)->frametime*2*((ProgData *)pdata)->args.channels; } } diff --git a/recordmydesktop/src/encode_sound_buffer.c b/recordmydesktop/src/encode_sound_buffer.c index 094b64c..85e277d 100644 --- a/recordmydesktop/src/encode_sound_buffer.c +++ b/recordmydesktop/src/encode_sound_buffer.c @@ -67,8 +67,11 @@ void *EncodeSoundBuffer(void *pdata){ vorbis_analysis(&((ProgData *)pdata)->enc_data->m_vo_block,NULL); vorbis_bitrate_addblock(&((ProgData *)pdata)->enc_data->m_vo_block); - while(vorbis_bitrate_flushpacket(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_ogg_pckt2)) + while(vorbis_bitrate_flushpacket(&((ProgData *)pdata)->enc_data->m_vo_dsp,&((ProgData *)pdata)->enc_data->m_ogg_pckt2)){ + pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); ogg_stream_packetin(&((ProgData *)pdata)->enc_data->m_ogg_vs,&((ProgData *)pdata)->enc_data->m_ogg_pckt2); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); + } } ((ProgData *)pdata)->avd-=((ProgData *)pdata)->periodtime; diff --git a/recordmydesktop/src/flush_to_ogg.c b/recordmydesktop/src/flush_to_ogg.c index 0892d2c..fed07c5 100644 --- a/recordmydesktop/src/flush_to_ogg.c +++ b/recordmydesktop/src/flush_to_ogg.c @@ -31,13 +31,17 @@ void *FlushToOgg(void *pdata){ double video_bytesout=0,audio_bytesout=0; ogg_page videopage,audiopage; while(((ProgData *)pdata)->running){ + pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); videoflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); if(videoflag){ video_bytesout+=fwrite(videopage.header,1,videopage.header_len,((ProgData *)pdata)->enc_data->fp); video_bytesout+=fwrite(videopage.body,1,videopage.body_len,((ProgData *)pdata)->enc_data->fp); videoflag=0; if(!((ProgData *)pdata)->args.nosound){ + pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); audioflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_vs,&audiopage); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); if(audioflag){ audio_bytesout+=fwrite(audiopage.header,1,audiopage.header_len,((ProgData *)pdata)->enc_data->fp); audio_bytesout+=fwrite(audiopage.body,1,audiopage.body_len,((ProgData *)pdata)->enc_data->fp); diff --git a/recordmydesktop/src/recordmydesktop.c b/recordmydesktop/src/recordmydesktop.c index adfc343..5b7e32b 100644 --- a/recordmydesktop/src/recordmydesktop.c +++ b/recordmydesktop/src/recordmydesktop.c @@ -93,6 +93,7 @@ int main(int argc,char **argv){ pthread_mutex_init(&pdata.list_mutex[0],NULL); pthread_mutex_init(&pdata.list_mutex[1],NULL); pthread_mutex_init(&pdata.sound_buffer_mutex,NULL); + pthread_mutex_init(&pdata.libogg_mutex,NULL); pthread_mutex_init(&pdata.yuv_mutex,NULL); pthread_cond_init(&pdata.time_cond,NULL); |