| 73 | | while ((sz=read(fin, buf, sizeof(buf))) > 0) { |
|---|
| 74 | | write(fout, buf, sz); |
|---|
| 75 | | t2 = time(NULL); |
|---|
| 76 | | if (t1 != t2) { |
|---|
| 77 | | t1 = t2; |
|---|
| 78 | | ioctl(fin, IVTV_IOC_G_INDEX, &idx); |
|---|
| 79 | | printf("entries %d\n", idx.entries); |
|---|
| 80 | | for (unsigned i = 0; i < idx.entries; i++) { |
|---|
| 81 | | if (idx.entry[i].flags != IVTV_IDX_FL_I) |
|---|
| 82 | | continue; |
|---|
| 83 | | stamps s; |
|---|
| 84 | | s.offset = idx.entry[i].offset; |
|---|
| 85 | | s.pts = idx.entry[i].pts; |
|---|
| 86 | | write(fidx, &s, sizeof(s)); |
|---|
| | 82 | ioctl(fin, IVTV_IOC_S_GOP_END, &gop); |
|---|
| | 83 | |
|---|
| | 84 | read(fin, buf, 0); // kickstart the recording |
|---|
| | 85 | ioctl(fin, IVTV_IOC_RESUME_ENCODE, 0); |
|---|
| | 86 | while (!quit) { |
|---|
| | 87 | FD_ZERO(&fd_in); |
|---|
| | 88 | FD_SET(0, &fd_in); |
|---|
| | 89 | FD_SET(fin, &fd_in); |
|---|
| | 90 | int res = select(fin + 1, &fd_in, NULL, NULL, NULL); |
|---|
| | 91 | |
|---|
| | 92 | if (res < 0) |
|---|
| | 93 | break; |
|---|
| | 94 | if (FD_ISSET(0, &fd_in)) { |
|---|
| | 95 | char ch; |
|---|
| | 96 | while (read(0, &ch, 1) > 0) { |
|---|
| | 97 | if (ch == '\n') |
|---|
| | 98 | break; |
|---|
| | 99 | if (ch == 'q') { |
|---|
| | 100 | // quit = 1; |
|---|
| | 101 | ioctl(fin, VIDIOC_STREAMOFF, &gop); |
|---|
| | 102 | } |
|---|
| | 103 | process(fin, ch); |
|---|
| | 106 | if (!FD_ISSET(fin, &fd_in)) |
|---|
| | 107 | continue; |
|---|
| | 108 | if ((sz=read(fin, buf, sizeof(buf))) > 0) { |
|---|
| | 109 | write(fout, buf, sz); |
|---|
| | 110 | t2 = time(NULL); |
|---|
| | 111 | if (t1 != t2) { |
|---|
| | 112 | t1 = t2; |
|---|
| | 113 | ioctl(fin, IVTV_IOC_G_INDEX, &idx); |
|---|
| | 114 | for (unsigned i = 0; i < idx.entries; i++) { |
|---|
| | 115 | printf("%d %lld %d\n", idx.entry[i].flags, idx.entry[i].offset, idx.entry[i].length); |
|---|
| | 116 | if (idx.entry[i].flags != IVTV_IDX_FL_I) |
|---|
| | 117 | continue; |
|---|
| | 118 | stamps s; |
|---|
| | 119 | s.offset = idx.entry[i].offset; |
|---|
| | 120 | s.pts = idx.entry[i].pts; |
|---|
| | 121 | write(fidx, &s, sizeof(s)); |
|---|
| | 122 | } |
|---|
| | 123 | fflush(stdout); |
|---|
| | 124 | } |
|---|
| | 125 | } |
|---|
| | 126 | if (sz == 0) |
|---|
| | 127 | break; |
|---|
| | 128 | } |
|---|
| | 129 | ioctl(fin, IVTV_IOC_G_INDEX, &idx); |
|---|
| | 130 | for (unsigned i = 0; i < idx.entries; i++) { |
|---|
| | 131 | printf("%d %lld %d\n", idx.entry[i].flags, idx.entry[i].offset, idx.entry[i].length); |
|---|
| | 132 | if (idx.entry[i].flags != IVTV_IDX_FL_I) |
|---|
| | 133 | continue; |
|---|
| | 134 | stamps s; |
|---|
| | 135 | s.offset = idx.entry[i].offset; |
|---|
| | 136 | s.pts = idx.entry[i].pts; |
|---|
| | 137 | write(fidx, &s, sizeof(s)); |
|---|