WIP: Volume support.

This commit is contained in:
Pieter Hulshoff
2019-03-21 20:37:28 +01:00
parent 68902745e0
commit 6a4532b0b3
10 changed files with 71 additions and 1 deletions

View File

@@ -137,3 +137,15 @@ bool Video::isPlaying( )
return false; return false;
} }
} }
void Video::setVolume(double volume)
{
volume_ = volume;
}
double Video::getVolume()
{
return volume_;
}

View File

@@ -30,6 +30,8 @@ public:
void allocateGraphicsMemory( ); void allocateGraphicsMemory( );
void draw( ); void draw( );
virtual bool isPlaying( ); virtual bool isPlaying( );
void setVolume(double volume);
double getVolume();
protected: protected:
Component *video_; Component *video_;
@@ -41,5 +43,6 @@ protected:
private: private:
static bool enabled_; static bool enabled_;
double volume_;
}; };

View File

@@ -28,6 +28,7 @@ VideoComponent::VideoComponent(IVideo *videoInst, Page &p, std::string videoFile
, scaleX_(scaleX) , scaleX_(scaleX)
, scaleY_(scaleY) , scaleY_(scaleY)
, isPlaying_(false) , isPlaying_(false)
, volume_(1.0)
{ {
// AllocateGraphicsMemory(); // AllocateGraphicsMemory();
} }
@@ -105,3 +106,15 @@ bool VideoComponent::isPlaying()
{ {
return isPlaying_; return isPlaying_;
} }
void VideoComponent::setVolume(double volume)
{
volume_ = volume;
}
double VideoComponent::getVolume()
{
return volume_;
}

View File

@@ -32,6 +32,8 @@ public:
void freeGraphicsMemory(); void freeGraphicsMemory();
void allocateGraphicsMemory(); void allocateGraphicsMemory();
virtual bool isPlaying(); virtual bool isPlaying();
void setVolume(double volume);
double getVolume();
private: private:
std::string videoFile_; std::string videoFile_;
@@ -40,4 +42,5 @@ private:
float scaleX_; float scaleX_;
float scaleY_; float scaleY_;
bool isPlaying_; bool isPlaying_;
double volume_;
}; };

View File

@@ -25,6 +25,7 @@
#include "Component/ReloadableScrollingText.h" #include "Component/ReloadableScrollingText.h"
#include "Component/ScrollingList.h" #include "Component/ScrollingList.h"
#include "Component/Video.h" #include "Component/Video.h"
#include "Component/VideoComponent.h"
#include "Animate/AnimationEvents.h" #include "Animate/AnimationEvents.h"
#include "Animate/TweenTypes.h" #include "Animate/TweenTypes.h"
#include "../Sound/Sound.h" #include "../Sound/Sound.h"
@@ -431,6 +432,7 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page)
xml_attribute<> *srcXml = componentXml->first_attribute("src"); xml_attribute<> *srcXml = componentXml->first_attribute("src");
xml_attribute<> *numLoopsXml = componentXml->first_attribute("numLoops"); xml_attribute<> *numLoopsXml = componentXml->first_attribute("numLoops");
xml_attribute<> *idXml = componentXml->first_attribute("id"); xml_attribute<> *idXml = componentXml->first_attribute("id");
xml_attribute<> *volumeXml = componentXml->first_attribute("volume");
int id = -1; int id = -1;
if (idXml) if (idXml)
@@ -463,6 +465,8 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page)
} }
buildViewInfo(componentXml, c->baseViewInfo); buildViewInfo(componentXml, c->baseViewInfo);
loadTweens(c, componentXml); loadTweens(c, componentXml);
if(volumeXml)
c->setVolume(Utils::convertFloat(volumeXml->value()));
page->addComponent(c); page->addComponent(c);
} }
} }
@@ -762,6 +766,10 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName,
{ {
static_cast<ReloadableMedia *>(c)->enableTextFallback_(false); static_cast<ReloadableMedia *>(c)->enableTextFallback_(false);
} }
xml_attribute<> *volumeXml = componentXml->first_attribute("volume");
if(volumeXml)
static_cast<VideoComponent *>(c)->setVolume(Utils::convertFloat(volumeXml->value()));
} }
if(c) if(c)

View File

@@ -21,7 +21,7 @@
std::string retrofe_version_major = "0"; std::string retrofe_version_major = "0";
std::string retrofe_version_minor = "8"; std::string retrofe_version_minor = "8";
std::string retrofe_version_build = "22"; std::string retrofe_version_build = "23";
std::string Version::getString( ) std::string Version::getString( )

View File

@@ -30,6 +30,7 @@
#include <gst/app/gstappsink.h> #include <gst/app/gstappsink.h>
#include <gst/video/gstvideometa.h> #include <gst/video/gstvideometa.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/audio/audio.h>
bool GStreamerVideo::initialized_ = false; bool GStreamerVideo::initialized_ = false;
@@ -56,6 +57,7 @@ GStreamerVideo::GStreamerVideo()
, isPlaying_(false) , isPlaying_(false)
, playCount_(0) , playCount_(0)
, numLoops_(0) , numLoops_(0)
, volume_(1.0)
{ {
} }
GStreamerVideo::~GStreamerVideo() GStreamerVideo::~GStreamerVideo()
@@ -348,6 +350,17 @@ void GStreamerVideo::update(float /* dt */)
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
} }
if(playbin_)
{
if(volume_ > 1.0)
volume_ = 1.0;
gst_stream_volume_set_volume( GST_STREAM_VOLUME( playbin_ ), GST_STREAM_VOLUME_FORMAT_LINEAR, static_cast<double>(volume_));
if(volume_ < 0.1)
gst_stream_volume_set_mute( GST_STREAM_VOLUME( playbin_ ), true );
else
gst_stream_volume_set_mute( GST_STREAM_VOLUME( playbin_ ), false );
}
if(videoBuffer_) if(videoBuffer_)
{ {
GstVideoMeta *meta; GstVideoMeta *meta;
@@ -450,3 +463,9 @@ bool GStreamerVideo::isPlaying()
{ {
return isPlaying_; return isPlaying_;
} }
void GStreamerVideo::setVolume(double volume)
{
volume_ = volume;
}

View File

@@ -41,6 +41,7 @@ public:
int getHeight(); int getHeight();
int getWidth(); int getWidth();
bool isPlaying(); bool isPlaying();
void setVolume(double volume);
private: private:
static void processNewBuffer (GstElement *fakesink, GstBuffer *buf, GstPad *pad, gpointer data); static void processNewBuffer (GstElement *fakesink, GstBuffer *buf, GstPad *pad, gpointer data);
@@ -62,4 +63,5 @@ private:
int playCount_; int playCount_;
std::string currentFile_; std::string currentFile_;
int numLoops_; int numLoops_;
double volume_;
}; };

View File

@@ -22,6 +22,7 @@ bool VideoFactory::enabled_ = true;
int VideoFactory::numLoops_ = 0; int VideoFactory::numLoops_ = 0;
IVideo *VideoFactory::instance_ = NULL; IVideo *VideoFactory::instance_ = NULL;
IVideo *VideoFactory::createVideo() IVideo *VideoFactory::createVideo()
{ {
@@ -35,12 +36,20 @@ IVideo *VideoFactory::createVideo()
return instance_; return instance_;
} }
void VideoFactory::setEnabled(bool enabled) void VideoFactory::setEnabled(bool enabled)
{ {
enabled_ = enabled; enabled_ = enabled;
} }
void VideoFactory::setNumLoops(int numLoops) void VideoFactory::setNumLoops(int numLoops)
{ {
numLoops_ = numLoops; numLoops_ = numLoops;
} }
void VideoFactory::setVolume(double volume)
{
((GStreamerVideo *)(instance_))->setVolume(volume);
}

View File

@@ -23,6 +23,7 @@ public:
static IVideo *createVideo(); static IVideo *createVideo();
static void setEnabled(bool enabled); static void setEnabled(bool enabled);
static void setNumLoops(int numLoops); static void setNumLoops(int numLoops);
static void setVolume(double volume);
private: private:
static bool enabled_; static bool enabled_;