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#ifndef QFFMPEGMEDIACAPTURESESSION_H
5#define QFFMPEGMEDIACAPTURESESSION_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qplatformmediacapture_p.h>
19#include <private/qplatformmediaintegration_p.h>
20#include "qpointer.h"
21#include "qiodevice.h"
22
23QT_BEGIN_NAMESPACE
24
25class QFFmpegMediaRecorder;
26class QFFmpegImageCapture;
27class QVideoFrame;
28class QAudioSink;
29class QFFmpegAudioInput;
30class QAudioBuffer;
31class QPlatformVideoSource;
32class QPlatformAudioBufferInput;
33class QPlatformAudioBufferInputBase;
34
35class QFFmpegMediaCaptureSession : public QPlatformMediaCaptureSession
36{
37 Q_OBJECT
38
39public:
40 using VideoSources = std::vector<QPointer<QPlatformVideoSource>>;
41
42 QFFmpegMediaCaptureSession();
43 ~QFFmpegMediaCaptureSession() override;
44
45 QPlatformCamera *camera() override;
46 void setCamera(QPlatformCamera *camera) override;
47
48 QPlatformSurfaceCapture *screenCapture() override;
49 void setScreenCapture(QPlatformSurfaceCapture *) override;
50
51 QPlatformSurfaceCapture *windowCapture() override;
52 void setWindowCapture(QPlatformSurfaceCapture *) override;
53
54 QPlatformVideoFrameInput *videoFrameInput() override;
55 void setVideoFrameInput(QPlatformVideoFrameInput *) override;
56
57 QPlatformImageCapture *imageCapture() override;
58 void setImageCapture(QPlatformImageCapture *imageCapture) override;
59
60 QPlatformMediaRecorder *mediaRecorder() override;
61 void setMediaRecorder(QPlatformMediaRecorder *recorder) override;
62
63 void setAudioInput(QPlatformAudioInput *input) override;
64 QPlatformAudioInput *audioInput() const;
65
66 void setAudioBufferInput(QPlatformAudioBufferInput *input) override;
67
68 void setVideoPreview(QVideoSink *sink) override;
69 void setAudioOutput(QPlatformAudioOutput *output) override;
70
71 QPlatformVideoSource *primaryActiveVideoSource();
72
73 // it might be moved to the base class, but it needs QPlatformAudioInput
74 // to be QPlatformAudioBufferInputBase, which might not make sense
75 std::vector<QPlatformAudioBufferInputBase *> activeAudioInputs() const;
76
77private Q_SLOTS:
78 void updateAudioSink();
79 void updateVolume();
80 void updateVideoFrameConnection();
81 void updatePrimaryActiveVideoSource();
82
83Q_SIGNALS:
84 void primaryActiveVideoSourceChanged();
85
86private:
87 template<typename VideoSource>
88 bool setVideoSource(QPointer<VideoSource> &source, VideoSource *newSource);
89
90 QPointer<QPlatformCamera> m_camera;
91 QPointer<QPlatformSurfaceCapture> m_screenCapture;
92 QPointer<QPlatformSurfaceCapture> m_windowCapture;
93 QPointer<QPlatformVideoFrameInput> m_videoFrameInput;
94 QPointer<QPlatformVideoSource> m_primaryActiveVideoSource;
95
96 QPointer<QFFmpegAudioInput> m_audioInput;
97 QPointer<QPlatformAudioBufferInput> m_audioBufferInput;
98
99 QFFmpegImageCapture *m_imageCapture = nullptr;
100 QFFmpegMediaRecorder *m_mediaRecorder = nullptr;
101 QPlatformAudioOutput *m_audioOutput = nullptr;
102 QVideoSink *m_videoSink = nullptr;
103 std::unique_ptr<QAudioSink> m_audioSink;
104 QPointer<QIODevice> m_audioIODevice;
105 qsizetype m_audioBufferSize = 0;
106
107 QMetaObject::Connection m_videoFrameConnection;
108};
109
110QT_END_NAMESPACE
111
112#endif // QGSTREAMERCAPTURESERVICE_H
113

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/qffmpegmediacapturesession_p.h