Project

General

Profile

Htsp » History » Version 23

Andreas Smas, 2009-02-28 18:30

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