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 4 : void appSrcEnoughData(GstAppSrc *src, gpointer user_data)
53 : {
54 4 : firebolt::rialto::server::IGstGenericPlayerPrivate *self =
55 : static_cast<firebolt::rialto::server::IGstGenericPlayerPrivate *>(user_data);
56 4 : 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 : appSrcEnoughData(src, user_data);
71 2 : return TRUE;
72 : }
73 : } // namespace
74 :
75 : namespace firebolt::rialto::server::tasks::generic
76 : {
77 10 : FinishSetupSource::FinishSetupSource(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
78 10 : IGstGenericPlayerClient *client)
79 10 : : m_context{context}, m_player{player}, m_gstPlayerClient{client}
80 : {
81 10 : RIALTO_SERVER_LOG_DEBUG("Constructing FinishSetupSource");
82 : }
83 :
84 11 : FinishSetupSource::~FinishSetupSource()
85 : {
86 10 : RIALTO_SERVER_LOG_DEBUG("FinishSetupSource finished");
87 11 : }
88 :
89 9 : void FinishSetupSource::execute() const
90 : {
91 9 : RIALTO_SERVER_LOG_DEBUG("Executing FinishSetupSource");
92 9 : m_context.wereAllSourcesAttached = true;
93 :
94 9 : if (!m_context.source)
95 : {
96 1 : RIALTO_SERVER_LOG_DEBUG("Source is not ready");
97 1 : return;
98 : }
99 :
100 8 : GstAppSrcCallbacks callbacks = {appSrcNeedData, appSrcEnoughData, appSrcSeekData, {nullptr}};
101 :
102 25 : for (auto &elem : m_context.streamInfo)
103 : {
104 17 : firebolt::rialto::MediaSourceType sourceType = elem.first;
105 17 : if (sourceType == firebolt::rialto::MediaSourceType::UNKNOWN)
106 : {
107 1 : RIALTO_SERVER_LOG_WARN("Unknown media segment type");
108 1 : continue;
109 : }
110 :
111 16 : StreamInfo &streamInfo = elem.second;
112 16 : m_context.gstSrc->setupAndAddAppArc(m_context.decryptionService, m_context.source, streamInfo, &callbacks,
113 16 : &m_player, sourceType);
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 : } // namespace firebolt::rialto::server::tasks::generic
|