Rename File::seek() to File::lseek() and related derived methods and calls.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 30b73db1c0)
r14.0.x
Michele Calgaro 3 years ago
parent baa3aed9e1
commit 484524f272
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -76,7 +76,7 @@ public:
* Seeks to the position. * Seeks to the position.
* Behaves semantically as lseek. * Behaves semantically as lseek.
*/ */
virtual ssize_t seek(long to, int whence = SEEK_SET) = 0; virtual ssize_t lseek(long to, int whence = SEEK_SET) = 0;
/*! /*!
* Returns current position in file, or negative if unknown. * Returns current position in file, or negative if unknown.
*/ */

@ -53,7 +53,7 @@ LocalFile::~LocalFile() {
bool LocalFile::openRO() { bool LocalFile::openRO() {
if(_fd != -1) { if(_fd != -1) {
return seek(0) && m_readable; return lseek(0) && m_readable;
} }
struct stat stat; struct stat stat;
@ -69,7 +69,7 @@ bool LocalFile::openRO() {
bool LocalFile::openRW() { bool LocalFile::openRW() {
if(_fd != -1) { if(_fd != -1) {
return seek(0) && m_readable && m_writeable; return lseek(0) && m_readable && m_writeable;
} }
struct stat stat; struct stat stat;
@ -84,7 +84,7 @@ bool LocalFile::openRW() {
bool LocalFile::openWO() { bool LocalFile::openWO() {
if(_fd != -1) { if(_fd != -1) {
return seek(0) && m_writeable; return lseek(0) && m_writeable;
} }
_fd = ::open(filename, O_WRONLY); _fd = ::open(filename, O_WRONLY);
@ -115,7 +115,7 @@ long LocalFile::write(const char* ptr, long num) {
return n; return n;
} }
ssize_t LocalFile::seek(long to, int whence) { ssize_t LocalFile::lseek(long to, int whence) {
if(_fd == -1) return -1; if(_fd == -1) return -1;
ssize_t s = ::lseek(_fd, to, whence); ssize_t s = ::lseek(_fd, to, whence);
if (s >= 0) pos = s; if (s >= 0) pos = s;

@ -50,7 +50,7 @@ public:
long read(char* ptr, long num); long read(char* ptr, long num);
long write(const char* ptr, long num); long write(const char* ptr, long num);
ssize_t seek(long to, int whence = SEEK_SET); ssize_t lseek(long to, int whence = SEEK_SET);
long position() const; long position() const;
long length() const; long length() const;

@ -74,7 +74,7 @@ namespace aKode {
Format* detectOgg(File *src, int skip) { Format* detectOgg(File *src, int skip) {
Format *res = 0; Format *res = 0;
char oggmagic[7]; char oggmagic[7];
src->seek(skip+28); src->lseek(skip+28);
src->read(oggmagic, 7); src->read(oggmagic, 7);
for (OggMagic *i = ogg_magic; i->len >0; i++) { for (OggMagic *i = ogg_magic; i->len >0; i++) {
@ -88,11 +88,11 @@ namespace aKode {
string detectRIFF(File *src, int skip) { string detectRIFF(File *src, int skip) {
string res; string res;
char riffmagic[4]; char riffmagic[4];
src->seek(skip+8); src->lseek(skip+8);
src->read(riffmagic, 4); src->read(riffmagic, 4);
if (memcmp(riffmagic, "WAVE",4) == 0) { if (memcmp(riffmagic, "WAVE",4) == 0) {
char wavmagic[2]; char wavmagic[2];
src->seek(skip+20); src->lseek(skip+20);
src->read(wavmagic, 2); src->read(wavmagic, 2);
if (wavmagic[0] == 1) if (wavmagic[0] == 1)
res = "wav"; res = "wav";
@ -109,7 +109,7 @@ namespace aKode {
string detectMPEG(File *src, int skip) { string detectMPEG(File *src, int skip) {
string res; string res;
unsigned char mpegheader[2]; unsigned char mpegheader[2];
src->seek(skip); src->lseek(skip);
src->read((char*)mpegheader, 2); src->read((char*)mpegheader, 2);
if (mpegheader[0] == 0xff && (mpegheader[1] & 0xe0) == 0xe0) // frame synchronizer if (mpegheader[0] == 0xff && (mpegheader[1] & 0xe0) == 0xe0) // frame synchronizer
@ -144,7 +144,7 @@ namespace aKode {
int skip = detectID3v2(src); int skip = detectID3v2(src);
char magic[4]; char magic[4];
src->seek(skip); src->lseek(skip);
src->read(magic, 4); src->read(magic, 4);
if (memcmp(magic, "fLaC", 4) == 0) if (memcmp(magic, "fLaC", 4) == 0)

@ -94,7 +94,7 @@ long MMapFile::write(const char*, long) {
return false; return false;
} }
ssize_t MMapFile::seek(long to, int whence) { ssize_t MMapFile::lseek(long to, int whence) {
if(!handle) return false; if(!handle) return false;
long newpos = 0; long newpos = 0;

@ -47,7 +47,7 @@ public:
long read(char* ptr, long num); long read(char* ptr, long num);
long write(const char*, long); long write(const char*, long);
ssize_t seek(long to, int whence = SEEK_SET); ssize_t lseek(long to, int whence = SEEK_SET);
long position() const; long position() const;
long length() const; long length() const;

@ -34,9 +34,9 @@ bool WavDecoderPlugin::canDecode(File* src) {
bool res = false; bool res = false;
src->openRO(); src->openRO();
if (src->read(header, 4) != 4 || memcmp(header, "RIFF",4) != 0 ) goto close; if (src->read(header, 4) != 4 || memcmp(header, "RIFF",4) != 0 ) goto close;
src->seek(8); src->lseek(8);
if (src->read(header, 4) != 4 || memcmp(header, "WAVE",4) != 0 ) goto close; if (src->read(header, 4) != 4 || memcmp(header, "WAVE",4) != 0 ) goto close;
src->seek(20); src->lseek(20);
if (src->read(header, 2) != 2 || memcmp(header, "\x01\0",2) != 0 ) goto close; if (src->read(header, 2) != 2 || memcmp(header, "\x01\0",2) != 0 ) goto close;
res = true; res = true;
close: close:
@ -77,11 +77,11 @@ bool WavDecoder::openFile(File* src) {
// Get format information // Get format information
unsigned char buffer[4]; unsigned char buffer[4];
src->seek(4); src->lseek(4);
src->read((char*)buffer, 4); // size of stream src->read((char*)buffer, 4); // size of stream
d->length = buffer[0] + buffer[1]*256 + buffer[2] * (1<<16) + buffer[3] * (1<<24) + 8; d->length = buffer[0] + buffer[1]*256 + buffer[2] * (1<<16) + buffer[3] * (1<<24) + 8;
src->seek(16); src->lseek(16);
src->read((char*)buffer, 4); // should really be 16 src->read((char*)buffer, 4); // should really be 16
d->pos = 20 + buffer[0] + buffer[1]*256; d->pos = 20 + buffer[0] + buffer[1]*256;
if (buffer[2] != 0 || buffer[3] != 0) goto invalid; if (buffer[2] != 0 || buffer[3] != 0) goto invalid;
@ -99,7 +99,7 @@ bool WavDecoder::openFile(File* src) {
src->read((char*)buffer, 4); src->read((char*)buffer, 4);
d->config.sample_rate = buffer[0] + buffer[1]*256 + buffer[2] * (1<<16) + buffer[3] * (1<<24); d->config.sample_rate = buffer[0] + buffer[1]*256 + buffer[2] * (1<<16) + buffer[3] * (1<<24);
src->seek(34); src->lseek(34);
src->read((char*)buffer, 2); src->read((char*)buffer, 2);
d->config.sample_width = buffer[0] + buffer[1]*256; d->config.sample_width = buffer[0] + buffer[1]*256;
@ -108,7 +108,7 @@ bool WavDecoder::openFile(File* src) {
if (d->config.sample_rate > 200000) goto invalid; if (d->config.sample_rate > 200000) goto invalid;
find_data: find_data:
src->seek(d->pos); src->lseek(d->pos);
src->read((char*)buffer, 4); src->read((char*)buffer, 4);
if (memcmp(buffer, "data", 4) != 0) if (memcmp(buffer, "data", 4) != 0)
if (memcmp(buffer, "clm ", 4) != 0) if (memcmp(buffer, "clm ", 4) != 0)
@ -119,7 +119,7 @@ find_data:
goto find_data; goto find_data;
} }
src->seek(d->pos+8); // start of data src->lseek(d->pos+8); // start of data
d->position = 0; d->position = 0;
d->valid = true; d->valid = true;
// 1024 samples: // 1024 samples:
@ -219,7 +219,7 @@ bool WavDecoder::seek(long pos) {
long sample_pos = (pos * byterate) / 1000; long sample_pos = (pos * byterate) / 1000;
long byte_pos = sample_pos * samplesize; long byte_pos = sample_pos * samplesize;
if (byte_pos+44 >= d->length) return false; if (byte_pos+44 >= d->length) return false;
if (!d->src->seek(byte_pos+44)) return false; if (!d->src->lseek(byte_pos+44)) return false;
d->pos = byte_pos + 44; d->pos = byte_pos + 44;
return true; return true;
} }

@ -58,7 +58,7 @@ extern "C" {
static off_t akode_seek(void* opaque, off_t pos, int whence) static off_t akode_seek(void* opaque, off_t pos, int whence)
{ {
aKode::File *file = (aKode::File*)opaque; aKode::File *file = (aKode::File*)opaque;
return file->seek(pos, whence); return file->lseek(pos, whence);
} }
} }

@ -48,7 +48,7 @@ public:
m_file->close(); m_file->close();
} }
size_t read ( void *ptr, size_t size ) {return m_file->read((char*)ptr,size);} size_t read ( void *ptr, size_t size ) {return m_file->read((char*)ptr,size);}
bool seek ( int offset, int origin ) {return m_file->seek(offset,origin);} bool seek ( int offset, int origin ) {return m_file->lseek(offset,origin);}
long tell () {return m_file->position();} long tell () {return m_file->position();}
long get_size () {return m_file->length();} long get_size () {return m_file->length();}
bool canseek() {return m_file->seekable();} bool canseek() {return m_file->seekable();}

@ -52,7 +52,7 @@ bool MPEGDecoderPlugin::canDecode(File* src) {
size += buf[4] << 7; size += buf[4] << 7;
size += buf[3] << 14; size += buf[3] << 14;
size += buf[2] << 21; size += buf[2] << 21;
src->seek(10+size); src->lseek(10+size);
src->read(header, 4); src->read(header, 4);
} }
if (buf[0] == 0xff && (buf[1] & 14)) // frame synchronizer if (buf[0] == 0xff && (buf[1] & 14)) // frame synchronizer
@ -142,7 +142,7 @@ MPEGDecoder::~MPEGDecoder() {
} }
bool MPEGDecoder::skipID3v2() { bool MPEGDecoder::skipID3v2() {
m_data->src->seek(0); m_data->src->lseek(0);
m_data->id3v2size = 0; m_data->id3v2size = 0;
char buf[16]; char buf[16];
if (m_data->src->read(buf, 10)) { if (m_data->src->read(buf, 10)) {
@ -158,7 +158,7 @@ bool MPEGDecoder::skipID3v2() {
size += buf[7] << 14; size += buf[7] << 14;
size += buf[6] << 21; size += buf[6] << 21;
m_data->id3v2size = size; m_data->id3v2size = size;
if (!m_data->src->seek(10+size)) { if (!m_data->src->lseek(10+size)) {
char space[256]; char space[256];
for(int i=0; i<size; ) { for(int i=0; i<size; ) {
i += m_data->src->read(space, (size-i) > 256 ? 256 : (size-i)); i += m_data->src->read(space, (size-i) > 256 ? 256 : (size-i));
@ -167,7 +167,7 @@ bool MPEGDecoder::skipID3v2() {
return true; return true;
} }
} }
if (!m_data->src->seek(0)) { if (!m_data->src->lseek(0)) {
mad_stream_buffer(&m_data->stream, (uint8_t*)buf, 10); mad_stream_buffer(&m_data->stream, (uint8_t*)buf, 10);
} }
return false; return false;
@ -542,7 +542,7 @@ bool MPEGDecoder::seek(long pos) {
#ifdef MPEG_DEBUG #ifdef MPEG_DEBUG
cerr << "TOC seeking " << procent << "/100 -> " << (long)(place*256.0) << "/256\n" ; cerr << "TOC seeking " << procent << "/100 -> " << (long)(place*256.0) << "/256\n" ;
#endif #endif
res = m_data->src->seek(bpos); res = m_data->src->lseek(bpos);
if (res) if (res)
m_data->position = (long)(((float)procent/100.0)*mpeg_length(m_data)*m_data->config.sample_rate); m_data->position = (long)(((float)procent/100.0)*mpeg_length(m_data)*m_data->config.sample_rate);
} }
@ -552,7 +552,7 @@ bool MPEGDecoder::seek(long pos) {
#endif #endif
long bpos = (long)((((float)pos)*m_data->bitrate)/8000.0); long bpos = (long)((((float)pos)*m_data->bitrate)/8000.0);
bpos += m_data->id3v2size; bpos += m_data->id3v2size;
res = m_data->src->seek(bpos); res = m_data->src->lseek(bpos);
if (res) if (res)
m_data->position = (long)(((float)pos*(float)m_data->config.sample_rate)/1000.0); m_data->position = (long)(((float)pos*(float)m_data->config.sample_rate)/1000.0);
} }

@ -41,7 +41,7 @@ class FLACDecoder;
static bool checkFLAC(File *src) { static bool checkFLAC(File *src) {
char header[6]; char header[6];
bool res = false; bool res = false;
src->seek(0); src->lseek(0);
if(src->read(header, 4) == 4) { if(src->read(header, 4) == 4) {
// skip id3v2 headers // skip id3v2 headers
if (memcmp(header, "ID3", 3) == 0) { if (memcmp(header, "ID3", 3) == 0) {
@ -52,7 +52,7 @@ static bool checkFLAC(File *src) {
size += header[4] << 7; size += header[4] << 7;
size += header[3] << 14; size += header[3] << 14;
size += header[2] << 21; size += header[2] << 21;
src->seek(10+size); src->lseek(10+size);
if (src->read(header, 4) != 4) goto end; if (src->read(header, 4) != 4) goto end;
} }
if (memcmp(header, "fLaC",4) == 0 ) res = true; if (memcmp(header, "fLaC",4) == 0 ) res = true;
@ -64,7 +64,7 @@ end:
static bool checkOggFLAC(File *src) { static bool checkOggFLAC(File *src) {
char header[34]; char header[34];
bool res = false; bool res = false;
src->seek(0); src->lseek(0);
if (src->read(header, 34) == 34) if (src->read(header, 34) == 34)
if (memcmp(header, "OggS",4) == 0 ) if (memcmp(header, "OggS",4) == 0 )
// old FLAC 1.1.0 format // old FLAC 1.1.0 format
@ -134,7 +134,7 @@ static FLAC__StreamDecoderSeekStatus flac_seek_callback(
{ {
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data;
if(data->source->seek(absolute_byte_offset)) if(data->source->lseek(absolute_byte_offset))
return FLAC__STREAM_DECODER_SEEK_STATUS_OK; return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
else else
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;

@ -327,7 +327,7 @@ bool SpeexDecoder::seek(long pos) {
if(!m_data->initialized) return false; if(!m_data->initialized) return false;
long bpos = (long)(((float)pos*(float)m_data->bitrate)/8000.0); long bpos = (long)(((float)pos*(float)m_data->bitrate)/8000.0);
if (m_data->src->seek(bpos)) { if (m_data->src->lseek(bpos)) {
speex_bits_reset(&m_data->bits); speex_bits_reset(&m_data->bits);
ogg_sync_reset(&m_data->sync); ogg_sync_reset(&m_data->sync);
ogg_stream_reset(&m_data->stream); ogg_stream_reset(&m_data->stream);

@ -39,7 +39,7 @@ static size_t _read(void *ptr, size_t size, size_t nmemb, void *datasource) {
static int _seek(void *datasource, ogg_int64_t offset, int whence) { static int _seek(void *datasource, ogg_int64_t offset, int whence) {
File *src = (File*)datasource; File *src = (File*)datasource;
if (src->seek(offset, whence)) if (src->lseek(offset, whence))
return 0; return 0;
else else
return -1; return -1;

Loading…
Cancel
Save