Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from phunkyfish/rtmp-read-pause-timer
Rtmp read pause timer - Inputstream API 2.2.0
- Loading branch information
Showing
8 changed files
with
549 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then | ||
echo "Usage: $0 <XBMC-SRC-DIR>" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ "$OSTYPE" != "darwin"* ]]; then | ||
echo "Error: Script only for use on MacOSX" >&2 | ||
exit 1 | ||
fi | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
if [[ "$1" = /* ]] | ||
then | ||
#absolute path | ||
SCRIPT_DIR="" | ||
else | ||
#relative | ||
SCRIPT_DIR="$SCRIPT_DIR/" | ||
fi | ||
|
||
BINARY_ADDONS_TARGET_DIR="$1/tools/depends/target/binary-addons" | ||
MACOSX_BINARY_ADDONS_TARGET_DIR="" | ||
KODI_ADDONS_DIR="$HOME/Library/Application Support/Kodi/addons" | ||
ADDON_NAME=`basename -s .git \`git config --get remote.origin.url\`` | ||
|
||
if [ ! -d "$BINARY_ADDONS_TARGET_DIR" ]; then | ||
echo "Error: Could not find binary addons directory at: $BINARY_ADDONS_TARGET_DIR" >&2 | ||
exit 1 | ||
fi | ||
|
||
for DIR in "$BINARY_ADDONS_TARGET_DIR/"macosx*; do | ||
if [ -d "${DIR}" ]; then | ||
MACOSX_BINARY_ADDONS_TARGET_DIR="${DIR}" | ||
break | ||
fi | ||
done | ||
|
||
if [ -z "$MACOSX_BINARY_ADDONS_TARGET_DIR" ]; then | ||
echo "Error: Could not find binary addons build directory at: $BINARY_ADDONS_TARGET_DIR/macosx*" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ ! -d "$KODI_ADDONS_DIR" ]; then | ||
echo "Error: Kodi addons dir does not exist at: $KODI_ADDONS_DIR" >&2 | ||
exit 1 | ||
fi | ||
|
||
cd "$MACOSX_BINARY_ADDONS_TARGET_DIR" | ||
make | ||
|
||
XBMC_BUILD_ADDON_INSTALL_DIR=$(cd "$SCRIPT_DIR$1/addons/$ADDON_NAME" 2> /dev/null && pwd -P) | ||
rm -rf "$KODI_ADDONS_DIR/$ADDON_NAME" | ||
echo "Removed previous addon build from: $KODI_ADDONS_DIR" | ||
cp -rf "$XBMC_BUILD_ADDON_INSTALL_DIR" "$KODI_ADDONS_DIR" | ||
echo "Copied new addon build to: $KODI_ADDONS_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (C) 2005-2020 Team Kodi | ||
* https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSE.md for more information. | ||
*/ | ||
|
||
#include "Timer.h" | ||
|
||
#include <algorithm> | ||
|
||
namespace rtmpstream | ||
{ | ||
|
||
CTimer::CTimer(std::function<void()> const& callback) | ||
: m_callback(callback), | ||
m_timeout(0), | ||
m_interval(false), | ||
m_endTime(0) | ||
{ } | ||
|
||
CTimer::CTimer(ITimerCallback *callback) | ||
: CTimer(std::bind(&ITimerCallback::OnTimeout, callback)) | ||
{ } | ||
|
||
CTimer::~CTimer() | ||
{ | ||
Stop(); | ||
} | ||
|
||
bool CTimer::Start(uint32_t timeout, bool interval /* = false */) | ||
{ | ||
if (m_callback == nullptr || timeout == 0 || IsRunning()) | ||
return false; | ||
|
||
m_timeout = timeout; | ||
m_interval = interval; | ||
|
||
m_eventTimeout.Reset(); | ||
|
||
m_running = true; | ||
m_thread = std::thread{&CTimer::Process, this}; | ||
|
||
m_thread.detach(); | ||
|
||
return true; | ||
} | ||
|
||
bool CTimer::Stop() | ||
{ | ||
if (!m_running) | ||
return false; | ||
|
||
m_running = false; | ||
m_eventTimeout.Signal(); | ||
|
||
return true; | ||
} | ||
|
||
void CTimer::RestartAsync(uint32_t timeout) | ||
{ | ||
m_timeout = timeout; | ||
m_endTime = SystemClockMillis() + timeout; | ||
m_eventTimeout.Signal(); | ||
} | ||
|
||
bool CTimer::Restart() | ||
{ | ||
if (!IsRunning()) | ||
return false; | ||
|
||
Stop(); | ||
return Start(m_timeout, m_interval); | ||
} | ||
|
||
float CTimer::GetElapsedSeconds() | ||
{ | ||
return GetElapsedMilliseconds() / 1000.0f; | ||
} | ||
|
||
float CTimer::GetElapsedMilliseconds() | ||
{ | ||
if (!IsRunning()) | ||
return 0.0f; | ||
|
||
return static_cast<float>(m_timer.TimeLeft()); | ||
} | ||
|
||
void CTimer::Process() | ||
{ | ||
while (m_running) | ||
{ | ||
uint32_t currentTime = SystemClockMillis(); | ||
m_endTime = currentTime + m_timeout; | ||
m_timer.Init(m_timeout); | ||
|
||
// wait the necessary time | ||
if (!m_eventTimeout.Wait(m_timeout)) | ||
{ | ||
currentTime = SystemClockMillis(); | ||
if (m_running && m_endTime <= currentTime) | ||
{ | ||
// execute OnTimeout() callback | ||
m_callback(); | ||
|
||
// continue if this is an interval timer, or if it was restarted during callback | ||
if (!m_interval && m_endTime <= currentTime) | ||
break; | ||
} | ||
} | ||
} | ||
|
||
m_running = false; | ||
} | ||
|
||
unsigned int CTimer::SystemClockMillis() | ||
{ | ||
uint64_t now_time; | ||
static uint64_t start_time = 0; | ||
static bool start_time_set = false; | ||
|
||
now_time = static_cast<int64_t>(std::chrono::duration<double>(std::chrono::high_resolution_clock::now().time_since_epoch()).count() * 1000.0); | ||
|
||
if (!start_time_set) | ||
{ | ||
start_time = now_time; | ||
start_time_set = true; | ||
} | ||
return (unsigned int)(now_time - start_time); | ||
} | ||
|
||
} /* namespace rtmpstream */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2005-2020 Team Kodi | ||
* https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSE.md for more information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "TimerHelper.h" | ||
|
||
#include <functional> | ||
|
||
namespace rtmpstream | ||
{ | ||
|
||
class ATTRIBUTE_HIDDEN ITimerCallback | ||
{ | ||
public: | ||
virtual ~ITimerCallback() = default; | ||
|
||
virtual void OnTimeout() = 0; | ||
}; | ||
|
||
class ATTRIBUTE_HIDDEN CTimer | ||
{ | ||
public: | ||
explicit CTimer(ITimerCallback *callback); | ||
explicit CTimer(std::function<void()> const& callback); | ||
~CTimer(); | ||
|
||
bool Start(uint32_t timeout, bool interval = false); | ||
bool Stop(); | ||
bool Restart(); | ||
void RestartAsync(uint32_t timeout); | ||
|
||
bool IsRunning() { return m_running; } | ||
|
||
float GetElapsedSeconds(); | ||
float GetElapsedMilliseconds(); | ||
|
||
private: | ||
void Process(); | ||
unsigned int SystemClockMillis(); | ||
|
||
std::function<void()> m_callback; | ||
uint32_t m_timeout; | ||
bool m_interval; | ||
uint32_t m_endTime; | ||
CEvent m_eventTimeout; | ||
CTimeout m_timer; | ||
std::thread m_thread; | ||
bool m_running = false; | ||
}; | ||
|
||
} /* namespace rtmpstream */ |
Oops, something went wrong.