From 02b72f2c4d512bbb3ae9a386423d13cc9451110a Mon Sep 17 00:00:00 2001 From: Shaofeng Tang Date: Wed, 14 Dec 2022 17:19:17 +0800 Subject: [PATCH 1/3] Dumping decoded buffer Add a debug option for dumpping decoded buffer Signed-off-by: Shaofeng Tang --- .../src/mfx_c2_decoder_component.cpp | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/c2_components/src/mfx_c2_decoder_component.cpp b/c2_components/src/mfx_c2_decoder_component.cpp index 87fdd6c2..674324cb 100755 --- a/c2_components/src/mfx_c2_decoder_component.cpp +++ b/c2_components/src/mfx_c2_decoder_component.cpp @@ -2277,13 +2277,6 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn MFX_DEBUG_TRACE_I32(m_mfxVideoParams.mfx.FrameInfo.CropW); MFX_DEBUG_TRACE_I32(m_mfxVideoParams.mfx.FrameInfo.CropH); -#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES - static int frameIndex = 0; - uint8_t stride = frame_out.GetC2GraphicView()->layout().planes[C2PlanarLayout::PLANE_Y].rowInc; - static YUVWriter writer("/data/local/tmp",std::vector({}),"decoder_frame.log"); - writer.Write(mfx_surface->Data.Y, stride, frame_out.GetC2GraphicBlock()->height(), frameIndex++); -#endif - decltype(C2WorkOrdinalStruct::timestamp) ready_timestamp{mfx_surface->Data.TimeStamp}; std::unique_ptr work; @@ -2392,6 +2385,40 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn } m_updatingC2Configures.clear(); +#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES + static FILE* m_f = 0; + static int count = 0; + MFX_DEBUG_TRACE_MSG("################## dumping decoded buffer #############################"); + MFX_DEBUG_TRACE_I64(count); + + const C2GraphicView& output_view = block->map().get(); + if (count < 200) { + const uint8_t* srcY = output_view.data()[C2PlanarLayout::PLANE_Y]; + const uint8_t* srcU = output_view.data()[C2PlanarLayout::PLANE_U]; + const uint8_t* srcV = output_view.data()[C2PlanarLayout::PLANE_V]; + if (!m_f) { + m_f = fopen("/data/local/traces/dec.yuv", "w+"); + MFX_DEBUG_TRACE_MSG("/data/local/traces/dec.yuv: created"); + MFX_DEBUG_TRACE_I64(m_f); + } + if (m_f) { + MFX_DEBUG_TRACE_I64(count); + size_t copied_size = 0; + copied_size = fwrite(srcY, m_mfxVideoParams.mfx.FrameInfo.CropW * m_mfxVideoParams.mfx.FrameInfo.CropH, 1, m_f); + MFX_DEBUG_TRACE_I64(copied_size); + copied_size = fwrite(srcU, m_mfxVideoParams.mfx.FrameInfo.CropW * m_mfxVideoParams.mfx.FrameInfo.CropH / 2, 1, m_f); + MFX_DEBUG_TRACE_I64(copied_size); + count++; + } + } else { + if (m_f) { + fclose(m_f); + MFX_DEBUG_TRACE_MSG("stang23 dump closed"); + m_f = NULL; + } + } +#endif + worklet->output.buffers.push_back(out_buffer); block = nullptr; } From 7040a3e9ea3e11309bd34265d348624b04f2cb30 Mon Sep 17 00:00:00 2001 From: Shaofeng Tang Date: Thu, 8 Dec 2022 18:32:24 +0800 Subject: [PATCH 2/3] Debugging log Signed-off-by: Shaofeng Tang --- c2_utils/include/mfx_debug.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/c2_utils/include/mfx_debug.h b/c2_utils/include/mfx_debug.h index c4ecda8e..f0218fbc 100755 --- a/c2_utils/include/mfx_debug.h +++ b/c2_utils/include/mfx_debug.h @@ -23,7 +23,8 @@ #define MFX_DEBUG_NO 0 #define MFX_DEBUG_YES 1 -#define MFX_DEBUG MFX_DEBUG_NO // enables DEBUG output +#define MFX_DEBUG MFX_DEBUG_YES // enables DEBUG output + #define MFX_PERF MFX_DEBUG_NO // enables PERF output, doesn't depends on MFX_DEBUG #define MFX_ATRACE MFX_DEBUG_NO // enables systrace #define MFX_DEBUG_DUMP_FRAME MFX_DEBUG_NO // enables write frame to file From 1b3ff1132d206120361512966180ea725fe06f6e Mon Sep 17 00:00:00 2001 From: Shaofeng Tang Date: Thu, 15 Dec 2022 11:32:23 +0800 Subject: [PATCH 3/3] Add property "mediacodec2.dump.buffer" for triggering dumping buffer setenforce 0 setprop mediacodec2.dump.buffer X to dumping X frames buffer into /data/local/traces/decoder_frame.yuv for instance, setprop mediacodec2.dump.buffer 100 dumping 100 frame buffers. Signed-off-by: Shaofeng Tang --- .../include/mfx_c2_decoder_component.h | 11 +++ .../src/mfx_c2_decoder_component.cpp | 88 ++++++++++++++----- 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/c2_components/include/mfx_c2_decoder_component.h b/c2_components/include/mfx_c2_decoder_component.h index 1ebf26c0..3219b860 100755 --- a/c2_components/include/mfx_c2_decoder_component.h +++ b/c2_components/include/mfx_c2_decoder_component.h @@ -31,6 +31,10 @@ #include "mfx_c2_color_aspects_wrapper.h" #include "mfx_c2_setters.h" +#include + +#define MAX_DUMP_BUFFER 200 + class MfxC2DecoderComponent : public MfxC2Component { public: @@ -251,6 +255,13 @@ class MfxC2DecoderComponent : public MfxC2Component unsigned int m_uOutputDelay = 8u; unsigned int m_uInputDelay = 0u; +//#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES +#if 1 + int m_count = 0; + std::mutex m_count_lock; + bool NeedDumpBuffer(); +#endif + /* -----------------------C2Parameters--------------------------- */ std::shared_ptr m_name; std::shared_ptr m_kind; diff --git a/c2_components/src/mfx_c2_decoder_component.cpp b/c2_components/src/mfx_c2_decoder_component.cpp index 674324cb..e0b2c223 100755 --- a/c2_components/src/mfx_c2_decoder_component.cpp +++ b/c2_components/src/mfx_c2_decoder_component.cpp @@ -2248,6 +2248,45 @@ void MfxC2DecoderComponent::Drain(std::unique_ptr&& work) } } +//#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES +#if 1 +bool MfxC2DecoderComponent::NeedDumpBuffer() { + MFX_DEBUG_TRACE_FUNC; + const char* key = "mediacodec2.dump.buffer"; + char* value = new char[20]; + int len = property_get(key, value, "0"); + +#include +#include + + std::stringstream strValue; + strValue << value; + + unsigned int m_frame_number; + strValue >> m_frame_number; + + if (m_frame_number) + MFX_DEBUG_TRACE_U32(m_frame_number); + m_count_lock.lock(); + if (m_count) { + delete[] value; + m_count_lock.unlock(); + return true; + } else { + delete[] value; + if (len > 0 && m_frame_number > 0) { + m_count = m_frame_number; + MFX_DEBUG_TRACE_PRINTF("--------triggered to dump %d buffers---------", m_frame_number); + property_set(key, "0"); + m_count_lock.unlock(); + return true; + } + m_count_lock.unlock(); + return false; + } +} +#endif + void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint sync_point) { MFX_DEBUG_TRACE_FUNC; @@ -2385,38 +2424,39 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn } m_updatingC2Configures.clear(); -#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES - static FILE* m_f = 0; - static int count = 0; - MFX_DEBUG_TRACE_MSG("################## dumping decoded buffer #############################"); - MFX_DEBUG_TRACE_I64(count); - - const C2GraphicView& output_view = block->map().get(); - if (count < 200) { +//#if MFX_DEBUG_DUMP_FRAME == MFX_DEBUG_YES +#if 1 + static FILE* m_f = 0; + if (NeedDumpBuffer()) { + const C2GraphicView& output_view = block->map().get(); + m_count_lock.lock(); + if (m_count) { const uint8_t* srcY = output_view.data()[C2PlanarLayout::PLANE_Y]; const uint8_t* srcU = output_view.data()[C2PlanarLayout::PLANE_U]; const uint8_t* srcV = output_view.data()[C2PlanarLayout::PLANE_V]; if (!m_f) { - m_f = fopen("/data/local/traces/dec.yuv", "w+"); - MFX_DEBUG_TRACE_MSG("/data/local/traces/dec.yuv: created"); - MFX_DEBUG_TRACE_I64(m_f); - } - if (m_f) { - MFX_DEBUG_TRACE_I64(count); - size_t copied_size = 0; - copied_size = fwrite(srcY, m_mfxVideoParams.mfx.FrameInfo.CropW * m_mfxVideoParams.mfx.FrameInfo.CropH, 1, m_f); - MFX_DEBUG_TRACE_I64(copied_size); - copied_size = fwrite(srcU, m_mfxVideoParams.mfx.FrameInfo.CropW * m_mfxVideoParams.mfx.FrameInfo.CropH / 2, 1, m_f); - MFX_DEBUG_TRACE_I64(copied_size); - count++; + m_f = fopen("/data/local/traces/decoder_frame.yuv", "w+"); + MFX_DEBUG_TRACE_STREAM("/data/local/traces/decoder_frame.yuv: create:" << m_f); } - } else { if (m_f) { - fclose(m_f); - MFX_DEBUG_TRACE_MSG("stang23 dump closed"); - m_f = NULL; + size_t copied_Y = 0, copied_U = 0; + copied_Y = fwrite(srcY, mfx_surface->Data.PitchLow * m_mfxVideoParams.mfx.FrameInfo.CropH, 1, m_f); + copied_U = fwrite(srcU, mfx_surface->Data.PitchLow * m_mfxVideoParams.mfx.FrameInfo.CropH / 2, 1, m_f); + MFX_DEBUG_TRACE_PRINTF("############# dumping #%d decoded buffer in size: %dx%d, Y:%zu, U:%zu #################", + m_count, mfx_surface->Data.PitchLow, m_mfxVideoParams.mfx.FrameInfo.CropH, copied_Y, copied_U); + if (copied_Y > 0 || copied_U > 0) + m_count--; } + } + m_count_lock.unlock(); } + m_count_lock.lock(); + if (m_count == 0 && m_f) { + fclose(m_f); + MFX_DEBUG_TRACE_MSG("dump file is closed"); + m_f = NULL; + } + m_count_lock.unlock(); #endif worklet->output.buffers.push_back(out_buffer);