From 55bdc9795f34e713930d0425a9643f7c035f89ed Mon Sep 17 00:00:00 2001 From: emeric Date: Sun, 14 Sep 2014 17:12:57 +0200 Subject: [PATCH] WIP. some transcoding parameters update for video widget --- ui/audio/AudioWidget.cpp | 6 ++++-- ui/video/VideoWidget.cpp | 34 +++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ui/audio/AudioWidget.cpp b/ui/audio/AudioWidget.cpp index 3bafe42b..0473d452 100644 --- a/ui/audio/AudioWidget.cpp +++ b/ui/audio/AudioWidget.cpp @@ -51,12 +51,14 @@ AudioWidget::playTrack(boost::filesystem::path p) if (user) bitrate = user->getAudioBitrate(); else + { + LMS_LOG(MOD_UI, SEV_ERROR) << "Can't play video: user does not exists!"; return; // TODO logout? + } } Transcode::InputMediaFile inputFile(p); - // TODO get the input stream bitrate and min the result with the desired bitrate Transcode::Parameters parameters(inputFile, Transcode::Format::get(Transcode::Format::OGA)); parameters.setBitrate(Transcode::Stream::Audio, bitrate); @@ -70,7 +72,7 @@ AudioWidget::playTrack(boost::filesystem::path p) if (!covers.empty()) { LMS_LOG(MOD_UI, SEV_DEBUG) << "Cover found!"; - if (!covers.front().scale(256)) + if (!covers.front().scale(256)) // TODO LMS_LOG(MOD_UI, SEV_ERROR) << "Cannot resize!"; //_imgResource->setMimeType(covers.front().getMimeType()); diff --git a/ui/video/VideoWidget.cpp b/ui/video/VideoWidget.cpp index d5356a2b..ef3465af 100644 --- a/ui/video/VideoWidget.cpp +++ b/ui/video/VideoWidget.cpp @@ -1,6 +1,8 @@ #include #include +#include "logger/Logger.hpp" + #include "VideoWidget.hpp" namespace UserInterface { @@ -38,10 +40,30 @@ VideoWidget::backToList(void) void VideoWidget::playVideo(boost::filesystem::path p) { - std::cout << "Want to play video " << p << "'" << std::endl; + LMS_LOG(MOD_UI, SEV_DEBUG) << "Want to play video " << p << "'" << std::endl; try { - // TODO get user's encoding preference + std::size_t audioBitrate = 0; + std::size_t videoBitrate = 0; + + // Get user preferences + { + Wt::Dbo::Transaction transaction(_sessionData.getDatabaseHandler().getSession()); + Database::User::pointer user = _sessionData.getDatabaseHandler().getCurrentUser(); + if (user) + { + audioBitrate = user->getMaxAudioBitrate(); + videoBitrate = user->getMaxVideoBitrate(); + } + else + { + LMS_LOG(MOD_UI, SEV_ERROR) << "Can't play video: user does not exists!"; + return; // TODO logout? + } + } + + LMS_LOG(MOD_UI, SEV_DEBUG) << "Max bitrate set to " << videoBitrate << "/" << audioBitrate; + Transcode::InputMediaFile inputFile(p); Transcode::Format::Encoding encoding; @@ -53,8 +75,10 @@ VideoWidget::playVideo(boost::filesystem::path p) Transcode::Parameters parameters(inputFile, Transcode::Format::get(encoding)); - parameters.setBitrate(Transcode::Stream::Audio, 128000); // TODO - parameters.setBitrate(Transcode::Stream::Video, 500000); // TODO + // TODO, make a quality button in order to choose... + + parameters.setBitrate(Transcode::Stream::Audio, 0/*audioBitrate*/); + parameters.setBitrate(Transcode::Stream::Video, 0/*videoBitrate*/); _mediaPlayer = new VideoMediaPlayerWidget(parameters, this); _mediaPlayer->close().connect(this, &VideoWidget::backToList); @@ -62,7 +86,7 @@ VideoWidget::playVideo(boost::filesystem::path p) _videoDbWidget->setHidden(true); } catch( std::exception& e) { - std::cerr <<"Caught exception while loading '" << p << "': " << e.what() << std::endl; + LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception while loading '" << p << "': " << e.what() << std::endl; } }