]>
cvs.zerfleddert.de Git - record-dvb/blob - record-dvb.c
d32eba1fe0576d63a75f9c5328d6c85d7b01703b
   6 #include <sys/socket.h> 
  16 #define CHUNKSIZE 1500 
  18 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
) 
  20         struct timeval start
, curr
; 
  22         char buffer
[CHUNKSIZE
]; 
  26         if ((out 
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) { 
  31         if ((in 
= (*open_fn
)(url
)) < 0) { 
  32                 fprintf(stderr
,"Can't open url %s!\n",url
); 
  36         printf("Recording from %s for %d seconds...\n", url
, duration
); 
  38         gettimeofday(&start
, NULL
); 
  41                 if ((bytes 
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) { 
  42                         /* TODO: Insert better connection-loss recovery here */ 
  47                         if ((i 
= write(out
, buffer
, bytes
-written
)) < 0) { 
  52                 } while(written 
< bytes
); 
  54                 gettimeofday(&curr
, NULL
); 
  55         } while (curr
.tv_sec 
< start
.tv_sec
+duration
); 
  59         shutdown(in
, SHUT_RDWR
); 
  62 int main(int argc
, char **argv
) 
  67         int(*open_fn
)(char *); 
  71                 duration 
= atol(argv
[2])*60; 
  74                 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]); 
  80         } else if (is_mcast(url
)) { 
  81                 open_fn 
= &open_mcast
; 
  83                 printf("URL %s not supported!\n", url
); 
  87         record(open_fn
, url
, outfile
, duration
);