| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "playbackengine/qffmpegsubtitlerenderer_p.h" |
| 5 | |
| 6 | #include "qvideosink.h" |
| 7 | #include "qdebug.h" |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | namespace QFFmpeg { |
| 12 | |
| 13 | SubtitleRenderer::SubtitleRenderer(const TimeController &tc, QVideoSink *sink) |
| 14 | : Renderer(tc), m_sink(sink) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | void SubtitleRenderer::setOutput(QVideoSink *sink, bool cleanPrevSink) |
| 19 | { |
| 20 | setOutputInternal(actual&: m_sink, desired: sink, changeHandler: [=](QVideoSink *prev) { |
| 21 | if (!prev) |
| 22 | return; |
| 23 | |
| 24 | if (sink) |
| 25 | sink->setSubtitleText(prev->subtitleText()); |
| 26 | |
| 27 | if (cleanPrevSink) |
| 28 | prev->setSubtitleText({}); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | SubtitleRenderer::~SubtitleRenderer() |
| 33 | { |
| 34 | if (m_sink) |
| 35 | m_sink->setSubtitleText({}); |
| 36 | } |
| 37 | |
| 38 | Renderer::RenderingResult SubtitleRenderer::renderInternal(Frame frame) |
| 39 | { |
| 40 | if (m_sink) |
| 41 | m_sink->setSubtitleText(frame.isValid() ? frame.text() : QString()); |
| 42 | |
| 43 | return {}; |
| 44 | } |
| 45 | |
| 46 | } // namespace QFFmpeg |
| 47 | |
| 48 | QT_END_NAMESPACE |
| 49 | |
| 50 | #include "moc_qffmpegsubtitlerenderer_p.cpp" |
| 51 |
