X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fffmpeg_pts_offset.cc;h=4a9a57b402295e52d6668fec3b2e1ef92ed06109;hb=08d62727f7f1c813cbc7041027fe4a52518623da;hp=15c2b38e1befd4ffe70f1b8ec5bcadb111d55d3d;hpb=89115db77729a2c99f1a09ff6a461720e16f889e;p=dcpomatic.git diff --git a/test/ffmpeg_pts_offset.cc b/test/ffmpeg_pts_offset.cc index 15c2b38e1..4a9a57b40 100644 --- a/test/ffmpeg_pts_offset.cc +++ b/test/ffmpeg_pts_offset.cc @@ -17,23 +17,60 @@ */ +#include +#include "lib/film.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/ffmpeg_content.h" +#include "test.h" + +using boost::shared_ptr; + BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) { - /* Sound == video so no offset required */ - BOOST_CHECK_EQUAL (FFmpegDecoder::compute_pts_offset (0, 0, 24), 0); + shared_ptr film = new_test_film ("ffmpeg_pts_offset_test"); + shared_ptr content (new FFmpegContent (film, "test/data/test.mp4")); + content->_audio_stream.reset (new FFmpegAudioStream); + content->_video_frame_rate = 24; - /* Common offset should be removed */ - BOOST_CHECK_CLOSE (FFmpegDecoder::compute_pts_offset (42, 42, 24), -42, 1e-9); + { + /* Sound == video so no offset required */ + content->_first_video = ContentTime (); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (film, content, true, true); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); + } - /* Video is on a frame boundary */ - BOOST_CHECK_EQUAL (FFmpegDecoder::compute_pts_offset (1.0 / 24.0, 0, 24), 0); + { + /* Common offset should be removed */ + content->_first_video = ContentTime::from_seconds (600); + content->_audio_stream->first_audio = ContentTime::from_seconds (600); + FFmpegDecoder decoder (film, content, true, true); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime::from_seconds (-600)); + } - /* Again, video is on a frame boundary */ - BOOST_CHECK_EQUAL (FFmpegDecoder::compute_pts_offset (1.0 / 23.97, 0, 23.97), 0); + { + /* Video is on a frame boundary */ + content->_first_video = ContentTime::from_frames (1, 24); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (film, content, true, true); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); + } - /* And again, video is on a frame boundary */ - BOOST_CHECK_EQUAL (FFmpegDecoder::compute_pts_offset (3.0 / 23.97, 0, 23.97), 0); + { + /* Video is off a frame boundary */ + double const frame = 1.0 / 24.0; + content->_first_video = ContentTime::from_seconds (frame + 0.0215); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (film, content, true, true); + BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001); + } - /* Off a frame boundary */ - BOOST_CHECK_CLOSE (FFmpegDecoder::compute_pts_offset (1.0 / 24.0 - 0.0215, 0, 24), 0.0215, 1e-9); + { + /* Video is off a frame boundary and both have a common offset */ + double const frame = 1.0 / 24.0; + content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1); + content->_audio_stream->first_audio = ContentTime::from_seconds (4.1); + FFmpegDecoder decoder (film, content, true, true); + BOOST_CHECK_EQUAL (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1); + } }