Ginga  0.13.6
 All Classes Namespaces Functions Variables
BDAGraph.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao das ferramentas DTV do TeleMidia
3 
4 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
5 
6 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
7 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
8 Software Foundation.
9 
10 Este programa eh distribuido na expectativa de que seja util, porem, SEM
11 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
12 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
13 GNU versao 2 para mais detalhes.
14 
15 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
16 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
17 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
18 
19 Para maiores informacoes:
20 ncl @ telemidia.puc-rio.br
21 http://www.ncl.org.br
22 http://www.ginga.org.br
23 http://www.telemidia.puc-rio.br
24 ******************************************************************************
25 This file is part of the TeleMidia DTV Tools
26 
27 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
28 
29 This program is free software; you can redistribute it and/or modify it under
30 the terms of the GNU General Public License version 2 as published by
31 the Free Software Foundation.
32 
33 This program is distributed in the hope that it will be useful, but WITHOUT ANY
34 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
35 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
36 details.
37 
38 You should have received a copy of the GNU General Public License version 2
39 along with this program; if not, write to the Free Software
40 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
41 
42 For further information contact:
43 ncl @ telemidia.puc-rio.br
44 http://www.ncl.org.br
45 http://www.ginga.org.br
46 http://www.telemidia.puc-rio.br
47 *******************************************************************************/
48 
49 #ifndef BDAGRAPH_H_
50 #define BDAGRAPH_H_
51 
52 #include "tuner/providers/Channels.h"
53 
54 #include "system/thread/Thread.h"
55 using namespace br::pucrio::telemidia::ginga::core::system::thread;
56 
57 #include <wtypes.h>
58 #include <unknwn.h>
59 #include <ole2.h>
60 #include <limits.h>
61 /* FIXME: mingw.org doesn't define secure versions of
62  * http://msdn.microsoft.com/en-us/library/f30dzcf6.aspxu */
63 #define NO_DSHOW_STRSAFE
64 #include <DShow.h>
65 #include <comcat.h>
66 
67 #include <atlbase.h>
68 #include <initguid.h>
69 
70 #include <ks.h>
71 #include <ksmedia.h>
72 #include <bdatypes.h>
73 #include <bdamedia.h>
74 #include <bdaiface.h>
75 #include <bdatif.h>
76 
77 #include <dvdmedia.h>
78 #include <Tuner.h>
79 #include <uuids.h>
80 #include <time.h>
81 #include <iostream>
82 #include <cstdio>
83 #include <string>
84 #include <comutil.h>
85 
86 #include <map>
87 #include <vector>
88 #include <fstream>
89 
91 
92 #ifndef __qedit_h__
93 #define __qedit_h__
94 
96 
97 #pragma once
98 
100 
101 interface
102 ISampleGrabberCB : public IUnknown {
103  virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0;
104  virtual STDMETHODIMP BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ) = 0;
105 };
106 
108 
109 static
110 const
111 IID IID_ISampleGrabberCB = { 0x0579154A, 0x2B53, 0x4994, { 0xB0, 0xD0, 0xE7, 0x73, 0x14, 0x8E, 0xFF, 0x85 } };
112 
114 
115 interface
116 ISampleGrabber : public IUnknown {
117  virtual HRESULT STDMETHODCALLTYPE SetOneShot( BOOL OneShot ) = 0;
118  virtual HRESULT STDMETHODCALLTYPE SetMediaType( const AM_MEDIA_TYPE *pType ) = 0;
119  virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType( AM_MEDIA_TYPE *pType ) = 0;
120  virtual HRESULT STDMETHODCALLTYPE SetBufferSamples( BOOL BufferThem ) = 0;
121  virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer( long *pBufferSize, long *pBuffer ) = 0;
122  virtual HRESULT STDMETHODCALLTYPE GetCurrentSample( IMediaSample **ppSample ) = 0;
123  virtual HRESULT STDMETHODCALLTYPE SetCallback( ISampleGrabberCB *pCallback, long WhichMethodToCallback ) = 0;
124 };
125 
127 
128 static
129 const
130 IID IID_ISampleGrabber = { 0x6B652FFF, 0x11FE, 0x4fce, { 0x92, 0xAD, 0x02, 0x66, 0xB5, 0xD7, 0xC7, 0x8F } };
131 
133 
134 static
135 const
136 CLSID CLSID_SampleGrabber = { 0xC1F400A0, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };
137 
139 
140 static
141 const
142 CLSID CLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };
143 
145 
146 static
147 const
148 CLSID CLSID_VideoEffects1Category = { 0xcc7bfb42, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };
149 
151 
152 static
153 const
154 CLSID CLSID_VideoEffects2Category = { 0xcc7bfb43, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };
155 
157 
158 static
159 const
160 CLSID CLSID_AudioEffects1Category = { 0xcc7bfb44, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };
161 
163 
164 static
165 const
166 CLSID CLSID_AudioEffects2Category = { 0xcc7bfb45, 0xf175, 0x11d1, { 0xa3, 0x92, 0x0, 0xe0, 0x29, 0x1f, 0x39, 0x59 } };
167 
169 
170 #endif
171 
173 
174 
175 using namespace std;
176 
177 enum {
178  ATSC = 0x00000001,
179  DVB_C = 0x00000010,
180  DVB_C2 = 0x00000020,
181  DVB_S = 0x00000040,
182  DVB_S2 = 0x00000080,
183  DVB_T = 0x00000100,
184  DVB_T2 = 0x00000200,
185  ISDB_C = 0x00001000,
186  ISDB_S = 0x00002000,
187  ISDB_T = 0x00004000,
188 };
189 
190 #define FREQ_LOW 470143
191 #define FREQ_HIGH 806143
192 #define FREQ_BANDWIDTH 6
193 
194 struct Buffer {
195  char* buffer;
196  int len;
197 };
198 
199 /* The main class for building the filter graph */
200 namespace br {
201 namespace pucrio {
202 namespace telemidia {
203 namespace ginga {
204 namespace core {
205 namespace tuning {
206 class BDAGraph : public ISampleGrabberCB {
207 
208 public:
209  BDAGraph(string channelsFile, Channels *channelsList);
210  virtual ~BDAGraph();
211 
212  /* */
213  HRESULT tryToTune();
214  HRESULT searchChannels();
215  long getSignalStrength();
216 
217  bool initDevice();
218  HRESULT execute(long freq);
219  HRESULT changeChannelTo(long freq, bool setDefault = false);
220  bool getBuffer(Buffer** buffer);
221  long getTunedFreq();
222 
223 private:
224  bool searching;
225  vector<Buffer*> bufferList;
226  pthread_mutex_t bufferMutex;
227 
228  /* ISampleGrabberCB methods */
229  ULONG ul_cbrc;
230  STDMETHODIMP_(ULONG) AddRef() { return ++ul_cbrc; }
231  STDMETHODIMP_(ULONG) Release() { return --ul_cbrc; }
232  STDMETHODIMP QueryInterface(REFIID /*riid*/, void** /*p_p_object*/)
233  { return E_NOTIMPL; }
234  STDMETHODIMP SampleCB(double d_time, IMediaSample* p_sample);
235  STDMETHODIMP BufferCB(double d_time, BYTE* p_buffer, long l_buffer_len);
236 
237  CLSID guid_network_type; /* network type in use */
238  long l_tuner_used; /* Index of the Tuning Device in use */
239  unsigned systems; /* bitmask of all tuners' network types */
240 
241  /* registration number for the RunningObjectTable */
242  DWORD d_graph_register;
243 
244  IMediaControl* p_media_control;
245  IGraphBuilder* p_filter_graph;
246  ITuningSpaceContainer* p_tuning_space_container;
247  ITuningSpace* p_tuning_space;
248  ITuneRequest* p_tune_request;
249  IDVBTuningSpace* p_dvb_tuning_space;
250  IDVBSTuningSpace* p_dvbs_tuning_space;
251 
252  bool canReadNetworkName;
253  string currentNetworkName;
254  unsigned char currentVirtualChannel;
255  clock_t rntStopTime;
256  Channels *channelsList;
257  string channelsFile;
258  long tunedFreq;
259 
260  ICreateDevEnum* p_system_dev_enum;
261  IBaseFilter* p_network_provider;
262  IBaseFilter* p_tuner_device;
263  IBaseFilter* p_capture_device;
264  IBaseFilter* p_sample_grabber;
265  IBaseFilter* p_mpeg_demux;
266  IBaseFilter* p_transport_info;
267  IScanningTuner* p_scanning_tuner;
268  ISampleGrabber* p_grabber;
269 
270  void readNetworkInfo(clock_t stopTime);
271  void readNI(BYTE* buf, size_t bufLen);
272  int SubmitTuneRequest(void);
273  unsigned EnumSystems(void);
274 
275  HRESULT SetUpTuner(REFCLSID guid_this_network_type);
276  HRESULT Build();
277  HRESULT Check(REFCLSID guid_this_network_type);
278  HRESULT GetFilterName(IBaseFilter* p_filter, char** psz_bstr_name);
279  HRESULT GetPinName(IPin* p_pin, char** psz_bstr_name);
280  unsigned GetSystem(REFCLSID clsid);
281  HRESULT ListFilters(REFCLSID this_clsid);
282  HRESULT FindFilter(REFCLSID clsid, long* i_moniker_used,
283  IBaseFilter* p_upstream, IBaseFilter** p_p_downstream);
284  HRESULT Connect(IBaseFilter* p_filter_upstream,
285  IBaseFilter* p_filter_downstream);
286  HRESULT SetDVBT(long, long);
287  HRESULT Start();
288  HRESULT Destroy();
289  HRESULT Register();
290  void Deregister();
291 };
292 }
293 }
294 }
295 }
296 }
297 }
298 #endif /* BDAGRAPH_H_ */
Definition: BDAGraph.h:194