Reinstate subtitle list view.
authorCarl Hetherington <cth@carlh.net>
Tue, 13 Dec 2016 15:02:09 +0000 (15:02 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 19 Apr 2017 22:04:32 +0000 (23:04 +0100)
15 files changed:
src/lib/dcp_decoder.cc
src/lib/dcp_decoder.h
src/lib/dcp_subtitle_decoder.cc
src/lib/dcp_subtitle_decoder.h
src/lib/decoder.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/image_decoder.cc
src/lib/image_decoder.h
src/lib/text_subtitle_decoder.cc
src/lib/text_subtitle_decoder.h
src/lib/video_mxf_decoder.cc
src/lib/video_mxf_decoder.h
src/wx/subtitle_view.cc
src/wx/subtitle_view.h

index 25c805d3f2ab74d8a9c77c7d7941d18a8e7aad93..e7f04a0619ac57028b0e375b2f2af05eec1e1c54 100644 (file)
@@ -79,11 +79,11 @@ DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, shared_ptr<Log> 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
index 84deab10143f741a7dd4029dc0ee94e6e1586801..71687ad15df1e3eabe711466f7d27cc21f78e776 100644 (file)
@@ -47,7 +47,7 @@ public:
 
        void set_decode_referenced ();
 
-       void pass ();
+       bool pass ();
        void seek (ContentTime t, bool accurate);
 
 private:
index ea24bb1c50d0f62e1d93fdf1c84ddc5777dbdc08..120836643dfcd8019581cf512c6462bd39be3a71 100644 (file)
@@ -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
index 076dc3f3bb9bd9af3dd28838140c786b6f5543b6..359d191457379f8713ed9ee78035c3ac0a6b0a42 100644 (file)
@@ -28,7 +28,7 @@ class DCPSubtitleDecoder : public DCPSubtitle, public Decoder
 public:
        DCPSubtitleDecoder (boost::shared_ptr<const DCPSubtitleContent>, boost::shared_ptr<Log> log);
 
-       void pass ();
+       bool pass ();
        void seek (ContentTime time, bool accurate);
 
 private:
index f70eca8b3fb55a41ca8d627b9e141f3728abf0d5..26035d221080a5304cbccdde0bcf4490c78550bf 100644 (file)
@@ -47,7 +47,8 @@ public:
        boost::shared_ptr<AudioDecoder> audio;
        boost::shared_ptr<SubtitleDecoder> 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;
index 32903a20eb8995d4a2c2847f3b8b2d10e037afc5..b7b70e0618ad129137b6e773e388d0ed59d05e35 100644 (file)
@@ -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.
index 82472c1648a7e1739fe2f6ff32f9e03d79ef17c2..65e4cf46afc6ff6ba9ea87a7dcdcc3264acc808a 100644 (file)
@@ -46,7 +46,7 @@ class FFmpegDecoder : public FFmpeg, public Decoder
 public:
        FFmpegDecoder (boost::shared_ptr<const FFmpegContent>, boost::shared_ptr<Log>);
 
-       void pass ();
+       bool pass ();
        void seek (ContentTime time, bool);
 
 private:
index 6d8f878efeef1a8fe0dd1cd44bed12708c11849b..5a637f4df98d4be1bbe4da7c2753adfcc7a4bfb6 100644 (file)
@@ -44,11 +44,11 @@ ImageDecoder::ImageDecoder (shared_ptr<const ImageContent> c, shared_ptr<Log> 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
index 7978f34c84223006f53bf368d0f99b93a6142296..140032317f9fb331147c31ede4e4a998f73607e2 100644 (file)
@@ -33,7 +33,7 @@ public:
                return _image_content;
        }
 
-       void pass ();
+       bool pass ();
        void seek (ContentTime, bool);
 
 private:
index 51a747fa9343b66d11a6472ff2b6d833aee13530..1b8ee131004bd4fdb8f50e8399960c9ae45f7372 100644 (file)
@@ -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
index 01338683f46033e416676825d36f25c90d81d852..72bb89b77e57a89c8da71ecb449f663c0edb89d6 100644 (file)
@@ -32,7 +32,7 @@ public:
        TextSubtitleDecoder (boost::shared_ptr<const TextSubtitleContent>, boost::shared_ptr<Log> log);
 
        void seek (ContentTime time, bool accurate);
-       void pass ();
+       bool pass ();
 
 private:
        ContentTimePeriod content_time_period (sub::Subtitle s) const;
index 95dd668ee4246709ed72c08479613cd02536b9d2..7b4066f20eaaef204b48518aacbf7fba356d8c88 100644 (file)
@@ -66,14 +66,14 @@ VideoMXFDecoder::VideoMXFDecoder (shared_ptr<const VideoMXFContent> 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
index 3a93bbb063738aada11fccd8f79c3c09fb1dc9e3..3cbdcfb2dffbc5e4316bffc725243ceba76ebc84 100644 (file)
@@ -30,7 +30,7 @@ class VideoMXFDecoder : public Decoder
 public:
        VideoMXFDecoder (boost::shared_ptr<const VideoMXFContent>, boost::shared_ptr<Log> log);
 
-       void pass ();
+       bool pass ();
        void seek (ContentTime t, bool accurate);
 
 private:
index a4218dc5d7f64658e2c19a9537ee6a2cf0f73df3..7c66f1db2d15cf073137c59be8cedbac1582ff86 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
 
     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> film, shared_ptr<
                sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
        }
 
-#if 0
-       XXX
-
-       list<ContentTextSubtitle> 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<ContentTextSubtitle>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
-               for (list<dcp::SubtitleString>::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<dcp::SubtitleString>::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;
+       }
+}
index ac8e496ce00402baa1ec74e9c92f15f50f3c3ca2..f88bb490f5e1b928cbf9b7d8c766e9d45f805779 100644 (file)
@@ -18,6 +18,7 @@
 
 */
 
+#include "lib/content_subtitle.h"
 #include <boost/shared_ptr.hpp>
 #include <wx/wx.h>
 #include <wx/listctrl.h>
@@ -30,5 +31,9 @@ public:
        SubtitleView (wxWindow *, boost::shared_ptr<Film>, boost::shared_ptr<Decoder>, DCPTime position);
 
 private:
+       void data (ContentTextSubtitle cts);
+
        wxListCtrl* _list;
+       int _subs;
+       boost::optional<FrameRateChange> _frc;
 };