Project

General

Profile

Htsp » History » Version 24

Andreas Smas, 2009-02-28 18:32

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 24 Andreas Smas
It is also possible to have the client authenticate itself without it having to be a direct result of a denied method invocation.
83
This can be done by just asking for a challenge (using the 'getChallenge' request) and then perform an 'authenticate' request.
84
85 1 Andreas Smas
----
86 17 Andreas Smas
= Client to Server (RPC) methods =
87 1 Andreas Smas
88 5 Andreas Smas
----
89 1 Andreas Smas
=== getChallenge ===
90
91 7 Andreas Smas
Request a 32 byte challenge used to generate a authentication digest.
92
93
Request message fields:
94
{{{
95
None
96
}}}
97
98
Reply message fields:
99
{{{
100 9 Andreas Smas
challenge        bin  required   32 bytes of random challenge to be used in next authentication request from client.
101 7 Andreas Smas
}}}
102
103
104 5 Andreas Smas
----
105 1 Andreas Smas
=== authenticate ===
106 8 Andreas Smas
107
Request message fields:
108 7 Andreas Smas
{{{
109
username         str  required   Username.
110
digest           bin  required   SHA-1 hash of [password (not including terminating NUL)] + [challenge]
111
}}}
112 1 Andreas Smas
113 9 Andreas Smas
Reply message fields:
114
{{{
115
noaccess         int  optional   Set to '1' if access was denied.
116 1 Andreas Smas
challenge        bin  optional   32 bytes of random challenge to be used in next authentication request from client.
117 7 Andreas Smas
                                 Always present if 'noaccess' is set. This is supplied so the client does not have
118
                                 to issue an extra 'getChallenge' request.
119
}}}
120 5 Andreas Smas
121 10 Andreas Smas
122
----
123 18 Andreas Smas
=== enableAsyncMetadata ===
124 10 Andreas Smas
125 18 Andreas Smas
When this is enabled the client will get continuous updates from the server about channels and tags.
126 10 Andreas Smas
This also includes creation and deletion of channels and tags. 
127
128
An interactive application that presents the user with information about channels and tags would probably want to switch to this mode.
129
130
131
Request message fields:
132
{{{
133
None
134
}}}
135
136
Reply message fields:
137
{{{
138
None
139
}}}
140
141 1 Andreas Smas
142 5 Andreas Smas
143 1 Andreas Smas
----
144 6 Andreas Smas
=== getEvent ===
145 23 Andreas Smas
146
Request information about the given event. An event typically corresponds to a program on a channel.
147
148
Request message fields:
149
{{{
150
eventId          int  required   Event ID.
151
}}}
152
153
Reply message fields:
154
{{{
155
start            int  required   Start time of event (Seconds since the epoch, in UTC)
156
stop             int  required   Ending time of event (Seconds since the epoch, in UTC)
157
title            str  required   Title of event.
158
description      str  required   Description of event. This can be quite huge and may also contain newlines.
159
nextEventId      int  optional   ID of next event on the same channel.
160
}}}
161 6 Andreas Smas
162 1 Andreas Smas
----
163 6 Andreas Smas
=== subscribe ===
164
165
Request subscription to the given channel. A request for a subscription is always successful.
166 4 Andreas Smas
When the server is ready to transmit data it will first send a 'subscriptionStart' message.
167
168 1 Andreas Smas
169
170
Request message fields:
171 8 Andreas Smas
{{{
172
channelId        int  required   ID for channel. 
173
subscriptionId   int  required   Subscription ID. Selected by client. This value is not interpreted by the server in any form. 
174 1 Andreas Smas
                                 The value is used from now on in all messages related to the subscription.
175 6 Andreas Smas
}}}
176
177
Reply message fields:
178
{{{
179 4 Andreas Smas
None.
180 6 Andreas Smas
}}}
181 5 Andreas Smas
182 1 Andreas Smas
183 5 Andreas Smas
----
184 1 Andreas Smas
=== unsubscribe ===
185 5 Andreas Smas
186
Stop a subscription.
187 1 Andreas Smas
Attributes
188
{{{
189 6 Andreas Smas
subscriptionId   int  required   Subscription ID.
190
}}}
191
192
Reply message fields:
193 2 Andreas Smas
{{{
194
None.
195
}}}
196
197
198
----
199 12 Andreas Smas
200 2 Andreas Smas
= Server to Client methods =
201 1 Andreas Smas
202 11 Andreas Smas
----
203
=== channelAdd ===
204
205
A new channel has been created on the server.
206
207
Message fields:
208
{{{
209
channelId        int   required   ID of channel.
210 13 Andreas Smas
channelName      str   required   Name of channel.
211 11 Andreas Smas
channelIcon      str   required   URL to an icon representative for the channel.
212
eventId          int   optional   ID of the current (or next to be) event on this channel.
213 12 Andreas Smas
tags             int[] optional   Tags this channel is mapped to.
214 1 Andreas Smas
}}}
215
216 11 Andreas Smas
----
217
=== channelUpdate ===
218 1 Andreas Smas
219 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
220
with the very same code.
221
222
Message fields:
223
{{{
224
channelId        int   required   ID of channel.
225
channelName      str   required   Name of channel.
226
channelIcon      str   optioanl   URL to an icon representative for the channel.
227 13 Andreas Smas
eventId          int   optional   ID of the current (or next to be) event on this channel.
228 12 Andreas Smas
tags             int[] required   Tags this channel is mapped to.
229 3 Andreas Smas
}}}
230 1 Andreas Smas
231 11 Andreas Smas
----
232 1 Andreas Smas
=== channelDelete ===
233 11 Andreas Smas
234
A channel has been deleted on the server.
235
236
This message is only sent if session is in asynchronous mode.
237
238
Message fields:
239
{{{
240 12 Andreas Smas
channelId        int   required   ID of channel.
241 11 Andreas Smas
}}}
242 1 Andreas Smas
243 11 Andreas Smas
----
244
=== tagAdd ===
245
246
A new tag has been created on the server.
247 13 Andreas Smas
248 11 Andreas Smas
Message fields:
249
{{{
250
tagId            int   required   ID of tag.
251
tagName          str   required   Name of tag.
252
tagIcon          str   optional   URL to an icon representative for the channel.
253 1 Andreas Smas
channels         int[] required   Channels this tag is mapped to.
254 11 Andreas Smas
}}}
255 1 Andreas Smas
256 11 Andreas Smas
----
257
=== tagUpdate ===
258
259
A tag has been updated on the server.
260 13 Andreas Smas
261 11 Andreas Smas
Message fields:
262
{{{
263
tagId            int   required   ID of tag.
264
tagName          str   required   Name of tag.
265
tagIcon          str   optional   URL to an icon representative for the channel.
266 12 Andreas Smas
channels         int[] required   Channels this tag is mapped to.
267 1 Andreas Smas
}}}
268
269 11 Andreas Smas
----
270
=== tagDelete ===
271
272 1 Andreas Smas
A tag has been deleted from the server.
273 11 Andreas Smas
274
Message fields:
275 1 Andreas Smas
{{{
276 11 Andreas Smas
tagId            str   required   ID of tag.
277
}}}
278 12 Andreas Smas
279 11 Andreas Smas
----
280 2 Andreas Smas
=== subscriptionStart ===
281 14 Andreas Smas
282
Message fields:
283
{{{
284
subscriptionId   int   required   Subscription ID.
285
streams          msg[] required   Array of messages with stream information
286
287
288
'streams' message:
289
290
index            int   required   Index for this stream
291
type             str   required   Type of stream
292
language         str   optional   Language for stream
293
294
295
Stream types:
296
    AC3                           AC3 audio
297
    MPEG2AUDIO                    MPEG2 audio (MP2)
298
    MPEG2VIDEO                    MPEG2 video
299
    H264                          H264 video
300 1 Andreas Smas
301 14 Andreas Smas
302
}}}
303 21 Andreas Smas
304 12 Andreas Smas
305 2 Andreas Smas
----
306
=== subscriptionStop ===
307 15 Andreas Smas
308
Message fields:
309
{{{
310
subscriptionId   int   required   Subscription ID.
311
reason           str   optional   Reason for subscription stop.
312
}}}
313 12 Andreas Smas
314 2 Andreas Smas
----
315
=== subscriptionStatus ===
316 15 Andreas Smas
317
Message fields:
318
{{{
319
subscriptionId   int   required   Subscription ID.
320
status           str   optional   English clear text of status. Absence of this field means that the status is OK. 
321
}}}
322
323 12 Andreas Smas
324 2 Andreas Smas
----
325 15 Andreas Smas
=== queueStatus ===
326
327
The queueStatus message is sent every second during normal data delivery.
328
329
The transmit scheduler have different drop thresholds for different frame types.
330
If congestion occurs it will favor dropping B-frames before P-frames before I-frames.
331
All audio is recognized as I-frames. 
332
333
Message fields:
334
{{{
335
subscriptionId   int   required   Subscription ID.
336
packets          int   required   Number of data packets in queue.
337
bytes            int   required   Number of bytes in queue.
338
delay            int   required   Estimated delay of queue (in µs)
339
Bdrops           int   required   Number of B-frames dropped
340
Pdrops           int   required   Number of P-frames dropped
341
Idrops           int   required   Number of I-frames dropped
342 16 Andreas Smas
}}}
343
344
----
345
=== muxpkt ===
346
347
Streaming data.
348
349
Message fields:
350
{{{
351
subscriptionId   int   required   Subscription ID.
352
frametype        int   required   Type of frame as ASCII value: 'I', 'P', 'B'
353
stream           int   required   Stream index. Corresponds to the streams reported in the subscriptionStart message.
354
dts              int   required   Decode Time Stamp in µs.
355
pts              int   required   Presentation Time Stamp in µs.
356
duration         int   required   Duration of frame in µs.
357
payload          bin   required   Actual frame data.
358
359 1 Andreas Smas
}}}