fwdv.c revision 1.8 1 1.8 christos /* $NetBSD: fwdv.c,v 1.8 2013/10/19 17:06:57 christos Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (C) 2003
4 1.1 kiyohara * Hidetoshi Shimokawa. All rights reserved.
5 1.2 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
15 1.1 kiyohara * must display the following acknowledgement:
16 1.1 kiyohara *
17 1.1 kiyohara * This product includes software developed by Hidetoshi Shimokawa.
18 1.1 kiyohara *
19 1.1 kiyohara * 4. Neither the name of the author nor the names of its contributors
20 1.1 kiyohara * may be used to endorse or promote products derived from this software
21 1.1 kiyohara * without specific prior written permission.
22 1.2 kiyohara *
23 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 kiyohara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 kiyohara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 kiyohara * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 kiyohara * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 kiyohara * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 kiyohara * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 kiyohara * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 kiyohara * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 kiyohara * SUCH DAMAGE.
34 1.2 kiyohara *
35 1.4 cegger * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.8 2009/02/02 21:05:12 sbruno Exp $
36 1.1 kiyohara */
37 1.1 kiyohara #include <sys/param.h>
38 1.1 kiyohara #include <sys/ioctl.h>
39 1.1 kiyohara #include <sys/time.h>
40 1.1 kiyohara #include <sys/types.h>
41 1.1 kiyohara #include <sys/uio.h>
42 1.1 kiyohara
43 1.1 kiyohara #include <err.h>
44 1.1 kiyohara #include <errno.h>
45 1.1 kiyohara #include <unistd.h>
46 1.1 kiyohara #include <fcntl.h>
47 1.1 kiyohara #include <stdio.h>
48 1.1 kiyohara #include <stdlib.h>
49 1.1 kiyohara #include <string.h>
50 1.2 kiyohara #include <sysexits.h>
51 1.1 kiyohara
52 1.1 kiyohara #include <dev/ieee1394/firewire.h>
53 1.1 kiyohara #include <dev/ieee1394/iec68113.h>
54 1.1 kiyohara
55 1.2 kiyohara #include "fwmethods.h"
56 1.1 kiyohara
57 1.1 kiyohara #define DEBUG 0
58 1.1 kiyohara #define FIX_FRAME 1
59 1.1 kiyohara
60 1.1 kiyohara struct frac {
61 1.2 kiyohara int n,d;
62 1.1 kiyohara };
63 1.1 kiyohara
64 1.1 kiyohara struct frac frame_cycle[2] = {
65 1.1 kiyohara {8000*100, 2997}, /* NTSC 8000 cycle / 29.97 Hz */
66 1.1 kiyohara {320, 1}, /* PAL 8000 cycle / 25 Hz */
67 1.1 kiyohara };
68 1.1 kiyohara int npackets[] = {
69 1.1 kiyohara 250 /* NTSC */,
70 1.1 kiyohara 300 /* PAL */
71 1.1 kiyohara };
72 1.1 kiyohara struct frac pad_rate[2] = {
73 1.1 kiyohara {203, 2997}, /* = (8000 - 29.97 * 250)/(29.97 * 250) */
74 1.1 kiyohara {1, 15}, /* = (8000 - 25 * 300)/(25 * 300) */
75 1.1 kiyohara };
76 1.3 xtraeme const char *system_name[] = {"NTSC", "PAL"};
77 1.1 kiyohara int frame_rate[] = {30, 25};
78 1.1 kiyohara
79 1.1 kiyohara #define PSIZE 512
80 1.1 kiyohara #define DSIZE 480
81 1.2 kiyohara #define NCHUNK 64
82 1.1 kiyohara
83 1.1 kiyohara #define NPACKET_R 256
84 1.1 kiyohara #define NPACKET_T 255
85 1.1 kiyohara #define TNBUF 100 /* XXX too large value causes block noise */
86 1.1 kiyohara #define NEMPTY 10 /* depends on TNBUF */
87 1.1 kiyohara #define RBUFSIZE (PSIZE * NPACKET_R)
88 1.1 kiyohara #define MAXBLOCKS (300)
89 1.1 kiyohara #define CYCLE_FRAC 0xc00
90 1.1 kiyohara
91 1.2 kiyohara void
92 1.2 kiyohara dvrecv(int d, const char *filename, char ich, int count)
93 1.1 kiyohara {
94 1.1 kiyohara struct fw_isochreq isoreq;
95 1.1 kiyohara struct fw_isobufreq bufreq;
96 1.1 kiyohara struct dvdbc *dv;
97 1.1 kiyohara struct ciphdr *ciph;
98 1.1 kiyohara struct fw_pkt *pkt;
99 1.1 kiyohara char *pad, *buf;
100 1.4 cegger uint32_t *ptr;
101 1.3 xtraeme int len, tlen, npad, fd, k, m, vec, lsystem = -1, nb;
102 1.1 kiyohara int nblocks[] = {250 /* NTSC */, 300 /* PAL */};
103 1.1 kiyohara struct iovec wbuf[NPACKET_R];
104 1.1 kiyohara
105 1.4 cegger if (strcmp(filename, "-") == 0) {
106 1.2 kiyohara fd = STDOUT_FILENO;
107 1.2 kiyohara } else {
108 1.2 kiyohara fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660);
109 1.2 kiyohara if (fd == -1)
110 1.6 christos err(EX_NOINPUT, "%s: %s", __func__, filename);
111 1.2 kiyohara }
112 1.2 kiyohara buf = malloc(RBUFSIZE);
113 1.6 christos if (buf == NULL)
114 1.6 christos err(EX_SOFTWARE, "%s: buffer alloc", __func__);
115 1.6 christos memset(wbuf, 0, sizeof(wbuf));
116 1.6 christos
117 1.2 kiyohara pad = malloc(DSIZE*MAXBLOCKS);
118 1.6 christos if (pad == NULL)
119 1.6 christos err(EX_SOFTWARE, "%s: pad alloc", __func__);
120 1.6 christos
121 1.1 kiyohara memset(pad, 0xff, DSIZE*MAXBLOCKS);
122 1.1 kiyohara
123 1.1 kiyohara bufreq.rx.nchunk = NCHUNK;
124 1.1 kiyohara bufreq.rx.npacket = NPACKET_R;
125 1.1 kiyohara bufreq.rx.psize = PSIZE;
126 1.1 kiyohara bufreq.tx.nchunk = 0;
127 1.1 kiyohara bufreq.tx.npacket = 0;
128 1.1 kiyohara bufreq.tx.psize = 0;
129 1.2 kiyohara if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
130 1.6 christos err(EXIT_FAILURE, "%s: ioctl FW_SSTBUF", __func__);
131 1.1 kiyohara
132 1.1 kiyohara isoreq.ch = ich & 0x3f;
133 1.1 kiyohara isoreq.tag = (ich >> 6) & 3;
134 1.1 kiyohara
135 1.2 kiyohara if (ioctl(d, FW_SRSTREAM, &isoreq) < 0)
136 1.6 christos err(EXIT_FAILURE, "%s: ioctl", __func__);
137 1.1 kiyohara
138 1.1 kiyohara k = m = 0;
139 1.1 kiyohara while (count <= 0 || k <= count) {
140 1.1 kiyohara #if 0
141 1.1 kiyohara tlen = 0;
142 1.1 kiyohara while ((len = read(d, buf + tlen, PSIZE
143 1.6 christos /* RBUFSIZE - tlen */)) > 0) {
144 1.1 kiyohara if (len < 0) {
145 1.1 kiyohara if (errno == EAGAIN) {
146 1.4 cegger fprintf(stderr, "(EAGAIN)\n");
147 1.1 kiyohara fflush(stderr);
148 1.1 kiyohara if (len <= 0)
149 1.1 kiyohara continue;
150 1.1 kiyohara } else
151 1.6 christos err(EXIT_FAILURE, "%s: read failed",
152 1.7 dholland __func__);
153 1.1 kiyohara }
154 1.1 kiyohara tlen += len;
155 1.1 kiyohara if ((RBUFSIZE - tlen) < PSIZE)
156 1.1 kiyohara break;
157 1.1 kiyohara };
158 1.1 kiyohara #else
159 1.1 kiyohara tlen = len = read(d, buf, RBUFSIZE);
160 1.1 kiyohara if (len < 0) {
161 1.1 kiyohara if (errno == EAGAIN) {
162 1.4 cegger fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
163 1.1 kiyohara fflush(stderr);
164 1.1 kiyohara if (len <= 0)
165 1.1 kiyohara continue;
166 1.1 kiyohara } else
167 1.6 christos err(EXIT_FAILURE, "%s: read failed", __func__);
168 1.1 kiyohara }
169 1.1 kiyohara #endif
170 1.1 kiyohara vec = 0;
171 1.4 cegger ptr = (uint32_t *) buf;
172 1.1 kiyohara again:
173 1.2 kiyohara pkt = (struct fw_pkt *) ptr;
174 1.1 kiyohara #if DEBUG
175 1.1 kiyohara fprintf(stderr, "%08x %08x %08x %08x\n",
176 1.1 kiyohara htonl(ptr[0]), htonl(ptr[1]),
177 1.1 kiyohara htonl(ptr[2]), htonl(ptr[3]));
178 1.1 kiyohara #endif
179 1.1 kiyohara ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */
180 1.1 kiyohara if (ciph->fmt != CIP_FMT_DVCR)
181 1.6 christos errx(EXIT_FAILURE, "%s: unknown format 0x%x",
182 1.6 christos __func__, ciph->fmt);
183 1.4 cegger ptr = (uint32_t *) (ciph + 1); /* skip cip header */
184 1.1 kiyohara #if DEBUG
185 1.4 cegger if (ciph->fdf.dv.cyc != 0xffff && k == 0)
186 1.1 kiyohara fprintf(stderr, "0x%04x\n", ntohs(ciph->fdf.dv.cyc));
187 1.1 kiyohara #endif
188 1.1 kiyohara if (pkt->mode.stream.len <= sizeof(struct ciphdr))
189 1.1 kiyohara /* no payload */
190 1.1 kiyohara goto next;
191 1.1 kiyohara for (dv = (struct dvdbc *)ptr;
192 1.1 kiyohara (char *)dv < (char *)(ptr + ciph->len);
193 1.1 kiyohara dv+=6) {
194 1.1 kiyohara
195 1.1 kiyohara #if DEBUG
196 1.1 kiyohara fprintf(stderr, "(%d,%d) ", dv->sct, dv->dseq);
197 1.1 kiyohara #endif
198 1.1 kiyohara if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) {
199 1.3 xtraeme if (lsystem < 0) {
200 1.3 xtraeme lsystem = ciph->fdf.dv.fs;
201 1.2 kiyohara fprintf(stderr,
202 1.3 xtraeme "%s\n", system_name[lsystem]);
203 1.1 kiyohara }
204 1.1 kiyohara
205 1.1 kiyohara /* Fix DSF bit */
206 1.3 xtraeme if (lsystem == 1 &&
207 1.1 kiyohara (dv->payload[0] & DV_DSF_12) == 0)
208 1.1 kiyohara dv->payload[0] |= DV_DSF_12;
209 1.3 xtraeme nb = nblocks[lsystem];
210 1.4 cegger fprintf(stderr, "%d:%02d:%02d %d\r",
211 1.4 cegger k / (3600 * frame_rate[lsystem]),
212 1.4 cegger (k / (60 * frame_rate[lsystem])) % 60,
213 1.4 cegger (k / frame_rate[lsystem]) % 60,
214 1.4 cegger k % frame_rate[lsystem]);
215 1.4 cegger
216 1.1 kiyohara #if FIX_FRAME
217 1.1 kiyohara if (m > 0 && m != nb) {
218 1.1 kiyohara /* padding bad frame */
219 1.1 kiyohara npad = ((nb - m) % nb);
220 1.1 kiyohara if (npad < 0)
221 1.1 kiyohara npad += nb;
222 1.4 cegger fprintf(stderr, "\n%d blocks padded\n",
223 1.4 cegger npad);
224 1.1 kiyohara npad *= DSIZE;
225 1.1 kiyohara wbuf[vec].iov_base = pad;
226 1.1 kiyohara wbuf[vec++].iov_len = npad;
227 1.1 kiyohara if (vec >= NPACKET_R) {
228 1.1 kiyohara writev(fd, wbuf, vec);
229 1.1 kiyohara vec = 0;
230 1.1 kiyohara }
231 1.1 kiyohara }
232 1.1 kiyohara #endif
233 1.1 kiyohara k++;
234 1.1 kiyohara fflush(stderr);
235 1.1 kiyohara m = 0;
236 1.1 kiyohara }
237 1.1 kiyohara if (k == 0 || (count > 0 && k > count))
238 1.1 kiyohara continue;
239 1.1 kiyohara m++;
240 1.1 kiyohara wbuf[vec].iov_base = (char *) dv;
241 1.1 kiyohara wbuf[vec++].iov_len = DSIZE;
242 1.1 kiyohara if (vec >= NPACKET_R) {
243 1.1 kiyohara writev(fd, wbuf, vec);
244 1.1 kiyohara vec = 0;
245 1.1 kiyohara }
246 1.1 kiyohara }
247 1.4 cegger ptr = (uint32_t *)dv;
248 1.1 kiyohara next:
249 1.1 kiyohara if ((char *)ptr < buf + tlen)
250 1.1 kiyohara goto again;
251 1.1 kiyohara if (vec > 0)
252 1.1 kiyohara writev(fd, wbuf, vec);
253 1.1 kiyohara }
254 1.4 cegger if (fd != STDOUT_FILENO)
255 1.2 kiyohara close(fd);
256 1.1 kiyohara fprintf(stderr, "\n");
257 1.1 kiyohara }
258 1.1 kiyohara
259 1.1 kiyohara
260 1.2 kiyohara void
261 1.2 kiyohara dvsend(int d, const char *filename, char ich, int count)
262 1.1 kiyohara {
263 1.1 kiyohara struct fw_isochreq isoreq;
264 1.1 kiyohara struct fw_isobufreq bufreq;
265 1.1 kiyohara struct dvdbc *dv;
266 1.1 kiyohara struct fw_pkt *pkt;
267 1.1 kiyohara int len, tlen, header, fd, frames, packets, vec, offset, nhdr, i;
268 1.8 christos int lsystem=-1, pad_acc, cycle_acc, cycle, f_frac;
269 1.1 kiyohara struct iovec wbuf[TNBUF*2 + NEMPTY];
270 1.1 kiyohara char *pbuf;
271 1.4 cegger uint32_t iso_data, iso_empty, hdr[TNBUF + NEMPTY][3];
272 1.1 kiyohara struct ciphdr *ciph;
273 1.1 kiyohara struct timeval start, end;
274 1.1 kiyohara double rtime;
275 1.1 kiyohara
276 1.1 kiyohara cycle_acc = cycle = 0;
277 1.1 kiyohara
278 1.1 kiyohara fd = open(filename, O_RDONLY);
279 1.2 kiyohara if (fd == -1)
280 1.6 christos err(EX_NOINPUT, "%s: %s", __func__, filename);
281 1.2 kiyohara
282 1.2 kiyohara pbuf = malloc(DSIZE * TNBUF);
283 1.1 kiyohara bzero(wbuf, sizeof(wbuf));
284 1.1 kiyohara
285 1.1 kiyohara bufreq.rx.nchunk = 0;
286 1.1 kiyohara bufreq.rx.npacket = 0;
287 1.1 kiyohara bufreq.rx.psize = 0;
288 1.1 kiyohara bufreq.tx.nchunk = NCHUNK;
289 1.1 kiyohara bufreq.tx.npacket = NPACKET_T;
290 1.1 kiyohara bufreq.tx.psize = PSIZE;
291 1.2 kiyohara if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
292 1.6 christos err(EXIT_FAILURE, "%s: ioctl FW_SSTBUF", __func__);
293 1.1 kiyohara
294 1.1 kiyohara isoreq.ch = ich & 0x3f;
295 1.1 kiyohara isoreq.tag = (ich >> 6) & 3;
296 1.1 kiyohara
297 1.2 kiyohara if (ioctl(d, FW_STSTREAM, &isoreq) < 0)
298 1.6 christos err(EXIT_FAILURE, "%s: ioctl FW_STSTREAM", __func__);
299 1.1 kiyohara
300 1.1 kiyohara iso_data = 0;
301 1.1 kiyohara pkt = (struct fw_pkt *) &iso_data;
302 1.1 kiyohara pkt->mode.stream.len = DSIZE + sizeof(struct ciphdr);
303 1.1 kiyohara pkt->mode.stream.sy = 0;
304 1.1 kiyohara pkt->mode.stream.tcode = FWTCODE_STREAM;
305 1.1 kiyohara pkt->mode.stream.chtag = ich;
306 1.1 kiyohara iso_empty = iso_data;
307 1.1 kiyohara pkt = (struct fw_pkt *) &iso_empty;
308 1.1 kiyohara pkt->mode.stream.len = sizeof(struct ciphdr);
309 1.1 kiyohara
310 1.1 kiyohara bzero(hdr[0], sizeof(hdr[0]));
311 1.1 kiyohara hdr[0][0] = iso_data;
312 1.1 kiyohara ciph = (struct ciphdr *)&hdr[0][1];
313 1.1 kiyohara ciph->src = 0; /* XXX */
314 1.1 kiyohara ciph->len = 120;
315 1.1 kiyohara ciph->dbc = 0;
316 1.1 kiyohara ciph->eoh1 = 1;
317 1.1 kiyohara ciph->fdf.dv.cyc = 0xffff;
318 1.1 kiyohara
319 1.2 kiyohara for (i = 1; i < TNBUF; i++)
320 1.1 kiyohara bcopy(hdr[0], hdr[i], sizeof(hdr[0]));
321 1.1 kiyohara
322 1.1 kiyohara gettimeofday(&start, NULL);
323 1.1 kiyohara #if DEBUG
324 1.1 kiyohara fprintf(stderr, "%08x %08x %08x\n",
325 1.1 kiyohara htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2]));
326 1.1 kiyohara #endif
327 1.1 kiyohara frames = 0;
328 1.1 kiyohara packets = 0;
329 1.1 kiyohara pad_acc = 0;
330 1.6 christos for (;;) {
331 1.1 kiyohara tlen = 0;
332 1.1 kiyohara while (tlen < DSIZE * TNBUF) {
333 1.1 kiyohara len = read(fd, pbuf + tlen, DSIZE * TNBUF - tlen);
334 1.1 kiyohara if (len <= 0) {
335 1.1 kiyohara if (tlen > 0)
336 1.1 kiyohara break;
337 1.1 kiyohara if (len < 0)
338 1.1 kiyohara warn("read");
339 1.1 kiyohara else
340 1.2 kiyohara fprintf(stderr, "\nend of file\n");
341 1.1 kiyohara goto send_end;
342 1.1 kiyohara }
343 1.1 kiyohara tlen += len;
344 1.1 kiyohara }
345 1.1 kiyohara vec = 0;
346 1.1 kiyohara offset = 0;
347 1.1 kiyohara nhdr = 0;
348 1.1 kiyohara next:
349 1.1 kiyohara dv = (struct dvdbc *)(pbuf + offset * DSIZE);
350 1.1 kiyohara #if 0
351 1.1 kiyohara header = (dv->sct == 0 && dv->dseq == 0);
352 1.1 kiyohara #else
353 1.3 xtraeme header = (packets == 0 || packets % npackets[lsystem] == 0);
354 1.1 kiyohara #endif
355 1.1 kiyohara
356 1.1 kiyohara ciph = (struct ciphdr *)&hdr[nhdr][1];
357 1.1 kiyohara if (header) {
358 1.3 xtraeme if (lsystem < 0) {
359 1.3 xtraeme lsystem = ((dv->payload[0] & DV_DSF_12) != 0);
360 1.3 xtraeme printf("%s\n", system_name[lsystem]);
361 1.1 kiyohara cycle = 1;
362 1.3 xtraeme cycle_acc = frame_cycle[lsystem].d * cycle;
363 1.1 kiyohara }
364 1.1 kiyohara fprintf(stderr, "%d", frames % 10);
365 1.1 kiyohara frames ++;
366 1.1 kiyohara if (count > 0 && frames > count)
367 1.1 kiyohara break;
368 1.3 xtraeme if (frames % frame_rate[lsystem] == 0)
369 1.1 kiyohara fprintf(stderr, "\n");
370 1.1 kiyohara fflush(stderr);
371 1.3 xtraeme f_frac = (cycle_acc % frame_cycle[lsystem].d
372 1.3 xtraeme * CYCLE_FRAC) / frame_cycle[lsystem].d;
373 1.1 kiyohara #if 0
374 1.8 christos int f_cycle = (cycle_acc / frame_cycle[lsystem].d)
375 1.8 christos & 0xf;
376 1.1 kiyohara ciph->fdf.dv.cyc = htons(f_cycle << 12 | f_frac);
377 1.1 kiyohara #else
378 1.1 kiyohara ciph->fdf.dv.cyc = htons(cycle << 12 | f_frac);
379 1.1 kiyohara #endif
380 1.3 xtraeme cycle_acc += frame_cycle[lsystem].n;
381 1.3 xtraeme cycle_acc %= frame_cycle[lsystem].d * 0x10;
382 1.1 kiyohara
383 1.1 kiyohara } else {
384 1.1 kiyohara ciph->fdf.dv.cyc = 0xffff;
385 1.1 kiyohara }
386 1.1 kiyohara ciph->dbc = packets++ % 256;
387 1.3 xtraeme pad_acc += pad_rate[lsystem].n;
388 1.3 xtraeme if (pad_acc >= pad_rate[lsystem].d) {
389 1.3 xtraeme pad_acc -= pad_rate[lsystem].d;
390 1.1 kiyohara bcopy(hdr[nhdr], hdr[nhdr+1], sizeof(hdr[0]));
391 1.1 kiyohara hdr[nhdr][0] = iso_empty;
392 1.1 kiyohara wbuf[vec].iov_base = (char *)hdr[nhdr];
393 1.1 kiyohara wbuf[vec++].iov_len = sizeof(hdr[0]);
394 1.1 kiyohara nhdr ++;
395 1.1 kiyohara cycle ++;
396 1.1 kiyohara }
397 1.1 kiyohara hdr[nhdr][0] = iso_data;
398 1.1 kiyohara wbuf[vec].iov_base = (char *)hdr[nhdr];
399 1.1 kiyohara wbuf[vec++].iov_len = sizeof(hdr[0]);
400 1.1 kiyohara wbuf[vec].iov_base = (char *)dv;
401 1.1 kiyohara wbuf[vec++].iov_len = DSIZE;
402 1.1 kiyohara nhdr ++;
403 1.1 kiyohara cycle ++;
404 1.1 kiyohara offset ++;
405 1.1 kiyohara if (offset * DSIZE < tlen)
406 1.1 kiyohara goto next;
407 1.1 kiyohara
408 1.1 kiyohara again:
409 1.1 kiyohara len = writev(d, wbuf, vec);
410 1.1 kiyohara if (len < 0) {
411 1.1 kiyohara if (errno == EAGAIN) {
412 1.2 kiyohara fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
413 1.1 kiyohara goto again;
414 1.1 kiyohara }
415 1.6 christos err(EXIT_FAILURE, "%s: write failed", __func__);
416 1.1 kiyohara }
417 1.1 kiyohara }
418 1.1 kiyohara close(fd);
419 1.1 kiyohara fprintf(stderr, "\n");
420 1.1 kiyohara send_end:
421 1.1 kiyohara gettimeofday(&end, NULL);
422 1.2 kiyohara rtime = end.tv_sec - start.tv_sec
423 1.1 kiyohara + (end.tv_usec - start.tv_usec) * 1e-6;
424 1.1 kiyohara fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n",
425 1.1 kiyohara frames, rtime, frames/rtime);
426 1.1 kiyohara }
427