Skip to content

Commit c4077ca

Browse files
committed
Fix/Change: proper fix for 'fe' query attribute now follows numbering in WebIF #158
1 parent a9e2547 commit c4077ca

28 files changed

+105
-84
lines changed

src/Defs.h

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class FeID : public TypeID {
7070
FeID(int id=-1) : TypeID(id) {}
7171
};
7272

73+
class FeIndex : public TypeID {
74+
public:
75+
FeIndex(int index=-1) : TypeID(index) {}
76+
};
77+
7378
class StreamID : public TypeID {
7479
public:
7580
StreamID(int id=-1) : TypeID(id) {}

src/HeaderVector.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <Defs.h>
2424

25+
#include <string_view>
26+
2527
class HeaderVector {
2628
// =========================================================================
2729
// -- Constructors and destructor ------------------------------------------

src/HttpcServer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ void HttpcServer::processStreamingRequest(SocketClient &client) {
159159
const std::string sessionID = headers.getFieldParameter("Session");
160160
const StreamID streamID = params.getIntParameter("stream");
161161
// Find the FeID with requesed StreamID
162-
const FeID feID = _streamManager.findFrontendIDWithStreamID(streamID);
162+
const auto [feIndex, feID] = _streamManager.findFrontendIDWithStreamID(streamID);
163163

164164
const std::string method = client.getMethod();
165165
std::string httpcReply;
166166
if (sessionID.empty() && method == "OPTIONS") {
167167
methodOptions("", cseq, httpcReply);
168168
} else if (sessionID.empty() && method == "DESCRIBE") {
169-
methodDescribe("", cseq, feID, httpcReply);
169+
methodDescribe("", cseq, feIndex, httpcReply);
170170
} else {
171171
int clientID;
172172
SpStream stream = _streamManager.findStreamAndClientIDFor(client, clientID);
@@ -201,7 +201,7 @@ void HttpcServer::processStreamingRequest(SocketClient &client) {
201201
} else if (method == "OPTIONS") {
202202
methodOptions(sessionID, cseq, httpcReply);
203203
} else if (method == "DESCRIBE") {
204-
methodDescribe(sessionID, cseq, feID, httpcReply);
204+
methodDescribe(sessionID, cseq, feIndex, httpcReply);
205205
} else {
206206
// method not supported
207207
SI_LOG_ERROR("@#1: Method not allowed: @#2", method, client.getRawMessage());

src/HttpcServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class HttpcServer :
107107
virtual void methodOptions(const std::string &UNUSED(sessionID), int UNUSED(cseq), std::string &UNUSED(htmlBody)) {}
108108

109109
/// RTSP Method
110-
virtual void methodDescribe(const std::string &UNUSED(sessionID), int UNUSED(cseq), FeID UNUSED(id), std::string &UNUSED(htmlBody)) {}
110+
virtual void methodDescribe(const std::string &UNUSED(sessionID), int UNUSED(cseq), FeIndex UNUSED(index), std::string &UNUSED(htmlBody)) {}
111111

112112
/// Process the data received from @c SocketClient
113113
virtual bool process(SocketClient &client) final;

src/RtspServer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void RtspServer::methodOptions(
169169
}
170170

171171
void RtspServer::methodDescribe(
172-
const std::string &sessionID, const int cseq, const FeID id, std::string &htmlBody) {
172+
const std::string &sessionID, const int cseq, const FeIndex feIndex, std::string &htmlBody) {
173173
static const char *RTSP_DESCRIBE =
174174
"@#1" \
175175
"CSeq: @#2\r\n" \
@@ -196,20 +196,20 @@ void RtspServer::methodDescribe(
196196
std::size_t streamsSetup = 0;
197197

198198
// Lambda Expression 'setupDescribeMediaLevelString'
199-
const auto setupDescribeMediaLevelString = [&](const FeID id) {
200-
const std::string mediaLevel = _streamManager.getDescribeMediaLevelString(id);
199+
const auto setupDescribeMediaLevelString = [&](const FeIndex feIndex) {
200+
const std::string mediaLevel = _streamManager.getDescribeMediaLevelString(feIndex);
201201
if (mediaLevel.size() > 5) {
202202
++streamsSetup;
203203
desc += mediaLevel;
204204
}
205205
};
206-
// Check if there is a specific Frontend ID requested
207-
if (id == -1) {
206+
// Check if there is a specific Frontend ID index requested
207+
if (feIndex == -1) {
208208
for (std::size_t i = 0; i < _streamManager.getMaxStreams(); ++i) {
209209
setupDescribeMediaLevelString(i);
210210
}
211211
} else {
212-
setupDescribeMediaLevelString(id);
212+
setupDescribeMediaLevelString(feIndex);
213213
}
214214

215215
// check if we are in session, then we need to send the Session ID

src/RtspServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class RtspServer :
6666
virtual void methodOptions(const std::string &sessionID, int cseq, std::string &htmlBody) final;
6767

6868
///
69-
virtual void methodDescribe(const std::string &sessionID, int cseq, FeID id, std::string &htmlBody) final;
69+
virtual void methodDescribe(const std::string &sessionID, int cseq, FeIndex index, std::string &htmlBody) final;
7070

7171
// =====================================================================
7272
// -- Data members -----------------------------------------------------

src/Stream.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ FeID Stream::getFeID() const {
7575
return _device->getFeID();
7676
}
7777

78+
int Stream::getFeIndex() const {
79+
return _device->getFeIndex();
80+
}
81+
7882
StreamClient &Stream::getStreamClient(int clientID) const {
7983
return _client[clientID];
8084
}

src/Stream.h

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class Stream :
8888

8989
virtual FeID getFeID() const final;
9090

91+
virtual int getFeIndex() const final;
92+
9193
virtual StreamClient &getStreamClient(int clientID) const final;
9294

9395
virtual input::SpDevice getInputDevice() const final;

src/StreamInterface.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class StreamInterface {
4949
/// Get the FeID of the Frontend used for this stream
5050
virtual FeID getFeID() const = 0;
5151

52+
/// Get the index of this Frontend used for this stream
53+
virtual int getFeIndex() const = 0;
54+
5255
///
5356
virtual StreamClient &getStreamClient(int clientID) const = 0;
5457

src/StreamManager.cpp

+23-22
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,30 @@ std::string StreamManager::getRTSPDescribeString() const {
125125
return StringConverter::stringFormat("@#1,@#2,@#3", dvb_s2, dvb_t + dvb_t2, dvb_c + dvb_c2);
126126
}
127127

128-
FeID StreamManager::findFrontendIDWithStreamID(const StreamID id) const {
128+
std::tuple<FeIndex, FeID> StreamManager::findFrontendIDWithStreamID(const StreamID id) const {
129129
for (SpStream stream : _streamVector) {
130130
if (stream->getStreamID() == id) {
131-
return stream->getFeID();
131+
return { stream->getFeIndex(), stream->getFeID() };
132132
}
133133
}
134-
return FeID();
134+
return { FeIndex(), FeID() };
135135
}
136136

137-
std::pair<FeID, StreamID> StreamManager::findFrontendID(const TransportParamVector& params) const {
137+
std::tuple<FeIndex, FeID, StreamID> StreamManager::findFrontendID(const TransportParamVector& params) const {
138138
const StreamID streamID = params.getIntParameter("stream");
139-
const FeID feID = params.getIntParameter("fe");
139+
FeID feID = params.getIntParameter("fe");
140140
// Did we find StreamID an NO FrondendID
141141
if (streamID != -1 && feID == -1) {
142-
return { findFrontendIDWithStreamID(streamID), streamID };
142+
const auto [index, feID] = findFrontendIDWithStreamID(streamID);
143+
return { index, feID, streamID };
143144
}
144145
// Is the requested FrondendID in range, then return this
145146
if (feID >= 1 && feID <= static_cast<int>(_streamVector.size())) {
146-
// We start with FeID = 0, therefore we subtract 1 from transport parameter 'fe='
147-
return { feID - 1, streamID};
147+
// The vector starts at 0, therefore we subtract 1 from transport parameter 'fe='/'FeID'
148+
return { feID - 1, feID, streamID };
148149
}
149-
// Out of range, return -1, -1
150-
return { FeID(), StreamID() };
150+
// Out of range, return -1, -1, -1
151+
return { FeIndex(), FeID(), StreamID() };
151152
}
152153

153154
SpStream StreamManager::findStreamAndClientIDFor(SocketClient &socketClient, int &clientID) {
@@ -156,8 +157,8 @@ SpStream StreamManager::findStreamAndClientIDFor(SocketClient &socketClient, int
156157
HeaderVector headers = socketClient.getHeaders();
157158
TransportParamVector params = socketClient.getTransportParameters();
158159

159-
// Now find FrontendID and/or StreamID of this message
160-
const auto [feID, streamID] = findFrontendID(params);
160+
// Now find index for FrontendID and/or StreamID of this message
161+
const auto [feIndex, feID, streamID] = findFrontendID(params);
161162

162163
std::string sessionID = headers.getFieldParameter("Session");
163164
bool newSession = false;
@@ -179,8 +180,8 @@ SpStream StreamManager::findStreamAndClientIDFor(SocketClient &socketClient, int
179180
}
180181
}
181182

182-
// if no FeID, then we have to find a suitable one
183-
if (feID == -1) {
183+
// if no index, then we have to find a suitable one
184+
if (feIndex == -1) {
184185
SI_LOG_INFO("Found FrondtendID: x (fe=x) StreamID: x SessionID: @#1", sessionID);
185186
for (SpStream stream : _streamVector) {
186187
if (stream->findClientIDFor(socketClient, newSession, sessionID, clientID)) {
@@ -189,11 +190,11 @@ SpStream StreamManager::findStreamAndClientIDFor(SocketClient &socketClient, int
189190
}
190191
}
191192
} else {
192-
SI_LOG_INFO("Found FrondtendID: @#1 (fe=@#2) StreamID: @#3 SessionID: @#4", feID, feID + 1, streamID, sessionID);
193+
SI_LOG_INFO("Found FrondtendID: @#1 (fe=@#2) StreamID: @#3 SessionID: @#4", feID, feID, streamID, sessionID);
193194
// Did we find the StreamClient?
194-
if (_streamVector[feID.getID()]->findClientIDFor(socketClient, newSession, sessionID, clientID)) {
195-
_streamVector[feID.getID()]->getStreamClient(clientID).setSessionID(sessionID);
196-
return _streamVector[feID.getID()];
195+
if (_streamVector[feIndex]->findClientIDFor(socketClient, newSession, sessionID, clientID)) {
196+
_streamVector[feIndex]->getStreamClient(clientID).setSessionID(sessionID);
197+
return _streamVector[feIndex];
197198
}
198199
// No, Then try to search in other Streams
199200
for (SpStream stream : _streamVector) {
@@ -217,14 +218,14 @@ void StreamManager::checkForSessionTimeout() {
217218
}
218219
}
219220

220-
std::string StreamManager::getDescribeMediaLevelString(const FeID id) const {
221+
std::string StreamManager::getDescribeMediaLevelString(const FeIndex feIndex) const {
221222
assert(!_streamVector.empty());
222-
return _streamVector[id.getID()]->getDescribeMediaLevelString();
223+
return _streamVector[feIndex.getID()]->getDescribeMediaLevelString();
223224
}
224225

225226
#ifdef LIBDVBCSA
226-
input::dvb::SpFrontendDecryptInterface StreamManager::getFrontendDecryptInterface(const FeID id) {
227-
return _streamVector[id.getID()]->getFrontendDecryptInterface();
227+
input::dvb::SpFrontendDecryptInterface StreamManager::getFrontendDecryptInterface(const FeIndex feIndex) {
228+
return _streamVector[feIndex.getID()]->getFrontendDecryptInterface();
228229
}
229230
#endif
230231

src/StreamManager.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <base/XMLSupport.h>
2626

2727
#include <string>
28+
#include <tuple>
2829

2930
FW_DECL_NS0(SocketClient);
3031
FW_DECL_NS0(TransportParamVector);
@@ -81,7 +82,7 @@ class StreamManager :
8182
int &clientID);
8283

8384
///
84-
FeID findFrontendIDWithStreamID(StreamID id) const;
85+
std::tuple<FeIndex, FeID> findFrontendIDWithStreamID(StreamID id) const;
8586

8687
///
8788
void checkForSessionTimeout();
@@ -98,17 +99,17 @@ class StreamManager :
9899
}
99100

100101
///
101-
std::string getDescribeMediaLevelString(FeID id) const;
102+
std::string getDescribeMediaLevelString(FeIndex feIndex) const;
102103

103104
#ifdef LIBDVBCSA
104105
///
105-
input::dvb::SpFrontendDecryptInterface getFrontendDecryptInterface(FeID id);
106+
input::dvb::SpFrontendDecryptInterface getFrontendDecryptInterface(FeIndex feIndex);
106107
#endif
107108

108109
private:
109110

110111
///
111-
std::pair<FeID, StreamID> findFrontendID(const TransportParamVector& params) const;
112+
std::tuple<FeIndex, FeID, StreamID> findFrontendID(const TransportParamVector& params) const;
112113

113114
// =====================================================================
114115
// -- Data members -----------------------------------------------------

src/TransportParamVector.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <Defs.h>
2424
#include <input/InputSystem.h>
2525

26+
#include <string_view>
27+
2628
class TransportParamVector {
2729
// =========================================================================
2830
// -- Constructors and destructor ------------------------------------------

src/decrypt/dvbapi/Client.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ namespace decrypt::dvbapi {
9191
joinThread();
9292
}
9393

94-
void Client::decrypt(const FeID id, mpegts::PacketBuffer &buffer) {
94+
void Client::decrypt(const FeIndex index, const FeID id, mpegts::PacketBuffer &buffer) {
9595
if (_connected && _enabled) {
96-
const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(id);
96+
const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(index);
9797
const int maxBatchSize = frontend->getMaximumBatchSize();
9898
static constexpr std::size_t size = buffer.getNumberOfTSPackets();
9999
for (std::size_t i = 0; i < size; ++i) {
@@ -179,7 +179,7 @@ namespace decrypt::dvbapi {
179179
///////////////////////////////////////////////////////////////////
180180

181181
if (frontend->isMarkedAsActivePMT(pid)) {
182-
sendPMT(id, *frontend->getSDTData(), *frontend->getPMTData());
182+
sendPMT(index, id, *frontend->getSDTData(), *frontend->getPMTData());
183183
// Do we need to clean PMT
184184
if (_rewritePMT) {
185185
cleanPMT(data);
@@ -191,11 +191,11 @@ namespace decrypt::dvbapi {
191191
}
192192
}
193193

194-
bool Client::stopDecrypt(const FeID id) {
195-
const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(id);
194+
bool Client::stopDecrypt(const FeIndex index, const FeID id) {
195+
const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(index);
196196
if (_connected) {
197197
// Stop 9F 80 3f 04 83 02 00 <demux index>
198-
const int demux = id.getID() + _adapterOffset;
198+
const int demux = index.getID() + _adapterOffset;
199199
const uint32_t request = htonl(DVBAPI_AOT_CA_STOP);
200200
unsigned char buff[8];
201201
std::memcpy(&buff[0], &request, 4);
@@ -222,7 +222,7 @@ namespace decrypt::dvbapi {
222222
*/
223223
}
224224
// Remove this PMT from the list
225-
const auto it = _capmtMap.find(id);
225+
const auto it = _capmtMap.find(index.getID());
226226
if (it != _capmtMap.end()) {
227227
_capmtMap.erase(it);
228228
}
@@ -340,7 +340,7 @@ namespace decrypt::dvbapi {
340340
}
341341
}
342342

343-
void Client::sendPMT(const FeID id, const mpegts::SDT &sdt, const mpegts::PMT &pmt) {
343+
void Client::sendPMT(const FeIndex index, const FeID id, const mpegts::SDT &sdt, const mpegts::PMT &pmt) {
344344
// Did we collect SDT and PMT
345345
if (!sdt.isCollected()) {
346346
return;
@@ -349,7 +349,7 @@ namespace decrypt::dvbapi {
349349
if (!pmt.isReadySend()) {
350350
return;
351351
}
352-
const int adapterIndex = id.getID() + _adapterOffset;
352+
const int adapterIndex = index.getID() + _adapterOffset;
353353
const int demuxIndex = adapterIndex;
354354

355355
#if USE_DEPRECATED_DVBAPI
@@ -415,7 +415,7 @@ namespace decrypt::dvbapi {
415415
std::memcpy(&caPMT[12], oscamDesc, sizeof(oscamDesc));
416416
std::memcpy(&caPMT[12 + sizeof(oscamDesc)], progInfo.data(), progInfo.size());
417417
// Save new PMT so we can send it
418-
_capmtMap[id] = PMTEntry{ caPMT, totLength + 6 };
418+
_capmtMap[index.getID()] = PMTEntry{ caPMT, totLength + 6 };
419419

420420
// Send the collected PMT list
421421
unsigned int i = 0;
@@ -538,7 +538,7 @@ namespace decrypt::dvbapi {
538538
const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(adapter);
539539
frontend->setKey(cw, parity, index);
540540
SI_LOG_DEBUG("Frontend: @#1, Received @#2(@#3) CW: @#4 @#5 @#6 @#7 @#8 @#9 @#10 @#11 index: @#12",
541-
adapter, (parity == 0) ? "even" : "odd", HEX2(parity),
541+
frontend->getFeID(), (parity == 0) ? "even" : "odd", HEX2(parity),
542542
HEX2(cw[0]), HEX2(cw[1]), HEX2(cw[2]), HEX2(cw[3]),
543543
HEX2(cw[4]), HEX2(cw[5]), HEX2(cw[6]), HEX2(cw[7]), index);
544544

@@ -581,7 +581,7 @@ namespace decrypt::dvbapi {
581581
frontend->setECMInfo(pid, serviceID, caID, provID, emcTime,
582582
cardSystem, readerName, sourceName, protocolName, hops);
583583
SI_LOG_DEBUG("Frontend: @#1, Receive ECM Info System: @#2 Reader: @#3 Source: @#4 Protocol: @#5 ECM Time: @#6",
584-
adapter, cardSystem, readerName, sourceName, protocolName, emcTime);
584+
frontend->getFeID(), cardSystem, readerName, sourceName, protocolName, emcTime);
585585
break;
586586
}
587587
default:

src/decrypt/dvbapi/Client.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ class Client :
108108
public:
109109

110110
///
111-
void decrypt(FeID id, mpegts::PacketBuffer &buffer);
111+
void decrypt(FeIndex index, FeID id, mpegts::PacketBuffer &buffer);
112112

113113
///
114-
bool stopDecrypt(FeID id);
114+
bool stopDecrypt(FeIndex index, FeID id);
115115

116116
private:
117117

@@ -125,7 +125,7 @@ class Client :
125125
void sendClientInfo();
126126

127127
///
128-
void sendPMT(FeID id, const mpegts::SDT &sdt, const mpegts::PMT &pmt);
128+
void sendPMT(FeIndex index, FeID id, const mpegts::SDT &sdt, const mpegts::PMT &pmt);
129129

130130
///
131131
void cleanPMT(unsigned char *data);

0 commit comments

Comments
 (0)