]>
git.zerfleddert.de Git - record-dvb/blob - record-dvb.c
9356348343fe4f81d20cc0cf580f8c63b95fd1f2
6 #include <sys/socket.h>
9 #include <sys/select.h>
18 #define CHUNKSIZE 3000
19 #define GTOD_INTERVAL 100
20 #define MAX_ERROR_SLEEP 60
22 void record(int(*open_fn
)(char *), char *url
, char *outfile
, int duration
)
24 struct timeval start
, curr
;
25 int bytes
, recvd
, written
, count
= 0;
27 char buffer
[CHUNKSIZE
];
33 if ((in
= (*open_fn
)(url
)) < 0) {
34 fprintf(stderr
,"Can't open url %s!\n",url
);
38 if ((out
= open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
|O_LARGEFILE
, 00644)) < 0) {
43 printf("Recording from %s for %d seconds...\n", url
, duration
);
45 gettimeofday(&start
, NULL
);
51 printf("Reconnecting... ");
52 if ((in
= (*open_fn
)(url
)) < 0) {
53 if (error_sleep
< MAX_ERROR_SLEEP
)
56 if (error_sleep
> MAX_ERROR_SLEEP
)
57 error_sleep
= MAX_ERROR_SLEEP
;
62 printf("succeeded\n");
73 if ((retval
= select(in
+ 1, &rfds
, NULL
, NULL
, &tv
)) == -1) {
79 gettimeofday(&curr
, NULL
);
83 if ((recvd
= recv(in
, buffer
, CHUNKSIZE
, 0)) < 1) {
89 if ((bytes
= write(out
, buffer
, recvd
-written
)) < 0) {
94 } while(written
< recvd
);
96 if (!(++count
% GTOD_INTERVAL
))
97 gettimeofday(&curr
, NULL
);
98 } while (curr
.tv_sec
< start
.tv_sec
+duration
);
102 shutdown(in
, SHUT_RDWR
);
105 int main(int argc
, char **argv
)
110 int(*open_fn
)(char *);
114 duration
= atoi(argv
[2])*60;
117 fprintf(stderr
,"Syntax: %s URL duration_in_minutes outfile\n", argv
[0]);
121 if (!is_http(url
) && !is_mcast(url
)) {
123 if ((service_url
= get_url_from_sap(url
))) {
124 printf("SAP says: '%s' -> %s\n", url
, service_url
);
130 open_fn
= &open_http
;
131 } else if (is_mcast(url
)) {
132 open_fn
= &open_mcast
;
134 printf("URL '%s' not supported!\n", url
);
138 record(open_fn
, url
, outfile
, duration
);