changeset 59:3eacedd172ab

Fence some lingering audio code, based on fixes from visy.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 23:27:37 +0300
parents 1099b8eb152a
children 9c63b355c82b
files liboggplayer-src/src/imp.hpp liboggplayer-src/src/oggplayer.cpp liboggplayer-src/src/play.cpp
diffstat 3 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/liboggplayer-src/src/imp.hpp	Tue Aug 06 23:15:34 2013 +0300
+++ b/liboggplayer-src/src/imp.hpp	Tue Aug 06 23:27:37 2013 +0300
@@ -40,7 +40,9 @@
 	bool parse_headers();
 	void open(std::string path, AudioFormat audio_format, int channels,
 			int rate, VideoFormat video_format);
+#ifdef VORBIS_SUPPORT
 	bool decode_audio();
+#endif
 	bool decode_video();
 	bool ready();
 	void play();
@@ -89,10 +91,12 @@
 	bool playing;
 
 	boost::thread play_thread;
+	boost::mutex video_mut;
+	boost::condition_variable video_ready_cond;
+#ifdef VORBIS_SUPPORT
 	boost::mutex audio_mut;
-	boost::mutex video_mut;
 	boost::condition_variable audio_ready_cond;
-	boost::condition_variable video_ready_cond;
+#endif
 
 	bool videobuf_ready;
 	double videobuf_time;
--- a/liboggplayer-src/src/oggplayer.cpp	Tue Aug 06 23:15:34 2013 +0300
+++ b/liboggplayer-src/src/oggplayer.cpp	Tue Aug 06 23:27:37 2013 +0300
@@ -61,6 +61,7 @@
 }
 
 
+#ifdef VORBIS_SUPPORT
 int OggPlayer::audio_read(char* buf, unsigned int size) {
 	if(NULL==buf || !imp->vorbis_p || !playing() || !imp->ready()) return 0;
 	boost::unique_lock<boost::mutex> lock(imp->audio_mut);
@@ -82,6 +83,7 @@
 
 	return k;
 }
+#endif
 
 bool OggPlayer::yuv_buffer_try_lock(YUVBuffer *buffer) {
 	if (!playing() || !imp->theora_p || !imp->ready()) 
--- a/liboggplayer-src/src/play.cpp	Tue Aug 06 23:15:34 2013 +0300
+++ b/liboggplayer-src/src/play.cpp	Tue Aug 06 23:27:37 2013 +0300
@@ -1,14 +1,20 @@
 #include "imp.hpp"
 
 bool OggPlayer::Imp::ready() {
+#ifdef VORBIS_SUPPORT
 	return audio_cache_ready;
+#else
+	return true;
+#endif
 }
+
+
+#ifdef VORBIS_SUPPORT
 // return true if need more data
 // the return value is strange but the function is
 // for internal use only and should only be called
 // in play()
 bool OggPlayer::Imp::decode_audio() {
-#ifdef VORBIS_SUPPORT
 	int ret;
 	float **pcm;
 	// if there's pending, decoded audio, grab it
@@ -80,9 +86,10 @@
 			return false;
 		}
 	} else { return true; }
-#endif
 	return true;
 }
+#endif
+
 // similar to decode_audio
 bool OggPlayer::Imp::decode_video() {
 	bool was_ready=videobuf_ready;
@@ -131,9 +138,13 @@
 
 void OggPlayer::Imp::play_loop() {
 	if(!file_in.is_open()) return;
+#ifdef VORBIS_SUPPORT
 	audio_cache_ready = false;
 	audio_bytes_played = 0;
 	bool audio_need_data = vorbis_p;
+#else
+	bool audio_need_data = false;
+#endif
 	bool video_need_data = theora_p;
 	timer.restart();
 	// buffer_data() will close the file on eof
@@ -150,9 +161,11 @@
 			video_need_data = decode_video();
 		}
 
+#ifdef VORBIS_SUPPORT
 		if (vorbis_p) {
 			audio_need_data = decode_audio();
 		}
+#endif
 
 		// are we at or past time for this video frame?
 		if (videobuf_ready && videobuf_time <= get_time()) {
@@ -172,7 +185,9 @@
 	playing = false;
 
 	// do not risk a lock
+#ifdef VORBIS_SUPPORT
 	audio_ready_cond.notify_one();
+#endif
 	video_ready_cond.notify_one();
 
 	// cleanup