RPC Methods Common to all Services

RPC (Remote Procedure Call) — a data exchange protocol allowing the client to call pre-known methods on the server to get a certain data/result. The SmartMEDIA services use the JSON-RPC over TCP. All the services support a set of common methods (see below) and a set of service-specific methods (Conveyor, SmartPVR, and RTSPServer).

The SmartMEDIA solution includes an RPC client (the rpcClient utility) described here.

GetVersion()

The method returns the service version.

Response Example

JSON

{

 “result”:“4.1.0”

}

GetMethods()

The method returns the list of names of methods available to call.

Response Example

JSON

{

 “result”: [

   “GetEvents”,

   “GetMethodDescription”,

   “GetMethods”,

   “GetServiceName”,

   “GetUptime”,

   “GetVersion”,

   “StartRecord”,

   “StopRecord”

 ]

}

GetMethodDescription(method_name)

The method returns a short method description.

method_name, string 

Name of the method.

Response Example

JSON

{

 “result”:“Return uptime”

}

GetUptime()

The method returns the uptime of the current RPC server, in seconds.

Response Example

JSON

{

 “result”:174.1041376590729

}

GetServiceName()

The method returns the name of the service (conveyor, rtspServer) managed by the current RPC server.

Response Example

JSON

{

 “result”:“rtspServer”

}

GetConfig()

The method returns the first 100 KB of the main configuration file of the current service.

Response Example

JSON

{

 “core”: {

   “port”:9001

 },

 “dash”: {

   “uri_path”:“/dash”

 }

}

GetEvents(last_event_num, session_id)

The method returns statistics (a list of events) of the current service.

last_event_num, integer 

The last event number in the response. When restarting, SmartMEDIA services start numbering each statistical event sequentially with 0. To limit the size of the returned result, the request passes the number of the last event.

session_id, integer 

The Unix-timestamp of the service startup used as the session ID. Allows you to distinguish events with the same number for the same service running at different times. However, if the server receives a request with the session_id other than the current value, it responds with all available events without taking into account the last_event_num value.

Response Parameters

Depending on the service, the method returns the following data:

Parameters Common to all Services

id

Event number within the session

sessionID

ID of the session

time

Unix-timestamp of event occurrence

Conveyor (conveyor) Parameters

channel

Channel name. Generated using the channels → id and channels → sources → id parameters of the Conveyor configuration file.

type

Event type: Started, Stopped, Error or ReadBitrate.

description

Event description. For example, the ReadBitrate event type is supplemented with the channel read bitrate.

file

Name of the file being indexed

type

Event type: FileProcessStarted; FileProcessSuccess; FileProcessFailed — file is not indexed completely; IndexingError — errors occurred during indexing, but the file is completely or partially indexed.

description

Event description. For example, the IndexingError event type is supplemented with the error description + the number of its repetitions.

Playlist Generator (plgen) Parameters

type

Event type: PlaylistRequest, Error.

description

Event description.

url

Request URI

duration

Duration of the request processing

userAgent

Client User-Agent

result

Request success: true — success; false — fail.

ubSession

HTTP session

ubType

Short error description (for the Error event type only)

ubCounter

The number of error repetitions (for the Error event type only)

address

Client IP address

xMACAddress

Client MAC address

resourceID

ID of the resource requested (typically the name of a file or channel)

Examples Of Calling RPC Methods

Examples of calling RPC methods using the rpcClient utility are provided here.

Interaction with the RPC server can be organized in Python scripts using the tinyrpc library. First, create a TCP transport:

Python

from tinyrpc.transports import ClientTransport

from tinyrpc.protocols.jsonrpc import JSONRPCProtocol

from tinyrpc import RPCClient

import socket

class TcpClientTransport(ClientTransport):

 def__init__(self, ip, port):

   self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

   self.s.connect((ip, port))

   self.buffered_data =“”

   def send_message(self, message, expect_reply=True):

     self.s.send(message)

     packet_data =“”

     open_tags =0

     in_quote =False

     escape_next =False

     have_json =False

     while open_tags !=0ornot have_json:

       if len(self.buffered_data) ==0:

         self.buffered_data +=self.s.recv(1024*1024)

         continue

         data =self.buffered_data[0]

         packet_data += data

         self.buffered_data =self.buffered_data[1:]

         if in_quote:

           if data ==“””:

             ifnot escape_next:

               in_quote =False

               continue

               if escape_next:

                 escape_next =False

                 else:

                   if data ==“\”:

                     escape_next =True

                     else:

                       if data ==“{“:

                         have_json =True

                         open_tags = open_tags +1

                         if data ==“}”:

                           open_tags = open_tags 1

                           if data ==“””:

                             in_quote =True

                             return packet_data

                           def create_json_tcp_rpc(ip, port):

                             rpc_client = RPCClient(JSONRPCProtocol(), TcpClientTransport(ip, port))

                             return rpc_client.get_proxy()

Then create a connection and call the necessary methods:

Python

rpc_object = create_json_tcp_rpc(“127.0.0.1”, 42000)

service_name = rpc_object.GetServiceName()

service_version = rpc_object.GetVersion()

CONTENTS
Sign-in
Sign-in with your SmartLabs Support Portal account credentials to see non-public articles.