diff --git a/src/QtAV/VideoOutput.h b/src/QtAV/VideoOutput.h index 7c8edbeb..945834ab 100644 --- a/src/QtAV/VideoOutput.h +++ b/src/QtAV/VideoOutput.h @@ -42,41 +42,40 @@ public: ~VideoOutput(); VideoRendererId id() const; - bool receive(const VideoFrame& frame); //has default + virtual bool receive(const VideoFrame& frame); //has default //void setVideoFormat(const VideoFormat& format); //has default + + VideoFormat::PixelFormat preferredPixelFormat() const; + bool isSupported(VideoFormat::PixelFormat pixfmt) const; + bool open(); + bool close(); + QWidget* widget(); + QGraphicsItem* graphicsItem(); + +private: /*! * \brief setPreferredPixelFormat * \param pixfmt * pixfmt will be used if decoded format is not supported by this renderer. otherwise, use decoded format. * return false if \a pixfmt is not supported and not changed. */ - bool setPreferredPixelFormat(VideoFormat::PixelFormat pixfmt); //has default - VideoFormat::PixelFormat preferredPixelFormat() const; - void forcePreferredPixelFormat(bool force = true); //has default - bool isSupported(VideoFormat::PixelFormat pixfmt) const; - void scaleInRenderer(bool q); //has default - void setOutAspectRatioMode(OutAspectRatioMode mode); //has default - void setOutAspectRatio(qreal ratio); //has default - void setQuality(Quality q); //has default - bool open(); - bool close(); - void resizeRenderer(int width, int height); //has default - void setRegionOfInterest(const QRectF& roi); //has default - QPointF mapToFrame(const QPointF& p) const; //has default - QPointF mapFromFrame(const QPointF& p) const; //has default - QWidget* widget(); - QGraphicsItem* graphicsItem(); + virtual bool onSetPreferredPixelFormat(VideoFormat::PixelFormat pixfmt); + virtual void onForcePreferredPixelFormat(bool force = true); + virtual void onScaleInRenderer(bool q); + virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode); + virtual void onSetOutAspectRatio(qreal ratio); + virtual void onSetQuality(Quality q); + virtual void onResizeRenderer(int width, int height); + virtual void onSetRegionOfInterest(const QRectF& roi); + virtual QPointF onMapToFrame(const QPointF& p) const; + virtual QPointF onMapFromFrame(const QPointF& p) const; + virtual OSDFilter* onSetOSDFilter(OSDFilter *filter); + virtual Filter* onSetSubtitleFilter(Filter *filter); - //TODO: enable/disable = new a default for this vo engine or push back/remove from list - //filter: null means disable - //return the old filter. you may release the ptr manually - OSDFilter* setOSDFilter(OSDFilter *filter); //has default - Filter* setSubtitleFilter(Filter *filter); //has default - void enableDefaultEventFilter(bool e); //has default - bool setBrightness(qreal brightness); //has default - bool setContrast(qreal contrast); //has default - bool setHue(qreal hue); //has default - bool setSaturation(qreal saturation); //has default + virtual bool onSetBrightness(qreal brightness); + virtual bool onSetContrast(qreal contrast); + virtual bool onSetHue(qreal hue); + virtual bool onSetSaturation(qreal saturation); signals: void brightnessChanged(qreal value); diff --git a/src/QtAV/VideoRenderer.h b/src/QtAV/VideoRenderer.h index 6b155363..121feef4 100644 --- a/src/QtAV/VideoRenderer.h +++ b/src/QtAV/VideoRenderer.h @@ -43,8 +43,8 @@ /*! * A bridge for VideoOutput(QObject based) and video renderer backend classes - * All setters are virtual, with default behavior used by backend. - * While VideoOutput simply calls backend one and set the value from it. + * Every public setter call it's virtual onSetXXX(...) which has default behavior. + * While VideoOutput simply calls backend onSetXXX(...) and set the value from it. */ struct AVCodecContext; struct AVFrame; @@ -95,32 +95,32 @@ public: * pixfmt will be used if decoded format is not supported by this renderer. otherwise, use decoded format. * return false if \a pixfmt is not supported and not changed. */ - virtual bool setPreferredPixelFormat(VideoFormat::PixelFormat pixfmt); //has default + bool setPreferredPixelFormat(VideoFormat::PixelFormat pixfmt); /*! * \brief preferredPixelFormat * \return preferred pixel format. e.g. WidgetRenderer is rgb formats. */ - virtual VideoFormat::PixelFormat preferredPixelFormat() const; + virtual VideoFormat::PixelFormat preferredPixelFormat() const; //virtual? /*! * \brief forcePreferredPixelFormat * force to use preferredPixelFormat() even if incoming format is supported * \param force */ - virtual void forcePreferredPixelFormat(bool force = true); //has default + void forcePreferredPixelFormat(bool force = true); bool isPreferredPixelFormatForced() const; virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const = 0; //for testing performance - virtual void scaleInRenderer(bool q); //has default + void scaleInRenderer(bool q); bool scaleInRenderer() const; - virtual void setOutAspectRatioMode(OutAspectRatioMode mode); //has default + void setOutAspectRatioMode(OutAspectRatioMode mode); OutAspectRatioMode outAspectRatioMode() const; //If setOutAspectRatio(qreal) is used, then OutAspectRatioMode is CustomAspectRation - virtual void setOutAspectRatio(qreal ratio); //has default + void setOutAspectRatio(qreal ratio); qreal outAspectRatio() const;// - virtual void setQuality(Quality q); //has default + void setQuality(Quality q); Quality quality() const; //TODO: unregister @@ -129,7 +129,7 @@ public: //virtual QImage currentFrameImage() const = 0; //const QImage& const? //TODO: resizeRenderer void resizeRenderer(const QSize& size); - virtual void resizeRenderer(int width, int height); //has default + void resizeRenderer(int width, int height); QSize rendererSize() const; int rendererWidth() const; int rendererHeight() const; @@ -149,7 +149,7 @@ public: QRectF regionOfInterest() const; // TODO: reset aspect ratio to roi.width/roi/heghit void setRegionOfInterest(qreal x, qreal y, qreal width, qreal height); - virtual void setRegionOfInterest(const QRectF& roi); //has default + void setRegionOfInterest(const QRectF& roi); // compute the real ROI QRect realROI() const; @@ -158,12 +158,12 @@ public: * \brief mapToFrame * map point in VideoRenderer coordinate to VideoFrame, with current ROI */ - virtual QPointF mapToFrame(const QPointF& p) const; //has default + QPointF mapToFrame(const QPointF& p) const; /*! * \brief mapFromFrame * map point in VideoFrame coordinate to VideoRenderer, with current ROI */ - virtual QPointF mapFromFrame(const QPointF& p) const; //has default + QPointF mapFromFrame(const QPointF& p) const; /*! * \brief widget @@ -179,11 +179,11 @@ public: //TODO: enable/disable = new a default for this vo engine or push back/remove from list //filter: null means disable //return the old filter. you may release the ptr manually - virtual OSDFilter* setOSDFilter(OSDFilter *filter); //has default + OSDFilter* setOSDFilter(OSDFilter *filter); OSDFilter *osdFilter(); - virtual Filter* setSubtitleFilter(Filter *filter); //has default + Filter* setSubtitleFilter(Filter *filter); Filter* subtitleFilter(); - virtual void enableDefaultEventFilter(bool e); //has default + void enableDefaultEventFilter(bool e); bool isDefaultEventFilterEnabled() const; /*! @@ -194,13 +194,13 @@ public: * \return \a false if failed (may be onChangingXXX not implemented or return false) */ qreal brightness() const; - virtual bool setBrightness(qreal brightness); //has default + bool setBrightness(qreal brightness); qreal contrast() const; - virtual bool setContrast(qreal contrast); //has default + bool setContrast(qreal contrast); qreal hue() const; - virtual bool setHue(qreal hue); //has default + bool setHue(qreal hue); qreal saturation() const; - virtual bool setSaturation(qreal saturation); //has default + bool setSaturation(qreal saturation); protected: VideoRenderer(VideoRendererPrivate &d); @@ -222,7 +222,7 @@ protected: */ virtual void resizeFrame(int width, int height); //TODO: parameter QRect? - virtual void handlePaintEvent(); //has default + virtual void handlePaintEvent(); //has default. User don't have to implement it /*! * \brief onBrightness * It's called when user call setBrightness(). You should implement how to actually change the brightness. @@ -235,6 +235,24 @@ protected: virtual bool onChangingHue(qreal h); virtual bool onChangingSaturation(qreal s); +private: //used by VideoOutput class + virtual bool onSetPreferredPixelFormat(VideoFormat::PixelFormat pixfmt); + virtual void onForcePreferredPixelFormat(bool force = true); + virtual void onScaleInRenderer(bool q); + virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode); + virtual void onSetOutAspectRatio(qreal ratio); + virtual void onSetQuality(Quality q); + virtual void onResizeRenderer(int width, int height); + virtual void onSetRegionOfInterest(const QRectF& roi); + virtual QPointF onMapToFrame(const QPointF& p) const; + virtual QPointF onMapFromFrame(const QPointF& p) const; + virtual OSDFilter* onSetOSDFilter(OSDFilter *filter); + virtual Filter* onSetSubtitleFilter(Filter *filter); + + virtual bool onSetBrightness(qreal brightness); + virtual bool onSetContrast(qreal contrast); + virtual bool onSetHue(qreal hue); + virtual bool onSetSaturation(qreal saturation); private: friend class VideoThread; friend class VideoOutput; diff --git a/src/VideoOutput.cpp b/src/VideoOutput.cpp index 3f763348..621338ae 100644 --- a/src/VideoOutput.cpp +++ b/src/VideoOutput.cpp @@ -70,7 +70,7 @@ void VideoOutput::setVideoFormat(const VideoFormat& format) d_func().impl->setVideoFormat(format); } */ -bool VideoOutput::setPreferredPixelFormat(VideoFormat::PixelFormat pixfmt) +bool VideoOutput::onSetPreferredPixelFormat(VideoFormat::PixelFormat pixfmt) { DPTR_D(VideoOutput); bool ret = d.impl->setPreferredPixelFormat(pixfmt); @@ -83,49 +83,11 @@ VideoFormat::PixelFormat VideoOutput::preferredPixelFormat() const return d_func().impl->preferredPixelFormat(); } -void VideoOutput::forcePreferredPixelFormat(bool force) -{ - DPTR_D(VideoOutput); - d.impl->forcePreferredPixelFormat(force); - d.force_preferred = d.impl->isPreferredPixelFormatForced(); -} - bool VideoOutput::isSupported(VideoFormat::PixelFormat pixfmt) const { return d_func().impl->isSupported(pixfmt); } -void VideoOutput::scaleInRenderer(bool q) -{ - DPTR_D(VideoOutput); - -} - -void VideoOutput::setOutAspectRatioMode(OutAspectRatioMode mode) -{ - DPTR_D(VideoOutput); - d.impl->setOutAspectRatioMode(mode); - d.out_rect = d.impl->videoRect(); - d.out_aspect_ratio = d.impl->outAspectRatio(); - d.out_aspect_ratio_mode = d.impl->outAspectRatioMode(); -} - -void VideoOutput::setOutAspectRatio(qreal ratio) -{ - DPTR_D(VideoOutput); - d.impl->setOutAspectRatio(ratio); - d.out_rect = d.impl->videoRect(); - d.out_aspect_ratio = d.impl->outAspectRatio(); - d.out_aspect_ratio_mode = d.impl->outAspectRatioMode(); -} - -void VideoOutput::setQuality(Quality q) -{ - DPTR_D(VideoOutput); - d.impl->setQuality(q); - d.quality = d.impl->quality(); -} - bool VideoOutput::open() { DPTR_D(VideoOutput); @@ -138,37 +100,6 @@ bool VideoOutput::close() return d.impl->close(); } -void VideoOutput::resizeRenderer(int width, int height) -{ - DPTR_D(VideoOutput); - if (width == 0 || height == 0) - return; - d.impl->resizeRenderer(width, height); - d.renderer_width = width; - d.renderer_height = height; - d.out_aspect_ratio = d.impl->outAspectRatio(); - d.out_rect = d.impl->videoRect(); -} - -void VideoOutput::setRegionOfInterest(const QRectF& roi) -{ - DPTR_D(VideoOutput); - d.impl->setRegionOfInterest(roi); - d.roi = d.impl->regionOfInterest(); -} - -QPointF VideoOutput::mapToFrame(const QPointF& p) const -{ - DPTR_D(const VideoOutput); - return d.impl->mapToFrame(p); -} - -QPointF VideoOutput::mapFromFrame(const QPointF& p) const -{ - DPTR_D(const VideoOutput); - return d.impl->mapFromFrame(p); -} - QWidget* VideoOutput::widget() { return d_func().impl->widget(); @@ -179,61 +110,6 @@ QGraphicsItem* VideoOutput::graphicsItem() return d_func().impl->graphicsItem(); } -OSDFilter* VideoOutput::setOSDFilter(OSDFilter *filter) -{ - DPTR_D(VideoOutput); - return d.impl->setOSDFilter(filter); -} - -Filter* VideoOutput::setSubtitleFilter(Filter *filter) -{ - DPTR_D(VideoOutput); - return d.impl->setSubtitleFilter(filter); -} - -void VideoOutput::enableDefaultEventFilter(bool e) -{ - DPTR_D(VideoOutput); - d.impl->enableDefaultEventFilter(e); - d.default_event_filter = d.impl->isDefaultEventFilterEnabled(); -} - -bool VideoOutput::setBrightness(qreal brightness) -{ - DPTR_D(VideoOutput); - if (!d.impl->setBrightness(brightness)) - return false; - d.brightness = brightness; - return false; -} - -bool VideoOutput::setContrast(qreal contrast) -{ - DPTR_D(VideoOutput); - if (!d.impl->setContrast(contrast)) - return false; - d.contrast = d.impl->contrast(); - return true; -} - -bool VideoOutput::setHue(qreal hue) -{ - DPTR_D(VideoOutput); - if (!d.impl->setHue(hue)) - return false; - d.hue = d.impl->hue(); - return true; -} - -bool VideoOutput::setSaturation(qreal saturation) -{ - DPTR_D(VideoOutput); - if (!d.impl->setSaturation(saturation)) - return false; - d.saturation = d.impl->saturation(); - return true; -} - bool VideoOutput::receiveFrame(const VideoFrame& frame) { DPTR_D(VideoOutput); @@ -312,6 +188,125 @@ bool VideoOutput::onChangingSaturation(qreal s) return true; } + + +void VideoOutput::onForcePreferredPixelFormat(bool force) +{ + DPTR_D(VideoOutput); + d.impl->onForcePreferredPixelFormat(force); + d.force_preferred = d.impl->isPreferredPixelFormatForced(); +} + +void VideoOutput::onScaleInRenderer(bool q) +{ + DPTR_D(VideoOutput); + +} + +void VideoOutput::onSetOutAspectRatioMode(OutAspectRatioMode mode) +{ + DPTR_D(VideoOutput); + d.impl->onSetOutAspectRatioMode(mode); + d.out_rect = d.impl->videoRect(); + d.out_aspect_ratio = d.impl->outAspectRatio(); + d.out_aspect_ratio_mode = d.impl->outAspectRatioMode(); +} + +void VideoOutput::onSetOutAspectRatio(qreal ratio) +{ + DPTR_D(VideoOutput); + d.impl->onSetOutAspectRatio(ratio); + d.out_rect = d.impl->videoRect(); + d.out_aspect_ratio = d.impl->outAspectRatio(); + d.out_aspect_ratio_mode = d.impl->outAspectRatioMode(); +} + +void VideoOutput::onSetQuality(Quality q) +{ + DPTR_D(VideoOutput); + d.impl->onSetQuality(q); + d.quality = d.impl->quality(); +} + +void VideoOutput::onResizeRenderer(int width, int height) +{ + DPTR_D(VideoOutput); + if (width == 0 || height == 0) + return; + d.impl->onResizeRenderer(width, height); + d.renderer_width = width; + d.renderer_height = height; + d.out_aspect_ratio = d.impl->outAspectRatio(); + d.out_rect = d.impl->videoRect(); +} + +void VideoOutput::onSetRegionOfInterest(const QRectF& roi) +{ + DPTR_D(VideoOutput); + d.impl->onSetRegionOfInterest(roi); + d.roi = d.impl->regionOfInterest(); +} + +QPointF VideoOutput::onMapToFrame(const QPointF& p) const +{ + DPTR_D(const VideoOutput); + return d.impl->onMapToFrame(p); +} + +QPointF VideoOutput::onMapFromFrame(const QPointF& p) const +{ + DPTR_D(const VideoOutput); + return d.impl->onMapFromFrame(p); +} + +OSDFilter* VideoOutput::onSetOSDFilter(OSDFilter *filter) +{ + DPTR_D(VideoOutput); + return d.impl->onSetOSDFilter(filter); +} + +Filter* VideoOutput::onSetSubtitleFilter(Filter *filter) +{ + DPTR_D(VideoOutput); + return d.impl->onSetSubtitleFilter(filter); +} + +bool VideoOutput::onSetBrightness(qreal brightness) +{ + DPTR_D(VideoOutput); + if (!d.impl->onSetBrightness(brightness)) + return false; + d.brightness = brightness; + return true; +} + +bool VideoOutput::onSetContrast(qreal contrast) +{ + DPTR_D(VideoOutput); + if (!d.impl->onSetContrast(contrast)) + return false; + d.contrast = d.impl->contrast(); + return true; +} + +bool VideoOutput::onSetHue(qreal hue) +{ + DPTR_D(VideoOutput); + if (!d.impl->onSetHue(hue)) + return false; + d.hue = d.impl->hue(); + return true; +} + +bool VideoOutput::onSetSaturation(qreal saturation) +{ + DPTR_D(VideoOutput); + if (!d.impl->onSetSaturation(saturation)) + return false; + d.saturation = d.impl->saturation(); + return true; +} + void VideoOutput::setInSize(int width, int height) { DPTR_D(VideoOutput); diff --git a/src/VideoRenderer.cpp b/src/VideoRenderer.cpp index bc47ab52..89329910 100644 --- a/src/VideoRenderer.cpp +++ b/src/VideoRenderer.cpp @@ -50,6 +50,11 @@ bool VideoRenderer::receive(const VideoFrame &frame) } bool VideoRenderer::setPreferredPixelFormat(VideoFormat::PixelFormat pixfmt) +{ + return onSetPreferredPixelFormat(pixfmt); +} + +bool VideoRenderer::onSetPreferredPixelFormat(VideoFormat::PixelFormat pixfmt) { if (!isSupported(pixfmt)) { qWarning("pixel format '%s' is not supported", VideoFormat(pixfmt).name().toUtf8().constData()); @@ -65,6 +70,11 @@ VideoFormat::PixelFormat VideoRenderer::preferredPixelFormat() const } void VideoRenderer::forcePreferredPixelFormat(bool force) +{ + onForcePreferredPixelFormat(force); +} + +void VideoRenderer::onForcePreferredPixelFormat(bool force) { d_func().force_preferred = force; } @@ -75,6 +85,11 @@ bool VideoRenderer::isPreferredPixelFormatForced() const } void VideoRenderer::scaleInRenderer(bool q) +{ + onScaleInRenderer(q); +} + +void VideoRenderer::onScaleInRenderer(bool q) { d_func().scale_in_renderer = q; } @@ -85,6 +100,11 @@ bool VideoRenderer::scaleInRenderer() const } void VideoRenderer::setOutAspectRatioMode(OutAspectRatioMode mode) +{ + onSetOutAspectRatioMode(mode); +} + +void VideoRenderer::onSetOutAspectRatioMode(OutAspectRatioMode mode) { DPTR_D(VideoRenderer); if (mode == d.out_aspect_ratio_mode) @@ -107,6 +127,11 @@ VideoRenderer::OutAspectRatioMode VideoRenderer::outAspectRatioMode() const } void VideoRenderer::setOutAspectRatio(qreal ratio) +{ + onSetOutAspectRatio(ratio); +} + +void VideoRenderer::onSetOutAspectRatio(qreal ratio) { DPTR_D(VideoRenderer); bool ratio_changed = d.out_aspect_ratio != ratio; @@ -132,6 +157,11 @@ qreal VideoRenderer::outAspectRatio() const } void VideoRenderer::setQuality(Quality q) +{ + onSetQuality(q); +} + +void VideoRenderer::onSetQuality(Quality q) { DPTR_D(VideoRenderer); d.quality = q; @@ -184,6 +214,11 @@ void VideoRenderer::resizeRenderer(const QSize &size) } void VideoRenderer::resizeRenderer(int width, int height) +{ + onResizeRenderer(width, height); +} + +void VideoRenderer::onResizeRenderer(int width, int height) { DPTR_D(VideoRenderer); if (width == 0 || height == 0) @@ -233,6 +268,11 @@ void VideoRenderer::setRegionOfInterest(qreal x, qreal y, qreal width, qreal hei } void VideoRenderer::setRegionOfInterest(const QRectF &roi) +{ + onSetRegionOfInterest(roi); +} + +void VideoRenderer::onSetRegionOfInterest(const QRectF &roi) { d_func().roi = roi; } @@ -258,6 +298,11 @@ QRect VideoRenderer::realROI() const } QPointF VideoRenderer::mapToFrame(const QPointF &p) const +{ + return onMapToFrame(p); +} + +QPointF VideoRenderer::onMapToFrame(const QPointF &p) const { QRectF roi = realROI(); // zoom=roi.w/roi.h>vo.w/vo.h?roi.w/vo.w:roi.h/vo.h @@ -267,6 +312,11 @@ QPointF VideoRenderer::mapToFrame(const QPointF &p) const } QPointF VideoRenderer::mapFromFrame(const QPointF &p) const +{ + return onMapFromFrame(p); +} + +QPointF VideoRenderer::onMapFromFrame(const QPointF &p) const { QRectF roi = realROI(); // zoom=roi.w/roi.h>vo.w/vo.h?roi.w/vo.w:roi.h/vo.h @@ -277,6 +327,11 @@ QPointF VideoRenderer::mapFromFrame(const QPointF &p) const } OSDFilter *VideoRenderer::setOSDFilter(OSDFilter *filter) +{ + return onSetOSDFilter(filter); +} + +OSDFilter *VideoRenderer::onSetOSDFilter(OSDFilter *filter) { DPTR_D(VideoRenderer); Filter *old = d.osd_filter; @@ -305,6 +360,11 @@ OSDFilter* VideoRenderer::osdFilter() } //TODO: setSubtitleFilter and setOSDFilter are almost the same. refine code Filter* VideoRenderer::setSubtitleFilter(Filter *filter) +{ + return onSetSubtitleFilter(filter); +} + +Filter* VideoRenderer::onSetSubtitleFilter(Filter *filter) { DPTR_D(VideoRenderer); Filter *old = d.subtitle_filter; @@ -419,6 +479,11 @@ qreal VideoRenderer::brightness() const } bool VideoRenderer::setBrightness(qreal brightness) +{ + return onSetBrightness(brightness); +} + +bool VideoRenderer::onSetBrightness(qreal brightness) { if (!onChangingBrightness(brightness)) return false; @@ -438,6 +503,11 @@ qreal VideoRenderer::contrast() const } bool VideoRenderer::setContrast(qreal contrast) +{ + return onSetContrast(contrast); +} + +bool VideoRenderer::onSetContrast(qreal contrast) { if (!onChangingContrast(contrast)) return false; @@ -457,6 +527,11 @@ qreal VideoRenderer::hue() const } bool VideoRenderer::setHue(qreal hue) +{ + return onSetHue(hue); +} + +bool VideoRenderer::onSetHue(qreal hue) { if (!onChangingHue(hue)) return false; @@ -476,6 +551,11 @@ qreal VideoRenderer::saturation() const } bool VideoRenderer::setSaturation(qreal saturation) +{ + return onSetSaturation(saturation); +} + +bool VideoRenderer::onSetSaturation(qreal saturation) { if (!onChangingSaturation(saturation)) return false;