Skip to content

Commit 20dd3e8

Browse files
Asure correct data & flush order during postponed flushes (#436)
Summary: Asure correct data & flush order during multiple flushes Type: Fix Test Plan: UT/CT, Fullstack Jira: NO-JIRA
1 parent 19f5628 commit 20dd3e8

35 files changed

Lines changed: 282 additions & 148 deletions

media/server/gstplayer/include/FlushOnPrerollController.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define FIREBOLT_RIALTO_SERVER_FLUSH_ONPREROLL_CONTROLLER_H_
2222

2323
#include "IFlushOnPrerollController.h"
24+
#include <condition_variable>
2425
#include <mutex>
2526
#include <optional>
2627
#include <set>
@@ -37,13 +38,16 @@ class FlushOnPrerollController : public IFlushOnPrerollController
3738
FlushOnPrerollController() = default;
3839
~FlushOnPrerollController() override = default;
3940

40-
bool shouldPostponeFlush(const MediaSourceType &type) const override;
41-
void setFlushing(const MediaSourceType &type, const GstState &currentPipelineState) override;
41+
void waitIfRequired(const MediaSourceType &type) override;
42+
void setFlushing(const MediaSourceType &type) override;
43+
void setPrerolling() override;
4244
void stateReached(const GstState &newPipelineState) override;
45+
void setTargetState(const GstState &state) override;
4346
void reset() override;
4447

4548
private:
46-
mutable std::mutex m_mutex{};
49+
std::mutex m_mutex{};
50+
std::condition_variable m_conditionVariable{};
4751
std::set<MediaSourceType> m_flushingSources{};
4852
std::optional<GstState> m_targetState{std::nullopt};
4953
bool m_isPrerolled{false};

media/server/gstplayer/include/GenericPlayerContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ struct GenericPlayerContext
270270
/**
271271
* @brief Workaround for the gstreamer flush issue
272272
*/
273-
FlushOnPrerollController flushOnPrerollController;
273+
std::shared_ptr<IFlushOnPrerollController> flushOnPrerollController{std::make_shared<FlushOnPrerollController>()};
274274
};
275275
} // namespace firebolt::rialto::server
276276

media/server/gstplayer/include/GstDispatcherThread.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ class GstDispatcherThreadFactory : public IGstDispatcherThreadFactory
3434
~GstDispatcherThreadFactory() override = default;
3535
std::unique_ptr<IGstDispatcherThread>
3636
createGstDispatcherThread(IGstDispatcherThreadClient &client, GstElement *pipeline,
37+
const std::shared_ptr<IFlushOnPrerollController> &flushOnPrerollController,
3738
const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper) const override;
3839
};
3940

4041
class GstDispatcherThread : public IGstDispatcherThread
4142
{
4243
public:
4344
GstDispatcherThread(IGstDispatcherThreadClient &client, GstElement *pipeline,
45+
const std::shared_ptr<IFlushOnPrerollController> &flushOnPrerollController,
4446
const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper);
4547
~GstDispatcherThread() override;
4648

@@ -58,6 +60,11 @@ class GstDispatcherThread : public IGstDispatcherThread
5860
*/
5961
IGstDispatcherThreadClient &m_client;
6062

63+
/**
64+
* @brief The flush on preroll controller.
65+
*/
66+
std::shared_ptr<IFlushOnPrerollController> m_flushOnPrerollController;
67+
6168
/**
6269
* @brief The gstreamer wrapper object.
6370
*/

media/server/gstplayer/include/GstGenericPlayer.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ class GstGenericPlayer : public IGstGenericPlayer, public IGstGenericPlayerPriva
195195
GstElement *getSink(const MediaSourceType &mediaSourceType) const override;
196196
void setSourceFlushed(const MediaSourceType &mediaSourceType) override;
197197
bool isAsync(const MediaSourceType &mediaSourceType) const;
198-
void postponeFlush(const MediaSourceType &mediaSourceType, bool resetTime) override;
199-
void executePostponedFlushes() override;
200198
void notifyPlaybackInfo() override;
201199

202200
private:
@@ -426,11 +424,6 @@ class GstGenericPlayer : public IGstGenericPlayer, public IGstGenericPlayerPriva
426424
*/
427425
std::unique_ptr<IFlushWatcher> m_flushWatcher;
428426

429-
/**
430-
* @brief The postponed flush tasks
431-
*/
432-
std::vector<std::pair<MediaSourceType, bool>> m_postponedFlushes{};
433-
434427
/**
435428
* @brief The ongoing state change operations counter
436429
*/

media/server/gstplayer/include/IFlushOnPrerollController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ class IFlushOnPrerollController
3434
public:
3535
virtual ~IFlushOnPrerollController() = default;
3636

37-
virtual bool shouldPostponeFlush(const MediaSourceType &type) const = 0;
38-
virtual void setFlushing(const MediaSourceType &type, const GstState &currentPipelineState) = 0;
37+
virtual void waitIfRequired(const MediaSourceType &type) = 0;
38+
virtual void setFlushing(const MediaSourceType &type) = 0;
39+
virtual void setPrerolling() = 0;
3940
virtual void stateReached(const GstState &newPipelineState) = 0;
41+
virtual void setTargetState(const GstState &state) = 0;
4042
virtual void reset() = 0;
4143
};
4244
} // namespace firebolt::rialto::server

media/server/gstplayer/include/IGstDispatcherThread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef FIREBOLT_RIALTO_SERVER_I_GST_DISPATCHER_THREAD_H_
2121
#define FIREBOLT_RIALTO_SERVER_I_GST_DISPATCHER_THREAD_H_
2222

23+
#include "IFlushOnPrerollController.h"
2324
#include "IGstDispatcherThreadClient.h"
2425
#include "IGstWrapper.h"
2526
#include <memory>
@@ -36,6 +37,7 @@ class IGstDispatcherThreadFactory
3637

3738
virtual std::unique_ptr<IGstDispatcherThread>
3839
createGstDispatcherThread(IGstDispatcherThreadClient &client, GstElement *pipeline,
40+
const std::shared_ptr<IFlushOnPrerollController> &flushOnPrerollController,
3941
const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper) const = 0;
4042
};
4143

media/server/gstplayer/include/IGstGenericPlayerPrivate.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,6 @@ class IGstGenericPlayerPrivate
321321
*/
322322
virtual void setSourceFlushed(const MediaSourceType &mediaSourceType) = 0;
323323

324-
/**
325-
* @brief Postpones flush for the given source type
326-
*
327-
* @param[in] mediaSourceType : the source type that has been flushed
328-
* @param[in] resetTime : whether to reset the time after flush
329-
*/
330-
virtual void postponeFlush(const MediaSourceType &mediaSourceType, bool resetTime) = 0;
331-
332-
/**
333-
* @brief Queues postponed flushes for execution
334-
*/
335-
virtual void executePostponedFlushes() = 0;
336-
337324
/**
338325
* @brief Sends PlaybackInfo notification. Called by the worker thread.
339326
*/

media/server/gstplayer/include/tasks/IGenericPlayerTaskFactory.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ class IGenericPlayerTaskFactory
429429
* @param[in] context : The GstPlayer context
430430
* @param[in] type : The media source type to flush
431431
* @param[in] resetTime : True if time should be reset
432+
* @param[in] isAsync : True if flushed source is asynchronous
432433
*
433434
* @retval the new Flush task instance.
434435
*/
435436
virtual std::unique_ptr<IPlayerTask> createFlush(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
436-
const firebolt::rialto::MediaSourceType &type,
437-
bool resetTime) const = 0;
437+
const firebolt::rialto::MediaSourceType &type, bool resetTime,
438+
bool isAsync) const = 0;
438439

439440
/**
440441
* @brief Creates a SetSourcePosition task.

media/server/gstplayer/include/tasks/generic/Flush.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Flush : public IPlayerTask
3333
{
3434
public:
3535
Flush(GenericPlayerContext &context, IGstGenericPlayerPrivate &player, IGstGenericPlayerClient *client,
36-
std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper, const MediaSourceType &type,
37-
bool resetTime);
36+
const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper, const MediaSourceType &type,
37+
bool resetTime, bool isAsync);
3838
~Flush() override;
3939
void execute() const override;
4040

@@ -45,6 +45,7 @@ class Flush : public IPlayerTask
4545
std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper;
4646
MediaSourceType m_type;
4747
bool m_resetTime;
48+
bool m_isAsync;
4849
};
4950
} // namespace firebolt::rialto::server::tasks::generic
5051

media/server/gstplayer/include/tasks/generic/GenericPlayerTaskFactory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class GenericPlayerTaskFactory : public IGenericPlayerTaskFactory
108108
IGstGenericPlayerPrivate &player) const override;
109109
std::unique_ptr<IPlayerTask> createPing(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler) const override;
110110
std::unique_ptr<IPlayerTask> createFlush(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
111-
const firebolt::rialto::MediaSourceType &type,
112-
bool resetTime) const override;
111+
const firebolt::rialto::MediaSourceType &type, bool resetTime,
112+
bool isAsync) const override;
113113
std::unique_ptr<IPlayerTask> createSetSourcePosition(GenericPlayerContext &context,
114114
const firebolt::rialto::MediaSourceType &type,
115115
std::int64_t position, bool resetTime, double appliedRate,

0 commit comments

Comments
 (0)