From owner-freebsd-multimedia@FreeBSD.ORG Mon Apr 12 21:29:11 2004 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BCB4616A4CF for ; Mon, 12 Apr 2004 21:29:11 -0700 (PDT) Received: from mail012.syd.optusnet.com.au (mail012.syd.optusnet.com.au [211.29.132.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 07E1943D1D for ; Mon, 12 Apr 2004 21:29:10 -0700 (PDT) (envelope-from akm@theinternet.com.au) Received: from theinternet.com.au (c211-30-103-113.carlnfd1.nsw.optusnet.com.au [211.30.103.113]) i3D4T7S17152; Tue, 13 Apr 2004 14:29:07 +1000 Received: from theinternet.com.au (localhost [127.0.0.1]) by theinternet.com.au (8.12.11/8.12.11) with ESMTP id i3D4T9gv048316; Tue, 13 Apr 2004 14:29:09 +1000 (EST) (envelope-from akm@theinternet.com.au) Received: (from akm@localhost) by theinternet.com.au (8.12.11/8.12.11/Submit) id i3D4T9GH048315; Tue, 13 Apr 2004 14:29:09 +1000 (EST) (envelope-from akm) Date: Tue, 13 Apr 2004 14:29:09 +1000 From: Andrew Milton To: Tim Aslat Message-ID: <20040413042909.GC28737@camelot.theinternet.com.au> Mail-Followup-To: Tim Aslat , FreeBSD Multimedia References: <20040413125131.04358c77@bofh.spyderweb.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040413125131.04358c77@bofh.spyderweb.com.au> User-Agent: Mutt/1.5.6i cc: FreeBSD Multimedia Subject: Re: Media Detection X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2004 04:29:11 -0000 +-------[ Tim Aslat ]---------------------- | Hi All, | | Just trying to set up a PVR type device and would like to throw in a | feature to detect what media (if any) is inserted into the DVD burner. [snip] | How would I go about checking the media if it's a blank, non-blank or RW | disk? | | C or C++ code would be great. I don't have a DVD burner, but, the following chunk of code serves me fairly well for my atapi DVD and CD drives. SCSI drives have a different API to ATA ones, so this may not work for SCSI or ATAPICAM devices. There's some debug in there that could go, but, it might help you so I left it in. It compiles under -current. It's also based on empircal loading of different media types I have lying around, so YMMV w.r.t to detection d8) returns 0 for NO DISK returns 1 for Audio or Audio + Copy Protection/Data. returns 2 for Data returns 3 for Unknown (something is loaded, but, we don't know what). ------------------------------------------------------------------------ #include #include #include #include #include #include #include #define CD_TYPE_AUDIO 100 #define CD_TYPE_MIXED 105 #define CD_STATUS_OK 4 #define CD_STATUS_NO_DISC 1 int CD_getTOCHeader(int fd, struct ioc_toc_header *ith) { if(ioctl(fd, CDIOREADTOCHEADER, ith) < 0) { perror("Read TOC"); return(0); } return(1); } int CD_Status(int fd) { struct ioc_read_toc_entry irte; struct cd_toc_entry *tocP; struct ioc_toc_header ith; u_int control; u_char track; int status = 0, i; status = CD_STATUS_NO_DISC; if(CD_getTOCHeader(fd, &ith) < 0) { perror("read toc header"); return(0); } printf("Start: %d\n", ith.starting_track); printf("End: %d\n", ith.ending_track); printf("Length %d\n", ith.len); memset(&irte, 0, sizeof(struct ioc_read_toc_entry)); irte.data = (struct cd_toc_entry *)malloc(ith.len * sizeof(struct cd_toc_entry)); irte.data_len = ith.len * sizeof(struct cd_toc_entry);; irte.address_format = CD_LBA_FORMAT; irte.starting_track = 0; if(ioctl(fd, CDIOREADTOCENTRYS, &irte) < 0) { free(irte.data); perror("read toc"); return(0); } for(i = 0; i control; track = tocP->track; if(track == 0) { break; } if(control == 0 && status != CD_TYPE_MIXED) { status = CD_TYPE_AUDIO; } else if(control != 0) { if(status == CD_TYPE_AUDIO) { status = CD_TYPE_MIXED; } else { status = 100 + control; } } else if(control == 5) { status = CD_TYPE_MIXED; } } free(irte.data); if(status == CD_TYPE_AUDIO || status == CD_TYPE_MIXED) { return(1); } status == lseek(fd, 0x8000, SEEK_SET); if(status < 0) { perror("lseek"); return(3); } return(2); } -- Totally Holistic Enterprises Internet| | Andrew Milton The Internet (Aust) Pty Ltd | M:+61 416 022 411 | ACN: 082 081 472 ABN: 83 082 081 472 |akm@theinternet.com.au| Carpe Daemon