Skip to content

Commit

Permalink
Per-channel preferences!
Browse files Browse the repository at this point in the history
  • Loading branch information
aassif committed May 2, 2019
1 parent 96c2684 commit 6ff34b5
Showing 3 changed files with 146 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pvr.freebox/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.freebox"
version="2.0.0~beta3"
version="2.0.0"
name="PVR Freebox TV"
provider-name="aassif">
<requires>@ADDON_DEPENDS@</requires>
142 changes: 128 additions & 14 deletions src/Freebox.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
#include "openssl/buffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"

using namespace std;
@@ -136,6 +137,32 @@ enum Freebox::Quality Freebox::ParseQuality (const string & q)
return Quality::DEFAULT;
}

/* static */
string Freebox::StrSource (enum Source s)
{
switch (s)
{
case Source::AUTO : return "";
case Source::IPTV : return "iptv";
case Source::DVB : return "dvb";
default : return "";
}
}

/* static */
string Freebox::StrQuality (enum Quality q)
{
switch (q)
{
case Quality::AUTO : return "auto";
case Quality::HD : return "hd";
case Quality::SD : return "sd";
case Quality::LD : return "ld";
case Quality::STEREO : return "3d";
default : return "";
}
}

/* static */
bool Freebox::HTTP (const string & custom,
const string & path,
@@ -572,6 +599,7 @@ string Freebox::Event::Native (int c)
case 5: return "Documentaire";
case 6: return "Théâtre";
case 7: return "Opéra";
case 8: return "Ballet";
case 9: return "Variétés";
case 10: return "Magazine";
case 11: return "Jeunesse";
@@ -599,6 +627,7 @@ int Freebox::Event::Colors (int c)
case 5: return 0x23; // Documentaire
case 6: return 0x70; // Théâtre
case 7: return 0x65; // Opéra
case 8: return 0x66; // Ballet
case 9: return 0x32; // Variétés
case 10: return 0x81; // Magazine
case 11: return 0x50; // Jeunesse
@@ -787,6 +816,26 @@ bool Freebox::ProcessChannels ()
}
}

{
Document d;
ifstream ifs (m_path + "source.txt");
IStreamWrapper wrapper (ifs);
d.ParseStream (wrapper);
if (! d.HasParseError () && d.IsObject ())
for (auto i = d.MemberBegin (); i != d.MemberEnd (); ++i)
m_tv_prefs_source.emplace (ChannelId (i->name.GetString ()), ParseSource (i->value.GetString ()));
}

{
Document d;
ifstream ifs (m_path + "quality.txt");
IStreamWrapper wrapper (ifs);
d.ParseStream (wrapper);
if (! d.HasParseError () && d.IsObject ())
for (auto i = d.MemberBegin (); i != d.MemberEnd (); ++i)
m_tv_prefs_quality.emplace (ChannelId (i->name.GetString ()), ParseQuality (i->value.GetString ()));
}

return true;
}

@@ -806,6 +855,8 @@ Freebox::Freebox (const string & path,
m_tv_channels (),
m_tv_source (Source (source)),
m_tv_quality (Quality (quality)),
m_tv_prefs_source (),
m_tv_prefs_quality (),
m_epg_queries (),
m_epg_cache (),
m_epg_days (0),
@@ -820,7 +871,7 @@ Freebox::Freebox (const string & path,
XBMC->QueueNotification (QUEUE_INFO, PVR_FREEBOX_VERSION);
SetDays (days);
ProcessChannels ();
CreateThread (false);
CreateThread ();
}

Freebox::~Freebox ()
@@ -1116,14 +1167,75 @@ PVR_ERROR Freebox::GetChannelStreamProperties (const PVR_CHANNEL * channel, PVR_
if (! channel || ! properties || ! count || *count < 2)
return PVR_ERROR_INVALID_PARAMETERS;

enum Source source = ChannelSource (channel->iUniqueId, true);
enum Quality quality = ChannelQuality (channel->iUniqueId, true);

P8PLATFORM::CLockObject lock (m_mutex);
auto f = m_tv_channels.find (channel->iUniqueId);
if (f != m_tv_channels.end ())
return f->second.GetStreamProperties (m_tv_source, m_tv_quality, properties, count);
return f->second.GetStreamProperties (source, quality, properties, count);

return PVR_ERROR_NO_ERROR;
}

enum Freebox::Source Freebox::ChannelSource (unsigned int id, bool fallback)
{
P8PLATFORM::CLockObject lock (m_mutex);
auto f = m_tv_prefs_source.find (id);
return f != m_tv_prefs_source.end () ? f->second : (fallback ? m_tv_source : Source::DEFAULT);
}

void Freebox::SetChannelSource (unsigned int id, enum Source source)
{
P8PLATFORM::CLockObject lock (m_mutex);
switch (source)
{
case Source::AUTO : m_tv_prefs_source.erase (id); break;
case Source::IPTV : m_tv_prefs_source.insert_or_assign (id, Source::IPTV); break;
case Source::DVB : m_tv_prefs_source.insert_or_assign (id, Source::DVB); break;
}

Document d (kObjectType);
auto & a = d.GetAllocator ();
for (auto & i : m_tv_prefs_source)
d.AddMember (Value ("uuid-webtv-" + to_string (i.first), a), Value (StrSource (i.second), a), a);

ofstream ofs (m_path + "source.txt");
OStreamWrapper wrapper (ofs);
Writer<OStreamWrapper> writer (wrapper);
d.Accept (writer);
}

enum Freebox::Quality Freebox::ChannelQuality (unsigned int id, bool fallback)
{
P8PLATFORM::CLockObject lock (m_mutex);
auto f = m_tv_prefs_quality.find (id);
return f != m_tv_prefs_quality.end () ? f->second : (fallback ? m_tv_quality : Quality::DEFAULT);
}

void Freebox::SetChannelQuality (unsigned int id, enum Quality quality)
{
P8PLATFORM::CLockObject lock (m_mutex);
switch (quality)
{
case Quality::AUTO : m_tv_prefs_quality.erase (id); break;
case Quality::HD : m_tv_prefs_quality.insert_or_assign (id, Quality::HD); break;
case Quality::SD : m_tv_prefs_quality.insert_or_assign (id, Quality::SD); break;
case Quality::LD : m_tv_prefs_quality.insert_or_assign (id, Quality::LD); break;
case Quality::STEREO : m_tv_prefs_quality.insert_or_assign (id, Quality::STEREO); break;
}

Document d (kObjectType);
auto & a = d.GetAllocator ();
for (auto & i : m_tv_prefs_quality)
d.AddMember (Value ("uuid-webtv-" + to_string (i.first), a), Value (StrQuality (i.second), a), a);

ofstream ofs (m_path + "quality.txt");
OStreamWrapper wrapper (ofs);
Writer<OStreamWrapper> writer (wrapper);
d.Accept (writer);
}

////////////////////////////////////////////////////////////////////////////////
// R E C O R D I N G S /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -1859,6 +1971,10 @@ PVR_ERROR Freebox::DeleteTimer (const PVR_TIMER & timer, bool force)
return PVR_ERROR_NO_ERROR;
}

////////////////////////////////////////////////////////////////////////////////
// H O O K S ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

int freebox_dialog_select (const vector<long> & v, int selected = -1)
{
// Localize labels.
@@ -1875,7 +1991,8 @@ int freebox_dialog_select (const vector<long> & v, int selected = -1)
return r;
}

int freebox_dialog_source (int selected = -1)
/* static */
enum Freebox::Source Freebox::DialogSource (enum Source selected)
{
static const vector<long> LABELS =
{
@@ -1887,10 +2004,11 @@ int freebox_dialog_source (int selected = -1)
PVR_FREEBOX_STRING_CHANNEL_SOURCE_DVB
};

return freebox_dialog_select (LABELS, selected);
return (Source) freebox_dialog_select (LABELS, (int) selected);
}

int freebox_dialog_quality (int selected = -1)
/* static */
enum Freebox::Quality Freebox::DialogQuality (enum Quality selected)
{
static const vector<long> LABELS =
{
@@ -1904,7 +2022,7 @@ int freebox_dialog_quality (int selected = -1)
PVR_FREEBOX_STRING_CHANNEL_QUALITY_3D
};

return freebox_dialog_select (LABELS, selected);
return (Quality) freebox_dialog_select (LABELS, (int) selected);
}

PVR_ERROR Freebox::MenuHook (const PVR_MENUHOOK & hook, const PVR_MENUHOOK_DATA & data)
@@ -1915,10 +2033,8 @@ PVR_ERROR Freebox::MenuHook (const PVR_MENUHOOK & hook, const PVR_MENUHOOK_DATA
{
const PVR_CHANNEL & channel = data.data.channel;

cout << "PVR_FREEBOX_MENUHOOK_CHANNEL_SOURCE" << ' '
<< '"' << channel.strChannelName << '"' << ' ' << '[' << channel.iUniqueId << ']' << endl;

int source = freebox_dialog_source ();
unsigned int id = channel.iUniqueId;
SetChannelSource (id, DialogSource (ChannelSource (id, false)));

return PVR_ERROR_NO_ERROR;
}
@@ -1927,10 +2043,8 @@ PVR_ERROR Freebox::MenuHook (const PVR_MENUHOOK & hook, const PVR_MENUHOOK_DATA
{
const PVR_CHANNEL & channel = data.data.channel;

cout << "PVR_FREEBOX_MENUHOOK_CHANNEL_QUALITY" << ' '
<< '"' << channel.strChannelName << '"' << ' ' << '[' << channel.iUniqueId << ']' << endl;

int quality = freebox_dialog_quality ();
unsigned int id = channel.iUniqueId;
SetChannelQuality (id, DialogQuality (ChannelQuality (id, false)));

return PVR_ERROR_NO_ERROR;
}
20 changes: 17 additions & 3 deletions src/Freebox.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
#include "p8-platform/threads/threads.h"
#include "rapidjson/document.h"

#define PVR_FREEBOX_VERSION "2.0b3"
#define PVR_FREEBOX_VERSION "2.0"

#define PVR_FREEBOX_BACKEND_NAME "Freebox TV"
#define PVR_FREEBOX_BACKEND_VERSION PVR_FREEBOX_VERSION
@@ -94,10 +94,10 @@ class Freebox :
}

// Channel source.
enum class Source {DEFAULT = 0, AUTO = 1, IPTV = 2, DVB = 3};
enum class Source {DEFAULT = -1, AUTO = 0, IPTV = 1, DVB = 2};

// Channel quality.
enum class Quality {DEFAULT = 0, AUTO = 1, HD = 2, SD = 3, LD = 4, STEREO = 5};
enum class Quality {DEFAULT = -1, AUTO = 0, HD = 1, SD = 2, LD = 3, STEREO = 4};

class Stream
{
@@ -391,10 +391,22 @@ class Freebox :
void ProcessTimers ();
void ProcessRecordings ();

// Channel preferences.
enum Source ChannelSource (unsigned int id, bool fallback = true);
enum Quality ChannelQuality (unsigned int id, bool fallback = true);
void SetChannelSource (unsigned int id, enum Source);
void SetChannelQuality (unsigned int id, enum Quality);

protected:
static enum Source ParseSource (const std::string &);
static enum Quality ParseQuality (const std::string &);

static std::string StrSource (enum Source);
static std::string StrQuality (enum Quality);

static enum Source DialogSource (enum Source selected = Source::DEFAULT);
static enum Quality DialogQuality (enum Quality selected = Quality::DEFAULT);

static std::string Password (const std::string & token, const std::string & challenge);

template <typename T>
@@ -423,6 +435,8 @@ class Freebox :
std::map<unsigned int, Channel> m_tv_channels;
enum Source m_tv_source;
enum Quality m_tv_quality;
std::map<unsigned int, enum Source> m_tv_prefs_source;
std::map<unsigned int, enum Quality> m_tv_prefs_quality;
// EPG /////////////////////////////////////////////////////////////////////
std::queue<Query> m_epg_queries;
std::set<std::string> m_epg_cache;

0 comments on commit 6ff34b5

Please sign in to comment.