View | Details | Raw Unified | Return to bug 55546
Collapse All | Expand All

(-)b/usr.sbin/cdcontrol/cdcontrol.c (-89 / +85 lines)
Lines 29-34 Link Here
29
 * 		the uchar storing the volume (256 -> 0, -20 -> 236, ...).
29
 * 		the uchar storing the volume (256 -> 0, -20 -> 236, ...).
30
 * 		Version 2.0.2
30
 * 		Version 2.0.2
31
 *
31
 *
32
 * 03-Feb-2011	Tatsuki Makino <tatsuki_makino@hotmail.com>
33
 * 		Fixed an ability to specify addresses relative to the
34
 * 		beginning of a track.
35
 * 		Version 2.0.3
36
 *
32
 */
37
 */
33
38
34
#include <sys/cdefs.h>
39
#include <sys/cdefs.h>
Lines 52-58 __FBSDID("$FreeBSD$"); Link Here
52
#include <unistd.h>
57
#include <unistd.h>
53
#include <vis.h>
58
#include <vis.h>
54
59
55
#define VERSION "2.0.2"
60
#define VERSION "2.0.3"
56
61
57
#define ASTS_INVALID	0x00  /* Audio status byte not valid */
62
#define ASTS_INVALID	0x00  /* Audio status byte not valid */
58
#define ASTS_PLAYING	0x11  /* Audio play operation in progress */
63
#define ASTS_PLAYING	0x11  /* Audio play operation in progress */
Lines 523-528 int play (char *arg) Link Here
523
		unsigned tr1, tr2;
528
		unsigned tr1, tr2;
524
		unsigned m1, m2, s1, s2, f1, f2;
529
		unsigned m1, m2, s1, s2, f1, f2;
525
		unsigned char tm, ts, tf;
530
		unsigned char tm, ts, tf;
531
		unsigned int lba1, lba2, tlba;
526
532
527
		tr2 = m2 = s2 = f2 = f1 = 0;
533
		tr2 = m2 = s2 = f2 = f1 = 0;
528
		if (8 == sscanf (arg, "%d %d:%d.%d %d %d:%d.%d",
534
		if (8 == sscanf (arg, "%d %d:%d.%d %d %d:%d.%d",
Lines 589-706 int play (char *arg) Link Here
589
		goto Try_Absolute_Timed_Addresses;
595
		goto Try_Absolute_Timed_Addresses;
590
596
591
Play_Relative_Addresses:
597
Play_Relative_Addresses:
592
		if (! tr1)
598
		if (!tr1) {
593
			tr1 = 1;
599
			tr1 = 1;
594
		else if (tr1 > n)
600
		} else if (tr1 > n) {
595
			tr1 = n;
601
			tr1 = n;
602
		}
603
		--tr1;
596
604
597
		tr1--;
605
		/*
598
606
		 * XXX: need check tr1 == toc_buffer[tr1].track ?
607
		 */
599
		if (msf) {
608
		if (msf) {
600
			tm = toc_buffer[tr1].addr.msf.minute;
609
			tm = toc_buffer[tr1].addr.msf.minute;
601
			ts = toc_buffer[tr1].addr.msf.second;
610
			ts = toc_buffer[tr1].addr.msf.second;
602
			tf = toc_buffer[tr1].addr.msf.frame;
611
			tf = toc_buffer[tr1].addr.msf.frame;
603
		} else
612
			tlba = msf2lba(tm, ts, tf);
604
			lba2msf(ntohl(toc_buffer[tr1].addr.lba),
613
		} else {
605
				&tm, &ts, &tf);
614
			tlba = ntohl(toc_buffer[tr1].addr.lba);
606
		if ((m1 > tm)
607
		    || ((m1 == tm)
608
		    && ((s1 > ts)
609
		    || ((s1 == ts)
610
		    && (f1 > tf))))) {
611
			printf ("Track %d is not that long.\n", tr1);
612
			return (0);
613
		}
615
		}
614
616
615
		f1 += tf;
617
		lba1 = msf2lba((u_char)m1, (u_char)s1, (u_char)f1) + 150 + tlba;
616
		if (f1 >= 75) {
617
			s1 += f1 / 75;
618
			f1 %= 75;
619
		}
620
618
621
		s1 += ts;
619
		if (lba1 < tlba) {
622
		if (s1 >= 60) {
620
			printf("Track %d is not that long.\n", tr1 + 1);
623
			m1 += s1 / 60;
621
			return 0;
624
			s1 %= 60;
625
		}
622
		}
626
623
627
		m1 += tm;
624
		if (msf) {
628
625
			tm = toc_buffer[tr1 + 1].addr.msf.minute;
629
		if (! tr2) {
626
			ts = toc_buffer[tr1 + 1].addr.msf.second;
630
			if (m2 || s2 || f2) {
627
			tf = toc_buffer[tr1 + 1].addr.msf.frame;
631
				tr2 = tr1;
628
			tlba = msf2lba(tm, ts, tf);
632
				f2 += f1;
629
		} else {
633
				if (f2 >= 75) {
630
			tlba = ntohl(toc_buffer[tr1 + 1].addr.lba);
634
					s2 += f2 / 75;
631
		}
635
					f2 %= 75;
636
				}
637
638
				s2 += s1;
639
				if (s2 > 60) {
640
					m2 += s2 / 60;
641
					s2 %= 60;
642
				}
643
632
644
				m2 += m1;
633
		if (lba1 > tlba) {
634
			if ((tr1 + 1) == n) {
635
				printf("The playing time of the disc is not that long.\n");
645
			} else {
636
			} else {
646
				tr2 = n;
637
				printf("Track %d is not that long.\n", tr1 + 1);
647
				if (msf) {
648
					m2 = toc_buffer[n].addr.msf.minute;
649
					s2 = toc_buffer[n].addr.msf.second;
650
					f2 = toc_buffer[n].addr.msf.frame;
651
				} else {
652
					lba2msf(ntohl(toc_buffer[n].addr.lba),
653
						&tm, &ts, &tf);
654
					m2 = tm;
655
					s2 = ts;
656
					f2 = tf;
657
				}
658
			}
638
			}
639
			return 0;
640
		}
641
642
		if (!tr2) {
643
			tr2 = tr1 + 1;
659
		} else if (tr2 > n) {
644
		} else if (tr2 > n) {
660
			tr2 = n;
645
			tr2 = n;
661
			m2 = s2 = f2 = 0;
646
		}
647
		--tr2;
648
649
		if (msf) {
650
			tm = toc_buffer[tr2].addr.msf.minute;
651
			ts = toc_buffer[tr2].addr.msf.second;
652
			tf = toc_buffer[tr2].addr.msf.frame;
653
			tlba = msf2lba(tm, ts, tf);
662
		} else {
654
		} else {
663
			if (m2 || s2 || f2)
655
			tlba = ntohl(toc_buffer[tr2].addr.lba);
664
				tr2--;
656
		}
665
			if (msf) {
666
				tm = toc_buffer[tr2].addr.msf.minute;
667
				ts = toc_buffer[tr2].addr.msf.second;
668
				tf = toc_buffer[tr2].addr.msf.frame;
669
			} else
670
				lba2msf(ntohl(toc_buffer[tr2].addr.lba),
671
					&tm, &ts, &tf);
672
			f2 += tf;
673
			if (f2 >= 75) {
674
				s2 += f2 / 75;
675
				f2 %= 75;
676
			}
677
657
678
			s2 += ts;
658
		if (m2 || s2 || f2) {
679
			if (s2 > 60) {
659
			lba2 = msf2lba((u_char)m2, (u_char)s2, (u_char)f2) + 150 + tlba;
680
				m2 += s2 / 60;
660
		} else if (msf) {
681
				s2 %= 60;
661
			tm = toc_buffer[tr2 + 1].addr.msf.minute;
682
			}
662
			ts = toc_buffer[tr2 + 1].addr.msf.second;
663
			tf = toc_buffer[tr2 + 1].addr.msf.frame;
664
			lba2 = msf2lba(tm, ts, tf);
665
		} else {
666
			lba2 = ntohl(toc_buffer[tr2 + 1].addr.lba);
667
		}
683
668
684
			m2 += tm;
669
		if (lba2 < tlba) {
670
			printf("Track %d is not that long.\n", tr2 + 1);
671
			return 0;
685
		}
672
		}
686
673
687
		if (msf) {
674
		if (msf) {
688
			tm = toc_buffer[n].addr.msf.minute;
675
			tm = toc_buffer[tr2 + 1].addr.msf.minute;
689
			ts = toc_buffer[n].addr.msf.second;
676
			ts = toc_buffer[tr2 + 1].addr.msf.second;
690
			tf = toc_buffer[n].addr.msf.frame;
677
			tf = toc_buffer[tr2 + 1].addr.msf.frame;
691
		} else
678
			tlba = msf2lba(tm, ts, tf);
692
			lba2msf(ntohl(toc_buffer[n].addr.lba),
679
		} else {
693
				&tm, &ts, &tf);
680
			tlba = ntohl(toc_buffer[tr2 + 1].addr.lba);
694
		if ((tr2 < n)
695
		    && ((m2 > tm)
696
		    || ((m2 == tm)
697
		    && ((s2 > ts)
698
		    || ((s2 == ts)
699
		    && (f2 > tf)))))) {
700
			printf ("The playing time of the disc is not that long.\n");
701
			return (0);
702
		}
681
		}
703
		return (play_msf (m1, s1, f1, m2, s2, f2));
682
683
		if (lba2 > tlba) {
684
			if ((tr2 + 1) == n) {
685
				printf("The playing time of the disc is not that long.\n");
686
			} else {
687
				printf("Track %d is not that long.\n", tr2 + 1);
688
			}
689
			return 0;
690
		}
691
692
		if (lba1 > lba2) {
693
			/* swap */
694
			lba1 ^= lba2;
695
			lba2 ^= lba1;
696
			lba1 ^= lba2;
697
		}
698
699
		return play_blocks(lba1, lba2 - lba1);
704
700
705
Try_Absolute_Timed_Addresses:
701
Try_Absolute_Timed_Addresses:
706
		if (6 != sscanf (arg, "%d:%d.%d%d:%d.%d",
702
		if (6 != sscanf (arg, "%d:%d.%d%d:%d.%d",

Return to bug 55546