BugFix Seek OSC as percent of play duration

Response to issue #120
This commit is contained in:
Bruno Herbelin
2024-02-02 14:53:23 +01:00
parent 52840ce8ae
commit 842247de54
3 changed files with 35 additions and 6 deletions

View File

@@ -655,11 +655,13 @@ void Seek::update(Source *s, float dt)
// access media player if target source is a media source
MediaSource *ms = dynamic_cast<MediaSource *>(s);
if (ms != nullptr) {
// set target position
// get media info
GstClockTime media_duration = ms->mediaplayer()->timeline()->duration();
GstClockTime t = (double) media_duration * (double) target_percent_;
if (target_time_ > 0)
t = target_time_;
// set target position
GstClockTime t = target_time_;
// set target as percent if not provided
if (t<1)
t = ms->mediaplayer()->timeline()->timeFromPercent(target_percent_);
// perform seek
if (GST_CLOCK_TIME_IS_VALID(t) && GST_CLOCK_TIME_IS_VALID(media_duration)

View File

@@ -78,7 +78,7 @@ void Timeline::reset()
clearFading();
}
bool Timeline::is_valid()
bool Timeline::is_valid() const
{
return timing_.is_valid() && step_ != GST_CLOCK_TIME_NONE;
}
@@ -314,6 +314,32 @@ GstClockTime Timeline::sectionsTimeAt(GstClockTime t) const
return d;
}
GstClockTime Timeline::timeFromPercent(const float p) const
{
if (!is_valid())
return 0;
// compute time at p % of actural section duration
GstClockTime percent = (double) p * 100000;
GstClockTime d = (sectionsDuration() * percent ) / 100000;
// loop over gaps
for (auto g = gaps_.begin(); g != gaps_.end(); ++g) {
// gap before target?
if ( g->begin < d ) {
// jump over gap
d += g->duration();
}
else
// done
break;
}
// return time corresponding to p% of play duration
return d;
}
size_t Timeline::fillSectionsArrays( float* const gaps, float* const fading)
{
size_t arraysize = MAX_TIMELINE_ARRAY;

View File

@@ -100,7 +100,7 @@ public:
~Timeline();
Timeline& operator = (const Timeline& b);
bool is_valid();
bool is_valid() const;
void update();
void refresh();
@@ -121,6 +121,7 @@ public:
inline TimeInterval interval() const { return timing_; }
GstClockTime next(GstClockTime time) const;
GstClockTime previous(GstClockTime time) const;
GstClockTime timeFromPercent(const float p) const;
// Manipulation of gaps
inline TimeIntervalSet gaps() const { return gaps_; }