Ginga  0.13.6
 All Classes Namespaces Functions Variables
Demuxer.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 DEMUXER_H_
51 #define DEMUXER_H_
52 
53 #include "util/functions.h"
54 using namespace ::br::pucrio::telemidia::util;
55 
56 #include "system/compat/SystemCompat.h"
57 using namespace ::br::pucrio::telemidia::ginga::core::system::compat;
58 
59 #include "system/thread/Thread.h"
60 using namespace ::br::pucrio::telemidia::ginga::core::system::thread;
61 
62 #include "Pmt.h"
63 #include "Pat.h"
64 using namespace ::br::pucrio::telemidia::ginga::core::tsparser::si;
65 
66 #include "FrontendFilter.h"
67 #include "TSPacket.h"
68 #include "ITSFilter.h"
69 #include "IDemuxer.h"
70 
71 #include <sys/types.h>
72 #include <sys/stat.h>
73 #include <stdio.h>
74 
75 #include <map>
76 #include <vector>
77 #include <set>
78 #include <string>
79 using namespace std;
80 
81 namespace br {
82 namespace pucrio {
83 namespace telemidia {
84 namespace ginga {
85 namespace core {
86 namespace tsparser {
87  class Demuxer : public IDemuxer {
88  private:
89  Pat* pat;
90  Pmt* newPmt;
91  map<unsigned int, Pmt*> pmts;
92  map<unsigned int, ITSFilter*> pidFilters;
93  map<short, ITSFilter*> stFilters;
94  map<unsigned int, ITSFilter*> pesFilters;
95  IFrontendFilter* audioFilter;
96  IFrontendFilter* videoFilter;
97  set<IFrontendFilter*> feFilters;
98  set<IFrontendFilter*> feFiltersToSetup;
99  static vector<Pat*> pats;
100  static unsigned int sectionPid; //debug only
101  static set<unsigned int> knownSectionPids;
102  ITuner* tuner;
103 
104  short debugDest;
105  unsigned int debugPacketCounter;
106  bool isWaitingPI;
107 
108  pthread_mutex_t flagLockUntilSignal;
109  pthread_cond_t flagCondSignal;
110 
111  static pthread_mutex_t stlMutex;
112 
113  unsigned char packetSize;
114  bool nptPrinter;
115  int nptPid;
116 
117  bool enableDemuxer;
118  string outPipeUri;
119  PipeDescriptor outPipeD;
120  bool outPipeCreated;
121 
122  public:
123  //defs
124  static const short NB_PID_MAX = 0x1FFF; //8191
125  static const short ERR_CONDITION_SATISFIED = 5;
126 
127  public:
128  Demuxer(ITuner* tuner);
129  virtual ~Demuxer();
130 
131  string disableDemuxer(string tsOutputUri);
132  bool hasStreamType(short streamType);
133  void printPat();
134  void setNptPrinter(bool nptPrinter);
135 
136  private:
137  void createPSI();
138  void clearPSI();
139  void initMaps();
140  void clearMaps();
141  void resetDemuxer();
142  void setDestination(short streamType); //debug purpose only
143  void removeFilter(IFrontendFilter* filter);
144  void setupUnsolvedFilters();
145  bool setupFilter(IFrontendFilter* filter);
146  void demux(ITSPacket* packet);
147  static void* createNullDemuxer(void* ptr);
148 
149  public:
150  map<unsigned int, Pmt*>* getProgramsInfo();
151  unsigned int getTSId();
152  Pat* getPat();
153  int getDefaultMainVideoPid();
154  int getDefaultMainAudioPid();
155  int getDefaultMainCarouselPid();
156  void removeFilter(ITSFilter* tsFilter);
157  void addFilter(ITSFilter* tsFilter, int pid, int tid);
158  void addFilter(IFrontendFilter* filter);
159 
160  private:
161  void attachFilter(IFrontendFilter* filter);
162  void createPatFilter(INetworkInterface* ni);
163  void createPmtFilter(INetworkInterface* ni);
164 
165  public:
166  void receiveSection(
167  char* section, int secLen, IFrontendFilter* filter);
168 
169  void addPidFilter(unsigned int pid, ITSFilter* filter);
170  void addSectionFilter(unsigned int tid, ITSFilter* filter);
171  void addStreamTypeFilter(short streamType, ITSFilter* filter);
172  void addPesFilter(short type, ITSFilter* filter);
173  void addVideoFilter(unsigned int pid, ITSFilter* f);
174 
175  private:
176  void receiveData(char* buff, unsigned int size);
177  void updateChannelStatus(short newStatus, IChannel* channel);
178 
179  public:
180  static void addPat(Pat* pat);
181  static bool isSectionStream(unsigned int pid);
182  static void setSectionPid(unsigned int pid); //debug only
183 
184  private:
185  unsigned int hunt(char* buff, unsigned int size);
186 
187  public:
188  short getCaps();
189 
190  private:
191  void checkProgramInformation();
192  void programInfoSatisfied();
193 
194  public:
195  bool waitProgramInformation();
196  bool waitBuffers();
197  };
198 }
199 }
200 }
201 }
202 }
203 }
204 
205 #endif /*DEMUXER_H_*/