Revision 2cecea08

View differences:

src/.cvsignore
1 1
.deps
2 2
Makefile
3 3
Makefile.in
4
dvbcat
5
dvbd
6
dvblist
7
dvbsched
4 8
k
5 9
lextime.c
6 10
parsetime.c
src/connection.cpp
32 32
#include <cerrno>
33 33
#include <ctime>
34 34
#include <algorithm>
35
#include <cassert>
35 36

  
36 37
Connection::Connection(TunerManager *tm, int dataFD)
37 38
  : dataFD(dataFD), priority(0), 
......
69 70
bool Connection::doSubscribe()
70 71
{
71 72
  bool result = true;
73
  int n = 0;
72 74

  
73
  for (DemuxerList::iterator i = demuxers.begin(); i != demuxers.end(); i++)
75
  for (DemuxerList::iterator i = demuxers.begin(); i != demuxers.end(); i++) 
74 76
    result = (*i)->subscribe(this) && result;
75

  
77
   
76 78
  if (!result) {
77 79
    doUnsubscribe();
78 80
    return false;
79 81
  }
82

  
80 83
  return true;
81 84
}
82 85

  
......
196 199
    SavePriority save(this, p - 1);
197 200

  
198 201
    // Try to allocate the new demuxers
199
    tm->getDemuxers(newType, newChannel, newDemuxers, p);
202
    tm->getDemuxers(newType, newChannel, true, newDemuxers, p);
200 203
    retuning = false;
201 204

  
202 205
    if (newDemuxers.empty()) 
src/demuxer.cpp
41 41

  
42 42
static void set_ts_filt(int fd,uint16_t pid, dmx_pes_type_t pestype);
43 43

  
44
Demuxer::Demuxer(Tuner *tuner, int pid, Demuxer::PESType pestype)
44
Demuxer::Demuxer(Tuner *tuner, int pid, bool convertToPS, Demuxer::PESType pestype)
45 45
  : tuner(tuner), pid(pid), demuxFD(-1)
46 46
{
47 47
  init_ipack(&packer, IPACKS, output, 1);
......
138 138

  
139 139
void Demuxer::receiveData(unsigned char *data, unsigned size)
140 140
{
141
  // adapted from my_ts_to_ps( uint8_t* buf, uint16_t pida, uint16_t pidv)
142
  // in dvbstream.c (Dave Chapman)
143

  
144
  uint16_t pid;
145
  ipack *p = &this->packer;
146
  uint8_t off = 0;
147
  uint8_t *buf = (uint8_t *) data;
148

  
149
  pid = get_pid(buf+1);
150
  if (!(buf[3]&0x10)) // no payload?
151
    return;
152

  
153
  // Is this our packet?
154
  if (pid != this->pid)
155
    return;
156

  
157
  if ( buf[1]&0x40) {
158
    if (p->plength == MMAX_PLENGTH-6){
159
      p->plength = p->found-6;
160
      p->found = 0;
161
      send_ipack(p);
162
      reset_ipack(p);
141
  if (convertToPS) {
142
    // adapted from my_ts_to_ps( uint8_t* buf, uint16_t pida, uint16_t pidv)
143
    // in dvbstream.c (Dave Chapman)
144

  
145
    uint16_t pid;
146
    ipack *p = &this->packer;
147
    uint8_t off = 0;
148
    uint8_t *buf = (uint8_t *) data;
149

  
150
    pid = get_pid(buf+1);
151
    if (!(buf[3]&0x10)) // no payload?
152
      return;
153

  
154
    // Is this our packet?
155
    if (pid != this->pid)
156
      return;
157

  
158
    if ( buf[1]&0x40) {
159
      if (p->plength == MMAX_PLENGTH-6){
160
	p->plength = p->found-6;
161
	p->found = 0;
162
	send_ipack(p);
163
	reset_ipack(p);
164
      }
163 165
    }
164
  }
165 166

  
166
  if ( buf[3] & 0x20) {  // adaptation field?
167
    off = buf[4] + 1;
168
  }
167
    if ( buf[3] & 0x20) {  // adaptation field?
168
      off = buf[4] + 1;
169
    }
169 170
        
170
  instant_repack(buf+4+off, TS_SIZE-4-off, p);
171
    instant_repack(buf+4+off, TS_SIZE-4-off, p);
172
  }
173
  else {
174
    if (get_pid(data + 1) == pid)
175
      sendData(data, (unsigned) size);
176
  }
171 177
}
172 178

  
173 179
static void set_ts_filt(int fd,uint16_t pid, dmx_pes_type_t pestype)
src/demuxer.h
32 32
protected:
33 33

  
34 34
  friend class Tuner;
35
  Demuxer(Tuner *tuner, int pid, PESType pestype);
35
  Demuxer(Tuner *tuner, int pid, bool convertToPS, PESType pestype);
36 36
  virtual ~Demuxer();
37 37

  
38 38
public:
......
52 52
private:
53 53
  Tuner *tuner;
54 54
  int pid;
55
  bool convertToPS;
55 56
  int demuxFD;
56 57
  ipack packer;
57 58
  int pesType;
src/fakedemuxer.cpp
18 18

  
19 19
#include "fakedemuxer.h"
20 20

  
21
FakeDemuxer::FakeDemuxer(Tuner *tuner, int pid, PESType pestype)
22
  : Demuxer(tuner, pid, pestype)
21
FakeDemuxer::FakeDemuxer(Tuner *tuner, int pid, bool convertToPS, PESType pestype)
22
  : Demuxer(tuner, pid, convertToPS, pestype)
23 23
{
24 24
}
25 25

  
src/fakedemuxer.h
27 27
class FakeDemuxer : public Demuxer {
28 28
protected:
29 29
  friend class FakeTuner;
30
  FakeDemuxer(Tuner *tuner, int pid, PESType pestype);
30
  FakeDemuxer(Tuner *tuner, int pid, bool convertToPS, PESType pestype);
31 31

  
32 32
protected:
33 33
  virtual bool openDemux();
src/faketuner.cpp
29 29
  setTuneParams(realTuner.getTuneParams());
30 30
}
31 31

  
32
Demuxer *FakeTuner::makeNewDemuxer(int pid, Demuxer::PESType pesType) const
32
Demuxer *FakeTuner::makeNewDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const
33 33
{
34
  return new FakeDemuxer(const_cast<FakeTuner *>(this), pid, pesType);
34
  return new FakeDemuxer(const_cast<FakeTuner *>(this), pid, convertToPS, pesType);
35 35
}
36 36

  
37 37
bool FakeTuner::openFrontend()
src/faketuner.h
27 27
  FakeTuner( const Tuner &realTuner );
28 28

  
29 29
protected:
30
  virtual Demuxer *makeNewDemuxer(int pid, Demuxer::PESType pesType) const;
30
  virtual Demuxer *makeNewDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const;
31 31
  virtual bool openFrontend();
32 32
  virtual void closeFrontend();
33 33
  virtual bool openDvr();
src/signals.cpp
74 74
    exit(0);
75 75

  
76 76
  chdir("/");
77
  umask(0);
77
  umask(022);
78 78
  setsid();
79 79

  
80 80
  // Fork #2
src/tuner.cpp
69 69
  unsubscribeAll();
70 70

  
71 71
  // Destroy all the Demuxes
72
  for (DemuxerMap::iterator i = demuxerMap.begin(); i != demuxerMap.end(); i++) {
73
    PIDMap &pidmap = i->second;
74
    for (PIDMap::iterator j = pidmap.begin(); j != pidmap.end(); j++)
75
      delete j->second;
72
  for (int h = 0; h < 2; h++) {
73
    DemuxerMap &dm = demuxerMap[h];
74
    for (DemuxerMap::iterator i = dm.begin(); i != dm.end(); i++) {
75
      PIDMap &pidmap = i->second;
76
      for (PIDMap::iterator j = pidmap.begin(); j != pidmap.end(); j++)
77
	delete j->second;
78
    }
76 79
  }
77 80
}
78 81

  
......
98 101
  return s.readyToRead(dvrFD);
99 102
}
100 103

  
101
Demuxer *Tuner::makeNewDemuxer(int pid, Demuxer::PESType pesType) const
104
Demuxer *Tuner::makeNewDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const
102 105
{
103
  return new Demuxer(const_cast<Tuner *>(this), pid, pesType);
106
  return new Demuxer(const_cast<Tuner *>(this), pid, convertToPS, pesType);
104 107
}
105 108

  
106 109
// Keep a list of all the demuxers ever created
107
Demuxer *Tuner::getDemuxer(int pid, Demuxer::PESType pesType) const
110
Demuxer *Tuner::getDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const
108 111
{
109 112
  // Strictly speaking getDemuxer() is not a const
110 113
  // method, however, it does have minimal side
......
116 119

  
117 120
  assert(tuneParams != NULL);
118 121

  
119
  PIDMap &pidMap = demuxerMap[tuneParams];
122
  DemuxerMap &dm = demuxerMap[ convertToPS ? 1 : 0 ];
123
  PIDMap &pidMap = dm[tuneParams];
120 124
  Demuxer *&demuxer = pidMap[pid];
121 125

  
122 126
  if (demuxer == NULL)
123
    demuxer = makeNewDemuxer(pid, pesType);
127
    demuxer = makeNewDemuxer(pid, convertToPS, pesType);
124 128

  
125 129
  return demuxer;
126 130
}
src/tuner.h
45 45
  virtual void addSelectFDs(Select &) const;
46 46
  virtual bool isReady(const Select &) const;
47 47

  
48
  Demuxer *getDemuxer(int pid, Demuxer::PESType pesType) const;
48
  Demuxer *getDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const;
49 49

  
50 50
  int getMaxNumSubscribers() const { return 8; }
51 51
  virtual bool subscribe(Sink *s);
......
55 55
  void process();
56 56

  
57 57
protected:
58
  virtual Demuxer *makeNewDemuxer(int pid, Demuxer::PESType pesType) const;
58
  virtual Demuxer *makeNewDemuxer(int pid, bool convertToPS, Demuxer::PESType pesType) const;
59 59
  virtual bool openFrontend();
60 60
  virtual void closeFrontend();
61 61
  virtual bool openDvr();
......
74 74
  typedef std::map <int, Demuxer *> PIDMap;
75 75
  typedef std::map <const TuneParams *, PIDMap> DemuxerMap;
76 76

  
77
  mutable DemuxerMap demuxerMap;
77
  // demuxerMap[0] for TS
78
  // demuxerMap[1] for PS
79
  mutable DemuxerMap demuxerMap[2];
78 80
};
79 81

  
80 82
#endif // __TUNER_H
src/tunermanager.cpp
180 180
	  continue;
181 181
      }
182 182

  
183
      Demuxer *audio = t->getDemuxer(c->getAudioPID(), Demuxer::Audio);
184
      Demuxer *video = t->getDemuxer(c->getVideoPID(), Demuxer::Video);
183
      Demuxer *audio = t->getDemuxer(c->getAudioPID(), false, Demuxer::Audio);
184
      Demuxer *video = t->getDemuxer(c->getVideoPID(), false, Demuxer::Video);
185 185

  
186 186
      // Check to see if perhaps someone else has already
187 187
      // tuned the audio or video channels (this should
......
205 205
}
206 206

  
207 207
void TunerManager::getDemuxers(const std::string &type, const std::string &channel,
208
			       DemuxerList &demuxers, int priority) 
208
			       bool convertToPS, DemuxerList &demuxers, int priority) 
209 209
{
210 210
  TypeTunerMap::iterator li = typeTunerMap.find(type);
211 211
  assert(li != typeTunerMap.end());
......
233 233
      if (!t->getTuneParams()->sameAsExceptPIDs(*c)) 
234 234
	continue;
235 235

  
236
      Demuxer *audio = t->getDemuxer(c->getAudioPID(), Demuxer::Audio);
237
      Demuxer *video = t->getDemuxer(c->getVideoPID(), Demuxer::Video);
236
      Demuxer *audio = t->getDemuxer(c->getAudioPID(), convertToPS, Demuxer::Audio);
237
      Demuxer *video = t->getDemuxer(c->getVideoPID(), convertToPS, Demuxer::Video);
238 238

  
239 239
      // Check to see if perhaps someone else has already
240 240
      // tuned the audio or video channels (this should
src/tunermanager.h
51 51
	    const std::string &channels );
52 52

  
53 53
  void getDemuxers(const std::string &type, const std::string &channel,
54
		   DemuxerList &demuxers, int priority);
54
		   bool convertToPS, DemuxerList &demuxers, int priority);
55 55

  
56 56
  bool canGetDemuxers(const std::string &type, const std::string &channel,
57 57
		      int priority) const;

Also available in: Unified diff