[DEV]play sound not so bad ...

This commit is contained in:
Edouard DUPIN 2017-04-13 23:42:00 +02:00
parent 6f75373855
commit 0ced25aed1
11 changed files with 253 additions and 8 deletions

View File

@ -18,6 +18,7 @@
#include <appl/widget/ListViewer.hpp>
#include <appl/widget/Player.hpp>
#include <appl/widget/ProgressBar.hpp>
#include <appl/widget/VolumeBar.hpp>
#include <zeus/zeus.hpp>
namespace appl {
@ -74,6 +75,7 @@ namespace appl {
appl::widget::ListViewer::createManagerWidget(_context.getWidgetManager());
appl::widget::Player::createManagerWidget(_context.getWidgetManager());
appl::widget::ProgressBar::createManagerWidget(_context.getWidgetManager());
appl::widget::VolumeBar::createManagerWidget(_context.getWidgetManager());
// Create the windows
ememory::SharedPtr<appl::Windows> basicWindows = appl::Windows::create();
// configure the ewol context to use the new windows

View File

@ -711,6 +711,9 @@ void appl::MediaDecoder::init() {
}
// Open Audio Decoder:
if (open_codec_context(&m_audioStream_idx, m_formatContext, AVMEDIA_TYPE_AUDIO) >= 0) {
APPL_ERROR("***********************************************************");
APPL_ERROR("** Presence of Audio ... **");
APPL_ERROR("***********************************************************");
m_audioPresent = true;
m_audioStream = m_formatContext->streams[m_audioStream_idx];
m_audioDecoderContext = m_audioStream->codec;

View File

@ -45,6 +45,7 @@ void appl::widget::Player::init() {
subBind(appl::widget::VideoDisplay, "[" + etk::to_string(getId()) + "]appl-player-display", signalFps, sharedFromThis(), &appl::widget::Player::onCallbackFPS);
subBind(appl::widget::ProgressBar, "[" + etk::to_string(getId()) + "]appl-player-progress-bar", signalChange, sharedFromThis(), &appl::widget::Player::onCallbackSeekRequest);
subBind(appl::widget::VolumeBar, "[" + etk::to_string(getId()) + "]appl-player-volume", signalChange, sharedFromThis(), &appl::widget::Player::onCallbackVolumeRequest);
m_display = ememory::dynamicPointerCast<appl::widget::VideoDisplay>(getSubObjectNamed("[" + etk::to_string(getId()) + "]appl-player-display"));
m_progress = ememory::dynamicPointerCast<appl::widget::ProgressBar>(getSubObjectNamed("[" + etk::to_string(getId()) + "]appl-player-progress-bar"));
@ -130,14 +131,26 @@ void appl::widget::Player::onCallbackPosition(const echrono::Duration& _time) {
}
void appl::widget::Player::onCallbackSeekRequest(const float& _value) {
APPL_ERROR("===========================================================================");
APPL_ERROR("seek at = " << echrono::Duration(_value) << " from value=" << _value);
APPL_ERROR("===========================================================================");
APPL_DEBUG("===========================================================================");
APPL_DEBUG("seek at = " << echrono::Duration(_value) << " from value=" << _value);
APPL_DEBUG("===========================================================================");
if (m_display != nullptr) {
m_display->seek(echrono::Duration(_value));
}
}
void appl::widget::Player::onCallbackVolumeRequest(const float& _value) {
APPL_DEBUG("===========================================================================");
APPL_DEBUG("volume change value=" << _value << " dB");
APPL_DEBUG("===========================================================================");
if (m_display != nullptr) {
m_display->changeVolume(_value);
}
std::string display = etk::to_string(int32_t(_value)) + "." + etk::to_string(std::abs(int32_t(_value*10.0f)-int32_t(_value)*10));
propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-label-volume", "value", display + " dB");
}
void appl::widget::Player::onCallbackFPS(const int32_t& _fps) {
APPL_DEBUG("FPS = " << _fps);
propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-label-fps", "value", "FPS=<font color='orangered'>" + etk::to_string(_fps) + "</font>");

View File

@ -11,6 +11,7 @@
#include <esignal/Signal.hpp>
#include <appl/widget/VideoPlayer.hpp>
#include <appl/widget/ProgressBar.hpp>
#include <appl/widget/VolumeBar.hpp>
#include <appl/ClientProperty.hpp>
namespace appl {
@ -47,6 +48,7 @@ namespace appl {
void onCallbackPosition(const echrono::Duration& _value);
void onCallbackDuration(const echrono::Duration& _value);
void onCallbackSeekRequest(const float& _value);
void onCallbackVolumeRequest(const float& _value);
void onCallbackFPS(const int32_t& _fps);
};
};

View File

@ -65,7 +65,7 @@ void appl::widget::ProgressBar::onRegenerateDisplay() {
for (auto &it: m_listAvaillable) {
//APPL_INFO("plop " << it.first << " " << it.second);
m_draw.setPos(vec3(dotRadius+(it.first/propertyMaximum)*(m_size.x()-2*dotRadius), m_size.y()*0.1, 0));
m_draw.rectangleWidth(vec3((it.second/propertyMaximum)*(m_size.x()-2*dotRadius), m_size.y()*0.8, 0) );
m_draw.rectangleWidth(vec3(std::min((m_size.x()-2*dotRadius), (it.second/propertyMaximum)*(m_size.x()-2*dotRadius)), m_size.y()*0.8, 0) );
}
m_draw.setColor(m_textColorDone);
@ -91,7 +91,7 @@ bool appl::widget::ProgressBar::onEventInput(const ewol::event::Input& _event) {
if( gale::key::status::pressSingle == _event.getStatus()
|| gale::key::status::move == _event.getStatus()) {
// get the new position :
EWOL_VERBOSE("Event on ProgressBar (" << relativePos.x() << "," << relativePos.y() << ")");
EWOL_VERBOSE("Event on ProgressBar " << relativePos);
float oldValue = *propertyValue;
updateValue((float)(relativePos.x() - dotRadius) / (m_size.x()-2*dotRadius) * (*propertyMaximum));
if (oldValue != *propertyValue) {

View File

@ -126,6 +126,10 @@ void appl::widget::VideoDisplay::play() {
APPL_DEBUG("Already started");
return;
}
/*
APPL_ERROR("==========================================================");
APPL_ERROR("== Presence of Audio: " << m_decoder->haveAudio() << " ==");
APPL_ERROR("==========================================================");
if (m_decoder->haveAudio() == true) {
m_audioInterface = m_audioManager->createOutput(m_decoder->audioGetSampleRate(),
m_decoder->audioGetChannelMap(),
@ -137,11 +141,18 @@ void appl::widget::VideoDisplay::play() {
m_audioInterface->setReadwrite();
m_audioInterface->start();
}
*/
// Start decoder, this is maybe not the good point, but if we configure a decoder, it is to use it ...
m_decoder->start();
//TODO: Set an option to river to auto-generate dot: m_audioManager->generateDotAll("out/local_player_flow.dot");
}
void appl::widget::VideoDisplay::changeVolume(const float& _value) {
if (m_audioManager != nullptr) {
m_audioManager->setVolume("MASTER", _value);
}
}
void appl::widget::VideoDisplay::pause() {
m_isPalying = false;
}
@ -274,12 +285,28 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
int32_t idSlot = m_decoder->audioGetOlderSlot();
if ( idSlot != -1
&& m_currentTime > m_decoder->m_audioPool[idSlot].m_time) {
if (m_audioInterface == nullptr) {
// start audio interface the first time we need it
APPL_ERROR("==========================================================");
APPL_ERROR("== Presence of Audio: " << m_decoder->haveAudio() << " ==");
APPL_ERROR("==========================================================");
if (m_decoder->haveAudio() == true) {
m_audioInterface = m_audioManager->createOutput(m_decoder->audioGetSampleRate(),
m_decoder->audioGetChannelMap(),
m_decoder->audioGetFormat(),
"speaker");
if(m_audioInterface == nullptr) {
APPL_ERROR("Can not create Audio interface");
}
m_audioInterface->setReadwrite();
m_audioInterface->start();
}
}
if (m_audioInterface != nullptr) {
int32_t nbSample = m_decoder->m_audioPool[idSlot].m_buffer.size()
/ audio::getFormatBytes(m_decoder->m_audioPool[idSlot].m_format)
/ m_decoder->m_audioPool[idSlot].m_map.size();
m_audioInterface->write(&m_decoder->m_audioPool[idSlot].m_buffer[0], nbSample);
APPL_WARNING("write samples ... ");
}
m_decoder->m_audioPool[idSlot].m_isUsed = false;
getSomething = true;

View File

@ -96,6 +96,7 @@ namespace appl {
}
return m_decoder->getDownloadPart();
}
void changeVolume(const float& _value);
};
}
}

View File

@ -0,0 +1,121 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <appl/widget/VolumeBar.hpp>
#include <ewol/widget/Manager.hpp>
const int32_t dotRadius = 6;
appl::widget::VolumeBar::VolumeBar() :
signalChange(this, "change", ""),
propertyValue(this, "value",
0.0f,
"Value of the VolumeBar",
&appl::widget::VolumeBar::onChangePropertyValue),
propertyMinimum(this, "min",
-10.0f,
"Minimum value",
&appl::widget::VolumeBar::onChangePropertyMinimum),
propertyMaximum(this, "max",
5.0f,
"Maximum value",
&appl::widget::VolumeBar::onChangePropertyMaximum) {
addObjectType("appl::widget::VolumeBar");
m_textColorFg = etk::color::orange;
m_textColorLoaded = etk::color::red;
m_textColorDone = etk::color::green;
m_textColorBg = etk::color::black;
m_textColorBg.setA(0x3F);
propertyCanFocus.setDirectCheck(true);
// Limit event at 1:
setMouseLimit(1);
}
appl::widget::VolumeBar::~VolumeBar() {
}
void appl::widget::VolumeBar::calculateMinMaxSize() {
vec2 minTmp = propertyMinSize->getPixel();
m_minSize.setValue(std::max(minTmp.x(), 40.0f),
std::max(minTmp.y(), dotRadius*2.0f) );
markToRedraw();
}
void appl::widget::VolumeBar::onDraw() {
m_draw.draw();
}
void appl::widget::VolumeBar::onRegenerateDisplay() {
if (needRedraw() == false) {
return;
}
// clean the object list ...
m_draw.clear();
m_draw.setColor(m_textColorFg);
// draw a line:
m_draw.setPos(vec3(dotRadius, 0, 0));
m_draw.rectangleWidth(vec3(m_size.x(), m_size.y()-dotRadius*2.0, 0));
// chaneg color whe soud became louder ...
if (*propertyValue > 0.5f) {
m_draw.setColor(m_textColorLoaded);
} else {
m_draw.setColor(m_textColorDone);
}
m_draw.setPos(vec3(m_size.x()*0.1, dotRadius, 0));
float offset = (*propertyValue-*propertyMinimum)/(*propertyMaximum-*propertyMinimum);
m_draw.rectangleWidth(vec3(m_size.x()*0.8, offset*(m_size.y()-2*dotRadius), 0) );
}
bool appl::widget::VolumeBar::onEventInput(const ewol::event::Input& _event) {
vec2 relativePos = relativePosition(_event.getPos());
//EWOL_DEBUG("Event on VolumeBar ..." << _event);
if (1 == _event.getId()) {
if( gale::key::status::pressSingle == _event.getStatus()
|| gale::key::status::move == _event.getStatus()) {
// get the new position :
EWOL_VERBOSE("Event on VolumeBar " << relativePos);
float oldValue = *propertyValue;
updateValue((float)(relativePos.y() - dotRadius) / (m_size.y()-2*dotRadius) * (*propertyMaximum-*propertyMinimum)+*propertyMinimum);
if (oldValue != *propertyValue) {
EWOL_VERBOSE(" new value : " << *propertyValue << " in [" << *propertyMinimum << ".." << *propertyMaximum << "]");
signalChange.emit(*propertyValue);
}
return true;
}
}
return false;
}
void appl::widget::VolumeBar::updateValue(float _newValue) {
_newValue = std::max(std::min(_newValue, *propertyMaximum), *propertyMinimum);
propertyValue.setDirect(_newValue);
markToRedraw();
}
void appl::widget::VolumeBar::onChangePropertyValue() {
updateValue(*propertyValue);
return;
}
void appl::widget::VolumeBar::onChangePropertyMaximum() {
updateValue(*propertyValue);
return;
}
void appl::widget::VolumeBar::onChangePropertyMinimum() {
updateValue(*propertyValue);
return;
}

View File

@ -0,0 +1,66 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Color.hpp>
#include <appl/debug.hpp>
#include <ewol/widget/Widget.hpp>
#include <ewol/compositing/Drawing.hpp>
#include <esignal/Signal.hpp>
namespace appl {
namespace widget {
class VolumeBar;
using VolumeBarShared = ememory::SharedPtr<appl::widget::VolumeBar>;
using VolumeBarWeak = ememory::WeakPtr<appl::widget::VolumeBar>;
/**
* @ingroup ewolWidgetGroup
*/
class VolumeBar : public ewol::Widget {
public: // signals
esignal::Signal<float> signalChange;
public:
//eproperty::Value<std::string> propertyShape; //!< name of the shape used
eproperty::Value<float> propertyValue; //!< current value of the VolumeBar
eproperty::Value<float> propertyMinimum; //!< minimum value of the VolumeBar
eproperty::Value<float> propertyMaximum; //!< maximum value of the VolumeBar
protected:
VolumeBar();
public:
DECLARE_WIDGET_FACTORY(VolumeBar, "appl_VolumeBar");
virtual ~VolumeBar();
public:
// TODO : Rewoek the color in the theme ...
void setColor(etk::Color<> _newColor) {
m_textColorFg = _newColor;
};
protected:
ewol::compositing::Drawing m_draw; //!< drawing tool.
etk::Color<> m_textColorFg; //!< Text color
etk::Color<> m_textColorBg; //!< Background color
etk::Color<> m_textColorDone;
etk::Color<> m_textColorLoaded;
void updateValue(float _newValue);
public: // Derived function
void onDraw() override;
void calculateMinMaxSize() override;
void onRegenerateDisplay() override;
bool onEventInput(const ewol::event::Input& _event) override;
private:
std::vector<std::pair<float,float>> m_listAvaillable;
public:
void setRangeAvaillable(std::vector<std::pair<float,float>>& _values) {
m_listAvaillable = _values;
}
protected:
virtual void onChangePropertyValue();
virtual void onChangePropertyMinimum();
virtual void onChangePropertyMaximum();
};
}
}

View File

@ -29,8 +29,17 @@
<spacer expand="true,false" fill="true"/>
<label name="[{ID}]appl-player-label-duration"/>
</sizer>
<spacer expand="true" fill="true"/>
<label name="[{ID}]appl-player-label-fps"/>
<sizer mode="hori" fill="true" expand="true,false">
<sizer mode="vert" fill="true" expand="true">
<spacer expand="true" fill="true"/>
<label name="[{ID}]appl-player-label-fps"/>
</sizer>
<sizer mode="vert" fill="true" expand="false,true">
<appl_VolumeBar name="[{ID}]appl-player-volume" expand="false,true" fill="true" step="0.1" value="0" min="-60" max="6" mode="vert"/>
<label name="[{ID}]appl-player-label-volume">0dB</label>
</sizer>
</sizer>
</sizer>
<VideoDisplay name="[{ID}]appl-player-display" expand="true" fill="true"/>
</layer>

View File

@ -39,6 +39,7 @@ def configure(target, my_module):
'appl/widget/Connection.cpp',
'appl/widget/Player.cpp',
'appl/widget/ProgressBar.cpp',
'appl/widget/VolumeBar.cpp',
])
my_module.add_depend([
'ffmpeg-libs',