OpenShot Library | libopenshot  0.1.3
AudioPlaybackThread.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for AudioPlaybackThread class
4  * @author Duzy Chan <code@duzy.info>
5  * @author Jonathan Thomas <jonathan@openshot.org>
6  *
7  * @section LICENSE
8  *
9  * Copyright (c) 2008-2014 OpenShot Studios, LLC
10  * <http://www.openshotstudios.com/>. This file is part of
11  * OpenShot Library (libopenshot), an open-source project dedicated to
12  * delivering high quality video editing and animation solutions to the
13  * world. For more information visit <http://www.openshot.org/>.
14  *
15  * OpenShot Library (libopenshot) is free software: you can redistribute it
16  * and/or modify it under the terms of the GNU Lesser General Public License
17  * as published by the Free Software Foundation, either version 3 of the
18  * License, or (at your option) any later version.
19  *
20  * OpenShot Library (libopenshot) is distributed in the hope that it will be
21  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public License
26  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
29 #ifndef OPENSHOT_AUDIO_PLAYBACK_THREAD_H
30 #define OPENSHOT_AUDIO_PLAYBACK_THREAD_H
31 
32 #include "../../include/ReaderBase.h"
33 #include "../../include/RendererBase.h"
34 #include "../../include/AudioReaderSource.h"
35 
36 namespace openshot
37 {
38  using juce::Thread;
39  using juce::WaitableEvent;
40 
41  struct SafeTimeSliceThread : TimeSliceThread
42  {
43  SafeTimeSliceThread(const String & s) : TimeSliceThread(s) {}
44  void run()
45  {
46  try {
47  TimeSliceThread::run();
48  } catch (const TooManySeeks & e) {
49  // ...
50  }
51  }
52  };
53 
54  /**
55  * @brief The audio playback thread
56  */
57  class AudioPlaybackThread : Thread
58  {
59  AudioDeviceManager audioDeviceManager;
60  AudioSourcePlayer player;
61  AudioTransportSource transport;
62  MixerAudioSource mixer;
63  AudioReaderSource *source;
64  double sampleRate;
65  int numChannels;
66  WaitableEvent play;
67  WaitableEvent played;
68  int buffer_size;
69  bool is_playing;
70  SafeTimeSliceThread time_thread;
71 
72  /// Constructor
74  /// Destructor
76 
77  /// Set the current thread's reader
78  void Reader(ReaderBase *reader);
79 
80  /// Get the current frame object (which is filling the buffer)
81  tr1::shared_ptr<Frame> getFrame();
82 
83  /// Get the current frame number being played
84  int getCurrentFramePosition();
85 
86  /// Play the audio
87  void Play();
88 
89  /// Seek the audio thread
90  void Seek(int new_position);
91 
92  /// Stop the audio playback
93  void Stop();
94 
95  /// Start thread
96  void run();
97 
98  /// Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
99  void setSpeed(int new_speed) { if (source) source->setSpeed(new_speed); }
100 
101  /// Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
102  int getSpeed() const { if (source) return source->getSpeed(); else return 1; }
103 
104  friend class PlayerPrivate;
105  friend class QtPlayer;
106  };
107 
108 }
109 
110 #endif // OPENSHOT_AUDIO_PLAYBACK_THREAD_H
This class is used to playback a video from a reader.
Definition: QtPlayer.h:46
int getSpeed() const
Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
The audio playback thread.
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:95
The private part of QtPlayer class, which contains an audio thread and video thread, and controls the video timing and audio synchronization code.
Definition: PlayerPrivate.h:47
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
This namespace is the default namespace for all code in the openshot library.
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
Exception when too many seek attempts happen.
Definition: Exceptions.h:254