Skip to content

Commit

Permalink
WIP: for Generate PSI (Program-specific information) metadata for Tra…
Browse files Browse the repository at this point in the history
…nslation M3U files #169
  • Loading branch information
Barracuda09 committed Nov 12, 2022
1 parent 5d0b631 commit c56c6a7
Show file tree
Hide file tree
Showing 32 changed files with 644 additions and 106 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ SOURCES = Version.cpp \
input/stream/Streamer.cpp \
input/stream/StreamerData.cpp \
mpegts/Filter.cpp \
mpegts/Generator.cpp \
mpegts/NIT.cpp \
mpegts/PacketBuffer.cpp \
mpegts/PAT.cpp \
mpegts/PCR.cpp \
Expand Down
15 changes: 12 additions & 3 deletions src/StringConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ class StringConverter {
return stream.str();
}

///
template<class T>
static std::string toStringFrom4BitBCD(const T bcd, const int charNr) {
std::ostringstream stream;
if (charNr > 0) {
for (int i = 0; i < charNr; ++i) {
stream << std::right << ((bcd >> ((charNr - 1 - i) * 4)) & 0xF);
}
}
return stream.str();
}

/// Get next line with line_delim (if available) from msg
/// @return @c line or empty line
static std::string getline(std::string_view msg,
Expand All @@ -135,9 +147,6 @@ class StringConverter {
///
static std::string stringToUpper(std::string_view str);

///
static std::string getProtocol(const std::string &msg);

///
static void splitPath(const std::string &fullPath, std::string &path, std::string &file);

Expand Down
5 changes: 5 additions & 0 deletions src/base/M3UParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ namespace base {
/// transformation
bool exist(const double freq) const;

/// This will return a copy of the M3U map
TransformationMap getTransformationMap() const {
return _transformationMap;
}

// =======================================================================
// -- Data members -------------------------------------------------------
// =======================================================================
Expand Down
6 changes: 3 additions & 3 deletions src/input/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ class Device :
virtual std::string attributeDescribeString() const = 0;

///
virtual mpegts::Filter &getFilterData() = 0;
virtual mpegts::Filter &getFilter() = 0;

/// Generic pid filtering Update function
virtual void updatePIDFilters() {
getFilterData().updatePIDFilters(_feID,
getFilter().updatePIDFilters(_feID,
// openPid lambda function
[&](const int) {
return true;
Expand All @@ -119,7 +119,7 @@ class Device :

/// Generic pid filtering Close function
virtual void closeActivePIDFilters() {
getFilterData().closeActivePIDFilters(_feID,
getFilter().closeActivePIDFilters(_feID,
// closePid lambda function
[&](const int) {
return true;
Expand Down
17 changes: 10 additions & 7 deletions src/input/DeviceData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,27 @@ std::string DeviceData::attributeDescribeString(FeID id) const {
return doAttributeDescribeString(id);
}

void DeviceData::setDeliverySystem(const input::InputSystem system) {
base::MutexLock lock(_mutex);
_delsys = system;
}

input::InputSystem DeviceData::getDeliverySystem() const {
base::MutexLock lock(_mutex);
return _delsys;
}

const mpegts::Filter &DeviceData::getFilterData() const {
const mpegts::Filter &DeviceData::getFilter() const {
return _filter;
}

mpegts::Filter &DeviceData::getFilterData() {
mpegts::Filter &DeviceData::getFilter() {
return _filter;
}

const mpegts::Generator &DeviceData::getPSIGenerator() const {
return _generator;
}

mpegts::Generator &DeviceData::getPSIGenerator() {
return _generator;
}

fe_delivery_system DeviceData::convertDeliverySystem() const {
base::MutexLock lock(_mutex);
switch (_delsys) {
Expand Down
15 changes: 10 additions & 5 deletions src/input/DeviceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <input/InputSystem.h>
#include <input/dvb/dvbfix.h>
#include <mpegts/Filter.h>
#include <mpegts/Generator.h>
#include <TransportParamVector.h>

FW_DECL_NS1(mpegts, PacketBuffer);
Expand Down Expand Up @@ -107,17 +108,20 @@ class DeviceData :
/// Reset/clear the 'Channel Data changed' flag
void resetDeviceDataChanged();

/// Set the current Delivery System
void setDeliverySystem(input::InputSystem system);

/// Get the current Delivery System
input::InputSystem getDeliverySystem() const;

///
const mpegts::Filter &getFilterData() const;
const mpegts::Filter &getFilter() const;

///
mpegts::Filter &getFilter();

///
const mpegts::Generator &getPSIGenerator() const;

///
mpegts::Filter &getFilterData();
mpegts::Generator &getPSIGenerator();

///
fe_delivery_system convertDeliverySystem() const;
Expand Down Expand Up @@ -153,6 +157,7 @@ class DeviceData :
bool _changed;
input::InputSystem _delsys;
mpegts::Filter _filter;
mpegts::Generator _generator;
bool _internalPidFiltering;

// =======================================================================
Expand Down
10 changes: 7 additions & 3 deletions src/input/Transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ namespace input {
// -- Constructors and destructor ----------------------------------------------
// =============================================================================

Transformation::Transformation(const std::string &appDataPath) :
Transformation::Transformation(
const std::string &appDataPath,
const input::InputSystem ownInputSystem) :
_enabled(false),
_transform(false),
_advertiseAs(AdvertiseAs::NONE),
_ownInputSystem(ownInputSystem),
_appDataPath(appDataPath),
_transformFileM3U("mapping.m3u"),
_transformFreq(0) {
_transformFreq(0),
_generatePSIFreq(10111) {
_fileParsed = _m3u.parse(_appDataPath + "/" + _transformFileM3U);
}

Expand Down Expand Up @@ -173,7 +177,7 @@ TransportParamVector Transformation::transformStreamString(
// Parse the Stream String to the 'dummy' FrontendData and update PID filters
// for correct RTCP Attribute Describe String when transforming request
_transformedDeviceData.parseStreamString(id, params);
_transformedDeviceData.getFilterData().updatePIDFilters(id,
_transformedDeviceData.getFilter().updatePIDFilters(id,
// openPid lambda function
[&](const int) {
return true;
Expand Down
7 changes: 6 additions & 1 deletion src/input/Transformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class Transformation :
// =====================================================================
public:

Transformation(const std::string &appDataPath);
Transformation(const std::string &appDataPath) :
Transformation(appDataPath, input::InputSystem::UNDEFINED) {}

Transformation(const std::string &appDataPath, input::InputSystem ownInputSystem);

virtual ~Transformation() = default;

Expand Down Expand Up @@ -109,11 +112,13 @@ class Transformation :
bool _transform;
bool _fileParsed;
AdvertiseAs _advertiseAs;
input::InputSystem _ownInputSystem;
base::M3UParser _m3u;
std::string _appDataPath;
std::string _transformFileM3U;
mutable input::dvb::FrontendData _transformedDeviceData;
uint32_t _transformFreq;
uint32_t _generatePSIFreq;
};

} // namespace input
Expand Down
14 changes: 6 additions & 8 deletions src/input/childpipe/TSReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#include <chrono>
#include <thread>

namespace input {
namespace childpipe {
namespace input::childpipe {

// =============================================================================
// -- Constructors and destructor ---------------------------------------------
Expand Down Expand Up @@ -96,7 +95,7 @@ void TSReader::addDeliverySystemCount(

bool TSReader::isDataAvailable() {
const int pcrTimer = _deviceData.getPCRTimer();
const std::int64_t pcrDelta = _deviceData.getFilterData().getPCRData()->getPCRDelta();
const std::int64_t pcrDelta = _deviceData.getFilter().getPCRData()->getPCRDelta();
if (pcrDelta != 0 && pcrTimer == 0) {
_t2 = _t1;
_t1 = std::chrono::steady_clock::now();
Expand All @@ -106,7 +105,7 @@ bool TSReader::isDataAvailable() {
std::this_thread::sleep_for(std::chrono::microseconds(interval));
}
_t1 = std::chrono::steady_clock::now();
_deviceData.getFilterData().getPCRData()->clearPCRDelta();
_deviceData.getFilter().getPCRData()->clearPCRDelta();
} else {
std::this_thread::sleep_for(std::chrono::microseconds(150 + pcrTimer));
}
Expand All @@ -123,7 +122,7 @@ bool TSReader::readFullTSPacket(mpegts::PacketBuffer &buffer) {
buffer.trySyncing();
if (buffer.full()) {
// Add data to Filter
_deviceData.getFilterData().addData(_feID, buffer, _deviceData.isInternalPidFilteringEnabled());
_deviceData.getFilter().filterData(_feID, buffer, _deviceData.isInternalPidFilteringEnabled());
}
}
// Check again if buffer is still full
Expand Down Expand Up @@ -180,7 +179,7 @@ bool TSReader::update() {
}
}
updatePIDFilters();
SI_LOG_DEBUG("Frontend: @#1, PIDs Table: @#2", _feID, _deviceData.getFilterData().getPidCSV());
SI_LOG_DEBUG("Frontend: @#1, PIDs Table: @#2", _feID, _deviceData.getFilter().getPidCSV());
SI_LOG_DEBUG("Frontend: @#1, Updating frontend (Finished)", _feID);
return true;
}
Expand All @@ -205,5 +204,4 @@ std::string TSReader::attributeDescribeString() const {
// -- Other member functions --------------------------------------------------
// =============================================================================

} // namespace childpipe
} // namespace input
}
10 changes: 4 additions & 6 deletions src/input/childpipe/TSReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ FW_DECL_SP_NS2(input, childpipe, TSReader);

FW_DECL_VECTOR_OF_SP_NS0(Stream);

namespace input {
namespace childpipe {
namespace input::childpipe {

/// The class @c TSReader is for reading from an Child PIPE as input device
/// Some example for opening a TS file with 'cat /dir/test.ts':
Expand Down Expand Up @@ -108,8 +107,8 @@ class TSReader :

virtual std::string attributeDescribeString() const final;

virtual mpegts::Filter &getFilterData() final {
return _deviceData.getFilterData();
virtual mpegts::Filter &getFilter() final {
return _deviceData.getFilter();
}

// =====================================================================
Expand All @@ -131,7 +130,6 @@ class TSReader :
std::chrono::steady_clock::time_point _t2;
};

} // namespace childpipe
} // namespace input
}

#endif // INPUT_CHILD_PIPE_TSREADER_H_INCLUDE
6 changes: 2 additions & 4 deletions src/input/childpipe/TSReaderData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

#include <string>

namespace input {
namespace childpipe {
namespace input::childpipe {

/// The class @c TSReaderData carries all the data/information for Reading
/// from an Child PIPE
Expand Down Expand Up @@ -86,7 +85,6 @@ class TSReaderData :

};

} // namespace childpipe
} // namespace input
}

#endif // INPUT_CHILD_PIPE_TSREADER_DATA_H_INCLUDE
6 changes: 3 additions & 3 deletions src/input/dvb/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ namespace input::dvb {
buffer.addAmountOfBytesWritten(readSize);
if (buffer.full()) {
// Add data to Filter
_frontendData.getFilterData().addData(_feID, buffer);
_frontendData.getFilter().filterData(_feID, buffer);
}
} else if (readSize < 0) {
SI_LOG_PERROR("Frontend: @#1, Error reading data..", _feID);
Expand Down Expand Up @@ -460,7 +460,7 @@ namespace input::dvb {
}

void Frontend::closeActivePIDFilters() {
_frontendData.getFilterData().closeActivePIDFilters(_feID,
_frontendData.getFilter().closeActivePIDFilters(_feID,
// closePid lambda function
[&](const int pid) {
if (::ioctl(_fd_dmx, DMX_REMOVE_PID, &pid) != 0) {
Expand All @@ -476,7 +476,7 @@ namespace input::dvb {
SI_LOG_INFO("Frontend: @#1, Update PID filters requested, but frontend not tuned!", _feID);
return;
}
_frontendData.getFilterData().updatePIDFilters(_feID,
_frontendData.getFilter().updatePIDFilters(_feID,
// openPid lambda function
[&](const int pid) {
// Check if we have already a DMX open
Expand Down
4 changes: 2 additions & 2 deletions src/input/dvb/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class Frontend :

virtual std::string attributeDescribeString() const final;

virtual mpegts::Filter &getFilterData() final {
return _frontendData.getFilterData();
virtual mpegts::Filter &getFilter() final {
return _frontendData.getFilter();
}

///
Expand Down
8 changes: 4 additions & 4 deletions src/input/dvb/Frontend_DecryptInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace input::dvb {
HEX2(filterData[0]), HEX2(filterData[1]), HEX2(filterData[2]),
HEX2(filterMask[0]), HEX2(filterMask[1]), HEX2(filterMask[2]), HEX2(filterMask[3]));
_dvbapiData.startOSCamFilterData(_feID, pid, demux, filter, filterData, filterMask);
_frontendData.getFilterData().setPID(pid, true);
_frontendData.getFilter().setPID(pid, true);
// now update frontend, PID list has changed
updatePIDFilters();
}
Expand Down Expand Up @@ -96,14 +96,14 @@ namespace input::dvb {
}

bool Frontend::isMarkedAsActivePMT(int pid) const {
return _frontendData.getFilterData().isMarkedAsActivePMT(pid);
return _frontendData.getFilter().isMarkedAsActivePMT(pid);
}

mpegts::SpPMT Frontend::getPMTData() const {
return _frontendData.getFilterData().getPMTData();
return _frontendData.getFilter().getPMTData();
}

mpegts::SpSDT Frontend::getSDTData() const {
return _frontendData.getFilterData().getSDTData();
return _frontendData.getFilter().getSDTData();
}
}
6 changes: 3 additions & 3 deletions src/input/file/TSReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void TSReader::addDeliverySystemCount(
}

bool TSReader::isDataAvailable() {
const std::int64_t pcrDelta = _deviceData.getFilterData().getPCRData()->getPCRDelta();
const std::int64_t pcrDelta = _deviceData.getFilter().getPCRData()->getPCRDelta();
if (pcrDelta != 0) {
_t2 = _t1;
_t1 = std::chrono::steady_clock::now();
Expand All @@ -105,7 +105,7 @@ bool TSReader::isDataAvailable() {
std::this_thread::sleep_for(std::chrono::microseconds(interval));
}
_t1 = std::chrono::steady_clock::now();
_deviceData.getFilterData().getPCRData()->clearPCRDelta();
_deviceData.getFilter().getPCRData()->clearPCRDelta();
} else {
std::this_thread::sleep_for(std::chrono::microseconds(150));
}
Expand All @@ -124,7 +124,7 @@ bool TSReader::readFullTSPacket(mpegts::PacketBuffer &buffer) {
return false;
}
// Add data to Filter
_deviceData.getFilterData().addData(_feID, buffer);
_deviceData.getFilter().filterData(_feID, buffer);
return true;
}

Expand Down

0 comments on commit c56c6a7

Please sign in to comment.