Skip to content

Commit

Permalink
add Statistics which can be used by filters
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 29, 2013
1 parent e4cd1bf commit 5ca3bdb
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -326,6 +335,7 @@ bool AVPlayer::load()
}
audio_dec->setCodecContext(aCodecCtx);
video_dec->setCodecContext(vCodecCtx);
//TODO: init statistics
return loaded;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -45,7 +46,6 @@ void Filter::process(QByteArray &data)
}



void Filter::setEnabled(bool enabled)
{
DPTR_D(Filter);
Expand Down
5 changes: 0 additions & 5 deletions src/FilterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,5 @@ FilterContext::Type QPainterFilterContext::type() const
return FilterContext::QtPainter;
}

void FilterContext::shareCommonData(FilterContext *other)
{

}


} //namespace QtAV
4 changes: 4 additions & 0 deletions src/QtAV/AVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QtAV/AVClock.h>
#include <QtAV/AVDemuxer.h>
#include <QtAV/Statistics.h>

namespace QtAV {

Expand Down Expand Up @@ -76,6 +77,8 @@ class Q_EXPORT AVPlayer : public QObject
/*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();
Expand Down Expand Up @@ -115,6 +118,7 @@ protected slots:
QObject *event_filter;
VideoCapture *video_capture;
OSDFilter *osd;
Statistics mStatistics;
};

} //namespace QtAV
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/QtAV/FilterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <QtAV/QtAV_Global.h>
#include <QtCore/QByteArray>
#include <QtCore/QRect>
#include <QtCore/QTime>
/*
* QPainterFilterContext, D2DFilterContext, ...
*/
Expand All @@ -48,10 +47,7 @@ class Q_EXPORT FilterContext
};
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?
};

Expand Down
113 changes: 113 additions & 0 deletions src/QtAV/Statistics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
* 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 changes: 5 additions & 0 deletions src/QtAV/private/AVOutput_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -51,6 +53,9 @@ class Q_EXPORT AVOutputPrivate : public DPtrPrivate<AVOutput>
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;
};
Expand Down
60 changes: 60 additions & 0 deletions src/Statistics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
* 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
4 changes: 3 additions & 1 deletion src/WidgetRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ SOURCES += \
WidgetRenderer.cpp \
AVOutput.cpp \
AVClock.cpp \
Statistics.cpp \
VideoDecoder.cpp \
VideoThread.cpp

Expand Down Expand Up @@ -163,6 +164,7 @@ SDK_HEADERS *= \
QtAV/VideoThread.h \
QtAV/FactoryDefine.h \
QtAV/ImageConverterTypes.h \
QtAV/Statistics.h \
QtAV/version.h


Expand Down

0 comments on commit 5ca3bdb

Please sign in to comment.