summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/input/cdromRawAccess.cpp
blob: e23158f62cbac1e90f08c1eb19ff46358e6d4280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
  reads raw input data from cdrom (system dependent)
  Copyright (C) 1999  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#include <iostream>

#include "cdromRawAccess.h"

using namespace std;

CDRomRawAccess::CDRomRawAccess(CDRomToc* cdromToc) {
  cdfile=NULL;
  lOpen=false;
  leof=true;
  this->cdromToc=cdromToc;
  lData=false;
  dataStart=0;
  len=0;
}


CDRomRawAccess::~CDRomRawAccess() {
  close();
}



char* CDRomRawAccess::getBufferStart() {
  return (char*)(data+dataStart);
}

int CDRomRawAccess::getBufferLen() {
  if (eof()) {
    return 0;
  }
  return len;
}

int CDRomRawAccess::open(const char* filename) {
  if (isOpen()) {
    close();
  }
  if (filename==NULL) {
    filename=(char*)"/dev/cdrom";
  }
  if (strlen(filename) <= 1) {
    filename="/dev/cdrom";
  } 
  const char* openfile=strchr(filename,'/');
  cout << "openfile:"<<openfile<<endl;
  cdfile=fopen(openfile, "rb");
  lOpen=false;

  if (cdfile == NULL) {
    perror("open CDRomRawAccess");
  } else {
    lOpen=true;  
    leof=false;
  }
  return lOpen;
}


int CDRomRawAccess::eof() {
  return leof;
}


int CDRomRawAccess::read(int minute,int second, int frame) {
  if (isOpen()==false) {
    cerr << "CDRomRawAccess not open"<<endl;
    return false;
  }

  int lInRange=cdromToc->isInRange(minute,second,frame);
  if (lInRange == false) {
    if (minute*60+second+1 > cdromToc->getEndSecond()) {
      leof=true;
    }
    return false;
  }
  return readDirect(minute,second,frame);
}


void CDRomRawAccess::close() {
  if (isOpen()) {
    fclose(cdfile);
    lOpen=false;
    leof=true;
  }
}

int CDRomRawAccess::isData() {
  return lData;
}

int CDRomRawAccess::isOpen() {
  return lOpen;
}