/* * 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); }