From owner-freebsd-firewire@FreeBSD.ORG Mon Jan 31 10:41:51 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 82A9216A4CE for ; Mon, 31 Jan 2005 10:41:51 +0000 (GMT) Received: from ithil.ics.muni.cz (ns.muni.cz [147.251.4.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 40F2343D5A for ; Mon, 31 Jan 2005 10:41:50 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (kloboucek.fi.muni.cz [147.251.54.33]) (user=hopet@META mech=LOGIN bits=0) by ithil.ics.muni.cz (8.12.1/8.12.1) with ESMTP id j0VAflXQ000821 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Mon, 31 Jan 2005 11:41:47 +0100 From: "Petr Holub" To: Date: Mon, 31 Jan 2005 11:41:48 +0100 Message-ID: <001201c50781$774eb670$2603fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Muni-Spam-TestIP: 147.251.54.33 X-Muni-Virus-Test: Clean cc: Hidetoshi Shimokawa Subject: fwcontrol patch for MPEG TS X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Jan 2005 10:41:51 -0000 Hi guys, below is very rudimentary patch for fwcontrol to be able to receive high bandwidth MPEG TS stream using -M filname flag. I've tested it with SONY HDR-FX1E camera (a HDV camera) and my notebook. Patch is against 5.3-RELEASE. Cheers, Petr ================================================================ Petr Holub CESNET z.s.p.o. Supercomputing Center Brno Zikova 4 Institute of Compt. Science 162 00 Praha 6, CZ Masaryk University Czech Republic Botanicka 68a, 60200 Brno, CZ e-mail: Petr.Holub@cesnet.cz phone: +420-549493944 fax: +420-541212747 e-mail: hopet@ics.muni.cz Index: fwcontrol/Makefile =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/Makefile,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 Makefile --- fwcontrol/Makefile 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/Makefile 30 Jan 2005 23:20:38 -0000 @@ -1,7 +1,7 @@ # $FreeBSD: src/usr.sbin/fwcontrol/Makefile,v 1.4 2003/04/30 03:39:25 simokawa Exp $ PROG= fwcontrol -SRCS= fwcontrol.c fwcrom.c fwdv.c +SRCS= fwcontrol.c fwcrom.c fwdv.c fwmpegts.c MAN= fwcontrol.8 .PATH: ${.CURDIR}/../../sys/dev/firewire Index: fwcontrol/fwcontrol.8 =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.8,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- fwcontrol/fwcontrol.8 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.8 30 Jan 2005 23:14:07 -0000 1.2 @@ -102,6 +102,8 @@ Ports Collection. .It Fl S Ar filename Send a DV file as isochronous stream. +.It Fl M Ar filename +Receive an MPEG TS stream and dump it to a file from the isochronous stream. .El .Sh EXAMPLES Each DV frame has a fixed size and it is easy to edit the frame order. @@ -144,3 +146,5 @@ .An Hidetoshi Shimokawa Aq simokawa@FreeBSD.org .Sh BUGS This utility is still under development and provided for debugging purposes. +MPEG TS receiving support is very experimental and supports only high bandwidth +streams (fn=3). Index: fwcontrol/fwcontrol.c =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 fwcontrol.c --- fwcontrol/fwcontrol.c 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.c 31 Jan 2005 10:14:13 -0000 @@ -54,6 +54,7 @@ extern int dvrecv(int, char *, char, int); extern int dvsend(int, char *, char, int); +extern int mpegtsrecv(int, char *, char, int); static void usage(void) @@ -73,7 +74,8 @@ "\t-d: hex dump of configuration ROM\n" "\t-l: load and parse hex dump file of configuration ROM\n" "\t-R: Receive DV stream\n" - "\t-S: Send DV stream\n"); + "\t-S: Send DV stream\n" + "\t-M: Receive MPEG TS stream\n"); exit(0); } @@ -609,7 +611,7 @@ list_dev(fd); } - while ((ch = getopt(argc, argv, "g:o:s:b:prtc:d:l:u:R:S:")) != -1) + while ((ch = getopt(argc, argv, "g:o:s:b:prtc:d:l:u:R:S:M:")) != -1) switch(ch) { case 'b': tmp = strtol(optarg, NULL, 0); @@ -681,6 +683,10 @@ case 'S': open_dev(&fd, devbase); dvsend(fd, optarg, TAG | CHANNEL, -1); + break; + case 'M': + open_dev(&fd, devbase); + mpegtsrecv(fd, optarg, TAG | CHANNEL, -1); break; default: usage(); Index: fwcontrol/fwmpegts.c =================================================================== RCS file: fwcontrol/fwmpegts.c diff -N fwcontrol/fwmpegts.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ fwcontrol/fwmpegts.c 31 Jan 2005 10:14:27 -0000 1.4 @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2003 + * Petr Holub. 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. + * + * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.5 2003/04/17 03:38:03 simokawa Exp $ + */ +#include +#include +#include +#include +#include + +#if __FreeBSD_version >= 500000 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define DEBUG 0 + +typedef uint8_t mpeg_ts_pld[188]; + +struct mpeg_pldt { +#if BYTE_ORDER == BIG_ENDIAN + uint32_t :7, + c_count:13, + c_offset:12; +#else + uint32_t c_offset:12, + c_count:13, + :7; +#endif + mpeg_ts_pld payload; +}; + + +#define NCHUNK 8 +#define PSIZE 596 +#define NPACKET_R 4096 +#define RBUFSIZE (PSIZE * NPACKET_R) + +int +mpegtsrecv(int d, char *filename, char ich, int count) +{ + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + struct ciphdr *ciph; + struct fw_pkt *pkt; + struct mpeg_pldt *pld; + int pkt_size; + char *buf; + u_int32_t *ptr; + int len, tlen, fd, k, m, startwr = 0; + + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); + buf = (char *)malloc(RBUFSIZE); + + bufreq.rx.nchunk = NCHUNK; + bufreq.rx.npacket = NPACKET_R; + bufreq.rx.psize = PSIZE; + bufreq.tx.nchunk = 0; + bufreq.tx.npacket = 0; + bufreq.tx.psize = 0; + if (ioctl(d, FW_SSTBUF, &bufreq) < 0) { + err(1, "ioctl"); + } + + isoreq.ch = ich & 0x3f; + isoreq.tag = (ich >> 6) & 3; + + if( ioctl(d, FW_SRSTREAM, &isoreq) < 0) + err(1, "ioctl"); + + k = m = 0; + while (count <= 0 || k <= count) { + len = tlen = read(d, buf, RBUFSIZE); +#if DEBUG + fprintf(stderr, "Read %d bytes.\n", len); +#endif + if (len < 0) { + if (errno == EAGAIN) { + fprintf(stderr, "(EAGAIN)\n"); + fflush(stderr); + if (len <= 0) + continue; + } else + err(1, "read failed"); + } + ptr = (u_int32_t *) buf; + + do { + pkt = (struct fw_pkt *) ptr; +#if DEBUG + fprintf(stderr, "%08x %08x %08x %08x\n", + htonl(ptr[0]), htonl(ptr[1]), + htonl(ptr[2]), htonl(ptr[3])); +#endif + /* there is no CRC in the 1394 header */ + ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ + if (ciph->fmt != CIP_FMT_MPEG) + errx(1, "unknown format 0x%x", ciph->fmt); + if (ciph->fn != 3) + errx(1, "unsupported MPEG TS stream, fn=%d (only fn=3 is supported)", ciph->fn); + ptr = (u_int32_t *) (ciph + 1); /* skip cip header */ + + if (pkt->mode.stream.len <= sizeof(struct ciphdr)) { + /* no payload */ + /* tlen needs to be decremented before end of the loop */ + goto next; + } +#if DEBUG + else { + fprintf(stderr, "Packet net payload length (IEEE1394 header): %d\n", pkt->mode.stream.len - sizeof(struct ciphdr)); + fprintf(stderr, "Data block size (CIP header): %d [q], %d [B]\n", ciph->len, ciph->len * 4); + fprintf(stderr, "Data fraction number (CIP header): %d => DBC increments with %d\n", ciph->fn, (1<fn) ); + fprintf(stderr, "QCP (CIP header): %d\n", ciph->qpc ); + fprintf(stderr, "DBC counter (CIP header): %d\n", ciph->dbc ); + fprintf(stderr, "MPEG payload type size: %d\n", sizeof(struct mpeg_pldt)); + } +#endif + + if ( ciph->dbc % (1<fn) == 0) { + startwr = 1; + } + for (pld = (struct mpeg_pldt *)ptr; + (int)pld < (int)((char *)ptr + pkt->mode.stream.len - sizeof(struct ciphdr) ); + pld++) { + if(startwr == 1) + write(fd, pld->payload, sizeof(pld->payload)); + } + +next: + /* CRCs are removed from both header and trailer + so that only 4 bytes of 1394 header remains */ + pkt_size = pkt->mode.stream.len + 4; + ptr = (u_int32_t *) ((int)pkt + pkt_size); +#if DEBUG + fprintf(stderr, "Packet size is %d.\n", pkt_size); + fprintf(stderr, "tlen = %d.\n\n", tlen); +#endif + tlen -= pkt_size; + } while (tlen > 0); +#if DEBUG + fprintf(stderr, "\nReading a data from firewire.\n"); +#endif + + } + close(fd); + fprintf(stderr, "\n"); + return 0; +} + From owner-freebsd-firewire@FreeBSD.ORG Tue Feb 1 04:47:17 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9CA4A16A4CE for ; Tue, 1 Feb 2005 04:47:17 +0000 (GMT) Received: from ybbsmtp14.mail.mci.yahoo.co.jp (ybbsmtp14.mail.mci.yahoo.co.jp [210.80.241.188]) by mx1.FreeBSD.org (Postfix) with SMTP id E821B43D45 for ; Tue, 1 Feb 2005 04:47:16 +0000 (GMT) (envelope-from simokawa@FreeBSD.org) Received: from unknown (HELO tora.nunu.org) (nunuorg@219.3.182.35 with login) by ybbsmtp14.mail.mci.yahoo.co.jp with SMTP; 1 Feb 2005 04:47:15 -0000 X-Apparently-From: Received: from tora.nunu.org (tora.nunu.org [192.168.1.2]) by tora.nunu.org (Postfix) with ESMTP id AB98052CAF; Mon, 31 Jan 2005 21:52:13 +0900 (JST) Date: Mon, 31 Jan 2005 21:52:11 +0900 Message-ID: <87d5vlrcas.wl@tora.nunu.org> From: Hidetoshi Shimokawa To: "Petr Holub" In-Reply-To: <001201c50781$774eb670$2603fb93@KLOBOUCEK> References: <001201c50781$774eb670$2603fb93@KLOBOUCEK> User-Agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.6 MULE XEmacs/21.4 (patch 14) (Reasonable Discussion) (i386--freebsd) MIME-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII cc: freebsd-firewire@freebsd.org Subject: Re: fwcontrol patch for MPEG TS X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 04:47:17 -0000 At Mon, 31 Jan 2005 11:41:48 +0100, Petr Holub wrote: > below is very rudimentary patch for fwcontrol to be able to receive > high bandwidth MPEG TS stream using > -M filname > flag. I've tested it with SONY HDR-FX1E camera (a HDV camera) and > my notebook. Patch is against 5.3-RELEASE. > > Cheers, > Petr Thank you very much for your work! I'll take a look. /\ Hidetoshi Shimokawa \/ simokawa@FreeBSD.org From owner-freebsd-firewire@FreeBSD.ORG Tue Feb 1 08:59:53 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5868916A4CF; Tue, 1 Feb 2005 08:59:53 +0000 (GMT) Received: from ithil.ics.muni.cz (ithil.ics.muni.cz [147.251.4.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 95CAC43D41; Tue, 1 Feb 2005 08:59:52 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (kloboucek.ics.muni.cz [147.251.3.38]) (user=hopet@META mech=LOGIN bits=0) by ithil.ics.muni.cz (8.12.1/8.12.1) with ESMTP id j118xpXQ014991 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Tue, 1 Feb 2005 09:59:51 +0100 From: "Petr Holub" To: "Hidetoshi Shimokawa" Date: Tue, 1 Feb 2005 09:59:53 +0100 Message-ID: <003f01c5083c$64d444e0$2603fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 In-Reply-To: <87d5vlrcas.wl@tora.nunu.org> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Muni-Spam-TestIP: 147.251.3.38 X-Muni-Virus-Test: Clean cc: freebsd-firewire@FreeBSD.org Subject: RE: fwcontrol patch for MPEG TS X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 08:59:53 -0000 I'm thinking about modifying it once again to do format autodetection and then use appropriate receiving function via -R flag. Do you think it's worth doing it like this? Cheers, Petr From owner-freebsd-firewire@FreeBSD.ORG Tue Feb 1 11:53:03 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC7F816A4CE for ; Tue, 1 Feb 2005 11:53:03 +0000 (GMT) Received: from tora.nunu.org (YahooBB219003182035.bbtec.net [219.3.182.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4936843D2D for ; Tue, 1 Feb 2005 11:53:03 +0000 (GMT) (envelope-from simokawa@FreeBSD.org) Received: from tora.nunu.org (tora.nunu.org [192.168.1.2]) by tora.nunu.org (Postfix) with ESMTP id C0CBD52BAC; Tue, 1 Feb 2005 20:53:01 +0900 (JST) Date: Tue, 01 Feb 2005 20:53:01 +0900 Message-ID: <87acqoqyxu.wl@tora.nunu.org> From: Hidetoshi Shimokawa To: "Petr Holub" In-Reply-To: <003f01c5083c$64d444e0$2603fb93@KLOBOUCEK> References: <87d5vlrcas.wl@tora.nunu.org> <003f01c5083c$64d444e0$2603fb93@KLOBOUCEK> User-Agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.6 MULE XEmacs/21.4 (patch 14) (Reasonable Discussion) (i386--freebsd) MIME-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII cc: freebsd-firewire@FreeBSD.org Subject: Re: fwcontrol patch for MPEG TS X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 11:53:03 -0000 At Tue, 1 Feb 2005 09:59:53 +0100, Petr Holub wrote: > I'm thinking about modifying it once again to do format autodetection > and then use appropriate receiving function via -R flag. Do you > think it's worth doing it like this? Yes, I like this idea. /\ Hidetoshi Shimokawa \/ simokawa@FreeBSD.org From owner-freebsd-firewire@FreeBSD.ORG Wed Feb 2 16:56:46 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 865B716A4CE; Wed, 2 Feb 2005 16:56:46 +0000 (GMT) Received: from ithil.ics.muni.cz (ithil.ics.muni.cz [147.251.4.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5049643D53; Wed, 2 Feb 2005 16:56:45 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (kloboucek.ics.muni.cz [147.251.3.38]) (user=hopet@META mech=LOGIN bits=0) by ithil.ics.muni.cz (8.12.1/8.12.1) with ESMTP id j12GufXQ003158 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Wed, 2 Feb 2005 17:56:42 +0100 From: "Petr Holub" To: "Hidetoshi Shimokawa" Date: Wed, 2 Feb 2005 17:56:45 +0100 Message-ID: <008f01c50948$2d391c60$2603fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 In-Reply-To: <87acqoqyxu.wl@tora.nunu.org> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Muni-Spam-TestIP: 147.251.3.38 X-Muni-Virus-Test: Clean cc: freebsd-firewire@FreeBSD.org Subject: fwcontrol with MPEG TS and autodetection support X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 16:56:46 -0000 > Yes, I like this idea. OK - the patch is attached below. It also prints out on stderr, which format has been detected. I've added some docs and documented firewire packet format in a comment at the beginning of fwmpegts.c. Could you test it and tell me what you think? Petr PS: I think it would be nice to document the firewire layer properly in the FreeBSD Developer's Handbook or man pages. Since I didn't have enough time to read through the kernel driver sources, I'm still missing e.g. what nchunks in ioctl structure is good for. P. ================================================================ Petr Holub CESNET z.s.p.o. Supercomputing Center Brno Zikova 4 Institute of Compt. Science 162 00 Praha 6, CZ Masaryk University Czech Republic Botanicka 68a, 60200 Brno, CZ e-mail: Petr.Holub@cesnet.cz phone: +420-549493944 fax: +420-541212747 e-mail: hopet@ics.muni.cz Index: fwcontrol/Makefile =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- fwcontrol/Makefile 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/Makefile 30 Jan 2005 23:14:07 -0000 1.2 @@ -1,7 +1,7 @@ # $FreeBSD: src/usr.sbin/fwcontrol/Makefile,v 1.4 2003/04/30 03:39:25 simokawa Exp $ PROG= fwcontrol -SRCS= fwcontrol.c fwcrom.c fwdv.c +SRCS= fwcontrol.c fwcrom.c fwdv.c fwmpegts.c MAN= fwcontrol.8 .PATH: ${.CURDIR}/../../sys/dev/firewire Index: fwcontrol/fwcontrol.8 =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.8,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- fwcontrol/fwcontrol.8 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.8 2 Feb 2005 16:46:58 -0000 1.4 @@ -84,7 +84,7 @@ .Dv PRIORITY_BUDGET register on all supported nodes. .It Fl R Ar filename -Receive DV stream and dump it to a file. +Receive DV or MPEG TS stream and dump it to a file. Use Ctrl-C to stop the receiving. Some DV cameras seem not to send the stream if a bus manager exits. If you cannot get the stream, try the following commands: @@ -99,6 +99,11 @@ .Nm libdv in the .Fx +Ports Collection. Resulting MPEG TS stream can be played and sent over a +network using the VideoLAN +.Nm vlc +tool in the +.Fx Ports Collection. .It Fl S Ar filename Send a DV file as isochronous stream. @@ -108,7 +113,7 @@ .Pp .Dl "fwcontrol -R original.dv" .Pp -Receive stream. +Receive a DV stream with DV camera attached. .Pp .Dl "dd if=original.dv of=first.dv bs=120000 count=30" .Pp @@ -126,6 +131,12 @@ .Dq Li bs=120000 with .Dq Li bs=144000 . +.Pp +.Dl "fwcontrol -R file.m2t +.Pp +Receive an MPEG TS stream from a camera producing MPEG transport stream. This +has been tested with SONY HDR-FX1E camera that produces HD MPEG-2 stream at +19.2 Mbps bandwidth. .Sh FILES .Bl -tag .It Pa /dev/fw0.0 @@ -144,3 +155,5 @@ .An Hidetoshi Shimokawa Aq simokawa@FreeBSD.org .Sh BUGS This utility is still under development and provided for debugging purposes. +Especially MPEG TS reception support is very rudimental and supports only +high-bandwidth MPEG-2 streams (fn field in CIP header equals 3). Index: fwcontrol/fwcontrol.c =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.c,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- fwcontrol/fwcontrol.c 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.c 2 Feb 2005 16:46:58 -0000 1.4 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,7 @@ extern int dvrecv(int, char *, char, int); extern int dvsend(int, char *, char, int); +extern int mpegtsrecv(int, char *, char, int); static void usage(void) @@ -72,7 +74,7 @@ "\t-t: read topology map\n" "\t-d: hex dump of configuration ROM\n" "\t-l: load and parse hex dump file of configuration ROM\n" - "\t-R: Receive DV stream\n" + "\t-R: Receive DV or MPEG TS stream\n" "\t-S: Send DV stream\n"); exit(0); } @@ -595,12 +597,64 @@ } } +static int (* +detect_recv_fn(int fd, char ich)) (int, char *, char, int) +{ + char *buf; + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + int len; + u_int32_t *ptr; + struct ciphdr *ciph; + int (*retfn)(int, char *, char, int); + + bufreq.rx.nchunk = 8; + bufreq.rx.npacket = 16; + bufreq.rx.psize = 1024; + bufreq.tx.nchunk = 0; + bufreq.tx.npacket = 0; + bufreq.tx.psize = 0; + + if (ioctl(fd, FW_SSTBUF, &bufreq) < 0) { + err(1, "ioctl"); + } + + isoreq.ch = ich & 0x3f; + isoreq.tag = (ich >> 6) & 3; + + if( ioctl(fd, FW_SRSTREAM, &isoreq) < 0) + err(1, "ioctl"); + + buf = (char *)malloc(1024*16); + len = read(fd, buf, 1024*16); + ptr = (u_int32_t *) buf; + ciph = (struct ciphdr *)(ptr + 1); + + switch(ciph->fmt) { + case CIP_FMT_DVCR: + fprintf(stderr, "Detected DV format on input.\n"); + retfn = dvrecv; + break; + case CIP_FMT_MPEG: + fprintf(stderr, "Detected MPEG TS format on input.\n"); + retfn = mpegtsrecv; + break; + default: + errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt); + } + + free(buf); + return retfn; + +} + int main(int argc, char **argv) { u_int32_t crom_buf[1024/4]; char devbase[1024] = "/dev/fw0"; int fd, i, tmp, ch, len=1024; + int *recvfn(); fd = -1; @@ -676,7 +730,7 @@ #define CHANNEL 63 case 'R': open_dev(&fd, devbase); - dvrecv(fd, optarg, TAG | CHANNEL, -1); + (*detect_recv_fn(fd, TAG | CHANNEL))(fd, optarg, TAG | CHANNEL, -1); break; case 'S': open_dev(&fd, devbase); Index: fwcontrol/fwmpegts.c =================================================================== RCS file: fwcontrol/fwmpegts.c diff -N fwcontrol/fwmpegts.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ fwcontrol/fwmpegts.c 2 Feb 2005 16:46:58 -0000 1.6 @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2003 + * Petr Holub, 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. + * + * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.5 2003/04/17 03:38:03 simokawa Exp $ + */ +#include +#include +#include +#include +#include + +#if __FreeBSD_version >= 500000 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define DEBUG 0 + +/***************************************************************************** + +MPEG TS packet format: + +31 15 0 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| len |tag| channel | tcode | sy | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1394 +| header CRC | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +|0|0| sid | dbs |fn | qpc |S|RSV| dbc | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ CIP +|1|0| fmt | fdf | fdf/syt | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| reserved | cycle_count | cycle_offset | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| | N x +. . MPEG +. MPEG TS payload 188 bytes . +. . +| | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| header CRC | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +N.b. that CRCs are removed by firewire layer! + +*****************************************************************************/ + + +typedef uint8_t mpeg_ts_pld[188]; + +struct mpeg_pldt { +#if BYTE_ORDER == BIG_ENDIAN + uint32_t :7, + c_count:13, + c_offset:12; +#else + uint32_t c_offset:12, + c_count:13, + :7; +#endif + mpeg_ts_pld payload; +}; + + +#define NCHUNK 8 +#define PSIZE 596 +#define NPACKET_R 4096 +#define RBUFSIZE (PSIZE * NPACKET_R) + +int +mpegtsrecv(int d, char *filename, char ich, int count) +{ + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + struct ciphdr *ciph; + struct fw_pkt *pkt; + struct mpeg_pldt *pld; + int pkt_size; + char *buf; + u_int32_t *ptr; + int len, tlen, fd, k, m, startwr = 0; + + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); + buf = (char *)malloc(RBUFSIZE); + + bufreq.rx.nchunk = NCHUNK; + bufreq.rx.npacket = NPACKET_R; + bufreq.rx.psize = PSIZE; + bufreq.tx.nchunk = 0; + bufreq.tx.npacket = 0; + bufreq.tx.psize = 0; + if (ioctl(d, FW_SSTBUF, &bufreq) < 0) { + err(1, "ioctl"); + } + + isoreq.ch = ich & 0x3f; + isoreq.tag = (ich >> 6) & 3; + + if( ioctl(d, FW_SRSTREAM, &isoreq) < 0) + err(1, "ioctl"); + + k = m = 0; + while (count <= 0 || k <= count) { + len = tlen = read(d, buf, RBUFSIZE); +#if DEBUG + fprintf(stderr, "Read %d bytes.\n", len); +#endif + if (len < 0) { + if (errno == EAGAIN) { + fprintf(stderr, "(EAGAIN)\n"); + fflush(stderr); + if (len <= 0) + continue; + } else + err(1, "read failed"); + } + ptr = (u_int32_t *) buf; + + do { + pkt = (struct fw_pkt *) ptr; +#if DEBUG + fprintf(stderr, "%08x %08x %08x %08x\n", + htonl(ptr[0]), htonl(ptr[1]), + htonl(ptr[2]), htonl(ptr[3])); +#endif + /* there is no CRC in the 1394 header */ + ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ + if (ciph->fmt != CIP_FMT_MPEG) + errx(1, "unknown format 0x%x", ciph->fmt); + if (ciph->fn != 3) + errx(1, "unsupported MPEG TS stream, fn=%d (only fn=3 is supported)", ciph->fn); + ptr = (u_int32_t *) (ciph + 1); /* skip cip header */ + + if (pkt->mode.stream.len <= sizeof(struct ciphdr)) { + /* no payload */ + /* tlen needs to be decremented before end of the loop */ + goto next; + } +#if DEBUG + else { + fprintf(stderr, "Packet net payload length (IEEE1394 header): %d\n", pkt->mode.stream.len - sizeof(struct ciphdr)); + fprintf(stderr, "Data block size (CIP header): %d [q], %d [B]\n", ciph->len, ciph->len * 4); + fprintf(stderr, "Data fraction number (CIP header): %d => DBC increments with %d\n", ciph->fn, (1<fn) ); + fprintf(stderr, "QCP (CIP header): %d\n", ciph->qpc ); + fprintf(stderr, "DBC counter (CIP header): %d\n", ciph->dbc ); + fprintf(stderr, "MPEG payload type size: %d\n", sizeof(struct mpeg_pldt)); + } +#endif + + if ( ciph->dbc % (1<fn) == 0) { + startwr = 1; + } + for (pld = (struct mpeg_pldt *)ptr; + (int)pld < (int)((char *)ptr + pkt->mode.stream.len - sizeof(struct ciphdr) ); + pld++) { + if(startwr == 1) + write(fd, pld->payload, sizeof(pld->payload)); + } + +next: + /* CRCs are removed from both header and trailer + so that only 4 bytes of 1394 header remains */ + pkt_size = pkt->mode.stream.len + 4; + ptr = (u_int32_t *) ((int)pkt + pkt_size); +#if DEBUG + fprintf(stderr, "Packet size is %d.\n", pkt_size); + fprintf(stderr, "tlen = %d.\n\n", tlen); +#endif + tlen -= pkt_size; + } while (tlen > 0); +#if DEBUG + fprintf(stderr, "\nReading a data from firewire.\n"); +#endif + + } + close(fd); + fprintf(stderr, "\n"); + return 0; +} + From owner-freebsd-firewire@FreeBSD.ORG Wed Feb 2 18:26:37 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7B4FF16A4CE; Wed, 2 Feb 2005 18:26:37 +0000 (GMT) Received: from ithil.ics.muni.cz (ithil.ics.muni.cz [147.251.4.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id B51B343D31; Wed, 2 Feb 2005 18:26:36 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (kloboucek.ics.muni.cz [147.251.3.38]) (user=hopet@META mech=LOGIN bits=0) by ithil.ics.muni.cz (8.12.1/8.12.1) with ESMTP id j12IQZXQ004080 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Wed, 2 Feb 2005 19:26:35 +0100 From: "Petr Holub" To: "Petr Holub" , "Hidetoshi Shimokawa" Date: Wed, 2 Feb 2005 19:26:37 +0100 Message-ID: <009401c50954$bb692460$2603fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Muni-Spam-TestIP: 147.251.3.38 X-Muni-Envelope-From: hopet@ics.muni.cz X-Muni-Virus-Test: Clean cc: freebsd-firewire@FreeBSD.org Subject: RE: fwcontrol with MPEG TS and autodetection support X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 18:26:37 -0000 I've encountered one problem with the patch I've sent a while ago. The receiving process after the autodetection generates the following message: fwohci0: IR DMA no free chunk fwohci0: IR DMA overrun (0x40008011) I think I can aviod it by re-opening the device but I would like to a) know what happens (is it related to the nchunk variable I don't understand?) b) avoid it in some cleaner way. Petr From owner-freebsd-firewire@FreeBSD.ORG Thu Feb 3 11:11:06 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 587CD16A4CE; Thu, 3 Feb 2005 11:11:06 +0000 (GMT) Received: from ithil.ics.muni.cz (ns.muni.cz [147.251.4.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2834F43D1F; Thu, 3 Feb 2005 11:11:05 +0000 (GMT) (envelope-from hopet@ics.muni.cz) Received: from KLOBOUCEK (kloboucek.ics.muni.cz [147.251.3.38]) (user=hopet@META mech=LOGIN bits=0) by ithil.ics.muni.cz (8.12.1/8.12.1) with ESMTP id j13BB2XQ014525 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Thu, 3 Feb 2005 12:11:02 +0100 From: "Petr Holub" To: "Hidetoshi Shimokawa" Date: Thu, 3 Feb 2005 12:11:05 +0100 Message-ID: <012901c509e1$0dbeb220$2603fb93@KLOBOUCEK> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2377.0 In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Muni-Spam-TestIP: 147.251.3.38 X-Muni-Virus-Test: Clean cc: freebsd-firewire@FreeBSD.org Subject: RE: fwcontrol with MPEG TS and autodetection support X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2005 11:11:06 -0000 Hi, I've updated to code so that after auto-detection, the device is reopened to avoid the errors I've mentioned yesterday. If somebody comes up with cleaner solution, I'd be just happy. Anyway, current patch is below. I've also added more docs and did a little cleanup. The patch is against 5.3-RELEASE. Petr ================================================================ Petr Holub CESNET z.s.p.o. Supercomputing Center Brno Zikova 4 Institute of Compt. Science 162 00 Praha 6, CZ Masaryk University Czech Republic Botanicka 68a, 60200 Brno, CZ e-mail: Petr.Holub@cesnet.cz phone: +420-549493944 fax: +420-541212747 e-mail: hopet@ics.muni.cz Index: fwcontrol/Makefile =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- fwcontrol/Makefile 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/Makefile 30 Jan 2005 23:14:07 -0000 1.2 @@ -1,7 +1,7 @@ # $FreeBSD: src/usr.sbin/fwcontrol/Makefile,v 1.4 2003/04/30 03:39:25 simokawa Exp $ PROG= fwcontrol -SRCS= fwcontrol.c fwcrom.c fwdv.c +SRCS= fwcontrol.c fwcrom.c fwdv.c fwmpegts.c MAN= fwcontrol.8 .PATH: ${.CURDIR}/../../sys/dev/firewire Index: fwcontrol/fwcontrol.8 =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.8,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- fwcontrol/fwcontrol.8 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.8 2 Feb 2005 16:46:58 -0000 1.4 @@ -84,7 +84,7 @@ .Dv PRIORITY_BUDGET register on all supported nodes. .It Fl R Ar filename -Receive DV stream and dump it to a file. +Receive DV or MPEG TS stream and dump it to a file. Use Ctrl-C to stop the receiving. Some DV cameras seem not to send the stream if a bus manager exits. If you cannot get the stream, try the following commands: @@ -99,6 +99,11 @@ .Nm libdv in the .Fx +Ports Collection. Resulting MPEG TS stream can be played and sent over a +network using the VideoLAN +.Nm vlc +tool in the +.Fx Ports Collection. .It Fl S Ar filename Send a DV file as isochronous stream. @@ -108,7 +113,7 @@ .Pp .Dl "fwcontrol -R original.dv" .Pp -Receive stream. +Receive a DV stream with DV camera attached. .Pp .Dl "dd if=original.dv of=first.dv bs=120000 count=30" .Pp @@ -126,6 +131,12 @@ .Dq Li bs=120000 with .Dq Li bs=144000 . +.Pp +.Dl "fwcontrol -R file.m2t +.Pp +Receive an MPEG TS stream from a camera producing MPEG transport stream. This +has been tested with SONY HDR-FX1E camera that produces HD MPEG-2 stream at +19.2 Mbps bandwidth. .Sh FILES .Bl -tag .It Pa /dev/fw0.0 @@ -144,3 +155,5 @@ .An Hidetoshi Shimokawa Aq simokawa@FreeBSD.org .Sh BUGS This utility is still under development and provided for debugging purposes. +Especially MPEG TS reception support is very rudimental and supports only +high-bandwidth MPEG-2 streams (fn field in CIP header equals 3). Index: fwcontrol/fwcontrol.c =================================================================== RCS file: /home/hopet/fwcontrol/fwcontrol/fwcontrol.c,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -u -r1.1.1.1 -r1.5 --- fwcontrol/fwcontrol.c 30 Jan 2005 22:35:05 -0000 1.1.1.1 +++ fwcontrol/fwcontrol.c 3 Feb 2005 10:32:29 -0000 1.5 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,7 @@ extern int dvrecv(int, char *, char, int); extern int dvsend(int, char *, char, int); +extern int mpegtsrecv(int, char *, char, int); static void usage(void) @@ -72,7 +74,7 @@ "\t-t: read topology map\n" "\t-d: hex dump of configuration ROM\n" "\t-l: load and parse hex dump file of configuration ROM\n" - "\t-R: Receive DV stream\n" + "\t-R: Receive DV or MPEG TS stream\n" "\t-S: Send DV stream\n"); exit(0); } @@ -595,12 +597,64 @@ } } +static int (* +detect_recv_fn(int fd, char ich)) (int, char *, char, int) +{ + char *buf; + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + int len; + u_int32_t *ptr; + struct ciphdr *ciph; + int (*retfn)(int, char *, char, int); + + bufreq.rx.nchunk = 8; + bufreq.rx.npacket = 16; + bufreq.rx.psize = 1024; + bufreq.tx.nchunk = 0; + bufreq.tx.npacket = 0; + bufreq.tx.psize = 0; + + if (ioctl(fd, FW_SSTBUF, &bufreq) < 0) { + err(1, "ioctl"); + } + + isoreq.ch = ich & 0x3f; + isoreq.tag = (ich >> 6) & 3; + + if( ioctl(fd, FW_SRSTREAM, &isoreq) < 0) + err(1, "ioctl"); + + buf = (char *)malloc(1024*16); + len = read(fd, buf, 1024*16); + ptr = (u_int32_t *) buf; + ciph = (struct ciphdr *)(ptr + 1); + + switch(ciph->fmt) { + case CIP_FMT_DVCR: + fprintf(stderr, "Detected DV format on input.\n"); + retfn = dvrecv; + break; + case CIP_FMT_MPEG: + fprintf(stderr, "Detected MPEG TS format on input.\n"); + retfn = mpegtsrecv; + break; + default: + errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt); + } + + free(buf); + return retfn; + +} + int main(int argc, char **argv) { u_int32_t crom_buf[1024/4]; char devbase[1024] = "/dev/fw0"; int fd, i, tmp, ch, len=1024; + int (*recvfn)(int, char *, char, int); fd = -1; @@ -676,7 +730,11 @@ #define CHANNEL 63 case 'R': open_dev(&fd, devbase); - dvrecv(fd, optarg, TAG | CHANNEL, -1); + recvfn = detect_recv_fn(fd, TAG | CHANNEL); + close(fd); + fd = -1; + open_dev(&fd, devbase); + (*recvfn)(fd, optarg, TAG | CHANNEL, -1); break; case 'S': open_dev(&fd, devbase); Index: fwcontrol/fwmpegts.c =================================================================== RCS file: fwcontrol/fwmpegts.c diff -N fwcontrol/fwmpegts.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ fwcontrol/fwmpegts.c 3 Feb 2005 07:59:19 -0000 1.8 @@ -0,0 +1,250 @@ +/* + * Copyright (C) 2003 + * Petr Holub, 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. + * + * $FreeBSD: src/usr.sbin/fwcontrol/fwdv.c,v 1.5 2003/04/17 03:38:03 simokawa Exp $ + */ +#include +#include +#include +#include +#include + +#if __FreeBSD_version >= 500000 +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define DEBUG 0 + +/***************************************************************************** + +MPEG-2 Transport Stream (MPEG TS) packet format according to IEC 61883: + +31 15 0 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| len |tag| channel | tcode | sy | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1394 +| header CRC | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +|0|0| sid | dbs |fn | qpc |S|RSV| dbc | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ CIP +|1|0| fmt | fdf | fdf/syt | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| reserved | cycle_count | cycle_offset | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| | N x +. . MPEG +. MPEG TS payload 188 bytes . +. . +| | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- +| header CRC | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +N.b. that CRCs are removed by firewire layer! + +The following fiels are fixed for IEEE-1394: +tag = 01b +tcode = 1010b +The length is payload length, i.e. includes CIP header and data size. + +The following fields are constant for MPEG TS: +sph = 1 (denoted as S in CIP header above) +dbs = 6 +fmt = (1<<5) +fdf = reserved +In the supported streams we also require +qpc = 0 +fn = 3 +and thus the payload is divided in 8 blocks as follows: + + +-----+-----+-----+-----+-----+-----+-----+-----+ + | db0 | db1 | db2 | db3 | db4 | db5 | db6 | db7 | + +-----+-----+-----+-----+-----+-----+-----+-----+ + +We have several cases of payload distribution based on stream +bandwidth (R): +1) R < 1.5 Mbps: any of db0..db7 may be payload +2) 1.5 < R < 3 Mbps: db0/db1 or db2/db3 or db4/db5 or db6/7 is payload +3) 3 < R < 6 Mbps: db0/db1/db2/db3 or db4/db5/db6/db7 is payload +4) R > 6 Mbps: all db0..db7 contain the payload +Curently, only case (4) is supported in fwmpegts.c + +Each packet may contain N MPEG TS data blocks with timestamp header, +which are (4+188)B long. Experimentally, the N ranges from 0 through 3. + +*****************************************************************************/ + + +typedef uint8_t mpeg_ts_pld[188]; + +struct mpeg_pldt { +#if BYTE_ORDER == BIG_ENDIAN + uint32_t :7, + c_count:13, + c_offset:12; +#else + uint32_t c_offset:12, + c_count:13, + :7; +#endif + mpeg_ts_pld payload; +}; + + +#define NCHUNK 8 +#define PSIZE 596 +#define NPACKET_R 4096 +#define RBUFSIZE (PSIZE * NPACKET_R) + +int +mpegtsrecv(int d, char *filename, char ich, int count) +{ + struct fw_isochreq isoreq; + struct fw_isobufreq bufreq; + struct ciphdr *ciph; + struct fw_pkt *pkt; + struct mpeg_pldt *pld; + int pkt_size; + char *buf; + u_int32_t *ptr; + int len, tlen, fd, k, m, startwr = 0; + + fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); + buf = (char *)malloc(RBUFSIZE); + + bufreq.rx.nchunk = NCHUNK; + bufreq.rx.npacket = NPACKET_R; + bufreq.rx.psize = PSIZE; + bufreq.tx.nchunk = 0; + bufreq.tx.npacket = 0; + bufreq.tx.psize = 0; + if (ioctl(d, FW_SSTBUF, &bufreq) < 0) { + err(1, "ioctl"); + } + + isoreq.ch = ich & 0x3f; + isoreq.tag = (ich >> 6) & 3; + + if( ioctl(d, FW_SRSTREAM, &isoreq) < 0) + err(1, "ioctl"); + + k = m = 0; + while (count <= 0 || k <= count) { + len = tlen = read(d, buf, RBUFSIZE); +#if DEBUG + fprintf(stderr, "Read %d bytes.\n", len); +#endif + if (len < 0) { + if (errno == EAGAIN) { + fprintf(stderr, "(EAGAIN)\n"); + fflush(stderr); + if (len <= 0) + continue; + } else + err(1, "read failed"); + } + ptr = (u_int32_t *) buf; + + do { + pkt = (struct fw_pkt *) ptr; +#if DEBUG + fprintf(stderr, "\nReading new packet.\n"); + fprintf(stderr, "%08x %08x %08x %08x\n", + htonl(ptr[0]), htonl(ptr[1]), + htonl(ptr[2]), htonl(ptr[3])); +#endif + /* there is no CRC in the 1394 header */ + ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ + if (ciph->fmt != CIP_FMT_MPEG) + errx(1, "unknown format 0x%x", ciph->fmt); + if (ciph->fn != 3) + errx(1, "unsupported MPEG TS stream, fn=%d (only fn=3 is supported)", ciph->fn); + ptr = (u_int32_t *) (ciph + 1); /* skip cip header */ + + if (pkt->mode.stream.len <= sizeof(struct ciphdr)) { + /* no payload */ + /* tlen needs to be decremented before end of the loop */ + goto next; + } +#if DEBUG + else { + fprintf(stderr, "Packet net payload length (IEEE1394 header): %d\n", pkt->mode.stream.len - sizeof(struct ciphdr)); + fprintf(stderr, "Data block size (CIP header): %d [q], %d [B]\n", ciph->len, ciph->len * 4); + fprintf(stderr, "Data fraction number (CIP header): %d => DBC increments with %d\n", ciph->fn, (1<fn) ); + fprintf(stderr, "QCP (CIP header): %d\n", ciph->qpc ); + fprintf(stderr, "DBC counter (CIP header): %d\n", ciph->dbc ); + fprintf(stderr, "MPEG payload type size: %d\n", sizeof(struct mpeg_pldt)); + } +#endif + + /* This is a condition that needs to be satisfied to start + writing the data */ + if ( ciph->dbc % (1<fn) == 0) { + startwr = 1; + } + /* Read out all the MPEG TS data blocks from current packet */ + for (pld = (struct mpeg_pldt *)ptr; + (int)pld < (int)((char *)ptr + pkt->mode.stream.len - sizeof(struct ciphdr) ); + pld++) { + if(startwr == 1) + write(fd, pld->payload, sizeof(pld->payload)); + } + +next: + /* CRCs are removed from both header and trailer + so that only 4 bytes of 1394 header remains */ + pkt_size = pkt->mode.stream.len + 4; + ptr = (u_int32_t *) ((int)pkt + pkt_size); + tlen -= pkt_size; + } while (tlen > 0); +#if DEBUG + fprintf(stderr, "\nReading a data from firewire.\n"); +#endif + + } + close(fd); + fprintf(stderr, "\n"); + return 0; +} + From owner-freebsd-firewire@FreeBSD.ORG Thu Feb 3 15:48:26 2005 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0287416A4CE for ; Thu, 3 Feb 2005 15:48:26 +0000 (GMT) Received: from relay03.roc.ny.frontiernet.net (relay03.roc.ny.frontiernet.net [66.133.131.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 67B9C43D31 for ; Thu, 3 Feb 2005 15:48:25 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from filter01.roc.ny.frontiernet.net (filter01.roc.ny.frontiernet.net [66.133.131.176]) by relay03.roc.ny.frontiernet.net (Postfix) with ESMTP id C9D1D191BED for ; Thu, 3 Feb 2005 15:48:24 +0000 (UTC) Received: from relay03.roc.ny.frontiernet.net ([66.133.131.36]) [66.133.131.176]) (amavisd-new, port 10024) with LMTP id 03617-18-3 for ; Thu, 3 Feb 2005 15:48:24 +0000 (UTC) Received: from blacklamb.mykitchentable.net (67-137-237-141.dsl2.elk.ca.frontiernet.net [67.137.237.141]) by relay03.roc.ny.frontiernet.net (Postfix) with ESMTP id 137C4191E1B for ; Thu, 3 Feb 2005 15:48:22 +0000 (UTC) Received: from [192.168.1.3] (bigdaddy.mykitchentable.net [192.168.1.3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTP id E1DE43BF371 for ; Thu, 3 Feb 2005 07:48:21 -0800 (PST) Message-ID: <420247C5.4040103@mykitchentable.net> Date: Thu, 03 Feb 2005 07:48:21 -0800 From: Drew Tomlinson User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-firewire@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20040701 (2.0) at filter01.roc.ny.frontiernet.net Subject: Help Interpreting sbp0 Errors X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2005 15:48:26 -0000 I'm still having this problem and would appreciate any assistance someone might offer. Please let me know if I can include more information. Thanks, Drew -------- Original Message -------- Subject: Help Interpreting sbp0 Errors Date: Mon, 24 Jan 2005 11:43:21 -0800 From: Drew Tomlinson To: freebsd-firewire@freebsd.org I posted about this issue first on -questions but have not received a response. I'm hoping some one here might be able to offer some assistance. I've been having problems with vinum volumes since an upgrade from 4.9 to 4.10 which I posted about here: http://docs.freebsd.org/cgi/mid.cgi?41D748F0.1000303 However maybe that is the *symptom* instead of the *problem*. I shut down my system from the console and saw this output: --- BEGIN --- boot() called on cpu#0 Waiting (max 60 seconds) for system process `vnlru' to stop...stopped Waiting (max 60 seconds) for system process `bufdaemon' to stop...stopped Waiting (max 60 seconds) for system process `syncer' to stop...stopped syncing disks... 4 done Uptime: 28d20h48m39s sbp0:0:0 request timeout(mgm orb:0x0a550b14) ... reset start sbp0:0:0 request timeout(cmd orb:0x0a550c4c) ... agent reset (da2:sbp0:0:0:0): Synchronize cache failed, status == 0xb, scsi status == 0x0 sbp0:0:1 request timeout(cmd orb:0x0a5528a4) ... agent reset (da3:sbp0:0:0:1): Synchronize cache failed, status == 0xb, scsi status == 0x0 The operating system has halted. Please press any key to reboot. --- END --- da2 and da3 are two IDE drives in a firewire enclosure. These are also the drives that come up "referenced" after restarting. What do these errors mean? How can I correct them? Is the following section from the sbp man page applicable to my situation? Some (broken) HDDs don't work well with tagged queuing. If you have prob- lems with such drives, try ``camcontrol [device id] tags -N 1'' to dis- able tagged queuing. Thanks for your help! Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, & More! http://www.alchemistswarehouse.com