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 "SetSourcePosition.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 8 : SetSourcePosition::SetSourcePosition(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
28 : IGstGenericPlayerClient *client,
29 : const std::shared_ptr<wrappers::IGlibWrapper> &glibWrapper,
30 : const MediaSourceType &type, std::int64_t position, bool resetTime,
31 8 : double appliedRate, uint64_t stopPosition)
32 16 : : m_context{context}, m_player(player), m_gstPlayerClient{client}, m_glibWrapper{glibWrapper}, m_type{type},
33 8 : m_position{position}, m_resetTime{resetTime}, m_appliedRate{appliedRate}, m_stopPosition{stopPosition}
34 : {
35 8 : RIALTO_SERVER_LOG_DEBUG("Constructing SetSourcePosition");
36 : }
37 :
38 9 : SetSourcePosition::~SetSourcePosition()
39 : {
40 8 : RIALTO_SERVER_LOG_DEBUG("SetSourcePosition finished");
41 9 : }
42 :
43 7 : void SetSourcePosition::execute() const
44 : {
45 7 : RIALTO_SERVER_LOG_DEBUG("Executing SetSourcePosition for %s source", common::convertMediaSourceType(m_type));
46 :
47 7 : if (MediaSourceType::UNKNOWN == m_type)
48 : {
49 1 : RIALTO_SERVER_LOG_WARN("failed to set source position - source type is unknown");
50 2 : return;
51 : }
52 :
53 : // Get source first
54 6 : GstElement *source{nullptr};
55 6 : auto sourceElem = m_context.streamInfo.find(m_type);
56 6 : if (sourceElem != m_context.streamInfo.end())
57 : {
58 5 : source = sourceElem->second.appSrc;
59 : }
60 6 : if (!source)
61 : {
62 1 : RIALTO_SERVER_LOG_WARN("failed to set source position - %s source is NULL",
63 : common::convertMediaSourceType(m_type));
64 1 : return;
65 : }
66 :
67 5 : if (MediaSourceType::VIDEO == m_type || MediaSourceType::AUDIO == m_type)
68 : {
69 3 : m_context.initialPositions[source].emplace_back(
70 3 : SegmentData{m_position, m_resetTime, m_appliedRate, m_stopPosition});
71 : }
72 2 : else if (MediaSourceType::SUBTITLE == m_type)
73 : {
74 2 : setSubtitlePosition(source);
75 : }
76 :
77 5 : if (m_context.setupSourceFinished)
78 : {
79 : // Reset Eos info
80 3 : m_context.endOfStreamInfo.erase(m_type);
81 3 : m_context.eosNotified = false;
82 :
83 : // Trigger NeedData for source
84 3 : NeedData task{m_context, m_player, m_gstPlayerClient, GST_APP_SRC(source)};
85 3 : task.execute();
86 : }
87 : }
88 :
89 2 : void SetSourcePosition::setSubtitlePosition(GstElement *source) const
90 : {
91 : // in case of subtitles, all data might be already in the sink and we might not get any data anymore,
92 : // so set position here and to not depend on any following buffers
93 2 : if (m_context.setupSourceFinished)
94 : {
95 1 : m_glibWrapper->gObjectSet(m_context.subtitleSink, "position", static_cast<guint64>(m_position), nullptr);
96 : }
97 : else
98 : {
99 1 : m_context.initialPositions[source].emplace_back(
100 1 : SegmentData{m_position, m_resetTime, m_appliedRate, m_stopPosition});
101 : }
102 2 : }
103 :
104 : } // namespace firebolt::rialto::server::tasks::generic
|