~ubuntu-branches/ubuntu/edgy/libcdio/edgy-updates

« back to all changes in this revision

Viewing changes to example/C++/paranoia.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-11-15 16:53:23 UTC
  • mfrom: (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20051115165323-peroku75syl2j36u
Tags: 0.76-1ubuntu1
* Sync to new Debian version, manually apply Ubuntu patches:
  - debian/control: Remove dpkg-awk build dependency.
  - debian/rules: hardcode $LIBCDEV. This keeps the diff small (compared to
    the original patch of changing every ${libcdev} occurence).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as published by
 
6
 *   the Free Software Foundation; either version 2, or (at your option)
 
7
 *   any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program; if not, write to the Free Software
 
16
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
/* Simple program to show using libcdio's version of the CD-DA paranoia. 
 
20
   library. 
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
# include "config.h"
 
25
#endif
 
26
 
 
27
#include <cdio/paranoia.h>
 
28
#include <cdio/cd_types.h>
 
29
#include <stdio.h>
 
30
 
 
31
#ifdef HAVE_STDLIB_H
 
32
#include <stdlib.h>
 
33
#endif
 
34
 
 
35
int
 
36
main(int argc, const char *argv[])
 
37
{
 
38
  cdrom_drive_t *d = NULL; /* Place to store handle given by cd-paranoia. */
 
39
  char **ppsz_cd_drives;  /* List of all drives with a loaded CDDA in it. */
 
40
 
 
41
  /* See if we can find a device with a loaded CD-DA in it. */
 
42
  ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
 
43
 
 
44
  if (ppsz_cd_drives) {
 
45
    /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in
 
46
       the list. */
 
47
    d=cdda_identify(*ppsz_cd_drives, 1, NULL);
 
48
  } else {
 
49
    printf("Unable find or access a CD-ROM drive with an audio CD in it.\n");
 
50
    exit(1);
 
51
  }
 
52
 
 
53
  /* Don't need a list of CD's with CD-DA's any more. */
 
54
  cdio_free_device_list(ppsz_cd_drives);
 
55
 
 
56
  if ( !d ) {
 
57
    printf("Unable to identify audio CD disc.\n");
 
58
    exit(1);
 
59
  }
 
60
 
 
61
  /* We'll set for verbose paranoia messages. */
 
62
  cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
 
63
 
 
64
  if ( 0 != cdda_open(d) ) {
 
65
    printf("Unable to open disc.\n");
 
66
    exit(1);
 
67
  }
 
68
 
 
69
  /* Okay now set up to read up to the first 300 frames of the first
 
70
     audio track of the Audio CD. */
 
71
  { 
 
72
    cdrom_paranoia_t *p = paranoia_init(d);
 
73
    lsn_t i_first_lsn = cdda_disc_firstsector(d);
 
74
 
 
75
    if ( -1 == i_first_lsn ) {
 
76
      printf("Trouble getting starting LSN\n");
 
77
    } else {
 
78
      lsn_t   i_cursor;
 
79
      track_t i_track    = cdda_sector_gettrack(d, i_first_lsn);
 
80
      lsn_t   i_last_lsn = cdda_track_lastsector(d, i_track);
 
81
 
 
82
      /* For demo purposes we'll read only 300 frames (about 4
 
83
         seconds).  We don't want this to take too long. On the other
 
84
         hand, I suppose it should be something close to a real test.
 
85
       */
 
86
      if ( i_last_lsn - i_first_lsn > 300) i_last_lsn = i_first_lsn + 299;
 
87
 
 
88
      printf("Reading track %d from LSN %ld to LSN %ld\n", i_track, 
 
89
             (long int) i_first_lsn, (long int) i_last_lsn);
 
90
 
 
91
      /* Set reading mode for full paranoia, but allow skipping sectors. */
 
92
      paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
 
93
 
 
94
      paranoia_seek(p, i_first_lsn, SEEK_SET);
 
95
 
 
96
      for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
 
97
        /* read a sector */
 
98
        int16_t *p_readbuf=paranoia_read(p, NULL);
 
99
        char *psz_err=cdda_errors(d);
 
100
        char *psz_mes=cdda_messages(d);
 
101
 
 
102
        if (psz_mes || psz_err)
 
103
          printf("%s%s\n", psz_mes ? psz_mes: "", psz_err ? psz_err: "");
 
104
 
 
105
        if (psz_err) free(psz_err);
 
106
        if (psz_mes) free(psz_mes);
 
107
        if( !p_readbuf ) {
 
108
          printf("paranoia read error. Stopping.\n");
 
109
          break;
 
110
        }
 
111
      }
 
112
    }
 
113
    paranoia_free(p);
 
114
  }
 
115
 
 
116
  cdda_close(d);
 
117
 
 
118
  exit(0);
 
119
}