diff --git a/src/AVPlayer.cpp b/src/AVPlayer.cpp index 1b724d9e..c9e8c6dd 100644 --- a/src/AVPlayer.cpp +++ b/src/AVPlayer.cpp @@ -166,6 +166,15 @@ void AVPlayer::setPlayerEventFilter(QObject *obj) } } +Statistics& AVPlayer::statistics() +{ + return mStatistics; +} + +const Statistics& AVPlayer::statistics() const +{ + return mStatistics; +} //TODO: remove? void AVPlayer::resizeRenderer(const QSize &size) { @@ -326,6 +335,7 @@ bool AVPlayer::load() } audio_dec->setCodecContext(aCodecCtx); video_dec->setCodecContext(vCodecCtx); + //TODO: init statistics return loaded; } diff --git a/src/Filter.cpp b/src/Filter.cpp index 4055e3ec..bae43345 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -34,9 +34,10 @@ Filter::~Filter() { } -void Filter::process(FilterContext *context) +void Filter::process(FilterContext *context, Statistics *statistics) { Q_UNUSED(context); + Q_UNUSED(statistics); } void Filter::process(QByteArray &data) @@ -45,7 +46,6 @@ void Filter::process(QByteArray &data) } - void Filter::setEnabled(bool enabled) { DPTR_D(Filter); diff --git a/src/FilterContext.cpp b/src/FilterContext.cpp index 06e72381..305329cb 100644 --- a/src/FilterContext.cpp +++ b/src/FilterContext.cpp @@ -32,10 +32,5 @@ FilterContext::Type QPainterFilterContext::type() const return FilterContext::QtPainter; } -void FilterContext::shareCommonData(FilterContext *other) -{ - -} - } //namespace QtAV diff --git a/src/QtAV/AVPlayer.h b/src/QtAV/AVPlayer.h index b98c9d06..d38b7675 100644 --- a/src/QtAV/AVPlayer.h +++ b/src/QtAV/AVPlayer.h @@ -24,6 +24,7 @@ #include #include +#include namespace QtAV { @@ -76,6 +77,8 @@ public: /*only 1 event filter is available. the previous one will be removed. setPlayerEventFilter(0) will remove the event filter*/ void setPlayerEventFilter(QObject *obj); + Statistics& statistics(); + const Statistics& statistics() const; signals: void started(); void stopped(); @@ -115,6 +118,7 @@ protected: QObject *event_filter; VideoCapture *video_capture; OSDFilter *osd; + Statistics mStatistics; }; } //namespace QtAV diff --git a/src/QtAV/Filter.h b/src/QtAV/Filter.h index 7d5040c6..9344cccc 100644 --- a/src/QtAV/Filter.h +++ b/src/QtAV/Filter.h @@ -35,13 +35,14 @@ class QByteArray; namespace QtAV { class FilterPrivate; +class Statistics; class Q_EXPORT Filter { DPTR_DECLARE_PRIVATE(Filter) public: virtual ~Filter() = 0; //isEnabled() then setContext - virtual void process(FilterContext* context); + virtual void process(FilterContext* context, Statistics* statistics); //TODO: parameter FrameContext void setEnabled(bool enabled); //AVComponent.enabled bool isEnabled() const; diff --git a/src/QtAV/FilterContext.h b/src/QtAV/FilterContext.h index 0b97294b..c6a9a2b5 100644 --- a/src/QtAV/FilterContext.h +++ b/src/QtAV/FilterContext.h @@ -25,7 +25,6 @@ #include #include #include -#include /* * QPainterFilterContext, D2DFilterContext, ... */ @@ -48,10 +47,7 @@ public: }; virtual ~FilterContext(); virtual Type type() const = 0; - void shareCommonData(FilterContext* other); QByteArray data; - //common audio/video info - QTime current_time, total_time; //QPainter, paintdevice, surface etc. contains all of them here? }; diff --git a/src/QtAV/Statistics.h b/src/QtAV/Statistics.h new file mode 100644 index 00000000..5214ba9c --- /dev/null +++ b/src/QtAV/Statistics.h @@ -0,0 +1,113 @@ +/****************************************************************************** + QtAV: Media play library based on Qt and FFmpeg + Copyright (C) 2013 Wang Bin + +* This file is part of QtAV + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +******************************************************************************/ + +#ifndef QTAV_STATISTICS_H +#define QTAV_STATISTICS_H + +#include +#include + +/* + * time unit is s + */ + +namespace QtAV { + +class StatisticsPrivate; +class Q_EXPORT Statistics +{ +public: + Statistics(); + ~Statistics(); + + QString url; + class Common { + public: + Common(); + QString format; + QString codec, codec_long; + //common audio/video info that may be used(visualize) by filters + QTime current_time, total_time, start_time; + qreal bit_rate, avg_frame_rate; //Kps + qint64 frames; + qint64 size; //audio/video stream size + + //union member with ctor, dtor, copy ctor only works in c++11 + /*union { + audio_only audio; + video_only video; + } only;*/ + } audio, video; //init them + + //from AVCodecContext + class AudioOnly { + public: + AudioOnly(); + int sample_rate; ///< samples per second + int channels; ///< number of audio channels + //enum AVSampleFormat sample_fmt; ///< sample format + /** + * Number of samples per channel in an audio frame. + * - decoding: may be set by some decoders to indicate constant frame size + */ + int frame_size; + /** + * Frame counter, set by libavcodec. + * @note the counter is not incremented if encoding/decoding resulted in an error. + */ + int frame_number; + /** + * number of bytes per packet if constant and known or 0 + * Used by some WAV based audio codecs. + */ + int block_align; + //int cutoff; //Audio cutoff bandwidth (0 means "automatic") + //uint64_t channel_layout; + } audio_only; + //from AVCodecContext + class VideoOnly { + public: + //union member with ctor, dtor, copy ctor only works in c++11 + VideoOnly(); + int width, height; + /** + * Bitstream width / height, may be different from width/height if lowres enabled. + * - encoding: unused + * - decoding: Set by user before init if known. Codec should override / dynamically change if needed. + */ + int coded_width, coded_height; + /** + * the number of pictures in a group of pictures, or 0 for intra_only + */ + int gop_size; + //enum AVPixelFormat pix_fmt; //TODO: new enum in QtAV + /** + * Motion estimation algorithm used for video coding. + * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex), + * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific] + */ + //int me_method; + } video_only; +}; + +} //namespace QtAV + +#endif // QTAV_STATISTICS_H diff --git a/src/QtAV/private/AVOutput_p.h b/src/QtAV/private/AVOutput_p.h index 3b26ccc3..3aab9486 100644 --- a/src/QtAV/private/AVOutput_p.h +++ b/src/QtAV/private/AVOutput_p.h @@ -33,12 +33,14 @@ class AVOutput; class AVDecoder; class Filter; class FilterContext; +class Statistics; class Q_EXPORT AVOutputPrivate : public DPtrPrivate { public: AVOutputPrivate(): paused(false) , available(true) + , statistics(0) , filter_context(0) {} virtual ~AVOutputPrivate() { @@ -51,6 +53,9 @@ public: QWaitCondition cond; //pause QByteArray data; + //paintEvent is in main thread, copy it(only dynamic information) is better. + //the static data are copied from AVPlayer when open + Statistics *statistics; FilterContext *filter_context; QList filters; }; diff --git a/src/Statistics.cpp b/src/Statistics.cpp new file mode 100644 index 00000000..372f683f --- /dev/null +++ b/src/Statistics.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** + QtAV: Media play library based on Qt and FFmpeg + Copyright (C) 2013 Wang Bin + +* This file is part of QtAV + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +******************************************************************************/ + +#include "QtAV/Statistics.h" + +namespace QtAV { + +Statistics::Common::Common(): + bit_rate(0) + , avg_frame_rate(0) + , frames(0) + , size(0) +{ +} + +Statistics::AudioOnly::AudioOnly(): + sample_rate(0) + , channels(0) + , frame_size(0) + , frame_number(0) + , block_align(0) +{ +} + +Statistics::VideoOnly::VideoOnly(): + width(0) + , height(0) + , coded_width(0) + , coded_height(0) + , gop_size(0) +{ +} + +Statistics::Statistics() +{ +} + +Statistics::~Statistics() +{ +} + +} //namespace QtAV diff --git a/src/WidgetRenderer.cpp b/src/WidgetRenderer.cpp index cd872869..b57b984a 100644 --- a/src/WidgetRenderer.cpp +++ b/src/WidgetRenderer.cpp @@ -162,6 +162,7 @@ void WidgetRenderer::mouseDoubleClickEvent(QMouseEvent *) void WidgetRenderer::paintEvent(QPaintEvent *) { + //TODO: set QPainter to context; DPTR_D(WidgetRenderer); //begin paint. how about QPainter::beginNativePainting()? //fill background color when necessary, e.g. renderer is resized, image is null @@ -193,9 +194,10 @@ void WidgetRenderer::paintEvent(QPaintEvent *) foreach(Filter* filter, d.filters) { if (!filter) { qWarning("a null filter!"); + //d.filters.removeOne(filter); continue; } - filter->process(d.filter_context); + filter->process(d.filter_context, d.statistics); } } diff --git a/src/libQtAV.pro b/src/libQtAV.pro index e3946c92..ecdfc594 100644 --- a/src/libQtAV.pro +++ b/src/libQtAV.pro @@ -129,6 +129,7 @@ SOURCES += \ WidgetRenderer.cpp \ AVOutput.cpp \ AVClock.cpp \ + Statistics.cpp \ VideoDecoder.cpp \ VideoThread.cpp @@ -163,6 +164,7 @@ SDK_HEADERS *= \ QtAV/VideoThread.h \ QtAV/FactoryDefine.h \ QtAV/ImageConverterTypes.h \ + QtAV/Statistics.h \ QtAV/version.h