forked from rofafor/vdr-plugin-iptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocoludp.cpp
121 lines (94 loc) · 3.2 KB
/
protocoludp.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
/*
* protocoludp.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <vdr/device.h>
#include "config.h"
#include "log.h"
#include "socket.h"
#include "protocoludp.h"
cIptvProtocolUdp::cIptvProtocolUdp()
: isIGMPv3M(false),
sourceAddrM(strdup("")),
streamAddrM(strdup("")),
streamPortM(0) {
debug1("%s", __PRETTY_FUNCTION__);
}
cIptvProtocolUdp::~cIptvProtocolUdp() {
debug1("%s", __PRETTY_FUNCTION__);
// Drop the multicast group and close the socket
cIptvProtocolUdp::Close();
// Free allocated memory
free(streamAddrM);
free(sourceAddrM);
}
bool cIptvProtocolUdp::Open() {
debug1("%s streamAddr='%s'", __PRETTY_FUNCTION__, streamAddrM);
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
if (!isempty(streamAddrM)) {
// Join a new multicast group
JoinMulticast();
}
return true;
}
bool cIptvProtocolUdp::Close() {
debug1("%s streamAddr='%s'", __PRETTY_FUNCTION__, streamAddrM);
if (!isempty(streamAddrM)) {
// Drop the multicast group
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Close the socket
CloseSocket();
// Do NOT reset stream and source addresses
//sourceAddrM = strcpyrealloc(sourceAddrM, "");
//streamAddrM = strcpyrealloc(streamAddrM, "");
//streamPortM = 0;
return true;
}
int cIptvProtocolUdp::Read(unsigned char *bufferAddrP, unsigned int bufferLenP) {
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolUdp::SetSource(SourceParameter parameter) {
debug1("%s (%s, %d, %d)", __PRETTY_FUNCTION__, parameter.locationP, parameter.parameterP, parameter.indexP);
if (!isempty(parameter.locationP)) {
// Drop the multicast group
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Update stream address and port
streamAddrM = strcpyrealloc(streamAddrM, parameter.locationP);
// <group address> or <source address>@<group address>
char *p = strstr(streamAddrM, "@");
if (p) {
*p = 0;
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
streamAddrM = strcpyrealloc(streamAddrM, p + 1);
isIGMPv3M = true;
} else {
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
isIGMPv3M = false;
}
streamPortM = parameter.parameterP;
// Join a new multicast group
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
JoinMulticast();
}
}
return true;
}
bool cIptvProtocolUdp::SetPid(int pidP, int typeP, bool onP) {
debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, pidP, typeP, onP);
return true;
}
cString cIptvProtocolUdp::GetInformation() {
debug16("%s", __PRETTY_FUNCTION__);
if (isIGMPv3M) {
return cString::sprintf("udp://%s@%s:%d", sourceAddrM, streamAddrM, streamPortM);
}
return cString::sprintf("udp://%s:%d", streamAddrM, streamPortM);
}