Skip to content

Commit f5c1cbb

Browse files
committed
Add dump file option to control output file (#109)
generation. Signed-off-by: Ying Luo <ying2.luo@intel.com>
1 parent e062ed0 commit f5c1cbb

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

modules/Examples/SampleDecodeApp/src/sample_decode.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ extern "C" {
4444

4545
#define MULTITHREADDECODING 1
4646

47+
bool g_dump_file = false;
48+
4749
#include <thread>
4850
#include <chrono>
4951

@@ -145,7 +147,7 @@ MRDAStatus DecodeFrame(MRDAHandle mrda_handle, FILE *sink, std::shared_ptr<Frame
145147
// success
146148
if (outBuffer->pts >= 0)
147149
{
148-
WriteDecodedFrame(sink, outBuffer.get());
150+
if (g_dump_file) WriteDecodedFrame(sink, outBuffer.get());
149151
*cur_pts = outBuffer->pts;
150152
// MRDA_LOG(LOG_INFO, "Receive frame at pts: %llu, buffer id %d", outBuffer->pts, outBuffer->bufferItem->buf_id);
151153
}
@@ -200,7 +202,7 @@ void ReceiveFrameThread(MRDAHandle mrda_handle, FILE *sink, uint64_t frameNum)
200202
#ifdef _ENABLE_TRACE_
201203
MRDA_LOG(LOG_INFO, "MRDA trace log: complete receive frame in sample decode, pts: %llu", outBuffer->pts);
202204
#endif
203-
WriteDecodedFrame(sink, outBuffer.get());
205+
if (g_dump_file) WriteDecodedFrame(sink, outBuffer.get());
204206
cur_pts = outBuffer->pts;
205207
// MRDA_LOG(LOG_INFO, "Receive frame at pts: %llu, buffer id %d", outBuffer->pts, outBuffer->bufferItem->buf_id);
206208
}
@@ -235,7 +237,7 @@ MRDAStatus FlushFrame(MRDAHandle mrda_handle, FILE *sink, uint64_t cur_pts, uint
235237
// success
236238
if (outBuffer->pts >= 0)
237239
{
238-
WriteDecodedFrame(sink, outBuffer.get());
240+
if (g_dump_file) WriteDecodedFrame(sink, outBuffer.get());
239241
// MRDA_LOG(LOG_INFO, "In flush process: Receive frame at pts: %llu", outBuffer->pts);
240242
}
241243
cur_pts = outBuffer->pts;
@@ -386,6 +388,7 @@ void PrintHelp()
386388
printf("%s", " [--height frame_height] - specifies the frame height. \n");
387389
printf("%s", " [--colorFormat color_format] - specifies the color format. option: yuv420p, nv12, rgb32 \n");
388390
printf("%s", " [--decodeType decode_type] - specifies the decode type. option: ffmpeg, oneVPL \n");
391+
printf("%s", " [--dumpFile 1/0] - dump file(1) or not(0). default: 0: no dump file \n");
389392
printf("%s", "Examples: ./MRDASampleDecodeApp.exe --hostSessionAddr 127.0.0.1:50051 -i input.h265 -o output.raw --memDevSize 1000000000 --bufferNum 100 --bufferSize 10000000 --inDevPath /dev/shm/shm1IN --outDevPath /dev/shm/shm1OUT --inDevSlotNumber 11 --outDevSlotNumber 12 --frameNum 3000 --codecId h265 --fps 30 --width 1920 --height 1080 --colorFormat rgb32 --decodeType ffmpeg \n");
390393
}
391394

@@ -403,6 +406,15 @@ TASKTYPE StringToDecodeType(const char *decode_type_str)
403406
return decode_type;
404407
}
405408

409+
bool stringToBool(const std::string& str) {
410+
if (str == "1") return true;
411+
else if (str == "0") return false;
412+
else {
413+
MRDA_LOG(LOG_ERROR, "Invalid boolean string: %s", str.c_str());
414+
return false;
415+
}
416+
}
417+
406418
bool ParseConfig(int argc, char **argv, InputConfig *inputConfig) {
407419
// Check if the argument count is reasonable compared to InputConfig requirements
408420
if (argc < 2) {
@@ -447,6 +459,8 @@ bool ParseConfig(int argc, char **argv, InputConfig *inputConfig) {
447459
inputConfig->color_format = StringToColorFormat(argv[++i]);
448460
} else if (strcmp(argv[i], "--decodeType") == 0 && i + 1 < argc) {
449461
inputConfig->decode_type = StringToDecodeType(argv[++i]);
462+
} else if (strcmp(argv[i], "--dumpFile") == 0 && i + 1 < argc) {
463+
g_dump_file = stringToBool(argv[++i]);
450464
} else if (strcmp(argv[i], "--help") == 0 && i + 1 < argc) {
451465
PrintHelp();
452466
return false;

modules/Examples/SampleDecodeApp/src/sample_decode_sw.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct INPUTCONFIG
5959
uint32_t frame_height; //!< height of frame
6060
AVPixelFormat color_format; //!< pixel color format
6161
TASKTYPE decode_type; //!< decode type, 0 is ffmpeg decode, 1 is oneVPL decode
62+
bool dump_file; //!< dump file flag
6263
} InputConfig;
6364

6465
typedef struct DECODERCONTEXT
@@ -86,6 +87,7 @@ void PrintHelp()
8687
printf("%s", " [--height frame_height] - specifies the frame height. \n");
8788
printf("%s", " [--colorFormat color_format] - specifies the color format. option: yuv420p, nv12, rgb32 \n");
8889
printf("%s", " [--decodeType decode_type] - specifies the decode type. option: ffmpeg \n");
90+
printf("%s", " [--dumpFile 1/0] - dump file(1) or not(0). default: 0: no dump file \n");
8991
printf("%s", "Examples: ./MRDASampleDecodeAppSW.exe -i input.h265 -o output.raw --frameNum 3000 --codecId h265 --fps 30 --width 1920 --height 1080 --colorFormat rgb32 --decodeType ffmpeg \n");
9092
}
9193

@@ -142,6 +144,15 @@ TASKTYPE StringToDecodeType(const char *decode_type_str)
142144
return decode_type;
143145
}
144146

147+
bool stringToBool(const std::string& str) {
148+
if (str == "1") return true;
149+
else if (str == "0") return false;
150+
else {
151+
MRDA_LOG(LOG_ERROR, "Invalid boolean string: %s", str.c_str());
152+
return false;
153+
}
154+
}
155+
145156
bool ParseConfig(int argc, char **argv, InputConfig *inputConfig) {
146157
// Check if the argument count is reasonable compared to InputConfig requirements
147158
if (argc < 2) {
@@ -170,6 +181,8 @@ bool ParseConfig(int argc, char **argv, InputConfig *inputConfig) {
170181
inputConfig->color_format = StringToColorFormat(argv[++i]);
171182
} else if (strcmp(argv[i], "--decodeType") == 0 && i + 1 < argc) {
172183
inputConfig->decode_type = StringToDecodeType(argv[++i]);
184+
} else if (strcmp(argv[i], "--dumpFile") == 0 && i + 1 < argc) {
185+
inputConfig->dump_file = stringToBool(argv[++i]);
173186
} else if (strcmp(argv[i], "--help") == 0 && i + 1 < argc) {
174187
PrintHelp();
175188
return false;
@@ -381,7 +394,7 @@ MRDAStatus DecodeOneFrame(DecodeContext *decodeContext, InputConfig *inputConfig
381394
}
382395
}
383396

384-
if ((ret = fwrite(buffer, 1, size, decodeContext->output_file)) < 0) {
397+
if (inputConfig->dump_file && ((ret = fwrite(buffer, 1, size, decodeContext->output_file)) < 0)) {
385398
MRDA_LOG(LOG_ERROR, "Failed to dump raw data.");
386399
av_free(buffer);
387400
return MRDA_STATUS_OPERATION_FAIL;

0 commit comments

Comments
 (0)