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.
25 #include <boost/test/unit_test.hpp>
27 #include "lib/ffmpeg_decoder.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/ffmpeg_audio_stream.h"
30 #include "lib/audio_content.h"
33 using boost::shared_ptr;
35 BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
37 shared_ptr<Film> film = new_test_film ("ffmpeg_pts_offset_test");
38 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
39 film->examine_and_add_content (content);
42 content->audio.reset (new AudioContent (content.get()));
43 content->audio->add_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream));
44 content->_video_frame_rate = 24;
47 /* Sound == video so no offset required */
48 content->_first_video = ContentTime ();
49 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
50 FFmpegDecoder decoder (content, film->log());
51 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), 0);
55 /* Common offset should be removed */
56 content->_first_video = ContentTime::from_seconds (600);
57 content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (600);
58 FFmpegDecoder decoder (content, film->log());
59 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), ContentTime::from_seconds(-600).get());
63 /* Video is on a frame boundary */
64 content->_first_video = ContentTime::from_frames (1, 24);
65 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
66 FFmpegDecoder decoder (content, film->log());
67 BOOST_CHECK_EQUAL (decoder._pts_offset.get(), 0);
71 /* Video is off a frame boundary */
72 double const frame = 1.0 / 24.0;
73 content->_first_video = ContentTime::from_seconds (frame + 0.0215);
74 content->ffmpeg_audio_streams().front()->first_audio = ContentTime ();
75 FFmpegDecoder decoder (content, film->log());
76 BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001);
80 /* Video is off a frame boundary and both have a common offset */
81 double const frame = 1.0 / 24.0;
82 content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1);
83 content->ffmpeg_audio_streams().front()->first_audio = ContentTime::from_seconds (4.1);
84 FFmpegDecoder decoder (content, film->log());
85 BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1, 0.1);