xref: /titanic_44/usr/src/cmd/cdrw/dae.c (revision 9858459238fb4f2d8f924f4d3fe9f51ed2e32564)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
230c83a891Snakanon  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <string.h>
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <libintl.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "bstream.h"
367c478bd9Sstevel@tonic-gate #include "util.h"
377c478bd9Sstevel@tonic-gate #include "misc_scsi.h"
387c478bd9Sstevel@tonic-gate #include "device.h"
397c478bd9Sstevel@tonic-gate #include "main.h"
407c478bd9Sstevel@tonic-gate #include "msgs.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	BLOCK_SIZE		2352
437c478bd9Sstevel@tonic-gate #define	READ_BURST_SIZE		200
447c478bd9Sstevel@tonic-gate #define	SMALL_READ_BURST_SIZE	24	/* < 64K in all cases */
457c478bd9Sstevel@tonic-gate #define	READ_OVERLAP		7
467c478bd9Sstevel@tonic-gate #define	BLOCKS_COMPARE		3
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static int			abort_read;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * These are routines for extracting audio from a cd. During
527c478bd9Sstevel@tonic-gate  * extraction we will also convert the audio type from the
537c478bd9Sstevel@tonic-gate  * CD to the audio type specified on the command line. This
547c478bd9Sstevel@tonic-gate  * handles both newer CD drives which support the MMC2 standard
557c478bd9Sstevel@tonic-gate  * and older Sun Toshiba drives which need jitter correction.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static bstreamhandle
open_audio_for_extraction(char * fname)597c478bd9Sstevel@tonic-gate open_audio_for_extraction(char *fname)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	int at;
627c478bd9Sstevel@tonic-gate 	char *ext;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if (audio_type == AUDIO_TYPE_NONE) {
657c478bd9Sstevel@tonic-gate 		ext = (char *)(strrchr(fname, '.'));
667c478bd9Sstevel@tonic-gate 		if (ext) {
677c478bd9Sstevel@tonic-gate 			ext++;
687c478bd9Sstevel@tonic-gate 		}
697c478bd9Sstevel@tonic-gate 		if ((ext == NULL) || ((at = get_audio_type(ext)) == -1)) {
707c478bd9Sstevel@tonic-gate 			err_msg(gettext(
717c478bd9Sstevel@tonic-gate 			    "Cannot understand file extension for %s\n"),
727c478bd9Sstevel@tonic-gate 			    fname);
737c478bd9Sstevel@tonic-gate 			exit(1);
747c478bd9Sstevel@tonic-gate 		}
757c478bd9Sstevel@tonic-gate 	} else {
767c478bd9Sstevel@tonic-gate 		at = audio_type;
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate 	if (at == AUDIO_TYPE_SUN)
797c478bd9Sstevel@tonic-gate 		return (open_au_write_stream(fname));
807c478bd9Sstevel@tonic-gate 	if (at == AUDIO_TYPE_WAV)
817c478bd9Sstevel@tonic-gate 		return (open_wav_write_stream(fname));
827c478bd9Sstevel@tonic-gate 	if (at == AUDIO_TYPE_CDA)
837c478bd9Sstevel@tonic-gate 		return (open_file_write_stream(fname));
847c478bd9Sstevel@tonic-gate 	if (at == AUDIO_TYPE_AUR)
857c478bd9Sstevel@tonic-gate 		return (open_aur_write_stream(fname));
867c478bd9Sstevel@tonic-gate 	return (NULL);
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* ARGSUSED */
907c478bd9Sstevel@tonic-gate static void
extract_signal_handler(int sig,siginfo_t * info,void * context)917c478bd9Sstevel@tonic-gate extract_signal_handler(int sig, siginfo_t *info, void *context)
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	abort_read = 1;
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Older drives use different data buffer and m:s:f channels to transmit audio
987c478bd9Sstevel@tonic-gate  * information. These channels may not be in sync with each other with the
997c478bd9Sstevel@tonic-gate  * maximum disparity being the size of the data buffer. So handling is needed
1007c478bd9Sstevel@tonic-gate  * to keep these two channels in sync.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static int
handle_jitter(uchar_t * buf,uchar_t * last_end)1047c478bd9Sstevel@tonic-gate handle_jitter(uchar_t *buf, uchar_t *last_end)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	int i;
1077c478bd9Sstevel@tonic-gate 	for (i = BLOCK_SIZE*(READ_OVERLAP - BLOCKS_COMPARE); i >= 0; i -= 4) {
1087c478bd9Sstevel@tonic-gate 		if (memcmp(last_end - BLOCK_SIZE * BLOCKS_COMPARE, buf + i,
1097c478bd9Sstevel@tonic-gate 		    BLOCK_SIZE * BLOCKS_COMPARE) == 0) {
1107c478bd9Sstevel@tonic-gate 			return (i + (BLOCK_SIZE * BLOCKS_COMPARE));
1117c478bd9Sstevel@tonic-gate 		}
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 	for (i = BLOCK_SIZE*(READ_OVERLAP - BLOCKS_COMPARE);
1147c478bd9Sstevel@tonic-gate 		i < 2*READ_OVERLAP*BLOCK_SIZE; i += 4) {
1157c478bd9Sstevel@tonic-gate 		if (memcmp(last_end - BLOCK_SIZE * BLOCKS_COMPARE, buf + i,
1167c478bd9Sstevel@tonic-gate 		    BLOCK_SIZE * BLOCKS_COMPARE) == 0) {
1177c478bd9Sstevel@tonic-gate 			return (i + (BLOCK_SIZE * BLOCKS_COMPARE));
1187c478bd9Sstevel@tonic-gate 		}
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 	return (-1);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate int
read_audio_track(cd_device * dev,struct track_info * ti,bstreamhandle h)1247c478bd9Sstevel@tonic-gate read_audio_track(cd_device *dev, struct track_info *ti, bstreamhandle h)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	uint32_t	blocks_to_write, blocks_to_read, blks_to_overlap;
1277c478bd9Sstevel@tonic-gate 	uint32_t	start_blk, end_blk, c_blk;
1287c478bd9Sstevel@tonic-gate 	uint32_t	read_burst_size;
1297c478bd9Sstevel@tonic-gate 	uchar_t		*tmp, *buf, *prev, *previous_end;
1307c478bd9Sstevel@tonic-gate 	int		ret, off;
1317c478bd9Sstevel@tonic-gate 	struct sigaction	sv;
1327c478bd9Sstevel@tonic-gate 	struct sigaction	oldsv;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	ret = 0;
1357c478bd9Sstevel@tonic-gate 	abort_read = 0;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	/*
1387c478bd9Sstevel@tonic-gate 	 * It is good to do small sized I/Os as we have seen many devices
1397c478bd9Sstevel@tonic-gate 	 * choke with large I/Os. But if the device does not support
1407c478bd9Sstevel@tonic-gate 	 * reading accurate CDDA then we have to do overlapped I/Os
1417c478bd9Sstevel@tonic-gate 	 * and reducing size might affect performance. So use small
1427c478bd9Sstevel@tonic-gate 	 * I/O size if device supports accurate CDDA.
1437c478bd9Sstevel@tonic-gate 	 */
1447c478bd9Sstevel@tonic-gate 	if (dev->d_cap & DEV_CAP_ACCURATE_CDDA) {
1457c478bd9Sstevel@tonic-gate 		read_burst_size = SMALL_READ_BURST_SIZE;
1467c478bd9Sstevel@tonic-gate 	} else {
1477c478bd9Sstevel@tonic-gate 		read_burst_size = READ_BURST_SIZE;
1487c478bd9Sstevel@tonic-gate 	}
1497c478bd9Sstevel@tonic-gate 	buf = (uchar_t *)my_zalloc(BLOCK_SIZE * read_burst_size);
1507c478bd9Sstevel@tonic-gate 	prev = (uchar_t *)my_zalloc(BLOCK_SIZE * read_burst_size);
1517c478bd9Sstevel@tonic-gate 	start_blk = ti->ti_start_address;
1527c478bd9Sstevel@tonic-gate 	end_blk = ti->ti_start_address + ti->ti_track_size - 1;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/* Even when we need jitter correction, this will be 0 1st time */
1557c478bd9Sstevel@tonic-gate 	blks_to_overlap = 0;
1567c478bd9Sstevel@tonic-gate 	off = 0;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	/* set up signal handler to write audio TOC if ^C is pressed */
1597c478bd9Sstevel@tonic-gate 	sv.sa_handler = extract_signal_handler;
1607c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&sv.sa_mask);
1617c478bd9Sstevel@tonic-gate 	sv.sa_flags = 0;
1627c478bd9Sstevel@tonic-gate 	(void) sigaction(SIGINT, &sv, &oldsv);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if ((dev->d_cap & DEV_CAP_EXTRACT_CDDA) == 0) {
1657c478bd9Sstevel@tonic-gate 		err_msg(gettext("Audio extraction method unknown for %s\n"),
1667c478bd9Sstevel@tonic-gate 		    dev->d_name ? dev->d_name : gettext("CD drive"));
1677c478bd9Sstevel@tonic-gate 		exit(1);
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/* if the speed option given, try to change the speed */
1717c478bd9Sstevel@tonic-gate 	if ((requested_speed != 0) && !cflag) {
1727c478bd9Sstevel@tonic-gate 		if (verbose)
1737c478bd9Sstevel@tonic-gate 			(void) printf(gettext("Trying to set speed to %dX.\n"),
1747c478bd9Sstevel@tonic-gate 			    requested_speed);
1757c478bd9Sstevel@tonic-gate 		if (dev->d_speed_ctrl(dev, SET_READ_SPEED,
1767c478bd9Sstevel@tonic-gate 		    requested_speed) == 0) {
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 			err_msg(gettext("Unable to set speed.\n"));
1797c478bd9Sstevel@tonic-gate 			exit(1);
1807c478bd9Sstevel@tonic-gate 		}
1817c478bd9Sstevel@tonic-gate 		if (verbose) {
1827c478bd9Sstevel@tonic-gate 			int speed;
1837c478bd9Sstevel@tonic-gate 			speed = dev->d_speed_ctrl(dev, GET_READ_SPEED, 0);
1847c478bd9Sstevel@tonic-gate 			if (speed == requested_speed) {
1857c478bd9Sstevel@tonic-gate 				(void) printf(gettext("Speed set to %dX.\n"),
1867c478bd9Sstevel@tonic-gate 				    speed);
187*98584592Sarutz 			} else if (speed == 0) {
188*98584592Sarutz 				(void) printf(gettext("Could not obtain "
189*98584592Sarutz 				    "current Read Speed.\n"));
1907c478bd9Sstevel@tonic-gate 			} else {
191*98584592Sarutz 				(void) printf(gettext("Speed set to "
192*98584592Sarutz 				    "closest approximation of %dX allowed "
193*98584592Sarutz 				    "by device (%dX).\n"),
1947c478bd9Sstevel@tonic-gate 				    requested_speed, speed);
1957c478bd9Sstevel@tonic-gate 			}
1967c478bd9Sstevel@tonic-gate 		}
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	print_n_flush(
2007c478bd9Sstevel@tonic-gate 	    gettext("Extracting audio from track %d..."), ti->ti_track_no);
2017c478bd9Sstevel@tonic-gate 	init_progress();
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (debug)
2047c478bd9Sstevel@tonic-gate 		(void) printf("\nStarting: %d Ending: %d\n",
2057c478bd9Sstevel@tonic-gate 		    start_blk, end_blk);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	blocks_to_write = 0;
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	for (c_blk = start_blk; c_blk < end_blk; c_blk += blocks_to_write) {
2107c478bd9Sstevel@tonic-gate 		/* update progress indicator */
2110c83a891Snakanon 		(void) progress((end_blk - start_blk),
2127c478bd9Sstevel@tonic-gate 		    (int64_t)(c_blk - start_blk));
2137c478bd9Sstevel@tonic-gate 		blocks_to_read =  end_blk - c_blk + blks_to_overlap;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 		/*
2167c478bd9Sstevel@tonic-gate 		 * Make sure we don't read more blocks than the maximum
2177c478bd9Sstevel@tonic-gate 		 * burst size.
2187c478bd9Sstevel@tonic-gate 		 */
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 		if (blocks_to_read > read_burst_size)
2217c478bd9Sstevel@tonic-gate 			blocks_to_read = read_burst_size;
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 		if (dev->d_read_audio(dev, c_blk - blks_to_overlap,
2247c478bd9Sstevel@tonic-gate 		    blocks_to_read, buf) == 0)
2257c478bd9Sstevel@tonic-gate 			goto read_audio_track_done;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 		/*
2287c478bd9Sstevel@tonic-gate 		 * This drive supports accurate audio extraction don't
2297c478bd9Sstevel@tonic-gate 		 * do jitter correction.
2307c478bd9Sstevel@tonic-gate 		 */
2317c478bd9Sstevel@tonic-gate 		if ((c_blk == start_blk) ||
2327c478bd9Sstevel@tonic-gate 		    (dev->d_cap & DEV_CAP_ACCURATE_CDDA)) {
2337c478bd9Sstevel@tonic-gate 			blocks_to_write = blocks_to_read;
2347c478bd9Sstevel@tonic-gate 			previous_end = buf + (blocks_to_write * BLOCK_SIZE);
2357c478bd9Sstevel@tonic-gate 			goto skip_jitter_correction;
2367c478bd9Sstevel@tonic-gate 		}
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 		if (c_blk == start_blk)
2397c478bd9Sstevel@tonic-gate 			blks_to_overlap = 0;
2407c478bd9Sstevel@tonic-gate 		else
2417c478bd9Sstevel@tonic-gate 			blks_to_overlap = READ_OVERLAP;
2427c478bd9Sstevel@tonic-gate 		off = handle_jitter(buf, previous_end);
2437c478bd9Sstevel@tonic-gate 		if (off == -1) {
2447c478bd9Sstevel@tonic-gate 			if (debug)
2457c478bd9Sstevel@tonic-gate 				(void) printf(
2467c478bd9Sstevel@tonic-gate 				    "jitter control failed\n");
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 			/* recover if jitter correction failed */
2497c478bd9Sstevel@tonic-gate 			off = BLOCK_SIZE * BLOCKS_COMPARE;
2507c478bd9Sstevel@tonic-gate 		}
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 		blocks_to_write = blocks_to_read - blks_to_overlap;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 		while ((off + (blocks_to_write*BLOCK_SIZE)) >
2557c478bd9Sstevel@tonic-gate 		    (blocks_to_read * BLOCK_SIZE)) {
2567c478bd9Sstevel@tonic-gate 			blocks_to_write--;
2577c478bd9Sstevel@tonic-gate 		}
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 		if ((blocks_to_write + c_blk) > end_blk) {
2607c478bd9Sstevel@tonic-gate 			blocks_to_write = end_blk - c_blk;
2617c478bd9Sstevel@tonic-gate 		}
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 		if (blocks_to_write == 0) {
2647c478bd9Sstevel@tonic-gate 			c_blk = end_blk - 1;
2657c478bd9Sstevel@tonic-gate 			blocks_to_write = 1;
2667c478bd9Sstevel@tonic-gate 			(void) memset(&buf[off], 0, off % BLOCK_SIZE);
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		previous_end = buf + off + blocks_to_write * BLOCK_SIZE;
2707c478bd9Sstevel@tonic-gate skip_jitter_correction:
2717c478bd9Sstevel@tonic-gate 		(void) memcpy(prev, buf, read_burst_size * BLOCK_SIZE);
2727c478bd9Sstevel@tonic-gate 		if (h->bstr_write(h, &buf[off], blocks_to_write*BLOCK_SIZE)
2737c478bd9Sstevel@tonic-gate 		    < 0)
2747c478bd9Sstevel@tonic-gate 			goto read_audio_track_done;
2757c478bd9Sstevel@tonic-gate 		tmp = buf;
2767c478bd9Sstevel@tonic-gate 		buf = prev;
2777c478bd9Sstevel@tonic-gate 		prev = tmp;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		if (abort_read == 1)
2807c478bd9Sstevel@tonic-gate 			goto read_audio_track_done;
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	ret = 1;
2847c478bd9Sstevel@tonic-gate 	(void) str_print(gettext("done.\n"), progress_pos);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate read_audio_track_done:
2877c478bd9Sstevel@tonic-gate 	(void) sigaction(SIGINT, &oldsv, (struct sigaction *)0);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	free(buf);
2907c478bd9Sstevel@tonic-gate 	free(prev);
2917c478bd9Sstevel@tonic-gate 	return (ret);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate void
extract_audio(void)2957c478bd9Sstevel@tonic-gate extract_audio(void)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	bstreamhandle h;
2987c478bd9Sstevel@tonic-gate 	struct track_info *ti;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	(void) check_device(target, CHECK_NO_MEDIA | CHECK_DEVICE_NOT_READY |
3017c478bd9Sstevel@tonic-gate 	    EXIT_IF_CHECK_FAILED);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	ti = (struct track_info *)my_zalloc(sizeof (*ti));
3047c478bd9Sstevel@tonic-gate 	if (!build_track_info(target, extract_track_no, ti)) {
3057c478bd9Sstevel@tonic-gate 		err_msg(gettext("Cannot get track information for track %d\n"),
3067c478bd9Sstevel@tonic-gate 		    extract_track_no);
3077c478bd9Sstevel@tonic-gate 		exit(1);
3087c478bd9Sstevel@tonic-gate 	}
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	/* Verify track */
3117c478bd9Sstevel@tonic-gate 	if ((ti->ti_track_size == 0) || ((ti->ti_flags & TI_NWA_VALID) &&
3127c478bd9Sstevel@tonic-gate 	    (ti->ti_start_address == ti->ti_nwa))) {
3137c478bd9Sstevel@tonic-gate 		err_msg(gettext("Track %d is empty\n"), extract_track_no);
3147c478bd9Sstevel@tonic-gate 		exit(1);
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 	if (ti->ti_track_mode & 4) {
3177c478bd9Sstevel@tonic-gate 		err_msg(gettext("Track %d is not an audio track\n"),
3187c478bd9Sstevel@tonic-gate 		    extract_track_no);
3197c478bd9Sstevel@tonic-gate 		exit(1);
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate 	if (ti->ti_data_mode == 2) {
3227c478bd9Sstevel@tonic-gate 		err_msg(gettext("Track format is not supported\n"));
3237c478bd9Sstevel@tonic-gate 		exit(1);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	h = open_audio_for_extraction(extract_file);
3277c478bd9Sstevel@tonic-gate 	if (h == NULL) {
3287c478bd9Sstevel@tonic-gate 		err_msg(gettext("Cannot open %s:%s\n"), extract_file,
3297c478bd9Sstevel@tonic-gate 		    get_err_str());
3307c478bd9Sstevel@tonic-gate 		exit(1);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	if (read_audio_track(target, ti, h) == 0) {
3337c478bd9Sstevel@tonic-gate 		err_msg(gettext("Extract audio failed\n"));
3347c478bd9Sstevel@tonic-gate 		h->bstr_close(h);
3357c478bd9Sstevel@tonic-gate 		exit(1);
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 	if (h->bstr_close(h) != 0) {
3387c478bd9Sstevel@tonic-gate 		err_msg(gettext("Error closing audio stream : %s\n"),
3397c478bd9Sstevel@tonic-gate 		    get_err_str());
3407c478bd9Sstevel@tonic-gate 		exit(1);
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 	exit(0);
3437c478bd9Sstevel@tonic-gate }
344