Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For debugging R2, no need to merge or review #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions c2_components/include/mfx_c2_decoder_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "mfx_c2_color_aspects_wrapper.h"
#include "mfx_c2_setters.h"

#include <cutils/properties.h>

#define MAX_DUMP_BUFFER 200

class MfxC2DecoderComponent : public MfxC2Component
{
public:
Expand Down Expand Up @@ -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<C2ComponentNameSetting> m_name;
std::shared_ptr<C2ComponentKindSetting> m_kind;
Expand Down
81 changes: 74 additions & 7 deletions c2_components/src/mfx_c2_decoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,45 @@ void MfxC2DecoderComponent::Drain(std::unique_ptr<C2Work>&& 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 <iostream>
#include <sstream>

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;
Expand Down Expand Up @@ -2277,13 +2316,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<std::string>({}),"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<C2Work> work;
Expand Down Expand Up @@ -2392,6 +2424,41 @@ void MfxC2DecoderComponent::WaitWork(MfxC2FrameOut&& frame_out, mfxSyncPoint syn
}
m_updatingC2Configures.clear();

//#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/decoder_frame.yuv", "w+");
MFX_DEBUG_TRACE_STREAM("/data/local/traces/decoder_frame.yuv: create:" << m_f);
}
if (m_f) {
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);
block = nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion c2_utils/include/mfx_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down