Index: src/ieee1394/utils/dvts/configure.in diff -u src/ieee1394/utils/dvts/configure.in:1.1.1.1 src/ieee1394/utils/dvts/configure.in:1.2 --- src/ieee1394/utils/dvts/configure.in:1.1.1.1 Fri May 9 14:13:22 2003 +++ src/ieee1394/utils/dvts/configure.in Fri May 9 15:06:58 2003 @@ -50,31 +50,17 @@ AC_CANONICAL_HOST case "$host_os" in - freebsd4*) - echo " + OS Type is FreeBSD 4.x" - CFLAGS="-I/usr/src/sys/ -DFREEBSD_4 $CFLAGS" - DVSEND_SRC="ieee1394-freebsd4.c" - DVSEND_LDADD="ieee1394-freebsd4.o" - DVSAVE_SRC="freebsd4.c" - DVSAVE_LDADD="freebsd4.o" - DVRECV_SRC="ieee1394-freebsd4.c write-freebsd4.c" - DVRECV_LDADD="ieee1394-freebsd4.o write-freebsd4.o" - DVPLAY_SRC="ieee1394-freebsd4.c" - DVPLAY_LDADD="ieee1394-freebsd4.o" - DVPLAY_LDFLAGS="" - ;; - - freebsd5*) - echo " + OS Type is FreeBSD 5.x" - CFLAGS="-DFREEBSD_5 $CFLAGS" - DVSEND_SRC="ieee1394-freebsd5.c" - DVSEND_LDADD="ieee1394-freebsd5.o" - DVSAVE_SRC="freebsd5.c" - DVSAVE_LDADD="freebsd5.o" - DVRECV_SRC="ieee1394-freebsd5.c write-freebsd5.c" - DVRECV_LDADD="ieee1394-freebsd5.o write-freebsd5.o" - DVPLAY_SRC="ieee1394-freebsd5.c" - DVPLAY_LDADD="ieee1394-freebsd5.o" + freebsd*) + echo " + OS Type is FreeBSD" + CFLAGS="-I/usr/src/sys/ $CFLAGS" + DVSEND_SRC="ieee1394-freebsd.c" + DVSEND_LDADD="ieee1394-freebsd.o" + DVSAVE_SRC="freebsd.c" + DVSAVE_LDADD="freebsd.o" + DVRECV_SRC="ieee1394-freebsd.c write-freebsd.c" + DVRECV_LDADD="ieee1394-freebsd.o write-freebsd.o" + DVPLAY_SRC="ieee1394-freebsd.c" + DVPLAY_LDADD="ieee1394-freebsd.o" DVPLAY_LDFLAGS="" ;; Index: src/ieee1394/utils/dvts/dvrecv/ieee1394-freebsd.c diff -u /dev/null src/ieee1394/utils/dvts/dvrecv/ieee1394-freebsd.c:1.8 --- /dev/null Tue Aug 5 13:07:28 2003 +++ src/ieee1394/utils/dvts/dvrecv/ieee1394-freebsd.c Tue Aug 5 13:05:12 2003 @@ -0,0 +1,176 @@ +/* + * Copyright (c) 1999-2003 WIDE Project + * All rights reserved. + * + * Author : Akimichi OGAWA (akimichi@sfc.wide.ad.jp) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code MUST retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form MUST reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * MUST display the following acknowledgement: + * This product includes software developed by Akimichi OGAWA. + * 4. The name of the author MAY NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * +*/ + +/* + * Copyright (c) 2003 + * Hidetoshi Shimokawa. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Hidetoshi Shimokawa. + * + * 4. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: ieee1394-freebsd.c,v 1.8 2003/08/05 04:05:12 simokawa Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include "param.h" +#include "ieee1394-struct.h" + +int cycle_offset=0; + +static void +tune_timing(int dummy) +{ + cycle_offset = 3; +} + +int +prepare_ieee1394 (struct dvrecv_param *dvrecv_param) +{ + char devname[256]; + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + int i, fd = -1; + + memset(&isoreq, 0, sizeof(isoreq)); + memset(&bufreq, 0, sizeof(bufreq)); + + if (dvrecv_param->ieee1394dv.devname[0] == 0) + strlcpy(dvrecv_param->ieee1394dv.devname, "/dev/fw0", + sizeof(dvrecv_param->ieee1394dv.devname)); + + fd = open(dvrecv_param->ieee1394dv.devname, O_RDWR); + if (fd < 0) { +#define MAXDEV 8 + for (i = 0; i < MAXDEV; i ++) { + snprintf(devname, sizeof(devname), "%s.%d", + dvrecv_param->ieee1394dv.devname, i); + if ((fd = open(devname, O_RDWR)) >= 0) + break; + } + if (fd < 0) { + perror("ieee1394 open"); + return(fd); + } + strlcpy(dvrecv_param->ieee1394dv.devname, devname, + sizeof(dvrecv_param->ieee1394dv.devname)); + } + + bufreq.tx.nchunk = 8; + bufreq.tx.npacket = 255; + bufreq.tx.psize = 512; + + if (ioctl(fd, FW_SSTBUF, &bufreq) < 0) { + perror("ioctl FW_SSTBUF"); + return(-1); + } + + isoreq.ch = dvrecv_param->ieee1394dv.channel; +#if 0 + isoreq.tag = (dvrecv_param->ieee1394dv.channel >> 6) & 3; +#else + isoreq.tag = 1; +#endif + printf("%d, %d\n", isoreq.ch, isoreq.tag); + if (ioctl(fd, FW_STSTREAM, &isoreq) < 0) { + perror("ioctl FW_STSTREAM"); + return(-1); + } + + printf("IEEE1394 dev : %s\n", dvrecv_param->ieee1394dv.devname); + + dvrecv_param->ieee1394dv.fd = fd; + + signal(SIGUSR1, tune_timing); + + return(1); +} + +#if 0 +int +freebsd_write_frame_to_ieee1394 (struct dvrecv_param *dvrecv_param, + unsigned long *buf, + int len) +{ +} +#endif + +void +stop_ieee1394_output (struct dvrecv_param *dvrecv_param) +{ +} Index: src/ieee1394/utils/dvts/dvrecv/ieee1394-struct.h diff -u src/ieee1394/utils/dvts/dvrecv/ieee1394-struct.h:1.1.1.1 src/ieee1394/utils/dvts/dvrecv/ieee1394-struct.h:1.5 --- src/ieee1394/utils/dvts/dvrecv/ieee1394-struct.h:1.1.1.1 Fri May 9 14:13:23 2003 +++ src/ieee1394/utils/dvts/dvrecv/ieee1394-struct.h Sun May 11 12:21:04 2003 @@ -35,16 +35,13 @@ #ifndef _DVRECV_IEEE1394_STRUCT_H_ #define _DVRECV_IEEE1394_STRUCT_H_ -#ifdef FREEBSD_4 +#ifdef __FreeBSD__ struct ieee1394dv { int channel; - char *ifname; - int fd; - int sync; - int frac; - int mod; + char devname[256]; + int fd; }; -#endif /* FREEBSD_4 */ +#endif /* __FreeBSD__ */ #ifdef MACOS_X #include Index: src/ieee1394/utils/dvts/dvrecv/info.c diff -u src/ieee1394/utils/dvts/dvrecv/info.c:1.1.1.1 src/ieee1394/utils/dvts/dvrecv/info.c:1.2 --- src/ieee1394/utils/dvts/dvrecv/info.c:1.1.1.1 Fri May 9 14:13:23 2003 +++ src/ieee1394/utils/dvts/dvrecv/info.c Fri May 9 15:18:15 2003 @@ -55,10 +55,10 @@ printf(" example, [-M fxp0]\n"); printf("-P port : RTP port number \"port\"\n"); printf(" example, [-P 8100]\n"); -#ifdef FREEBSD_4 +#ifdef __FreeBSD__ printf("-D dev : use device \"dev\"\n"); - printf(" example, [-D /dev/dv0]\n"); -#endif /* FREEBSD_4 */ + printf(" example, [-D /dev/fw0]\n"); +#endif /* __FreeBSD__ */ printf("-L : show packet loss\n"); printf("-R : don't use RTCP\n"); printf("-l number : show packet loss, specify display granularity\n"); Index: src/ieee1394/utils/dvts/dvrecv/main.c diff -u src/ieee1394/utils/dvts/dvrecv/main.c:1.1.1.1 src/ieee1394/utils/dvts/dvrecv/main.c:1.5 --- src/ieee1394/utils/dvts/dvrecv/main.c:1.1.1.1 Fri May 9 14:13:23 2003 +++ src/ieee1394/utils/dvts/dvrecv/main.c Sun May 11 12:21:04 2003 @@ -89,15 +89,9 @@ dvrecv_param.ieee1394dv.channel = 63; -#ifdef FREEBSD_4 - dvrecv_param.ieee1394dv.ifname = "/dev/dv0"; -#ifdef CANOPUS_MC - dvrecv_param.ieee1394dv.frac = 15; -#else /* CANOPUS_MC */ - dvrecv_param.ieee1394dv.frac = 17; -#endif /* CANOPUS_MC */ - dvrecv_param.ieee1394dv.mod = 0; -#endif /* FREEBSD_4 */ +#ifdef __FreeBSD__ + dvrecv_param.ieee1394dv.devname[0] = 0; +#endif /* __FreeBSD__ */ #ifdef LINUX dvrecv_param.ieee1394dv.devname = "/dev/dv1394"; @@ -187,11 +181,12 @@ } break; -#ifdef FREEBSD_4 +#ifdef __FreeBSD__ case 'D': - dvrecv_param.ieee1394dv.ifname = optarg; + strncpy(dvrecv_param.ieee1394dv.devname, optarg, + sizeof(dvrecv_param.ieee1394dv.devname)); break; -#endif /* FREEBSD_4 */ +#endif /* __FreeBSD__ */ case 'L': dvrecv_param.flags |= SHOW_PACKETLOSS; Index: src/ieee1394/utils/dvts/dvrecv/write-freebsd.c diff -u /dev/null src/ieee1394/utils/dvts/dvrecv/write-freebsd.c:1.10 --- /dev/null Tue Aug 5 13:07:28 2003 +++ src/ieee1394/utils/dvts/dvrecv/write-freebsd.c Sat May 10 22:26:06 2003 @@ -0,0 +1,284 @@ +/* + * Copyright (c) 1999-2003 WIDE Project + * All rights reserved. + * + * Author : Akimichi OGAWA (akimichi@sfc.wide.ad.jp) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code MUST retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form MUST reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * MUST display the following acknowledgement: + * This product includes software developed by Akimichi OGAWA. + * 4. The name of the author MAY NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * +*/ + +/* + * Copyright (c) 2003 + * Hidetoshi Shimokawa. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Hidetoshi Shimokawa. + * + * 4. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: write-freebsd.c,v 1.10 2003/05/10 13:26:06 simokawa Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include "write.h" +#include "ieee1394.h" +#include "shm.h" + +/* blocks used for [u_int32_t outbuf] */ +#define NBLOCKS 400 + +#define USE_SILENT_AUDIO 0x00000001 + +struct frac { + int n,d; +}; + +struct frac frame_cycle[2] = { + {8000*100, 2997}, /* NTSC 8000 cycle / 29.97 Hz */ + {320, 1}, /* PAL 8000 cycle / 25 Hz */ +}; +struct frac pad_rate[2] = { + {203, 2997}, /* = (8000 - 29.97 * 250)/(29.97 * 250) */ + {1, 15}, /* = (8000 - 25 * 300)/(25 * 300) */ +}; +#define CYCLE_FRAC 0xc00 + + +struct audio_buf { + struct dv_difblock dbn[9]; +}; + +int cycle_offset; + +void +ieee1394dv_write_loop (struct dvrecv_param *dvrecv_param) +{ + u_long silent_audio[dvrecv_param->maxdifseq*9*80/4]; + u_long silent_audio_flag = 0; + u_long same_audio_count = 0; + + u_int32_t outbuf[3 * NBLOCKS]; + struct iovec vec[2 * NBLOCKS]; + u_char seq = 0; + u_char dseq, sct, dbn; + int i, nvec, audio_off, audio_dbn; + int ieee1394_pkt_count = 0; + int count; + u_int32_t system, pad_acc, cycle_acc, cycle, f_cycle, f_frac, packets; + struct ciphdr *ciph; + struct dv1394_pkts *dvframe; + struct audio_buf *audio_seq; + + /* check video system */ + if (dvrecv_param->format == DV_FORMAT_NTSC) + system = 0; + else if (dvrecv_param->format == DV_FORMAT_PAL) + system = 1; + else + return; + + /* prepare DV DIF block without any sound */ + memset(silent_audio, 0, sizeof(silent_audio)); + + sct = SCT_AUDIO; + for (dseq=0; dseqmaxdifseq; dseq++) { + for (dbn=0; dbn<9; dbn++) { + silent_audio[(dseq*9*80 + dbn*80)/4] = htonl((sct & 0x7) << 29 | (seq & 0xf) << 24 | (dseq & 0xf) << 20 | (dbn & 0xff) << 8); + } + } + + memset(outbuf, 0, sizeof(outbuf)); + + for (i=0; ivideo_framebuf->next->framebuf->lock == DVFRAME_DATA_READY) { + dvrecv_param->video_framebuf = dvrecv_param->video_framebuf->next; + dvrecv_param->video_framebuf->framebuf->lock = DVFRAME_WRITING_IEEE1394; + } + + if (dvrecv_param->audio_framebuf->next->framebuf->lock == DVFRAME_DATA_READY) { + same_audio_count = 0; + silent_audio_flag = 0; + dvrecv_param->audio_framebuf = dvrecv_param->audio_framebuf->next; + dvrecv_param->audio_framebuf->framebuf->lock = DVFRAME_WRITING_IEEE1394; + } else { + same_audio_count++; + if (same_audio_count > 5) { + if (same_audio_count == 6) { + printf("MUTE AUDIO\n"); + } + same_audio_count = 10; + silent_audio_flag = USE_SILENT_AUDIO; + } + } + + dvframe = &dvrecv_param->video_framebuf->framebuf->dvframe; + if (silent_audio_flag) + audio_seq = (struct audio_buf *)&silent_audio[0]; + else + audio_seq = (struct audio_buf *) + &dvrecv_param->audio_framebuf->framebuf->dseq[0].dbn[0]; + + for (dseq=0; dseqmaxdifseq; dseq++) { + audio_off = 6; + audio_dbn = 0; + for (count=0; count= pad_rate[system].d) { + pad_acc -= pad_rate[system].d; + outbuf[ieee1394_pkt_count*3] = 8 << 16 | 0x00007fa0; + ciph = (struct ciphdr *)&outbuf[ieee1394_pkt_count*3 + 1]; + ciph->dbc = packets % 256; + if (ieee1394_pkt_count == 0) + ciph->fdf.dv.cyc = htons(cycle << 12 | f_frac); + else + ciph->fdf.dv.cyc = htons(0xffff); + vec[nvec].iov_base = (char *)&outbuf[ieee1394_pkt_count*3]; + vec[nvec].iov_len = 12; + nvec ++; + ieee1394_pkt_count++; + cycle ++; + } + + outbuf[ieee1394_pkt_count*3] = 488 << 16 | 0x00007fa0; + ciph = (struct ciphdr *)&outbuf[ieee1394_pkt_count*3 + 1]; + ciph->dbc = packets % 256; + if (ieee1394_pkt_count == 0) + ciph->fdf.dv.cyc = htons(cycle << 12 | f_frac); + else + ciph->fdf.dv.cyc = htons(0xffff); + vec[nvec].iov_base = (char *)&outbuf[ieee1394_pkt_count*3]; + vec[nvec].iov_len = 12; + nvec ++; + /* audio block is in (6 + 16*i)th block. */ + if (audio_off < 6) { + if (audio_off != 0) { + vec[nvec].iov_base = (char *)&dvframe->pkt[dseq][count][0]; + vec[nvec].iov_len = 80 * audio_off; + nvec ++; + } + vec[nvec].iov_base = (char *)&audio_seq[dseq].dbn[audio_dbn++]; + vec[nvec].iov_len = 80; + if (audio_off != 5) { + nvec ++; + vec[nvec].iov_base = (char *) + &dvframe->pkt[dseq][count][80/4*(audio_off+1)]; + vec[nvec].iov_len = 80 * (5 - audio_off); + } + audio_off += 16; + } else { + vec[nvec].iov_base = (char *)&dvframe->pkt[dseq][count][0]; + vec[nvec].iov_len = 80*6; + } + audio_off -= 6; + nvec ++; + ieee1394_pkt_count++; + cycle ++; + } /* end of for(count=0; countmaxdifseq; dseq++) */ + + if (writev(dvrecv_param->ieee1394dv.fd, vec, nvec) < 0) { + warn("writev error\n"); + break; + } + + dvrecv_param->video_framebuf->framebuf->lock = DVFRAME_READY; + dvrecv_param->audio_framebuf->framebuf->lock = DVFRAME_READY; + } +} Index: src/ieee1394/utils/dvts/dvsend/ieee1394-freebsd.c diff -u /dev/null src/ieee1394/utils/dvts/dvsend/ieee1394-freebsd.c:1.11 --- /dev/null Tue Aug 5 13:07:28 2003 +++ src/ieee1394/utils/dvts/dvsend/ieee1394-freebsd.c Tue Aug 5 12:59:11 2003 @@ -0,0 +1,231 @@ +/* + * Copyright (c) 1999-2003 WIDE Project + * All rights reserved. + * + * Author : Akimichi OGAWA (akimichi@sfc.wide.ad.jp) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code MUST retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form MUST reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * MUST display the following acknowledgement: + * This product includes software developed by Akimichi OGAWA. + * 4. The name of the author MAY NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * +*/ + +/* + * Copyright (c) 2003 + * Hidetoshi Shimokawa. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Hidetoshi Shimokawa. + * + * 4. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: ieee1394-freebsd.c,v 1.11 2003/08/05 03:59:11 simokawa Exp $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "param.h" +#include "ieee1394.h" +#include "flags.h" +#include "rtp.h" +#include "rtcp.h" + +#define RTCP_SR_INTERVAL 3 +#define NPACKETS 128 + +int +prepare_ieee1394 (struct dvsend_param *dvsend_param) +{ + char devname[256]; + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + int i, fd = -1; + + memset(&isoreq, 0, sizeof(isoreq)); + memset(&bufreq, 0, sizeof(bufreq)); + + if (dvsend_param->ieee1394dv.devname[0] == 0) + strlcpy(dvsend_param->ieee1394dv.devname, "/dev/fw0", + sizeof(dvsend_param->ieee1394dv.devname)); + + fd = open(dvsend_param->ieee1394dv.devname, O_RDWR); + if (fd < 0) { +#define MAXDEV 8 + for (i = 0; i < MAXDEV; i ++) { + snprintf(devname, sizeof(devname), "%s.%d", + dvsend_param->ieee1394dv.devname, i); + if ((fd = open(devname, O_RDWR)) >= 0) + break; + } + if (fd < 0) { + perror("ieee1394 open"); + return(fd); + } + strlcpy(dvsend_param->ieee1394dv.devname, devname, + sizeof(dvsend_param->ieee1394dv.devname)); + } + + bufreq.rx.nchunk = 4; + bufreq.rx.npacket = NPACKETS; + bufreq.rx.psize = 512; + + if (ioctl(fd, FW_SSTBUF, &bufreq) < 0) { + perror("ioctl FW_SSTBUF"); + return(-1); + } + + isoreq.ch = dvsend_param->ieee1394dv.channel; +#if 0 + isoreq.tag = (dvsend_param->ieee1394dv.channel >> 6) & 3; +#else + isoreq.tag = 1; +#endif + if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0) { + perror("ioctl FW_SRSTREAM"); + return(-1); + } + + printf("IEEE1394 dev : %s\n", dvsend_param->ieee1394dv.devname); + + dvsend_param->ieee1394dv.fd = fd; + + return(1); +} + +int +main_loop (struct dvsend_param *dvsend_param) +{ + /* length of data received from IEEE1394 device */ + int len; + + /* buffer for receiving data from IEEE1394 device */ + char recvbuf[512 * NPACKETS], *ptr; + + /* IEEE1394 packet */ + struct fw_pkt *pkt; + + /* how many times received from IEEE1394 */ + u_long readcount = 0; + + /* to calculate the RTCP interval */ + struct timeval tv, tv_prev; + + int i; + + /*************************/ + /* program starts here */ + /*************************/ + + gettimeofday(&tv, NULL); + gettimeofday(&tv_prev, NULL); + +/* aprox. per 1000 packets */ +#define POLLCYCLE (1000 / NPACKETS) + + while (1) { + /* RTCP */ + readcount++; + /* just do RTCP process sometimes */ + if ((dvsend_param->flags & USE_RTCP) && (readcount % POLLCYCLE) == 0) { + if (gettimeofday(&tv, NULL) < 0) { + printf("gettimeofday failed\n"); + break; + } + if ((tv.tv_sec - tv_prev.tv_sec) > RTCP_SR_INTERVAL) { + send_rtcp_sr(dvsend_param); + memcpy(&tv_prev, &tv, sizeof(tv_prev)); + } + + /* process rtcp input */ + process_rtcp(dvsend_param); + } + + /* receive packet from IEEE1394 device */ + while ((len = read(dvsend_param->ieee1394dv.fd, recvbuf, 512 * NPACKETS)) + < 1) { + if (errno != EAGAIN) { + printf("ieee1394 recv len : %d\n", len); + return(-1); + } + printf("(EAGAIN)"); + fflush(stdout); + } + + /* process DIF blocks */ + ptr = &recvbuf[0]; + while (len > 0) { + pkt = (struct fw_pkt *)ptr; + ptr += sizeof(struct fw_isohdr); + if (pkt->mode.stream.len > sizeof(struct ciphdr)) + for (i = 0; i < 6; i ++) + proc_dvdif(dvsend_param, (u_int32_t *) + (ptr + sizeof(struct ciphdr) + 80 * i)); + ptr += pkt->mode.stream.len; + len -= sizeof(struct fw_isohdr) + pkt->mode.stream.len; + } + } + + return(-1); +} Index: src/ieee1394/utils/dvts/dvsend/ieee1394-struct.h diff -u src/ieee1394/utils/dvts/dvsend/ieee1394-struct.h:1.1.1.1 src/ieee1394/utils/dvts/dvsend/ieee1394-struct.h:1.3 --- src/ieee1394/utils/dvts/dvsend/ieee1394-struct.h:1.1.1.1 Fri May 9 14:13:24 2003 +++ src/ieee1394/utils/dvts/dvsend/ieee1394-struct.h Sun May 11 12:08:10 2003 @@ -44,14 +44,6 @@ /* IEEE1394 isochronous channel */ int channel; -#ifdef FREEBSD_4 - /* for receiving data from IEEE1394 device */ - int fd; - - /* IEEE1394 interface name */ - char *ifname; -#endif /* FREEBSD_4 */ - #ifdef MACOS_X #endif /* MACOS_X */ @@ -69,9 +61,10 @@ int fd1394; #endif /* LINUX */ -#ifdef FREEBSD_5 - char *devname; -#endif /* FREEBSD_5 */ +#ifdef __FreeBSD__ + char devname[256]; + int fd; +#endif /* __FreeBSD__ */ }; #endif /* _DVSEND_IEEE1394_STRUCT_H_ */ Index: src/ieee1394/utils/dvts/dvsend/info.c diff -u src/ieee1394/utils/dvts/dvsend/info.c:1.1.1.1 src/ieee1394/utils/dvts/dvsend/info.c:1.3 --- src/ieee1394/utils/dvts/dvsend/info.c:1.1.1.1 Fri May 9 14:13:24 2003 +++ src/ieee1394/utils/dvts/dvsend/info.c Mon May 12 19:29:35 2003 @@ -52,10 +52,10 @@ printf("-h hostname : sendto host \"hostname\"\n"); printf("-f rate : send full frame by 1/rate\n"); -#ifdef FREEBSD_4 - printf("-I 1394if : use interface \"1394if\"\n"); - printf(" example, [ -I ohci0 ]\n"); -#endif /* FREEBSD_4 */ +#ifdef __FreeBSD__ + printf("-D 1394dev : use device \"1394dev\"\n"); + printf(" example, [ -D /dev/fw0 ]\n"); +#endif /* __FreeBSD__ */ #ifdef NETBSD printf("-D 1394dev : use device \"1394dev\"\n"); @@ -69,6 +69,7 @@ printf("-s number : number of DIF blocks included in one packet\n"); printf(" packet length will be [IPhdr+UDPhdr+RTPhdr+80*number]\n"); printf("-N : do NOT send video\n"); + printf("-n : do NOT send audio\n"); printf("-d port : send audio and video in different stream\n"); printf(" send audio usind port \"port\"\n"); printf("-L : show packet loss state of the receivers\n"); Index: src/ieee1394/utils/dvts/dvsend/main.c diff -u src/ieee1394/utils/dvts/dvsend/main.c:1.1.1.1 src/ieee1394/utils/dvts/dvsend/main.c:1.4 --- src/ieee1394/utils/dvts/dvsend/main.c:1.1.1.1 Fri May 9 14:13:24 2003 +++ src/ieee1394/utils/dvts/dvsend/main.c Mon May 12 13:42:02 2003 @@ -113,10 +113,10 @@ /* IEEE1394 isochronous channel */ dvsend_param.ieee1394dv.channel = 0x3f; -#ifdef FREEBSD_4 - /* IEEE1394 interface name (DEFAULT value will be ohci0) */ - dvsend_param.ieee1394dv.ifname = "ohci0"; -#endif /* FREEBSD_4 */ +#ifdef __FreeBSD__ + /* IEEE1394 device name (DEFAULT value will be /dev/fw*) */ + dvsend_param.ieee1394dv.devname[0] = 0; +#endif /* __FreeBSD__ */ #ifdef NETBSD /* IEEE1394 interface name (DEFAULT value will be /dev/fw0) */ @@ -143,7 +143,7 @@ /*---------------------*/ /* getting options */ - while ((op = getopt(argc, argv, "vh:64NI:P:s:M:m:t:d:f:LHD:C:Rr:p")) > 0) { + while ((op = getopt(argc, argv, "vh:64NnI:P:s:M:m:t:d:f:LHD:C:Rr:p")) > 0) { switch (op) { case 'v': show_version(); @@ -168,11 +168,16 @@ dvsend_param.flags |= NO_VIDEO_STREAM; break; -#ifdef FREEBSD_4 - case 'I': - dvsend_param.ieee1394dv.ifname = optarg; + case 'n': + dvsend_param.flags |= NO_AUDIO_STREAM; break; -#endif /* FREEBSD_4 */ + +#ifdef __FreeBSD__ + case 'D': + strncpy(&dvsend_param.ieee1394dv.devname[0], optarg, + sizeof(dvsend_param.ieee1394dv.devname)); + break; +#endif /* __FreeBSD__ */ #ifdef LINUX case 'I': Index: src/ieee1394/utils/dvts/dvsend/udp.c diff -u src/ieee1394/utils/dvts/dvsend/udp.c:1.1.1.1 src/ieee1394/utils/dvts/dvsend/udp.c:1.2 --- src/ieee1394/utils/dvts/dvsend/udp.c:1.1.1.1 Fri May 9 14:13:24 2003 +++ src/ieee1394/utils/dvts/dvsend/udp.c Fri May 9 21:33:46 2003 @@ -352,6 +352,7 @@ if (dvsend_param->rtcp_recv_list == NULL) { new = (struct rtcp_recv_obj *)malloc(sizeof(struct rtcp_recv_obj)); + memset(new, 0, sizeof(struct rtcp_recv_obj)); memcpy(&new->s_addr, &rtcp_out->s_addr, sizeof(new->s_addr)); new->port = rtcp_out->port;