forked from rofafor/vdr-plugin-iptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocolcurl.cpp
675 lines (543 loc) · 21.2 KB
/
protocolcurl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
* protocolcurl.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "common.h"
#include "config.h"
#include "log.h"
#include "protocolcurl.h"
#ifdef CURLOPT_RTSPHEADER
#define USE_RTSP
#endif
#define iptv_curl_easy_setopt(X, Y, Z) \
if ((res = curl_easy_setopt((X), (Y), (Z))) != CURLE_OK) { \
error("curl_easy_setopt(%s, %s) failed: %s (%d)", #Y, #Z, curl_easy_strerror(res), res); \
}
#define iptv_curl_easy_perform(X) \
if ((res = curl_easy_perform((X))) != CURLE_OK) { \
error("curl_easy_perform() failed: %s (%d)", curl_easy_strerror(res), res); \
}
cIptvProtocolCurl::cIptvProtocolCurl()
: streamUrlM(""),
streamParamM(0),
streamPortM(0),
mutexM(),
handleM(nullptr),
multiM(nullptr),
headerListM(nullptr),
ringBufferM(new cRingBufferLinear(IPTV_BUFFER_SIZE, 7*TS_SIZE, false, "IPTV CURL")),
rtspControlM(""),
modeM(eModeUnknown),
timeoutM(),
connectedM(false),
pausedM(false) {
debug1("%s", __PRETTY_FUNCTION__);
if (ringBufferM) {
ringBufferM->SetTimeouts(100, 0);
ringBufferM->SetIoThrottle();
}
Connect();
}
cIptvProtocolCurl::~cIptvProtocolCurl() {
debug1("%s", __PRETTY_FUNCTION__);
Disconnect();
// Free allocated memory
DELETE_POINTER(ringBufferM);
}
int cIptvProtocolCurl::DebugCallback(CURL *handleP, curl_infotype typeP, char *dataP, size_t sizeP, void *userPtrP) {
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
if (obj) {
switch (typeP) {
case CURLINFO_TEXT:debug8("%s INFO %.*s", __PRETTY_FUNCTION__, (int) sizeP, dataP);
break;
case CURLINFO_HEADER_IN:debug8("%s HEAD <<< %.*s", __PRETTY_FUNCTION__, (int) sizeP, dataP);
break;
case CURLINFO_HEADER_OUT:debug8("%s HEAD >>>\n%.*s", __PRETTY_FUNCTION__, (int) sizeP, dataP);
break;
case CURLINFO_DATA_IN:debug8("%s DATA <<< %zu", __PRETTY_FUNCTION__, sizeP);
break;
case CURLINFO_DATA_OUT:debug8("%s DATA >>> %zu", __PRETTY_FUNCTION__, sizeP);
break;
default:
break;
}
}
return 0;
}
size_t cIptvProtocolCurl::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) {
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
size_t len = sizeP*nmembP;
debug16("%s (, %zu, %zu, ) len=%zu", __PRETTY_FUNCTION__, sizeP, nmembP, len);
if (obj && !obj->PutData((unsigned char *) ptrP, (int) len)) {
return CURL_WRITEFUNC_PAUSE;
}
return len;
}
size_t cIptvProtocolCurl::WriteRtspCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) {
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
size_t len = sizeP*nmembP;
unsigned char *p = (unsigned char *) ptrP;
debug16("%s (, %zu, %zu, ) len=%zu", __PRETTY_FUNCTION__, sizeP, nmembP, len);
// Validate packet header ('$') and channel (0)
if (obj && (p[0] == 0x24) && (p[1] == 0)) {
int length = (p[2] << 8) | p[3];
if (length > 3) {
// Skip interleave header
p += 4;
// http://tools.ietf.org/html/rfc3550
// http://tools.ietf.org/html/rfc2250
// Version
unsigned int v = (p[0] >> 6) & 0x03;
// Extension bit
unsigned int x = (p[0] >> 4) & 0x01;
// CSCR count
unsigned int cc = p[0] & 0x0F;
// Payload type: MPEG2 TS = 33
//unsigned int pt = p[1] & 0x7F;
// Header lenght
unsigned int headerlen = (3 + cc) * (unsigned int) sizeof(uint32_t);
// Check if extension
if (x) {
// Extension header length
unsigned int ehl = (((p[headerlen + 2] & 0xFF) << 8) | (p[headerlen + 3] & 0xFF));
// Update header length
headerlen += (ehl + 1) * (unsigned int) sizeof(uint32_t);
}
// Check that rtp is version 2 and payload contains multiple of TS packet data
if ((v == 2) && (((length - headerlen) % TS_SIZE)==0) && (p[headerlen] == TS_SYNC_BYTE)) {
// Set argument point to payload in read buffer
obj->PutData(&p[headerlen], (length - headerlen));
}
}
}
return len;
}
size_t cIptvProtocolCurl::DescribeCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) {
cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
size_t len = sizeP*nmembP;
debug16("%s (, %zu, %zu, ) len=%zu", __PRETTY_FUNCTION__, sizeP, nmembP, len);
bool found = false;
cString control = "";
char *p = (char *) ptrP;
char *r = strtok(p, "\r\n");
while (r) {
debug16("%s (, %zu, %zu, ) len=%zu r=%s", __PRETTY_FUNCTION__, sizeP, nmembP, len, r);
// Look for a media name: "video"
if (strstr(r, "m=video")) {
found = true;
}
// ... and find out its attribute
if (found && strstr(r, "a=control")) {
char *s = nullptr;
if (sscanf(r, "a=control:%255ms", &s)==1)
control = compactspace(s);
free(s);
break;
}
r = strtok(nullptr, "\r\n");
}
if (!isempty(*control) && obj) {
obj->SetRtspControl(*control);
}
return len;
}
size_t cIptvProtocolCurl::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) {
//cIptvProtocolCurl *obj = reinterpret_cast<cIptvProtocolCurl *>(dataP);
size_t len = sizeP*nmembP;
debug16("%s (, %zu, %zu, ) len=%zu", __PRETTY_FUNCTION__, sizeP, nmembP, len);
char *p = (char *) ptrP;
char *r = strtok(p, "\r\n");
while (r) {
debug16("%s (, %zu, %zu, ) len=%zu r=%s", __PRETTY_FUNCTION__, sizeP, nmembP, len, r);
r = strtok(nullptr, "\r\n");
}
return len;
}
void cIptvProtocolCurl::SetRtspControl(const char *controlP) {
cMutexLock MutexLock(&mutexM);
debug16("%s (%s)", __PRETTY_FUNCTION__, controlP);
cString protocol = ChangeCase(controlP, false).Truncate(7);
if (startswith(*protocol, "rtsp://")) {
streamUrlM = controlP;
rtspControlM = "";
} else {
rtspControlM = controlP;
}
}
bool cIptvProtocolCurl::PutData(unsigned char *dataP, int lenP) {
cMutexLock MutexLock(&mutexM);
debug16("%s (, %d)", __PRETTY_FUNCTION__, lenP);
if (pausedM) {
return false;
}
if (ringBufferM && (lenP >= 0)) {
// Should we pause the transfer ?
if (ringBufferM->Free() < (2*CURL_MAX_WRITE_SIZE)) {
debug1("%s Pause free=%d available=%d len=%d", __PRETTY_FUNCTION__, ringBufferM->Free(), ringBufferM->Available(), lenP);
pausedM = true;
return false;
}
int p = ringBufferM->Put(dataP, lenP);
if (p != lenP) {
ringBufferM->ReportOverflow(lenP - p);
}
}
return true;
}
void cIptvProtocolCurl::DelData(int lenP) {
cMutexLock MutexLock(&mutexM);
debug16("%s", __PRETTY_FUNCTION__);
if (ringBufferM && (lenP >= 0)) {
ringBufferM->Del(lenP);
}
}
void cIptvProtocolCurl::ClearData() {
debug16("%s", __PRETTY_FUNCTION__);
if (ringBufferM) {
ringBufferM->Clear();
}
}
unsigned char *cIptvProtocolCurl::GetData(int &lenP) {
cMutexLock MutexLock(&mutexM);
debug16("%s", __PRETTY_FUNCTION__);
unsigned char *p = nullptr;
lenP = 0;
if (ringBufferM) {
int count = 0;
p = ringBufferM->Get(count);
#if 0
if (p && count >= TS_SIZE) {
if (*p != TS_SYNC_BYTE) {
for (int i = 1; i < count; ++i) {
if (p[i] == TS_SYNC_BYTE) {
count = i;
break;
}
}
error("IPTV skipped %d bytes to sync on TS packet", count);
ringBufferM->Del(count);
lenP = 0;
return NULL;
}
}
#endif
count -= (count % TS_SIZE);
lenP = count;
}
return p;
}
bool cIptvProtocolCurl::Connect() {
cMutexLock MutexLock(&mutexM);
debug1("%s", __PRETTY_FUNCTION__);
if (connectedM) {
return true;
}
// Initialize the curl session
if (!handleM) {
handleM = curl_easy_init();
}
if (handleM && !isempty(*streamUrlM)) {
CURLcode res = CURLE_OK;
cString netrc = cString::sprintf("%s/netrc", IptvConfig.GetConfigDirectory());
// Verbose output
iptv_curl_easy_setopt(handleM, CURLOPT_VERBOSE, 1L);
iptv_curl_easy_setopt(handleM, CURLOPT_DEBUGFUNCTION, cIptvProtocolCurl::DebugCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_DEBUGDATA, this);
// Set callbacks
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, cIptvProtocolCurl::WriteCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_HEADERFUNCTION, cIptvProtocolCurl::HeaderCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEHEADER, this);
// No progress meter and no signaling
iptv_curl_easy_setopt(handleM, CURLOPT_NOPROGRESS, 1L);
iptv_curl_easy_setopt(handleM, CURLOPT_NOSIGNAL, 1L);
// Support netrc
iptv_curl_easy_setopt(handleM, CURLOPT_NETRC, (long) CURL_NETRC_OPTIONAL);
iptv_curl_easy_setopt(handleM, CURLOPT_NETRC_FILE, *netrc);
// Set timeouts
iptv_curl_easy_setopt(handleM, CURLOPT_CONNECTTIMEOUT, (long) eConnectTimeoutS);
iptv_curl_easy_setopt(handleM, CURLOPT_LOW_SPEED_LIMIT, (long) eLowSpeedLimitBytes);
iptv_curl_easy_setopt(handleM, CURLOPT_LOW_SPEED_TIME, (long) eLowSpeedTimeoutS);
// Set user-agent
iptv_curl_easy_setopt(handleM, CURLOPT_USERAGENT, *cString::sprintf("vdr-%s/%s", PLUGIN_NAME_I18N, VERSION));
// Set URL
char *p = curl_easy_unescape(handleM, *streamUrlM, 0, nullptr);
streamUrlM = p;
curl_free(p);
iptv_curl_easy_setopt(handleM, CURLOPT_URL, *streamUrlM);
// Protocol specific initializations
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp: {
cString uri, control, transport, range;
// Create the listening socket for UDP mode
if (!streamParamM) {
OpenSocket(streamPortM);
}
// Request server options
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_perform(handleM);
// Request session description - SDP is delivered in message body and not in the header!
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, cIptvProtocolCurl::DescribeCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, this);
uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_DESCRIBE);
iptv_curl_easy_perform(handleM);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEFUNCTION, NULL);
iptv_curl_easy_setopt(handleM, CURLOPT_WRITEDATA, NULL);
// Setup media stream
if (isempty(*rtspControlM)) {
uri = cString::sprintf("%s", *streamUrlM);
} else {
uri = cString::sprintf("%s/%s", *streamUrlM, *rtspControlM);
}
if (streamParamM) {
transport = "RTP/AVP/TCP;unicast;interleaved=0-1";
} else {
transport = cString::sprintf("RTP/AVP;unicast;client_port=%d-%d", streamPortM, streamPortM + 1);
}
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_TRANSPORT, *transport);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_SETUP);
iptv_curl_easy_perform(handleM);
// Start playing
uri = cString::sprintf("%s/", *streamUrlM);
range = "0.000-";
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
//iptv_curl_easy_setopt(handleM, CURLOPT_RANGE, *range);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_PLAY);
iptv_curl_easy_perform(handleM);
// Start receiving
if (streamParamM) {
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEFUNCTION, cIptvProtocolCurl::WriteRtspCallback);
iptv_curl_easy_setopt(handleM, CURLOPT_INTERLEAVEDATA, this);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
}
// Don't add handle into multi set
isActiveM = true;
}
break;
#endif
case eModeHttp:
case eModeHttps: {
// Limit download speed (bytes/s)
iptv_curl_easy_setopt(handleM, CURLOPT_MAX_RECV_SPEED_LARGE, eMaxDownloadSpeedMBits*131072L);
// Follow location
iptv_curl_easy_setopt(handleM, CURLOPT_FOLLOWLOCATION, 1L);
// Fail if HTTP return code is >= 400
iptv_curl_easy_setopt(handleM, CURLOPT_FAILONERROR, 1L);
// Set additional headers to prevent caching
headerListM = curl_slist_append(headerListM, "Cache-Control: no-store, no-cache, must-revalidate");
headerListM = curl_slist_append(headerListM, "Cache-Control: post-check=0, pre-check=0");
headerListM = curl_slist_append(headerListM, "Pragma: no-cache");
headerListM = curl_slist_append(headerListM, "Expires: Mon, 26 Jul 1997 05:00:00 GMT");
iptv_curl_easy_setopt(handleM, CURLOPT_HTTPHEADER, headerListM);
// Initialize multi set and add handle into it
if (!multiM)
multiM = curl_multi_init();
if (multiM)
curl_multi_add_handle(multiM, handleM);
}
break;
case eModeFile: {
// Set timeout
iptv_curl_easy_setopt(handleM, CURLOPT_TIMEOUT_MS, 10L);
// Initialize multi set and add handle into it
if (!multiM) {
multiM = curl_multi_init();
}
if (multiM) {
curl_multi_add_handle(multiM, handleM);
}
}
break;
case eModeUnknown:
default:
break;
}
timeoutM.Set(eKeepAliveIntervalMs);
connectedM = true;
return true;
}
return false;
}
bool cIptvProtocolCurl::Disconnect() {
cMutexLock MutexLock(&mutexM);
debug1("%s", __PRETTY_FUNCTION__);
if (!connectedM) {
return true;
}
// Terminate curl session
if (handleM) {
// Remove handle from multi set
if (multiM) {
curl_multi_remove_handle(multiM, handleM);
curl_multi_cleanup(multiM);
multiM = nullptr;
}
// Mode specific tricks
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp: {
CURLcode res = CURLE_OK;
// Teardown rtsp session
cString uri = cString::sprintf("%s/", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_TEARDOWN);
iptv_curl_easy_perform(handleM);
rtspControlM = "";
isActiveM = false;
// Close the listening socket
CloseSocket();
}
break;
#endif
case eModeHttp:
case eModeHttps:
case eModeFile:
case eModeUnknown:
default:break;
}
// Cleanup curl stuff
if (headerListM) {
curl_slist_free_all(headerListM);
headerListM = nullptr;
}
curl_easy_cleanup(handleM);
handleM = nullptr;
}
ClearData();
connectedM = false;
return true;
}
bool cIptvProtocolCurl::Open() {
debug1("%s", __PRETTY_FUNCTION__);
return Connect();
}
bool cIptvProtocolCurl::Close() {
debug1("%s", __PRETTY_FUNCTION__);
Disconnect();
return true;
}
int cIptvProtocolCurl::Read(unsigned char *bufferAddrP, unsigned int bufferLenP) {
debug16("%s (, %u)", __PRETTY_FUNCTION__, bufferLenP);
int len = 0;
if (ringBufferM) {
// Fill up the buffer
if (handleM) {
switch (modeM) {
#ifdef USE_RTSP
case eModeRtsp: {
cMutexLock MutexLock(&mutexM);
CURLcode res = CURLE_OK;
// Remember the heart beat
if (timeoutM.TimedOut()) {
debug1("%s KeepAlive", __PRETTY_FUNCTION__);
cString uri = cString::sprintf("%s", *streamUrlM);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_STREAM_URI, *uri);
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_OPTIONS);
iptv_curl_easy_perform(handleM);
timeoutM.Set(eKeepAliveIntervalMs);
}
// Check whether UDP or TCP mode used
if (streamParamM) {
iptv_curl_easy_setopt(handleM, CURLOPT_RTSP_REQUEST, (long) CURL_RTSPREQ_RECEIVE);
iptv_curl_easy_perform(handleM);
} else {
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
}
break;
#endif
case eModeFile:
case eModeHttp:
case eModeHttps:
if (multiM) {
CURLMcode res;
int running_handles;
do {
cMutexLock MutexLock(&mutexM);
res = curl_multi_perform(multiM, &running_handles);
} while (res==CURLM_CALL_MULTI_PERFORM);
// Use 20% threshold before continuing to filling up the buffer.
mutexM.Lock();
if (pausedM && (ringBufferM->Available() < (IPTV_BUFFER_SIZE/5))) {
debug1("%s Continue free=%d available=%d", __PRETTY_FUNCTION__, ringBufferM->Free(), ringBufferM->Available());
pausedM = false;
curl_easy_pause(handleM, CURLPAUSE_CONT);
}
mutexM.Unlock();
// Check if end of file
if (running_handles==0) {
int msgcount;
mutexM.Lock();
CURLMsg *msg = curl_multi_info_read(multiM, &msgcount);
mutexM.Unlock();
if (msg && (msg->msg==CURLMSG_DONE)) {
debug1("%s Done %s (%d)", __PRETTY_FUNCTION__, curl_easy_strerror(msg->data.result), msg->data.result);
Disconnect();
Connect();
}
}
}
break;
case eModeUnknown:
default:
break;
}
}
// ... and try to empty it
unsigned char *p = GetData(len);
if (p && (len > 0)) {
len = min(len, (int) bufferLenP);
memcpy(bufferAddrP, p, len);
DelData(len);
debug16("%s Get %d bytes", __PRETTY_FUNCTION__, len);
}
}
return len;
}
bool
cIptvProtocolCurl::SetSource(SourceParameter parameter) {
debug1("%s (%s, %d, %d)", __PRETTY_FUNCTION__, parameter.locationP, parameter.parameterP, parameter.indexP);
if (!isempty(parameter.locationP)) {
// Disconnect
Disconnect();
// Update stream URL
streamUrlM = parameter.locationP;
cString protocol = ChangeCase(streamUrlM, false).Truncate(5);
if (startswith(*protocol, "rtsp")) {
modeM = eModeRtsp;
} else if (startswith(*protocol, "https")) {
modeM = eModeHttps;
} else if (startswith(*protocol, "http")) {
modeM = eModeHttp;
} else if (startswith(*protocol, "file")) {
modeM = eModeFile;
} else {
modeM = eModeUnknown;
}
debug1("%s (%s, %d, %d) protocol=%s mode=%d", __PRETTY_FUNCTION__, parameter.locationP, parameter.parameterP, parameter.indexP, *protocol, modeM);
// Update stream parameter - force UDP mode for RTSP
streamParamM = (modeM==eModeRtsp) ? 0 : parameter.parameterP;
// Update listen port
streamPortM = IptvConfig.GetProtocolBasePort() + parameter.indexP*2;
// Reconnect
Connect();
}
return true;
}
bool cIptvProtocolCurl::SetPid(int pidP, int typeP, bool onP) {
debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolCurl::GetInformation() {
debug16("%s", __PRETTY_FUNCTION__);
return cString::sprintf("%s [%d]", *streamUrlM, streamParamM);
}