Mercurial > hg > forks > bilotrip-mj12
comparison liboggplayer-src/src/play.cpp @ 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 | 083c73ceb716 |
children | 9c63b355c82b |
comparison
equal
deleted
inserted
replaced
58:1099b8eb152a | 59:3eacedd172ab |
---|---|
1 #include "imp.hpp" | 1 #include "imp.hpp" |
2 | 2 |
3 bool OggPlayer::Imp::ready() { | 3 bool OggPlayer::Imp::ready() { |
4 #ifdef VORBIS_SUPPORT | |
4 return audio_cache_ready; | 5 return audio_cache_ready; |
5 } | 6 #else |
7 return true; | |
8 #endif | |
9 } | |
10 | |
11 | |
12 #ifdef VORBIS_SUPPORT | |
6 // return true if need more data | 13 // return true if need more data |
7 // the return value is strange but the function is | 14 // the return value is strange but the function is |
8 // for internal use only and should only be called | 15 // for internal use only and should only be called |
9 // in play() | 16 // in play() |
10 bool OggPlayer::Imp::decode_audio() { | 17 bool OggPlayer::Imp::decode_audio() { |
11 #ifdef VORBIS_SUPPORT | |
12 int ret; | 18 int ret; |
13 float **pcm; | 19 float **pcm; |
14 // if there's pending, decoded audio, grab it | 20 // if there's pending, decoded audio, grab it |
15 while ((ret = vorbis_synthesis_pcmout(&v_state, &pcm)) > 0) { | 21 while ((ret = vorbis_synthesis_pcmout(&v_state, &pcm)) > 0) { |
16 boost::unique_lock<boost::mutex> lock(audio_mut); | 22 boost::unique_lock<boost::mutex> lock(audio_mut); |
78 if (vorbis_synthesis(&v_block, &o_packet) == 0) { | 84 if (vorbis_synthesis(&v_block, &o_packet) == 0) { |
79 vorbis_synthesis_blockin(&v_state, &v_block); | 85 vorbis_synthesis_blockin(&v_state, &v_block); |
80 return false; | 86 return false; |
81 } | 87 } |
82 } else { return true; } | 88 } else { return true; } |
83 #endif | |
84 return true; | 89 return true; |
85 } | 90 } |
91 #endif | |
92 | |
86 // similar to decode_audio | 93 // similar to decode_audio |
87 bool OggPlayer::Imp::decode_video() { | 94 bool OggPlayer::Imp::decode_video() { |
88 bool was_ready=videobuf_ready; | 95 bool was_ready=videobuf_ready; |
89 boost::unique_lock<boost::mutex> lock(video_mut, boost::defer_lock); | 96 boost::unique_lock<boost::mutex> lock(video_mut, boost::defer_lock); |
90 ogg_int64_t videobuf_granulepos = -1; | 97 ogg_int64_t videobuf_granulepos = -1; |
129 return !videobuf_ready; | 136 return !videobuf_ready; |
130 } | 137 } |
131 | 138 |
132 void OggPlayer::Imp::play_loop() { | 139 void OggPlayer::Imp::play_loop() { |
133 if(!file_in.is_open()) return; | 140 if(!file_in.is_open()) return; |
141 #ifdef VORBIS_SUPPORT | |
134 audio_cache_ready = false; | 142 audio_cache_ready = false; |
135 audio_bytes_played = 0; | 143 audio_bytes_played = 0; |
136 bool audio_need_data = vorbis_p; | 144 bool audio_need_data = vorbis_p; |
145 #else | |
146 bool audio_need_data = false; | |
147 #endif | |
137 bool video_need_data = theora_p; | 148 bool video_need_data = theora_p; |
138 timer.restart(); | 149 timer.restart(); |
139 // buffer_data() will close the file on eof | 150 // buffer_data() will close the file on eof |
140 while ((file_in.is_open() || !audio_need_data || !video_need_data) && playing) { | 151 while ((file_in.is_open() || !audio_need_data || !video_need_data) && playing) { |
141 | 152 |
148 | 159 |
149 if (theora_p && !videobuf_ready) { | 160 if (theora_p && !videobuf_ready) { |
150 video_need_data = decode_video(); | 161 video_need_data = decode_video(); |
151 } | 162 } |
152 | 163 |
164 #ifdef VORBIS_SUPPORT | |
153 if (vorbis_p) { | 165 if (vorbis_p) { |
154 audio_need_data = decode_audio(); | 166 audio_need_data = decode_audio(); |
155 } | 167 } |
168 #endif | |
156 | 169 |
157 // are we at or past time for this video frame? | 170 // are we at or past time for this video frame? |
158 if (videobuf_ready && videobuf_time <= get_time()) { | 171 if (videobuf_ready && videobuf_time <= get_time()) { |
159 videobuf_ready = false; | 172 videobuf_ready = false; |
160 } | 173 } |
170 } | 183 } |
171 } | 184 } |
172 playing = false; | 185 playing = false; |
173 | 186 |
174 // do not risk a lock | 187 // do not risk a lock |
188 #ifdef VORBIS_SUPPORT | |
175 audio_ready_cond.notify_one(); | 189 audio_ready_cond.notify_one(); |
190 #endif | |
176 video_ready_cond.notify_one(); | 191 video_ready_cond.notify_one(); |
177 | 192 |
178 // cleanup | 193 // cleanup |
179 close(); | 194 close(); |
180 } | 195 } |