2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file test/ffmpeg_pts_offset_test.cc
22 * @brief Check the computation of _pts_offset in FFmpegDecoder.
26 #include <boost/test/unit_test.hpp>
28 #include "lib/ffmpeg_decoder.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/ffmpeg_audio_stream.h"
31 #include "lib/audio_content.h"
34 using boost::shared_ptr;
35 using namespace dcpomatic;
37 BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
39 shared_ptr<Film> film = new_test_film ("ffmpeg_pts_offset_test");
40 shared_ptr<FFmpegContent> content (new FFmpegContent ("test/data/test.mp4"));
41 film->examine_and_add_content (content);
42 BOOST_REQUIRE (!wait_for_jobs());
44 content->audio.reset (new AudioContent (content.get()));
45 content->audio->add_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream));
46 content->_video_frame_rate = 24;
49 /* Sound == video so no offset required */
50 content->_first_video = ContentTime ();
51 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
52 FFmpegDecoder decoder (film, content, false);
53 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), 0);
57 /* Common offset should be removed */
58 content->_first_video = ContentTime::from_seconds (600);
59 content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (600);
60 FFmpegDecoder decoder (film, content, false);
61 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), ContentTime::from_seconds(-600).get());
65 /* Video is on a frame boundary */
66 content->_first_video = ContentTime::from_frames (1, 24);
67 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
68 FFmpegDecoder decoder (film, content, false);
69 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), 0);
73 /* Video is off a frame boundary */
74 double const frame = 1.0 / 24.0;
75 content->_first_video = ContentTime::from_seconds (frame + 0.0215);
76 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
77 FFmpegDecoder decoder (film, content, false);
78 BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001);
82 /* Video is off a frame boundary and both have a common offset */
83 double const frame = 1.0 / 24.0;
84 content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1);
85 content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (4.1);
86 FFmpegDecoder decoder (film, content, false);
87 BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1, 0.1);