Skip to content

Commit

Permalink
fix wrong logging logic etc
Browse files Browse the repository at this point in the history
log level takes affect for ffmpeg and libass log
TODO:
remove qDebug() in headers
  • Loading branch information
wang-bin committed Oct 16, 2014
1 parent b91f136 commit 74cba4b
Show file tree
Hide file tree
Showing 68 changed files with 312 additions and 120 deletions.
5 changes: 3 additions & 2 deletions examples/player/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void Logger(QtMsgType type, const QMessageLogContext &, const QString& qmsg)

int main(int argc, char *argv[])
{
// has no effect if qInstallMessageHandler() called
//qSetMessagePattern("%{function} @%{line}: %{message}");
QApplication a(argc, argv);
if (a.arguments().contains("-h") || a.arguments().contains("--help")) {
qDebug("Usage: %s [-vo qt/gl/d2d/gdi] [url/path]filename", a.applicationFilePath().section(QDir::separator(), -1).toUtf8().constData());
Expand Down Expand Up @@ -184,10 +186,9 @@ int main(int argc, char *argv[])
if (!vd.isEmpty())
window.setVideoDecoderNames(vd);


idx = a.arguments().indexOf("--no-ffmpeg-log");
idxmax = qMax(idx, idxmax);
if (idx < 0)
if (idx > 0)
setFFmpegLogHandler(0);
bool opt_has_file = argc > idxmax+1;
if (opt_has_file) {
Expand Down
4 changes: 2 additions & 2 deletions qml/QmlAV/QQuickItemRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#include <QtAV/VideoRenderer.h>
#include <QtQuick/QQuickItem>

namespace QtAV
{
namespace QtAV {
extern QMLAV_EXPORT VideoRendererId VideoRendererId_QQuickItem;

class QQuickItemRendererPrivate;
Expand Down Expand Up @@ -85,5 +84,6 @@ class QMLAV_EXPORT QQuickItemRenderer : public QQuickItem, public VideoRenderer
};
typedef QQuickItemRenderer VideoRendererQQuickItem;
}
QML_DECLARE_TYPE(QtAV::QQuickItemRenderer)

#endif // QTAV_QML_QQUICKRENDERER_H
1 change: 1 addition & 0 deletions src/AVClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QtAV/AVClock.h>
#include <QtCore/QTimerEvent>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
4 changes: 2 additions & 2 deletions src/AVCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#include <QtAV/private/AVCompat.h>
#include "QtAV/private/AVCompat.h"
#include "QtAV/version.h"
#include "QtAV/prepost.h"

Expand Down Expand Up @@ -68,7 +68,7 @@ void ffmpeg_version_print()
fflush(0);
}

PRE_FUNC_ADD(ffmpeg_version_print);
//PRE_FUNC_ADD(ffmpeg_version_print); //move to Internal::Logger

#ifndef av_err2str

Expand Down
1 change: 1 addition & 0 deletions src/AVDemuxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QtAV/AVThread.h>
#include <QtCore/QTimer>
#include <QtCore/QEventLoop>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
3 changes: 2 additions & 1 deletion src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "QtAV/Packet.h"
#include "QAVIOContext.h"
#include "QtAV/private/AVCompat.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down Expand Up @@ -165,7 +166,7 @@ AVDemuxer::AVDemuxer(const QString& fileName, QObject *parent)
class AVInitializer {
public:
AVInitializer() {
qDebug("av_register_all, avcodec_register_all, avformat_network_init");
//qDebug("av_register_all, avcodec_register_all, avformat_network_init");
avcodec_register_all();
#if QTAV_HAVE(AVDEVICE)
avdevice_register_all();
Expand Down
2 changes: 1 addition & 1 deletion src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "output/OutputSet.h"
#include "output/video/VideoOutputEventFilter.h"
#include "QtAV/private/AVCompat.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down Expand Up @@ -103,7 +104,6 @@ AVPlayer::AVPlayer(QObject *parent) :

mpVOSet = new OutputSet(this);
mpAOSet = new OutputSet(this);
qDebug("%s", aboutQtAV_PlainText().toUtf8().constData());
/*
* call stop() before the window(_renderer) closed to stop the waitcondition
* If close the _renderer widget, the the _renderer may destroy before waking up.
Expand Down
1 change: 1 addition & 0 deletions src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "QtAV/AVOutput.h"
#include "QtAV/Filter.h"
#include "output/OutputSet.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down
5 changes: 3 additions & 2 deletions src/AudioFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
******************************************************************************/

#include "QtAV/AudioFormat.h"
#include <QtCore/QtDebug>
#include "QtAV/private/AVCompat.h"

#ifndef QT_NO_DEBUG_STREAM
#include <QtDebug>
#endif //QT_NO_DEBUG_STREAM
//FF_API_OLD_SAMPLE_FMT. e.g. FFmpeg 0.9
#ifdef SampleFormat
#undef SampleFormat
Expand Down
2 changes: 2 additions & 0 deletions src/AudioResamplerFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "QtAV/private/AudioResampler_p.h"
#include "QtAV/private/AVCompat.h"
#include "QtAV/prepost.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down Expand Up @@ -223,6 +224,7 @@ bool AudioResamplerFF::prepare()
int ret = swr_init(d.context);
if (ret < 0) {
qWarning("swr_init failed: %s", av_err2str(ret));
swr_free(&d.context);
return false;
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/AudioResamplerLibav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "QtAV/private/AudioResampler_p.h"
#include "QtAV/private/AVCompat.h"
#include "QtAV/prepost.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down Expand Up @@ -257,6 +258,7 @@ bool AudioResamplerLibav::prepare()
int ret = swr_init(d.context);
if (ret < 0) {
qWarning("swr_init failed: %s", av_err2str(ret));
swr_free(&d.context);
return false;
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/AudioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "output/OutputSet.h"
#include "QtAV/private/AVCompat.h"
#include <QtCore/QCoreApplication>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "QtAV/Frame.h"
#include "QtAV/private/Frame_p.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/ImageConverterFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "QtAV/private/AVCompat.h"
#include "QtAV/private/mkid.h"
#include "QtAV/prepost.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/ImageConverterIPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#else

#endif
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/OpenGLVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "QtAV/SurfaceInterop.h"
#include "QtAV/VideoShader.h"
#include "ShaderManager.h"
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
******************************************************************************/

#include <QtAV/Packet.h>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/QAVIOContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "QAVIOContext.h"
#include "QtAV/private/AVCompat.h"
#include <QtCore/QIODevice>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
2 changes: 1 addition & 1 deletion src/QtAV/AVClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ double AVClock::value() const
if (timer.isValid()) {
pts_ += double(timer.restart()) * kThousandth;
} else {//timer is paused
qDebug("clock is paused. return the last value %f", pts_);
//qDebug("clock is paused. return the last value %f", pts_);
}
return pts_ * speed() + value0;
}
Expand Down
21 changes: 10 additions & 11 deletions src/QtAV/QtAV_Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ Q_AV_EXPORT QString QtAV_Version_String_Long();
namespace QtAV {

enum LogLevel {
LogOff = -1,
LogDefault = 0,
LogDebug,
LogWarning,
LogCritical,
LogFatal,
LogOff,
LogDebug, // log all
LogWarning, // log warning, critical, fatal
LogCritical, // log critical, fatal
LogFatal, // log fatal
LogAll
};

Expand All @@ -61,6 +60,11 @@ Q_AV_EXPORT void aboutQtAV();
Q_AV_EXPORT QString aboutQtAV_PlainText();
Q_AV_EXPORT QString aboutQtAV_HTML();

/*!
* The level can also be changed at runtime by setting the QTAV_LOG_LEVEL environment variable;
* QTAV_LOG_LEVEL can be: off, debug, warning, critical, fatal, all. Or use their enum values
* if both setLogLevel() is called and QTAV_LOG_LEVEL is set, the environment variable takes preceden.
*/
Q_AV_EXPORT void setLogLevel(LogLevel value);
Q_AV_EXPORT LogLevel logLevel();

Expand Down Expand Up @@ -104,10 +108,5 @@ Q_AV_EXPORT void setFFmpegLogHandler(void(*)(void *, int, const char *, va_list)
#define Q_FUNC_INFO __FUNCTION__
#endif

#if defined(BUILD_QTAV_LIB)
#include "utils/Logger.h"
//#undef qDebug()
#endif //BUILD_QTAV_LIB

#endif // QTAV_GLOBAL_H

1 change: 1 addition & 0 deletions src/QtAV/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Q_AV_EXPORT Statistics
qreal pts() const; // last pts
// compute from pts history
qreal currentDisplayFPS() const;
//http://ffmpeg.org/faq.html#AVStream_002er_005fframe_005frate-is-wrong_002c-it-is-much-larger-than-the-frame-rate_002e
//AVStream.avg_frame_rate may be 0, then use AVStream.r_frame_rate
//http://libav-users.943685.n4.nabble.com/Libav-user-Reading-correct-frame-rate-fps-of-input-video-td4657666.html
qreal fps_guess;
Expand Down
40 changes: 20 additions & 20 deletions src/QtAV_Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "QtAV/QtAV_Global.h"
#include <QtCore/QObject>
#include <QtCore/QRegExp>
#include <QtDebug>
#if QTAV_HAVE(WIDGETS)
#include <QBoxLayout>
#include <QMessageBox>
Expand All @@ -32,13 +31,7 @@
#endif //QTAV_HAVE(WIDGETS)
#include "QtAV/version.h"
#include "QtAV/private/AVCompat.h"

// disable logging for release. you can manually enable it.
#ifdef QT_NO_DEBUG
static QtAV::LogLevel gLogLevel = QtAV::LogOff;
#else
static QtAV::LogLevel gLogLevel = QtAV::LogAll;
#endif
#include "utils/Logger.h"

unsigned QtAV_Version()
{
Expand All @@ -57,6 +50,17 @@ QString QtAV_Version_String_Long()

namespace QtAV {

namespace Internal {
// disable logging for release. you can manually enable it.
#ifdef QT_NO_DEBUG
static QtAV::LogLevel gLogLevel = QtAV::LogOff;
#else
static QtAV::LogLevel gLogLevel = QtAV::LogAll;
#endif
static bool gLogLevelSet = false;
bool isLogLevelSet() { return gLogLevelSet;}
} //namespace Internal

//TODO: auto add new depend libraries information
void about()
{
Expand Down Expand Up @@ -183,12 +187,13 @@ QString aboutQtAV_HTML()

void setLogLevel(LogLevel value)
{
gLogLevel = value;
Internal::gLogLevelSet = true;
Internal::gLogLevel = value;
}

LogLevel logLevel()
{
return (LogLevel)gLogLevel;
return (LogLevel)Internal::gLogLevel;
}

void setFFmpegLogHandler(void (*callback)(void *, int, const char *, va_list))
Expand All @@ -203,19 +208,14 @@ static void qtav_ffmpeg_log_callback(void* , int level,const char* fmt, va_list
{
QString qmsg = "{FFmpeg} " + QString().vsprintf(fmt, vl);
qmsg = qmsg.trimmed();
QtMsgType mt = QtDebugMsg;
if (level == AV_LOG_WARNING || level == AV_LOG_ERROR)
mt = QtWarningMsg;
qWarning() << qmsg;
else if (level == AV_LOG_FATAL)
mt = QtCriticalMsg;
qFatal("%s", qmsg.toUtf8().constData());
else if (level == AV_LOG_PANIC)
mt = QtFatalMsg;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QMessageLogContext ctx;
qt_message_output(mt, ctx, qmsg);
#else
qt_message_output(mt, qPrintable(qmsg));
#endif //QT_VERSION
qFatal("%s", qmsg.toUtf8().constData());
else
qDebug() << qmsg;
}

// TODO: static link. move all into 1
Expand Down
1 change: 1 addition & 0 deletions src/VideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QtCore/QRunnable>
#include <QtCore/QThreadPool>
#include <QtGui/QImage>
#include "utils/Logger.h"

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QDesktopServices>
Expand Down
5 changes: 3 additions & 2 deletions src/VideoFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
******************************************************************************/

#include "QtAV/VideoFormat.h"
#include <QtCore/QtDebug>
#include <QtCore/QVector>

#ifndef QT_NO_DEBUG_STREAM
#include <QtDebug>
#endif
#include "QtAV/private/AVCompat.h"
extern "C" {
#include <libavutil/imgutils.h>
Expand Down
1 change: 1 addition & 0 deletions src/VideoShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cmath>
#include <QtCore/QCoreApplication>
#include <QtCore/QFile>
#include "utils/Logger.h"

/*
* TODO: glActiveTexture for Qt4
Expand Down
1 change: 1 addition & 0 deletions src/VideoThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "output/OutputSet.h"
#include "QtAV/private/AVCompat.h"
#include <QtCore/QFileInfo>
#include "utils/Logger.h"

namespace QtAV {

Expand Down
2 changes: 1 addition & 1 deletion src/codec/AVDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <QtAV/AVDecoder.h>
#include <QtAV/private/AVDecoder_p.h>
#include <QtAV/version.h>
#include <QtDebug>
#include "utils/Logger.h"

namespace QtAV {
AVDecoder::AVDecoder()
Expand Down
Loading

0 comments on commit 74cba4b

Please sign in to comment.