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 2022 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/FinishSetupSource.h"
21 : #include "GenericPlayerContext.h"
22 : #include "IGstGenericPlayerClient.h"
23 : #include "IGstGenericPlayerPrivate.h"
24 : #include "RialtoServerLogging.h"
25 : #include <gst/app/gstappsrc.h>
26 : #include <gst/gst.h>
27 :
28 : namespace
29 : {
30 : /**
31 : * @brief Callback for need-data event from gstreamer. Called by the Gstreamer thread.
32 : *
33 : * @param[in] src : the appsrc element that emitted the signal
34 : * @param[in] length : the amount of bytes needed.
35 : * @param[in] user_data : The data to be passed with the message.
36 : *
37 : */
38 2 : void appSrcNeedData(GstAppSrc *src, guint length, gpointer user_data)
39 : {
40 2 : firebolt::rialto::server::IGstGenericPlayerPrivate *self =
41 : static_cast<firebolt::rialto::server::IGstGenericPlayerPrivate *>(user_data);
42 2 : self->scheduleNeedMediaData(src);
43 : }
44 :
45 : /**
46 : * @brief Callback for enough-data event from gstreamer. Called by the Gstreamer thread.
47 : *
48 : * @param[in] src : the appsrc element that emitted the signal
49 : * @param[in] user_data : The data to be passed with the message.
50 : *
51 : */
52 2 : void appSrcEnoughData(GstAppSrc *src, gpointer user_data)
53 : {
54 2 : firebolt::rialto::server::IGstGenericPlayerPrivate *self =
55 : static_cast<firebolt::rialto::server::IGstGenericPlayerPrivate *>(user_data);
56 2 : self->scheduleEnoughData(src);
57 : }
58 :
59 : /**
60 : * @brief Callback for seek-data event from gstreamer. Called by the Gstreamer thread.
61 : *
62 : * @param[in] src : the appsrc element that emitted the signal
63 : * @param[in] offset : the offset to seek to
64 : * @param[in] user_data : The data to be passed with the message.
65 : *
66 : * @retval true if the handling of the message is successful, false otherwise.
67 : */
68 2 : gboolean appSrcSeekData(GstAppSrc *src, guint64 offset, gpointer user_data)
69 : {
70 2 : return TRUE;
71 : }
72 : } // namespace
73 :
74 : namespace firebolt::rialto::server::tasks::generic
75 : {
76 10 : FinishSetupSource::FinishSetupSource(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
77 10 : IGstGenericPlayerClient *client)
78 10 : : m_context{context}, m_player{player}, m_gstPlayerClient{client}
79 : {
80 10 : RIALTO_SERVER_LOG_DEBUG("Constructing FinishSetupSource");
81 : }
82 :
83 11 : FinishSetupSource::~FinishSetupSource()
84 : {
85 10 : RIALTO_SERVER_LOG_DEBUG("FinishSetupSource finished");
86 11 : }
87 :
88 9 : void FinishSetupSource::execute() const
89 : {
90 9 : RIALTO_SERVER_LOG_DEBUG("Executing FinishSetupSource");
91 9 : m_context.wereAllSourcesAttached = true;
92 :
93 9 : if (!m_context.source)
94 : {
95 1 : RIALTO_SERVER_LOG_DEBUG("Source is not ready");
96 1 : return;
97 : }
98 :
99 8 : GstAppSrcCallbacks callbacks = {appSrcNeedData, appSrcEnoughData, appSrcSeekData, {nullptr}};
100 :
101 25 : for (auto &elem : m_context.streamInfo)
102 : {
103 17 : firebolt::rialto::MediaSourceType sourceType = elem.first;
104 17 : if (sourceType == firebolt::rialto::MediaSourceType::UNKNOWN)
105 : {
106 1 : RIALTO_SERVER_LOG_WARN("Unknown media segment type");
107 1 : continue;
108 : }
109 :
110 16 : StreamInfo &streamInfo = elem.second;
111 16 : m_context.gstSrc->setupAndAddAppSrc(m_context.decryptionService, m_context.source, streamInfo, &callbacks,
112 16 : &m_player, sourceType);
113 16 : streamInfo.isDataNeeded = true;
114 16 : m_player.notifyNeedMediaData(sourceType);
115 : }
116 :
117 8 : m_context.gstSrc->allAppSrcsAdded(m_context.source);
118 :
119 : // Notify GstPlayerClient of Idle state once setup has finished
120 8 : if (m_gstPlayerClient)
121 8 : m_gstPlayerClient->notifyPlaybackState(PlaybackState::IDLE);
122 :
123 8 : m_context.setupSourceFinished = true;
124 :
125 8 : RIALTO_SERVER_LOG_MIL("All sources attached.");
126 16 : auto recordId = m_context.gstProfiler->createRecord("All Sources Attached");
127 8 : if (recordId)
128 0 : m_context.gstProfiler->logRecord(recordId.value());
129 : }
130 : } // namespace firebolt::rialto::server::tasks::generic
|