summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/qnx/mediaplayer/qqnxmediaplayer_p.h
blob: c570a6334d2067074fea7bfd44c4098b43772a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (C) 2016 Research In Motion
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQnxMediaPlayer_H
#define QQnxMediaPlayer_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qqnxmediametadata_p.h"
#include "mmrenderertypes.h"

#include <private/qplatformmediaplayer_p.h>
#include <QtCore/qabstractnativeeventfilter.h>
#include <QtCore/qpointer.h>
#include <QtCore/qtimer.h>

#include <mm/renderer.h>
#include <mm/renderer/types.h>

#include <optional>

QT_BEGIN_NAMESPACE

class QQnxVideoSink;
class QQnxMediaEventThread;
class QQnxWindowGrabber;

class QQnxMediaPlayer : public QObject
                      , public QPlatformMediaPlayer
{
    Q_OBJECT
public:
    explicit QQnxMediaPlayer(QMediaPlayer *parent = nullptr);
    ~QQnxMediaPlayer();

    qint64 duration() const override;

    qint64 position() const override;
    void setPosition(qint64 position) override;

    void setAudioOutput(QPlatformAudioOutput *) override;

    float bufferProgress() const override;

    bool isAudioAvailable() const override;
    bool isVideoAvailable() const override;

    bool isSeekable() const override;

    QMediaTimeRange availablePlaybackRanges() const override;

    qreal playbackRate() const override;
    void setPlaybackRate(qreal rate) override;

    QUrl media() const override;
    const QIODevice *mediaStream() const override;
    void setMedia(const QUrl &media, QIODevice *stream) override;

    void play() override;
    void pause() override;
    void stop() override;

    void setVideoSink(QVideoSink *videoSink);

private Q_SLOTS:
    void setVolume(float volume);
    void setMuted(bool muted);
    void readEvents();

private:
    void startMonitoring();
    void stopMonitoring();
    void resetMonitoring();

    void openConnection();
    void emitMmError(const char *msg);
    void emitMmError(const QString &msg);
    void emitPError(const QString &msg);

    void handleMmPositionChanged(qint64 newPosition);
    void updateBufferLevel(int level, int capacity);
    void updateMetaData(const strm_dict_t *dict);

    void handleMmEventState(const mmr_event_t *event);
    void handleMmEventStatus(const mmr_event_t *event);
    void handleMmEventStatusData(const strm_dict_t *data);
    void handleMmEventError(const mmr_event_t *event);

    QByteArray resourcePathForUrl(const QUrl &url);

    void closeConnection();
    void attach();

    bool attachVideoOutput();
    bool attachAudioOutput();
    bool attachInput();

    void detach();
    void detachVideoOutput();
    void detachAudioOutput();
    void detachInput();

    bool isVideoOutputAttached() const;
    bool isAudioOutputAttached() const;
    bool isInputAttached() const;

    void updateScene(const QSize &size);

    void updateVolume();

    void setPositionInternal(qint64 position);
    void flushPosition();

    bool isPendingPositionFlush() const;

    void setDeferredSpeedEnabled(bool enabled);
    bool isDeferredSpeedEnabled() const;

    mmr_context_t *m_context = nullptr;
    mmr_connection_t *m_connection = nullptr;

    QString m_contextName;

    int m_id = -1;
    int m_audioId = -1;
    int m_volume = 50; // range is 0-100

    QUrl m_media;
    QPointer<QAudioOutput> m_audioOutput;
    QPointer<QQnxVideoSink> m_platformVideoSink;

    QQnxMediaMetaData m_metaData;

    qint64 m_position = 0;
    qint64 m_pendingPosition = 0;

    int m_bufferLevel = 0;

    int m_videoId = -1;

    QTimer m_flushPositionTimer;

    QQnxMediaEventThread *m_eventThread = nullptr;

    int m_speed = 1000;
    int m_configuredSpeed = 1000;

    std::optional<int> m_deferredSpeed;

    QQnxWindowGrabber* m_windowGrabber = nullptr;

    bool m_inputAttached = false;
    bool m_muted = false;
    bool m_deferredSpeedEnabled = false;
};

QT_END_NAMESPACE

#endif