Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
avfaudiodecoder_p.h
Go to the documentation of this file.
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#ifndef AVFAUDIODECODER_H
5#define AVFAUDIODECODER_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 <QtMultimedia/private/qtmultimediaglobal_p.h>
19#include <QObject>
20#include <QtCore/qurl.h>
21#include <QWaitCondition>
22#include <QMutex>
23#include <QQueue>
24
25#include "private/qplatformaudiodecoder_p.h"
26#include "qaudiodecoder.h"
27
28#include <dispatch/dispatch.h>
29
36
37QT_BEGIN_NAMESPACE
38
39class AVFAudioDecoder final : public QPlatformAudioDecoder
40{
41 Q_OBJECT
42
43 struct DecodingContext;
44
45public:
46 AVFAudioDecoder(QAudioDecoder *parent);
47 ~AVFAudioDecoder() override;
48
49 QUrl source() const override;
50 void setSource(const QUrl &fileName) override;
51
52 QIODevice *sourceDevice() const override;
53 void setSourceDevice(QIODevice *device) override;
54
55 void start() override;
56 void stop() override;
57
58 QAudioFormat audioFormat() const override;
59 void setAudioFormat(const QAudioFormat &format) override;
60
61 QAudioBuffer read() override;
62
63private:
64 void handleNewAudioBuffer(QAudioBuffer);
65 void startReading();
66
67 void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
68 void initAssetReader();
69 void onFinished();
70
71 void waitUntilBuffersCounterLessMax();
72
73 void decBuffersCounter(uint val);
74
75 template<typename F>
76 void invokeWithDecodingContext(std::weak_ptr<DecodingContext> weakContext, F &&f);
77 Q_INVOKABLE void initAssetReaderImpl(AVAssetTrack *track, NSError *error);
78
79private:
80 QUrl m_source;
81 QIODevice *m_device = nullptr;
82 QAudioFormat m_format;
83
84 // Use a separate counter instead of buffers queue size in order to
85 // ensure atomic access and also make mutex locking shorter
86 std::atomic<int> m_buffersCounter = 0;
87 QQueue<QAudioBuffer> m_cachedBuffers;
88
89 AVURLAsset *m_asset = nullptr;
90
91 AVFResourceReaderDelegate *m_readerDelegate = nullptr;
92 dispatch_queue_t m_readingQueue;
93 dispatch_queue_t m_decodingQueue;
94
95 std::shared_ptr<DecodingContext> m_decodingContext;
96 QMutex m_buffersCounterMutex;
97 QWaitCondition m_buffersCounterCondition;
98};
99
100QT_END_NAMESPACE
101
102#endif // AVFAUDIODECODER_H
static constexpr int MAX_BUFFERS_IN_QUEUE
static QAudioBuffer handleNextSampleBuffer(CMSampleBufferRef sampleBuffer)
Q_FORWARD_DECLARE_OBJC_CLASS(AVURLAsset)
Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetReader)
Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetTrack)
Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetReaderTrackOutput)
Q_FORWARD_DECLARE_OBJC_CLASS(AVFResourceReaderDelegate)
Q_FORWARD_DECLARE_OBJC_CLASS(NSError)
AVAssetReaderTrackOutput * m_readerOutput