Skip to content

Commit aad9c24

Browse files
Fixed the MD5 calculation error on some streams when both decoded output dumping and MD5 generation are on. (#607)
* * Fixed the MD5 calculation error on some streams when both decoded output dumping and MD5 generation are on. - The issue is with the final flushing of the remaining frames at the end of stream, where MD5 update is skipped when output dumping is on. * * Minor format changes. --------- Co-authored-by: Aryan Salmanpour <aryan.salmanpour@amd.com>
1 parent 23c17cc commit aad9c24

7 files changed

Lines changed: 40 additions & 37 deletions

File tree

docs/how-to/using-rocDecode-video-decoder.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ For example, the reconfiguration structs are defined in |common|_ in the rocDeco
9393
.. code:: C++
9494

9595
typedef enum ReconfigFlushMode_enum {
96-
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
97-
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
98-
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
96+
RECONFIG_FLUSH_MODE_NONE = 0x0, /**< Just flush to get the frame count */
97+
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 0x1, /**< The remaining frames will be dumped to file in this mode */
98+
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = (0x1 << 1), /**< Calculate the MD5 of the flushed frames */
9999
} ReconfigFlushMode;
100100
101101
typedef struct ReconfigDumpFileStruct_t {
@@ -108,10 +108,12 @@ For example, the reconfiguration structs are defined in |common|_ in the rocDeco
108108
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
109109
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
110110
reconfig_user_struct.output_file_name = output_file_path;
111+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
111112
if (dump_output_frames) {
112-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
113-
} else {
114-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
113+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
114+
}
115+
if (b_generate_md5) {
116+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_CALCULATE_MD5;
115117
}
116118
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
117119
viddec.SetReconfigParams(&reconfig_params);

docs/how-to/using-rocDecode-videodecode-sample.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ The reconfiguration structs are defined in |common|_ in the rocDecode samples. T
133133
.. code:: C++
134134

135135
typedef enum ReconfigFlushMode_enum {
136-
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
137-
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
138-
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
136+
RECONFIG_FLUSH_MODE_NONE = 0x0, /**< Just flush to get the frame count */
137+
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 0x1, /**< The remaining frames will be dumped to file in this mode */
138+
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = (0x1 << 1), /**< Calculate the MD5 of the flushed frames */
139139
} ReconfigFlushMode;
140140
141141
typedef struct ReconfigDumpFileStruct_t {
@@ -152,12 +152,12 @@ If the ``-o`` output file path argument was set, the remaining frames in the dec
152152
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
153153
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
154154
reconfig_user_struct.output_file_name = output_file_path;
155+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
155156
if (dump_output_frames) {
156-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
157-
} else if (b_generate_md5) {
158-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_CALCULATE_MD5;
159-
} else {
160-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
157+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
158+
}
159+
if (b_generate_md5) {
160+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_CALCULATE_MD5;
161161
}
162162
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
163163

samples/common.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ THE SOFTWARE.
2626
#include "md5.h"
2727

2828
typedef enum ReconfigFlushMode_enum {
29-
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
30-
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
31-
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
29+
RECONFIG_FLUSH_MODE_NONE = 0x0, /**< Just flush to get the frame count */
30+
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 0x1, /**< The remaining frames will be dumped to file in this mode */
31+
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = (0x1 << 1), /**< Calculate the MD5 of the flushed frames */
3232
} ReconfigFlushMode;
3333

34-
// this struct is used by videodecode and videodecodeMultiFiles to dump last frames to file
34+
// This struct is used by sample apps to dump last frames to file
3535
typedef struct ReconfigDumpFileStruct_t {
3636
bool b_dump_frames_to_file;
3737
std::string output_file_name;
@@ -56,11 +56,12 @@ int ReconfigureFlushCallback(void *p_viddec_obj, uint32_t flush_mode, void *p_us
5656
while ((pframe = viddec->GetFrame(&pts))) {
5757
if (flush_mode != RECONFIG_FLUSH_MODE_NONE) {
5858
ReconfigDumpFileStruct *p_dump_file_struct = static_cast<ReconfigDumpFileStruct *>(p_user_struct);
59-
if (flush_mode == ReconfigFlushMode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE) {
59+
if (flush_mode & ReconfigFlushMode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE) {
6060
if (p_dump_file_struct->b_dump_frames_to_file) {
6161
viddec->SaveFrameToFile(p_dump_file_struct->output_file_name, pframe, surf_info);
6262
}
63-
} else if (flush_mode == ReconfigFlushMode::RECONFIG_FLUSH_MODE_CALCULATE_MD5) {
63+
}
64+
if (flush_mode & ReconfigFlushMode::RECONFIG_FLUSH_MODE_CALCULATE_MD5) {
6465
MD5Generator *md5_generator = static_cast<MD5Generator*>(p_dump_file_struct->md5_generator_handle);
6566
md5_generator->UpdateMd5ForFrame(pframe, surf_info);
6667
}

samples/videoDecode/videodecode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ int main(int argc, char **argv) {
294294
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
295295
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
296296
reconfig_user_struct.output_file_name = output_file_path;
297+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
297298
if (dump_output_frames) {
298-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
299-
} else if (b_generate_md5) {
300-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_CALCULATE_MD5;
301-
} else {
302-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
299+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
300+
}
301+
if (b_generate_md5) {
302+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_CALCULATE_MD5;
303303
}
304304
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
305305

samples/videoDecodeBatch/videodecodebatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ int main(int argc, char **argv) {
317317
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
318318
if (!b_dump_output_frames) {
319319
reconfig_user_struct.b_dump_frames_to_file = false;
320-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
320+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
321321
} else {
322322
reconfig_user_struct.b_dump_frames_to_file = true;
323-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
323+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
324324
}
325325
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
326326

samples/videoDecodePicFiles/videodecodepicfiles.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ int main(int argc, char **argv) {
265265
reconfig_params.p_fn_reconfigure_flush = ReconfigureFlushCallback;
266266
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
267267
reconfig_user_struct.output_file_name = output_file_path;
268+
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
268269
if (dump_output_frames) {
269-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
270-
} else if (b_generate_md5) {
271-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_CALCULATE_MD5;
272-
} else {
273-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
270+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
271+
}
272+
if (b_generate_md5) {
273+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_CALCULATE_MD5;
274274
}
275275
reconfig_params.p_reconfig_user_struct = &reconfig_user_struct;
276276

samples/videoDecodeRaw/videodecoderaw.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ THE SOFTWARE.
4141
#include "roc_video_dec.h"
4242

4343
typedef enum ReconfigFlushMode_enum {
44-
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
45-
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
46-
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
44+
RECONFIG_FLUSH_MODE_NONE = 0x0, /**< Just flush to get the frame count */
45+
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 0x1, /**< The remaining frames will be dumped to file in this mode */
46+
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = (0x1 << 1), /**< Calculate the MD5 of the flushed frames */
4747
} ReconfigFlushMode;
4848

4949
// this struct is used by videodecode and videodecodeMultiFiles to dump last frames to file
@@ -71,7 +71,7 @@ int ReconfigureFlushCallback(void *p_viddec_obj, uint32_t flush_mode, void *p_us
7171
while ((pframe = viddec->GetFrame(&pts))) {
7272
if (flush_mode != RECONFIG_FLUSH_MODE_NONE) {
7373
ReconfigDumpFileStruct *p_dump_file_struct = static_cast<ReconfigDumpFileStruct *>(p_user_struct);
74-
if (flush_mode == ReconfigFlushMode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE) {
74+
if (flush_mode & ReconfigFlushMode::RECONFIG_FLUSH_MODE_DUMP_TO_FILE) {
7575
if (p_dump_file_struct->b_dump_frames_to_file) {
7676
viddec->SaveFrameToFile(p_dump_file_struct->output_file_name, pframe, surf_info);
7777
}
@@ -252,7 +252,7 @@ int main(int argc, char **argv) {
252252
reconfig_user_struct.b_dump_frames_to_file = dump_output_frames;
253253
reconfig_user_struct.output_file_name = output_file_path;
254254
if (dump_output_frames) {
255-
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
255+
reconfig_params.reconfig_flush_mode |= RECONFIG_FLUSH_MODE_DUMP_TO_FILE;
256256
} else {
257257
reconfig_params.reconfig_flush_mode = RECONFIG_FLUSH_MODE_NONE;
258258
}

0 commit comments

Comments
 (0)