]>
git.zerfleddert.de Git - record-dvb/blob - record-dvb.c
38609a4996c27cf7caea23c89a8469e22c57fe00
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;
24 char buffer
[CHUNKSIZE
];
27 if ((in
= (*open_fn
)(url
)) < 0) {
28 fprintf(stderr
,"Can't open url %s!\n",url
);
32 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
37 printf("Recording from %s for %d seconds...\n", url
, duration
);
39 gettimeofday(&start
, NULL
);
45 printf("Reconnecting... ");
46 if ((in
= (*open_fn
)(url
)) < 0) {
53 printf("succeeded\n");
58 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
64 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
69 } while(written
< recvd
);
71 if (!(++count
% GTOD_INTERVAL
))
72 gettimeofday(&curr
, NULL
);
73 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
77 shutdown(in
, SHUT_RDWR
);
80 int main(int argc
, char **argv
)
85 int(*open_fn
)(char *);
89 duration
= atoi(argv
[2])*60;
92 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
98 } else if (is_mcast(url
)) {
99 open_fn
= &open_mcast
;
101 printf("URL %s not supported!\n", url
);
105 record(open_fn
, url
, outfile
, duration
);