Debian Codegraph @

lib/aviplay/aviplay_impl.h

raw
1 #ifndef AVIPLAY_IMPL_H
2 #define AVIPLAY_IMPL_H
3
4 #include "IAudioRenderer.h"
5 #include "Statistic.h"
6 #include "audiodecoder.h"
7 #include "aviplay.h"
8 #include "renderer.h"
9 #include "videodecoder.h"
10
11 /***************************************************
12
13 Here aviplay interface goes
14
15 ****************************************************/
16
17 AVM_BEGIN_NAMESPACE;
18
19 class AviPlayer: public IAviPlayer2
20 {
21 public:
22 AviPlayer(const char* filename, int _depth, const char*subname,
23 int flags = 0, const char* vcodec = 0, const char* acodec = 0);
24 ~AviPlayer();
25
26 int SetColorSpace(fourcc_t csp, bool test_only);
27
28 virtual int GetWidth() const {return m_iWidth;}
29 virtual int GetHeight() const {return m_iHeight;}
30 virtual void SetKillHandler(KILLHANDLER handler, void* arg = 0)
31 {
32 m_pKillhandler = handler;
33 m_pKillhandlerArg = arg;
34 }
35 virtual void SetAudioFunc(AUDIOFUNC func, void* arg = 0);
36 virtual double GetTime() const;
37 virtual framepos_t GetFramePos() const;
38
39 virtual bool GetURLs(avm::vector<avm::string>& urls) const { return (m_pClip) ? m_pClip->GetURLs(urls) : false; }
40 virtual bool IsOpened() const { return (m_pClip) ? m_pClip->IsOpened() : false; }
41 virtual bool IsValid() const { return (m_pClip) ? m_pClip->IsValid() : false; }
42 virtual bool IsRedirector() const { return (m_pClip) ? m_pClip->IsRedirector() : false; }
43 virtual bool IsStopped() const;
44 virtual bool IsPlaying() const;
45 virtual bool IsPaused() const;
46 virtual void Restart();
47 virtual double Reseek(double pos);
48 virtual int ReseekExact(double pos);
49 virtual void Start();
50 virtual void Stop();
51 virtual int NextKeyFrame();
52 virtual int NextFrame();
53 virtual int PrevKeyFrame();
54 virtual int PrevFrame();
55 virtual void Play();
56 virtual void Pause(bool state);
57 virtual const subtitle_line_t* GetCurrentSubtitles();
58 virtual double GetLengthTime() const;
59 virtual double GetAudioLengthTime() const
60 {
61 return (m_pAudioRenderer) ? m_pAudioRenderer->GetLengthTime() : 0.0;
62 }
63 virtual double GetVideoLengthTime() const
64 {
65 return (m_pVideostream) ? m_pVideostream->GetLengthTime() : 0.0;
66 }
67 virtual const char* GetAudioFormat() const;
68 virtual StreamInfo* GetAudioStreamInfo() const;
69
70 virtual const char* GetVideoFormat() const;
71 virtual StreamInfo* GetVideoStreamInfo() const;
72 virtual double GetFps() const
73 {
74 return (m_pVideostream) ? 1.0 / m_pVideostream->GetFrameTime() : 0.0;
75 }
76 virtual const char* GetFileName() const { return m_Filename.c_str(); }
77 virtual const avm::vector<IVideoRenderer*>& GetVideoRenderers() const;
78 virtual int SetVideoRenderers(avm::vector<IVideoRenderer*>);
79 virtual State GetState(double* percent);
80 virtual bool HasSubtitles() const;
81 virtual int InitSubtitles(const char* filename);
82 virtual int Set(...);
83 virtual int Get(...) const;
84 virtual void SetAsync(float async);
85 virtual float GetAsync() const { return m_fAsync; }
86 virtual const CodecInfo& GetCodecInfo(int type = VIDEO_CODECS) const;
87 virtual IRtConfig* GetRtConfig(int type = VIDEO_CODECS) const;
88
89 virtual void SetVideo(bool enabled) { m_bVideoMute = enabled; }
90 virtual void SetAudio(bool enabled) { }
91 virtual bool GetVideo() const { return m_bVideoMute; }
92 virtual bool GetAudio() const { return (m_pAudioRenderer != 0); }
93
94 virtual int Refresh() { return -1; }
95 virtual int Resize(int& new_w, int& new_h) { return -1; }
96 virtual int Zoom(int x, int y, int w, int h) { return -1; }
97 virtual int ToggleFullscreen(bool maximize = false) { return -1; }
98
99 protected:
100 enum ThreadId
101 { // do not change order
102 THREAD_FIRST = 0,
103 THREAD_DECODER = THREAD_FIRST, THREAD_AUDIO, THREAD_VIDEO,
104 THREAD_LAST,
105 };
106
107 static void* constructThread(void* arg);
108 void* constructThreadfunc();
109 void construct();
110 int lockThreads(const char *name = 0);
111 void unlockThreads(void);
112 int checkSync(ThreadId);
113 int drawFrame(bool aseek = true);
114 void syncFrame();
115 void changePriority(const char* taskName, int add, int schedt = 0);
116
117 float getVideoAsync();
118 bool dropFrame();
119 void setQuality();
120
121 void* videoThread();
122 void* audioThread();
123 void* decoderThread();
124 // special way to have function compatible with C code pthread parameter
125 // we could use only one parameter and this seems to be simpliest way
126 static void* startVideoThread(void* arg);
127 static void* startAudioThread(void* arg);
128 static void* startDecoderThread(void* arg);
129
130 virtual int setAudioStream(int channel);
131 virtual int setAudioUrl(const char* filename);
132 virtual int setFont(const char* fn) { return -1; }
133 virtual void setVideoBuffering();
134 virtual void createVideoRenderer() {}
135 void createAudioRenderer();
136 int restartVideoStreaming(const char* codec = 0);
137
138 mutable int propertyRead[LAST_PROPERTY]; // have we read at least once from Registry::
139
140 avm::vector<IVideoRenderer*> m_VideoRenderers; // we could draw image to more places
141 IAudioRenderer* m_pAudioRenderer; // not sure about the sound - this will be
142 // more complicated because of buffer sizes
143 KILLHANDLER m_pKillhandler;
144 void* m_pKillhandlerArg;
145 AUDIOFUNC m_pAudiofunc;
146 void* m_pAudiofuncArg;
147 IReadFile* m_pClip;
148 IReadFile* m_pClipAudio; // second (audio - only stream)
149 IReadStream* m_pVideostream;
150 IReadStream* m_pAudiostream;
151 Statistic m_Drop;
152 Statistic m_Quality;
153
154 avm::string m_Filename;
155 avm::string m_Subfilename;
156 avm::string m_vcodec;
157 avm::string m_acodec;
158 subtitles_t* m_pSubtitles; // list of subtitles
159 subtitle_line_t* m_pSubline;// contains current subtitle line
160
161 float m_fAsync; // a-v async time
162 float m_fSubAsync;
163 int m_iMaxAuto;
164 int m_iFramesVideo; // just counters
165 int m_iFrameDrop;
166 int m_iLockCount;
167 // these vars are used in syncing video with time
168 int64_t m_llTimeStart; // timestamp of moment when we started playing
169 // updated after each reseek or pause
170 int64_t m_llLastVideoSync; // stamp for last video time in sync
171 int64_t m_llLastTimeStart; // timestamp of the last displayed frame
172 double m_dFrameStart; // precise position of video at time_start ( needed
173 // for timing of video-only streams )
174 double m_dLastFrameStart; // precise position of video at last frame
175 double m_dLastAudioSync; // stamp for last audio time in sync
176 float m_fLastDiff; // difference between succesive
177 float m_fLastSyncTime; // length of the last Video sync call
178 float m_fLastSleepTime;
179 float m_fDecodingTime;
180 PthreadTask* m_pVideoThread; // performs video output and sync
181 PthreadTask* m_pAudioThread; // performs audio output and sync
182 PthreadTask* m_pDecoderThread; // performs video decompression and caching
183
184 int m_iEffectiveUid; // effective user id
185 int m_iEffectiveGid; // effective group id
186
187 framepos_t m_uiPgPrevPos;
188 int64_t m_llPgPrevTime;
189
190 PthreadMutex m_ThreadMut[THREAD_LAST]; // 3 mutexes
191 PthreadCond m_ThreadCond[THREAD_LAST]; // 3 conditions
192 PthreadMutex m_LockMutex;
193
194 PthreadMutex m_QueueMutex;
195 PthreadCond m_QueueCond;
196
197 double m_dVideoSeekDest;
198 double m_dVframetime;
199 int m_iWidth;
200 int m_iHeight;
201 int m_iDepth;
202 uint_t m_CSP; // used colorspace by renderer
203
204 bool m_bVideoMute;
205 bool m_bVideoAsync; // true - do not care about a-v sync
206 bool m_bQualityAuto;
207 bool m_bVideoBuffered;
208 bool m_bVideoDirect;
209 bool m_bVideoDropping;
210 bool m_bDropping; // internal flag for temporal stop of decoder
211
212 bool m_bPaused; // true if we are paused
213 bool m_bInitialized; // true if we are playing OR paused
214 bool m_bQuit; // true signals to all processing threads
215 // to terminate
216
217 bool m_bHangup; // signals main_thread to enter 'waiting' state
218 // and set initialized=0
219 bool m_bBuffering;
220 bool m_bCallSync; // marks that video update is needed
221 bool m_bConstructed; // marks that video update is needed
222 };
223
224 AVM_END_NAMESPACE;
225
226 #endif // AVIPLAY_IMPL_H