forked from rofafor/vdr-plugin-iptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocolstream.cpp
103 lines (77 loc) · 2.55 KB
/
protocolstream.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
#include "protocolstream.h"
#include "common.h"
#include "config.h"
#include "streambasehandler.h"
#include "log.h"
cIptvProtocolStream::cIptvProtocolStream() : channelId(0), isActiveM(false), handler("STREAM") {
debug1("%s", __PRETTY_FUNCTION__);
}
cIptvProtocolStream::~cIptvProtocolStream() {
debug1("%s", __PRETTY_FUNCTION__);
// Drop open handles
cIptvProtocolStream::Close();
handler.stop();
}
int cIptvProtocolStream::Read(unsigned char *bufferAddrP, unsigned int bufferLenP) {
// debug16("%s (, %u)", __PRETTY_FUNCTION__, bufferLenP);
return handler.popPackets(bufferAddrP, bufferLenP);
}
bool cIptvProtocolStream::Open() {
debug1("%s", __PRETTY_FUNCTION__);
if (!isActiveM) {
isActiveM = true;
m3u_stream streams;
{
LOCK_CHANNELS_READ;
const cChannel *Channel = Channels->GetByNumber(channelId);
if (Channel) {
streams.url = url;
streams.channelName = Channel->Name();
streams.vpid = Channel->Vpid();
streams.spid = Channel->Sid();
streams.tpid = Channel->Tid();
streams.nid = Channel->Nid();
int aidx = 0;
while (true) {
int apid = Channel->Apid(aidx);
if (apid==0) {
break;
}
streams.apids.push_back(apid);
aidx++;
}
}
}
handler.streamVideo(streams);
}
return true;
}
bool cIptvProtocolStream::Close() {
debug1("%s", __PRETTY_FUNCTION__);
isActiveM = false;
handler.stop();
return true;
}
bool cIptvProtocolStream::SetSource(SourceParameter parameter) {
debug1("%s (%s, %d, %d)", __PRETTY_FUNCTION__, parameter.locationP, parameter.parameterP, parameter.indexP);
url = parameter.locationP;
url = ReplaceAll(url, "%3A", ":");
url = ReplaceAll(url, "%7C", "|");
if (url.empty()) {
error("URL %s not found", parameter.locationP);
return false;
}
channelId = parameter.channelNumber;
handlerType = parameter.handlerType;
handler.setChannelId(channelId);
handler.setHandlerType(handlerType);
return true;
}
bool cIptvProtocolStream::SetPid(int pidP, int typeP, bool onP) {
debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolStream::GetInformation() {
debug16("%s", __PRETTY_FUNCTION__);
return cString::sprintf("%s", url.c_str());
}