Skip to content

Loading…

[pvr] added json-rpc pvr operations. needs sync on win32 #1412

Closed
wants to merge 1 commit into from

3 participants

@opdenkamp
Team Kodi member

this re-adds the json-rpc pvr operations that were present in the pvr branch

@RobertMe

Personally I don't like the PVR.ChannelUp/Down(/Switch) methods. I would rather like to see those implemented in Player, where there already are GoNext, GoPrevious and GoTo methods. These changes are also part of the PR I send you on your fork (opdenkamp#626). I will see if I can finish some last pieces on the TV/EPG part, transplant the branches to mainline and send a PR for them.

@opdenkamp
Team Kodi member

sure, I just took the previously implement stuff

@RobertMe

I know, but this would be the time to break backwards compatibility I guess. So merging it in now and removing it before the Frodo release would just add to the confusion. Currently it already is left out, so not adding it back (or adding it back, and leaving it in) would IMO be the best choice.

@opdenkamp
Team Kodi member

or you just send a PR to this branch

@Montellese Montellese was assigned
@opdenkamp opdenkamp referenced this pull request in opdenkamp/xbmc
Closed

Add propper Live TV support to the Player JSON API #640

@Montellese
Team Kodi member

In general I'd prefer the Channel(Switch|Up|Down) to be integrated into Player.Go(To|Previous|Next). I'll try to find time for a more thorough review later today.

@opdenkamp
Team Kodi member

Yeah that's also what I said on the other PR that goes on top of this one.

@RobertMe

Montellese, ChannelSwitch/Up/Down are indeed meant to be replaced with Player.GoTo/Previous/Next from my PR. I think RecordCurrentChannel (or whatever it is called) could also be moved? I will comment on my PR (opdenkamps fork) later today. As I just booted my computer since Friday, so have some reading up to do :)

@Montellese
Team Kodi member

OK I looked through the changes and in general they look fine. As mentioned I'd prefer to have the Channel(Switch|Up|Down) to be integrated into Player.Go(To|Previous|Next). I'm not sure about the recording stuff. As it's currently only available for PVR and e.g. ScheduleRecording doesn't make sense in the Player namespace I tend to keep those in the PVR namespace.

Btw would it make more sense to call the new namespace "LiveTV" instead of "PVR" (as that's what the english text is in the home screen as well)?

@opdenkamp
Team Kodi member

They even need to be integrated into the player, that's not optional.

The namespace is called PVR in the code, so calling it PVR in json-rpc makes more sense to me. It's also not just TV, but also radio ;-)

@opdenkamp
Team Kodi member

closing this one

@opdenkamp opdenkamp closed this
@tru tru added a commit to plexinc/plex-home-theater-public that referenced this pull request
@tru tru Only allow localhost connections when user is !restricted.
Fixes #1412
561ef52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
14 xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
@@ -34,6 +34,7 @@
#include "InputOperations.h"
#include "XBMCOperations.h"
#include "ApplicationOperations.h"
+#include "PVROperations.h"
using namespace std;
using namespace JSONRPC;
@@ -184,7 +185,18 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
// XBMC operations
{ "XBMC.GetInfoLabels", CXBMCOperations::GetInfoLabels },
- { "XBMC.GetInfoBooleans", CXBMCOperations::GetInfoBooleans }
+ { "XBMC.GetInfoBooleans", CXBMCOperations::GetInfoBooleans },
+
+// PVR operations
+ { "PVR.ChannelSwitch", CPVROperations::ChannelSwitch },
+ { "PVR.ChannelUp", CPVROperations::ChannelUp },
+ { "PVR.ChannelDown", CPVROperations::ChannelDown },
+ { "PVR.RecordCurrentChannel", CPVROperations::RecordCurrentChannel },
+ { "PVR.ScheduleRecording", CPVROperations::ScheduleRecording },
+ { "PVR.IsAvailable", CPVROperations::IsAvailable },
+ { "PVR.IsScanningChannels", CPVROperations::IsScanningChannels },
+ { "PVR.IsRecording", CPVROperations::IsRecording },
+ { "PVR.ScanChannels", CPVROperations::ScanChannels }
};
JSONSchemaTypeDefinition::JSONSchemaTypeDefinition()
View
1 xbmc/interfaces/json-rpc/Makefile
@@ -11,6 +11,7 @@ SRCS=ApplicationOperations.cpp \
SystemOperations.cpp \
VideoLibrary.cpp \
XBMCOperations.cpp \
+ PVROperations.cpp \
LIB=json-rpc.a
View
209 xbmc/interfaces/json-rpc/PVROperations.cpp
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.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, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "PVROperations.h"
+#include "ApplicationMessenger.h"
+#include "utils/log.h"
+
+#include "pvr/PVRManager.h"
+#include "pvr/channels/PVRChannelGroupsContainer.h"
+#include "pvr/channels/PVRChannel.h"
+#include "pvr/timers/PVRTimers.h"
+#include "pvr/timers/PVRTimerInfoTag.h"
+#include "epg/Epg.h"
+#include "epg/EpgContainer.h"
+
+using namespace JSONRPC;
+using namespace PVR;
+using namespace EPG;
+
+JSONRPC_STATUS CPVROperations::ChannelSwitch(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ int iChannelId = (int)parameterObject["channelid"].asInteger();
+ if (iChannelId <= 0)
+ return InvalidParams;
+
+ CLog::Log(LOGDEBUG, "JSONRPC: switch to channel '%d'", iChannelId);
+
+ CFileItemPtr channel = g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId);
+ if (!channel || !channel->HasPVRChannelInfoTag())
+ return InternalError;
+
+ CPVRChannelPtr currentChannel;
+ if (g_PVRManager.GetCurrentChannel(currentChannel) && currentChannel->IsRadio() == channel->GetPVRChannelInfoTag()->IsRadio())
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_CHANNEL_SWITCH, (float)channel->GetPVRChannelInfoTag()->ChannelNumber()));
+ else
+ CApplicationMessenger::Get().MediaPlay(*channel);
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ChannelUp(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CLog::Log(LOGDEBUG, "JSONRPC: channel up");
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_NEXT_ITEM));
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ChannelDown(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CLog::Log(LOGDEBUG, "JSONRPC: channel down");
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_PREV_ITEM));
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::RecordCurrentChannel(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CPVRChannelPtr currentChannel;
+ if (g_PVRManager.GetCurrentChannel(currentChannel))
+ {
+ bool bOnOff = !currentChannel->IsRecording();
+ if (g_PVRManager.StartRecordingOnPlayingChannel(bOnOff))
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: set recording on currently playing channel to '%s'", bOnOff ? "on" : "off" );
+ return ACK;
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: unable to set recording to '%s'", bOnOff ? "on" : "off" );
+ return InternalError;
+ }
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: failed to start recording - no channel is playing");
+ return FailedToExecute;
+ }
+}
+
+JSONRPC_STATUS CPVROperations::IsAvailable(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ result = g_PVRManager.IsStarted();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::IsScanningChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ result = g_PVRManager.IsRunningChannelScan();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::IsRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ result = g_PVRManager.IsRecording();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::ScanChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ if (!g_PVRManager.IsRunningChannelScan())
+ g_PVRManager.StartChannelScan();
+
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ScheduleRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ int iEpgId = (int)parameterObject["epgid"].asInteger();
+ int iStartTime = (int)parameterObject["starttime"].asInteger();
+
+ if (iEpgId > 0 && iStartTime > 0)
+ {
+ CDateTime startTime(iStartTime);
+ CEpgInfoTagPtr tag = g_EpgContainer.GetById(iEpgId)->GetTag(startTime);
+
+ if (tag && tag->HasPVRChannel())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: schedule recording - channel: '%s' start: '%s' end: '%s'",
+ tag->PVRChannelName().c_str(),
+ tag->StartAsLocalTime().GetAsLocalizedDateTime(false, false).c_str(),
+ tag->EndAsLocalTime().GetAsLocalizedDateTime(false, false).c_str());
+
+ CPVRTimerInfoTag *newTimer = CPVRTimerInfoTag::CreateFromEpg(*tag);
+ bool bCreated = (newTimer != NULL);
+ bool bAdded = false;
+
+ if (bCreated)
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: recording scheduled");
+ bAdded = CPVRTimers::AddTimer(*newTimer);
+ delete newTimer;
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: failed to schedule recording");
+ }
+ return bAdded ? ACK : InternalError;
+ }
+ }
+
+ return InvalidParams;
+}
View
41 xbmc/interfaces/json-rpc/PVROperations.h
@@ -0,0 +1,41 @@
+#pragma once
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.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, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "utils/StdString.h"
+#include "JSONRPC.h"
+
+namespace JSONRPC
+{
+ class CPVROperations
+ {
+ public:
+ static JSONRPC_STATUS ChannelSwitch(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ChannelUp(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ChannelDown(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS RecordCurrentChannel(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ScheduleRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsAvailable(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsScanningChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ScanChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ };
+}
View
79 xbmc/interfaces/json-rpc/ServiceDescription.h
@@ -1109,6 +1109,7 @@ namespace JSONRPC
"\"RemoveData\": { \"type\": \"boolean\", \"required\": true },"
"\"Navigate\": { \"type\": \"boolean\", \"required\": true },"
"\"WriteFile\": { \"type\": \"boolean\", \"required\": true },"
+ "\"ControlPVR\": { \"type\": \"boolean\", \"required\": true },"
"\"ControlSystem\": { \"type\": \"boolean\", \"required\": true },"
"\"ControlGUI\": { \"type\": \"boolean\", \"required\": true }"
"}"
@@ -2796,6 +2797,84 @@ namespace JSONRPC
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info booleans\""
"}"
+ "}",
+ "\"PVR.ChannelSwitch\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel to given channelid\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": ["
+ "{ \"name\": \"channelid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ChannelUp\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel up\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ChannelDown\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel down\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.RecordCurrentChannel\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Toggles Recording of currently playing channel\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ScheduleRecording\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Schedule recording\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": ["
+ "{ \"name\": \"epgid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true },"
+ "{ \"name\": \"uniqueid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true },"
+ "{ \"name\": \"starttime\", \"type\": \"integer\", \"minimum\": 0, \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.IsAvailable\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is available or not\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.IsScanningChannels\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is scanning channels\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.IsRecording\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is recording\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.ScanChannels\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Starts a channel scan\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
"}"
};
View
79 xbmc/interfaces/json-rpc/methods.json
@@ -43,6 +43,7 @@
"RemoveData": { "type": "boolean", "required": true },
"Navigate": { "type": "boolean", "required": true },
"WriteFile": { "type": "boolean", "required": true },
+ "ControlPVR": { "type": "boolean", "required": true },
"ControlSystem": { "type": "boolean", "required": true },
"ControlGUI": { "type": "boolean", "required": true }
}
@@ -1730,5 +1731,83 @@
"type": "object",
"description": "List of key-value pairs of the retrieved info booleans"
}
+ },
+ "PVR.ChannelSwitch": {
+ "type": "method",
+ "description": "Switch channel to given channelid",
+ "transport": "Response",
+ "permission": "ControlPlayback",
+ "params": [
+ { "name": "channelid", "type": "integer", "minimum": 0, "required": true }
+ ],
+ "returns": "string"
+ },
+ "PVR.ChannelUp": {
+ "type": "method",
+ "description": "Switch channel up",
+ "transport": "Response",
+ "permission": "ControlPlayback",
+ "params": [],
+ "returns": "string"
+ },
+ "PVR.ChannelDown": {
+ "type": "method",
+ "description": "Switch channel down",
+ "transport": "Response",
+ "permission": "ControlPlayback",
+ "params": [],
+ "returns": "string"
+ },
+ "PVR.RecordCurrentChannel": {
+ "type": "method",
+ "description": "Toggles Recording of currently playing channel",
+ "transport": "Response",
+ "permission": "ControlPVR",
+ "params": [],
+ "returns": "string"
+ },
+ "PVR.ScheduleRecording": {
+ "type": "method",
+ "description": "Schedule recording",
+ "transport": "Response",
+ "permission": "ControlPVR",
+ "params": [
+ { "name": "epgid", "type": "integer", "minimum": 0, "required": true },
+ { "name": "uniqueid", "type": "integer", "minimum": 0, "required": true },
+ { "name": "starttime", "type": "integer", "minimum": 0, "required": true}
+ ],
+ "returns": "string"
+ },
+ "PVR.IsAvailable": {
+ "type": "method",
+ "description": "Checks whether PVR is available or not",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [],
+ "returns": "boolean"
+ },
+ "PVR.IsScanningChannels": {
+ "type": "method",
+ "description": "Checks whether PVR is scanning channels",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [],
+ "returns": "boolean"
+ },
+ "PVR.IsRecording": {
+ "type": "method",
+ "description": "Checks whether PVR is recording",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [],
+ "returns": "boolean"
+ },
+ "PVR.ScanChannels": {
+ "type": "method",
+ "description": "Starts a channel scan",
+ "transport": "Response",
+ "permission": "ControlPVR",
+ "params": [],
+ "returns": "string"
}
}
Something went wrong with that request. Please try again.