Skip to content

Commit

Permalink
sView - add --avlog=LEVEL argument to setup FFmpeg log callback
Browse files Browse the repository at this point in the history
  • Loading branch information
gkv311 committed Jan 17, 2025
1 parent b4ea6a3 commit 1849b3f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
26 changes: 26 additions & 0 deletions StCore/StApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

#include "StEventsBuffer.h"

namespace stAV
{
ST_CPPIMPORT bool init(int theLogLevel);
}

namespace {

static const StCString ST_SETTING_RENDERER_AUTO = stCString("rendererPluginAuto");
Expand Down Expand Up @@ -541,6 +546,7 @@ StHandle<StOpenInfo> StApplication::parseProcessArguments() {
const StString ARGUMENT_LEFT_VIEW = "left";
const StString ARGUMENT_RIGHT_VIEW = "right";
const StString ARGUMENT_DEMO = "demo";
const StString ARGUMENT_AVLOG = "avlog";
// parse extra parameters
for(size_t aParamIter = 1; aParamIter < anArguments.size(); ++aParamIter) {
StString aParam = anArguments[aParamIter];
Expand Down Expand Up @@ -578,6 +584,26 @@ StHandle<StOpenInfo> StApplication::parseProcessArguments() {
anArg.setValue(aFilePath);
anInfo->setPath(aFilePath);
anOpenFileArgs.add(anArg);
} else if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_AVLOG)) {
int aLevel = 0;
if (anArg.getValue().isEquals(stCString("0"))
|| anArg.getValue().isEqualsIgnoreCase(stCString("off"))) {
aLevel = 0;
} else if (anArg.getValue().isEquals(stCString("1"))
|| anArg.getValue().isEqualsIgnoreCase(stCString("on"))) {
aLevel = 1;
} else if (anArg.getValue().isEquals(stCString("2"))
|| anArg.getValue().isEqualsIgnoreCase(stCString("trace"))
|| anArg.getValue().isEqualsIgnoreCase(stCString("verbose"))) {
aLevel = 2;
} else if (anArg.getValue().isEquals(stCString("-1"))
|| anArg.getValue().isEqualsIgnoreCase(stCString("auto"))) {
aLevel = -1;
} else {
stErrorConsole(StString("Syntax error at '") + aParam + "'");
return NULL;
}
stAV::init(aLevel);
} else {
// pass argument unchanged
anOpenFileArgs.add(anArg);
Expand Down
30 changes: 19 additions & 11 deletions StShared/stAV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,22 @@ StCString stAV::PIX_FMT::getString(const AVPixelFormat theFrmt) {

namespace {

#if defined(ST_DEBUG_FFMPEG) || defined(ST_DEBUG_FFMPEG_VERBOSE)
static int ST_FFMPEG_DEBUG_LEVEL =
#if defined(ST_DEBUG_FFMPEG_VERBOSE)
2;
#elif defined(ST_DEBUG_FFMPEG)
1;
#else
0;
#endif

/**
* Logger callback.
*/
static void stAvLogCallback(void* thePtr, int theLevel, const char* theFormat, va_list theArgs) {
#if !defined(ST_DEBUG_FFMPEG_VERBOSE)
if(theLevel > AV_LOG_INFO) {
if(ST_FFMPEG_DEBUG_LEVEL < 2 && theLevel > AV_LOG_INFO) {
return;
}
#endif

//static int aPrintPrefix = 1;
int aPrintPrefix = 1;
Expand All @@ -202,15 +208,17 @@ namespace {

StLogger::GetDefault().write(StString(aLine), aLevelSt);
}
#endif

static bool initOnce() {
static bool initOnce(int theLogLevel) {
avformat_network_init();
ST_DEBUG_LOG("FFmpeg initialized:");

#if defined(ST_DEBUG_FFMPEG) || defined(ST_DEBUG_FFMPEG_VERBOSE)
av_log_set_callback(stAvLogCallback);
#endif
if (theLogLevel != -1) {
ST_FFMPEG_DEBUG_LEVEL = theLogLevel;
}
if (ST_FFMPEG_DEBUG_LEVEL > 0) {
av_log_set_callback(&stAvLogCallback);
}

// show up information about dynamically linked libraries
ST_DEBUG_LOG(" libavutil\t" + stAV::Version::libavutil().toString());
Expand All @@ -223,8 +231,8 @@ namespace {

}

bool stAV::init() {
static const bool isFFmpegInitiailed = initOnce();
bool stAV::init(int theLogLevel) {
static const bool isFFmpegInitiailed = initOnce(theLogLevel);
return isFFmpegInitiailed;
}

Expand Down
2 changes: 1 addition & 1 deletion include/StAV/stAV.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace stAV {
/**
* Should be called at application start.
*/
ST_CPPEXPORT bool init();
ST_CPPEXPORT bool init(int theLogLevel = -1);

/**
* Returns string description for AVError code.
Expand Down
1 change: 1 addition & 0 deletions sview/StMultiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static StString getAbout() {
+ st::formatToString(StFormat_FrameSequence) + "\n"
+ " --left=PATH Specify source for left view\n"
" --right=PATH Specify source for right view\n"
" --avlog=LEVEL Specify log level for FFmpeg library (0: off, 1: on, 2: verbose)\n"
" --webuiCmdPort=PORT Use http://localhost:PORT for remote control (see --invokeAction).\n"
" --invokeAction=ACT Invoke action on http://localhost:PORT.\n"
" play - play/pause\n"
Expand Down

0 comments on commit 1849b3f

Please sign in to comment.