]>
git.zerfleddert.de Git - record-dvb/blob - record-dvb.c
bb69447e7b72d9a101c244d739046f7f7a9e45db
6 #include <sys/socket.h>
16 #define CHUNKSIZE 3000
17 #define GTOD_INTERVAL 100
18 #define MAX_ERROR_SLEEP 60
20 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
)
22 struct timeval start
, curr
;
23 int bytes
, recvd
, written
, count
= 0;
25 char buffer
[CHUNKSIZE
];
28 if ((in
= (*open_fn
)(url
)) < 0) {
29 fprintf(stderr
,"Can't open url %s!\n",url
);
33 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
38 printf("Recording from %s for %d seconds...\n", url
, duration
);
40 gettimeofday(&start
, NULL
);
46 printf("Reconnecting... ");
47 if ((in
= (*open_fn
)(url
)) < 0) {
48 if (error_sleep
< MAX_ERROR_SLEEP
)
51 if (error_sleep
> MAX_ERROR_SLEEP
)
52 error_sleep
= MAX_ERROR_SLEEP
;
57 printf("succeeded\n");
62 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
68 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
73 } while(written
< recvd
);
75 if (!(++count
% GTOD_INTERVAL
))
76 gettimeofday(&curr
, NULL
);
77 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
81 shutdown(in
, SHUT_RDWR
);
84 int main(int argc
, char **argv
)
89 int(*open_fn
)(char *);
93 duration
= atoi(argv
[2])*60;
96 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
101 open_fn
= &open_http
;
102 } else if (is_mcast(url
)) {
103 open_fn
= &open_mcast
;
105 printf("URL %s not supported!\n", url
);
109 record(open_fn
, url
, outfile
, duration
);