Skip to content

Commit

Permalink
Cleanup unused code (#65)
Browse files Browse the repository at this point in the history
Cleanup code
  • Loading branch information
tszumski authored Feb 11, 2025
1 parent 4433735 commit f27d737
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 226 deletions.
134 changes: 2 additions & 132 deletions gRPC/CmdPassImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,144 +4,14 @@
#include <sstream>
#include "CmdPassImpl.h"

// Helper function to convert string to any type
template <typename T>
T from_string(const std::string& str) {
std::istringstream iss(str);
T value;
iss >> value;
return value;
}

// Function to convert vector of string pairs to FrameRate
static FrameRate stringPairsToFrameRate(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
FrameRate frameRate;
frameRate.numerator = from_string<int>(pairs.at(prefix + "frame_rate_numerator"));
frameRate.denominator = from_string<int>(pairs.at(prefix + "frame_rate_denominator"));
return frameRate;
}

// Function to convert vector of string pairs to Video
static Video stringPairsToVideo(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
Video video;
video.frame_width = from_string<int>(pairs.at(prefix + "frame_width"));
video.frame_height = from_string<int>(pairs.at(prefix + "frame_height"));
video.pixel_format = pairs.at(prefix + "pixel_format");
video.video_type = pairs.at(prefix + "video_type");
video.frame_rate = stringPairsToFrameRate(pairs, prefix);
return video;
}

// Function to convert vector of string pairs to Audio
static Audio stringPairsToAudio(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
Audio audio;
audio.channels = from_string<int>(pairs.at(prefix + "channels"));
audio.sample_rate = from_string<int>(pairs.at(prefix + "sample_rate"));
audio.format = pairs.at(prefix + "format");
audio.packet_time = pairs.at(prefix + "packet_time");
return audio;
}

// Function to convert vector of string pairs to File
static File stringPairsToFile(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
File file;
file.path = pairs.at(prefix + "file_path");
file.filename = pairs.at(prefix + "file_filename");
return file;
}

// Function to convert vector of string pairs to ST2110
static ST2110 stringPairsToST2110(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
ST2110 st2110;
st2110.network_interface = pairs.at(prefix + "network_interface");
st2110.local_ip = pairs.at(prefix + "local_ip");
st2110.remote_ip = pairs.at(prefix + "remote_ip");
st2110.transport = pairs.at(prefix + "transport");
st2110.remote_port = from_string<int>(pairs.at(prefix + "remote_port"));
st2110.payload_type = from_string<int>(pairs.at(prefix + "st_payload_type"));
return st2110;
}

// Function to convert vector of string pairs to MCM
static MCM stringPairsToMCM(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
MCM mcm;
mcm.conn_type = pairs.at(prefix + "conn_type");
mcm.transport = pairs.at(prefix + "transport");
mcm.transport_pixel_format = pairs.at(prefix + "transport_pixel_format");
mcm.ip = pairs.at(prefix + "ip");
mcm.port = from_string<int>(pairs.at(prefix + "port"));
mcm.urn = pairs.at(prefix + "urn");
return mcm;
}

// Function to convert vector of string pairs to Payload
static Payload stringPairsToPayload(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
Payload payload;
payload.type = static_cast<payload_type>(from_string<int>(pairs.at(prefix + "payload_type")));
if (payload.type == video) {
payload.video = stringPairsToVideo(pairs, prefix);
} else if (payload.type == audio) {
payload.audio = stringPairsToAudio(pairs, prefix);
}
return payload;
}

// Function to convert vector of string pairs to StreamType
static StreamType stringPairsToStreamType(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
StreamType streamType;
streamType.type = static_cast<stream_type>(from_string<int>(pairs.at(prefix + "stream_type")));
if (streamType.type == file) {
streamType.file = stringPairsToFile(pairs, prefix);
} else if (streamType.type == st2110) {
streamType.st2110 = stringPairsToST2110(pairs, prefix);
} else if (streamType.type == mcm) {
streamType.mcm = stringPairsToMCM(pairs, prefix);
}
return streamType;
}

// Function to convert vector of string pairs to Stream
static Stream stringPairsToStream(const std::unordered_map<std::string, std::string>& pairs, const std::string& prefix) {
Stream stream;
stream.payload = stringPairsToPayload(pairs, prefix);
stream.stream_type = stringPairsToStreamType(pairs, prefix);
return stream;
}

// Function to convert vector of string pairs to Config
static Config stringPairsToConfig(const std::vector<std::pair<std::string, std::string>>& pairs) {
Config config;

if (pairs.front().first == "json") {
if (deserialize_config_json(config, pairs.front().second) != 0) {
std::cout << "Error deserializing Config from json, trying previous solution" << std::endl;
}
else {
return config;
}
if (deserialize_config_json(config, pairs.front().second) != 0) {
std::cout << "Error deserializing Config from json, trying previous solution" << std::endl;
}

std::unordered_map<std::string, std::string> pairs_map(pairs.begin(), pairs.end());
config.function = pairs_map.at("function");
config.gpu_hw_acceleration = pairs_map.at("gpu_hw_acceleration");
config.logging_level = from_string<int>(pairs_map.at("logging_level"));

// Extract senders and receivers
size_t sender_index = 0;
size_t receiver_index = 0;
while (true) {
std::string sender_prefix = "sender_" + std::to_string(sender_index) + "_";
std::string receiver_prefix = "receiver_" + std::to_string(receiver_index) + "_";
if (pairs_map.find(sender_prefix + "payload_type") != pairs_map.end()) {
config.senders.push_back(stringPairsToStream(pairs_map, sender_prefix));
++sender_index;
} else if (pairs_map.find(receiver_prefix + "payload_type") != pairs_map.end()) {
config.receivers.push_back(stringPairsToStream(pairs_map, receiver_prefix));
++receiver_index;
} else {
break;
}
}
return config;
}

Expand Down
94 changes: 0 additions & 94 deletions gRPC/FFmpeg_wrapper_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,90 +94,6 @@ void CmdPassClient::WaitForAllRequests() {
all_tasks_completed.wait(false);
}

// Helper function to convert any type to string
template <typename T>
std::string to_string(const T& value) {
std::ostringstream oss;
oss << value;
return oss.str();
}

// Function to convert FrameRate to vector of string pairs
static void frameRateToStringPairs(const FrameRate& frameRate, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "frame_rate_numerator", to_string<int>(frameRate.numerator)});
result.push_back({prefix + "frame_rate_denominator", to_string<int>(frameRate.denominator)});
}

// Function to convert Video to vector of string pairs
static void videoToStringPairs(const Video& video, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "frame_width", to_string<int>(video.frame_width)});
result.push_back({prefix + "frame_height", to_string<int>(video.frame_height)});
result.push_back({prefix + "pixel_format", video.pixel_format});
result.push_back({prefix + "video_type", video.video_type});
frameRateToStringPairs(video.frame_rate, result, prefix);
}

// Function to convert Audio to vector of string pairs
static void audioToStringPairs(const Audio& audio, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "channels", to_string<int>(audio.channels)});
result.push_back({prefix + "sample_rate", to_string<int>(audio.sample_rate)});
result.push_back({prefix + "format", audio.format});
result.push_back({prefix + "packet_time", audio.packet_time});
}

// Function to convert File to vector of string pairs
static void fileToStringPairs(const File& file, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "file_path", file.path});
result.push_back({prefix + "file_filename", file.filename});
}

// Function to convert ST2110 to vector of string pairs
static void st2110ToStringPairs(const ST2110& st2110, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "network_interface", st2110.network_interface});
result.push_back({prefix + "local_ip", st2110.local_ip});
result.push_back({prefix + "remote_ip", st2110.remote_ip});
result.push_back({prefix + "transport", st2110.transport});
result.push_back({prefix + "remote_port", to_string<int>(st2110.remote_port)});
result.push_back({prefix + "st_payload_type", to_string<int>(st2110.payload_type)});
}

// Function to convert MCM to vector of string pairs
static void mcmToStringPairs(const MCM& mcm, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "conn_type", mcm.conn_type});
result.push_back({prefix + "transport", mcm.transport});
result.push_back({prefix + "transport_pixel_format", mcm.transport_pixel_format});
result.push_back({prefix + "ip", mcm.ip});
result.push_back({prefix + "port", to_string<int>(mcm.port)});
result.push_back({prefix + "urn", mcm.urn});
}

// Function to convert Payload to vector of string pairs
static void payloadToStringPairs(const Payload& payload, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "payload_type", to_string<int>(payload.type)});
if (payload.type == video) {
videoToStringPairs(payload.video, result, prefix);
} else if (payload.type == audio) {
audioToStringPairs(payload.audio, result, prefix);
}
}

// Function to convert StreamType to vector of string pairs
static void streamTypeToStringPairs(const StreamType& streamType, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
result.push_back({prefix + "stream_type", to_string<int>(streamType.type)});
if (streamType.type == file) {
fileToStringPairs(streamType.file, result, prefix);
} else if (streamType.type == st2110) {
st2110ToStringPairs(streamType.st2110, result, prefix);
} else if (streamType.type == mcm) {
mcmToStringPairs(streamType.mcm, result, prefix);
}
}

// Function to convert Stream to vector of string pairs
static void streamToStringPairs(const Stream& stream, std::vector<std::pair<std::string, std::string>>& result, const std::string& prefix) {
payloadToStringPairs(stream.payload, result, prefix);
streamTypeToStringPairs(stream.stream_type, result, prefix);
}

// Function to convert Config to vector of string pairs
std::vector<std::pair<std::string, std::string>> commitConfigs(const Config& config) {
Expand All @@ -189,16 +105,6 @@ std::vector<std::pair<std::string, std::string>> commitConfigs(const Config& con
}
else {
std::cout << "Error serializing Config to json, trying previos solution" << std::endl;

result.push_back({"function", config.function});
result.push_back({"gpu_hw_acceleration", config.gpu_hw_acceleration});
result.push_back({"logging_level", to_string<int>(config.logging_level)});
for (size_t i = 0; i < config.senders.size(); ++i) {
streamToStringPairs(config.senders[i], result, "sender_" + to_string<int>(i) + "_");
}
for (size_t i = 0; i < config.receivers.size(); ++i) {
streamToStringPairs(config.receivers[i], result, "receiver_" + to_string<int>(i) + "_");
}
};

return result;
Expand Down

0 comments on commit f27d737

Please sign in to comment.