From 0040b84139b6f08f08f696c3c91dde9bc0cf2f86 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Sun, 11 Jan 2009 13:04:17 +0100 Subject: simplify Dxr3Open We dont need to give the used cardnum as param for Dxr3Open, as Dxr3Open will get the used cardnum by its own. --- dxr3interface.c | 51 +++++++++------------------------------------------ dxr3interface.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/dxr3interface.c b/dxr3interface.c index 9a10035..91d6601 100644 --- a/dxr3interface.c +++ b/dxr3interface.c @@ -41,29 +41,6 @@ static const char *DEV_DXR3_VIDEO = "_mv"; static const char *DEV_DXR3_OSS = "_ma"; static const char *DEV_DXR3_CONT = ""; -// ================================== -//! helper function to generate name -static const char *Dxr3Name(const char *Name, int n) -{ - static char buffer[PATH_MAX]; - snprintf(buffer, sizeof(buffer), "/dev/em8300%s-%d", Name, n); - return buffer; -} - -// ================================== -//! helper function to open card #n -static int Dxr3Open(const char *Name, int n, int Mode) -{ - const char *FileName = Dxr3Name(Name, n); - int fd = open(FileName, Mode); - - if (fd == -1) - { - esyslog("dxr3: unable to open %s: %m", FileName); - } - return fd; -} - // ================================== //! constructor cDxr3Interface::cDxr3Interface() : @@ -674,8 +651,7 @@ void cDxr3Interface::PlayAudioLpcmFrame(uint8_t* pBuf, int length) void cDxr3Interface::ClaimDevices() { // open control stream - m_fdControl = Dxr3Open(DEV_DXR3_CONT, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); + m_fdControl = Dxr3Open(DEV_DXR3_CONT, O_WRONLY | O_SYNC); if (m_fdControl == -1) { esyslog("dxr3: please verify that the em8300 modules are loaded"); @@ -686,12 +662,9 @@ void cDxr3Interface::ClaimDevices() UploadMicroCode(); ///< open multimedia streams - m_fdVideo = Dxr3Open(DEV_DXR3_VIDEO, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); - m_fdAudio = Dxr3Open(DEV_DXR3_OSS, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); - m_fdSpu = Dxr3Open(DEV_DXR3_OSD, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); + m_fdVideo = Dxr3Open(DEV_DXR3_VIDEO, O_WRONLY | O_SYNC); + m_fdAudio = Dxr3Open(DEV_DXR3_OSS, O_WRONLY | O_SYNC); + m_fdSpu = Dxr3Open(DEV_DXR3_OSD, O_WRONLY | O_SYNC); // everything ok? if (m_fdVideo == -1 || m_fdAudio == -1 || m_fdSpu == -1) @@ -791,16 +764,12 @@ void cDxr3Interface::ExternalReopenDevices() if (m_ExternalReleased) { // open control stream - m_fdControl = Dxr3Open(DEV_DXR3_CONT, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); + m_fdControl = Dxr3Open(DEV_DXR3_CONT, O_WRONLY | O_SYNC); // open 'multimedia' streams - m_fdVideo = Dxr3Open(DEV_DXR3_VIDEO, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); - m_fdAudio = Dxr3Open(DEV_DXR3_OSS, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); - m_fdSpu = Dxr3Open(DEV_DXR3_OSD, cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); + m_fdVideo = Dxr3Open(DEV_DXR3_VIDEO, O_WRONLY | O_SYNC); + m_fdAudio = Dxr3Open(DEV_DXR3_OSS, O_WRONLY | O_SYNC); + m_fdSpu = Dxr3Open(DEV_DXR3_OSD, O_WRONLY | O_SYNC); if (m_fdControl == -1 || m_fdVideo == -1 || m_fdAudio == -1 || m_fdSpu == -1) @@ -870,9 +839,7 @@ void cDxr3Interface::ReOpenAudio() delete m_pClock; close(m_fdAudio); - m_fdAudio = Dxr3Open("_ma", - cDxr3ConfigData::Instance().GetDxr3Card(), - O_WRONLY | O_SYNC); + m_fdAudio = Dxr3Open(DEV_DXR3_OSS, O_WRONLY | O_SYNC); uint32_t tmpAudioDataRate = m_audioDataRate; uint32_t tmpAudioChannelCount = m_audioChannelCount; diff --git a/dxr3interface.h b/dxr3interface.h index 6222e9e..7229b55 100644 --- a/dxr3interface.h +++ b/dxr3interface.h @@ -31,10 +31,22 @@ #include "dxr3vdrincludes.h" #include "dxr3configdata.h" #include "dxr3sysclock.h" +#include "dxr3configdata.h" // ================================== class cFixedLengthFrame; +class cDxr3Name { +public: + cDxr3Name(const char *name, int n) { + snprintf(buffer, sizeof(buffer), "%s%s-%d", "/dev/em8300", name, n); + } + const char *operator*() { return buffer; } + +private: + char buffer[PATH_MAX]; +}; + // ================================== //! interafce to dxr3-card /*! @@ -48,6 +60,16 @@ public: cDxr3Interface(); ~cDxr3Interface(); + static int Dxr3Open(const char *name, int mode, bool report_error = true) { + const char *filename = *cDxr3Name(name, cDxr3ConfigData::Instance().GetDxr3Card()); + int fd = open(filename, mode); + + if (report_error && (fd < 0)) { + LOG_ERROR_STR(filename); + } + return fd; + } + // audio void SetAudioAnalog(); void SetAudioDigitalPCM(); -- cgit v1.2.3