From eb135e8dcdf36ae82420bcd18e954ad593b3e9a5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 13 Dec 2016 15:02:09 +0000 Subject: [PATCH] Reinstate subtitle list view. --- src/lib/dcp_decoder.cc | 6 +++-- src/lib/dcp_decoder.h | 2 +- src/lib/dcp_subtitle_decoder.cc | 5 ++-- src/lib/dcp_subtitle_decoder.h | 2 +- src/lib/decoder.h | 3 ++- src/lib/ffmpeg_decoder.cc | 5 ++-- src/lib/ffmpeg_decoder.h | 2 +- src/lib/image_decoder.cc | 6 ++--- src/lib/image_decoder.h | 2 +- src/lib/text_subtitle_decoder.cc | 6 ++--- src/lib/text_subtitle_decoder.h | 2 +- src/lib/video_mxf_decoder.cc | 5 ++-- src/lib/video_mxf_decoder.h | 2 +- src/wx/subtitle_view.cc | 46 +++++++++++++++++++------------- src/wx/subtitle_view.h | 5 ++++ 15 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 25c805d3f..e7f04a061 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -79,11 +79,11 @@ DCPDecoder::DCPDecoder (shared_ptr c, shared_ptr log) get_readers (); } -void +bool DCPDecoder::pass () { if (_reel == _reels.end () || !_dcp_content->can_be_played ()) { - return; + return true; } double const vfr = _dcp_content->active_video_frame_rate (); @@ -163,6 +163,8 @@ DCPDecoder::pass () _next = ContentTime (); } } + + return false; } void diff --git a/src/lib/dcp_decoder.h b/src/lib/dcp_decoder.h index 84deab101..71687ad15 100644 --- a/src/lib/dcp_decoder.h +++ b/src/lib/dcp_decoder.h @@ -47,7 +47,7 @@ public: void set_decode_referenced (); - void pass (); + bool pass (); void seek (ContentTime t, bool accurate); private: diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc index ea24bb1c5..120836643 100644 --- a/src/lib/dcp_subtitle_decoder.cc +++ b/src/lib/dcp_subtitle_decoder.cc @@ -47,11 +47,11 @@ DCPSubtitleDecoder::seek (ContentTime time, bool) } } -void +bool DCPSubtitleDecoder::pass () { if (_next == _subtitles.end ()) { - return; + return true; } /* Gather all subtitles with the same time period that are next @@ -70,6 +70,7 @@ DCPSubtitleDecoder::pass () } subtitle->emit_text (p, s); + return false; } ContentTimePeriod diff --git a/src/lib/dcp_subtitle_decoder.h b/src/lib/dcp_subtitle_decoder.h index 076dc3f3b..359d19145 100644 --- a/src/lib/dcp_subtitle_decoder.h +++ b/src/lib/dcp_subtitle_decoder.h @@ -28,7 +28,7 @@ class DCPSubtitleDecoder : public DCPSubtitle, public Decoder public: DCPSubtitleDecoder (boost::shared_ptr, boost::shared_ptr log); - void pass (); + bool pass (); void seek (ContentTime time, bool accurate); private: diff --git a/src/lib/decoder.h b/src/lib/decoder.h index f70eca8b3..26035d221 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -47,7 +47,8 @@ public: boost::shared_ptr audio; boost::shared_ptr subtitle; - virtual void pass () = 0; + /** @return true if there is no more data to come from this decoder */ + virtual bool pass () = 0; virtual void seek (ContentTime time, bool accurate) = 0; ContentTime position () const; diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 32903a20e..b7b70e061 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -116,7 +116,7 @@ FFmpegDecoder::flush () } } -void +bool FFmpegDecoder::pass () { int r = av_read_frame (_format_context, &_packet); @@ -134,7 +134,7 @@ FFmpegDecoder::pass () } flush (); - return; + return true; } int const si = _packet.stream_index; @@ -149,6 +149,7 @@ FFmpegDecoder::pass () } av_packet_unref (&_packet); + return false; } /** @param data pointer to array of pointers to buffers. diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 82472c164..65e4cf46a 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -46,7 +46,7 @@ class FFmpegDecoder : public FFmpeg, public Decoder public: FFmpegDecoder (boost::shared_ptr, boost::shared_ptr); - void pass (); + bool pass (); void seek (ContentTime time, bool); private: diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc index 6d8f878ef..5a637f4df 100644 --- a/src/lib/image_decoder.cc +++ b/src/lib/image_decoder.cc @@ -44,11 +44,11 @@ ImageDecoder::ImageDecoder (shared_ptr c, shared_ptr lo video.reset (new VideoDecoder (this, c, log)); } -void +bool ImageDecoder::pass () { if (_frame_video_position >= _image_content->video->length()) { - return; + return true; } if (!_image_content->still() || !_image) { @@ -74,7 +74,7 @@ ImageDecoder::pass () video->emit (_image, _frame_video_position); ++_frame_video_position; - return; + return false; } void diff --git a/src/lib/image_decoder.h b/src/lib/image_decoder.h index 7978f34c8..140032317 100644 --- a/src/lib/image_decoder.h +++ b/src/lib/image_decoder.h @@ -33,7 +33,7 @@ public: return _image_content; } - void pass (); + bool pass (); void seek (ContentTime, bool); private: diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index 51a747fa9..1b8ee1310 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -50,18 +50,18 @@ TextSubtitleDecoder::seek (ContentTime time, bool) } } -void +bool TextSubtitleDecoder::pass () { if (_next >= _subtitles.size ()) { - return; + return true; } ContentTimePeriod const p = content_time_period (_subtitles[_next]); subtitle->emit_text (p, _subtitles[_next]); ++_next; - return; + return false; } ContentTimePeriod diff --git a/src/lib/text_subtitle_decoder.h b/src/lib/text_subtitle_decoder.h index 01338683f..72bb89b77 100644 --- a/src/lib/text_subtitle_decoder.h +++ b/src/lib/text_subtitle_decoder.h @@ -32,7 +32,7 @@ public: TextSubtitleDecoder (boost::shared_ptr, boost::shared_ptr log); void seek (ContentTime time, bool accurate); - void pass (); + bool pass (); private: ContentTimePeriod content_time_period (sub::Subtitle s) const; diff --git a/src/lib/video_mxf_decoder.cc b/src/lib/video_mxf_decoder.cc index 95dd668ee..7b4066f20 100644 --- a/src/lib/video_mxf_decoder.cc +++ b/src/lib/video_mxf_decoder.cc @@ -66,14 +66,14 @@ VideoMXFDecoder::VideoMXFDecoder (shared_ptr content, sha } } -void +bool VideoMXFDecoder::pass () { double const vfr = _content->active_video_frame_rate (); int64_t const frame = _next.frames_round (vfr); if (frame >= _content->video->length()) { - return; + return true; } if (_mono_reader) { @@ -90,6 +90,7 @@ VideoMXFDecoder::pass () } _next += ContentTime::from_frames (1, vfr); + return false; } void diff --git a/src/lib/video_mxf_decoder.h b/src/lib/video_mxf_decoder.h index 3a93bbb06..3cbdcfb2d 100644 --- a/src/lib/video_mxf_decoder.h +++ b/src/lib/video_mxf_decoder.h @@ -30,7 +30,7 @@ class VideoMXFDecoder : public Decoder public: VideoMXFDecoder (boost::shared_ptr, boost::shared_ptr log); - void pass (); + bool pass (); void seek (ContentTime t, bool accurate); private: diff --git a/src/wx/subtitle_view.cc b/src/wx/subtitle_view.cc index a4218dc5d..7c66f1db2 100644 --- a/src/wx/subtitle_view.cc +++ b/src/wx/subtitle_view.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2016 Carl Hetherington This file is part of DCP-o-matic. @@ -20,6 +20,8 @@ #include "lib/text_subtitle_decoder.h" #include "lib/content_subtitle.h" +#include "lib/video_decoder.h" +#include "lib/audio_decoder.h" #include "lib/film.h" #include "lib/text_subtitle_content.h" #include "subtitle_view.h" @@ -67,25 +69,31 @@ SubtitleView::SubtitleView (wxWindow* parent, shared_ptr film, shared_ptr< sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } -#if 0 - XXX - - list subs = decoder->subtitle->get_text (ContentTimePeriod (ContentTime(), ContentTime::max ()), true, true); - FrameRateChange const frc = film->active_frame_rate_change (position); - int n = 0; - for (list::const_iterator i = subs.begin(); i != subs.end(); ++i) { - for (list::const_iterator j = i->subs.begin(); j != i->subs.end(); ++j) { - wxListItem list_item; - list_item.SetId (n); - _list->InsertItem (list_item); - ContentTimePeriod const p = i->period (); - _list->SetItem (n, 0, std_to_wx (p.from.timecode (frc.source))); - _list->SetItem (n, 1, std_to_wx (p.to.timecode (frc.source))); - _list->SetItem (n, 2, std_to_wx (j->text ())); - ++n; - } + if (decoder->video) { + decoder->video->set_ignore (); + } + if (decoder->audio) { + decoder->audio->set_ignore (); } -#endif + _subs = 0; + _frc = film->active_frame_rate_change (position); + decoder->subtitle->TextData.connect (bind (&SubtitleView::data, this, _1)); + while (!decoder->pass ()) {} SetSizerAndFit (sizer); } + +void +SubtitleView::data (ContentTextSubtitle cts) +{ + for (list::const_iterator i = cts.subs.begin(); i != cts.subs.end(); ++i) { + wxListItem list_item; + list_item.SetId (_subs); + _list->InsertItem (list_item); + ContentTimePeriod const p = cts.period (); + _list->SetItem (_subs, 0, std_to_wx (p.from.timecode (_frc->source))); + _list->SetItem (_subs, 1, std_to_wx (p.to.timecode (_frc->source))); + _list->SetItem (_subs, 2, std_to_wx (i->text ())); + ++_subs; + } +} diff --git a/src/wx/subtitle_view.h b/src/wx/subtitle_view.h index ac8e496ce..f88bb490f 100644 --- a/src/wx/subtitle_view.h +++ b/src/wx/subtitle_view.h @@ -18,6 +18,7 @@ */ +#include "lib/content_subtitle.h" #include #include #include @@ -30,5 +31,9 @@ public: SubtitleView (wxWindow *, boost::shared_ptr, boost::shared_ptr, DCPTime position); private: + void data (ContentTextSubtitle cts); + wxListCtrl* _list; + int _subs; + boost::optional _frc; }; -- 2.30.2