MCPcopy Create free account
hub / github.com/Barracuda09/SATPI / decrypt

Method decrypt

src/decrypt/dvbapi/Client.cpp:91–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 }
90
91 void Client::decrypt(const int streamID, mpegts::PacketBuffer &buffer) {
92 if (_connected && _enabled) {
93 const input::dvb::SpFrontendDecryptInterface frontend = _streamManager.getFrontendDecryptInterface(streamID);
94 const int maxBatchSize = frontend->getMaximumBatchSize();
95 static constexpr std::size_t size = buffer.getNumberOfTSPackets();
96 for (std::size_t i = 0; i < size; ++i) {
97 // Get TS packet from the buffer
98 unsigned char *data = buffer.getTSPacketPtr(i);
99
100 // Check is this the beginning of the TS and no Transport error indicator
101 if (data[0] == 0x47 && (data[1] & 0x80) != 0x80) {
102 // get PID from TS
103 const int pid = ((data[1] & 0x1f) << 8) | data[2];
104
105 // this packet scrambled and no NULL packet
106 if (data[3] & 0x80 && pid < 0x1FFF) {
107
108 // scrambled TS packet with even(0) or odd(1) key?
109 const int parity = (data[3] & 0x40) > 0;
110
111 // get batch parity and count
112 const int parityBatch = frontend->getBatchParity();
113 const int countBatch = frontend->getBatchCount();
114
115 // check if the parity changed in this batch (but should not be the begin of the batch)
116 // or check if this batch full, then decrypt this batch
117 if (countBatch != 0 && (parity != parityBatch || countBatch >= maxBatchSize)) {
118 //
119 SI_LOG_COND_DEBUG(parity != parityBatch, "Stream: %d, Parity changed from %d to %d, decrypting batch size %d",
120 streamID, parityBatch, parity, countBatch);
121
122 // decrypt this batch
123 frontend->decryptBatch();
124 }
125
126 // Can we add this packet to the batch
127 if (frontend->getKey(parity) != nullptr) {
128 // check is there an adaptation field we should skip, then add it to batch
129 int skip = 4;
130 if((data[3] & 0x20) && (data[4] < 183)) {
131 skip += data[4] + 1;
132 }
133 frontend->setBatchData(data + skip, 188 - skip, parity, data);
134
135 // set pending decrypt for this buffer
136 buffer.setDecryptPending();
137 } else {
138 // set decrypt failed by setting NULL packet ID..
139 data[1] |= 0x1F;
140 data[2] |= 0xFF;
141
142 // clear scramble flag, so we can send it.
143 data[3] &= 0x3F;
144 }
145 } else {
146
147///////////////////////////////////////////////////////////////////
148 int demux = 0;

Callers 1

Calls 14

getNumberOfTSPacketsMethod · 0.80
getTSPacketPtrMethod · 0.80
setDecryptPendingMethod · 0.80
sendDataMethod · 0.80
getMaximumBatchSizeMethod · 0.45
getBatchParityMethod · 0.45
getBatchCountMethod · 0.45
decryptBatchMethod · 0.45
getKeyMethod · 0.45
setBatchDataMethod · 0.45
findOSCamFilterDataMethod · 0.45

Tested by

no test coverage detected