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/qaudiodecoder.h>
19#include <QtMultimedia/private/qplatformaudiodecoder_p.h>
20#include <QtMultimedia/private/qtmultimediaglobal_p.h>
21#include <QtCore/qmutex.h>
22#include <QtCore/qobject.h>
23#include <QtCore/qqueue.h>
24#include <QtCore/qurl.h>
25#include <QtCore/qwaitcondition.h>
26
27#import <dispatch/dispatch.h>
28#import <AVFoundation/AVFoundation.h>
29
30@class AVFResourceReaderDelegate;
31
32QT_BEGIN_NAMESPACE
33
34class AVFAudioDecoder final : public QPlatformAudioDecoder
35{
36 Q_OBJECT
37
38 struct DecodingContext;
39
40public:
41 AVFAudioDecoder(QAudioDecoder *parent);
42 ~AVFAudioDecoder() override;
43
44 QUrl source() const override;
45 void setSource(const QUrl &fileName) override;
46
47 QIODevice *sourceDevice() const override;
48 void setSourceDevice(QIODevice *device) override;
49
50 void start() override;
51 void stop() override;
52
53 QAudioFormat audioFormat() const override;
54 void setAudioFormat(const QAudioFormat &format) override;
55
56 QAudioBuffer read() override;
57
58private:
59 void handleNewAudioBuffer(QAudioBuffer);
60 void startReading(QAudioFormat);
61
62 void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
63 void initAssetReader();
64 void onFinished();
65
66 void waitUntilBuffersCounterLessMax();
67
68 void decBuffersCounter(uint val);
69
70 template<typename F>
71 void invokeWithDecodingContext(std::weak_ptr<DecodingContext> weakContext, F &&f);
72 Q_INVOKABLE void initAssetReaderImpl(AVAssetTrack *track, NSError *error);
73
74private:
75 QUrl m_source;
76 QIODevice *m_device = nullptr;
77 QAudioFormat m_format;
78
79 // Use a separate counter instead of buffers queue size in order to
80 // ensure atomic access and also make mutex locking shorter
81 std::atomic<int> m_buffersCounter = 0;
82 QQueue<QAudioBuffer> m_cachedBuffers;
83
84 AVURLAsset *m_asset = nullptr;
85
86 AVFResourceReaderDelegate *m_readerDelegate = nullptr;
87 dispatch_queue_t m_readingQueue;
88 dispatch_queue_t m_decodingQueue;
89
90 std::shared_ptr<DecodingContext> m_decodingContext;
91 QMutex m_buffersCounterMutex;
92 QWaitCondition m_buffersCounterCondition;
93};
94
95QT_END_NAMESPACE
96
97#endif // AVFAUDIODECODER_H
static constexpr int MAX_BUFFERS_IN_QUEUE
static QAudioBuffer handleNextSampleBuffer(QAudioFormat qtFormat, const QCFType< CMSampleBufferRef > &sampleBuffer)
AVAssetReaderTrackOutput * m_readerOutput
QImage::Format format
Definition qimage_p.h:53