Skip to content

Commit

Permalink
MythIOWrapper: Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-kendall committed Apr 9, 2020
1 parent 490e0b1 commit 28cb27b
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 347 deletions.
10 changes: 5 additions & 5 deletions mythtv/external/libmythdvdnav/dvdnav/vm/vm.c
Expand Up @@ -154,12 +154,12 @@ static int dvd_read_name(char *name, char *serial, const char *device) {
fprintf(MSG_OUT, "libdvdnav: Device name string NULL\n");
goto fail;
}
if ((fd = mythfile_open(device, O_RDONLY)) == -1) {
if ((fd = MythFileOpen(device, O_RDONLY)) == -1) {
fprintf(MSG_OUT, "libdvdnav: Unable to open device file %s.\n", device);
goto fail;
}

if ((off = mythfile_seek( fd, 32 * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET )) == (off_t) - 1) {
if ((off = MythFileSeek( fd, 32 * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET )) == (off_t) - 1) {
fprintf(MSG_OUT, "libdvdnav: Unable to seek to the title block %u.\n", 32);
goto fail;
}
Expand All @@ -169,12 +169,12 @@ static int dvd_read_name(char *name, char *serial, const char *device) {
goto fail;
}

if ((read_size = mythfile_read( fd, data, DVD_VIDEO_LB_LEN )) == -1) {
if ((read_size = MythFileRead( fd, data, DVD_VIDEO_LB_LEN )) == -1) {
fprintf(MSG_OUT, "libdvdnav: Can't read name block. Probably not a DVD-ROM device.\n");
goto fail;
}

mythfile_close(fd);
MythfileClose(fd);
fd = -1;
if (read_size != DVD_VIDEO_LB_LEN) {
fprintf(MSG_OUT, "libdvdnav: Can't read name block. Probably not a DVD-ROM device.\n");
Expand Down Expand Up @@ -217,7 +217,7 @@ static int dvd_read_name(char *name, char *serial, const char *device) {

fail:
if (fd >= 0)
mythfile_close(fd);
MythfileClose(fd);

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions mythtv/external/libmythdvdnav/dvdread/dvd_input.c
Expand Up @@ -176,7 +176,7 @@ static dvd_input_t file_open(const char *target,

/* Open the device */
#if !defined(WIN32) && !defined(__OS2__)
dev->fd = mythfile_open(target, O_RDONLY);
dev->fd = MythFileOpen(target, O_RDONLY);
#else
dev->fd = mythfile_open(target, O_RDONLY | O_BINARY);
#endif
Expand All @@ -197,7 +197,7 @@ static int file_seek(dvd_input_t dev, int blocks, int flags)
off_t pos;
(void)flags;

pos = mythfile_seek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
pos = MythFileSeek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
if(pos < 0) {
return pos;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ static int file_read(dvd_input_t dev, void *buffer, int blocks,
bytes = 0;

while(len > 0) {
ssize_t ret = mythfile_read(dev->fd, ((char*)buffer) + bytes, len);
ssize_t ret = MythFileRead(dev->fd, ((char*)buffer) + bytes, len);

if(ret < 0) {
/* One of the reads failed, too bad. We won't even bother
Expand All @@ -238,7 +238,7 @@ static int file_read(dvd_input_t dev, void *buffer, int blocks,
/* Nothing more to read. Return all of the whole blocks, if any.
* Adjust the file position back to the previous block boundary. */
off_t over_read = -(bytes % DVD_VIDEO_LB_LEN);
off_t pos = mythfile_seek(dev->fd, over_read, SEEK_CUR);
off_t pos = MythFileSeek(dev->fd, over_read, SEEK_CUR);
if(pos % 2048 != 0)
fprintf( stderr, "libdvdread: lseek not multiple of 2048! Something is wrong!\n" );
return (int) (bytes / DVD_VIDEO_LB_LEN);
Expand All @@ -258,7 +258,7 @@ static int file_close(dvd_input_t dev)
{
int ret;

ret = mythfile_close(dev->fd);
ret = MythfileClose(dev->fd);

free(dev);

Expand Down
16 changes: 8 additions & 8 deletions mythtv/external/libmythdvdnav/dvdread/dvd_reader.c
Expand Up @@ -379,7 +379,7 @@ static dvd_reader_t *DVDOpenCommon( const char *ppath,
}
#endif

ret = mythfile_stat( path, &fileinfo );
ret = MythFileStat( path, &fileinfo );

if( ret < 0 ) {

Expand Down Expand Up @@ -697,7 +697,7 @@ static int findDirFile( const char *path, const char *file, char *filename )
DIR *dir;
struct dirent *ent;

if (!strncmp(path, "myth://", 7) && mythfile_exists(path, file))
if (!strncmp(path, "myth://", 7) && MythFileExists(path, file))
{
sprintf( filename, "%s%s%s", path,
( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
Expand Down Expand Up @@ -820,7 +820,7 @@ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, const char *filename )
}
dvd_file->dvd = dvd;

if( mythfile_stat( full_path, &fileinfo ) < 0 ) {
if( MythFileStat( full_path, &fileinfo ) < 0 ) {
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
free( dvd_file );
dvdinput_close( dev );
Expand Down Expand Up @@ -910,7 +910,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
return NULL;
}

if( mythfile_stat( full_path, &fileinfo ) < 0 ) {
if( MythFileStat( full_path, &fileinfo ) < 0 ) {
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
dvdinput_close(dev);
free( dvd_file );
Expand All @@ -931,7 +931,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
break;
}

if( mythfile_stat( full_path, &fileinfo ) < 0 ) {
if( MythFileStat( full_path, &fileinfo ) < 0 ) {
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
break;
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
if( !findDVDFile( dvd, filename, full_path ) )
return -1;

if( mythfile_stat( full_path, &fileinfo ) < 0 ) {
if( MythFileStat( full_path, &fileinfo ) < 0 ) {
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
return -1;
}
Expand All @@ -1103,7 +1103,7 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
if( !findDVDFile( dvd, filename, full_path ) )
break;

if( mythfile_stat( full_path, &fileinfo ) < 0 ) {
if( MythFileStat( full_path, &fileinfo ) < 0 ) {
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
break;
}
Expand Down Expand Up @@ -1185,7 +1185,7 @@ int DVDFileStat( dvd_reader_t *dvd, int titlenum,
char full_path[ PATH_MAX + 1 ];

if( findDVDFile( dvd, filename, full_path ) ) {
if( mythfile_stat( full_path, &fileinfo ) < 0 )
if( MythFileStat( full_path, &fileinfo ) < 0 )
fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
else {
statbuf->size = fileinfo.st_size;
Expand Down
18 changes: 9 additions & 9 deletions mythtv/libs/libmythtv/Bluray/bdiowrapper.cpp
Expand Up @@ -26,7 +26,7 @@ static void dir_close_mythiowrapper(BD_DIR_H *dir)
{
if (dir)
{
mythdir_closedir((int)(intptr_t)dir->internal);
MythDirClose((int)(intptr_t)dir->internal);

LOG(VB_FILE, LOG_DEBUG, LOC + "Closed mythdir dir");

Expand All @@ -36,7 +36,7 @@ static void dir_close_mythiowrapper(BD_DIR_H *dir)

static int dir_read_mythiowrapper(BD_DIR_H *dir, BD_DIRENT *entry)
{
char *filename = mythdir_readdir((int)(intptr_t)dir->internal);
char *filename = MythDirRead((int)(intptr_t)dir->internal);
if (filename)
{
entry->d_name[255] = '\0';
Expand Down Expand Up @@ -64,7 +64,7 @@ static BD_DIR_H *dir_open_mythiowrapper(const char* dirname)
dir->read = dir_read_mythiowrapper;

int dirID = 0;
if ((dirID = mythdir_opendir(dirname)))
if ((dirID = MythDirOpen(dirname)))
{
dir->internal = (void *)(intptr_t)dirID;
return dir;
Expand All @@ -82,7 +82,7 @@ static void file_close_mythiowrapper(BD_FILE_H *file)
{
if (file)
{
mythfile_close((int)(intptr_t)file->internal);
MythfileClose((int)(intptr_t)file->internal);

LOG(VB_FILE, LOG_DEBUG, LOC + "Closed mythfile file");

Expand All @@ -92,22 +92,22 @@ static void file_close_mythiowrapper(BD_FILE_H *file)

static int64_t file_seek_mythiowrapper(BD_FILE_H *file, int64_t offset, int32_t origin)
{
return mythfile_seek((int)(intptr_t)file->internal, offset, origin);
return MythFileSeek((int)(intptr_t)file->internal, offset, origin);
}

static int64_t file_tell_mythiowrapper(BD_FILE_H *file)
{
return mythfile_tell((int)(intptr_t)file->internal);
return MythFileTell((int)(intptr_t)file->internal);
}

static int64_t file_read_mythiowrapper(BD_FILE_H *file, uint8_t *buf, int64_t size)
{
return mythfile_read((int)(intptr_t)file->internal, buf, size);
return MythFileRead((int)(intptr_t)file->internal, buf, size);
}

static int64_t file_write_mythiowrapper(BD_FILE_H *file, const uint8_t *buf, int64_t size)
{
return mythfile_write((int)(intptr_t)file->internal, (void *)buf, size);
return MythFileWrite((int)(intptr_t)file->internal, (void *)buf, size);
}

static BD_FILE_H *file_open_mythiowrapper(const char* filename, const char *cmode)
Expand All @@ -134,7 +134,7 @@ static BD_FILE_H *file_open_mythiowrapper(const char* filename, const char *cmod
if (strcasecmp(cmode, "wb") == 0)
intMode = O_WRONLY;

if ((fd = mythfile_open(filename, intMode)) >= 0)
if ((fd = MythFileOpen(filename, intMode)) >= 0)
{
file->internal = (void*)(intptr_t)fd;

Expand Down
24 changes: 12 additions & 12 deletions mythtv/libs/libmythtv/Bluray/bdringbuffer.cpp
Expand Up @@ -127,8 +127,8 @@ static void BDLogger(const char* Message)

static int BDRead(void *Handle, void *Buf, int LBA, int NumBlocks)
{
if (mythfile_seek(*(static_cast<int*>(Handle)), LBA * 2048LL, SEEK_SET) != -1)
return static_cast<int>(mythfile_read(*(static_cast<int*>(Handle)), Buf,
if (MythFileSeek(*(static_cast<int*>(Handle)), LBA * 2048LL, SEEK_SET) != -1)
return static_cast<int>(MythFileRead(*(static_cast<int*>(Handle)), Buf,
static_cast<size_t>(NumBlocks * 2048)) / 2048);
return -1;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ BDInfo::BDInfo(const QString &Filename)
// Since a local device (which is likely to be encrypted) can be
// opened directly, only use streaming for remote images, which
// presumably won't be encrypted.
bdhandle = mythfile_open(Filename.toLocal8Bit().data(), O_RDONLY);
bdhandle = MythFileOpen(Filename.toLocal8Bit().data(), O_RDONLY);
if (bdhandle >= 0)
{
bdnav = bd_init();
Expand All @@ -199,7 +199,7 @@ BDInfo::BDInfo(const QString &Filename)
}

if (bdhandle >= 0)
mythfile_close(bdhandle);
MythfileClose(bdhandle);

LOG(VB_PLAYBACK, LOG_INFO, QString("BDInfo: Done"));
}
Expand Down Expand Up @@ -303,7 +303,7 @@ void BDRingBuffer::Close(void)

if (m_imgHandle > 0)
{
mythfile_close(m_imgHandle);
MythfileClose(m_imgHandle);
m_imgHandle = -1;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
// several minutes when the disc structure is remote. The callback allows
// us to 'kick' the main UI - as the 'please wait' widget is still visible
// at this stage
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, FileOpenedCallback);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, FileOpenedCallback);

QMutexLocker locker(&m_infoLock);
m_rwLock.lockForWrite();
Expand All @@ -510,7 +510,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
// Since a local device (which is likely to be encrypted) can be
// opened directly, only use streaming for remote images, which
// presumably won't be encrypted.
m_imgHandle = mythfile_open(filename.toLocal8Bit().data(), O_RDONLY);
m_imgHandle = MythFileOpen(filename.toLocal8Bit().data(), O_RDONLY);
if (m_imgHandle >= 0)
{
m_bdnav = bd_init();
Expand All @@ -527,7 +527,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
{
m_lastError = tr("Could not open Blu-ray device: %1").arg(filename);
m_rwLock.unlock();
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, nullptr);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, nullptr);
return false;
}

Expand Down Expand Up @@ -557,7 +557,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
m_bdnav = nullptr;
m_lastError = tr("Could not open Blu-ray device %1, failed to decrypt").arg(filename);
m_rwLock.unlock();
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, nullptr);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, nullptr);
return false;
}

Expand Down Expand Up @@ -597,7 +597,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
m_bdnav = nullptr;
m_lastError = tr("Unable to find any Blu-ray compatible titles");
m_rwLock.unlock();
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, nullptr);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, nullptr);
return false;
}

Expand Down Expand Up @@ -701,7 +701,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
m_bdnav = nullptr;
m_lastError = tr("Unable to find any usable Blu-ray titles");
m_rwLock.unlock();
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, nullptr);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, nullptr);
return false;
}
SwitchTitle(m_mainTitle);
Expand All @@ -715,7 +715,7 @@ bool BDRingBuffer::OpenFile(const QString &Filename, uint /*Retry*/)
m_rawBitrate = 8000;
CalcReadAheadThresh();
m_rwLock.unlock();
mythfile_open_register_callback(filename.toLocal8Bit().data(), this, nullptr);
MythFileOpenRegisterCallback(filename.toLocal8Bit().data(), this, nullptr);
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/DVD/mythdvdinfo.cpp
Expand Up @@ -68,7 +68,7 @@ void MythDVDInfo::GetNameAndSerialNum(dvdnav_t* Nav,
if (Name.isEmpty() && Serialnum.isEmpty())
{
struct stat stat {};
if ((mythfile_stat(Filename.toLocal8Bit(), &stat) == 0) && S_ISDIR(stat.st_mode))
if ((MythFileStat(Filename.toLocal8Bit(), &stat) == 0) && S_ISDIR(stat.st_mode))
{
// Name and serial number are empty because we're reading
// from a directory (and not a device or image).
Expand All @@ -81,18 +81,18 @@ void MythDVDInfo::GetNameAndSerialNum(dvdnav_t* Nav,

// And use the CRC of VTS_01_0.IFO as a serial number
QString ifo = Filename + QString("/VIDEO_TS/VTS_01_0.IFO");
int fd = mythfile_open(ifo.toLocal8Bit(), O_RDONLY);
int fd = MythFileOpen(ifo.toLocal8Bit(), O_RDONLY);

if (fd > 0)
{
uint8_t buf[2048];
ssize_t read = 0;
uint32_t crc = static_cast<uint32_t>(crc32(0L, Z_NULL, 0));

while((read = mythfile_read(fd, buf, sizeof(buf))) > 0)
while((read = MythFileRead(fd, buf, sizeof(buf))) > 0)
crc = static_cast<uint32_t>(crc32(crc, buf, static_cast<uint>(read)));

mythfile_close(fd);
MythfileClose(fd);
Serialnum = QString("%1__gen").arg(crc, 0, 16, QChar('0'));
LOG(VB_PLAYBACK, LOG_DEBUG, LogPrefix + QString("Generated serial number '%1'")
.arg(Serialnum));
Expand Down

0 comments on commit 28cb27b

Please sign in to comment.