Skip to content

Commit a5da5b6

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

6 files changed

Lines changed: 491 additions & 32 deletions

File tree

common/libs/VkCodecUtils/ProgramConfig.h

Lines changed: 31 additions & 2 deletions
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,7 @@ 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+
return true;
192194
}},
193195
{"--output", "-o", 1, "Output filename to dump raw video to",
194196
[this](const char **args, const ProgramArgs &a) {
@@ -322,6 +324,17 @@ struct ProgramConfig {
322324
crcInitValue = crcInitValueTemp;
323325
return true;
324326
}},
327+
{"--poll-of-processes", nullptr, 1, "Use poll of worker processes and specify number of workers.",
328+
[this](const char **args, const ProgramArgs &a) {
329+
enableWorkerProcessesPoll = true;
330+
numberOfDecodeWorkers = std::atoi(args[0]);
331+
return true;
332+
}},
333+
{"--files-to-decode", nullptr, 1, "Specify a file location where command lines for the poll of worker processes are saved.",
334+
[this](const char **args, const ProgramArgs &a) {
335+
fileListIpc = args[0];
336+
return true;
337+
}},
325338
};
326339

327340
for (int i = 1; i < argc; i++) {
@@ -391,6 +404,18 @@ struct ProgramConfig {
391404
crcOutputFile = stdout;
392405
}
393406
}
407+
408+
if (!enableWorkerProcessesPoll) {
409+
if (videoFileName.length() == 0) {
410+
std::cerr << "Input file should be specified" << std::endl;
411+
exit(EXIT_FAILURE);
412+
}
413+
std::ifstream validVideoFileStream(videoFileName, std::ifstream::in);
414+
if (!(bool)validVideoFileStream) {
415+
std::cerr << "Can't open input file: invalid file name" << std::endl;
416+
exit(EXIT_FAILURE);
417+
}
418+
}
394419
}
395420

396421
// Assuming we have the length as a parameter:
@@ -461,6 +486,7 @@ struct ProgramConfig {
461486
uint32_t decoderQueueSize;
462487
int32_t enablePostProcessFilter;
463488
uint32_t *crcOutput;
489+
uint32_t numberOfDecodeWorkers;
464490
uint32_t enableStreamDemuxing : 1;
465491
uint32_t directMode : 1;
466492
uint32_t vsync : 1;
@@ -474,6 +500,9 @@ struct ProgramConfig {
474500
uint32_t outputy4m : 1;
475501
uint32_t outputcrc : 1;
476502
uint32_t outputcrcPerFrame : 1;
503+
uint32_t enableWorkerProcessesPoll : 1;
504+
uint32_t ipcType : 1;
505+
std::string fileListIpc;
477506
};
478507

479508
#endif /* _PROGRAMSETTINGS_H_ */
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
ZeroMemory( &si, sizeof(si) );
17+
si.cb = sizeof(si);
18+
ZeroMemory( &pi, sizeof(pi) );
19+
std::string argsToPass;
20+
for (int i = 0; i < argc; i++) {
21+
argsToPass += argv[i];
22+
argsToPass += " ";
23+
}
24+
argsToPass += "spawn";
25+
if( !CreateProcess( NULL,
26+
(LPTSTR)argsToPass.c_str(),
27+
NULL,
28+
NULL,
29+
FALSE,
30+
0,
31+
NULL,
32+
NULL,
33+
&si,
34+
&pi)
35+
)
36+
{
37+
printf( "CreateProcess failed (%d).\n", GetLastError() );
38+
return -1;
39+
}
40+
return 0;
41+
}
42+
#endif
43+
44+
static int parseCharArray(std::vector<std::string>& w, const char* messageString, int& argc, const char **argv) {
45+
std::stringstream ss(messageString);
46+
std::string word;
47+
argc = 0;
48+
std::cout << std::endl;
49+
while (ss >> w[argc]) {
50+
if (w[argc][0] == '~') {
51+
w[argc] = getenv("HOME") + w[argc].substr(1);
52+
}
53+
if (w[argc].substr(0, 6) == "finish") {
54+
printf("Received a request to finish this decode worker. The worker process is terminated (completed).\n");
55+
return 0;
56+
}
57+
if (w[argc].substr(0, 6) == "nodata") {
58+
printf("Received a request to wait for a data...\n");
59+
return 0;
60+
}
61+
argv[argc] = w[argc].c_str();
62+
argc++;
63+
}
64+
return argc >= 1;
65+
}
66+
67+
static int receiveNewBitstream(IPC_TYPE ipcType, bool enableWorkerProcessesPoll, std::string& receivedMessage)
68+
{
69+
if (!enableWorkerProcessesPoll) {
70+
return 0;
71+
}
72+
int isDataReceived = 0;
73+
if (ipcType == IPC_TYPE::UNIX_DOMAIN_SOCKETS) {
74+
isDataReceived = clientConnectServer(receivedMessage);
75+
}
76+
return isDataReceived;
77+
}

0 commit comments

Comments
 (0)