Some updates
This commit is contained in:
		
							parent
							
								
									0cdd1ad2c8
								
							
						
					
					
						commit
						91982ecc7b
					
				| @ -31,7 +31,7 @@ namespace tc::audio { | ||||
|             virtual bool impl_start(std::string& /* error */) = 0; | ||||
|             virtual void impl_stop() = 0; | ||||
| 
 | ||||
|             std::mutex state_lock{}; | ||||
|             std::timed_mutex state_lock{}; | ||||
|             bool running{false}; | ||||
|             bool stream_invalid{false}; | ||||
| 
 | ||||
|  | ||||
| @ -90,6 +90,7 @@ namespace tc::audio { | ||||
| 
 | ||||
|             struct ::SoundIoRingBuffer* buffer{nullptr}; | ||||
| 
 | ||||
|             bool stop_requested{false}; /* protected via fail_cv_mutex */ | ||||
|             void execute_recovery(); | ||||
|             void read_callback(int frame_count_min, int frame_count_max); | ||||
|     }; | ||||
|  | ||||
| @ -52,9 +52,14 @@ void SoundIORecord::execute_recovery() { | ||||
|             if(fc == 0) fc = 1; | ||||
|             else if(fc > 10) return; | ||||
|             this->fail_cv.wait_for(cv_lock, std::chrono::seconds{(fc - 1) * 10}); | ||||
|             if(!this->running || this->stop_requested) return; | ||||
|         } | ||||
| 
 | ||||
|         std::lock_guard slock{this->state_lock}; | ||||
|         std::unique_lock slock{this->state_lock, std::defer_lock}; | ||||
|         if(!slock.try_lock_for(std::chrono::milliseconds{20})) { | ||||
|             log_info(category::audio, tr("Failed lock state mutex. Exit input recover thread.")); | ||||
|             return; | ||||
|         } | ||||
|         if(!this->running) return; | ||||
| 
 | ||||
|         std::string error{}; | ||||
| @ -131,6 +136,7 @@ bool SoundIORecord::impl_start(std::string &error) { | ||||
| 
 | ||||
|     //TODO: Test for interleaved channel layout!
 | ||||
| 
 | ||||
|     this->stop_requested = false; | ||||
|     return true; | ||||
| 
 | ||||
|     error_cleanup: | ||||
| @ -140,6 +146,7 @@ bool SoundIORecord::impl_start(std::string &error) { | ||||
| 
 | ||||
|     if(this->buffer) soundio_ring_buffer_destroy(this->buffer); | ||||
|     this->buffer = nullptr; | ||||
| 
 | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| @ -147,6 +154,10 @@ void SoundIORecord::impl_stop() { | ||||
|     if(!this->stream) return; | ||||
| 
 | ||||
|     if(this->fail_recover_thread.joinable() && std::this_thread::get_id() != this->fail_recover_thread.get_id()) { | ||||
|         { | ||||
|             std::lock_guard flock{this->fail_cv_mutex}; | ||||
|             this->stop_requested = true; | ||||
|         } | ||||
|         this->fail_cv.notify_all(); | ||||
|         this->fail_recover_thread.join(); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user