]>
git.zerfleddert.de Git - record-dvb/blob - record-dvb.c
b673d83894565d265a7e0f4b6ada6433c298069e
6 #include <sys/socket.h>
16 #define CHUNKSIZE 8192
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 */
48 if ((i
= write(out
, buffer
, bytes
-written
)) < 0) {
53 } while(written
< bytes
);
55 gettimeofday(&curr
, NULL
);
56 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
60 shutdown(in
, SHUT_RDWR
);
63 int main(int argc
, char **argv
)
68 int(*open_fn
)(char *);
72 duration
= atol(argv
[2])*60;
75 fprintf(stderr
,"Syntax: %s URL duration outfile\n", argv
[0]);
81 } else if (is_mcast(url
)) {
82 open_fn
= &open_mcast
;
84 printf("URL %s not supported!\n", url
);
88 record(open_fn
, url
, outfile
, duration
);