Revision e386e4be

View differences:

src/dvbcat.cpp
47 47
  bool durationSpecified = false;
48 48
  unsigned duration = 0;
49 49
  int priority = 10;
50
  bool convertToPS = false;
50
  bool convertToPS = false, convertToES = false;
51 51

  
52 52
  while (true) {
53 53
    static struct option long_options[] = {
......
56 56
      {"output", 1, 0, 'o'},
57 57
      {"socket", 1, 0, 's'},
58 58
      {"ps", 0, 0, 'P'},
59
      {"es", 0, 0, 'E'},
59 60
      {0, 0, 0, 0}
60 61
    };
61 62
 
62 63
    int option_index = 0;
63
    int c = getopt_long(argc, argv, "Pd:p:o:s:", long_options, &option_index);
64
    int c = getopt_long(argc, argv, "EPd:p:o:s:", long_options, &option_index);
64 65
    if (c == -1)
65 66
      break;
66 67
    switch (c) {
......
77 78
    case 's':
78 79
      socketFile = optarg;
79 80
      break;
81
    case 'E':
82
      convertToES = true;
83
      break;
80 84
    case 'P':
81 85
      convertToPS = true;
82 86
      break;
......
207 211
	    << "                         (default is standard output).\n"
208 212
	    << "  -s, --socket           Specify socket to connect to\n"
209 213
	    << "                         (default is " << DEFAULT_SOCKET_FILE << ")\n"
210
	    << "  -P, --ps               Convert stream to program stream\n";
214
	    << "  -P, --ps               Convert stream to program stream\n"
215
	    << "  -E, --es               Convert stream to elementary stream (audio only)\n";
211 216
}
src/inputbuffer.cpp
18 18

  
19 19
#include "inputbuffer.h"
20 20
#include <unistd.h>
21
#include <cerrno>
21 22

  
22 23
InputBuffer::InputBuffer(int fd, int initSize, int maxSize)
23 24
  : CircularBuffer(initSize, maxSize), fd(fd)
......
48 49
  }
49 50

  
50 51
  char data[spaceAvailable];
51
  int bytesRead = ::read(fd, data, spaceAvailable);
52
  int bytesRead;
53

  
54
  bytesRead = ::read(fd, data, spaceAvailable);
52 55
  if (bytesRead <= 0)
53
    return false;
56
    return errno == EAGAIN;
54 57

  
55 58
  write(data, bytesRead);
56 59
  return true;
src/lobby.cpp
30 30
#include <sys/socket.h>
31 31
#include <cerrno>
32 32
#include <cstring>
33
#include <fcntl.h>
33
#include <cstdio>
34 34
#include <cstdlib>
35
#include <fcntl.h>
35 36
#include <time.h>
36 37
#include <iostream>
37 38
#include <unistd.h>
......
84 85
{
85 86
  if (server->isReady(s)) {
86 87
    int fd = server->accept();
87
    ::setNonBlocking(fd);
88
    clients.push_back(fd);
88
    if (fd >= 0) {
89
      // ALRM signal can interrupt the accept causing it to return -1
90
      // and errno = EAGAIN
91
      ::setNonBlocking(fd);
92
      clients.push_back(fd);
93
    }
89 94
  }
90 95

  
91 96
  for (ControlList::iterator i = controllers.begin(); i != controllers.end();) {
src/outputbuffer.cpp
66 66
  }
67 67

  
68 68
  int bytesWritten = ::write(fd, buffer1, length1);
69

  
70 69
  if (bytesWritten <= 0)
71
    return false;
70
    return errno == EAGAIN;
72 71

  
73 72
  discard(bytesWritten);
74 73
  return true;
src/signals.cpp
46 46
bool daemonize(ConfigFile &config)
47 47
{
48 48
  std::string logfile = config.get("log");
49
  int fd = open(logfile.c_str(), O_WRONLY|O_APPEND|O_CREAT);
49
  int fd = open(logfile.c_str(), O_WRONLY|O_APPEND|O_CREAT, 0744);
50 50
  if (fd == -1) {
51 51
    std::cerr << "Failed to open log file " << logfile << "\n";
52 52
    return false;
src/timer.cpp
42 42
  struct timeval now;
43 43
  gettimeofday(&now, 0);
44 44

  
45
  std::cout << "Calculating time difference between " << future.tv_sec << ", " 
46
	    << future.tv_usec << " and now " << now.tv_sec << ", " << now.tv_usec << std::endl;
47

  
45 48
  interval.tv_sec = future.tv_sec - now.tv_sec;
46 49
  interval.tv_usec = future.tv_usec - now.tv_usec;
47 50

  
......
91 94
  it.it_interval.tv_usec = 0;
92 95
  it.it_value = interval;
93 96
    
94
  std::cout << "Setting up itimer\n";
97
  std::cout << "Setting up itimer for interval " 
98
	    << it.it_value.tv_sec << ", " << it.it_value.tv_usec << std::endl;
95 99
  setitimer(ITIMER_REAL, &it, 0);
96 100
}
97 101

  
98 102
static void handleAlarmSig(int sig)
99 103
{
100
  std::cout << "Got alarm signal\n";
104
  std::cout << "Got alarm signal" << std::endl;
101 105
  // Alarm signal is masked already
102 106
  fireTimers();
103 107
  if (!timerQueue.empty())
......
107 111
static struct SetupSignalHandler {
108 112
  SetupSignalHandler()
109 113
  {
110
    std::cout << "Setting up signal handler\n";
114
    std::cout << "Setting up signal handler" << std::endl;
111 115
    struct sigaction act;
112 116
    act.sa_handler = handleAlarmSig;
113 117
    sigemptyset(&act.sa_mask);
......
120 124

  
121 125
void Timer::start()
122 126
{
127
  stop();
128

  
123 129
  // Calculate expiry time
124 130
  gettimeofday(&expiry, 0);
125 131
  expiry.tv_usec += delayMs * 1000;
126
  expiry.tv_sec += expiry.tv_usec % 1000000;
132
  expiry.tv_sec += expiry.tv_usec / 1000000;
127 133
  expiry.tv_usec %= 1000000;
128 134
  
129 135
  // Add the timer to the queue
......
140 146

  
141 147
void Timer::stop()
142 148
{
143
  maskTimer();
144
  TimerQueue copy = timerQueue;
149
  if (started) {
150
    started = false;
151
    maskTimer();
152
    TimerQueue copy = timerQueue;
145 153

  
146
  while (!timerQueue.empty())
147
    timerQueue.pop();
154
    while (!timerQueue.empty())
155
      timerQueue.pop();
148 156

  
149
  while (!copy.empty()) {
150
    Timer *top = copy.top();
151
    copy.pop();
152
    if (top != this)
153
      timerQueue.push(top);
157
    while (!copy.empty()) {
158
      Timer *top = copy.top();
159
      copy.pop();
160
      if (top != this)
161
	timerQueue.push(top);
162
    }
163
    unmaskTimer();
154 164
  }
155
  unmaskTimer();
156 165
}
src/timer.h
9 9
  typedef void CallbackType( void * );
10 10
  
11 11
  Timer( unsigned delayMs, CallbackType *callback, void *arg )
12
    : delayMs(delayMs), callback(callback), arg(arg)
12
    : started(false), delayMs(delayMs), callback(callback), arg(arg)
13 13
    {
14 14
    }
15 15

  
......
25 25

  
26 26
 private:
27 27

  
28
  bool started;
28 29
  unsigned delayMs;
29 30
  CallbackType *callback;
30 31
  void *arg;
src/tune.c
152 152
    }
153 153
    usleep(10000);
154 154
    tm2 = time((time_t*) NULL);
155
    if((festatus & FE_TIMEDOUT) || (locks >= 2) || (tm2 - tm1 >= 3))
155
    if((festatus & FE_TIMEDOUT) || (locks >= 2) || (tm2 - tm1 >= 20))
156 156
	    ok = 1;
157 157
  }
158 158

  
src/tuner.cpp
161 161
    // Take a second to actually close the front end
162 162
    // So that if another channel of the same frequency
163 163
    // is requested in that time we don't have to waste time re-tuning.
164
    std::cout << "Starting timer to close front end" << std::endl;
164 165
    closeTimer.start();
165 166
    oldTuneParams = tuneParams;
166 167
  }
......
168 169

  
169 170
void Tuner::reallyCloseFrontendCallback( void *arg )
170 171
{
172
  std::cout << "Really closing frontend" << std::endl;
171 173
  Tuner *self = (Tuner *) arg;
172 174
  close(self->frontendFD);
173 175
  self->frontendFD = -1;
......
194 196

  
195 197
bool Tuner::tune()
196 198
{
197
  if (tuneParams == oldTuneParams)
199
  if (tuneParams && oldTuneParams && 
200
      tuneParams->sameAsExceptPIDs(*oldTuneParams))
198 201
    return true;
199 202
  
200 203
  if (!tuneParams->tune(frontendFD))
......
231 234

  
232 235
void Tuner::unsubscribe(Sink *s)
233 236
{
237
  std::cout << "Unsubscribing" << std::endl;
234 238
  Source::unsubscribe(s);
235 239

  
236 240
  // On the last subscriber close down the dvr channel
237 241
  if (getNumSubscribers() == 0) {
242
    std::cout << "Closing dvr, and frontend" << std::endl;
238 243
    closeDvr();
239 244
    closeFrontend();
240 245
  }

Also available in: Unified diff