Project

General

Profile

Htsp » History » Version 20

Andreas Smas, 2009-02-28 18:22

1 17 Andreas Smas
= Home Tv Streaming Protocol (HTSP) =
2 1 Andreas Smas
3 17 Andreas Smas
== General ==
4 1 Andreas Smas
5 17 Andreas Smas
HTSP is a TCP based protocol primarily intended for streaming of live TV and related meta data such as channels, group of channels (called tags in HTSP) and electronic program guide (EPG) information.
6 1 Andreas Smas
7 17 Andreas Smas
The transmission and reception of a channel over HTSP is referred to a subscription. A single HTSP session can handle as many concurrent subscriptions as the bandwidth and CPU permits.
8 1 Andreas Smas
9
10 17 Andreas Smas
The HTSP server in tvheadend has a payload-aware scheduler for prioritizing more important packets (such as I-frames) before less important ones (such as B-frames). This makes HTSP is suitable for long-distance transmissions and/or paths with non-perfect delivery.
11
(It has been tested with a server in Stockholm and the client in Berlin).
12
13 18 Andreas Smas
----
14 17 Andreas Smas
== Communication ==
15
16
There are two distinct ways for communication within HTSP.
17
18
=== RPC communication ===
19 1 Andreas Smas
20 18 Andreas Smas
There is a normal RPC way of doing things. I.e. the client sends a request and the server responds with a reply. All the RPC methods are listed below as the 'Client to Server' methods. Apart from all message fields listed within each message type the client can add an additional field:
21
22
RPC request extra fields:
23 17 Andreas Smas
{{{
24
seq              int  optional   Sequence number. This field will be echoed back by the server in the reply.
25 1 Andreas Smas
}}}
26
This field should be used by the client to match the reply with the request.
27 18 Andreas Smas
All replies are guaranteed to arrive in the same order as the requests.
28
Even so, probably the best way to implement the request-reply client is by taking advantage of the 'seq' field.
29 1 Andreas Smas
30 18 Andreas Smas
RPC reply extra fields:
31
{{{
32
seq              int  optional   Sequence number. Same as in the request.
33
error            str  optional   If present an error has occurred and the text describes the error.
34 19 Andreas Smas
noaccess         int  optional   If present and set to '1' the user is prohibited from invoking the method due to 
35
                                 access restrictions. 
36 18 Andreas Smas
                                 The client should first try to authenticate and then try to re-invoke the method.
37 19 Andreas Smas
challenge        bin  optional   If 'noaccess' is set the server also provides a challenge to be used in the, if
38
                                 the user decides so, upcoming 'authentication' request.
39 18 Andreas Smas
}}}
40 1 Andreas Smas
41
42
43 17 Andreas Smas
=== Streaming communication ===
44 18 Andreas Smas
45 19 Andreas Smas
For streaming of live TV and various related messages the server will continuously push data to the client.
46
These messages are referred to as asynchronous messages and always have the 'method' field set and never have the 'seq' field set.
47
Also, the client can enable an additional asyncMetadata mode and by doing so it will be notified by the server when meta data changes. (EPG updates, creation of channels and tags, etc). 
48 1 Andreas Smas
49
50 19 Andreas Smas
=== Authentication ===
51
52 20 Andreas Smas
If the client receives a reply with the 'noaccess' field set it means that it was not allowed to invoke that method.
53
The client can try to raise it's access by invoking the 'authenticate' method and then try to re-invoke the original method.
54 19 Andreas Smas
55
A typical client would do something like this:
56
{{{
57
 sendRequest() {
58
    
59
 while(1) {
60
  reply = send(request)
61
62
  if(reply.noaccess == 0) {
63
   return reply}
64
  else {
65
66
    do {
67
      ask-user-for-credentials-and-or-get-them-from-keychain
68
       
69
      request.username = name of user
70
      request.digest = sha1(password + reply.challenge)
71
      reply = send(request);
72
    } while(reply.noaccess == 1)
73
  }
74
}}}
75
76 20 Andreas Smas
The challenge will always be present when 'noaccess' is set.
77 1 Andreas Smas
78
----
79 17 Andreas Smas
= Client to Server (RPC) methods =
80 1 Andreas Smas
81 5 Andreas Smas
----
82 1 Andreas Smas
=== getChallenge ===
83
84 7 Andreas Smas
Request a 32 byte challenge used to generate a authentication digest.
85
86
Request message fields:
87
{{{
88
None
89
}}}
90
91
Reply message fields:
92
{{{
93 9 Andreas Smas
challenge        bin  required   32 bytes of random challenge to be used in next authentication request from client.
94 7 Andreas Smas
}}}
95
96
97 5 Andreas Smas
----
98 1 Andreas Smas
=== authenticate ===
99 8 Andreas Smas
100
Request message fields:
101 7 Andreas Smas
{{{
102
username         str  required   Username.
103
digest           bin  required   SHA-1 hash of [password (not including terminating NUL)] + [challenge]
104
}}}
105 1 Andreas Smas
106 9 Andreas Smas
Reply message fields:
107
{{{
108
noaccess         int  optional   Set to '1' if access was denied.
109 1 Andreas Smas
challenge        bin  optional   32 bytes of random challenge to be used in next authentication request from client.
110 7 Andreas Smas
                                 Always present if 'noaccess' is set. This is supplied so the client does not have
111
                                 to issue an extra 'getChallenge' request.
112
}}}
113 5 Andreas Smas
114 10 Andreas Smas
115
----
116 18 Andreas Smas
=== enableAsyncMetadata ===
117 10 Andreas Smas
118 18 Andreas Smas
When this is enabled the client will get continuous updates from the server about channels and tags.
119 10 Andreas Smas
This also includes creation and deletion of channels and tags. 
120
121
An interactive application that presents the user with information about channels and tags would probably want to switch to this mode.
122
123
124
Request message fields:
125
{{{
126
None
127
}}}
128
129
Reply message fields:
130
{{{
131
None
132
}}}
133
134 1 Andreas Smas
135 5 Andreas Smas
136 1 Andreas Smas
----
137 6 Andreas Smas
=== getEvent ===
138
139 1 Andreas Smas
----
140 6 Andreas Smas
=== subscribe ===
141
142
Request subscription to the given channel. A request for a subscription is always successful.
143 4 Andreas Smas
When the server is ready to transmit data it will first send a 'subscriptionStart' message.
144
145 1 Andreas Smas
146
147
Request message fields:
148 8 Andreas Smas
{{{
149
channelId        int  required   ID for channel. 
150
subscriptionId   int  required   Subscription ID. Selected by client. This value is not interpreted by the server in any form. 
151 1 Andreas Smas
                                 The value is used from now on in all messages related to the subscription.
152 6 Andreas Smas
}}}
153
154
Reply message fields:
155
{{{
156 4 Andreas Smas
None.
157 6 Andreas Smas
}}}
158 5 Andreas Smas
159 1 Andreas Smas
160 5 Andreas Smas
----
161 1 Andreas Smas
=== unsubscribe ===
162 5 Andreas Smas
163
Stop a subscription.
164 1 Andreas Smas
Attributes
165
{{{
166 6 Andreas Smas
subscriptionId   int  required   Subscription ID.
167
}}}
168
169
Reply message fields:
170 2 Andreas Smas
{{{
171
None.
172
}}}
173
174
175
----
176 12 Andreas Smas
177 2 Andreas Smas
= Server to Client methods =
178 1 Andreas Smas
179 11 Andreas Smas
----
180
=== channelAdd ===
181
182
A new channel has been created on the server.
183
184
Message fields:
185
{{{
186
channelId        int   required   ID of channel.
187 13 Andreas Smas
channelName      str   required   Name of channel.
188 11 Andreas Smas
channelIcon      str   required   URL to an icon representative for the channel.
189
eventId          int   optional   ID of the current (or next to be) event on this channel.
190 12 Andreas Smas
tags             int[] optional   Tags this channel is mapped to.
191 1 Andreas Smas
}}}
192
193 11 Andreas Smas
----
194
=== channelUpdate ===
195 1 Andreas Smas
196 11 Andreas Smas
A channel has been updated on the server. All fields will be sent even if they are not changed. Most clients can process this and the 'channelAdd' message
197
with the very same code.
198
199
Message fields:
200
{{{
201
channelId        int   required   ID of channel.
202
channelName      str   required   Name of channel.
203
channelIcon      str   optioanl   URL to an icon representative for the channel.
204 13 Andreas Smas
eventId          int   optional   ID of the current (or next to be) event on this channel.
205 12 Andreas Smas
tags             int[] required   Tags this channel is mapped to.
206 3 Andreas Smas
}}}
207 1 Andreas Smas
208 11 Andreas Smas
----
209 1 Andreas Smas
=== channelDelete ===
210 11 Andreas Smas
211
A channel has been deleted on the server.
212
213
This message is only sent if session is in asynchronous mode.
214
215
Message fields:
216
{{{
217 12 Andreas Smas
channelId        int   required   ID of channel.
218 11 Andreas Smas
}}}
219 1 Andreas Smas
220 11 Andreas Smas
----
221
=== tagAdd ===
222
223
A new tag has been created on the server.
224 13 Andreas Smas
225 11 Andreas Smas
Message fields:
226
{{{
227
tagId            int   required   ID of tag.
228
tagName          str   required   Name of tag.
229
tagIcon          str   optional   URL to an icon representative for the channel.
230 1 Andreas Smas
channels         int[] required   Channels this tag is mapped to.
231 11 Andreas Smas
}}}
232 1 Andreas Smas
233 11 Andreas Smas
----
234
=== tagUpdate ===
235
236
A tag has been updated on the server.
237 13 Andreas Smas
238 11 Andreas Smas
Message fields:
239
{{{
240
tagId            int   required   ID of tag.
241
tagName          str   required   Name of tag.
242
tagIcon          str   optional   URL to an icon representative for the channel.
243 12 Andreas Smas
channels         int[] required   Channels this tag is mapped to.
244 1 Andreas Smas
}}}
245
246 11 Andreas Smas
----
247
=== tagDelete ===
248
249 1 Andreas Smas
A tag has been deleted from the server.
250 11 Andreas Smas
251
Message fields:
252 1 Andreas Smas
{{{
253 11 Andreas Smas
tagId            str   required   ID of tag.
254
}}}
255 12 Andreas Smas
256 11 Andreas Smas
----
257 2 Andreas Smas
=== subscriptionStart ===
258 14 Andreas Smas
259
Message fields:
260
{{{
261
subscriptionId   int   required   Subscription ID.
262
streams          msg[] required   Array of messages with stream information
263
264
265
'streams' message:
266
267
index            int   required   Index for this stream
268
type             str   required   Type of stream
269
language         str   optional   Language for stream
270
271
272
Stream types:
273
    AC3                           AC3 audio
274
    MPEG2AUDIO                    MPEG2 audio (MP2)
275
    MPEG2VIDEO                    MPEG2 video
276
    H264                          H264 video
277
278
279
}}}
280 12 Andreas Smas
281 2 Andreas Smas
----
282
=== subscriptionStop ===
283 15 Andreas Smas
284
Message fields:
285
{{{
286
subscriptionId   int   required   Subscription ID.
287
reason           str   optional   Reason for subscription stop.
288
}}}
289 12 Andreas Smas
290 2 Andreas Smas
----
291
=== subscriptionStatus ===
292 15 Andreas Smas
293
Message fields:
294
{{{
295
subscriptionId   int   required   Subscription ID.
296
status           str   optional   English clear text of status. Absence of this field means that the status is OK. 
297
}}}
298
299 12 Andreas Smas
300 2 Andreas Smas
----
301 15 Andreas Smas
=== queueStatus ===
302
303
The queueStatus message is sent every second during normal data delivery.
304
305
The transmit scheduler have different drop thresholds for different frame types.
306
If congestion occurs it will favor dropping B-frames before P-frames before I-frames.
307
All audio is recognized as I-frames. 
308
309
Message fields:
310
{{{
311
subscriptionId   int   required   Subscription ID.
312
packets          int   required   Number of data packets in queue.
313
bytes            int   required   Number of bytes in queue.
314
delay            int   required   Estimated delay of queue (in µs)
315
Bdrops           int   required   Number of B-frames dropped
316
Pdrops           int   required   Number of P-frames dropped
317
Idrops           int   required   Number of I-frames dropped
318 16 Andreas Smas
}}}
319
320
----
321
=== muxpkt ===
322
323
Streaming data.
324
325
Message fields:
326
{{{
327
subscriptionId   int   required   Subscription ID.
328
frametype        int   required   Type of frame as ASCII value: 'I', 'P', 'B'
329
stream           int   required   Stream index. Corresponds to the streams reported in the subscriptionStart message.
330
dts              int   required   Decode Time Stamp in µs.
331
pts              int   required   Presentation Time Stamp in µs.
332
duration         int   required   Duration of frame in µs.
333
payload          bin   required   Actual frame data.
334
335 1 Andreas Smas
}}}