2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/test/unit_test.hpp>
22 #include "lib/ffmpeg_decoder.h"
25 using boost::shared_ptr;
27 BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
29 shared_ptr<Film> film = new_test_film ("ffmpeg_pts_offset_test");
30 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
31 content->_audio_stream.reset (new FFmpegAudioStream);
32 content->_video_frame_rate = 24;
35 /* Sound == video so no offset required */
36 content->_first_video = 0;
37 content->_audio_stream->first_audio = 0;
38 FFmpegDecoder decoder (film, content, true, true);
39 BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0);
40 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0);
44 /* Common offset should be removed */
45 content->_first_video = 600;
46 content->_audio_stream->first_audio = 600;
47 FFmpegDecoder decoder (film, content, true, true);
48 BOOST_CHECK_EQUAL (decoder._video_pts_offset, -600);
49 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, -600);
53 /* Video is on a frame boundary */
54 content->_first_video = 1.0 / 24.0;
55 content->_audio_stream->first_audio = 0;
56 FFmpegDecoder decoder (film, content, true, true);
57 BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0);
58 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0);
62 /* Video is off a frame boundary */
63 double const frame = 1.0 / 24.0;
64 content->_first_video = frame + 0.0215;
65 content->_audio_stream->first_audio = 0;
66 FFmpegDecoder decoder (film, content, true, true);
67 BOOST_CHECK_EQUAL (decoder._video_pts_offset, (frame - 0.0215));
68 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, (frame - 0.0215));
72 /* Video is off a frame boundary and both have a common offset */
73 double const frame = 1.0 / 24.0;
74 content->_first_video = frame + 0.0215 + 4.1;
75 content->_audio_stream->first_audio = 4.1;
76 FFmpegDecoder decoder (film, content, true, true);
77 BOOST_CHECK_EQUAL (decoder._video_pts_offset, (frame - 0.0215) - 4.1);
78 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, (frame - 0.0215) - 4.1);