diff options
author | Matus Kral <matuskral@me.com> | 2016-04-17 05:22:59 +0200 |
---|---|---|
committer | Matus Kral <matuskral@me.com> | 2016-04-24 10:30:16 +0200 |
commit | d2f1cac8098be0e30c8833f3fe47261af6a6446a (patch) | |
tree | 8ba942a865550f1f7de03276bcc701aefe9de333 | |
parent | 2c57856234e88123a9890bf536a736115296721f (diff) |
[IMX/RefClock] refactor refclock IMX core engine. create global provider, adapt vsyncIMX
-rw-r--r-- | xbmc/linux/Makefile.in | 2 | ||||
-rw-r--r-- | xbmc/linux/imx/CMakeLists.txt | 6 | ||||
-rw-r--r-- | xbmc/linux/imx/GlobalsIMX.cpp | 24 | ||||
-rw-r--r-- | xbmc/linux/imx/IMX.cpp | 152 | ||||
-rw-r--r-- | xbmc/linux/imx/IMX.h | 55 | ||||
-rw-r--r-- | xbmc/video/videosync/VideoSyncIMX.cpp | 45 | ||||
-rw-r--r-- | xbmc/video/videosync/VideoSyncIMX.h | 1 |
7 files changed, 246 insertions, 39 deletions
diff --git a/xbmc/linux/Makefile.in b/xbmc/linux/Makefile.in index 744fd0626a..0cf90d1880 100644 --- a/xbmc/linux/Makefile.in +++ b/xbmc/linux/Makefile.in @@ -15,6 +15,8 @@ SRCS += XTimeUtils.cpp SRCS += RBP.cpp +SRCS += $(wildcard @CORE_SYSTEM_VARIANT@/*.cpp) + ifeq (@USE_OMXLIB@,1) SRCS += OMXClock.cpp SRCS += OMXCore.cpp diff --git a/xbmc/linux/imx/CMakeLists.txt b/xbmc/linux/imx/CMakeLists.txt new file mode 100644 index 0000000000..2c2fc9ae0a --- /dev/null +++ b/xbmc/linux/imx/CMakeLists.txt @@ -0,0 +1,6 @@ +set(SOURCES IMX.cpp + GlobalsIMX.cpp) + +set(HEADERS IMX.h) + +core_add_library(linuxsupport_imx) diff --git a/xbmc/linux/imx/GlobalsIMX.cpp b/xbmc/linux/imx/GlobalsIMX.cpp new file mode 100644 index 0000000000..3ff6217e3a --- /dev/null +++ b/xbmc/linux/imx/GlobalsIMX.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + + +#include "IMX.h" + +CIMX g_IMX; diff --git a/xbmc/linux/imx/IMX.cpp b/xbmc/linux/imx/IMX.cpp new file mode 100644 index 0000000000..e85def7d60 --- /dev/null +++ b/xbmc/linux/imx/IMX.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + + +#include "IMX.h" +#include <linux/mxcfb.h> +#include <algorithm> + +/* + * official imx6 -SR tree + * https://github.com/SolidRun/linux-fslc.git + * + */ + +#include <linux/mxc_dcic.h> +#include <sys/ioctl.h> + +#include "guilib/GraphicContext.h" +#include "windowing/WindowingFactory.h" +#include "utils/log.h" + +#define DCIC_DEVICE "/dev/mxc_dcic0" +#define FB_DEVICE "/dev/fb0" + +CIMX::CIMX(void) : CThread("CIMX"), m_change(true), m_frameTime(1000) +{ + g_Windowing.Register(this); +} + +CIMX::~CIMX(void) +{ + g_Windowing.Unregister(this); + Deinitialize(); +} + +bool CIMX::Initialize() +{ + CSingleLock lock(m_critSection); + + m_fddcic = open(DCIC_DEVICE, O_RDWR); + if (m_fddcic < 0) + { + m_frameTime = 0; + return false; + } + + Create(); + + return true; +} + +void CIMX::Deinitialize() +{ + CSingleLock lock(m_critSection); + + StopThread(); + m_VblankEvent.Set(); + + if (m_fddcic > 0) + close(m_fddcic); +} + +bool CIMX::UpdateDCIC() +{ + struct fb_var_screeninfo screen_info; + + if (!m_change) + return true; + + CSingleLock lock(m_critSection); + + int fb0 = open(FB_DEVICE, O_RDONLY | O_NONBLOCK); + if (fb0 < 0) + return false; + + int ret = ioctl(fb0, FBIOGET_VSCREENINFO, &screen_info); + close(fb0); + + if (ret < 0) + return false; + else if (m_lastSyncFlag == screen_info.sync) + return true; + + CLog::Log(LOGDEBUG, "CIMX::%s - Setting up screen_info parameters", __FUNCTION__); + ioctl(m_fddcic, DCIC_IOC_STOP_VSYNC, 0); + + if (ioctl(m_fddcic, DCIC_IOC_CONFIG_DCIC, &screen_info.sync) < 0) + return false; + + if (IsRunning()) + ioctl(m_fddcic, DCIC_IOC_START_VSYNC, 0); + + m_VblankEvent.Reset(); + m_change = false; + m_lastSyncFlag = screen_info.sync; + + return true; +} + +void CIMX::Process() +{ + ioctl(m_fddcic, DCIC_IOC_START_VSYNC, 0); + while (!m_bStop) + { + if (m_change && !UpdateDCIC()) + { + CLog::Log(LOGERROR, "CIMX::%s - Error occured. Exiting. Probably will need to reinitialize.", __FUNCTION__); + break; + } + + read(m_fddcic, &m_counter, sizeof(unsigned long)); + m_VblankEvent.Set(); + } + ioctl(m_fddcic, DCIC_IOC_STOP_VSYNC, 0); +} + +int CIMX::WaitVsync() +{ + int diff; + + if (!IsRunning()) + Initialize(); + + m_VblankEvent.WaitMSec(m_frameTime); + + diff = m_counter - m_counterLast; + m_counterLast = m_counter; + + return std::max(0, diff); +} + +void CIMX::OnResetDisplay() +{ + m_change = true; +} diff --git a/xbmc/linux/imx/IMX.h b/xbmc/linux/imx/IMX.h new file mode 100644 index 0000000000..75378ffc45 --- /dev/null +++ b/xbmc/linux/imx/IMX.h @@ -0,0 +1,55 @@ +#pragma once +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "threads/CriticalSection.h" +#include "threads/Event.h" +#include "threads/Thread.h" +#include "guilib/DispResource.h" + +class CIMX : public CThread, IDispResource +{ +public: + CIMX(void); + ~CIMX(void); + + bool Initialize(); + void Deinitialize(); + + int WaitVsync(); + virtual void OnResetDisplay(); + +private: + virtual void Process(); + bool UpdateDCIC(); + + int m_fddcic; + bool m_change; + unsigned long m_counter; + unsigned long m_counterLast; + CEvent m_VblankEvent; + + double m_frameTime; + CCriticalSection m_critSection; + + uint32_t m_lastSyncFlag; +}; + +extern CIMX g_IMX; diff --git a/xbmc/video/videosync/VideoSyncIMX.cpp b/xbmc/video/videosync/VideoSyncIMX.cpp index dd9bcca517..51f4f5fa0f 100644 --- a/xbmc/video/videosync/VideoSyncIMX.cpp +++ b/xbmc/video/videosync/VideoSyncIMX.cpp @@ -27,50 +27,23 @@ #include "windowing/WindowingFactory.h" #include "utils/TimeUtils.h" #include "utils/log.h" -#include <linux/mxcfb.h> - -/* - * official imx6 -SR tree - * https://github.com/SolidRun/linux-fslc.git - * - */ - -#include <linux/mxc_dcic.h> - -#include <sys/ioctl.h> +#include "linux/imx/IMX.h" CVideoSyncIMX::CVideoSyncIMX(CVideoReferenceClock *clock) : CVideoSync(clock) { - m_fddcic = open("/dev/mxc_dcic0", O_RDWR); + g_IMX.Initialize(); } CVideoSyncIMX::~CVideoSyncIMX() { - if (m_fddcic > 0) - close(m_fddcic); + g_IMX.Deinitialize(); } bool CVideoSyncIMX::Setup(PUPDATECLOCK func) { - struct fb_var_screeninfo screen_info; - UpdateClock = func; - m_abort = false; - - if (m_fddcic < 0) - return false; - int fb0 = open("/dev/fb0", O_RDONLY | O_NONBLOCK); - if (fb0 < 0) - return false; - - bool bContinue = !ioctl(fb0, FBIOGET_VSCREENINFO, &screen_info); - if (bContinue) - bContinue = !ioctl(m_fddcic, DCIC_IOC_CONFIG_DCIC, &screen_info.sync); - - close(fb0); - if (!bContinue) - return false; + m_abort = false; g_Windowing.Register(this); CLog::Log(LOGDEBUG, "CVideoReferenceClock: setting up IMX"); @@ -79,19 +52,15 @@ bool CVideoSyncIMX::Setup(PUPDATECLOCK func) void CVideoSyncIMX::Run(volatile bool& stop) { - unsigned long counter; - unsigned long last = 0; + int counter; - ioctl(m_fddcic, DCIC_IOC_START_VSYNC, 0); while (!stop && !m_abort) { - read(m_fddcic, &counter, sizeof(unsigned long)); + counter = g_IMX.WaitVsync(); uint64_t now = CurrentHostCounter(); - UpdateClock((unsigned int)(counter - last), now, m_refClock); - last = counter; + UpdateClock(counter, now, m_refClock); } - ioctl(m_fddcic, DCIC_IOC_STOP_VSYNC, 0); } void CVideoSyncIMX::Cleanup() diff --git a/xbmc/video/videosync/VideoSyncIMX.h b/xbmc/video/videosync/VideoSyncIMX.h index 6255b02610..d435292dd6 100644 --- a/xbmc/video/videosync/VideoSyncIMX.h +++ b/xbmc/video/videosync/VideoSyncIMX.h @@ -36,7 +36,6 @@ public: virtual void OnResetDisplay(); private: volatile bool m_abort; - int m_fddcic; }; #endif |