X-Git-Url: http://git.osdn.net/view?p=rec10%2Frec10-git.git;a=blobdiff_plain;f=tunerec%2Ftunerec.c;h=9bcf0ea85a664dd73b7ccef179345f60ed3100f9;hp=f3f3328a3c85b22a8f2a3989a62402b356cb2ac5;hb=84e1fb811a91d13741e3ea60c5f3bc7f88fa6a6f;hpb=fc9f3fc7f1d02c8eff5a5f026d7a0fa4a814cdf9 diff --git a/tunerec/tunerec.c b/tunerec/tunerec.c index f3f3328..9bcf0ea 100755 --- a/tunerec/tunerec.c +++ b/tunerec/tunerec.c @@ -7,6 +7,7 @@ #include #include #include +#include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -114,11 +115,42 @@ static int track(int adapter_nr) close(fd); return -1; } +} - while (1) - sleep(3); +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; + } + } - /* never returns */ + error: + close(fin); + close(fout); } int main(int argc, char *argv[]) { @@ -127,6 +159,7 @@ 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]); @@ -136,9 +169,12 @@ int main(int argc, char *argv[]) { 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 } @@ -148,6 +184,7 @@ int main(int argc, char *argv[]) { return 1; ret = track(adapter_nr); + record(adapter_nr, argv[3], rectime); close(fd); return ret < 0;