]>
cvs.zerfleddert.de Git - record-dvb/blob - record-dvb.c
6 #include <sys/socket.h>
16 #define CHUNKSIZE 1500
17 #define GTOD_INTERVAL 100
19 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
)
21 struct timeval start
, curr
;
22 int bytes
, written
, count
= 0;
23 char buffer
[CHUNKSIZE
];
27 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
32 if ((in
= (*open_fn
)(url
)) < 0) {
33 fprintf(stderr
,"Can't open url %s!\n",url
);
37 printf("Recording from %s for %d seconds...\n", url
, duration
);
39 gettimeofday(&start
, NULL
);
43 if ((bytes
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
44 /* TODO: Insert better connection-loss recovery here */
45 if ((in
= (*open_fn
)(url
)) < 0) {
52 if ((i
= write(out
, buffer
, bytes
-written
)) < 0) {
57 } while(written
< bytes
);
61 if (!(count
% GTOD_INTERVAL
))
62 gettimeofday(&curr
, NULL
);
63 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
67 shutdown(in
, SHUT_RDWR
);
70 int main(int argc
, char **argv
)
75 int(*open_fn
)(char *);
79 duration
= atoi(argv
[2])*60;
82 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
88 } else if (is_mcast(url
)) {
89 open_fn
= &open_mcast
;
91 printf("URL %s not supported!\n", url
);
95 record(open_fn
, url
, outfile
, duration
);