1 /**
2  * @file
3  * @brief Header file for PlayerBase class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_PLAYER_BASE_H
32 #define OPENSHOT_PLAYER_BASE_H
33 
34 #include <iostream>
35 #include "ReaderBase.h"
36 
37 namespace openshot
38 {
39 	/**
40 	 * @brief This enumeration determines the mode of the video player (i.e. playing, paused, etc...)
41 	 *
42 	 * A player can be in one of the following modes, which controls how it behaves.
43 	 */
44 	enum PlaybackMode
45 	{
46 		PLAYBACK_PLAY,		///< Play the video normally
47 		PLAYBACK_PAUSED,	///< Pause the video (holding the last displayed frame)
48 		PLAYBACK_LOADING,	///< Loading the video (display a loading animation)
49 		PLAYBACK_STOPPED,	///< Stop playing the video (clear cache, done with player)
50 	};
51 
52 	/**
53 	 * @brief This is the base class of all Players in libopenshot.
54 	 *
55 	 * Players are responsible for displaying images and playing back audio samples with specific
56 	 * frame rates and sample rates. All Players must be based on this class, and include these
57 	 * methods.
58 	 */
59 	class PlayerBase
60 	{
61 	protected:
62 		float speed;
63 		float volume;
64 		openshot::ReaderBase *reader;
65 		PlaybackMode mode;
66 
67 	public:
68 
69 		/// Display a loading animation
70 		virtual void Loading() = 0;
71 
72 		/// Get the current mode
73 		virtual PlaybackMode Mode() = 0;
74 
75 		/// Play the video
76 		virtual void Play() = 0;
77 
78 		/// Pause the video
79 		virtual void Pause() = 0;
80 
81 		/// Get the current frame number being played
82 		virtual int64_t Position() = 0;
83 
84 		/// Seek to a specific frame in the player
85 		virtual void Seek(int64_t new_frame) = 0;
86 
87 		/// Get the Playback speed
88 		virtual float Speed() = 0;
89 
90 		/// Set the Playback speed (1.0 = normal speed, <1.0 = slower, >1.0 faster)
91 		virtual void Speed(float new_speed) = 0;
92 
93 		/// Stop the video player and clear the cached frames
94 		virtual void Stop() = 0;
95 
96 		/// Get the current reader, such as a FFmpegReader
97 		virtual openshot::ReaderBase* Reader() = 0;
98 
99 		/// Set the current reader, such as a FFmpegReader
100 		virtual void Reader(openshot::ReaderBase *new_reader) = 0;
101 
102 		/// Get the Volume
103 		virtual float Volume() = 0;
104 
105 		/// Set the Volume (1.0 = normal volume, <1.0 = quieter, >1.0 louder)
106 		virtual void Volume(float new_volume) = 0;
107 
108 		virtual ~PlayerBase() = default;
109 	};
110 
111 }
112 
113 #endif
114