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 : if (m_context.videoSink)
46 : {
47 0 : gint64 position = 0;
48 0 : if (m_gstWrapper->gstElementQueryPosition(m_context.videoSink, GST_FORMAT_TIME, &position))
49 : {
50 0 : RIALTO_SERVER_LOG_DEBUG("Videosink position: %" PRId64 " ns", position);
51 : }
52 :
53 0 : auto sourceElem = m_context.streamInfo.find(MediaSourceType::SUBTITLE);
54 0 : GstElement *source{nullptr};
55 :
56 0 : if (sourceElem != m_context.streamInfo.end())
57 : {
58 0 : source = sourceElem->second.appSrc;
59 : }
60 : else
61 : {
62 0 : RIALTO_SERVER_LOG_WARN("subtitle source not found");
63 0 : return;
64 : }
65 :
66 0 : GstStructure *structure = m_gstWrapper->gstStructureNew("current-pts", "pts", G_TYPE_UINT64, position, nullptr);
67 0 : GstEvent *event = m_gstWrapper->gstEventNewCustom(GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
68 :
69 0 : if (event)
70 : {
71 0 : if (m_gstWrapper->gstElementSendEvent(source, event))
72 : {
73 0 : RIALTO_SERVER_LOG_DEBUG("Sent current-pts event to subtitlesource");
74 : }
75 : else
76 : {
77 0 : RIALTO_SERVER_LOG_ERROR("Failed to send current-pts event to source");
78 : }
79 : }
80 : else
81 : {
82 0 : RIALTO_SERVER_LOG_ERROR("Failed to create current-pts event");
83 : }
84 : }
85 : else
86 : {
87 0 : RIALTO_SERVER_LOG_ERROR("video-sink is NULL");
88 : }
89 : }
90 :
91 : } // namespace firebolt::rialto::server::tasks::generic
|