#include "job.h"
#include "image.h"
#include "player.h"
-#include "matcher.h"
-#include "delay_line.h"
-#include "gain.h"
#include "combiner.h"
-#include "trimmer.h"
/** @file src/ab_transcoder.cc
* @brief A transcoder which uses one Film for the left half of the screen, and a different one
, _encoder (new Encoder (film_a, j))
, _combiner (new Combiner (film_a->log()))
{
- _matcher.reset (new Matcher (film_a->log(), film_a->audio_frame_rate(), film_a->video_frame_rate()));
- _delay_line.reset (new DelayLine (film_a->log(), film_a->audio_delay() * film_a->audio_frame_rate() / 1000));
- _gain.reset (new Gain (film_a->log(), film_a->audio_gain()));
-
_player_a->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3, _4));
_player_b->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3, _4));
- int const trim_start = film_a->trim_type() == Film::ENCODE ? film_a->trim_start() : 0;
- int const trim_end = film_a->trim_type() == Film::ENCODE ? film_a->trim_end() : 0;
- _trimmer.reset (new Trimmer (
- film_a->log(), trim_start, trim_end, film_a->content_length(),
- film_a->audio_frame_rate(), film_a->video_frame_rate(), film_a->dcp_frame_rate()
- ));
-
-
- _combiner->connect_video (_delay_line);
- _delay_line->connect_video (_matcher);
- _matcher->connect_video (_trimmer);
- _trimmer->connect_video (_encoder);
-
- _player_a->connect_audio (_delay_line);
- _delay_line->connect_audio (_matcher);
- _matcher->connect_audio (_gain);
- _gain->connect_audio (_trimmer);
- _trimmer->connect_audio (_encoder);
+ _combiner->connect_video (_encoder);
+ _player_a->connect_audio (_encoder);
}
void
ABTranscoder::go ()
{
_encoder->process_begin ();
-
while (!_player_a->pass () || !_player_b->pass ()) {}
-
- _delay_line->process_end ();
- _matcher->process_end ();
- _gain->process_end ();
- _trimmer->process_end ();
_encoder->process_end ();
}
-
class Image;
class Log;
class Film;
-class Matcher;
-class DelayLine;
-class Gain;
class Combiner;
class Player;
-class Trimmer;
/** @class ABTranscoder
* @brief A transcoder which uses one Film for the left half of the screen, and a different one
boost::shared_ptr<Job> _job;
boost::shared_ptr<Encoder> _encoder;
boost::shared_ptr<Combiner> _combiner;
- boost::shared_ptr<Matcher> _matcher;
- boost::shared_ptr<DelayLine> _delay_line;
- boost::shared_ptr<Gain> _gain;
- boost::shared_ptr<Trimmer> _trimmer;
boost::shared_ptr<Image> _image;
};
+++ /dev/null
-/*
- Copyright (C) 2012 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 <stdint.h>
-#include <cstring>
-#include <algorithm>
-#include <iostream>
-#include "delay_line.h"
-#include "util.h"
-
-using std::min;
-using boost::shared_ptr;
-
-/* @param seconds Delay in seconds, +ve to move audio later.
- */
-DelayLine::DelayLine (shared_ptr<Log> log, double seconds)
- : TimedAudioVideoProcessor (log)
- , _seconds (seconds)
-{
-
-}
-
-void
-DelayLine::process_audio (shared_ptr<const AudioBuffers> data, double t)
-{
- if (_seconds > 0) {
- t += _seconds;
- }
-
- Audio (data, t);
-}
-
-void
-DelayLine::process_video (shared_ptr<const Image> image, bool same, boost::shared_ptr<Subtitle> sub, double t)
-{
- if (_seconds < 0) {
- t += _seconds;
- }
-
- Video (image, same, sub, t);
-}
+++ /dev/null
-/*
- Copyright (C) 2012 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 <boost/shared_ptr.hpp>
-#include "processor.h"
-
-/** A delay line */
-class DelayLine : public TimedAudioVideoProcessor
-{
-public:
- DelayLine (boost::shared_ptr<Log> log, double);
-
- void process_video (boost::shared_ptr<const Image>, bool, boost::shared_ptr<Subtitle>, double);
- void process_audio (boost::shared_ptr<const AudioBuffers>, double);
-
-private:
- double _seconds;
-};
+++ /dev/null
-/*
- Copyright (C) 2012 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 "gain.h"
-
-using boost::shared_ptr;
-
-/** @param gain gain in dB */
-Gain::Gain (shared_ptr<Log> log, float gain)
- : AudioProcessor (log)
- , _gain (gain)
-{
-
-}
-
-void
-Gain::process_audio (shared_ptr<const AudioBuffers> b)
-{
- if (_gain != 0) {
- float const linear_gain = pow (10, _gain / 20);
- for (int i = 0; i < b->channels(); ++i) {
- for (int j = 0; j < b->frames(); ++j) {
- b->data(i)[j] *= linear_gain;
- }
- }
- }
-
- Audio (b);
-}
+++ /dev/null
-/*
- Copyright (C) 2012 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 "processor.h"
-
-class Gain : public AudioProcessor
-{
-public:
- Gain (boost::shared_ptr<Log> log, float gain);
-
- void process_audio (boost::shared_ptr<const AudioBuffers>);
-
-private:
- float _gain;
-};
+++ /dev/null
-/*
- Copyright (C) 2012 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 "matcher.h"
-#include "image.h"
-#include "log.h"
-
-#include "i18n.h"
-
-using std::min;
-using std::cout;
-using std::list;
-using boost::shared_ptr;
-
-Matcher::Matcher (shared_ptr<Log> log, int sample_rate, float frames_per_second)
- : Processor (log)
- , _sample_rate (sample_rate)
- , _frames_per_second (frames_per_second)
- , _video_frames (0)
- , _audio_frames (0)
- , _had_first_video (false)
- , _had_first_audio (false)
-{
-
-}
-
-void
-Matcher::process_video (shared_ptr<const Image> image, bool same, boost::shared_ptr<Subtitle> sub, double t)
-{
- _pixel_format = image->pixel_format ();
- _size = image->size ();
-
- _log->log(String::compose("Matcher video @ %1 [audio=%2, video=%3, pending_audio=%4]", t, _audio_frames, _video_frames, _pending_audio.size()));
-
- if (!_first_input) {
- _first_input = t;
- }
-
- bool const this_is_first_video = !_had_first_video;
- _had_first_video = true;
-
- if (this_is_first_video && _had_first_audio) {
- /* First video since we got audio */
- fix_start (t);
- }
-
- /* Video before audio is fine, since we can make up an arbitrary difference
- with audio samples (contrasting with video which is quantised to frames)
- */
-
- /* Difference between where this video is and where it should be */
- double const delta = t - _first_input.get() - _video_frames / _frames_per_second;
- double const one_frame = 1 / _frames_per_second;
-
- if (delta > one_frame) {
- /* Insert frames to make up the difference */
- int const extra = rint (delta / one_frame);
- for (int i = 0; i < extra; ++i) {
- repeat_last_video ();
- _log->log (String::compose ("Extra video frame inserted at %1s", _video_frames / _frames_per_second));
- }
- }
-
- if (delta > -one_frame) {
- Video (image, same, sub);
- ++_video_frames;
- } else {
- /* We are omitting a frame to keep things right */
- _log->log (String::compose ("Frame removed at %1s", t));
- }
-
- _last_image = image;
- _last_subtitle = sub;
-}
-
-void
-Matcher::process_audio (shared_ptr<const AudioBuffers> b, double t)
-{
- _channels = b->channels ();
-
- _log->log (String::compose (
- "Matcher audio (%1 frames) @ %2 [video=%3, audio=%4, pending_audio=%5]",
- b->frames(), t, _video_frames, _audio_frames, _pending_audio.size()
- )
- );
-
- if (!_first_input) {
- _first_input = t;
- }
-
- bool const this_is_first_audio = _had_first_audio;
- _had_first_audio = true;
-
- if (!_had_first_video) {
- /* No video yet; we must postpone these data until we have some */
- _pending_audio.push_back (AudioRecord (b, t));
- } else if (this_is_first_audio && !_had_first_video) {
- /* First audio since we got video */
- _pending_audio.push_back (AudioRecord (b, t));
- fix_start (_first_input.get ());
- } else {
- /* Normal running. We assume audio time stamps are consecutive */
- Audio (b);
- _audio_frames += b->frames ();
- }
-}
-
-void
-Matcher::process_end ()
-{
- if (_audio_frames == 0 || !_pixel_format || !_size || !_channels) {
- /* We won't do anything */
- return;
- }
-
- _log->log (String::compose ("Matcher has seen %1 video frames (which equals %2 audio frames) and %3 audio frames",
- _video_frames, video_frames_to_audio_frames (_video_frames, _sample_rate, _frames_per_second), _audio_frames));
-
- match ((double (_audio_frames) / _sample_rate) - (double (_video_frames) / _frames_per_second));
-}
-
-void
-Matcher::fix_start (double first_video)
-{
- assert (!_pending_audio.empty ());
-
- _log->log (String::compose ("Fixing start; video at %1, audio at %2", first_video, _pending_audio.front().time));
-
- match (first_video - _pending_audio.front().time);
-
- for (list<AudioRecord>::iterator i = _pending_audio.begin(); i != _pending_audio.end(); ++i) {
- process_audio (i->audio, i->time);
- }
-
- _pending_audio.clear ();
-}
-
-void
-Matcher::match (double extra_video_needed)
-{
- _log->log (String::compose ("Match %1", extra_video_needed));
-
- if (extra_video_needed > 0) {
-
- /* Emit black video frames */
-
- int const black_video_frames = ceil (extra_video_needed * _frames_per_second);
-
- _log->log (String::compose (N_("Emitting %1 frames of black video"), black_video_frames));
-
- shared_ptr<Image> black (new SimpleImage (_pixel_format.get(), _size.get(), true));
- black->make_black ();
- for (int i = 0; i < black_video_frames; ++i) {
- Video (black, i != 0, shared_ptr<Subtitle>());
- ++_video_frames;
- }
-
- extra_video_needed -= black_video_frames / _frames_per_second;
- }
-
- if (extra_video_needed < 0) {
-
- /* Emit silence */
-
- int64_t to_do = -extra_video_needed * _sample_rate;
- _log->log (String::compose (N_("Emitting %1 frames of silence"), to_do));
-
- /* Do things in half second blocks as I think there may be limits
- to what FFmpeg (and in particular the resampler) can cope with.
- */
- int64_t const block = _sample_rate / 2;
- shared_ptr<AudioBuffers> b (new AudioBuffers (_channels.get(), block));
- b->make_silent ();
-
- while (to_do > 0) {
- int64_t const this_time = min (to_do, block);
- b->set_frames (this_time);
- Audio (b);
- _audio_frames += b->frames ();
- to_do -= this_time;
- }
- }
-}
-
-void
-Matcher::repeat_last_video ()
-{
- if (!_last_image) {
- shared_ptr<Image> im (new SimpleImage (_pixel_format.get(), _size.get(), true));
- im->make_black ();
- _last_image = im;
- }
-
- Video (_last_image, true, _last_subtitle);
- ++_video_frames;
-}
-
+++ /dev/null
-/*
- Copyright (C) 2012 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 <boost/optional.hpp>
-#include "processor.h"
-#include "ffmpeg_compatibility.h"
-
-class Matcher : public Processor, public TimedAudioSink, public TimedVideoSink, public AudioSource, public VideoSource
-{
-public:
- Matcher (boost::shared_ptr<Log> log, int sample_rate, float frames_per_second);
- void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s, double);
- void process_audio (boost::shared_ptr<const AudioBuffers>, double);
- void process_end ();
-
-private:
- void fix_start (double);
- void match (double);
- void repeat_last_video ();
-
- int _sample_rate;
- float _frames_per_second;
- int _video_frames;
- int64_t _audio_frames;
- boost::optional<AVPixelFormat> _pixel_format;
- boost::optional<libdcp::Size> _size;
- boost::optional<int> _channels;
-
- struct AudioRecord {
- AudioRecord (boost::shared_ptr<const AudioBuffers> a, double t)
- : audio (a)
- , time (t)
- {}
-
- boost::shared_ptr<const AudioBuffers> audio;
- double time;
- };
-
- std::list<AudioRecord> _pending_audio;
-
- boost::optional<double> _first_input;
- boost::shared_ptr<const Image> _last_image;
- boost::shared_ptr<Subtitle> _last_subtitle;
-
- bool _had_first_video;
- bool _had_first_audio;
-};
#include "transcoder.h"
#include "encoder.h"
#include "film.h"
-#include "matcher.h"
-#include "delay_line.h"
-#include "gain.h"
#include "video_decoder.h"
#include "audio_decoder.h"
#include "player.h"
-#include "trimmer.h"
#include "job.h"
using std::string;
, _player (f->player ())
, _encoder (new Encoder (f, j))
{
- _matcher.reset (new Matcher (f->log(), f->audio_frame_rate(), f->video_frame_rate()));
- _delay_line.reset (new DelayLine (f->log(), f->audio_delay() * f->audio_frame_rate() / 1000));
- _gain.reset (new Gain (f->log(), f->audio_gain()));
-
- int const trim_start = f->trim_type() == Film::ENCODE ? f->trim_start() : 0;
- int const trim_end = f->trim_type() == Film::ENCODE ? f->trim_end() : 0;
- _trimmer.reset (new Trimmer (
- f->log(), trim_start, trim_end, f->content_length(),
- f->audio_frame_rate(), f->video_frame_rate(), f->dcp_frame_rate()
- ));
-
if (!f->with_subtitles ()) {
_player->disable_subtitles ();
}
- _player->connect_video (_delay_line);
- _delay_line->connect_video (_matcher);
- _matcher->connect_video (_trimmer);
- _trimmer->connect_video (_encoder);
-
- _player->connect_audio (_delay_line);
- _delay_line->connect_audio (_matcher);
- _matcher->connect_audio (_gain);
- _gain->connect_audio (_trimmer);
- _trimmer->connect_audio (_encoder);
+ _player->connect_video (_encoder);
+ _player->connect_audio (_encoder);
}
void
Transcoder::go ()
{
_encoder->process_begin ();
-
while (!_player->pass ()) {}
-
- _delay_line->process_end ();
- if (_matcher) {
- _matcher->process_end ();
- }
- _gain->process_end ();
_encoder->process_end ();
}
class Film;
class Job;
class Encoder;
-class Matcher;
class VideoFilter;
-class Gain;
-class DelayLine;
class Player;
-class Trimmer;
/** @class Transcoder
*
boost::shared_ptr<Job> _job;
boost::shared_ptr<Player> _player;
boost::shared_ptr<Encoder> _encoder;
- boost::shared_ptr<Matcher> _matcher;
- boost::shared_ptr<DelayLine> _delay_line;
- boost::shared_ptr<Gain> _gain;
- boost::shared_ptr<Trimmer> _trimmer;
};
+++ /dev/null
-/*
- 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 <boost/shared_ptr.hpp>
-#include "trimmer.h"
-
-using std::cout;
-using std::max;
-using boost::shared_ptr;
-
-/** @param audio_sample_rate Audio sampling rate, or 0 if there is no audio */
-Trimmer::Trimmer (
- shared_ptr<Log> log,
- int video_trim_start,
- int video_trim_end,
- int video_length,
- int audio_sample_rate,
- float frames_per_second,
- int dcp_frames_per_second
- )
- : AudioVideoProcessor (log)
- , _video_start (video_trim_start)
- , _video_end (video_length - video_trim_end)
- , _video_in (0)
- , _audio_in (0)
-{
- FrameRateConversion frc (frames_per_second, dcp_frames_per_second);
-
- if (frc.skip) {
- _video_start /= 2;
- _video_end /= 2;
- } else if (frc.repeat) {
- _video_start *= 2;
- _video_end *= 2;
- }
-
- if (audio_sample_rate) {
- _audio_start = video_frames_to_audio_frames (_video_start, audio_sample_rate, frames_per_second);
- _audio_end = video_frames_to_audio_frames (_video_end, audio_sample_rate, frames_per_second);
- }
-
- /* XXX: this is a hack; this flag means that no trim is happening at the end of the film, and I'm
- using that to prevent audio trim being rounded to video trim, which breaks the current set
- of regression tests. This could be removed if a) the regression tests are regenerated and b)
- I can work out what DCP length should be.
- */
- _no_trim = (_video_start == 0) && (_video_end == (video_length - video_trim_end));
-}
-
-void
-Trimmer::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Subtitle> sub)
-{
- if (_no_trim || (_video_in >= _video_start && _video_in <= _video_end)) {
- Video (image, same, sub);
- }
-
- ++_video_in;
-}
-
-void
-Trimmer::process_audio (shared_ptr<const AudioBuffers> audio)
-{
- if (_no_trim) {
- Audio (audio);
- return;
- }
-
- int64_t offset = _audio_start - _audio_in;
- if (offset > audio->frames()) {
- _audio_in += audio->frames ();
- return;
- }
-
- if (offset < 0) {
- offset = 0;
- }
-
- int64_t length = _audio_end - max (_audio_in, _audio_start);
- if (length < 0) {
- _audio_in += audio->frames ();
- return;
- }
-
- if (length > (audio->frames() - offset)) {
- length = audio->frames () - offset;
- }
-
- _audio_in += audio->frames ();
-
- if (offset != 0 || length != audio->frames ()) {
- shared_ptr<AudioBuffers> copy (new AudioBuffers (audio));
- copy->move (offset, 0, length);
- copy->set_frames (length);
- audio = copy;
- }
-
- Audio (audio);
-}
-
+++ /dev/null
-/*
- 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 "processor.h"
-
-class Trimmer : public AudioVideoProcessor
-{
-public:
- Trimmer (boost::shared_ptr<Log>, int, int, int, int, float, int);
-
- void process_video (boost::shared_ptr<const Image> i, bool, boost::shared_ptr<Subtitle> s);
- void process_audio (boost::shared_ptr<const AudioBuffers>);
-
-private:
- friend class trimmer_test;
-
- int _video_start;
- int _video_end;
- int _video_in;
- int64_t _audio_start;
- int64_t _audio_end;
- int64_t _audio_in;
- bool _no_trim;
-};
dcp_content_type.cc
dcp_video_frame.cc
decoder.cc
- delay_line.cc
dolby_cp750.cc
encoder.cc
examine_content_job.cc
film.cc
filter.cc
format.cc
- gain.cc
image.cc
imagemagick_content.cc
imagemagick_decoder.cc
job_manager.cc
log.cc
lut.cc
- matcher.cc
player.cc
playlist.cc
scp_dcp_job.cc
transcode_job.cc
transcoder.cc
types.cc
- trimmer.cc
ui_signaller.cc
util.cc
video_content.cc
#include "ffmpeg_decoder.h"
#include "sndfile_decoder.h"
#include "dcp_content_type.h"
-#include "trimmer.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dcpomatic_test
#include <boost/test/unit_test.hpp>
}
}
-shared_ptr<const Image> trimmer_test_last_video;
-shared_ptr<const AudioBuffers> trimmer_test_last_audio;
-
-void
-trimmer_test_video_helper (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>)
-{
- trimmer_test_last_video = image;
-}
-
-void
-trimmer_test_audio_helper (shared_ptr<const AudioBuffers> audio)
-{
- trimmer_test_last_audio = audio;
-}
-
-BOOST_AUTO_TEST_CASE (trimmer_passthrough_test)
-{
- Trimmer trimmer (shared_ptr<Log> (), 0, 0, 200, 48000, 25, 25);
- trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
- trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
-
- shared_ptr<SimpleImage> video (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true));
- shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 42 * 1920));
-
- trimmer.process_video (video, false, shared_ptr<Subtitle> ());
- trimmer.process_audio (audio);
-
- BOOST_CHECK_EQUAL (video.get(), trimmer_test_last_video.get());
- BOOST_CHECK_EQUAL (audio.get(), trimmer_test_last_audio.get());
- BOOST_CHECK_EQUAL (audio->frames(), trimmer_test_last_audio->frames());
-}
-
-
-/** Test the audio handling of the Trimmer */
-BOOST_AUTO_TEST_CASE (trimmer_audio_test)
-{
- Trimmer trimmer (shared_ptr<Log> (), 25, 75, 200, 48000, 25, 25);
-
- trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
-
- /* 21 video frames-worth of audio frames; should be completely stripped */
- trimmer_test_last_audio.reset ();
- shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 21 * 1920));
- trimmer.process_audio (audio);
- BOOST_CHECK (trimmer_test_last_audio == 0);
-
- /* 42 more video frames-worth, 4 should be stripped from the start */
- audio.reset (new AudioBuffers (6, 42 * 1920));
- trimmer.process_audio (audio);
- BOOST_CHECK (trimmer_test_last_audio);
- BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 38 * 1920);
-
- /* 42 more video frames-worth, should be kept as-is */
- trimmer_test_last_audio.reset ();
- audio.reset (new AudioBuffers (6, 42 * 1920));
- trimmer.process_audio (audio);
- BOOST_CHECK (trimmer_test_last_audio);
- BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 42 * 1920);
-
- /* 25 more video frames-worth, 5 should be trimmed from the end */
- trimmer_test_last_audio.reset ();
- audio.reset (new AudioBuffers (6, 25 * 1920));
- trimmer.process_audio (audio);
- BOOST_CHECK (trimmer_test_last_audio);
- BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 20 * 1920);
-
- /* Now some more; all should be trimmed */
- trimmer_test_last_audio.reset ();
- audio.reset (new AudioBuffers (6, 100 * 1920));
- trimmer.process_audio (audio);
- BOOST_CHECK (trimmer_test_last_audio == 0);
-}
-
-
BOOST_AUTO_TEST_CASE (film_metadata_test)
{
setup_test_config ();