diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-04-04 10:13:41 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-04-04 10:13:41 +0100 |
| commit | 6bc12a2eeb9c84a539688f2f7eb876e3ea278a9f (patch) | |
| tree | 80339d65a1c1d6bfefc5ad164617f9b589220b10 /src/lib | |
| parent | d0c2e5d14224e0d1058a9b7058f88e6b32dc8e6f (diff) | |
Split playlist files up; fix build.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ab_transcoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/analyse_audio_job.cc | 2 | ||||
| -rw-r--r-- | src/lib/encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/film.cc | 1 | ||||
| -rw-r--r-- | src/lib/player.cc | 280 | ||||
| -rw-r--r-- | src/lib/player.h | 77 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 250 | ||||
| -rw-r--r-- | src/lib/playlist.h | 39 | ||||
| -rw-r--r-- | src/lib/transcoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/writer.cc | 2 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
11 files changed, 364 insertions, 294 deletions
diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc index 6bf092fee..81aa5a4ba 100644 --- a/src/lib/ab_transcoder.cc +++ b/src/lib/ab_transcoder.cc @@ -24,7 +24,7 @@ #include "encoder.h" #include "job.h" #include "image.h" -#include "playlist.h" +#include "player.h" #include "matcher.h" #include "delay_line.h" #include "gain.h" diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc index e2c9c5b18..5ef6515dd 100644 --- a/src/lib/analyse_audio_job.cc +++ b/src/lib/analyse_audio_job.cc @@ -21,7 +21,7 @@ #include "analyse_audio_job.h" #include "compose.hpp" #include "film.h" -#include "playlist.h" +#include "player.h" #include "i18n.h" diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index a41ebec51..2a8d8cc16 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -37,7 +37,7 @@ #include "format.h" #include "cross.h" #include "writer.h" -#include "playlist.h" +#include "player.h" #include "i18n.h" diff --git a/src/lib/film.cc b/src/lib/film.cc index b21b3454d..42f4b1c3d 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -53,6 +53,7 @@ #include "sndfile_decoder.h" #include "analyse_audio_job.h" #include "playlist.h" +#include "player.h" #include "ffmpeg_content.h" #include "imagemagick_content.h" #include "sndfile_content.h" diff --git a/src/lib/player.cc b/src/lib/player.cc new file mode 100644 index 000000000..6e2e7ed14 --- /dev/null +++ b/src/lib/player.cc @@ -0,0 +1,280 @@ +/* + Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "player.h" +#include "film.h" +#include "ffmpeg_decoder.h" +#include "imagemagick_decoder.h" +#include "sndfile_decoder.h" +#include "playlist.h" +#include "job.h" + +using std::list; +using boost::shared_ptr; + +Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p) + : _film (f) + , _playlist (p) + , _video (true) + , _audio (true) + , _subtitles (true) + , _have_setup_decoders (false) + , _ffmpeg_decoder_done (false) + , _video_sync (true) +{ + +} + +void +Player::disable_video () +{ + _video = false; +} + +void +Player::disable_audio () +{ + _audio = false; +} + +void +Player::disable_subtitles () +{ + _subtitles = false; +} + +bool +Player::pass () +{ + if (!_have_setup_decoders) { + setup_decoders (); + _have_setup_decoders = true; + } + + bool done = true; + + if (_playlist->video_from() == Playlist::VIDEO_FFMPEG || _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { + if (!_ffmpeg_decoder_done) { + if (_ffmpeg_decoder->pass ()) { + _ffmpeg_decoder_done = true; + } else { + done = false; + } + } + } + + if (_playlist->video_from() == Playlist::VIDEO_IMAGEMAGICK) { + if (_imagemagick_decoder != _imagemagick_decoders.end ()) { + if ((*_imagemagick_decoder)->pass ()) { + _imagemagick_decoder++; + } + + if (_imagemagick_decoder != _imagemagick_decoders.end ()) { + done = false; + } + } + } + + /* XXX: sndfile */ + + return done; +} + +void +Player::set_progress (shared_ptr<Job> job) +{ + /* Assume progress can be divined from how far through the video we are */ + switch (_playlist->video_from ()) { + case Playlist::VIDEO_NONE: + break; + case Playlist::VIDEO_FFMPEG: + if (_playlist->video_length ()) { + job->set_progress (float(_ffmpeg_decoder->video_frame()) / _playlist->video_length ()); + } + break; + case Playlist::VIDEO_IMAGEMAGICK: + { + int n = 0; + for (list<shared_ptr<ImageMagickDecoder> >::iterator i = _imagemagick_decoders.begin(); i != _imagemagick_decoders.end(); ++i) { + if (_imagemagick_decoder == i) { + job->set_progress (float (n) / _imagemagick_decoders.size ()); + } + ++n; + } + break; + } + } +} + +void +Player::process_video (shared_ptr<Image> i, bool same, shared_ptr<Subtitle> s) +{ + Video (i, same, s); +} + +void +Player::process_audio (shared_ptr<AudioBuffers> b) +{ + Audio (b); +} + +/** @return true on error */ +bool +Player::seek (double t) +{ + if (!_have_setup_decoders) { + setup_decoders (); + _have_setup_decoders = true; + } + + bool r = false; + + switch (_playlist->video_from()) { + case Playlist::VIDEO_NONE: + break; + case Playlist::VIDEO_FFMPEG: + if (!_ffmpeg_decoder || _ffmpeg_decoder->seek (t)) { + r = true; + } + /* We're seeking, so all `all done' bets are off */ + _ffmpeg_decoder_done = false; + break; + case Playlist::VIDEO_IMAGEMAGICK: + /* Find the decoder that contains this position */ + _imagemagick_decoder = _imagemagick_decoders.begin (); + while (_imagemagick_decoder != _imagemagick_decoders.end ()) { + double const this_length = (*_imagemagick_decoder)->video_length() / _film->video_frame_rate (); + if (t < this_length) { + break; + } + t -= this_length; + ++_imagemagick_decoder; + } + + if (_imagemagick_decoder != _imagemagick_decoders.end()) { + (*_imagemagick_decoder)->seek (t); + } else { + r = true; + } + break; + } + + /* XXX: don't seek audio because we don't need to... */ + + return r; +} + +bool +Player::seek_to_last () +{ + if (!_have_setup_decoders) { + setup_decoders (); + _have_setup_decoders = true; + } + + bool r = false; + + switch (_playlist->video_from ()) { + case Playlist::VIDEO_NONE: + break; + case Playlist::VIDEO_FFMPEG: + if (!_ffmpeg_decoder || _ffmpeg_decoder->seek_to_last ()) { + r = true; + } + + /* We're seeking, so all `all done' bets are off */ + _ffmpeg_decoder_done = false; + break; + case Playlist::VIDEO_IMAGEMAGICK: + if ((*_imagemagick_decoder)->seek_to_last ()) { + r = true; + } + break; + } + + /* XXX: don't seek audio because we don't need to... */ + + return r; +} + +void +Player::setup_decoders () +{ + if ((_video && _playlist->video_from() == Playlist::VIDEO_FFMPEG) || (_audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG)) { + _ffmpeg_decoder.reset ( + new FFmpegDecoder ( + _film, + _playlist->ffmpeg(), + _video && _playlist->video_from() == Playlist::VIDEO_FFMPEG, + _audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG, + _subtitles && _film->with_subtitles(), + _video_sync + ) + ); + } + + if (_video && _playlist->video_from() == Playlist::VIDEO_FFMPEG) { + _ffmpeg_decoder->connect_video (shared_from_this ()); + } + + if (_audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { + _ffmpeg_decoder->connect_audio (shared_from_this ()); + } + + if (_video && _playlist->video_from() == Playlist::VIDEO_IMAGEMAGICK) { + list<shared_ptr<const ImageMagickContent> > ic = _playlist->imagemagick (); + for (list<shared_ptr<const ImageMagickContent> >::iterator i = ic.begin(); i != ic.end(); ++i) { + shared_ptr<ImageMagickDecoder> d (new ImageMagickDecoder (_film, *i)); + _imagemagick_decoders.push_back (d); + d->connect_video (shared_from_this ()); + } + + _imagemagick_decoder = _imagemagick_decoders.begin (); + } + + if (_audio && _playlist->audio_from() == Playlist::AUDIO_SNDFILE) { + list<shared_ptr<const SndfileContent> > sc = _playlist->sndfile (); + for (list<shared_ptr<const SndfileContent> >::iterator i = sc.begin(); i != sc.end(); ++i) { + shared_ptr<SndfileDecoder> d (new SndfileDecoder (_film, *i)); + _sndfile_decoders.push_back (d); + d->connect_audio (shared_from_this ()); + } + } +} + +void +Player::disable_video_sync () +{ + _video_sync = false; +} + +double +Player::last_video_time () const +{ + switch (_playlist->video_from ()) { + case Playlist::VIDEO_NONE: + return 0; + case Playlist::VIDEO_FFMPEG: + return _ffmpeg_decoder->last_source_time (); + case Playlist::VIDEO_IMAGEMAGICK: + return (*_imagemagick_decoder)->last_source_time (); + } + + return 0; +} diff --git a/src/lib/player.h b/src/lib/player.h new file mode 100644 index 000000000..bc728d8f2 --- /dev/null +++ b/src/lib/player.h @@ -0,0 +1,77 @@ +/* + Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef DVDOMATIC_PLAYER_H +#define DVDOMATIC_PLAYER_H + +#include <list> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include "video_source.h" +#include "audio_source.h" +#include "video_sink.h" +#include "audio_sink.h" + +class FFmpegDecoder; +class ImageMagickDecoder; +class SndfileDecoder; +class Job; +class Film; +class Playlist; + +class Player : public VideoSource, public AudioSource, public VideoSink, public AudioSink, public boost::enable_shared_from_this<Player> +{ +public: + Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist>); + + void disable_video (); + void disable_audio (); + void disable_subtitles (); + void disable_video_sync (); + + bool pass (); + void set_progress (boost::shared_ptr<Job>); + bool seek (double); + bool seek_to_last (); + + double last_video_time () const; + +private: + void process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s); + void process_audio (boost::shared_ptr<AudioBuffers>); + void setup_decoders (); + + boost::shared_ptr<const Film> _film; + boost::shared_ptr<const Playlist> _playlist; + + bool _video; + bool _audio; + bool _subtitles; + + bool _have_setup_decoders; + boost::shared_ptr<FFmpegDecoder> _ffmpeg_decoder; + bool _ffmpeg_decoder_done; + std::list<boost::shared_ptr<ImageMagickDecoder> > _imagemagick_decoders; + std::list<boost::shared_ptr<ImageMagickDecoder> >::iterator _imagemagick_decoder; + std::list<boost::shared_ptr<SndfileDecoder> > _sndfile_decoders; + + bool _video_sync; +}; + +#endif diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index a7862f116..0a4803f6e 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -208,253 +208,3 @@ Playlist::has_audio () const return _audio_from != AUDIO_NONE; } -Player::Player (boost::shared_ptr<const Film> f, boost::shared_ptr<const Playlist> p) - : _film (f) - , _playlist (p) - , _video (true) - , _audio (true) - , _subtitles (true) - , _have_setup_decoders (false) - , _ffmpeg_decoder_done (false) - , _video_sync (true) -{ - -} - -void -Player::disable_video () -{ - _video = false; -} - -void -Player::disable_audio () -{ - _audio = false; -} - -void -Player::disable_subtitles () -{ - _subtitles = false; -} - -bool -Player::pass () -{ - if (!_have_setup_decoders) { - setup_decoders (); - _have_setup_decoders = true; - } - - bool done = true; - - if (_playlist->video_from() == Playlist::VIDEO_FFMPEG || _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { - if (!_ffmpeg_decoder_done) { - if (_ffmpeg_decoder->pass ()) { - _ffmpeg_decoder_done = true; - } else { - done = false; - } - } - } - - if (_playlist->video_from() == Playlist::VIDEO_IMAGEMAGICK) { - if (_imagemagick_decoder != _imagemagick_decoders.end ()) { - if ((*_imagemagick_decoder)->pass ()) { - _imagemagick_decoder++; - } - - if (_imagemagick_decoder != _imagemagick_decoders.end ()) { - done = false; - } - } - } - - /* XXX: sndfile */ - - return done; -} - -void -Player::set_progress (shared_ptr<Job> job) -{ - /* Assume progress can be divined from how far through the video we are */ - switch (_playlist->video_from ()) { - case Playlist::VIDEO_NONE: - break; - case Playlist::VIDEO_FFMPEG: - if (_playlist->video_length ()) { - job->set_progress (float(_ffmpeg_decoder->video_frame()) / _playlist->video_length ()); - } - break; - case Playlist::VIDEO_IMAGEMAGICK: - { - int n = 0; - for (std::list<boost::shared_ptr<ImageMagickDecoder> >::iterator i = _imagemagick_decoders.begin(); i != _imagemagick_decoders.end(); ++i) { - if (_imagemagick_decoder == i) { - job->set_progress (float (n) / _imagemagick_decoders.size ()); - } - ++n; - } - break; - } - } -} - -void -Player::process_video (shared_ptr<Image> i, bool same, shared_ptr<Subtitle> s) -{ - Video (i, same, s); -} - -void -Player::process_audio (shared_ptr<AudioBuffers> b) -{ - Audio (b); -} - -/** @return true on error */ -bool -Player::seek (double t) -{ - if (!_have_setup_decoders) { - setup_decoders (); - _have_setup_decoders = true; - } - - bool r = false; - - switch (_playlist->video_from()) { - case Playlist::VIDEO_NONE: - break; - case Playlist::VIDEO_FFMPEG: - if (!_ffmpeg_decoder || _ffmpeg_decoder->seek (t)) { - r = true; - } - /* We're seeking, so all `all done' bets are off */ - _ffmpeg_decoder_done = false; - break; - case Playlist::VIDEO_IMAGEMAGICK: - /* Find the decoder that contains this position */ - _imagemagick_decoder = _imagemagick_decoders.begin (); - while (_imagemagick_decoder != _imagemagick_decoders.end ()) { - double const this_length = (*_imagemagick_decoder)->video_length() / _film->video_frame_rate (); - if (t < this_length) { - break; - } - t -= this_length; - ++_imagemagick_decoder; - } - - if (_imagemagick_decoder != _imagemagick_decoders.end()) { - (*_imagemagick_decoder)->seek (t); - } else { - r = true; - } - break; - } - - /* XXX: don't seek audio because we don't need to... */ - - return r; -} - -bool -Player::seek_to_last () -{ - if (!_have_setup_decoders) { - setup_decoders (); - _have_setup_decoders = true; - } - - bool r = false; - - switch (_playlist->video_from ()) { - case Playlist::VIDEO_NONE: - break; - case Playlist::VIDEO_FFMPEG: - if (!_ffmpeg_decoder || _ffmpeg_decoder->seek_to_last ()) { - r = true; - } - - /* We're seeking, so all `all done' bets are off */ - _ffmpeg_decoder_done = false; - break; - case Playlist::VIDEO_IMAGEMAGICK: - if ((*_imagemagick_decoder)->seek_to_last ()) { - r = true; - } - break; - } - - /* XXX: don't seek audio because we don't need to... */ - - return r; -} - -void -Player::setup_decoders () -{ - if ((_video && _playlist->video_from() == Playlist::VIDEO_FFMPEG) || (_audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG)) { - _ffmpeg_decoder.reset ( - new FFmpegDecoder ( - _film, - _playlist->ffmpeg(), - _video && _playlist->video_from() == Playlist::VIDEO_FFMPEG, - _audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG, - _subtitles && _film->with_subtitles(), - _video_sync - ) - ); - } - - if (_video && _playlist->video_from() == Playlist::VIDEO_FFMPEG) { - _ffmpeg_decoder->connect_video (shared_from_this ()); - } - - if (_audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { - _ffmpeg_decoder->connect_audio (shared_from_this ()); - } - - if (_video && _playlist->video_from() == Playlist::VIDEO_IMAGEMAGICK) { - list<shared_ptr<const ImageMagickContent> > ic = _playlist->imagemagick (); - for (list<shared_ptr<const ImageMagickContent> >::iterator i = ic.begin(); i != ic.end(); ++i) { - shared_ptr<ImageMagickDecoder> d (new ImageMagickDecoder (_film, *i)); - _imagemagick_decoders.push_back (d); - d->connect_video (shared_from_this ()); - } - - _imagemagick_decoder = _imagemagick_decoders.begin (); - } - - if (_audio && _playlist->audio_from() == Playlist::AUDIO_SNDFILE) { - list<shared_ptr<const SndfileContent> > sc = _playlist->sndfile (); - for (list<shared_ptr<const SndfileContent> >::iterator i = sc.begin(); i != sc.end(); ++i) { - shared_ptr<SndfileDecoder> d (new SndfileDecoder (_film, *i)); - _sndfile_decoders.push_back (d); - d->connect_audio (shared_from_this ()); - } - } -} - -void -Player::disable_video_sync () -{ - _video_sync = false; -} - -double -Player::last_video_time () const -{ - switch (_playlist->video_from ()) { - case Playlist::VIDEO_NONE: - return 0; - case Playlist::VIDEO_FFMPEG: - return _ffmpeg_decoder->last_source_time (); - case Playlist::VIDEO_IMAGEMAGICK: - return (*_imagemagick_decoder)->last_source_time (); - } - - return 0; -} diff --git a/src/lib/playlist.h b/src/lib/playlist.h index 480f1b2ed..29a52d433 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -93,42 +93,3 @@ private: std::list<boost::shared_ptr<const ImageMagickContent> > _imagemagick; std::list<boost::shared_ptr<const SndfileContent> > _sndfile; }; - -class Player : public VideoSource, public AudioSource, public VideoSink, public AudioSink, public boost::enable_shared_from_this<Player> -{ -public: - Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist>); - - void disable_video (); - void disable_audio (); - void disable_subtitles (); - void disable_video_sync (); - - bool pass (); - void set_progress (boost::shared_ptr<Job>); - bool seek (double); - bool seek_to_last (); - - double last_video_time () const; - -private: - void process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s); - void process_audio (boost::shared_ptr<AudioBuffers>); - void setup_decoders (); - - boost::shared_ptr<const Film> _film; - boost::shared_ptr<const Playlist> _playlist; - - bool _video; - bool _audio; - bool _subtitles; - - bool _have_setup_decoders; - boost::shared_ptr<FFmpegDecoder> _ffmpeg_decoder; - bool _ffmpeg_decoder_done; - std::list<boost::shared_ptr<ImageMagickDecoder> > _imagemagick_decoders; - std::list<boost::shared_ptr<ImageMagickDecoder> >::iterator _imagemagick_decoder; - std::list<boost::shared_ptr<SndfileDecoder> > _sndfile_decoders; - - bool _video_sync; -}; diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index ef3a0e8c1..6744e9193 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -34,7 +34,7 @@ #include "gain.h" #include "video_decoder.h" #include "audio_decoder.h" -#include "playlist.h" +#include "player.h" using std::string; using boost::shared_ptr; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index b08b9caf1..d413d33f3 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -28,7 +28,7 @@ #include "format.h" #include "log.h" #include "dcp_video_frame.h" -#include "playlist.h" +#include "player.h" #include "i18n.h" diff --git a/src/lib/wscript b/src/lib/wscript index f2bb678aa..32a2cde23 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -38,6 +38,7 @@ sources = """ log.cc lut.cc matcher.cc + player.cc playlist.cc scp_dcp_job.cc scaler.cc |
