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 : std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper, const MediaSourceType &type,
29 9 : bool resetTime)
30 18 : : m_context{context}, m_player{player}, m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}, m_type{type},
31 9 : m_resetTime{resetTime}
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_player.stopPositionReportingAndCheckAudioUnderflowTimer();
80 :
81 : // Flush source
82 5 : GstEvent *flushStart = m_gstWrapper->gstEventNewFlushStart();
83 5 : if (!m_gstWrapper->gstElementSendEvent(source, flushStart))
84 : {
85 1 : RIALTO_SERVER_LOG_WARN("failed to send flush-start event for %s", common::convertMediaSourceType(m_type));
86 : }
87 :
88 5 : GstEvent *flushStop = m_gstWrapper->gstEventNewFlushStop(m_resetTime);
89 5 : if (!m_gstWrapper->gstElementSendEvent(source, flushStop))
90 : {
91 1 : RIALTO_SERVER_LOG_WARN("failed to send flush-stop event for %s", common::convertMediaSourceType(m_type));
92 : }
93 : }
94 : else
95 : {
96 1 : RIALTO_SERVER_LOG_DEBUG("Skip sending flush event for %s - pipeline below paused",
97 : common::convertMediaSourceType(m_type));
98 : }
99 :
100 : // Reset Eos info
101 6 : m_context.endOfStreamInfo.erase(m_type);
102 6 : m_context.eosNotified = false;
103 :
104 : // Notify client, that flush has been finished
105 6 : m_gstPlayerClient->notifySourceFlushed(m_type);
106 :
107 : // Notify GstGenericPlayer, that flush has been finished
108 6 : m_player.setSourceFlushed(m_type);
109 :
110 6 : if (m_context.setupSourceFinished)
111 : {
112 : // Trigger NeedData for source
113 2 : NeedData task{m_context, m_player, m_gstPlayerClient, GST_APP_SRC(source)};
114 2 : task.execute();
115 : }
116 :
117 6 : RIALTO_SERVER_LOG_MIL("%s source flushed.", common::convertMediaSourceType(m_type));
118 : }
119 : } // namespace firebolt::rialto::server::tasks::generic
|