~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/oggvorbis/vorbisInfo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  info about vorbis files.
 
3
  Copyright (C) 2001  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "vorbisInfo.h"
 
15
 
 
16
#ifdef OGG_VORBIS
 
17
#define CHUNKSIZE 4096
 
18
 
 
19
#define GETINPUT(stream,input)                                            \
 
20
                               VorbisInfo* info=(VorbisInfo*) stream;     \
 
21
                               FileAccess* input=info->getInput();   
 
22
 
 
23
 
 
24
size_t fread_func2(void *ptr, size_t size, size_t nmemb, void *stream) {
 
25
  GETINPUT(stream,input);
 
26
 
 
27
  size_t want=size*nmemb;
 
28
  size_t back=input->read((char*)ptr,want);
 
29
  return back;
 
30
}
 
31
 
 
32
 
 
33
int fseek_func2(void *stream, ogg_int64_t offset, int whence) {
 
34
  int ret;
 
35
  GETINPUT(stream,input);
 
36
 
 
37
  if (whence==SEEK_SET) {
 
38
    ret=input->seek(offset);
 
39
    info->setSeekPos(offset);
 
40
    return ret;
 
41
  }
 
42
  if (whence==SEEK_CUR) {
 
43
    ret=input->seek(input->getBytePosition()+offset);
 
44
    return ret;
 
45
  }  
 
46
  if (whence==SEEK_END) {
 
47
    ret=input->seek(input->getByteLength());
 
48
    return ret;
 
49
  }   
 
50
  cout << "hm, strange call"<<endl;
 
51
  return -1;
 
52
}
 
53
 
 
54
 
 
55
int fclose_func2 (void * stream) {
 
56
  cout << "fclose_func"<<endl;
 
57
  GETINPUT(stream,input);
 
58
  // its handled different in kmpg
 
59
  // we close the stream if the decoder signals eof.
 
60
  return true;
 
61
 
 
62
}
 
63
 
 
64
 
 
65
long ftell_func2  (void *stream) {
 
66
  GETINPUT(stream,input);
 
67
  return input->getBytePosition();
 
68
}
 
69
 
 
70
 
 
71
 
 
72
 
 
73
VorbisInfo::VorbisInfo(FileAccess* input) {
 
74
  this->input=input;
 
75
  vf=new OggVorbis_File();
 
76
 
 
77
  ov_callbacks callbacks;
 
78
 
 
79
  callbacks.read_func  = fread_func2;
 
80
  callbacks.seek_func  = fseek_func2;
 
81
  callbacks.close_func = fclose_func2;
 
82
  callbacks.tell_func  = ftell_func2;
 
83
 
 
84
  if(ov_open_callbacks(this, vf, NULL, 0, callbacks) < 0) {
 
85
    cout << "error ov_open_callbacks"<<endl;
 
86
  }
 
87
  
 
88
  // now init stream
 
89
  vi=ov_info(vf,-1);
 
90
  lastSeekPos=0;
 
91
}
 
92
 
 
93
 
 
94
VorbisInfo::~VorbisInfo() {
 
95
  delete vf;
 
96
  if (vi != NULL) {
 
97
    //?
 
98
  }
 
99
}
 
100
 
 
101
 
 
102
long VorbisInfo::getSeekPosition(int seconds) {
 
103
  int back=0;
 
104
  if (vi != NULL) {
 
105
    lastSeekPos=0;
 
106
    ov_time_seek(vf,seconds);
 
107
    back=lastSeekPos;
 
108
  }
 
109
  return back;
 
110
}
 
111
 
 
112
 
 
113
long VorbisInfo::getLength() {
 
114
  int back=0;
 
115
  if (vi != NULL) {
 
116
    back = (int) ov_time_total(vf, -1);
 
117
  }
 
118
  return back;
 
119
}
 
120
 
 
121
 
 
122
 
 
123
 
 
124
void VorbisInfo::print(const char* msg) {
 
125
  cout << "VorbisInfo:"<<msg<<endl;
 
126
  cout << "Length (sec):"<<getLength()<<endl;
 
127
 
 
128
}
 
129
 
 
130
 
 
131
void VorbisInfo::setSeekPos(long pos) {
 
132
  this->lastSeekPos=pos;
 
133
}
 
134
 
 
135
 
 
136
long VorbisInfo::getSeekPos() {
 
137
  return lastSeekPos;
 
138
}
 
139
 
 
140
FileAccess* VorbisInfo::getInput() {
 
141
  return input;
 
142
}
 
143
 
 
144
 
 
145
 
 
146
#endif