#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
fe_status_t status;
sprintf(file, "/dev/dvb/adapter%d/frontend0", adapter_nr);
- if ((fd = open(file, (O_RDWR | O_CREAT | O_TRUNC), 0666)) < 0) {
+ if ((fd = open(file, O_RDWR)) < 0) {
perror("open");
return -1;
}
close(fd);
return -1;
}
-}
-void record(int adapter_nr, char* output, int rectime) {
- int fin, fout;
- char input[256];
- time_t start_time, current_time;
- char buf[1316];
- ssize_t rt, wt;
- int size_remain;
-
- fout = open(output, (O_WRONLY | O_CREAT | O_TRUNC));
- if ( fout < 0 ) {
- printf("output file open failed\n");
- return;
- }
- sprintf(input, "/dev/dvb/adapter%d/dvr0", adapter_nr);
- start_time = time(NULL);
- fin = open(input, (O_RDONLY));
- while ( rt = read(fin, buf, 1316) ) {
- while ( wt = write(fout, buf, rt) ) {
- rt -= wt;
- if ( rt == 0 ) break;
- if ( wt == 0 ) {
- printf("output file write failed\n");
- goto error;
- }
- }
- current_time = time(NULL);
- if ( current_time - start_time > rectime ) {
- break;
- }
- }
+ while (1)
+ sleep(3);
- error:
- close(fin);
- close(fout);
+ /* never returns */
}
int main(int argc, char *argv[]) {
int channel_freq;
int fd;
int ret;
- int rectime;
if (argc <= 2) {
fprintf(stderr, "Usage: %s adapter_nr freq [tsid]\n", argv[0]);
adapter_nr = strtol(argv[1], NULL, 0);
channel_freq = strtol(argv[2], NULL, 10);
channel_id=0;
- if (argc >= 4){
+ if (argc == 4){
channel_id = strtol(argv[3], NULL, 10);
}
- if ( argc == 5 ) {
- rectime = atoi(argv[4]);
- }
struct channel ch1 ={0,"",channel_freq,channel_id};
ch = &ch1;
//struct channel ch;//{ 1, "NHK BS-1", 1318000, 0x40f1 }
return 1;
ret = track(adapter_nr);
- record(adapter_nr, argv[3], rectime);
close(fd);
return ret < 0;