]>
git.zerfleddert.de Git - record-dvb/blob - record-dvb.c
02fcd5157c2d9d3ae17ae6231ebe19132144e8ca
6 #include <sys/socket.h>
16 #define CHUNKSIZE 3000
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
, recvd
, written
, count
= 0;
23 char buffer
[CHUNKSIZE
];
26 if ((in
= (*open_fn
)(url
)) < 0) {
27 fprintf(stderr
,"Can't open url %s!\n",url
);
31 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
36 printf("Recording from %s for %d seconds...\n", url
, duration
);
38 gettimeofday(&start
, NULL
);
42 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
43 /* TODO: Insert better connection-loss recovery here */
44 if ((in
= (*open_fn
)(url
)) < 0) {
51 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
56 } while(written
< recvd
);
58 if (!(++count
% GTOD_INTERVAL
))
59 gettimeofday(&curr
, NULL
);
60 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
64 shutdown(in
, SHUT_RDWR
);
67 int main(int argc
, char **argv
)
72 int(*open_fn
)(char *);
76 duration
= atoi(argv
[2])*60;
79 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
85 } else if (is_mcast(url
)) {
86 open_fn
= &open_mcast
;
88 printf("URL %s not supported!\n", url
);
92 record(open_fn
, url
, outfile
, duration
);