add Statistics which can be used by filters

This commit is contained in:
wang-bin
2013-04-29 22:56:28 +08:00
parent e4cd1bf721
commit 5ca3bdbef5
11 changed files with 201 additions and 13 deletions
+10
View File
@@ -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;
}
+2 -2
View File
@@ -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);
-5
View File
@@ -32,10 +32,5 @@ FilterContext::Type QPainterFilterContext::type() const
return FilterContext::QtPainter;
}
void FilterContext::shareCommonData(FilterContext *other)
{
}
} //namespace QtAV
+4
View File
@@ -24,6 +24,7 @@
#include <QtAV/AVClock.h>
#include <QtAV/AVDemuxer.h>
#include <QtAV/Statistics.h>
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
+2 -1
View File
@@ -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;
-4
View File
@@ -25,7 +25,6 @@
#include <QtAV/QtAV_Global.h>
#include <QtCore/QByteArray>
#include <QtCore/QRect>
#include <QtCore/QTime>
/*
* 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?
};
+113
View File
@@ -0,0 +1,113 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <wbsecg1@gmail.com>
* 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 <QtAV/QtAV_Global.h>
#include <QtCore/QTime>
/*
* 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
+5
View File
@@ -33,12 +33,14 @@ class AVOutput;
class AVDecoder;
class Filter;
class FilterContext;
class Statistics;
class Q_EXPORT AVOutputPrivate : public DPtrPrivate<AVOutput>
{
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<Filter*> filters;
};
+60
View File
@@ -0,0 +1,60 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <wbsecg1@gmail.com>
* 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
+3 -1
View File
@@ -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);
}
}
+2
View File
@@ -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