Mercurial > hg > svcore
comparison data/fileio/OggVorbisFileReader.cpp @ 265:e08f486e8d8c
* Enable threaded decoding for Ogg and MP3 files.
Needs some work on reducing updates to the overview widget
author | Chris Cannam |
---|---|
date | Wed, 06 Jun 2007 16:24:55 +0000 |
parents | 71dfc6ab3b54 |
children | 822bd7fd526c |
comparison
equal
deleted
inserted
replaced
264:260032c26c4f | 265:e08f486e8d8c |
---|---|
39 m_path(path), | 39 m_path(path), |
40 m_progress(0), | 40 m_progress(0), |
41 m_fileSize(0), | 41 m_fileSize(0), |
42 m_bytesRead(0), | 42 m_bytesRead(0), |
43 m_cancelled(false), | 43 m_cancelled(false), |
44 m_completion(0), | |
44 m_decodeThread(0) | 45 m_decodeThread(0) |
45 { | 46 { |
46 m_frameCount = 0; | 47 m_frameCount = 0; |
47 m_channelCount = 0; | 48 m_channelCount = 0; |
48 m_sampleRate = 0; | 49 m_sampleRate = 0; |
100 | 101 |
101 OggVorbisFileReader::~OggVorbisFileReader() | 102 OggVorbisFileReader::~OggVorbisFileReader() |
102 { | 103 { |
103 std::cerr << "OggVorbisFileReader::~OggVorbisFileReader(" << m_path.toLocal8Bit().data() << "): now have " << (--instances) << " instances" << std::endl; | 104 std::cerr << "OggVorbisFileReader::~OggVorbisFileReader(" << m_path.toLocal8Bit().data() << "): now have " << (--instances) << " instances" << std::endl; |
104 if (m_decodeThread) { | 105 if (m_decodeThread) { |
106 m_cancelled = true; | |
105 m_decodeThread->wait(); | 107 m_decodeThread->wait(); |
106 delete m_decodeThread; | 108 delete m_decodeThread; |
107 } | 109 } |
108 } | 110 } |
109 | 111 |
116 m_reader->m_fishSound = 0; | 118 m_reader->m_fishSound = 0; |
117 oggz_close(m_reader->m_oggz); | 119 oggz_close(m_reader->m_oggz); |
118 m_reader->m_oggz = 0; | 120 m_reader->m_oggz = 0; |
119 | 121 |
120 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); | 122 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache(); |
123 m_reader->m_completion = 100; | |
121 } | 124 } |
122 | 125 |
123 int | 126 int |
124 OggVorbisFileReader::readPacket(OGGZ *, ogg_packet *packet, long, void *data) | 127 OggVorbisFileReader::readPacket(OGGZ *, ogg_packet *packet, long, void *data) |
125 { | 128 { |
128 | 131 |
129 fish_sound_prepare_truncation(fs, packet->granulepos, packet->e_o_s); | 132 fish_sound_prepare_truncation(fs, packet->granulepos, packet->e_o_s); |
130 fish_sound_decode(fs, packet->packet, packet->bytes); | 133 fish_sound_decode(fs, packet->packet, packet->bytes); |
131 | 134 |
132 reader->m_bytesRead += packet->bytes; | 135 reader->m_bytesRead += packet->bytes; |
136 | |
137 // The number of bytes read by this function is smaller than | |
138 // the file size because of the packet headers | |
139 int progress = lrint(double(reader->m_bytesRead) * 114 / | |
140 double(reader->m_fileSize)); | |
141 if (progress > 99) progress = 99; | |
142 reader->m_completion = progress; | |
133 | 143 |
134 if (reader->m_fileSize > 0 && reader->m_progress) { | 144 if (reader->m_fileSize > 0 && reader->m_progress) { |
135 // The number of bytes read by this function is smaller than | |
136 // the file size because of the packet headers | |
137 int progress = lrint(double(reader->m_bytesRead) * 114 / | |
138 double(reader->m_fileSize)); | |
139 if (progress > 99) progress = 99; | |
140 if (progress > reader->m_progress->value()) { | 145 if (progress > reader->m_progress->value()) { |
141 reader->m_progress->setValue(progress); | 146 reader->m_progress->setValue(progress); |
142 reader->m_progress->show(); | 147 reader->m_progress->show(); |
143 reader->m_progress->raise(); | 148 reader->m_progress->raise(); |
144 qApp->processEvents(); | 149 qApp->processEvents(); |
145 if (reader->m_progress->wasCanceled()) { | 150 if (reader->m_progress->wasCanceled()) { |
146 reader->m_cancelled = true; | 151 reader->m_cancelled = true; |
147 } | 152 } |
148 } | 153 } |
149 } | 154 } |
150 | 155 |
151 if (reader->m_cancelled) return 1; | 156 if (reader->m_cancelled) return 1; |
152 return 0; | 157 return 0; |
153 } | 158 } |
154 | 159 |