MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / run

Method run

src/Qt/AudioPlaybackThread.cpp:265–324  ·  view source on GitHub ↗

Start audio thread

Source from the content-addressed store, hash-verified

263
264 // Start audio thread
265 void AudioPlaybackThread::run()
266 {
267 while (!threadShouldExit())
268 {
269 if (source && !transport.isPlaying() && is_playing) {
270 // Start new audio device (or get existing one)
271 AudioDeviceManagerSingleton *audioInstance =
272 AudioDeviceManagerSingleton::Instance(sampleRate, numChannels);
273
274 // Add callback
275 audioInstance->audioDeviceManager.addAudioCallback(&player);
276
277 // Create TimeSliceThread for audio buffering
278 time_thread.startThread(Priority::high);
279
280 // Connect source to transport
281 transport.setSource(
282 source,
283 0, // No read ahead buffer
284 &time_thread,
285 0, // Sample rate correction (none)
286 numChannels); // max channels
287 transport.setPosition(0);
288 transport.setGain(1.0);
289
290 // Connect transport to mixer and player
291 mixer.addInputSource(&transport, false);
292 player.setSource(&mixer);
293
294 // Start the transport
295 transport.start();
296
297 while (!threadShouldExit() && transport.isPlaying() && is_playing) {
298 // Wait until transport state changes or thread should exit
299 std::unique_lock<std::mutex> lock(transportMutex);
300 transportCondition.wait_for(lock, std::chrono::milliseconds(10), [this]() {
301 return threadShouldExit() || !transport.isPlaying() || !is_playing;
302 });
303 }
304
305 // Stop audio and shutdown transport
306 Stop();
307 transport.stop();
308
309 // Kill previous audio
310 transport.setSource(NULL);
311
312 player.setSource(NULL);
313 audioInstance->audioDeviceManager.removeAudioCallback(&player);
314
315 // Remove source
316 delete source;
317 source = NULL;
318
319 // Stop time slice thread
320 time_thread.stopThread(-1);
321 }
322 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected