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 BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
22 shared_ptr<Film> film = new_test_film ("ffmpeg_pts_offset_test");
23 shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/test.mp4"));
24 content->_audio_stream.reset (new FFmpegAudioStream);
25 content->_video_frame_rate = 24;
28 /* Sound == video so no offset required */
29 content->_first_video = 0;
30 content->_audio_stream->first_audio = 0;
31 FFmpegDecoder decoder (film, content, true, true);
32 BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0);
33 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0);
37 /* Common offset should be removed */
38 content->_first_video = 600;
39 content->_audio_stream->first_audio = 600;
40 FFmpegDecoder decoder (film, content, true, true);
41 BOOST_CHECK_EQUAL (decoder._video_pts_offset, -600);
42 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, -600);
46 /* Video is on a frame boundary */
47 content->_first_video = 1.0 / 24.0;
48 content->_audio_stream->first_audio = 0;
49 FFmpegDecoder decoder (film, content, true, true);
50 BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0);
51 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0);
55 /* Video is off a frame boundary */
56 double const frame = 1.0 / 24.0;
57 content->_first_video = frame + 0.0215;
58 content->_audio_stream->first_audio = 0;
59 FFmpegDecoder decoder (film, content, true, true);
60 BOOST_CHECK_EQUAL (decoder._video_pts_offset, (frame - 0.0215));
61 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, (frame - 0.0215));
65 /* Video is off a frame boundary and both have a common offset */
66 double const frame = 1.0 / 24.0;
67 content->_first_video = frame + 0.0215 + 4.1;
68 content->_audio_stream->first_audio = 4.1;
69 FFmpegDecoder decoder (film, content, true, true);
70 BOOST_CHECK_EQUAL (decoder._video_pts_offset, (frame - 0.0215) - 4.1);
71 BOOST_CHECK_EQUAL (decoder._audio_pts_offset, (frame - 0.0215) - 4.1);