]>
cvs.zerfleddert.de Git - record-dvb/blob - record-dvb.c
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 */
43 if ((in
= (*open_fn
)(url
)) < 0) {
50 if ((i
= write(out
, buffer
, bytes
-written
)) < 0) {
55 } while(written
< bytes
);
57 gettimeofday(&curr
, NULL
);
58 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
62 shutdown(in
, SHUT_RDWR
);
65 int main(int argc
, char **argv
)
70 int(*open_fn
)(char *);
74 duration
= atoi(argv
[2])*60;
77 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
83 } else if (is_mcast(url
)) {
84 open_fn
= &open_mcast
;
86 printf("URL %s not supported!\n", url
);
90 record(open_fn
, url
, outfile
, duration
);