]>
cvs.zerfleddert.de Git - record-dvb/blob - record-dvb.c
6 #include <sys/socket.h>
17 #define CHUNKSIZE 3000
18 #define GTOD_INTERVAL 100
19 #define MAX_ERROR_SLEEP 60
21 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
)
23 struct timeval start
, curr
;
24 int bytes
, recvd
, written
, count
= 0;
26 char buffer
[CHUNKSIZE
];
29 if ((in
= (*open_fn
)(url
)) < 0) {
30 fprintf(stderr
,"Can't open url %s!\n",url
);
34 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
39 printf("Recording from %s for %d seconds...\n", url
, duration
);
41 gettimeofday(&start
, NULL
);
47 printf("Reconnecting... ");
48 if ((in
= (*open_fn
)(url
)) < 0) {
49 if (error_sleep
< MAX_ERROR_SLEEP
)
52 if (error_sleep
> MAX_ERROR_SLEEP
)
53 error_sleep
= MAX_ERROR_SLEEP
;
58 printf("succeeded\n");
63 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
69 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
74 } while(written
< recvd
);
76 if (!(++count
% GTOD_INTERVAL
))
77 gettimeofday(&curr
, NULL
);
78 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
82 shutdown(in
, SHUT_RDWR
);
85 int main(int argc
, char **argv
)
90 int(*open_fn
)(char *);
94 duration
= atoi(argv
[2])*60;
97 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
101 if (!is_http(url
) && !is_mcast(url
)) {
103 if ((service_url
= get_url_from_sap(url
))) {
104 printf("SAP says: '%s' -> %s\n", url
, service_url
);
110 open_fn
= &open_http
;
111 } else if (is_mcast(url
)) {
112 open_fn
= &open_mcast
;
114 printf("URL '%s' not supported!\n", url
);
118 record(open_fn
, url
, outfile
, duration
);