Skip to content

Commit

Permalink
virtual onXXX in AVOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Mar 22, 2014
1 parent a81ebdf commit 8f12354
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 25 deletions.
38 changes: 37 additions & 1 deletion src/AVOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,41 @@ bool AVOutput::tryPause()
}

void AVOutput::addOutputSet(OutputSet *set)
{
onAddOutputSet(set);
}

void AVOutput::onAddOutputSet(OutputSet *set)
{
d_func().output_sets.append(set);
}

void AVOutput::removeOutputSet(OutputSet *set)
{
onRemoveOutputSet(set);
}

void AVOutput::onRemoveOutputSet(OutputSet *set)
{
d_func().output_sets.removeAll(set);
}

void AVOutput::attach(OutputSet *set)
{
onAttach(set);
}

void AVOutput::onAttach(OutputSet *set)
{
set->addOutput(this);
}

void AVOutput::detach(OutputSet *set)
{
onDetach(set);
}

void AVOutput::onDetach(OutputSet *set)
{
DPTR_D(AVOutput);
if (set) {
Expand Down Expand Up @@ -128,6 +148,11 @@ void AVOutput::setStatistics(Statistics *statistics)
}

bool AVOutput::installFilter(Filter *filter)
{
onInstallFilter(filter);
}

bool AVOutput::onInstallFilter(Filter *filter)
{
if (!FilterManager::instance().registerFilter(filter, this)) {
return false;
Expand All @@ -142,6 +167,11 @@ bool AVOutput::installFilter(Filter *filter)
* an audio filter on audio output may be in audio thread
*/
bool AVOutput::uninstallFilter(Filter *filter)
{
onUninstallFilter(filter);
}

bool AVOutput::onUninstallFilter(Filter *filter)
{
if (!FilterManager::instance().unregisterFilter(filter)) {
qWarning("unregister filter %p failed", filter);
Expand All @@ -153,16 +183,22 @@ bool AVOutput::uninstallFilter(Filter *filter)
}

void AVOutput::hanlePendingTasks()
{
onHanlePendingTasks();
}

bool AVOutput::onHanlePendingTasks()
{
DPTR_D(AVOutput);
if (d.pending_uninstall_filters.isEmpty())
return;
return false;
foreach (Filter *filter, d.pending_uninstall_filters) {
d.filters.removeAll(filter);
//QMetaObject::invokeMethod(FilterManager::instance(), "onUninstallInTargetDone", Qt::AutoConnection, Q_ARG(Filter*, filter));
FilterManager::instance().emitOnUninstallInTargetDone(filter);
}
d.pending_uninstall_filters.clear();
return true;
}

} //namespace QtAV
2 changes: 1 addition & 1 deletion src/OutputSet.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 Wang Bin <[email protected]>
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down
12 changes: 11 additions & 1 deletion src/QtAV/AVOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ class Q_AV_EXPORT AVOutput
DPTR_DECLARE(AVOutput)

private:
void setStatistics(Statistics* statistics);
// for proxy VideoOutput
virtual void setStatistics(Statistics* statistics); //called by friend AVPlayer
virtual bool onInstallFilter(Filter *filter);
virtual bool onUninstallFilter(Filter *filter);
virtual void onAddOutputSet(OutputSet *set);
virtual void onRemoveOutputSet(OutputSet *set);
virtual void onAttach(OutputSet *set); //add this to set
virtual void onDetach(OutputSet *set = 0); //detatch from (all, if 0) output set(s)
// only called in handlePaintEvent. But filters may change. so required by proxy to update it's filters
virtual bool onHanlePendingTasks(); //return true: proxy update filters
friend class AVPlayer;
friend class OutputSet;
friend class VideoOutput;
};

} //namespace QtAV
Expand Down
51 changes: 31 additions & 20 deletions src/QtAV/VideoOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,27 @@ class Q_AV_EXPORT VideoOutput : public QObject, public VideoRenderer
QWidget* widget();
QGraphicsItem* graphicsItem();

private:
signals:
void brightnessChanged(qreal value);
void contrastChanged(qreal value);
void hueChanged(qreal value);
void saturationChanged(qreal value);

protected:
bool receiveFrame(const VideoFrame& frame);
bool needUpdateBackground() const;
void drawBackground();
bool needDrawFrame() const; //not important.
void drawFrame();
void resizeFrame(int width, int height);
void handlePaintEvent();
bool onChangingBrightness(qreal b);
bool onChangingContrast(qreal c);
bool onChangingHue(qreal h);
bool onChangingSaturation(qreal s);


private: //for proxy
/*!
* \brief setPreferredPixelFormat
* \param pixfmt
Expand All @@ -77,27 +97,18 @@ class Q_AV_EXPORT VideoOutput : public QObject, public VideoRenderer
virtual bool onSetHue(qreal hue);
virtual bool onSetSaturation(qreal saturation);

signals:
void brightnessChanged(qreal value);
void contrastChanged(qreal value);
void hueChanged(qreal value);
void saturationChanged(qreal value);
void setInSize(int width, int height); //private? for internal use only, called by VideoThread.

protected:
bool receiveFrame(const VideoFrame& frame);
bool needUpdateBackground() const;
void drawBackground();
bool needDrawFrame() const; //not important.
void drawFrame();
void resizeFrame(int width, int height);
void handlePaintEvent();
bool onChangingBrightness(qreal b);
bool onChangingContrast(qreal c);
bool onChangingHue(qreal h);
bool onChangingSaturation(qreal s);
// from AVOutput
virtual void setStatistics(Statistics* statistics); //called by friend AVPlayer
virtual bool onInstallFilter(Filter *filter);
virtual bool onUninstallFilter(Filter *filter);
virtual void onAddOutputSet(OutputSet *set);
virtual void onRemoveOutputSet(OutputSet *set);
virtual void onAttach(OutputSet *set); //add this to set
virtual void onDetach(OutputSet *set = 0); //detatch from (all, if 0) output set(s)
virtual bool onHanlePendingTasks();

private:
void setInSize(int width, int height); //private? for internal use only, called by VideoThread.
};

} //namespace QtAV
Expand Down
77 changes: 75 additions & 2 deletions src/VideoOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include "QtAV/VideoOutput.h"
#include "QtAV/private/VideoRenderer_p.h"
#include "QtAV/VideoRendererTypes.h"
#include "QtAV/OSDFilter.h"

/*!
* onSetXXX(...): impl->onSetXXX(...); set value as impl; return ;
*/

namespace QtAV {

Expand All @@ -32,6 +37,12 @@ class VideoOutputPrivate : public VideoRendererPrivate
impl = VideoRendererFactory::create(rendererId);
// assert not null?
available = !!impl;
if (!available)
return;
// set members as impl's that may be already set in ctor
osd_filter = impl->osdFilter();
subtitle_filter = impl->subtitleFilter();
filters = impl->filters();
}
~VideoOutputPrivate() {
if (impl) {
Expand Down Expand Up @@ -262,13 +273,19 @@ QPointF VideoOutput::onMapFromFrame(const QPointF& p) const
OSDFilter* VideoOutput::onSetOSDFilter(OSDFilter *filter)
{
DPTR_D(VideoOutput);
return d.impl->onSetOSDFilter(filter);
OSDFilter* old = d.impl->onSetOSDFilter(filter);
d.osd_filter = d.impl->osdFilter();
d.filters = d.impl->filters();
return old;
}

Filter* VideoOutput::onSetSubtitleFilter(Filter *filter)
{
DPTR_D(VideoOutput);
return d.impl->onSetSubtitleFilter(filter);
Filter* old = d.impl->onSetSubtitleFilter(filter);
d.subtitle_filter = d.impl->subtitleFilter();
d.filters = d.impl->filters();
return old;
}

bool VideoOutput::onSetBrightness(qreal brightness)
Expand Down Expand Up @@ -320,4 +337,60 @@ void VideoOutput::setInSize(int width, int height)
//d.update_background = d.impl->
}

void VideoOutput::setStatistics(Statistics* statistics)
{
DPTR_D(VideoOutput);
d.impl->setStatistics(statistics);
// only used internally for AVOutput
//d.statistics =
}

bool VideoOutput::onInstallFilter(Filter *filter)
{
DPTR_D(VideoOutput);
d.impl->onInstallFilter(filter);
d.filters = d.impl->filters();
}

bool VideoOutput::onUninstallFilter(Filter *filter)
{
DPTR_D(VideoOutput);
d.impl->onUninstallFilter(filter);
// only used internally for AVOutput
//d.pending_uninstall_filters =
}

void VideoOutput::onAddOutputSet(OutputSet *set)
{
DPTR_D(VideoOutput);
d.impl->onAddOutputSet(set);
}

void VideoOutput::onRemoveOutputSet(OutputSet *set)
{
DPTR_D(VideoOutput);
d.impl->onRemoveOutputSet(set);
}

void VideoOutput::onAttach(OutputSet *set)
{
DPTR_D(VideoOutput);
d.impl->onAttach(set);
}

void VideoOutput::onDetach(OutputSet *set)
{
DPTR_D(VideoOutput);
d.impl->onDetach(set);
//d.output_sets = d.impl->
}

bool VideoOutput::onHanlePendingTasks()
{
DPTR_D(VideoOutput);
if (!d.impl->onHanlePendingTasks())
return false;
d.filters = d.impl->filters();
}

} //namespace QtAV

0 comments on commit 8f12354

Please sign in to comment.