@@ -40,6 +40,8 @@ struct layer::impl
4040
4141 bool auto_play_ = false ;
4242 bool paused_ = false ;
43+ std::optional<uint32_t > foreground_length_override_;
44+ std::optional<uint32_t > background_length_override_;
4345
4446 public:
4547 impl (const core::video_format_desc format_desc)
@@ -55,6 +57,20 @@ struct layer::impl
5557 {
5658 background_ = std::move (producer);
5759 auto_play_ = auto_play;
60+ background_length_override_.reset (); // Clear any previous length override
61+
62+ if (auto_play_ && foreground_ == frame_producer::empty ()) {
63+ play ();
64+ } else if (preview_producer) {
65+ preview (true );
66+ }
67+ }
68+
69+ void load (spl::shared_ptr<frame_producer> producer, bool preview_producer, bool auto_play, std::optional<uint32_t > length)
70+ {
71+ background_ = std::move (producer);
72+ auto_play_ = auto_play;
73+ background_length_override_ = length;
5874
5975 if (auto_play_ && foreground_ == frame_producer::empty ()) {
6076 play ();
@@ -90,6 +106,8 @@ struct layer::impl
90106
91107 foreground_ = std::move (background_);
92108 background_ = frame_producer::empty ();
109+ foreground_length_override_ = background_length_override_;
110+ background_length_override_.reset ();
93111
94112 auto_play_ = false ;
95113 }
@@ -115,7 +133,8 @@ struct layer::impl
115133 auto auto_play_delta = background_->auto_play_delta ();
116134 if (auto_play_delta) {
117135 auto time = static_cast <std::int64_t >(foreground_->frame_number ());
118- auto duration = static_cast <std::int64_t >(foreground_->nb_frames ());
136+ auto duration = foreground_length_override_ ? static_cast <std::int64_t >(*foreground_length_override_)
137+ : static_cast <std::int64_t >(foreground_->nb_frames ());
119138 frames_left = duration - time - *auto_play_delta;
120139 if (frames_left < 1 && field != video_field::b) {
121140 play ();
@@ -179,6 +198,10 @@ void layer::load(spl::shared_ptr<frame_producer> frame_producer, bool preview, b
179198{
180199 return impl_->load (std::move (frame_producer), preview, auto_play);
181200}
201+ void layer::load (spl::shared_ptr<frame_producer> frame_producer, bool preview, bool auto_play, std::optional<uint32_t > length)
202+ {
203+ return impl_->load (std::move (frame_producer), preview, auto_play, length);
204+ }
182205void layer::play () { impl_->play (); }
183206void layer::preview () { impl_->preview (false ); }
184207void layer::pause () { impl_->pause (); }
0 commit comments