Revision a24dbbce src/tuner.cpp

View differences:

src/tuner.cpp
39 39
    : numReaders(0),
40 40
      frontendFD(-1),
41 41
      dvrFD(-1),
42
      tuneParams(NULL),
43
      frontendDevice(frontendDevice)      
42
      tuneParams(NULL), oldTuneParams(NULL),
43
      frontendDevice(frontendDevice),
44
      closeTimer(1000, &Tuner::reallyCloseFrontendCallback, this)
44 45
{
45 46
  // Derive the demuxDevice from the frontend string
46 47
  unsigned fPos = frontendDevice.find("frontend");
......
139 140

  
140 141
bool Tuner::openFrontend()
141 142
{
143
  closeTimer.stop();
144
  
145
  // Front end is already open, no need to close it.
146
  if (frontendFD != -1) 
147
    return true;
148
  
142 149
  if((frontendFD = open(frontendDevice.c_str(),O_RDWR)) < 0){
143 150
    std::cerr << "Error opening frontend device " << frontendDevice << ":" 
144 151
	      << strerror(errno) << std::endl;
......
151 158
void Tuner::closeFrontend()
152 159
{
153 160
  if (frontendFD >= 0) {
154
    close(frontendFD);
155
    frontendFD = -1;
161
    // Take a second to actually close the front end
162
    // So that if another channel of the same frequency
163
    // is requested in that time we don't have to waste time re-tuning.
164
    closeTimer.start();
165
    oldTuneParams = tuneParams;
156 166
  }
157 167
}
158 168

  
169
void Tuner::reallyCloseFrontendCallback( void *arg )
170
{
171
  Tuner *self = (Tuner *) arg;
172
  close(self->frontendFD);
173
  self->frontendFD = -1;
174
  self->oldTuneParams = 0;
175
}
176

  
159 177
bool Tuner::openDvr()
160 178
{
161 179
  if((dvrFD = open(dvrDevice.c_str(),O_RDONLY|O_NONBLOCK)) < 0){
......
176 194

  
177 195
bool Tuner::tune()
178 196
{
179
  return tuneParams->tune(frontendFD);
197
  if (tuneParams == oldTuneParams)
198
    return true;
199
  
200
  if (!tuneParams->tune(frontendFD))
201
    return false;
202
  
203
  oldTuneParams = tuneParams;
204
  return true;
180 205
}
181 206

  
182 207
bool Tuner::subscribe(Sink *s)

Also available in: Unified diff