Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2024 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "tasks/generic/Flush.h"
21 : #include "RialtoServerLogging.h"
22 : #include "TypeConverters.h"
23 : #include "tasks/generic/NeedData.h"
24 :
25 : namespace firebolt::rialto::server::tasks::generic
26 : {
27 9 : Flush::Flush(GenericPlayerContext &context, IGstGenericPlayerPrivate &player, IGstGenericPlayerClient *client,
28 : const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper, const MediaSourceType &type,
29 9 : bool resetTime, bool isAsync)
30 18 : : m_context{context}, m_player{player}, m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}, m_type{type},
31 9 : m_resetTime{resetTime}, m_isAsync{isAsync}
32 : {
33 9 : RIALTO_SERVER_LOG_DEBUG("Constructing Flush");
34 : }
35 :
36 10 : Flush::~Flush()
37 : {
38 9 : RIALTO_SERVER_LOG_DEBUG("Flush finished");
39 10 : }
40 :
41 8 : void Flush::execute() const
42 : {
43 8 : RIALTO_SERVER_LOG_DEBUG("Executing Flush for %s source", common::convertMediaSourceType(m_type));
44 :
45 : // Get source first
46 8 : GstElement *source{nullptr};
47 8 : auto sourceElem = m_context.streamInfo.find(m_type);
48 8 : if (sourceElem != m_context.streamInfo.end())
49 : {
50 7 : source = sourceElem->second.appSrc;
51 : }
52 8 : if (!source)
53 : {
54 1 : RIALTO_SERVER_LOG_WARN("failed to flush %s - source is NULL", common::convertMediaSourceType(m_type));
55 2 : return;
56 : }
57 :
58 7 : if (m_type == MediaSourceType::UNKNOWN)
59 : {
60 1 : RIALTO_SERVER_LOG_WARN("Flush failed: Media source type not supported.");
61 1 : return;
62 : }
63 :
64 6 : StreamInfo &streamInfo = sourceElem->second;
65 6 : streamInfo.isDataNeeded = false;
66 6 : streamInfo.isNeedDataPending = false;
67 :
68 12 : for (auto &buffer : streamInfo.buffers)
69 : {
70 6 : m_gstWrapper->gstBufferUnref(buffer);
71 : }
72 6 : streamInfo.buffers.clear();
73 6 : m_context.initialPositions.erase(sourceElem->second.appSrc);
74 :
75 6 : m_gstPlayerClient->invalidateActiveRequests(m_type);
76 :
77 6 : if (GST_STATE(m_context.pipeline) >= GST_STATE_PAUSED)
78 : {
79 5 : m_context.flushOnPrerollController->waitIfRequired(m_type);
80 :
81 5 : RIALTO_SERVER_LOG_MIL("Sending flush event for %s source.", common::convertMediaSourceType(m_type));
82 : // Flush source
83 5 : GstEvent *flushStart = m_gstWrapper->gstEventNewFlushStart();
84 5 : if (!m_gstWrapper->gstElementSendEvent(source, flushStart))
85 : {
86 1 : RIALTO_SERVER_LOG_WARN("failed to send flush-start event for %s", common::convertMediaSourceType(m_type));
87 : }
88 :
89 5 : GstEvent *flushStop = m_gstWrapper->gstEventNewFlushStop(m_resetTime);
90 5 : if (!m_gstWrapper->gstElementSendEvent(source, flushStop))
91 : {
92 1 : RIALTO_SERVER_LOG_WARN("failed to send flush-stop event for %s", common::convertMediaSourceType(m_type));
93 : }
94 :
95 5 : if (m_isAsync)
96 : {
97 5 : m_context.flushOnPrerollController->setFlushing(m_type);
98 : }
99 : }
100 : else
101 : {
102 1 : RIALTO_SERVER_LOG_DEBUG("Skip sending flush event for %s - pipeline below paused",
103 : common::convertMediaSourceType(m_type));
104 : }
105 :
106 : // Reset Eos info
107 6 : m_context.endOfStreamInfo.erase(m_type);
108 6 : m_context.eosNotified = false;
109 :
110 : // Notify client, that flush has been finished
111 6 : m_gstPlayerClient->notifySourceFlushed(m_type);
112 :
113 : // Notify GstGenericPlayer, that flush has been finished
114 6 : m_player.setSourceFlushed(m_type);
115 :
116 6 : if (m_context.setupSourceFinished)
117 : {
118 : // Trigger NeedData for source
119 2 : NeedData task{m_context, m_player, m_gstPlayerClient, GST_APP_SRC(source)};
120 2 : task.execute();
121 : }
122 :
123 6 : RIALTO_SERVER_LOG_MIL("%s source flushed.", common::convertMediaSourceType(m_type));
124 : }
125 : } // namespace firebolt::rialto::server::tasks::generic
|