| 1 | // Copyright (C) 2016 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 "qplatformvideosink_p.h" |
| 5 | #include "qmultimediautils_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | QPlatformVideoSink::QPlatformVideoSink(QVideoSink *parent) : QObject(parent), m_sink(parent) { } |
| 10 | |
| 11 | QPlatformVideoSink::~QPlatformVideoSink() = default; |
| 12 | |
| 13 | QSize QPlatformVideoSink::nativeSize() const |
| 14 | { |
| 15 | QMutexLocker locker(&m_mutex); |
| 16 | return m_nativeSize; |
| 17 | } |
| 18 | |
| 19 | void QPlatformVideoSink::setNativeSize(QSize s) |
| 20 | { |
| 21 | { |
| 22 | QMutexLocker locker(&m_mutex); |
| 23 | if (m_nativeSize == s) |
| 24 | return; |
| 25 | m_nativeSize = s; |
| 26 | } |
| 27 | emit m_sink->videoSizeChanged(); |
| 28 | } |
| 29 | |
| 30 | void QPlatformVideoSink::setVideoFrame(const QVideoFrame &frame) |
| 31 | { |
| 32 | bool sizeChanged = false; |
| 33 | QVideoFrame currentFrame; |
| 34 | { |
| 35 | QMutexLocker locker(&m_mutex); |
| 36 | if (frame == m_currentVideoFrame) |
| 37 | return; |
| 38 | m_currentVideoFrame = frame; |
| 39 | m_currentVideoFrame.setSubtitleText(m_subtitleText); |
| 40 | const QSize size = qRotatedFramePresentationSize(frame); |
| 41 | if (size != m_nativeSize) { |
| 42 | m_nativeSize = size; |
| 43 | sizeChanged = true; |
| 44 | } |
| 45 | currentFrame = m_currentVideoFrame; |
| 46 | } |
| 47 | |
| 48 | onVideoFrameChanged(currentFrame); |
| 49 | |
| 50 | // emit signals outside the mutex to avoid deadlocks on the user side |
| 51 | if (sizeChanged) |
| 52 | emit m_sink->videoSizeChanged(); |
| 53 | emit m_sink->videoFrameChanged(frame); |
| 54 | } |
| 55 | |
| 56 | QVideoFrame QPlatformVideoSink::currentVideoFrame() const |
| 57 | { |
| 58 | QMutexLocker locker(&m_mutex); |
| 59 | return m_currentVideoFrame; |
| 60 | } |
| 61 | |
| 62 | void QPlatformVideoSink::setSubtitleText(const QString &subtitleText) |
| 63 | { |
| 64 | { |
| 65 | QMutexLocker locker(&m_mutex); |
| 66 | if (m_subtitleText == subtitleText) |
| 67 | return; |
| 68 | m_subtitleText = subtitleText; |
| 69 | } |
| 70 | emit m_sink->subtitleTextChanged(subtitleText); |
| 71 | } |
| 72 | |
| 73 | QString QPlatformVideoSink::subtitleText() const |
| 74 | { |
| 75 | QMutexLocker locker(&m_mutex); |
| 76 | return m_subtitleText; |
| 77 | } |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 | |
| 81 | #include "moc_qplatformvideosink_p.cpp" |
| 82 |
