Ginga  0.13.6
 All Classes Namespaces Functions Variables
FFmpegVideoProvider.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef FFmpegVideoProvider_H_
51 #define FFmpegVideoProvider_H_
52 
53 #include "config.h"
54 
55 #include "mb/interface/IContinuousMediaProvider.h"
56 #include "mb/interface/dfb/content/audio/FusionSoundAudioProvider.h"
57 using namespace ::br::pucrio::telemidia::ginga::core::mb;
58 
59 #ifndef INT64_C
60 #define INT64_C(c) (c ## LL)
61 #define UINT64_C(c) (c ## ULL)
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 #include <stdio.h>
68 #include <stdint.h>
69 #include <stdlib.h>
70 #include <string.h>
71 #include <errno.h>
72 
73 #include <sys/types.h>
74 #include <sys/stat.h>
75 #include <sys/time.h>
76 #include <time.h>
77 #include <stdio.h>
78 #include <unistd.h>
79 
80 #include <math.h>
81 
82 #include <pthread.h>
83 
84 #include <direct/types.h>
85 #include <direct/list.h>
86 #include <direct/messages.h>
87 #include <direct/memcpy.h>
88 #include <direct/thread.h>
89 #include <direct/util.h>
90 
91 #include <dvc/dvc.h>
92 #include <directfb.h>
93 
94 #include "fusionsound/fusionsound_limits.h"
95 
96 #include "libavutil/common.h"
97 #include "libavcodec/avcodec.h"
98 #include "libavformat/avformat.h"
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 typedef struct {
104  DirectLink link;
105  AVPacket packet;
106 } PacketLink;
107 
108 typedef struct {
109  PacketLink *list;
110  int size;
111  s64 max_len;
112  int max_size;
113  pthread_mutex_t lock;
114 } PacketQueue;
115 
116 typedef struct {
117  DirectLink link;
118  IDirectFBEventBuffer *buffer;
119 } EventLink;
120 
121 typedef struct {
122  int ref;
123 
124  DFBVideoProviderStatus status;
125  DFBVideoProviderPlaybackFlags flags;
126  double speed;
127  float volume;
128 
129  u16 brightness;
130  u16 contrast;
131  u16 saturation;
132 
133  IDirectFBDataBuffer *buffer;
134  bool seekable;
135  void *iobuf;
136 
137  ByteIOContext pb;
138  AVFormatContext* context;
139 
140  s64 start_time;
141 
142  struct {
143  DirectThread *thread;
144  pthread_mutex_t lock;
145 
146  bool buffering;
147 
148  bool seeked;
149  s64 seek_time;
150  int seek_flag;
151  } input;
152 
153  struct {
154  DirectThread *thread;
155  pthread_mutex_t lock;
156  pthread_cond_t cond;
157 
158  AVStream *st;
159  AVCodecContext *ctx;
160  AVCodec *codec;
161 
162  PacketQueue queue;
163 
164  s64 pts;
165 
166  double rate;
167 
168  bool seeked;
169 
170  IDirectFBSurface *dest;
171  DFBRectangle rect;
172 
173  AVFrame *src_frame;
174  DVCColormap *colormap;
175 
176  } video;
177 
178  struct {
179  DirectThread *thread;
180  pthread_mutex_t lock;
181  pthread_cond_t cond;
182 
183  AVStream *st;
184  AVCodecContext *ctx;
185  AVCodec *codec;
186 
187  PacketQueue queue;
188 
189  s64 pts;
190 
191  bool seeked;
192 
193  IFusionSound *sound;
194  IFusionSoundStream *stream;
195  IFusionSoundPlayback *playback;
196 
197  int sample_size;
198  int sample_rate;
199  int buffer_size;
200  } audio;
201 
202  ISurface* surface;
203  DVFrameCallback callback;
204  void *ctx;
206 
207 
208 #define IO_BUFFER_SIZE 8 /* in kylobytes */
209 
210 #define MAX_QUEUE_LEN 3 /* in seconds */
211 
212 #define GAP_TOLERANCE 15000 /* in microseconds */
213 
214 #define GAP_THRESHOLD 250000 /* in microseconds */
215 
216 /*****************************************************************************/
217 
218 #include <set>
219 using namespace std;
220 
221 namespace br {
222 namespace pucrio {
223 namespace telemidia {
224 namespace ginga {
225 namespace core {
226 namespace mb {
228  private:
230  GingaScreenID myScreen;
231  int resumePos;
232  int startPos;
233  static bool _ffmpegInitialized;
234  string symbol;
235  bool getHasVisual(){return true;};
236 
237  public:
238  FFmpegVideoProvider(GingaScreenID screenId, const char* mrl);
239  virtual ~FFmpegVideoProvider();
240 
241  private:
242  bool initializeFFmpeg(const char* mrl);
243 
244  public:
245  void setLoadSymbol(string symbol);
246  string getLoadSymbol();
247 
248  void setAVPid(int aPid, int vPid);
249  void* getProviderContent();
250  void setProviderContent(void* content){};
251  void feedBuffers();
252 
253  private:
254  void getVideoSurfaceDescription(DFBSurfaceDescription* dsc);
255  IDirectFBSurface* getPerfectDFBSurface();
256 
257  public:
258  bool checkVideoResizeEvent(ISurface* frame);
259 
260  void getOriginalResolution(int* width, int* height);
261  double getTotalMediaTime();
262  int64_t getVPts();
263  double getMediaTime();
264  void setMediaTime(double pos);
265 
266  private:
267  bool updateVisualData(ISurface* surface);
268 
269  public:
270  static void dynamicRenderCallBack(void* surface);
271  void playOver(
272  ISurface* surface,
273  bool hasVisual=true, IProviderListener* listener=NULL);
274 
275  void resume(ISurface* surface, bool hasVisual=true);
276  void pause();
277  void stop();
278  void setSoundLevel(float level);
279  bool releaseAll();
280  void refreshDR(void* data){};
281  };
282 }
283 }
284 }
285 }
286 }
287 }
288 
289 #endif /*FFmpegVideoProvider_H_*/
Definition: FFmpegVideoProvider.h:116
Definition: NetworkUtil.h:53
Definition: FFmpegVideoProvider.h:108
Definition: FFmpegVideoProvider.h:121
Definition: FFmpegVideoProvider.h:103