Skip to content

Commit

Permalink
decode: added ability to decoder to resuse device in multisession dec…
Browse files Browse the repository at this point in the history
…ode mode
  • Loading branch information
t-boiko committed Dec 3, 2024
1 parent 8102c9b commit 1f0629c
Show file tree
Hide file tree
Showing 7 changed files with 584 additions and 31 deletions.
35 changes: 33 additions & 2 deletions common/libs/VkCodecUtils/ProgramConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct ProgramConfig {
outputcrcPerFrame = false;
outputcrc = false;
crcOutputFile = nullptr;
numberOfDecodeWorkers = 0;
enableWorkerProcessesPoll = false;
ipcType = 0;
}

using ProgramArgs = std::vector<ArgSpec>;
Expand Down Expand Up @@ -187,8 +190,9 @@ struct ProgramConfig {
{"--input", "-i", 1, "Input filename to decode",
[this](const char **args, const ProgramArgs &a) {
videoFileName = args[0];
std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
return (bool)validVideoFileStream;
// std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
// return (bool)validVideoFileStream;
return true;
}},
{"--output", "-o", 1, "Output filename to dump raw video to",
[this](const char **args, const ProgramArgs &a) {
Expand Down Expand Up @@ -322,6 +326,17 @@ struct ProgramConfig {
crcInitValue = crcInitValueTemp;
return true;
}},
{"--poll-of-processes", nullptr, 1, "Use poll of worker processes and specify number of workers.",
[this](const char **args, const ProgramArgs &a) {
enableWorkerProcessesPoll = true;
numberOfDecodeWorkers = std::atoi(args[0]);
return true;
}},
{"--files-to-decode", nullptr, 1, "Specify a file location where command lines for the poll of worker processes are saved.",
[this](const char **args, const ProgramArgs &a) {
fileListIpc = args[0];
return true;
}},
};

for (int i = 1; i < argc; i++) {
Expand Down Expand Up @@ -391,6 +406,18 @@ struct ProgramConfig {
crcOutputFile = stdout;
}
}

if (!enableWorkerProcessesPoll) {
if (videoFileName.length() == 0) {
std::cerr << "Input file should be specified" << std::endl;
exit(EXIT_FAILURE);
}
std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
if (!(bool)validVideoFileStream) {
std::cerr << "Can't open input file: invalid file name" << std::endl;
exit(EXIT_FAILURE);
}
}
}

// Assuming we have the length as a parameter:
Expand Down Expand Up @@ -461,6 +488,7 @@ struct ProgramConfig {
uint32_t decoderQueueSize;
int32_t enablePostProcessFilter;
uint32_t *crcOutput;
uint32_t numberOfDecodeWorkers;
uint32_t enableStreamDemuxing : 1;
uint32_t directMode : 1;
uint32_t vsync : 1;
Expand All @@ -474,6 +502,9 @@ struct ProgramConfig {
uint32_t outputy4m : 1;
uint32_t outputcrc : 1;
uint32_t outputcrcPerFrame : 1;
uint32_t enableWorkerProcessesPoll : 1;
uint32_t ipcType : 1;
std::string fileListIpc;
};

#endif /* _PROGRAMSETTINGS_H_ */
80 changes: 80 additions & 0 deletions common/libs/VkCodecUtils/poll_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <vector>
#include <string>
#include <iostream>
#include <sstream>

enum IPC_TYPE { UNIX_DOMAIN_SOCKETS = 0 };
constexpr int DEFAULT_BUFLEN = 512;

int usoc_manager(int isNoPresent, std::string& inputCmdsList);
int clientConnectServer(std::string& recvbuf, const char* usocfilename = NULL);

#ifdef _WIN32

static int cloneTheProcess(int argc, const char** argv, PROCESS_INFORMATION& pi, STARTUPINFO& si)
{
// Start the child process.
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
std::string argsToPass;
for (int i = 0; i < argc; i++) {
argsToPass += argv[i];
argsToPass += " ";
}
argsToPass += "spawn";
// std::cout << argsToPass;
if( !CreateProcess( NULL, // No module name (use command line)
(LPTSTR)argsToPass.c_str(), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags //debug: NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return -1;
}
return 0;
}
#endif

static int parseCharArray(std::vector<std::string>& w, const char* messageString, int& argc, const char **argv) {
std::stringstream ss(messageString);
std::string word;
argc = 0;
std::cout << std::endl;
while (ss >> w[argc]) {
if (w[argc][0] == '~') {
w[argc] = getenv("HOME") + w[argc].substr(1);
// printf("\n argv[%d] is %s", argc, w[argc].c_str());
}
if (w[argc].substr(0, 6) == "finish") {
printf("Received a request to finish this decode worker. The worker process is terminated (completed).\n");
return 0;
}
if (w[argc].substr(0, 6) == "nodata") {
printf("Received a request to wait for a data...\n");
return 0;
}
argv[argc] = w[argc].c_str();
argc++;
}
return argc >= 1;//3;
}

static int receiveNewBitstream(IPC_TYPE ipcType, bool enableWorkerProcessesPoll, std::string& receivedMessage)
{
if (!enableWorkerProcessesPoll) {
return 0;
}
int isDataReceived = 0;
if (ipcType == IPC_TYPE::UNIX_DOMAIN_SOCKETS) {
isDataReceived = clientConnectServer(receivedMessage);
}
return isDataReceived;
}
Loading

0 comments on commit 1f0629c

Please sign in to comment.