Ginga  0.13.6
 All Classes Namespaces Functions Variables
FFmpegAudioProvider.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 FFmpegAudioProvider_H_
51 #define FFmpegAudioProvider_H_
52 
53 #include "config.h"
54 
55 #include "mb/interface/IContinuousMediaProvider.h"
56 #include "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  IDirectFBDataBuffer *buffer;
130  bool seekable;
131  void *iobuf;
132 
133  ByteIOContext pb;
134  AVFormatContext* context;
135 
136  s64 start_time;
137 
138  struct {
139  DirectThread *thread;
140  pthread_mutex_t lock;
141 
142  bool buffering;
143 
144  bool seeked;
145  s64 seek_time;
146  int seek_flag;
147  } input;
148 
149  struct {
150  DirectThread *thread;
151  pthread_mutex_t lock;
152  pthread_cond_t cond;
153 
154  AVStream *st;
155  AVCodecContext *ctx;
156  AVCodec *codec;
157 
158  _PacketQueue queue;
159 
160  s64 pts;
161 
162  bool seeked;
163 
164  IFusionSound *sound;
165  IFusionSoundStream *stream;
166  IFusionSoundPlayback *playback;
167 
168  int sample_size;
169  int sample_rate;
170  int buffer_size;
171  } audio;
172 
173  ISurface* surface;
174  DVFrameCallback callback;
175  void *ctx;
176 
177  _EventLink* events;
178  DFBVideoProviderEventType events_mask;
179  pthread_mutex_t events_lock;
181 
182 
183 #define IO_BUFFER_SIZE 8 /* in kylobytes */
184 
185 #define MAX_QUEUE_LEN 3 /* in seconds */
186 
187 #define GAP_TOLERANCE 15000 /* in microseconds */
188 
189 #define GAP_THRESHOLD 250000 /* in microseconds */
190 
191 /*****************************************************************************/
192 
193 #include <set>
194 using namespace std;
195 
196 namespace br {
197 namespace pucrio {
198 namespace telemidia {
199 namespace ginga {
200 namespace core {
201 namespace mb {
203  private:
205  GingaScreenID myScreen;
206  int resumePos;
207  int startPos;
208  static bool _ffmpegInitialized;
209  string symbol;
210 
211  public:
212  FFmpegAudioProvider(GingaScreenID screenId, const char* mrl);
213  virtual ~FFmpegAudioProvider();
214 
215  private:
216  bool initializeFFmpeg(const char* mrl);
217 
218  public:
219  void setLoadSymbol(string symbol);
220  string getLoadSymbol();
221 
222  bool getHasVisual(){return false;};
223  void setAVPid(int aPid, int vPid);
224  void* getProviderContent();
225  void setProviderContent(void* content){};
226  void feedBuffers();
227 
228  private:
229  IDirectFBSurface* getPerfectDFBSurface();
230 
231  public:
232  bool checkVideoResizeEvent(ISurface* frame);
233 
234  void getOriginalResolution(int* width, int* height);
235  double getTotalMediaTime();
236  int64_t getVPts();
237  double getMediaTime();
238  void setMediaTime(double pos);
239 
240  private:
241  bool updateVisualData(ISurface* surface);
242 
243  public:
244  static void dynamicRenderCallBack(void* surface);
245  void playOver(
246  ISurface* surface,
247  bool hasVisual=true, IProviderListener* listener=NULL);
248 
249  void resume(ISurface* surface, bool hasVisual=true);
250  void pause();
251  void stop();
252  void setSoundLevel(float level);
253  bool releaseAll();
254  void refreshDR(void* data){};
255  };
256 }
257 }
258 }
259 }
260 }
261 }
262 
263 #endif /*FFmpegAudioProvider_H_*/
Definition: FFmpegAudioProvider.h:108
Definition: FFmpegAudioProvider.h:116
Definition: NetworkUtil.h:53
Definition: FFmpegAudioProvider.h:121
Definition: FFmpegAudioProvider.h:103