Project

General

Profile

Htsp » History » Version 52

magnus -, 2010-05-27 22:11
Correct link to Showtime HTSP client code

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 52 magnus -
The HTS Showtime client can be found [http://trac.lonelycoder.com/hts/browser/trunk/showtime/src/backend/htsp/htsp.c here].
14 22 Andreas Smas
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 28 Andreas Smas
Apart from this there is a number of messages that needs to be exchanged during login, see the login section below.
23
24 17 Andreas Smas
=== RPC communication ===
25 1 Andreas Smas
26 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:
27
28
RPC request extra fields:
29 17 Andreas Smas
{{{
30 1 Andreas Smas
seq              int  optional   Sequence number. This field will be echoed back by the server in the reply.
31 28 Andreas Smas
username         str  optional   Username, in combination with 'digest' this can be used to raise the privileges
32
                                 for the session in combination with invocation of a method. 
33
digest           bin  optional   Used to raise privileges.
34 1 Andreas Smas
}}}
35 28 Andreas Smas
36
The followings field should be used by the client to match the reply with the request.
37 18 Andreas Smas
All replies are guaranteed to arrive in the same order as the requests.
38
Even so, probably the best way to implement the request-reply client is by taking advantage of the 'seq' field.
39 1 Andreas Smas
40 18 Andreas Smas
RPC reply extra fields:
41
{{{
42 19 Andreas Smas
seq              int  optional   Sequence number. Same as in the request.
43
error            str  optional   If present an error has occurred and the text describes the error.
44 18 Andreas Smas
noaccess         int  optional   If present and set to '1' the user is prohibited from invoking the method due to 
45 19 Andreas Smas
                                 access restrictions. 
46 18 Andreas Smas
}}}
47 1 Andreas Smas
48 18 Andreas Smas
=== Streaming communication ===
49 19 Andreas Smas
50 1 Andreas Smas
For streaming of live TV and various related messages the server will continuously push data to the client.
51
These messages are referred to as asynchronous messages and always have the 'method' field set and never have the 'seq' field set.
52
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). 
53
54
=== Authentication ===
55
56 34 Andreas Smas
In Tvheadend, each method has an associated access restriction. Currently there is only one restriction (Streaming). However, this may change in the future.
57 29 Andreas Smas
58 1 Andreas Smas
Privileges for these restrictions may be granted in two ways: Username + Password and/or Source IP address.
59 29 Andreas Smas
Therefore it is possible to gain permissions to the system without entering a username and password.
60 7 Andreas Smas
While this is really useful it also complicates the authentication schema a bit.
61 29 Andreas Smas
Upon connect the initial privileges will be raised based on the source address.
62 1 Andreas Smas
63 34 Andreas Smas
Before any username / password based authentication has taken place the client must have
64
obtained a challenge (which stays fixed for the session). This is done via the 'hello' method.
65
66 1 Andreas Smas
In principle it's possible to use two different authentication idioms with HTSP.
67
Depending on how your application works one or another may be more suitable.
68
While they do not really differ from a protocol point of view it's worth mentioning a bit about them here:
69
70
=== Initial login authentication ===
71
72
The client performs all of its authentication using the 'login' method.
73
74
It may choose to send:
75
 * Username and password: Privileges will be raised based on these credentials.
76
 * Username only: Privileges will be based on just the source address. The username will be used for various logging purposes.
77
 * Nothing: Privileges will be based on just the source address.
78
79
If no privileges are granted after the login message has been received by the server (i.e. both network and username + password based)
80
the server will reply with 'noaccess' set to 1. A client that only employs initial login should honor this flag and ask the
81
user for a username + password and retry by using the 'authenticate' method. I.e. it should not send the 'login' method again.
82
83
=== On-demand authentication ===
84
85
The client performs all of its authentication when it needs to.
86
87
When using this method, the client will check every RPC reply for the 'noaccess' field.
88
If it set to 1 it whould ask the user for username + password and retry the request but also
89
add 'username' and 'digest' to the original message. (See ''RPC request extra fields'' above)
90
91
Typically it would not send a username or digest during login.
92 29 Andreas Smas
93
----
94
= Client to Server (RPC) methods =
95 34 Andreas Smas
96
97
98
----
99
=== hello ===
100
101
Used to identify the client toward the server and to get the session challenge used to
102
hash passwords into digests. The client can request a different version of the HTSP
103
protocol with this method. If no 'hello' message is sent the server assumes version 1
104
is to be used.
105
106
107
Request message fields:
108
{{{
109
htspversion      int  required   Client preferred HTSP version. If the server does not support this version
110
                                 it will respond with an error and also set the 'invalidversion' field in the reply. 
111
clientname       str  required   Client software name.
112
clientversion    str  required   Client software version.
113
}}}
114
115
116
Reply message fields:
117
{{{
118
htspversion      int  required   The server supports all versions of the protocol up to and including this number.
119
servername       str  required   Server software name.
120
serverversion    str  required   Server software version.
121
challenge        bin  required   32 bytes randomized data used to generate authentication digests
122
invalidversion   int  optional   If set, this means that the server does not understand the requested version.
123
                                 The 'error' field is also set to indicate an error.
124
}}}
125 33 Andreas Smas
126
127
----
128
=== authenticate ===
129
130
This can be used to issue authentication without doing anything else.
131
If no privileges are gained it will return with 'noaccess' set to 1.
132
133
Request message fields:
134
{{{
135
None
136
}}}
137
138
Reply message fields:
139
{{{
140
None
141
}}}
142 10 Andreas Smas
143
----
144
=== enableAsyncMetadata ===
145
146
When this is enabled the client will get continuous updates from the server about channels and tags.
147
This also includes creation and deletion of channels and tags. 
148
149
An interactive application that presents the user with information about channels and tags would probably want to switch to this mode.
150
151
152
Request message fields:
153
{{{
154
None
155
}}}
156
157 1 Andreas Smas
Reply message fields:
158 5 Andreas Smas
{{{
159 1 Andreas Smas
None
160 6 Andreas Smas
}}}
161 23 Andreas Smas
162
163
164
----
165
=== getEvent ===
166
167
Request information about the given event. An event typically corresponds to a program on a channel.
168
169
Request message fields:
170
{{{
171
eventId          int  required   Event ID.
172
}}}
173
174
Reply message fields:
175
{{{
176
start            int  required   Start time of event (Seconds since the epoch, in UTC)
177 6 Andreas Smas
stop             int  required   Ending time of event (Seconds since the epoch, in UTC)
178 47 mdd -
title            str  optional   Title of event.
179
description      str  optional   Description of event. This can be quite huge and may also contain newlines.
180 1 Andreas Smas
channelId        int  required   ID of channel (introduced in HTSP version 4)
181 43 mdd -
nextEventId      int  optional   ID of next event on the same channel.
182 49 mdd -
contentType      int  optional   dvb content code (introduced in HTSP version 4)
183 25 Andreas Smas
}}}
184 1 Andreas Smas
185
----
186 44 mdd -
=== getEvents ===
187
188
Introduced in HTSP version 4.
189
190
Request information about numFollowing events, starting with the given event
191
192
Request message fields:
193
{{{
194
eventId          int   required   Event ID.
195 45 mdd -
numFollowing     int   required   Number of events to add
196 44 mdd -
}}}
197
198
Reply message fields:
199 1 Andreas Smas
{{{
200 45 mdd -
events           msg[] required   List of events, using response message fields from getEvent
201
}}}
202
203
----
204
=== addDvrEntry ===
205
206
Introduced in HTSP version 4.
207
208
Adds an dvr entry for the given eventId.
209
210
Request message fields:
211
{{{
212
eventId          int   required   Event ID.
213
}}}
214
215
Reply message fields:
216
{{{
217
success          int   required   1 if entry was added, 0 otherwise
218
error            str   optional   English clear text of error message
219
}}}
220
221
----
222
=== deleteDvrEntry ===
223
224
Introduced in HTSP version 4.
225
226
Delete a dvr entry with the given id.
227
228
Request message fields:
229
{{{
230
dvrEntryId       int   required   dvrEnryId to delete
231
}}}
232
233
Reply message fields:
234
{{{
235
success          int   required   1 if entry was removed
236 44 mdd -
}}}
237
238
----
239 46 mdd -
=== epgQuery ===
240
241
Introduced in HTSP version 4.
242
243
query the epg, optionally restrict to channels/tags/dvb content type
244
245
Request message fields:
246
{{{
247
query            str   required  String to query epg for
248
channelId        int   optional  ChannelId to restrict search to
249
tagId            int   optional  TagId to restrict search to
250
contentType      int   optional  Dvb epg content type to restrict search to
251
}}}
252
253
Reply message fields:
254
{{{
255
eventIds         int[] optional  List of eventIds that match the query
256
}}}
257
258
----
259 8 Andreas Smas
=== subscribe ===
260
261
Request subscription to the given channel. 
262 1 Andreas Smas
263 6 Andreas Smas
Request message fields:
264
{{{
265
channelId        int  required   ID for channel. 
266
subscriptionId   int  required   Subscription ID. Selected by client. This value is not interpreted by the server in any form. 
267 4 Andreas Smas
                                 The value is used from now on in all messages related to the subscription.
268 6 Andreas Smas
}}}
269 5 Andreas Smas
270 1 Andreas Smas
Reply message fields:
271 5 Andreas Smas
{{{
272 1 Andreas Smas
None.
273 5 Andreas Smas
}}}
274
275 1 Andreas Smas
276
----
277 6 Andreas Smas
=== unsubscribe ===
278
279
Stop a subscription.
280
Attributes
281 2 Andreas Smas
{{{
282
subscriptionId   int  required   Subscription ID.
283
}}}
284
285
Reply message fields:
286
{{{
287 12 Andreas Smas
None.
288 2 Andreas Smas
}}}
289 1 Andreas Smas
290 40 Andreas Smas
----
291
=== getDiskSpace ===
292
293
Introduced in HTSP version 3.
294
295
Return diskspace status from Tvheadend's PVR storage
296
Attributes
297
{{{
298
}}}
299
300
Reply message fields:
301
{{{
302
freediskspace   int  required   Bytes available.
303
totaldiskspace  int  required   Total capacity.
304
}}}
305
306
----
307
=== getSysTime ===
308
309
Introduced in HTSP version 3.
310
311
Return system time on server
312
Attributes
313
{{{
314
}}}
315
316
Reply message fields:
317
{{{
318
time            int  required   Seconds since the unix epoch.
319
timezone        int  required   Minutes west of GMT.
320
}}}
321 11 Andreas Smas
322
----
323
324
= Server to Client methods =
325
326
----
327
=== channelAdd ===
328
329 13 Andreas Smas
A new channel has been created on the server.
330 11 Andreas Smas
331
Message fields:
332 12 Andreas Smas
{{{
333 1 Andreas Smas
channelId        int   required   ID of channel.
334
channelName      str   required   Name of channel.
335 42 Andreas Smas
channelNumber    int   required   Channel number. 0 means unconfigured
336 11 Andreas Smas
channelIcon      str   required   URL to an icon representative for the channel.
337
eventId          int   optional   ID of the current (or next to be) event on this channel.
338 1 Andreas Smas
tags             int[] optional   Tags this channel is mapped to.
339 11 Andreas Smas
}}}
340
341
----
342
=== channelUpdate ===
343
344 41 Andreas Smas
A channel has been updated on the server. If a field is not present it has not changed. Most clients can process this and the 'channelAdd' message
345 11 Andreas Smas
with the very same code.
346
347 13 Andreas Smas
Message fields:
348 12 Andreas Smas
{{{
349 3 Andreas Smas
channelId        int   required   ID of channel.
350 41 Andreas Smas
channelName      str   optional   Name of channel.
351 42 Andreas Smas
channelNumber    int   optional   Channel number. 0 means unconfigured
352 11 Andreas Smas
channelIcon      str   optioanl   URL to an icon representative for the channel.
353 1 Andreas Smas
eventId          int   optional   ID of the current (or next to be) event on this channel.
354 11 Andreas Smas
tags             int[] required   Tags this channel is mapped to.
355
}}}
356
357
----
358
=== channelDelete ===
359
360
A channel has been deleted on the server.
361 12 Andreas Smas
362 11 Andreas Smas
This message is only sent if session is in asynchronous mode.
363 1 Andreas Smas
364 11 Andreas Smas
Message fields:
365
{{{
366
channelId        int   required   ID of channel.
367
}}}
368 13 Andreas Smas
369 11 Andreas Smas
----
370
=== tagAdd ===
371
372
A new tag has been created on the server.
373
374 1 Andreas Smas
Message fields:
375 11 Andreas Smas
{{{
376 1 Andreas Smas
tagId            int   required   ID of tag.
377 11 Andreas Smas
tagName          str   required   Name of tag.
378
tagIcon          str   optional   URL to an icon representative for the channel.
379 39 elupus -
members          int[] required   Channels this tag is mapped to.
380 11 Andreas Smas
}}}
381 13 Andreas Smas
382 11 Andreas Smas
----
383
=== tagUpdate ===
384
385
A tag has been updated on the server.
386
387 12 Andreas Smas
Message fields:
388 1 Andreas Smas
{{{
389
tagId            int   required   ID of tag.
390 11 Andreas Smas
tagName          str   required   Name of tag.
391
tagIcon          str   optional   URL to an icon representative for the channel.
392 39 elupus -
members          int[] required   Channels this tag is mapped to.
393 1 Andreas Smas
}}}
394 11 Andreas Smas
395
----
396 1 Andreas Smas
=== tagDelete ===
397 11 Andreas Smas
398
A tag has been deleted from the server.
399 12 Andreas Smas
400 11 Andreas Smas
Message fields:
401 2 Andreas Smas
{{{
402 14 Andreas Smas
tagId            str   required   ID of tag.
403
}}}
404
405
----
406 48 mdd -
=== dvrEntryAdd ===
407
408
A new recording has been created on the server.
409
410
Added in HTSP version 4.
411
412
Message fields:
413
{{{
414
id               int   required   ID of dvrEntry.
415
channel          int   required   Channel of dvrEntry.
416 51 elupus -
start            int   required   Time of when this entry was scheduled to start recording.
417
stop             int   required   Time of when this entry was scheduled to stop recording.
418 48 mdd -
title            str   optional   Title of recording
419
description      str   optional   Description of recording. This can be quite huge and may also contain newlines.
420
state            str   required   Plain english status of recoding {scheduled, recording, completed, invalid}.
421
error            str   optional   Plain english error description (e.g. "Aborted by user").
422
}}}
423
424
----
425
=== dvrEntryUpdate ===
426
427
A recording has been updated on the server
428
429
Added in HTSP version 4.
430
431
Message fields:
432
{{{
433
id               int   required   ID of dvrEntry.
434
channel          int   required   Channel of dvrEntry.
435 51 elupus -
start            int   required   Time of when this entry was scheduled to start recording.
436
stop             int   required   Time of when this entry was scheduled to stop recording.
437 48 mdd -
title            str   optional   Title of recording
438
description      str   optional   Description of recording. This can be quite huge and may also contain newlines.
439
state            str   required   Plain english status of recoding {scheduled, recording, completed, invalid}.
440
error            str   optional   Plain english error description (e.g. "Aborted by user").
441
}}}
442
443
----
444
=== dvrEntryDelete ===
445
446
A recording has been deleted from the server.
447
448
Added in HTSP version 4.
449
450
Message fields:
451
{{{
452
id               int   required   ID of recording to delete.
453
}}}
454
455
----
456 35 Andreas Smas
=== initialSyncCompleted ===
457
458
Sent after all the initial channel and tag messages has been sent when session has been set to async mode.
459
460
Added in HTSP version 2.
461
462
Message fields:
463
{{{
464
}}}
465
466
----
467 14 Andreas Smas
=== subscriptionStart ===
468
469
Message fields:
470
{{{
471
subscriptionId   int   required   Subscription ID.
472
streams          msg[] required   Array of messages with stream information
473 38 Andreas Smas
sourceinfo       msg   optional   Message with strings in it. Each string is a descriptive
474
                                  entity about the source. All strings are optional any should
475
                                  only be thought of as informational.
476 14 Andreas Smas
477
'streams' message:
478
479
index            int   required   Index for this stream
480
type             str   required   Type of stream
481
language         str   optional   Language for stream
482
483
484 1 Andreas Smas
Stream types:
485 14 Andreas Smas
    AC3                           AC3 audio
486
    MPEG2AUDIO                    MPEG2 audio (MP2)
487 21 Andreas Smas
    MPEG2VIDEO                    MPEG2 video
488 12 Andreas Smas
    H264                          H264 video
489 37 Andreas Smas
    AAC                           ADTS framed AAC (one AAC packet per ADTS frame)
490 15 Andreas Smas
}}}
491
492
493
----
494
=== subscriptionStop ===
495
496 12 Andreas Smas
Message fields:
497 2 Andreas Smas
{{{
498
subscriptionId   int   required   Subscription ID.
499 15 Andreas Smas
reason           str   optional   Reason for subscription stop.
500
}}}
501
502
----
503
=== subscriptionStatus ===
504
505
Message fields:
506 1 Andreas Smas
{{{
507 2 Andreas Smas
subscriptionId   int   required   Subscription ID.
508 37 Andreas Smas
status           str   optional   English clear text of error status. Absence of this field means that the status is OK. 
509 15 Andreas Smas
}}}
510
511
512
----
513
=== queueStatus ===
514
515
The queueStatus message is sent every second during normal data delivery.
516
517
The transmit scheduler have different drop thresholds for different frame types.
518
If congestion occurs it will favor dropping B-frames before P-frames before I-frames.
519
All audio is recognized as I-frames. 
520
521
Message fields:
522
{{{
523
subscriptionId   int   required   Subscription ID.
524
packets          int   required   Number of data packets in queue.
525 16 Andreas Smas
bytes            int   required   Number of bytes in queue.
526
delay            int   required   Estimated delay of queue (in µs)
527
Bdrops           int   required   Number of B-frames dropped
528
Pdrops           int   required   Number of P-frames dropped
529
Idrops           int   required   Number of I-frames dropped
530
}}}
531
532
----
533
=== muxpkt ===
534
535
Streaming data.
536
537
Message fields:
538
{{{
539
subscriptionId   int   required   Subscription ID.
540
frametype        int   required   Type of frame as ASCII value: 'I', 'P', 'B'
541
stream           int   required   Stream index. Corresponds to the streams reported in the subscriptionStart message.
542 1 Andreas Smas
dts              int   required   Decode Time Stamp in µs.
543
pts              int   required   Presentation Time Stamp in µs.
544
duration         int   required   Duration of frame in µs.
545
payload          bin   required   Actual frame data.
546
547
}}}