Skip to content

Commit 1f0629c

Browse files
committed
decode: added ability to decoder to resuse device in multisession decode mode
1 parent 8102c9b commit 1f0629c

File tree

7 files changed

+584
-31
lines changed

7 files changed

+584
-31
lines changed

common/libs/VkCodecUtils/ProgramConfig.h

+33-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct ProgramConfig {
8080
outputcrcPerFrame = false;
8181
outputcrc = false;
8282
crcOutputFile = nullptr;
83+
numberOfDecodeWorkers = 0;
84+
enableWorkerProcessesPoll = false;
85+
ipcType = 0;
8386
}
8487

8588
using ProgramArgs = std::vector<ArgSpec>;
@@ -187,8 +190,9 @@ struct ProgramConfig {
187190
{"--input", "-i", 1, "Input filename to decode",
188191
[this](const char **args, const ProgramArgs &a) {
189192
videoFileName = args[0];
190-
std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
191-
return (bool)validVideoFileStream;
193+
// std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
194+
// return (bool)validVideoFileStream;
195+
return true;
192196
}},
193197
{"--output", "-o", 1, "Output filename to dump raw video to",
194198
[this](const char **args, const ProgramArgs &a) {
@@ -322,6 +326,17 @@ struct ProgramConfig {
322326
crcInitValue = crcInitValueTemp;
323327
return true;
324328
}},
329+
{"--poll-of-processes", nullptr, 1, "Use poll of worker processes and specify number of workers.",
330+
[this](const char **args, const ProgramArgs &a) {
331+
enableWorkerProcessesPoll = true;
332+
numberOfDecodeWorkers = std::atoi(args[0]);
333+
return true;
334+
}},
335+
{"--files-to-decode", nullptr, 1, "Specify a file location where command lines for the poll of worker processes are saved.",
336+
[this](const char **args, const ProgramArgs &a) {
337+
fileListIpc = args[0];
338+
return true;
339+
}},
325340
};
326341

327342
for (int i = 1; i < argc; i++) {
@@ -391,6 +406,18 @@ struct ProgramConfig {
391406
crcOutputFile = stdout;
392407
}
393408
}
409+
410+
if (!enableWorkerProcessesPoll) {
411+
if (videoFileName.length() == 0) {
412+
std::cerr << "Input file should be specified" << std::endl;
413+
exit(EXIT_FAILURE);
414+
}
415+
std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
416+
if (!(bool)validVideoFileStream) {
417+
std::cerr << "Can't open input file: invalid file name" << std::endl;
418+
exit(EXIT_FAILURE);
419+
}
420+
}
394421
}
395422

396423
// Assuming we have the length as a parameter:
@@ -461,6 +488,7 @@ struct ProgramConfig {
461488
uint32_t decoderQueueSize;
462489
int32_t enablePostProcessFilter;
463490
uint32_t *crcOutput;
491+
uint32_t numberOfDecodeWorkers;
464492
uint32_t enableStreamDemuxing : 1;
465493
uint32_t directMode : 1;
466494
uint32_t vsync : 1;
@@ -474,6 +502,9 @@ struct ProgramConfig {
474502
uint32_t outputy4m : 1;
475503
uint32_t outputcrc : 1;
476504
uint32_t outputcrcPerFrame : 1;
505+
uint32_t enableWorkerProcessesPoll : 1;
506+
uint32_t ipcType : 1;
507+
std::string fileListIpc;
477508
};
478509

479510
#endif /* _PROGRAMSETTINGS_H_ */
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <vector>
2+
#include <string>
3+
#include <iostream>
4+
#include <sstream>
5+
6+
enum IPC_TYPE { UNIX_DOMAIN_SOCKETS = 0 };
7+
constexpr int DEFAULT_BUFLEN = 512;
8+
9+
int usoc_manager(int isNoPresent, std::string& inputCmdsList);
10+
int clientConnectServer(std::string& recvbuf, const char* usocfilename = NULL);
11+
12+
#ifdef _WIN32
13+
14+
static int cloneTheProcess(int argc, const char** argv, PROCESS_INFORMATION& pi, STARTUPINFO& si)
15+
{
16+
// Start the child process.
17+
ZeroMemory( &si, sizeof(si) );
18+
si.cb = sizeof(si);
19+
ZeroMemory( &pi, sizeof(pi) );
20+
std::string argsToPass;
21+
for (int i = 0; i < argc; i++) {
22+
argsToPass += argv[i];
23+
argsToPass += " ";
24+
}
25+
argsToPass += "spawn";
26+
// std::cout << argsToPass;
27+
if( !CreateProcess( NULL, // No module name (use command line)
28+
(LPTSTR)argsToPass.c_str(), // Command line
29+
NULL, // Process handle not inheritable
30+
NULL, // Thread handle not inheritable
31+
FALSE, // Set handle inheritance to FALSE
32+
0, // No creation flags //debug: NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
33+
NULL, // Use parent's environment block
34+
NULL, // Use parent's starting directory
35+
&si, // Pointer to STARTUPINFO structure
36+
&pi ) // Pointer to PROCESS_INFORMATION structure
37+
)
38+
{
39+
printf( "CreateProcess failed (%d).\n", GetLastError() );
40+
return -1;
41+
}
42+
return 0;
43+
}
44+
#endif
45+
46+
static int parseCharArray(std::vector<std::string>& w, const char* messageString, int& argc, const char **argv) {
47+
std::stringstream ss(messageString);
48+
std::string word;
49+
argc = 0;
50+
std::cout << std::endl;
51+
while (ss >> w[argc]) {
52+
if (w[argc][0] == '~') {
53+
w[argc] = getenv("HOME") + w[argc].substr(1);
54+
// printf("\n argv[%d] is %s", argc, w[argc].c_str());
55+
}
56+
if (w[argc].substr(0, 6) == "finish") {
57+
printf("Received a request to finish this decode worker. The worker process is terminated (completed).\n");
58+
return 0;
59+
}
60+
if (w[argc].substr(0, 6) == "nodata") {
61+
printf("Received a request to wait for a data...\n");
62+
return 0;
63+
}
64+
argv[argc] = w[argc].c_str();
65+
argc++;
66+
}
67+
return argc >= 1;//3;
68+
}
69+
70+
static int receiveNewBitstream(IPC_TYPE ipcType, bool enableWorkerProcessesPoll, std::string& receivedMessage)
71+
{
72+
if (!enableWorkerProcessesPoll) {
73+
return 0;
74+
}
75+
int isDataReceived = 0;
76+
if (ipcType == IPC_TYPE::UNIX_DOMAIN_SOCKETS) {
77+
isDataReceived = clientConnectServer(receivedMessage);
78+
}
79+
return isDataReceived;
80+
}

0 commit comments

Comments
 (0)