}
out->set_frames (frames);
- write_audio (out);
+ _writer->write (out);
}
swr_free (&_swr_context);
}
#endif
- write_audio (data);
+ _writer->write (data);
}
void
_condition.notify_all ();
}
}
-
-void
-Encoder::write_audio (shared_ptr<const AudioBuffers> data)
-{
-#if 0
- XXX
- AutomaticAudioMapping m (_film->audio_channels ());
- if (m.dcp_channels() != _film->audio_channels()) {
-
- /* Remap (currently just for mono -> 5.1) */
-
- shared_ptr<AudioBuffers> b (new AudioBuffers (m.dcp_channels(), data->frames ()));
- for (int i = 0; i < m.dcp_channels(); ++i) {
- optional<int> s = m.dcp_to_source (static_cast<libdcp::Channel> (i));
- if (!s) {
- b->make_silent (i);
- } else {
- memcpy (b->data()[i], data->data()[s.get()], data->frames() * sizeof(float));
- }
- }
-
- data = b;
- }
-#endif
-
- _writer->write (data);
-}
void frame_done ();
- void write_audio (boost::shared_ptr<const AudioBuffers> data);
-
void encoder_thread (ServerDescription *);
void terminate_threads ();
#include "ffmpeg_decoder.h"
#include "imagemagick_decoder.h"
#include "sndfile_decoder.h"
+#include "sndfile_content.h"
#include "playlist.h"
#include "job.h"
}
}
- /* XXX: sndfile */
+ if (_playlist->audio_from() == Playlist::AUDIO_SNDFILE) {
+ for (list<shared_ptr<SndfileDecoder> >::iterator i = _sndfile_decoders.begin(); i != _sndfile_decoders.end(); ++i) {
+ if (!(*i)->pass ()) {
+ done = false;
+ }
+ }
+
+ Audio (_sndfile_buffers);
+ _sndfile_buffers.reset ();
+ }
return done;
}
}
void
-Player::process_audio (shared_ptr<AudioBuffers> b)
+Player::process_audio (weak_ptr<const AudioContent> c, shared_ptr<AudioBuffers> b)
{
- Audio (b);
+ if (_playlist->audio_from() == Playlist::AUDIO_SNDFILE) {
+ AudioMapping mapping = _film->audio_mapping ();
+ if (!_sndfile_buffers) {
+ _sndfile_buffers.reset (new AudioBuffers (mapping.dcp_channels(), b->frames ()));
+ _sndfile_buffers->make_silent ();
+ }
+
+ for (int i = 0; i < b->channels(); ++i) {
+ list<libdcp::Channel> dcp = mapping.content_to_dcp (AudioMapping::Channel (c, i));
+ for (list<libdcp::Channel>::iterator j = dcp.begin(); j != dcp.end(); ++j) {
+ _sndfile_buffers->accumulate (b, i, static_cast<int> (*j));
+ }
+ }
+
+ } else {
+ Audio (b);
+ }
}
/** @return true on error */
}
if (_audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG) {
- _ffmpeg_decoder->connect_audio (shared_from_this ());
+ _ffmpeg_decoder->Audio.connect (bind (&Player::process_audio, this, _playlist->ffmpeg (), _1));
}
if (_video && _playlist->video_from() == Playlist::VIDEO_IMAGEMAGICK) {
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 ());
+ d->Audio.connect (bind (&Player::process_audio, this, *i, _1));
}
}
}
class Job;
class Film;
class Playlist;
+class AudioContent;
-class Player : public VideoSource, public AudioSource, public VideoSink, public AudioSink, public boost::enable_shared_from_this<Player>
+class Player : public VideoSource, public AudioSource, public VideoSink, public boost::enable_shared_from_this<Player>
{
public:
Player (boost::shared_ptr<const Film>, boost::shared_ptr<const Playlist>);
private:
void process_video (boost::shared_ptr<Image> i, bool same, boost::shared_ptr<Subtitle> s);
- void process_audio (boost::shared_ptr<AudioBuffers>);
+ void process_audio (boost::weak_ptr<const AudioContent>, boost::shared_ptr<AudioBuffers>);
void setup_decoders ();
void playlist_changed ();
void content_changed (boost::weak_ptr<Content>, int);
std::list<boost::shared_ptr<ImageMagickDecoder> >::iterator _imagemagick_decoder;
std::list<boost::shared_ptr<SndfileDecoder> > _sndfile_decoders;
+ boost::shared_ptr<AudioBuffers> _sndfile_buffers;
+
bool _video_sync;
};
#include "i18n.h"
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::setfill;
+using std::ostream;
+using std::endl;
+using std::vector;
+using std::hex;
+using std::setw;
+using std::ifstream;
+using std::ios;
+using std::min;
+using std::max;
+using std::list;
+using std::multimap;
+using std::istream;
+using std::numeric_limits;
+using std::pair;
+using boost::shared_ptr;
+using boost::thread;
+using boost::lexical_cast;
using libdcp::Size;
thread::id ui_thread;
Filter::setup_filters ();
SoundProcessor::setup_sound_processors ();
- ui_thread = this_thread::get_id ();
+ ui_thread = boost::this_thread::get_id ();
}
#ifdef DVDOMATIC_WINDOWS
, _socket (_io_service)
, _timeout (timeout)
{
- _deadline.expires_at (posix_time::pos_infin);
+ _deadline.expires_at (boost::posix_time::pos_infin);
check ();
}
void
Socket::check ()
{
- if (_deadline.expires_at() <= asio::deadline_timer::traits_type::now ()) {
+ if (_deadline.expires_at() <= boost::asio::deadline_timer::traits_type::now ()) {
_socket.close ();
- _deadline.expires_at (posix_time::pos_infin);
+ _deadline.expires_at (boost::posix_time::pos_infin);
}
_deadline.async_wait (boost::bind (&Socket::check, this));
* @param endpoint End-point to connect to.
*/
void
-Socket::connect (asio::ip::basic_resolver_entry<asio::ip::tcp> const & endpoint)
+Socket::connect (boost::asio::ip::basic_resolver_entry<boost::asio::ip::tcp> const & endpoint)
{
- _deadline.expires_from_now (posix_time::seconds (_timeout));
- system::error_code ec = asio::error::would_block;
- _socket.async_connect (endpoint, lambda::var(ec) = lambda::_1);
+ _deadline.expires_from_now (boost::posix_time::seconds (_timeout));
+ boost::system::error_code ec = boost::asio::error::would_block;
+ _socket.async_connect (endpoint, boost::lambda::var(ec) = boost::lambda::_1);
do {
_io_service.run_one();
- } while (ec == asio::error::would_block);
+ } while (ec == boost::asio::error::would_block);
if (ec || !_socket.is_open ()) {
throw NetworkError (_("connect timed out"));
void
Socket::write (uint8_t const * data, int size)
{
- _deadline.expires_from_now (posix_time::seconds (_timeout));
- system::error_code ec = asio::error::would_block;
+ _deadline.expires_from_now (boost::posix_time::seconds (_timeout));
+ boost::system::error_code ec = boost::asio::error::would_block;
- asio::async_write (_socket, asio::buffer (data, size), lambda::var(ec) = lambda::_1);
+ boost::asio::async_write (_socket, boost::asio::buffer (data, size), boost::lambda::var(ec) = boost::lambda::_1);
do {
_io_service.run_one ();
- } while (ec == asio::error::would_block);
+ } while (ec == boost::asio::error::would_block);
if (ec) {
throw NetworkError (ec.message ());
void
Socket::read (uint8_t* data, int size)
{
- _deadline.expires_from_now (posix_time::seconds (_timeout));
- system::error_code ec = asio::error::would_block;
+ _deadline.expires_from_now (boost::posix_time::seconds (_timeout));
+ boost::system::error_code ec = boost::asio::error::would_block;
- asio::async_read (_socket, asio::buffer (data, size), lambda::var(ec) = lambda::_1);
+ boost::asio::async_read (_socket, boost::asio::buffer (data, size), boost::lambda::var(ec) = boost::lambda::_1);
do {
_io_service.run_one ();
- } while (ec == asio::error::would_block);
+ } while (ec == boost::asio::error::would_block);
if (ec) {
throw NetworkError (ec.message ());
}
}
+/** Add data from from `from', `from_channel' to our channel `to_channel' */
+void
+AudioBuffers::accumulate (shared_ptr<AudioBuffers> from, int from_channel, int to_channel)
+{
+ int const N = frames ();
+ assert (from->frames() == N);
+
+ float* s = from->data (from_channel);
+ float* d = _data[to_channel];
+
+ for (int i = 0; i < N; ++i) {
+ *d++ += *s++;
+ }
+}
+
/** Trip an assert if the caller is not in the UI thread */
void
ensure_ui_thread ()
{
- assert (this_thread::get_id() == ui_thread);
+ assert (boost::this_thread::get_id() == ui_thread);
}
/** @param v Content video frame.
void copy_from (AudioBuffers* from, int frames_to_copy, int read_offset, int write_offset);
void move (int from, int to, int frames);
+ void accumulate (boost::shared_ptr<AudioBuffers>, int, int);
private:
/** Number of channels */
}
ContentList c = _film->content ();
- assert (s >= 0 && size_t (s) < c.size ());
+ if (s < 0 || size_t (s) >= c.size ()) {
+ return shared_ptr<Content> ();
+ }
+
return c[s];
}
_play_button->Connect (wxID_ANY, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler (FilmViewer::play_clicked), 0, this);
_timer.Connect (wxID_ANY, wxEVT_TIMER, wxTimerEventHandler (FilmViewer::timer), 0, this);
- if (f) {
- /* We need a player before we set_film() so that the first frame will be displayed */
- _player = f->player ();
- _player->disable_audio ();
- _player->disable_video_sync ();
- /* Don't disable subtitles here as we may need them, and it's nice to be able to turn them
- on and off without needing obtain a new Player.
- */
-
- _player->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3));
- }
-
set_film (f);
JobManager::instance()->ActiveJobsChanged.connect (
if (_film == f) {
return;
}
-
+
_film = f;
if (!_film) {
return;
}
+ _player = f->player ();
+ _player->disable_audio ();
+ _player->disable_video_sync ();
+ /* Don't disable subtitles here as we may need them, and it's nice to be able to turn them
+ on and off without needing obtain a new Player.
+ */
+
+ _player->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3));
+
_film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1));
film_changed (Film::CONTENT);