Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
improve log verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
wongfei committed Oct 28, 2021
1 parent 45a47a7 commit df1e581
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
Binary file added Content/GStreamer/BP_Verbosity.uasset
Binary file not shown.
Binary file modified Content/GStreamer/TestLevel.umap
Binary file not shown.
Binary file modified Content/GStreamer/TestLevel_BuiltData.uasset
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ void FGstAppSrcImpl::PushBuffer(IGstAppSrcBuffer* Buffer)
const GstFlowReturn Result = gst_app_src_push_buffer(GST_APP_SRC(m_AppSrc), BufferObj);
if (Result != GST_FLOW_OK)
{
GST_LOG_ERR_A("GstAppSrc: GstFlowReturn <%s>", gst_flow_get_name(Result));
GST_LOG_ERR_A("gst_app_src_push_buffer failed: GstFlowReturn=%d (%s)", (int)Result, gst_flow_get_name(Result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ void UGstPipelineComponent::StopPipeline()

ResetState();
}

void UGstPipelineComponent::SetVerbosity(int Verbosity)
{
Verbosity = FMath::Clamp<int>(Verbosity, 0, (int)EGstVerbosity::_COUNT - 1);
GstSetVerbosity((EGstVerbosity::Type)Verbosity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class GSTREAMER_API UGstPipelineComponent : public UGstElementComponent
UFUNCTION(Category="GstPipeline", BlueprintCallable)
void StopPipeline();

UFUNCTION(Category="GstPipeline", BlueprintCallable)
static void SetVerbosity(int Verbosity);

protected:

void ResetState();
Expand Down
10 changes: 5 additions & 5 deletions Plugins/GStreamer/Source/GStreamer/Private/GstPipelineImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void ThreadWorkerFunc(FGstPipelineImpl* Context) { Context->WorkerLoop();

bool FGstPipelineImpl::Init(const char* Name, const char* Config)
{
GST_LOG_DBG_A("GstPipeline: Init <%s>", Name);
GST_LOG_INFO_A("GstPipeline: Init <%s>", Name);

if (m_Pipeline)
{
Expand All @@ -66,7 +66,7 @@ bool FGstPipelineImpl::Init(const char* Name, const char* Config)
{
m_Name = Name;

GST_LOG_DBG_A("GstPipeline: gst_parse_launch \"%s\"", Config);
GST_LOG_INFO_A("GstPipeline: gst_parse_launch \"%s\"", Config);
GError* Error = nullptr;
m_Pipeline = gst_parse_launch(Config, &Error);
if (Error)
Expand Down Expand Up @@ -100,7 +100,7 @@ void FGstPipelineImpl::Shutdown()

if (m_Pipeline)
{
GST_LOG_DBG_A("GstPipeline: Shutdown <%s>", m_Name.c_str());
GST_LOG_INFO_A("GstPipeline: Shutdown <%s>", m_Name.c_str());
gst_element_set_state(m_Pipeline, GST_STATE_NULL);
}

Expand All @@ -110,7 +110,7 @@ void FGstPipelineImpl::Shutdown()

bool FGstPipelineImpl::Start()
{
GST_LOG_DBG_A("GstPipeline: Start <%s>", m_Name.c_str());
GST_LOG_INFO_A("GstPipeline: Start <%s>", m_Name.c_str());

if (m_Loop)
{
Expand Down Expand Up @@ -142,7 +142,7 @@ void FGstPipelineImpl::Stop()
{
if (m_Loop)
{
GST_LOG_DBG_A("GstPipeline: Stop <%s>", m_Name.c_str());
GST_LOG_INFO_A("GstPipeline: Stop <%s>", m_Name.c_str());

g_main_loop_quit(m_Loop);

Expand Down
19 changes: 19 additions & 0 deletions Plugins/GStreamer/Source/GStreamer/Private/Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@

#define LOG_BUF_SIZE 2048

static EGstVerbosity::Type _GstVerbosity = EGstVerbosity::Error;

void GstSetVerbosity(EGstVerbosity::Type Verbosity)
{
_GstVerbosity = Verbosity;
}

EGstVerbosity::Type GstGetVerbosity()
{
return _GstVerbosity;
}

static ELogVerbosity::Type ConvertVerbosity(EGstVerbosity::Type GstVerbosity)
{
switch (GstVerbosity)
{
case EGstVerbosity::Error: return ELogVerbosity::Error;
case EGstVerbosity::Warning: return ELogVerbosity::Warning;
case EGstVerbosity::Info: return ELogVerbosity::Display;
case EGstVerbosity::Debug: return ELogVerbosity::Display;
}
return ELogVerbosity::Display;
Expand All @@ -21,6 +34,9 @@ static ELogVerbosity::Type ConvertVerbosity(EGstVerbosity::Type GstVerbosity)
void GstLogA(const char* File, int Line, EGstVerbosity::Type Verbosity, const char* Format, ...)
{
#if !NO_LOGGING
if (Verbosity > _GstVerbosity)
return;

char Buffer[LOG_BUF_SIZE];
va_list Argptr;
va_start(Argptr, Format);
Expand All @@ -39,6 +55,9 @@ void GstLogA(const char* File, int Line, EGstVerbosity::Type Verbosity, const ch
void GstLogW(const char* File, int Line, EGstVerbosity::Type Verbosity, const wchar_t* Format, ...)
{
#if !NO_LOGGING
if (Verbosity > _GstVerbosity)
return;

wchar_t Buffer[LOG_BUF_SIZE];
va_list Argptr;
va_start(Argptr, Format);
Expand Down
24 changes: 16 additions & 8 deletions Plugins/GStreamer/Source/GStreamer/Private/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// CONFIG

//#define GST_ENABLE_DEBUG_LOG
#define GST_ENABLE_DEBUG_LOG

// LOG

Expand All @@ -15,22 +15,30 @@ namespace EGstVerbosity
{
Error = 0,
Warning,
Debug
Info,
Debug,
_COUNT
};
}

#define GST_ERR_VERBOSITY EGstVerbosity::Error
#define GST_DBG_VERBOSITY EGstVerbosity::Debug
void GstSetVerbosity(EGstVerbosity::Type Verbosity);
EGstVerbosity::Type GstGetVerbosity();

void GstLogA(const char* File, int Line, EGstVerbosity::Type Verbosity, const char* Format, ...);
void GstLogW(const char* File, int Line, EGstVerbosity::Type Verbosity, const wchar_t* Format, ...);

#define GST_LOG_ERR_A(format, ...) GstLogA(__FILE__, __LINE__, GST_ERR_VERBOSITY, format, ##__VA_ARGS__)
#define GST_LOG_ERR(format, ...) GstLogW(__FILE__, __LINE__, GST_ERR_VERBOSITY, format, ##__VA_ARGS__)
#define GST_LOG_ERR_A(format, ...) GstLogA(__FILE__, __LINE__, EGstVerbosity::Error, format, ##__VA_ARGS__)
#define GST_LOG_ERR(format, ...) GstLogW(__FILE__, __LINE__, EGstVerbosity::Error, format, ##__VA_ARGS__)

#define GST_LOG_WARN_A(format, ...) GstLogA(__FILE__, __LINE__, EGstVerbosity::Warning, format, ##__VA_ARGS__)
#define GST_LOG_WARN(format, ...) GstLogW(__FILE__, __LINE__, EGstVerbosity::Warning, format, ##__VA_ARGS__)

#define GST_LOG_INFO_A(format, ...) GstLogA(__FILE__, __LINE__, EGstVerbosity::Info, format, ##__VA_ARGS__)
#define GST_LOG_INFO(format, ...) GstLogW(__FILE__, __LINE__, EGstVerbosity::Info, format, ##__VA_ARGS__)

#if defined(GST_ENABLE_DEBUG_LOG)
#define GST_LOG_DBG_A(format, ...) GstLogA(__FILE__, __LINE__, GST_DBG_VERBOSITY, format, ##__VA_ARGS__)
#define GST_LOG_DBG(format, ...) GstLogW(__FILE__, __LINE__, GST_DBG_VERBOSITY, format, ##__VA_ARGS__)
#define GST_LOG_DBG_A(format, ...) GstLogA(__FILE__, __LINE__, EGstVerbosity::Debug, format, ##__VA_ARGS__)
#define GST_LOG_DBG(format, ...) GstLogW(__FILE__, __LINE__, EGstVerbosity::Debug, format, ##__VA_ARGS__)
#else
#define GST_LOG_DBG_A(format, ...)
#define GST_LOG_DBG(format, ...)
Expand Down

0 comments on commit df1e581

Please sign in to comment.