From da19eaac0dd80afed3dd282d61ea3298196a5090 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 13 Dec 2013 10:23:20 +0000 Subject: [PATCH] Start of changing frame numbers to time. --- src/lib/audio_decoder.cc | 6 ++-- src/lib/audio_decoder.h | 5 ++- src/lib/ffmpeg_decoder.cc | 67 +++------------------------------------ src/lib/ffmpeg_decoder.h | 1 - src/lib/player.cc | 20 +++++++++--- src/lib/player.h | 8 ++--- src/lib/video_decoder.cc | 11 +++---- src/lib/video_decoder.h | 7 ++-- 8 files changed, 35 insertions(+), 90 deletions(-) diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index c0ef02f65..a73ad4d7c 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -35,16 +35,14 @@ using boost::shared_ptr; AudioDecoder::AudioDecoder (shared_ptr film, shared_ptr content) : Decoder (film) , _audio_content (content) - , _audio_position (0) { } void -AudioDecoder::audio (shared_ptr data, AudioContent::Frame frame) +AudioDecoder::audio (shared_ptr data, ContentTime time) { - Audio (data, frame); - _audio_position = frame + data->frames (); + Audio (data, time); } /** This is a bit odd, but necessary when we have (e.g.) FFmpegDecoders with no audio. diff --git a/src/lib/audio_decoder.h b/src/lib/audio_decoder.h index ab6c4b8a9..10e4298f7 100644 --- a/src/lib/audio_decoder.h +++ b/src/lib/audio_decoder.h @@ -41,13 +41,12 @@ public: bool has_audio () const; /** Emitted when some audio data is ready */ - boost::signals2::signal, AudioContent::Frame)> Audio; + boost::signals2::signal, ContentTime)> Audio; protected: - void audio (boost::shared_ptr, AudioContent::Frame); + void audio (boost::shared_ptr, ContentTime); boost::shared_ptr _audio_content; - AudioContent::Frame _audio_position; }; #endif diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 2cb18c557..d72fed0bc 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -70,7 +70,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr f, shared_ptrstreams[copy_packet.stream_index]->time_base) - * av_frame_get_best_effort_timestamp(_frame) + _audio_pts_offset; - - if (pts > 0) { - /* Emit some silence */ - shared_ptr silence ( - new AudioBuffers ( - _ffmpeg_content->audio_channels(), - pts * _ffmpeg_content->content_audio_frame_rate() - ) - ); - - silence->make_silent (); - audio (silence, _audio_position); - } - } + Time const t = (av_q2d (_format_context->streams[copy_packet.stream_index]->time_base) + * av_frame_get_best_effort_timestamp(_frame) + _audio_pts_offset) * TIME_HZ; int const data_size = av_samples_get_buffer_size ( 0, audio_codec_context()->channels, _frame->nb_samples, audio_sample_format (), 1 ); - audio (deinterleave_audio (_frame->data, data_size), _audio_position); + audio (deinterleave_audio (_frame->data, data_size), t); } copy_packet.data += decode_result; @@ -521,45 +501,8 @@ FFmpegDecoder::decode_video_packet () } if (i->second != AV_NOPTS_VALUE) { - - double const pts = i->second * av_q2d (_format_context->streams[_video_stream]->time_base) + _video_pts_offset; - - if (_just_sought) { - /* We just did a seek, so disable any attempts to correct for where we - are / should be. - */ - _video_position = rint (pts * _ffmpeg_content->video_frame_rate ()); - _just_sought = false; - } - - double const next = _video_position / _ffmpeg_content->video_frame_rate(); - double const one_frame = 1 / _ffmpeg_content->video_frame_rate (); - double delta = pts - next; - - while (delta > one_frame) { - /* This PTS is more than one frame forward in time of where we think we should be; emit - a black frame. - */ - - /* XXX: I think this should be a copy of the last frame... */ - boost::shared_ptr black ( - new Image ( - static_cast (_frame->format), - libdcp::Size (video_codec_context()->width, video_codec_context()->height), - true - ) - ); - - black->make_black (); - video (image, false, _video_position); - delta -= one_frame; - } - - if (delta > -one_frame) { - /* This PTS is within a frame of being right; emit this (otherwise it will be dropped) */ - video (image, false, _video_position); - } - + Time const t = (i->second * av_q2d (_format_context->streams[_video_stream]->time_base) + _video_pts_offset) * TIME_HZ; + video (image, false, t); } else { shared_ptr film = _film.lock (); assert (film); diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 06e0ef8a5..ed4557702 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -90,5 +90,4 @@ private: double _video_pts_offset; double _audio_pts_offset; - bool _just_sought; }; diff --git a/src/lib/player.cc b/src/lib/player.cc index be22ae242..7f5e78681 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -86,13 +86,23 @@ public: void repeat (Player* player) { + shared_ptr p = repeat_video.weak_piece.lock (); + if (!p) { + return; + } + + shared_ptr vc = dynamic_pointer_cast (p->content); + if (!vc) { + return; + } + player->process_video ( repeat_video.weak_piece, repeat_video.image, repeat_video.eyes, repeat_done > 0, - repeat_video.frame, - (repeat_done + 1) * (TIME_HZ / player->_film->video_frame_rate ()) + repeat_video.time, + (repeat_done + 1) * (TIME_HZ / vc->video_frame_rate ()) ); ++repeat_done; @@ -241,14 +251,14 @@ Player::pass () /** @param extra Amount of extra time to add to the content frame's time (for repeat) */ void -Player::process_video (weak_ptr weak_piece, shared_ptr image, Eyes eyes, bool same, VideoContent::Frame frame, DCPTime extra) +Player::process_video (weak_ptr weak_piece, shared_ptr image, Eyes eyes, bool same, ContentTime time, ContentTime extra) { /* Keep a note of what came in so that we can repeat it if required */ _last_incoming_video.weak_piece = weak_piece; _last_incoming_video.image = image; _last_incoming_video.eyes = eyes; _last_incoming_video.same = same; - _last_incoming_video.frame = frame; + _last_incoming_video.time = time; _last_incoming_video.extra = extra; shared_ptr piece = weak_piece.lock (); @@ -689,7 +699,7 @@ Player::repeat_last_video () _last_incoming_video.image, _last_incoming_video.eyes, _last_incoming_video.same, - _last_incoming_video.frame, + _last_incoming_video.time, _last_incoming_video.extra ); diff --git a/src/lib/player.h b/src/lib/player.h index 364d66249..0d6c8d8ba 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -49,8 +49,8 @@ public: boost::shared_ptr image; Eyes eyes; bool same; - VideoContent::Frame frame; - DCPTime extra; + ContentTime time; + ContentTime extra; }; /** A wrapper for an Image which contains some pending operations; these may @@ -118,8 +118,8 @@ private: friend class PlayerWrapper; friend class Piece; - void process_video (boost::weak_ptr, boost::shared_ptr, Eyes, bool, VideoContent::Frame, DCPTime); - void process_audio (boost::weak_ptr, boost::shared_ptr, AudioContent::Frame); + void process_video (boost::weak_ptr, boost::shared_ptr, Eyes, bool, ContentTime, ContentTime); + void process_audio (boost::weak_ptr, boost::shared_ptr, ContentTime); void process_subtitle (boost::weak_ptr, boost::shared_ptr, dcpomatic::Rect, DCPTime, DCPTime); void setup_pieces (); void playlist_changed (); diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index eaa4534e4..72caf72e9 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -28,27 +28,24 @@ using boost::shared_ptr; VideoDecoder::VideoDecoder (shared_ptr f, shared_ptr c) : Decoder (f) , _video_content (c) - , _video_position (0) { } void -VideoDecoder::video (shared_ptr image, bool same, VideoContent::Frame frame) +VideoDecoder::video (shared_ptr image, bool same, ContentTime time) { switch (_video_content->video_frame_type ()) { case VIDEO_FRAME_TYPE_2D: - Video (image, EYES_BOTH, same, frame); + Video (image, EYES_BOTH, same, time); break; case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT: { int const half = image->size().width / 2; - Video (image->crop (Crop (0, half, 0, 0), true), EYES_LEFT, same, frame); - Video (image->crop (Crop (half, 0, 0, 0), true), EYES_RIGHT, same, frame); + Video (image->crop (Crop (0, half, 0, 0), true), EYES_LEFT, same, time); + Video (image->crop (Crop (half, 0, 0, 0), true), EYES_RIGHT, same, time); break; } } - - _video_position = frame + 1; } diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index 01319e481..6e9060dbd 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -38,15 +38,14 @@ public: * First parameter is the video image. * Second parameter is the eye(s) which should see this image. * Third parameter is true if the image is the same as the last one that was emitted for this Eyes value. - * Fourth parameter is the frame within our source. + * Fourth parameter is the time within our source. */ - boost::signals2::signal, Eyes, bool, VideoContent::Frame)> Video; + boost::signals2::signal, Eyes, bool, ContentTime)> Video; protected: - void video (boost::shared_ptr, bool, VideoContent::Frame); + void video (boost::shared_ptr, bool, ContentTime); boost::shared_ptr _video_content; - VideoContent::Frame _video_position; }; #endif -- 2.30.2