Reworked the project layout
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WPushButton>
|
||||
|
||||
#include <Wt/WMediaPlayer>
|
||||
#include <Wt/WFileResource>
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
#include "database/VideoTypes.hpp"
|
||||
#include "database/MediaDirectory.hpp"
|
||||
|
||||
#include "VideoDatabaseWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
VideoDatabaseWidget::VideoDatabaseWidget(Database::Handler& db, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_db(db)
|
||||
{
|
||||
_table = new Wt::WTable( this );
|
||||
_table->setHeaderCount(1);
|
||||
|
||||
_table->addStyleClass("table form-inline");
|
||||
|
||||
_table->toggleStyleClass("table-hover", true);
|
||||
_table->toggleStyleClass("table-striped", true);
|
||||
|
||||
updateView( boost::filesystem::path(), 0);
|
||||
}
|
||||
|
||||
void
|
||||
VideoDatabaseWidget::addHeader(void)
|
||||
{
|
||||
_table->elementAt(0, 0)->addWidget(new Wt::WText("Name"));
|
||||
_table->elementAt(0, 1)->addWidget(new Wt::WText("Duration"));
|
||||
_table->elementAt(0, 2)->addWidget(new Wt::WText("Action"));
|
||||
}
|
||||
|
||||
void
|
||||
VideoDatabaseWidget::addDirectory(const std::string& name, boost::filesystem::path path, size_t depth)
|
||||
{
|
||||
|
||||
int row = _table->rowCount();
|
||||
|
||||
new Wt::WText(Wt::WString::fromUTF8( name ), _table->elementAt(row, 0));
|
||||
new Wt::WText(Wt::WString::fromUTF8( " " ), _table->elementAt(row, 1));
|
||||
|
||||
Wt::WPushButton* btn = new Wt::WPushButton(Wt::WString::fromUTF8( "Open"), _table->elementAt(row, 2));
|
||||
|
||||
btn->clicked().connect(std::bind([=] () {
|
||||
updateView(path, depth);
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoDatabaseWidget::addVideo(const std::string& name, const boost::posix_time::time_duration& duration, const boost::filesystem::path& path)
|
||||
{
|
||||
|
||||
int row = _table->rowCount();
|
||||
|
||||
new Wt::WText(Wt::WString::fromUTF8( name ), _table->elementAt(row, 0));
|
||||
new Wt::WText(Wt::WString::fromUTF8( boost::posix_time::to_simple_string( duration )), _table->elementAt(row, 1));
|
||||
|
||||
Wt::WPushButton* btn = new Wt::WPushButton(Wt::WString::fromUTF8( "Play"), _table->elementAt(row, 2));
|
||||
|
||||
btn->clicked().connect(std::bind([=] () {
|
||||
playVideo().emit(path);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoDatabaseWidget::updateView(boost::filesystem::path directory, size_t depth)
|
||||
{
|
||||
_table->clear();
|
||||
addHeader();
|
||||
|
||||
// If directory is not valid, add the root Media Directories
|
||||
if (depth == 0)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction ( _db.getSession() );
|
||||
|
||||
std::vector<Database::MediaDirectory::pointer> dirs
|
||||
= Database::MediaDirectory::getByType(_db.getSession(), Database::MediaDirectory::Video);
|
||||
|
||||
BOOST_FOREACH(Database::MediaDirectory::pointer dir, dirs)
|
||||
{
|
||||
addDirectory( dir->getPath().filename().string(),
|
||||
dir->getPath(),
|
||||
depth + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addDirectory( "..", directory.parent_path(), depth - 1);
|
||||
|
||||
// Iterators over files in the directory
|
||||
// If directory, add a directory entry
|
||||
// If video, add a video entry
|
||||
std::vector<boost::filesystem::path> paths;
|
||||
std::copy(boost::filesystem::directory_iterator(directory), boost::filesystem::directory_iterator(), std::back_inserter(paths));
|
||||
|
||||
std::sort(paths.begin(), paths.end());
|
||||
|
||||
BOOST_FOREACH(const boost::filesystem::path& path, paths)
|
||||
{
|
||||
if (boost::filesystem::is_directory(path))
|
||||
addDirectory( path.filename().string(), path, depth + 1);
|
||||
else if (boost::filesystem::is_regular(path) )
|
||||
{
|
||||
Wt::Dbo::Transaction transaction ( _db.getSession() );
|
||||
|
||||
Database::Video::pointer video = Database::Video::getByPath( _db.getSession(), path);
|
||||
if (video)
|
||||
addVideo( video->getName(), video->getDuration(), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_DB_WIDGET_HPP
|
||||
#define VIDEO_DB_WIDGET_HPP
|
||||
|
||||
#include <Wt/WTable>
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoDatabaseWidget : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
VideoDatabaseWidget( Database::Handler& db, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
// Signals
|
||||
Wt::Signal< boost::filesystem::path >& playVideo() { return _playVideo; }
|
||||
|
||||
private:
|
||||
|
||||
void addHeader(void);
|
||||
void addDirectory(const std::string& name, boost::filesystem::path path, size_t depth);
|
||||
void addVideo(const std::string& name, const boost::posix_time::time_duration& duration, const boost::filesystem::path& path);
|
||||
|
||||
void updateView(boost::filesystem::path directory, size_t depth);
|
||||
|
||||
Database::Handler& _db;
|
||||
|
||||
Wt::Signal< boost::filesystem::path > _playVideo;
|
||||
|
||||
Wt::WTable* _table;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/WMediaPlayer>
|
||||
|
||||
#include "VideoParametersDialog.hpp"
|
||||
|
||||
#include "VideoMediaPlayerWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
Wt::WMediaPlayer::Encoding
|
||||
convert(Transcode::Format format)
|
||||
{
|
||||
switch( format.getEncoding() )
|
||||
{
|
||||
case Transcode::Format::OGA: return Wt::WMediaPlayer::OGA;
|
||||
case Transcode::Format::OGV: return Wt::WMediaPlayer::OGV;
|
||||
case Transcode::Format::MP3: return Wt::WMediaPlayer::MP3;
|
||||
case Transcode::Format::WEBMA: return Wt::WMediaPlayer::WEBMA;
|
||||
case Transcode::Format::WEBMV: return Wt::WMediaPlayer::WEBMV;
|
||||
case Transcode::Format::FLV: return Wt::WMediaPlayer::FLV;
|
||||
case Transcode::Format::M4A: return Wt::WMediaPlayer::M4A;
|
||||
case Transcode::Format::M4V: return Wt::WMediaPlayer::M4V;
|
||||
}
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
VideoMediaPlayerWidget::VideoMediaPlayerWidget( const Transcode::Parameters& parameters, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_mediaResource(nullptr),
|
||||
_currentParameters(parameters),
|
||||
_dialog(nullptr)
|
||||
{
|
||||
_mediaPlayer = new Wt::WMediaPlayer( Wt::WMediaPlayer::Video, this );
|
||||
// _mediaPlayer->setAlternativeContent (new Wt::WText("You don't have HTML5 audio support!"));
|
||||
// _mediaPlayer->setOptions( Wt::WMediaPlayer::Autoplay );
|
||||
// _mediaPlayer->addSource( Wt::WMediaPlayer::WEBMV, "" );
|
||||
|
||||
{
|
||||
Wt::WContainerWidget *container = new Wt::WContainerWidget(this);
|
||||
|
||||
_playBtn = new Wt::WPushButton("Play", container );
|
||||
_pauseBtn = new Wt::WPushButton("Pause", container );
|
||||
|
||||
_curTime = new Wt::WText(container);
|
||||
_timeSlider = new Wt::WSlider( container );
|
||||
_duration = new Wt::WText(container);
|
||||
|
||||
_volumeSlider = new Wt::WSlider( container );
|
||||
_volumeSlider->setRange(0,100);
|
||||
_volumeSlider->setValue(_mediaPlayer->volume() * 100);
|
||||
|
||||
_mediaPlayer->setControlsWidget( container );
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Play, _playBtn);
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::Pause, _pauseBtn);
|
||||
|
||||
_mediaPlayer->setText( Wt::WMediaPlayer::CurrentTime, _curTime);
|
||||
_mediaPlayer->setText( Wt::WMediaPlayer::Duration, _duration);
|
||||
|
||||
_mediaPlayer->timeUpdated().connect(this, &VideoMediaPlayerWidget::handleTimeUpdated);
|
||||
|
||||
Wt::WPushButton* fullScreenButton = new Wt::WPushButton("Fullscreen", container);
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::FullScreen, fullScreenButton);
|
||||
|
||||
Wt::WPushButton* restoreScreenButton = new Wt::WPushButton("Restore screen", container);
|
||||
_mediaPlayer->setButton(Wt::WMediaPlayer::RestoreScreen, restoreScreenButton);
|
||||
|
||||
_mediaPlayer->timeUpdated().connect(this, &VideoMediaPlayerWidget::handleTimeUpdated);
|
||||
|
||||
_timeSlider->valueChanged().connect(this, &VideoMediaPlayerWidget::handlePlayOffset);
|
||||
_timeSlider->sliderMoved().connect(this, &VideoMediaPlayerWidget::handleSliderMoved);
|
||||
|
||||
_volumeSlider->sliderMoved().connect(this, &VideoMediaPlayerWidget::handleVolumeSliderMoved);
|
||||
}
|
||||
|
||||
|
||||
Wt::WPushButton* closeButton = new Wt::WPushButton("Close", this);
|
||||
closeButton->clicked().connect( this, &VideoMediaPlayerWidget::handleClose );
|
||||
|
||||
Wt::WPushButton* parametersButton = new Wt::WPushButton("Parameters", this);
|
||||
parametersButton->clicked().connect( this, &VideoMediaPlayerWidget::handleParametersEdit );
|
||||
|
||||
load(parameters);
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::load(const Transcode::Parameters& parameters)
|
||||
{
|
||||
_mediaPlayer->clearSources();
|
||||
|
||||
_currentParameters = parameters;
|
||||
|
||||
_mediaInternalLink.setResource( nullptr );
|
||||
if (_mediaResource)
|
||||
delete _mediaResource;
|
||||
|
||||
_mediaResource = new AvConvTranscodeStreamResource( parameters, this );
|
||||
_mediaInternalLink.setResource( _mediaResource );
|
||||
|
||||
_mediaPlayer->addSource( convert(parameters.getOutputFormat()), _mediaInternalLink );
|
||||
|
||||
_timeSlider->setRange(0, parameters.getInputMediaFile().getDuration().total_seconds() );
|
||||
_timeSlider->setValue( parameters.getOffset().total_seconds() );
|
||||
|
||||
_duration->setText( boost::posix_time::to_simple_string( parameters.getInputMediaFile().getDuration() ));
|
||||
|
||||
_mediaPlayer->play();
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handlePlayOffset(int offsetSecs)
|
||||
{
|
||||
std::cout << "Want to play at offset " << offsetSecs << std::endl;;
|
||||
_currentParameters.setOffset( boost::posix_time::seconds(offsetSecs) );
|
||||
load( _currentParameters );
|
||||
|
||||
_timeSlider->setValue( offsetSecs );
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleSliderMoved(int value)
|
||||
{
|
||||
std::cout << "Slider moved to " << value << std::endl;
|
||||
_curTime->setText( boost::posix_time::to_simple_string( boost::posix_time::seconds( value ) ) );
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleTimeUpdated(void)
|
||||
{
|
||||
std::cout << "Time updated to " << _mediaPlayer->currentTime() << std::endl;
|
||||
|
||||
if (_mediaPlayer->currentTime() > 0 && _mediaPlayer->currentTime() < _currentParameters.getInputMediaFile().getDuration().total_seconds())
|
||||
{
|
||||
boost::posix_time::time_duration currentTime ( boost::posix_time::seconds( _mediaPlayer->currentTime() + _currentParameters.getOffset().total_seconds()));
|
||||
|
||||
_timeSlider->setValue( currentTime.total_seconds() );
|
||||
_curTime->setText( boost::posix_time::to_simple_string( currentTime) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleVolumeSliderMoved(int value)
|
||||
{
|
||||
_mediaPlayer->setVolume( value / 100. );
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleClose(void)
|
||||
{
|
||||
_close.emit();
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleParametersEdit(void)
|
||||
{
|
||||
|
||||
_dialog = new VideoParametersDialog("Parameters");
|
||||
_dialog->load(_currentParameters);
|
||||
|
||||
_dialog->show();
|
||||
|
||||
_dialog->finished().connect(this, &VideoMediaPlayerWidget::handleParametersDone);
|
||||
}
|
||||
|
||||
void
|
||||
VideoMediaPlayerWidget::handleParametersDone(Wt::WDialog::DialogCode code)
|
||||
{
|
||||
assert(_dialog != nullptr);
|
||||
|
||||
if (code == Wt::WDialog::Accepted)
|
||||
{
|
||||
_dialog->save( _currentParameters );
|
||||
|
||||
// TODO SYNC current offset with player?
|
||||
// HACK use slider current value
|
||||
handlePlayOffset( _timeSlider->value());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __VIDEO_MEDIA_PLAYER_WIDGET_HPP
|
||||
#define __VIDEO_MEDIA_PLAYER_WIDGET_HPP
|
||||
|
||||
#include <Wt/WDialog>
|
||||
#include <Wt/WSlider>
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WLink>
|
||||
|
||||
#include "VideoParametersDialog.hpp"
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
#include "resource/AvConvTranscodeStreamResource.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoMediaPlayerWidget : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
VideoMediaPlayerWidget( const Transcode::Parameters& parameters, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
|
||||
Wt::Signal<void>& close() { return _close; };
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Signals
|
||||
Wt::Signal<void> _close;
|
||||
|
||||
void load(const Transcode::Parameters& parameters);
|
||||
|
||||
// Player controls
|
||||
void handlePlayOffset(int offsetSecs);
|
||||
void handleTimeUpdated(void);
|
||||
void handleSliderMoved(int value);
|
||||
void handleFullscreen(void);
|
||||
void handleVolumeSliderMoved(int value);
|
||||
|
||||
void handleClose(void);
|
||||
|
||||
void handleParametersEdit(void);
|
||||
void handleParametersDone(Wt::WDialog::DialogCode);
|
||||
|
||||
// Core
|
||||
Wt::WMediaPlayer* _mediaPlayer;
|
||||
AvConvTranscodeStreamResource* _mediaResource;
|
||||
Wt::WLink _mediaInternalLink;
|
||||
|
||||
// Controls
|
||||
Transcode::Parameters _currentParameters;
|
||||
Wt::WPushButton* _playBtn;
|
||||
Wt::WPushButton* _pauseBtn;
|
||||
Wt::WSlider* _timeSlider;
|
||||
Wt::WSlider* _volumeSlider;
|
||||
Wt::WText* _curTime;
|
||||
Wt::WText* _duration;
|
||||
|
||||
VideoParametersDialog* _dialog;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WLabel>
|
||||
#include <Wt/WTable>
|
||||
|
||||
#include "VideoParametersDialog.hpp"
|
||||
|
||||
using namespace Transcode;
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
static const std::list<Stream::Type> streamTypes = {Stream::Video, Stream::Audio, Stream::Subtitle};
|
||||
|
||||
VideoParametersDialog::VideoParametersDialog(const Wt::WString &windowTitle, Wt::WDialog* parent)
|
||||
: Wt::WDialog(windowTitle, parent)
|
||||
{
|
||||
|
||||
Wt::WTable* layout = new Wt::WTable(contents());
|
||||
int row = 0;
|
||||
|
||||
{
|
||||
Wt::WLabel* label = new Wt::WLabel("Format");
|
||||
_outputFormat = new Wt::WComboBox();
|
||||
label->setBuddy(_outputFormat);
|
||||
|
||||
layout->elementAt(row, 0)->addWidget(label);
|
||||
layout->elementAt(row, 1)->addWidget(_outputFormat);
|
||||
|
||||
_outputFormatModel = new Wt::WStringListModel(_outputFormat);
|
||||
|
||||
std::vector<Format> formats = Format::get( Format::Video );
|
||||
|
||||
for(std::size_t idFormat = 0; idFormat < formats.size(); ++idFormat)
|
||||
{
|
||||
_outputFormatModel->addString(formats[idFormat].getDesc());
|
||||
_outputFormatModel->setData(idFormat, 0, formats[idFormat].getEncoding(), Wt::UserRole);
|
||||
}
|
||||
|
||||
_outputFormat->setModel(_outputFormatModel);
|
||||
|
||||
row++;
|
||||
}
|
||||
|
||||
createStreamWidgets("Video", Stream::Video, layout);
|
||||
createStreamWidgets("Audio", Stream::Audio, layout);
|
||||
createStreamWidgets("Subtitles", Stream::Subtitle, layout);
|
||||
|
||||
Wt::WPushButton *ok = new Wt::WPushButton("Apply", contents());
|
||||
ok->clicked().connect(this, &Wt::WDialog::accept);
|
||||
|
||||
Wt::WPushButton *cancel = new Wt::WPushButton("Cancel", contents());
|
||||
cancel->clicked().connect(this, &Wt::WDialog::reject);
|
||||
}
|
||||
|
||||
void
|
||||
VideoParametersDialog::createStreamWidgets(const Wt::WString& labelString, Transcode::Stream::Type type, Wt::WTable* layout)
|
||||
{
|
||||
int row = layout->rowCount();
|
||||
|
||||
Wt::WLabel* label = new Wt::WLabel(labelString);
|
||||
Wt::WComboBox *combo = new Wt::WComboBox();
|
||||
label->setBuddy(combo);
|
||||
|
||||
layout->elementAt(row, 0)->addWidget(label);
|
||||
layout->elementAt(row, 1)->addWidget(combo);
|
||||
|
||||
Wt::WStringListModel* model = new Wt::WStringListModel(combo);
|
||||
|
||||
combo->setModel(model);
|
||||
|
||||
_streamSelection.insert( std::make_pair(type, std::make_pair(combo, model) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoParametersDialog::handleApply()
|
||||
{
|
||||
_apply.emit();
|
||||
}
|
||||
|
||||
void
|
||||
VideoParametersDialog::addStreams(Wt::WStringListModel* model, const std::vector<Stream>& streams)
|
||||
{
|
||||
for (std::size_t idStream = 0; idStream < streams.size(); ++idStream)
|
||||
{
|
||||
const Stream& stream = streams[idStream];
|
||||
|
||||
std::ostringstream oss;
|
||||
if (!stream.getLanguage().empty())
|
||||
oss << "[" << stream.getLanguage() << "] ";
|
||||
|
||||
oss << stream.getDesc();
|
||||
|
||||
model->addString(oss.str());
|
||||
model->setData(idStream, 0, stream.getId(), Wt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VideoParametersDialog::selectStream(const Wt::WStringListModel* model, Stream::Id streamId, Wt::WComboBox* combo)
|
||||
{
|
||||
for (int idStream = 0; idStream < model->rowCount(); ++idStream)
|
||||
{
|
||||
Stream::Id id = boost::any_cast<Stream::Id>( model->data( model->index(idStream, 0), Wt::UserRole));
|
||||
if (id == streamId)
|
||||
{
|
||||
combo->setCurrentIndex(idStream);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoParametersDialog::load(const Transcode::Parameters& parameters)
|
||||
{
|
||||
// Select proper encoding
|
||||
for (int row = 0; row < _outputFormat->count(); ++row)
|
||||
{
|
||||
Format::Encoding encoding = boost::any_cast<Format::Encoding>( _outputFormatModel->data(_outputFormatModel->index(row,0), Wt::UserRole));
|
||||
if (encoding == parameters.getOutputFormat().getEncoding()) {
|
||||
_outputFormat->setCurrentIndex(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the current selected input streams
|
||||
Parameters::StreamMap streamMap = parameters.getInputStreams();;
|
||||
|
||||
// Populate the combox with the available streams
|
||||
// And then show the selected one
|
||||
BOOST_FOREACH(Stream::Type streamType, streamTypes)
|
||||
{
|
||||
Wt::WComboBox* combo = _streamSelection[streamType].first;
|
||||
Wt::WStringListModel* model = _streamSelection[streamType].second;
|
||||
|
||||
addStreams(model, parameters.getInputMediaFile().getStreams( streamType ) );
|
||||
|
||||
selectStream(model, streamMap[streamType], combo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
VideoParametersDialog::save(Transcode::Parameters& parameters)
|
||||
{
|
||||
std::cout << "Grabbing user input!" << std::endl;
|
||||
|
||||
// Get encoder used
|
||||
Format::Encoding encoding = boost::any_cast<Format::Encoding>( _outputFormatModel->data(_outputFormatModel->index(_outputFormat->currentIndex(), 0), Wt::UserRole));
|
||||
parameters.setOutputFormat( Format::get(encoding) );
|
||||
|
||||
// Get stream selected, if any
|
||||
BOOST_FOREACH(Stream::Type streamType, streamTypes)
|
||||
{
|
||||
Wt::WComboBox* combo = _streamSelection[streamType].first;
|
||||
Wt::WStringListModel* model = _streamSelection[streamType].second;
|
||||
|
||||
if (combo->currentIndex() >= 0)
|
||||
{
|
||||
Stream::Id streamId = boost::any_cast<Stream::Id>( model->data(model->index(combo->currentIndex(), 0), Wt::UserRole));
|
||||
|
||||
parameters.selectInputStream(streamType, streamId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_PARAMETER_DIALOG
|
||||
#define VIDEO_PARAMETER_DIALOG
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <Wt/WSignal>
|
||||
#include <Wt/WDialog>
|
||||
#include <Wt/WComboBox>
|
||||
#include <Wt/WStringListModel>
|
||||
#include <Wt/WString>
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoParametersDialog : public Wt::WDialog
|
||||
{
|
||||
public:
|
||||
// parameters to be edited
|
||||
VideoParametersDialog(const Wt::WString &windowTitle, Wt::WDialog* parent = 0);
|
||||
|
||||
// Populates widget contents using these paramaters
|
||||
void load(const Transcode::Parameters& parameters);
|
||||
|
||||
// Save widgets contents into these parameters
|
||||
void save(Transcode::Parameters& parameters);
|
||||
|
||||
// Signal to be emitted if parameters are changed
|
||||
Wt::Signal<void>& apply() { return _apply; }
|
||||
|
||||
private:
|
||||
|
||||
void handleApply(void);
|
||||
|
||||
// Stream handling
|
||||
void createStreamWidgets(const Wt::WString& label, Transcode::Stream::Type type, Wt::WTable* layout);
|
||||
void addStreams(Wt::WStringListModel* model, const std::vector<Transcode::Stream>& streams);
|
||||
void selectStream(const Wt::WStringListModel* model, Transcode::Stream::Id streamId, Wt::WComboBox* combo);
|
||||
|
||||
Wt::Signal<void> _apply;
|
||||
|
||||
Wt::WComboBox* _outputFormat;
|
||||
Wt::WStringListModel* _outputFormatModel;
|
||||
|
||||
std::map<Transcode::Stream::Type, std::pair<Wt::WComboBox*, Wt::WStringListModel* > > _streamSelection;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WEnvironment>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "VideoWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
VideoWidget::VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent )
|
||||
: Wt::WContainerWidget(parent),
|
||||
_sessionData(sessionData)
|
||||
{
|
||||
|
||||
_videoDbWidget = new VideoDatabaseWidget(_sessionData.getDatabaseHandler(), this);
|
||||
|
||||
_videoDbWidget->playVideo().connect(this, &VideoWidget::playVideo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoWidget::search(const std::string& searchText)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void
|
||||
VideoWidget::backToList(void)
|
||||
{
|
||||
if (_mediaPlayer)
|
||||
delete _mediaPlayer;
|
||||
|
||||
_videoDbWidget->setHidden(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VideoWidget::playVideo(boost::filesystem::path p)
|
||||
{
|
||||
LMS_LOG(MOD_UI, SEV_DEBUG) << "Want to play video " << p << "'" << std::endl;
|
||||
try {
|
||||
|
||||
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;
|
||||
|
||||
if (Wt::WApplication::instance()->environment().agentIsChrome())
|
||||
encoding = Transcode::Format::WEBMV;
|
||||
else
|
||||
encoding = Transcode::Format::FLV;
|
||||
|
||||
Transcode::Parameters parameters(inputFile, Transcode::Format::get(encoding));
|
||||
|
||||
// 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);
|
||||
|
||||
_videoDbWidget->setHidden(true);
|
||||
}
|
||||
catch( std::exception& e) {
|
||||
LMS_LOG(MOD_UI, SEV_ERROR) << "Caught exception while loading '" << p << "': " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_WIDGET_HPP
|
||||
#define VIDEO_WIDGET_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
#include "video/VideoMediaPlayerWidget.hpp"
|
||||
#include "video/VideoDatabaseWidget.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoWidget : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
|
||||
VideoWidget(SessionData& sessionData, Wt::WContainerWidget* parent = 0);
|
||||
|
||||
void search(const std::string& searchText);
|
||||
|
||||
private:
|
||||
|
||||
void backToList(void);
|
||||
void playVideo(boost::filesystem::path p);
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
VideoDatabaseWidget* _videoDbWidget;
|
||||
VideoMediaPlayerWidget* _mediaPlayer;
|
||||
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user