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 2025 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/SynchroniseSubtitleClock.h"
21 : #include "IGstGenericPlayerPrivate.h"
22 : #include "RialtoServerLogging.h"
23 : #include "TypeConverters.h"
24 : #include <inttypes.h>
25 :
26 : namespace firebolt::rialto::server::tasks::generic
27 : {
28 1 : SynchroniseSubtitleClock::SynchroniseSubtitleClock(
29 : GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
30 : const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper,
31 1 : const std::shared_ptr<firebolt::rialto::wrappers::IGlibWrapper> &glibWrapper)
32 1 : : m_context{context}, m_player{player}, m_gstWrapper{gstWrapper}, m_glibWrapper{glibWrapper}
33 : {
34 1 : RIALTO_SERVER_LOG_DEBUG("Constructing SynchroniseSubtitleClock");
35 : }
36 :
37 2 : SynchroniseSubtitleClock::~SynchroniseSubtitleClock()
38 : {
39 1 : RIALTO_SERVER_LOG_DEBUG("SynchroniseSubtitleClock finished");
40 2 : }
41 :
42 0 : void SynchroniseSubtitleClock::execute() const
43 : {
44 0 : RIALTO_SERVER_LOG_DEBUG("Executing SynchroniseSubtitleClock");
45 0 : gint64 position = m_player.getPosition(m_context.pipeline);
46 0 : if (position == -1)
47 : {
48 0 : RIALTO_SERVER_LOG_WARN("Getting the position failed");
49 0 : return;
50 : }
51 :
52 0 : auto sourceElem = m_context.streamInfo.find(MediaSourceType::SUBTITLE);
53 0 : GstElement *source{nullptr};
54 :
55 0 : if (sourceElem != m_context.streamInfo.end())
56 : {
57 0 : source = sourceElem->second.appSrc;
58 : }
59 : else
60 : {
61 0 : RIALTO_SERVER_LOG_WARN("subtitle source not found");
62 0 : return;
63 : }
64 :
65 0 : GstStructure *structure = m_gstWrapper->gstStructureNew("current-pts", "pts", G_TYPE_UINT64, position, nullptr);
66 0 : GstEvent *event = m_gstWrapper->gstEventNewCustom(GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
67 :
68 0 : if (event)
69 : {
70 0 : if (m_gstWrapper->gstElementSendEvent(source, event))
71 : {
72 0 : RIALTO_SERVER_LOG_DEBUG("Sent current-pts event to subtitlesource");
73 : }
74 : else
75 : {
76 0 : RIALTO_SERVER_LOG_ERROR("Failed to send current-pts event to source");
77 : }
78 : }
79 : else
80 : {
81 0 : RIALTO_SERVER_LOG_ERROR("Failed to create current-pts event");
82 0 : m_gstWrapper->gstStructureFree(structure);
83 : }
84 : }
85 :
86 : } // namespace firebolt::rialto::server::tasks::generic
|