Skip to content

Commit

Permalink
[c2][encoder] Support dump input frames for encoder
Browse files Browse the repository at this point in the history
Tracked-On: OAM-124732
Signed-off-by: Lina Sun <[email protected]>
  • Loading branch information
lsun30 committed Sep 14, 2024
1 parent a071ad9 commit 7236faa
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
7 changes: 7 additions & 0 deletions c2_components/include/mfx_c2_encoder_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ class MfxC2EncoderComponent : public MfxC2Component
// Input frame info with width or height not 16byte aligned
mfxFrameInfo m_mfxInputInfo;

#if MFX_DEBUG_DUMP_FRAME_ENC == MFX_DEBUG_YES
int m_count = 0;
std::mutex m_count_lock;
FILE* m_file = 0;
bool NeedDumpBuffer();
#endif

/* -----------------------C2Parameters--------------------------- */
std::mutex m_c2ParameterMutex;
std::shared_ptr<C2ComponentNameSetting> m_name;
Expand Down
77 changes: 77 additions & 0 deletions c2_components/src/mfx_c2_encoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,43 @@ c2_status_t MfxC2EncoderComponent::ApplyWorkTunings(C2Work& work)
return res;
}

#if MFX_DEBUG_DUMP_FRAME_ENC == MFX_DEBUG_YES
#include <cutils/properties.h>
#include <iostream>
#include <sstream>

bool MfxC2EncoderComponent::NeedDumpBuffer() {
MFX_DEBUG_TRACE_FUNC;
const char* key = "mediacodec2.encoder.dump.buffer";
char* value = new char[20];
int len = property_get(key, value, "0");

std::stringstream strValue;
strValue << value;

unsigned int frame_number = 0;
strValue >> frame_number;

m_count_lock.lock();
if (m_count) {
delete[] value;
m_count_lock.unlock();
return true;
} else {
delete[] value;
if (len > 0 && frame_number > 0) {
m_count = frame_number;
MFX_DEBUG_TRACE_PRINTF("--------encoder triggered to dump %d buffers---------", frame_number);
property_set(key, "0");
m_count_lock.unlock();
return true;
}
m_count_lock.unlock();
return false;
}
}
#endif

void MfxC2EncoderComponent::DoWork(std::unique_ptr<C2Work>&& work)
{
MFX_DEBUG_TRACE_FUNC;
Expand Down Expand Up @@ -1363,6 +1400,46 @@ void MfxC2EncoderComponent::DoWork(std::unique_ptr<C2Work>&& work)
}
}

#if MFX_DEBUG_DUMP_FRAME_ENC == MFX_DEBUG_YES
if (MFX_IOPATTERN_IN_SYSTEM_MEMORY == m_mfxVideoParamsConfig.IOPattern &&
MFX_FOURCC_NV12 == m_mfxVideoParamsState.mfx.FrameInfo.FourCC &&
NeedDumpBuffer()) {
std::unique_ptr<const C2GraphicView> c_graph_view;
std::unique_ptr<C2ConstGraphicBlock> c_graph_block;

res = GetC2ConstGraphicBlock(input, &c_graph_block);
MapConstGraphicBlock(*c_graph_block, TIMEOUT_NS, &c_graph_view);

m_count_lock.lock();
if (m_count) {
const uint8_t* srcY = c_graph_view->data()[C2PlanarLayout::PLANE_Y];
const uint8_t* srcU = c_graph_view->data()[C2PlanarLayout::PLANE_U];
const uint8_t* srcV = c_graph_view->data()[C2PlanarLayout::PLANE_V];
if (!m_file) {
m_file = fopen("/data/local/traces/encoder_frame.yuv", "w+");
MFX_DEBUG_TRACE_STREAM("/data/local/traces/encoder_frame.yuv: create:" << m_file);
}
if (m_file) {
size_t copied_Y = 0, copied_U = 0;
copied_Y = fwrite(srcY, c_graph_block->width() * c_graph_block->height(), 1, m_file);
copied_U = fwrite(srcU, c_graph_block->width() * c_graph_block->height() / 2, 1, m_file);
MFX_DEBUG_TRACE_PRINTF("############# dumping #%d encoder input buffer in size: %dx%d, Y:%zu, U:%zu #################",
m_count, c_graph_block->width(), c_graph_block->height(), 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_file) {
fclose(m_file);
MFX_DEBUG_TRACE_MSG("encoder dump file is closed");
m_file = NULL;
}
m_count_lock.unlock();
#endif

std::shared_ptr<MfxFrameConverter> frame_converter;
if (m_mfxVideoParamsConfig.IOPattern == MFX_IOPATTERN_IN_VIDEO_MEMORY) {
frame_converter = m_device->GetFrameConverter();
Expand Down
4 changes: 3 additions & 1 deletion c2_utils/include/mfx_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#define MFX_DEBUG MFX_DEBUG_NO // 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
#define MFX_DEBUG_DUMP_FRAME MFX_DEBUG_NO // enables write decoder output frame to file
// enables write encoder input frame to file, currently only support NV12 format frame dump
#define MFX_DEBUG_DUMP_FRAME_ENC MFX_DEBUG_NO

#define MFX_DEBUG_FILE MFX_DEBUG_NO // sends DEBUG and PERF output to file, otherwise to logcat

Expand Down

0 comments on commit 7236faa

Please sign in to comment.