Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
32Q_FORWARD_DECLARE_OBJC_CLASS(AVAssetReaderTrackOutput);
34
36
38{
40
41 struct DecodingContext;
42
43public:
45 virtual ~AVFAudioDecoder();
46
47 QUrl source() const override;
48 void setSource(const QUrl &fileName) override;
49
50 QIODevice *sourceDevice() const override;
51 void setSourceDevice(QIODevice *device) override;
52
53 void start() override;
54 void stop() override;
55
56 QAudioFormat audioFormat() const override;
57 void setAudioFormat(const QAudioFormat &format) override;
58
59 QAudioBuffer read() override;
60
61private:
62 void handleNewAudioBuffer(QAudioBuffer);
63 void startReading();
64
65 void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
66 void initAssetReader();
67 void onFinished();
68
69 void waitUntilBuffersCounterLessMax();
70
71 void decBuffersCounter(uint val);
72
73 template<typename F>
74 void invokeWithDecodingContext(std::weak_ptr<DecodingContext> weakContext, F &&f);
75
76private:
77 QUrl m_source;
78 QIODevice *m_device = nullptr;
79 QAudioFormat m_format;
80
81 // Use a separate counter instead of buffers queue size in order to
82 // ensure atomic access and also make mutex locking shorter
83 std::atomic<int> m_buffersCounter = 0;
84 QQueue<QAudioBuffer> m_cachedBuffers;
85
86 AVURLAsset *m_asset = nullptr;
87
88 AVFResourceReaderDelegate *m_readerDelegate = nullptr;
89 dispatch_queue_t m_readingQueue;
90 dispatch_queue_t m_decodingQueue;
91
92 std::shared_ptr<DecodingContext> m_decodingContext;
93 QMutex m_buffersCounterMutex;
94 QWaitCondition m_buffersCounterCondition;
95};
96
98
99#endif // AVFAUDIODECODER_H
IOBluetoothDevice * device
QAudioBuffer read() override
void setAudioFormat(const QAudioFormat &format) override
AVFAudioDecoder(QAudioDecoder *parent)
QUrl source() const override
QIODevice * sourceDevice() const override
QAudioFormat audioFormat() const override
void setSource(const QUrl &fileName) override
void stop() override
void start() override
void setSourceDevice(QIODevice *device) override
virtual ~AVFAudioDecoder()
\inmodule QtMultimedia
The QAudioDecoder class implements decoding audio.
Error
Defines a media player error condition.
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qmutex.h:281
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
GLfloat GLfloat f
GLint GLsizei GLsizei GLenum format
GLuint GLfloat * val
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34