fwdv.c revision 1.4 1 1.4 cegger /* $NetBSD: fwdv.c,v 1.4 2010/08/24 08:41:24 cegger 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.2 kiyohara err(EX_NOINPUT, filename);
111 1.2 kiyohara }
112 1.2 kiyohara buf = malloc(RBUFSIZE);
113 1.2 kiyohara pad = malloc(DSIZE*MAXBLOCKS);
114 1.1 kiyohara memset(pad, 0xff, DSIZE*MAXBLOCKS);
115 1.1 kiyohara bzero(wbuf, sizeof(wbuf));
116 1.1 kiyohara
117 1.1 kiyohara bufreq.rx.nchunk = NCHUNK;
118 1.1 kiyohara bufreq.rx.npacket = NPACKET_R;
119 1.1 kiyohara bufreq.rx.psize = PSIZE;
120 1.1 kiyohara bufreq.tx.nchunk = 0;
121 1.1 kiyohara bufreq.tx.npacket = 0;
122 1.1 kiyohara bufreq.tx.psize = 0;
123 1.2 kiyohara if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
124 1.4 cegger err(EXIT_FAILURE, "ioctl FW_SSTBUF");
125 1.1 kiyohara
126 1.1 kiyohara isoreq.ch = ich & 0x3f;
127 1.1 kiyohara isoreq.tag = (ich >> 6) & 3;
128 1.1 kiyohara
129 1.2 kiyohara if (ioctl(d, FW_SRSTREAM, &isoreq) < 0)
130 1.4 cegger err(EXIT_FAILURE, "ioctl");
131 1.1 kiyohara
132 1.1 kiyohara k = m = 0;
133 1.1 kiyohara while (count <= 0 || k <= count) {
134 1.1 kiyohara #if 0
135 1.1 kiyohara tlen = 0;
136 1.1 kiyohara while ((len = read(d, buf + tlen, PSIZE
137 1.1 kiyohara /* RBUFSIZE - tlen */)) > 0) {
138 1.1 kiyohara if (len < 0) {
139 1.1 kiyohara if (errno == EAGAIN) {
140 1.4 cegger fprintf(stderr, "(EAGAIN)\n");
141 1.1 kiyohara fflush(stderr);
142 1.1 kiyohara if (len <= 0)
143 1.1 kiyohara continue;
144 1.1 kiyohara } else
145 1.4 cegger err(EXIT_FAILURE, "read failed");
146 1.1 kiyohara }
147 1.1 kiyohara tlen += len;
148 1.1 kiyohara if ((RBUFSIZE - tlen) < PSIZE)
149 1.1 kiyohara break;
150 1.1 kiyohara };
151 1.1 kiyohara #else
152 1.1 kiyohara tlen = len = read(d, buf, RBUFSIZE);
153 1.1 kiyohara if (len < 0) {
154 1.1 kiyohara if (errno == EAGAIN) {
155 1.4 cegger fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
156 1.1 kiyohara fflush(stderr);
157 1.1 kiyohara if (len <= 0)
158 1.1 kiyohara continue;
159 1.1 kiyohara } else
160 1.4 cegger err(EXIT_FAILURE, "read failed");
161 1.1 kiyohara }
162 1.1 kiyohara #endif
163 1.1 kiyohara vec = 0;
164 1.4 cegger ptr = (uint32_t *) buf;
165 1.1 kiyohara again:
166 1.2 kiyohara pkt = (struct fw_pkt *) ptr;
167 1.1 kiyohara #if DEBUG
168 1.1 kiyohara fprintf(stderr, "%08x %08x %08x %08x\n",
169 1.1 kiyohara htonl(ptr[0]), htonl(ptr[1]),
170 1.1 kiyohara htonl(ptr[2]), htonl(ptr[3]));
171 1.1 kiyohara #endif
172 1.1 kiyohara ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */
173 1.1 kiyohara if (ciph->fmt != CIP_FMT_DVCR)
174 1.1 kiyohara errx(1, "unknown format 0x%x", ciph->fmt);
175 1.4 cegger ptr = (uint32_t *) (ciph + 1); /* skip cip header */
176 1.1 kiyohara #if DEBUG
177 1.4 cegger if (ciph->fdf.dv.cyc != 0xffff && k == 0)
178 1.1 kiyohara fprintf(stderr, "0x%04x\n", ntohs(ciph->fdf.dv.cyc));
179 1.1 kiyohara #endif
180 1.1 kiyohara if (pkt->mode.stream.len <= sizeof(struct ciphdr))
181 1.1 kiyohara /* no payload */
182 1.1 kiyohara goto next;
183 1.1 kiyohara for (dv = (struct dvdbc *)ptr;
184 1.1 kiyohara (char *)dv < (char *)(ptr + ciph->len);
185 1.1 kiyohara dv+=6) {
186 1.1 kiyohara
187 1.1 kiyohara #if DEBUG
188 1.1 kiyohara fprintf(stderr, "(%d,%d) ", dv->sct, dv->dseq);
189 1.1 kiyohara #endif
190 1.1 kiyohara if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) {
191 1.3 xtraeme if (lsystem < 0) {
192 1.3 xtraeme lsystem = ciph->fdf.dv.fs;
193 1.2 kiyohara fprintf(stderr,
194 1.3 xtraeme "%s\n", system_name[lsystem]);
195 1.1 kiyohara }
196 1.1 kiyohara
197 1.1 kiyohara /* Fix DSF bit */
198 1.3 xtraeme if (lsystem == 1 &&
199 1.1 kiyohara (dv->payload[0] & DV_DSF_12) == 0)
200 1.1 kiyohara dv->payload[0] |= DV_DSF_12;
201 1.3 xtraeme nb = nblocks[lsystem];
202 1.4 cegger fprintf(stderr, "%d:%02d:%02d %d\r",
203 1.4 cegger k / (3600 * frame_rate[lsystem]),
204 1.4 cegger (k / (60 * frame_rate[lsystem])) % 60,
205 1.4 cegger (k / frame_rate[lsystem]) % 60,
206 1.4 cegger k % frame_rate[lsystem]);
207 1.4 cegger
208 1.1 kiyohara #if FIX_FRAME
209 1.1 kiyohara if (m > 0 && m != nb) {
210 1.1 kiyohara /* padding bad frame */
211 1.1 kiyohara npad = ((nb - m) % nb);
212 1.1 kiyohara if (npad < 0)
213 1.1 kiyohara npad += nb;
214 1.4 cegger fprintf(stderr, "\n%d blocks padded\n",
215 1.4 cegger npad);
216 1.1 kiyohara npad *= DSIZE;
217 1.1 kiyohara wbuf[vec].iov_base = pad;
218 1.1 kiyohara wbuf[vec++].iov_len = npad;
219 1.1 kiyohara if (vec >= NPACKET_R) {
220 1.1 kiyohara writev(fd, wbuf, vec);
221 1.1 kiyohara vec = 0;
222 1.1 kiyohara }
223 1.1 kiyohara }
224 1.1 kiyohara #endif
225 1.1 kiyohara k++;
226 1.1 kiyohara fflush(stderr);
227 1.1 kiyohara m = 0;
228 1.1 kiyohara }
229 1.1 kiyohara if (k == 0 || (count > 0 && k > count))
230 1.1 kiyohara continue;
231 1.1 kiyohara m++;
232 1.1 kiyohara wbuf[vec].iov_base = (char *) dv;
233 1.1 kiyohara wbuf[vec++].iov_len = DSIZE;
234 1.1 kiyohara if (vec >= NPACKET_R) {
235 1.1 kiyohara writev(fd, wbuf, vec);
236 1.1 kiyohara vec = 0;
237 1.1 kiyohara }
238 1.1 kiyohara }
239 1.4 cegger ptr = (uint32_t *)dv;
240 1.1 kiyohara next:
241 1.1 kiyohara if ((char *)ptr < buf + tlen)
242 1.1 kiyohara goto again;
243 1.1 kiyohara if (vec > 0)
244 1.1 kiyohara writev(fd, wbuf, vec);
245 1.1 kiyohara }
246 1.4 cegger if (fd != STDOUT_FILENO)
247 1.2 kiyohara close(fd);
248 1.1 kiyohara fprintf(stderr, "\n");
249 1.1 kiyohara }
250 1.1 kiyohara
251 1.1 kiyohara
252 1.2 kiyohara void
253 1.2 kiyohara dvsend(int d, const char *filename, char ich, int count)
254 1.1 kiyohara {
255 1.1 kiyohara struct fw_isochreq isoreq;
256 1.1 kiyohara struct fw_isobufreq bufreq;
257 1.1 kiyohara struct dvdbc *dv;
258 1.1 kiyohara struct fw_pkt *pkt;
259 1.1 kiyohara int len, tlen, header, fd, frames, packets, vec, offset, nhdr, i;
260 1.3 xtraeme int lsystem=-1, pad_acc, cycle_acc, cycle, f_cycle, f_frac;
261 1.1 kiyohara struct iovec wbuf[TNBUF*2 + NEMPTY];
262 1.1 kiyohara char *pbuf;
263 1.4 cegger uint32_t iso_data, iso_empty, hdr[TNBUF + NEMPTY][3];
264 1.1 kiyohara struct ciphdr *ciph;
265 1.1 kiyohara struct timeval start, end;
266 1.1 kiyohara double rtime;
267 1.1 kiyohara
268 1.1 kiyohara cycle_acc = cycle = 0;
269 1.1 kiyohara
270 1.1 kiyohara fd = open(filename, O_RDONLY);
271 1.2 kiyohara if (fd == -1)
272 1.2 kiyohara err(EX_NOINPUT, filename);
273 1.2 kiyohara
274 1.2 kiyohara pbuf = malloc(DSIZE * TNBUF);
275 1.1 kiyohara bzero(wbuf, sizeof(wbuf));
276 1.1 kiyohara
277 1.1 kiyohara bufreq.rx.nchunk = 0;
278 1.1 kiyohara bufreq.rx.npacket = 0;
279 1.1 kiyohara bufreq.rx.psize = 0;
280 1.1 kiyohara bufreq.tx.nchunk = NCHUNK;
281 1.1 kiyohara bufreq.tx.npacket = NPACKET_T;
282 1.1 kiyohara bufreq.tx.psize = PSIZE;
283 1.2 kiyohara if (ioctl(d, FW_SSTBUF, &bufreq) < 0)
284 1.4 cegger err(EXIT_FAILURE, "ioctl FW_SSTBUF");
285 1.1 kiyohara
286 1.1 kiyohara isoreq.ch = ich & 0x3f;
287 1.1 kiyohara isoreq.tag = (ich >> 6) & 3;
288 1.1 kiyohara
289 1.2 kiyohara if (ioctl(d, FW_STSTREAM, &isoreq) < 0)
290 1.4 cegger err(EXIT_FAILURE, "ioctl FW_STSTREAM");
291 1.1 kiyohara
292 1.1 kiyohara iso_data = 0;
293 1.1 kiyohara pkt = (struct fw_pkt *) &iso_data;
294 1.1 kiyohara pkt->mode.stream.len = DSIZE + sizeof(struct ciphdr);
295 1.1 kiyohara pkt->mode.stream.sy = 0;
296 1.1 kiyohara pkt->mode.stream.tcode = FWTCODE_STREAM;
297 1.1 kiyohara pkt->mode.stream.chtag = ich;
298 1.1 kiyohara iso_empty = iso_data;
299 1.1 kiyohara pkt = (struct fw_pkt *) &iso_empty;
300 1.1 kiyohara pkt->mode.stream.len = sizeof(struct ciphdr);
301 1.1 kiyohara
302 1.1 kiyohara bzero(hdr[0], sizeof(hdr[0]));
303 1.1 kiyohara hdr[0][0] = iso_data;
304 1.1 kiyohara ciph = (struct ciphdr *)&hdr[0][1];
305 1.1 kiyohara ciph->src = 0; /* XXX */
306 1.1 kiyohara ciph->len = 120;
307 1.1 kiyohara ciph->dbc = 0;
308 1.1 kiyohara ciph->eoh1 = 1;
309 1.1 kiyohara ciph->fdf.dv.cyc = 0xffff;
310 1.1 kiyohara
311 1.2 kiyohara for (i = 1; i < TNBUF; i++)
312 1.1 kiyohara bcopy(hdr[0], hdr[i], sizeof(hdr[0]));
313 1.1 kiyohara
314 1.1 kiyohara gettimeofday(&start, NULL);
315 1.1 kiyohara #if DEBUG
316 1.1 kiyohara fprintf(stderr, "%08x %08x %08x\n",
317 1.1 kiyohara htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2]));
318 1.1 kiyohara #endif
319 1.1 kiyohara frames = 0;
320 1.1 kiyohara packets = 0;
321 1.1 kiyohara pad_acc = 0;
322 1.1 kiyohara while (1) {
323 1.1 kiyohara tlen = 0;
324 1.1 kiyohara while (tlen < DSIZE * TNBUF) {
325 1.1 kiyohara len = read(fd, pbuf + tlen, DSIZE * TNBUF - tlen);
326 1.1 kiyohara if (len <= 0) {
327 1.1 kiyohara if (tlen > 0)
328 1.1 kiyohara break;
329 1.1 kiyohara if (len < 0)
330 1.1 kiyohara warn("read");
331 1.1 kiyohara else
332 1.2 kiyohara fprintf(stderr, "\nend of file\n");
333 1.1 kiyohara goto send_end;
334 1.1 kiyohara }
335 1.1 kiyohara tlen += len;
336 1.1 kiyohara }
337 1.1 kiyohara vec = 0;
338 1.1 kiyohara offset = 0;
339 1.1 kiyohara nhdr = 0;
340 1.1 kiyohara next:
341 1.1 kiyohara dv = (struct dvdbc *)(pbuf + offset * DSIZE);
342 1.1 kiyohara #if 0
343 1.1 kiyohara header = (dv->sct == 0 && dv->dseq == 0);
344 1.1 kiyohara #else
345 1.3 xtraeme header = (packets == 0 || packets % npackets[lsystem] == 0);
346 1.1 kiyohara #endif
347 1.1 kiyohara
348 1.1 kiyohara ciph = (struct ciphdr *)&hdr[nhdr][1];
349 1.1 kiyohara if (header) {
350 1.3 xtraeme if (lsystem < 0) {
351 1.3 xtraeme lsystem = ((dv->payload[0] & DV_DSF_12) != 0);
352 1.3 xtraeme printf("%s\n", system_name[lsystem]);
353 1.1 kiyohara cycle = 1;
354 1.3 xtraeme cycle_acc = frame_cycle[lsystem].d * cycle;
355 1.1 kiyohara }
356 1.1 kiyohara fprintf(stderr, "%d", frames % 10);
357 1.1 kiyohara frames ++;
358 1.1 kiyohara if (count > 0 && frames > count)
359 1.1 kiyohara break;
360 1.3 xtraeme if (frames % frame_rate[lsystem] == 0)
361 1.1 kiyohara fprintf(stderr, "\n");
362 1.1 kiyohara fflush(stderr);
363 1.3 xtraeme f_cycle = (cycle_acc / frame_cycle[lsystem].d) & 0xf;
364 1.3 xtraeme f_frac = (cycle_acc % frame_cycle[lsystem].d
365 1.3 xtraeme * CYCLE_FRAC) / frame_cycle[lsystem].d;
366 1.1 kiyohara #if 0
367 1.1 kiyohara ciph->fdf.dv.cyc = htons(f_cycle << 12 | f_frac);
368 1.1 kiyohara #else
369 1.1 kiyohara ciph->fdf.dv.cyc = htons(cycle << 12 | f_frac);
370 1.1 kiyohara #endif
371 1.3 xtraeme cycle_acc += frame_cycle[lsystem].n;
372 1.3 xtraeme cycle_acc %= frame_cycle[lsystem].d * 0x10;
373 1.1 kiyohara
374 1.1 kiyohara } else {
375 1.1 kiyohara ciph->fdf.dv.cyc = 0xffff;
376 1.1 kiyohara }
377 1.1 kiyohara ciph->dbc = packets++ % 256;
378 1.3 xtraeme pad_acc += pad_rate[lsystem].n;
379 1.3 xtraeme if (pad_acc >= pad_rate[lsystem].d) {
380 1.3 xtraeme pad_acc -= pad_rate[lsystem].d;
381 1.1 kiyohara bcopy(hdr[nhdr], hdr[nhdr+1], sizeof(hdr[0]));
382 1.1 kiyohara hdr[nhdr][0] = iso_empty;
383 1.1 kiyohara wbuf[vec].iov_base = (char *)hdr[nhdr];
384 1.1 kiyohara wbuf[vec++].iov_len = sizeof(hdr[0]);
385 1.1 kiyohara nhdr ++;
386 1.1 kiyohara cycle ++;
387 1.1 kiyohara }
388 1.1 kiyohara hdr[nhdr][0] = iso_data;
389 1.1 kiyohara wbuf[vec].iov_base = (char *)hdr[nhdr];
390 1.1 kiyohara wbuf[vec++].iov_len = sizeof(hdr[0]);
391 1.1 kiyohara wbuf[vec].iov_base = (char *)dv;
392 1.1 kiyohara wbuf[vec++].iov_len = DSIZE;
393 1.1 kiyohara nhdr ++;
394 1.1 kiyohara cycle ++;
395 1.1 kiyohara offset ++;
396 1.1 kiyohara if (offset * DSIZE < tlen)
397 1.1 kiyohara goto next;
398 1.1 kiyohara
399 1.1 kiyohara again:
400 1.1 kiyohara len = writev(d, wbuf, vec);
401 1.1 kiyohara if (len < 0) {
402 1.1 kiyohara if (errno == EAGAIN) {
403 1.2 kiyohara fprintf(stderr, "(EAGAIN) - push 'Play'?\n");
404 1.1 kiyohara goto again;
405 1.1 kiyohara }
406 1.4 cegger err(EXIT_FAILURE, "write failed");
407 1.1 kiyohara }
408 1.1 kiyohara }
409 1.1 kiyohara close(fd);
410 1.1 kiyohara fprintf(stderr, "\n");
411 1.1 kiyohara send_end:
412 1.1 kiyohara gettimeofday(&end, NULL);
413 1.2 kiyohara rtime = end.tv_sec - start.tv_sec
414 1.1 kiyohara + (end.tv_usec - start.tv_usec) * 1e-6;
415 1.1 kiyohara fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n",
416 1.1 kiyohara frames, rtime, frames/rtime);
417 1.1 kiyohara }
418