From ec9f88fccb42a639b9171ce9aa62fe4914ce1930 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 22 Feb 2017 22:18:47 +0100 Subject: [PATCH] [DEV] set back display of the video ==> must do it better --- tools/player-video/appl/MediaDecoder.cpp | 7 ++-- tools/player-video/appl/Windows.cpp | 32 +++------------- tools/player-video/appl/widget/Player.cpp | 46 +++++++++++++++++++++-- tools/player-video/appl/widget/Player.hpp | 9 +++++ 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/tools/player-video/appl/MediaDecoder.cpp b/tools/player-video/appl/MediaDecoder.cpp index 35ef925..8be6b00 100644 --- a/tools/player-video/appl/MediaDecoder.cpp +++ b/tools/player-video/appl/MediaDecoder.cpp @@ -619,6 +619,7 @@ void appl::StreamBuffering::checkIfWeNeedMoreDataFromNetwork() { return; } } +#define APPL_BUFFER_SIZE_FOR_FFMPEG (256*1024) void appl::MediaDecoder::init() { if ( m_isInit == true @@ -642,8 +643,8 @@ void appl::MediaDecoder::init() { APPL_ERROR("Could not create Format context"); return; } - uint8_t* ploooooo = (uint8_t*)av_malloc(1024*1024); - m_IOContext = avio_alloc_context(ploooooo, 1024*1024, 0 /* can not write */, this, g_readFunc, g_writeFunc, g_seekFunc); + uint8_t* ploooooo = (uint8_t*)av_malloc(APPL_BUFFER_SIZE_FOR_FFMPEG); + m_IOContext = avio_alloc_context(ploooooo, APPL_BUFFER_SIZE_FOR_FFMPEG, 0 /* can not write */, this, g_readFunc, g_writeFunc, g_seekFunc); if (m_IOContext == nullptr) { APPL_ERROR("Could not create IO stream"); return; @@ -769,7 +770,7 @@ bool appl::MediaDecoder::onThreadCall() { applySeek(tmpSeek); } // Need to wait at lease 1MB - if (m_remote->sizeReadable() < 1024*1024) { + if (m_remote->sizeReadable() < APPL_BUFFER_SIZE_FOR_FFMPEG) { // take some time to sleep the decoding ... std::this_thread::sleep_for(std::chrono::milliseconds(60/100)); return false; diff --git a/tools/player-video/appl/Windows.cpp b/tools/player-video/appl/Windows.cpp index 7f047d6..fbe46e2 100644 --- a/tools/player-video/appl/Windows.cpp +++ b/tools/player-video/appl/Windows.cpp @@ -26,6 +26,7 @@ #include #include #include +#include static std::string g_baseDBName = "USERDATA:config.json"; @@ -82,10 +83,6 @@ void appl::Windows::init() { m_listViewer = ememory::dynamicPointerCast(m_composer->getSubObjectNamed("ws-name-list-viewer")); m_listViewer->signalSelect.connect(sharedFromThis(), &appl::Windows::onCallbackSelectMedia); - subBind(ewol::widget::Button, "bt-previous", signalPressed, sharedFromThis(), &appl::Windows::onCallbackPrevious); - subBind(ewol::widget::Button, "bt-play", signalValue, sharedFromThis(), &appl::Windows::onCallbackPlay); - subBind(ewol::widget::Button, "bt-next", signalPressed, sharedFromThis(), &appl::Windows::onCallbackNext); - subBind(ewol::widget::Button, "bt-back", signalPressed, sharedFromThis(), &appl::Windows::onCallbackBack); subBind(appl::widget::VideoDisplay, "displayer", signalFps, sharedFromThis(), &appl::Windows::onCallbackFPS); subBind(appl::widget::VideoDisplay, "displayer", signalPosition, sharedFromThis(), &appl::Windows::onCallbackPosition); subBind(ewol::widget::Slider, "progress-bar", signalChange, sharedFromThis(), &appl::Windows::onCallbackSeekRequest); @@ -236,17 +233,8 @@ void appl::Windows::onCallbackBack() { } -void appl::Windows::onCallbackPlay(const bool& _isPressed) { - ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); - if (tmpDisp == nullptr) { - return; - } - if (_isPressed == true) { - tmpDisp->play(); - } else { - tmpDisp->pause(); - } -} + + void appl::Windows::onCallbackNext() { m_id++; @@ -333,17 +321,9 @@ void appl::Windows::onCallbackSelectSourses() { void appl::Windows::onCallbackSelectMedia(const uint32_t& _value) { ewol::propertySetOnObjectNamed("view-selection", "select", "ws-name-player"); - ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); - if (tmpDisp != nullptr) { - // stop previous (if needed) - tmpDisp->stop(); - // Set new file: - tmpDisp->setZeusMedia(m_clientProp, _value); - tmpDisp->play(); - echrono::Duration time = tmpDisp->getDuration(); - APPL_DEBUG("duration = " << time << " " << etk::to_string(time.toSeconds())); - propertySetOnWidgetNamed("progress-bar", "value", "0"); - propertySetOnWidgetNamed("progress-bar", "max", etk::to_string(time.toSeconds())); + ememory::SharedPtr tmpPlayer = ememory::dynamicPointerCast(getSubObjectNamed("ws-name-player")); + if (tmpPlayer != nullptr) { + tmpPlayer->playStream(m_clientProp, _value); } } diff --git a/tools/player-video/appl/widget/Player.cpp b/tools/player-video/appl/widget/Player.cpp index 8c5e026..09f6987 100644 --- a/tools/player-video/appl/widget/Player.cpp +++ b/tools/player-video/appl/widget/Player.cpp @@ -23,7 +23,10 @@ #include #include -appl::widget::Player::Player() { +appl::widget::Player::Player() : + signalFinished(this, "finish", "The playing of the stream is finished"), + signalNext(this, "next", "User request the next stream"), + signalPrevious(this, "previous", "User request the previous stream") { addObjectType("appl::widget::Player"); } @@ -35,6 +38,8 @@ void appl::widget::Player::init() { subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-previous", signalPressed, sharedFromThis(), &appl::widget::Player::onCallbackButtonPrevious); subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-play", signalValue, sharedFromThis(), &appl::widget::Player::onCallbackButtonPlay); subBind(ewol::widget::Button, "[" + etk::to_string(getId()) + "]appl-player-bt-next", signalPressed, sharedFromThis(), &appl::widget::Player::onCallbackButtonNext); + + m_display = ememory::dynamicPointerCast(getSubObjectNamed("[" + etk::to_string(getId()) + "]appl-player-display")); propertyCanFocus.set(true); markToRedraw(); } @@ -49,16 +54,49 @@ appl::widget::Player::~Player() { } +void appl::widget::Player::playStream(ememory::SharedPtr _property, uint32_t _mediaId) { + if (m_display == nullptr) { + return; + } + // stop previous (if needed) + propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-bt-play", "value", "false"); + m_display->stop(); + // Set new file: + m_display->setZeusMedia(_property, _mediaId); + m_display->play(); + //echrono::Duration time = tmpDisp->getDuration(); + //APPL_DEBUG("duration = " << time << " " << etk::to_string(time.toSeconds())); + //propertySetOnWidgetNamed("progress-bar", "value", "0"); + //propertySetOnWidgetNamed("progress-bar", "max", etk::to_string(time.toSeconds())); + propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-bt-play", "value", "true"); +} + +void appl::widget::Player::suspend() { + propertySetOnWidgetNamed("[" + etk::to_string(getId()) + "]appl-player-bt-play", "value", "false"); + if (m_display == nullptr) { + return; + } + m_display->pause(); +} + + void appl::widget::Player::onCallbackButtonPrevious() { - + signalPrevious.emit(); } void appl::widget::Player::onCallbackButtonPlay(const bool& _value) { - + if (m_display == nullptr) { + return; + } + if (_value == true) { + m_display->play(); + } else { + m_display->pause(); + } } void appl::widget::Player::onCallbackButtonNext() { - + signalNext.emit(); } diff --git a/tools/player-video/appl/widget/Player.hpp b/tools/player-video/appl/widget/Player.hpp index 2df189c..e1b318f 100644 --- a/tools/player-video/appl/widget/Player.hpp +++ b/tools/player-video/appl/widget/Player.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace appl { @@ -20,6 +21,9 @@ namespace appl { public: // properties public: // signals + esignal::Signal<> signalFinished; //!< the play is finished + esignal::Signal<> signalNext; //!< Next file is requested + esignal::Signal<> signalPrevious; //!< Previous file is requested protected: Player(); @@ -27,6 +31,11 @@ namespace appl { public: DECLARE_WIDGET_FACTORY(Player, "Player"); virtual ~Player(); + protected: + ememory::SharedPtr m_display; //!< Display widget + public: + void playStream(ememory::SharedPtr _property, uint32_t _mediaId); + void suspend(); public: void onGetFocus() override; private: