]>
cvs.zerfleddert.de Git - record-dvb/blob - record-dvb.c
6 #include <sys/socket.h>
9 #include <sys/select.h>
20 #define CHUNKSIZE 3000
21 #define GTOD_INTERVAL 100
22 #define MAX_ERROR_SLEEP 60
24 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
)
26 struct timeval start
, curr
;
27 int bytes
, recvd
, written
, count
= 0;
29 char buffer
[CHUNKSIZE
];
35 if ((in
= (*open_fn
)(url
)) < 0) {
36 fprintf(stderr
,"Can't open url %s!\n",url
);
40 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
45 printf("Recording from %s for %d seconds...\n", url
, duration
);
47 gettimeofday(&start
, NULL
);
53 printf("Reconnecting... ");
54 if ((in
= (*open_fn
)(url
)) < 0) {
55 if (error_sleep
< MAX_ERROR_SLEEP
)
58 if (error_sleep
> MAX_ERROR_SLEEP
)
59 error_sleep
= MAX_ERROR_SLEEP
;
64 printf("succeeded\n");
75 if ((retval
= select(in
+ 1, &rfds
, NULL
, NULL
, &tv
)) == -1) {
81 gettimeofday(&curr
, NULL
);
85 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
91 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
96 } while(written
< recvd
);
98 if (!(++count
% GTOD_INTERVAL
))
99 gettimeofday(&curr
, NULL
);
100 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
104 shutdown(in
, SHUT_RDWR
);
107 int main(int argc
, char **argv
)
112 int(*open_fn
)(char *);
116 duration
= atoi(argv
[2])*60;
119 fprintf(stderr
,"Syntax: %s URL|SAPServiceName duration_in_minutes outfile\n", argv
[0]);
125 if ((service_url
= get_url_from_sap(url
))) {
126 printf("SAP says: '%s' -> %s\n", url
, service_url
);
132 open_fn
= &open_http
;
133 } else if (is_mcast(url
)) {
134 open_fn
= &open_mcast
;
136 printf("URL '%s' not supported!\n", url
);
140 record(open_fn
, url
, outfile
, duration
);