Theora Playback Library  1.1.0
TheoraVideoClip.h
Go to the documentation of this file.
1 /************************************************************************************
2 This source file is part of the Theora Video Playback Library
3 For latest info, see http://libtheoraplayer.googlecode.com
4 *************************************************************************************
5 Copyright (c) 2008-2014 Kresimir Spes (kspes@cateia.com)
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the BSD license: http://opensource.org/licenses/BSD-3-Clause
8 *************************************************************************************/
9 
10 #ifndef _TheoraVideoClip_h
11 #define _TheoraVideoClip_h
12 
13 #include <string>
14 #include "TheoraExport.h"
15 
16 // forward class declarations
17 class TheoraMutex;
18 class TheoraFrameQueue;
19 class TheoraTimer;
21 class TheoraWorkerThread;
22 class TheoraDataSource;
23 class TheoraVideoFrame;
24 
29 {
30  // A = full alpha (255), order of letters represents the byte order for a pixel
31  // A means the image is treated as if it contains an alpha channel, while X formats
32  // just mean that RGB frame is transformed to a 4 byte format
34  TH_RGB = 1,
35  TH_RGBA = 2,
36  TH_RGBX = 3,
37  TH_ARGB = 4,
38  TH_XRGB = 5,
39  TH_BGR = 6,
40  TH_BGRA = 7,
41  TH_BGRX = 8,
42  TH_ABGR = 9,
43  TH_XBGR = 10,
44  TH_GREY = 11,
45  TH_GREY3 = 12,
46  TH_GREY3A = 13,
47  TH_GREY3X = 14,
48  TH_AGREY3 = 15,
49  TH_XGREY3 = 16,
50  TH_YUV = 17,
51  TH_YUVA = 18,
52  TH_YUVX = 19,
53  TH_AYUV = 20,
54  TH_XYUV = 21
55 };
56 
62 {
63  friend class TheoraWorkerThread;
64  friend class TheoraVideoFrame;
65  friend class TheoraVideoManager;
66 protected:
70 
71  TheoraTimer *mTimer, *mDefaultTimer;
72 
74 
75  bool mUseAlpha;
76 
78 
79  // benchmark vars
80  int mNumDroppedFrames, mNumDisplayedFrames, mNumPrecachedFrames;
81 
83 
84  int mSeekFrame;
85  float mDuration, mFrameDuration;
86  float mPriority;
87  std::string mName;
88  int mWidth, mHeight, mStride;
90  float mFPS;
91 
92  int mSubFrameWidth, mSubFrameHeight, mSubFrameOffsetX, mSubFrameOffsetY;
93  float mAudioGain;
94 
98  bool mEndOfFile, mRestarted;
99  int mIteration, mPlaybackIteration;
100 
103 
112  int calculatePriority();
113  void readTheoraVorbisHeaders();
114  virtual void doSeek() = 0;
115  virtual bool _readData() = 0;
116  bool isBusy();
117 
124  virtual float decodeAudio() = 0;
125 
126  int _getNumReadyFrames();
127  void resetFrameQueue();
128  int discardOutdatedFrames(float absTime);
129  float getAbsPlaybackTime();
130  virtual void load(TheoraDataSource* source) = 0;
131 
132  virtual void _restart() = 0; // resets the decoder and stream but leaves the frame queue intact
133 public:
134  TheoraVideoClip(TheoraDataSource* data_source, TheoraOutputMode output_mode, int nPrecachedFrames, bool usePower2Stride);
135  virtual ~TheoraVideoClip();
136 
137  std::string getName();
139  virtual std::string getDecoderName() = 0;
140 
142  int getNumDisplayedFrames() { return mNumDisplayedFrames; }
144  int getNumDroppedFrames() { return mNumDroppedFrames; }
145 
147  int getWidth();
149  int getHeight();
151  bool hasAlphaChannel() { return mUseAlpha; }
152 
154  int getSubFrameWidth();
156  int getSubFrameHeight();
158  int getSubFrameOffsetX();
160  int getSubFrameOffsetY();
170  int getStride() { return mStride; }
171 
173  TheoraTimer* getTimer();
175  void setTimer(TheoraTimer* timer);
176 
178  virtual bool decodeNextFrame() = 0;
179 
181  void update(float timeDelta);
188  float updateToNextFrame();
189 
190 
191  TheoraFrameQueue* getFrameQueue();
192 
198  void popFrame();
199 
205  TheoraVideoFrame* getNextFrame();
211  virtual void decodedAudioCheck() = 0;
212 
213  void setAudioInterface(TheoraAudioInterface* iface);
214  TheoraAudioInterface* getAudioInterface();
215 
221  void setNumPrecachedFrames(int n);
223  int getNumPrecachedFrames();
225  int getNumReadyFrames();
226 
228  void setAudioGain(float gain);
229  float getAudioGain();
230 
232  void setAutoRestart(bool value);
233  bool getAutoRestart() { return mAutoRestart; }
234 
235 
236 
240  void setPriority(float priority);
241  float getPriority();
242 
244  float getPriorityIndex();
245 
247  float getTimePosition();
249  float getDuration();
251  float getFPS();
253  int getNumFrames() { return mNumFrames; }
254 
256  TheoraOutputMode getOutputMode();
262  void setOutputMode(TheoraOutputMode mode);
263 
264  bool isDone();
265  void play();
266  void pause();
267  void restart();
268  bool isPaused();
269  void stop();
270  void setPlaybackSpeed(float speed);
271  float getPlaybackSpeed();
273  void seek(float time);
275  void seekToFrame(int frame);
277  float waitForCache(float desired_cache_factor = 0.5f, float max_wait_time = 1.0f);
278 };
279 
280 #endif
int getNumDroppedFrames()
benchmark function
Definition: TheoraVideoClip.h:144
bool mAutoRestart
Definition: TheoraVideoClip.h:97
Definition: TheoraVideoClip.h:44
bool hasAlphaChannel()
returns whether the clip has an alpha channel
Definition: TheoraVideoClip.h:151
int mNumFrames
Definition: TheoraVideoClip.h:89
Definition: TheoraVideoClip.h:33
float mFPS
Definition: TheoraVideoClip.h:90
TheoraAudioInterface * mAudioInterface
Definition: TheoraVideoClip.h:68
Definition: TheoraVideoClip.h:46
TheoraMutex * mAudioMutex
used to ensure smooth playback of looping videos
Definition: TheoraVideoClip.h:101
TheoraOutputMode
Definition: TheoraVideoClip.h:28
Definition: TheoraVideoManager.h:29
int getNumFrames()
get the number of frames in this movie
Definition: TheoraVideoClip.h:253
Definition: TheoraVideoClip.h:40
Definition: TheoraVideoClip.h:41
Definition: TheoraVideoClip.h:49
Definition: TheoraVideoClip.h:50
float mPriority
Definition: TheoraVideoClip.h:86
Definition: TheoraVideoClip.h:42
Definition: TheoraAsync.h:18
Definition: TheoraVideoClip.h:47
Definition: TheoraTimer.h:21
int mNumPrecachedFrames
Definition: TheoraVideoClip.h:80
TheoraWorkerThread * mAssignedWorkerThread
Definition: TheoraVideoClip.h:73
Definition: TheoraVideoClip.h:45
TheoraOutputMode mRequestedOutputMode
Definition: TheoraVideoClip.h:95
Definition: TheoraVideoClip.h:37
bool mRestarted
Definition: TheoraVideoClip.h:98
Definition: TheoraVideoFrame.h:19
std::string mName
User assigned priority. Default value is 1.
Definition: TheoraVideoClip.h:87
Definition: TheoraVideoClip.h:51
Definition: TheoraVideoClip.h:61
int mThreadAccessCount
Definition: TheoraVideoClip.h:82
int mWidth
Definition: TheoraVideoClip.h:88
int mSeekFrame
counter used by TheoraVideoManager to schedule workload
Definition: TheoraVideoClip.h:84
Definition: TheoraVideoClip.h:34
Definition: TheoraVideoClip.h:43
bool mWaitingForCache
Definition: TheoraVideoClip.h:77
TheoraFrameQueue * mFrameQueue
Definition: TheoraVideoClip.h:67
int mPlaybackIteration
Definition: TheoraVideoClip.h:99
void update(float timeDelta)
TheoraDataSource * mStream
Definition: TheoraVideoClip.h:69
Definition: TheoraVideoClip.h:36
bool mUseAlpha
Definition: TheoraVideoClip.h:75
int getStride()
return stride in pixels
Definition: TheoraVideoClip.h:170
TheoraTimer * mTimer
Definition: TheoraVideoClip.h:71
int getNumDisplayedFrames()
benchmark function
Definition: TheoraVideoClip.h:142
#define TheoraPlayerExport
Definition: TheoraExport.h:25
float mAudioGain
Definition: TheoraVideoClip.h:93
Definition: TheoraDataSource.h:23
Definition: TheoraVideoClip.h:38
Definition: TheoraVideoClip.h:52
TheoraMutex * mThreadAccessMutex
syncs audio decoding and extraction
Definition: TheoraVideoClip.h:102
Definition: TheoraAudioInterface.h:22
Definition: TheoraVideoClip.h:54
Definition: TheoraVideoClip.h:48
int mSubFrameWidth
Definition: TheoraVideoClip.h:92
Definition: TheoraVideoClip.h:39
float mFrameDuration
Definition: TheoraVideoClip.h:85
bool mFirstFrameDisplayed
Definition: TheoraVideoClip.h:96
Definition: TheoraVideoClip.h:35
Definition: TheoraVideoClip.h:53
Definition: TheoraFrameQueue.h:24
Definition: TheoraWorkerThread.h:20
bool getAutoRestart()
Definition: TheoraVideoClip.h:233