Skip to content

Commit

Permalink
Merge pull request #138 from phunkyfish/remove-p8platform
Browse files Browse the repository at this point in the history
Remove p8platform
  • Loading branch information
phunkyfish authored Nov 9, 2020
2 parents d1d789e + d40898a commit 3eb018d
Show file tree
Hide file tree
Showing 17 changed files with 1,120 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ env:
matrix:
include:
- os: linux
dist: xenial
dist: bionic
sudo: required
compiler: gcc
- os: linux
dist: xenial
dist: bionic
sudo: required
compiler: clang
- os: linux
Expand Down
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ project(pvr.dvblink)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})

find_package(Kodi REQUIRED)
find_package(p8-platform REQUIRED)
find_package(TinyXML2 REQUIRED)

include_directories(${p8-platform_INCLUDE_DIRS}
${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways
include_directories(${KODI_INCLUDE_DIR}/.. # Hack way with "/..", need bigger Kodi cmake rework to match right include ways
${TINYXML2_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/lib)

Expand All @@ -18,6 +16,7 @@ set(DVBLINK_SOURCES src/addon.cpp
src/base64.cpp
src/HttpPostClient.cpp
src/Settings.cpp
src/Socket.cpp
src/DVBLinkClient.cpp
src/RecordingStreamer.cpp
src/TimeShiftBuffer.cpp)
Expand All @@ -27,12 +26,18 @@ set(DVBLINK_HEADERS src/addon.h
src/dvblink_connection.h
src/HttpPostClient.h
src/Settings.h
src/Socket.h
src/DVBLinkClient.h
src/RecordingStreamer.h
src/TimeShiftBuffer.h)

add_subdirectory(lib/libdvblinkremote)
set(DEPLIBS ${p8-platform_LIBRARIES} dvblinkremote ${TINYXML2_LIBRARIES})
set(DEPLIBS dvblinkremote ${TINYXML2_LIBRARIES})
if(WIN32)
list(APPEND DEPLIBS ws2_32)
add_definitions(-D_WINSOCKAPI_ -D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()

build_addon(pvr.dvblink DVBLINK DEPLIBS)

include(CPack)
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: kodi-pvr-dvblink
Priority: extra
Maintainer: Nobody <[email protected]>
Build-Depends: debhelper (>= 9.0.0), cmake, libtinyxml2-dev,
libp8-platform-dev, kodi-addon-dev
kodi-addon-dev
Standards-Version: 4.1.2
Section: libs

Expand Down
1 change: 0 additions & 1 deletion depends/common/p8-platform/p8-platform.txt

This file was deleted.

1 change: 0 additions & 1 deletion depends/windowsstore/p8-platform/p8-platform.txt

This file was deleted.

2 changes: 1 addition & 1 deletion pvr.dvblink/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.dvblink"
version="9.0.0"
version="9.0.1"
name="TVMosaic/DVBLink PVR Client"
provider-name="DVBLogic">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
10 changes: 10 additions & 0 deletions pvr.dvblink/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[B]Version 9.0.1[/B]
Update: Remove p8-platform dependency
Update: Use different socket implementation
Update: Use std::thread
Update: Use std::mutex
Update: Remove p8 os header
Update: Remove use of SAFE_DELETE and p8 util header
Fixed: Fix proper return value if connected
Update: Update inputstream API 3.0.1 - Fix wrong flags bit shift

[B]Version 9.0.0[/B]
Update: PVR API 7.0.2
Fixed: Some compile warnings about missing ATTRIBUTE_HIDDEN
Expand Down
47 changes: 23 additions & 24 deletions src/DVBLinkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <kodi/General.h>
#include <kodi/gui/General.h>
#include <memory>
#include <p8-platform/os.h>

using namespace dvblinkremote;
using namespace dvblinkremotehttp;
Expand Down Expand Up @@ -235,8 +234,8 @@ DVBLinkClient::DVBLinkClient(const CDVBLinkAddon& base,
m_recordingsid_by_series = m_recordingsid;
m_recordingsid_by_series.append(DVBLINK_RECODINGS_BY_SERIES_ID);

m_updating = true;
CreateThread();
m_running = true;
m_thread = std::thread([&] { Process(); });
}
else
{
Expand Down Expand Up @@ -296,7 +295,7 @@ PVR_ERROR DVBLinkClient::GetCapabilities(kodi::addon::PVRCapabilities& capabilit
return PVR_ERROR_NO_ERROR;
}

void* DVBLinkClient::Process()
void DVBLinkClient::Process()
{
kodi::Log(ADDON_LOG_DEBUG, "DVBLinkUpdateProcess:: thread started");

Expand All @@ -307,7 +306,7 @@ void* DVBLinkClient::Process()
time_t next_update_time_timers = now + default_update_interval_sec_;
time_t next_update_time_recordings = now + default_update_interval_sec_;

while (m_updating)
while (m_running)
{
time(&now);

Expand Down Expand Up @@ -345,10 +344,9 @@ void* DVBLinkClient::Process()
next_update_time_recordings = now + default_update_interval_sec_;
}

Sleep(100);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
kodi::Log(ADDON_LOG_DEBUG, "DVBLinkUpdateProcess:: thread stopped");
return nullptr;
}

bool DVBLinkClient::GetStatus()
Expand Down Expand Up @@ -715,7 +713,7 @@ bool DVBLinkClient::parse_timer_hash(const char* timer_hash,

unsigned int DVBLinkClient::get_kodi_timer_idx_from_dvblink(const std::string& id)
{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

if (timer_idx_map_.find(id) == timer_idx_map_.end())
timer_idx_map_[id] = timer_idx_seed_++;
Expand All @@ -725,14 +723,14 @@ unsigned int DVBLinkClient::get_kodi_timer_idx_from_dvblink(const std::string& i

void DVBLinkClient::add_schedule_desc(const std::string& id, const schedule_desc& sd)
{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

schedule_map_[id] = sd;
}

bool DVBLinkClient::get_schedule_desc(const std::string& id, schedule_desc& sd)
{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

if (schedule_map_.find(id) != schedule_map_.end())
{
Expand Down Expand Up @@ -761,7 +759,7 @@ int DVBLinkClient::GetSchedules(kodi::addon::PVRTimersResultSet& results,
int total_count = 0;

{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

schedule_map_.clear();
}
Expand Down Expand Up @@ -1215,7 +1213,7 @@ PVR_ERROR DVBLinkClient::AddTimer(const kodi::addon::PVRTimer& timer)
kodi::Log(ADDON_LOG_ERROR, "Could not add timer (Error code : %d Description : %s)",
(int)status, error.c_str());
}
SAFE_DELETE(addScheduleRequest);
SafeDelete(addScheduleRequest);
}
else
{
Expand Down Expand Up @@ -1471,7 +1469,7 @@ PVR_ERROR DVBLinkClient::GetRecordings(bool deleted, kodi::addon::PVRRecordingsR
DVBLinkRemoteStatusCode status;

{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

m_recording_id_to_url_map.clear();
}
Expand Down Expand Up @@ -1558,7 +1556,7 @@ PVR_ERROR DVBLinkClient::GetRecordings(bool deleted, kodi::addon::PVRRecordingsR
xbmcRecording.SetPlot(tvitem->GetMetadata().ShortDescription);
xbmcRecording.SetPlotOutline(tvitem->GetMetadata().SubTitle);
{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex> critsec(m_mutex);

m_recording_id_to_url_map[xbmcRecording.GetRecordingId()] = tvitem->GetPlaybackUrl();
}
Expand Down Expand Up @@ -1634,7 +1632,7 @@ bool DVBLinkClient::GetRecordingURL(const std::string& recording_id,
}

{
P8PLATFORM::CLockObject critsec(m_mutex);
std::lock_guard<std::mutex>critsec(m_mutex);
if (m_recording_id_to_url_map.find(recording_id) == m_recording_id_to_url_map.end())
return false;

Expand Down Expand Up @@ -1697,10 +1695,10 @@ bool DVBLinkClient::OpenLiveStream(const kodi::addon::PVRChannel& channel)
return false;
}

P8PLATFORM::CLockObject critsec(live_mutex_);
std::lock_guard<std::mutex> critsec(live_mutex_);

if (m_live_streamer)
SAFE_DELETE(m_live_streamer);
SafeDelete(m_live_streamer);

if (use_timeshift)
m_live_streamer =
Expand Down Expand Up @@ -1750,7 +1748,7 @@ bool DVBLinkClient::IsRealTimeStream()

PVR_ERROR DVBLinkClient::GetStreamTimes(kodi::addon::PVRStreamTimes& stream_times)
{
P8PLATFORM::CLockObject critsec(live_mutex_);
std::lock_guard<std::mutex> critsec(live_mutex_);

if (m_live_streamer)
{
Expand All @@ -1767,7 +1765,7 @@ PVR_ERROR DVBLinkClient::GetStreamTimes(kodi::addon::PVRStreamTimes& stream_time

int64_t DVBLinkClient::LengthLiveStream()
{
P8PLATFORM::CLockObject critsec(live_mutex_);
std::lock_guard<std::mutex> critsec(live_mutex_);

if (m_live_streamer)
return m_live_streamer->Length();
Expand All @@ -1776,12 +1774,12 @@ int64_t DVBLinkClient::LengthLiveStream()

void DVBLinkClient::CloseLiveStream()
{
P8PLATFORM::CLockObject critsec(live_mutex_);
std::lock_guard<std::mutex> critsec(live_mutex_);

if (m_live_streamer != nullptr)
{
m_live_streamer->Stop();
SAFE_DELETE(m_live_streamer);
SafeDelete(m_live_streamer);
m_live_streamer = nullptr;
}
}
Expand Down Expand Up @@ -1953,13 +1951,14 @@ PVR_ERROR DVBLinkClient::GetEPGForChannel(int channelUid,

DVBLinkClient::~DVBLinkClient(void)
{
m_updating = false;
StopThread();
m_running = false;
if (m_thread.joinable())
m_thread.join();

if (m_live_streamer)
{
m_live_streamer->Stop();
SAFE_DELETE(m_live_streamer);
SafeDelete(m_live_streamer);
}

dvblink_channel_map_t::iterator ch_it = m_channels.begin();
Expand Down
20 changes: 10 additions & 10 deletions src/DVBLinkClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#include "dvblink_connection.h"
#include "libdvblinkremote/dvblinkremote.h"

#include <atomic>
#include <kodi/addon-instance/PVR.h>
#include <map>
#include <p8-platform/os.h>
#include <p8-platform/threads/mutex.h>
#include <p8-platform/threads/threads.h>
#include <p8-platform/util/util.h>
#include <mutex>
#include <thread>

#define DVBLINK_BUILD_IN_RECORDER_SOURCE_ID "8F94B459-EFC0-4D91-9B29-EC3D72E92677"
#define DVBLINK_RECODINGS_BY_DATA_ID "F6F08949-2A07-4074-9E9D-423D877270BB"
Expand Down Expand Up @@ -129,8 +128,7 @@ struct ATTRIBUTE_HIDDEN dvblink_server_caps
bool start_any_time_supported_;
};

class ATTRIBUTE_HIDDEN DVBLinkClient : public kodi::addon::CInstancePVRClient,
public P8PLATFORM::CThread
class ATTRIBUTE_HIDDEN DVBLinkClient : public kodi::addon::CInstancePVRClient
{
public:
DVBLinkClient(const CDVBLinkAddon& base,
Expand Down Expand Up @@ -220,7 +218,7 @@ class ATTRIBUTE_HIDDEN DVBLinkClient : public kodi::addon::CInstancePVRClient,
std::string GetBuildInRecorderObjectID();
std::string GetRecordedTVByDateObjectID(const std::string& buildInRecoderObjectID);
int GetInternalUniqueIdFromChannelId(const std::string& channelId);
virtual void* Process(void);
void Process();
bool get_dvblink_program_id(std::string& channelId,
int start_time,
std::string& dvblink_program_id);
Expand All @@ -242,15 +240,14 @@ class ATTRIBUTE_HIDDEN DVBLinkClient : public kodi::addon::CInstancePVRClient,
int m_currentChannelId;
long m_timerCount;
long m_recordingCount;
P8PLATFORM::CMutex m_mutex;
P8PLATFORM::CMutex live_mutex_;
std::mutex m_mutex;
std::mutex live_mutex_;
server_connection_properties connection_props_;
LiveStreamerBase* m_live_streamer;
RecordingStreamer* m_recording_streamer = nullptr;
bool m_add_episode_to_rec_title;
bool m_group_recordings_by_series;
bool m_showinfomsg;
bool m_updating;
bool m_update_timers_now;
bool m_update_timers_repeat;
bool m_update_recordings;
Expand All @@ -268,5 +265,8 @@ class ATTRIBUTE_HIDDEN DVBLinkClient : public kodi::addon::CInstancePVRClient,
std::map<std::string, unsigned int> timer_idx_map_;
unsigned int timer_idx_seed_;

std::atomic<bool> m_running = {false};
std::thread m_thread;

const CDVBLinkAddon& m_base;
};
21 changes: 14 additions & 7 deletions src/HttpPostClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

#include "base64.h"

#include "Socket.h"

#include <kodi/Filesystem.h>
#include <kodi/General.h>
#include <p8-platform/sockets/tcp.h>

using namespace dvblink;
using namespace dvblinkremotehttp;

/* Converts a hex character to its integer value */
Expand Down Expand Up @@ -82,19 +84,24 @@ int HttpPostClient::SendPostRequest(HttpWebRequest& request)
buffer.append("\r\n");
buffer.append(request.GetRequestData());

P8PLATFORM::CTcpSocket sock(m_server.c_str(), (unsigned short)m_serverport);
Socket sock;

if (!sock.create())
{
return -101;
}

int connect_timeout_ms = 15 * 1000; //15 seconds
if (!sock.Open(connect_timeout_ms))
if (!sock.connect(m_server, (int)m_serverport))
{
return -101;
}

ssize_t written_length = sock.Write((void*)buffer.c_str(), buffer.length());
ssize_t written_length = sock.send(buffer.c_str(), buffer.length());

if (written_length != buffer.length())
{
sock.Shutdown();
sock.close();
return -102;
}

Expand All @@ -103,10 +110,10 @@ int HttpPostClient::SendPostRequest(HttpWebRequest& request)
char read_buffer[read_buffer_size];
ssize_t read_size = 0;
std::string response;
while ((read_size = sock.Read(read_buffer, read_buffer_size, read_timeout_ms)) > 0)
while ((read_size = sock.receive(read_buffer, read_buffer_size, 0, read_timeout_ms)) > 0)
response.append(read_buffer, read_buffer + read_size);

sock.Shutdown();
sock.close();

if (response.size() > 0)
{
Expand Down
Loading

0 comments on commit 3eb018d

Please sign in to comment.