Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qffmpegmuxer.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 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
#
include
"qffmpegmuxer_p.h"
4
#
include
"qffmpegrecordingengine_p.h"
5
#
include
"qffmpegrecordingengineutils_p.h"
6
#
include
<
QtCore
/
qloggingcategory
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
namespace
QFFmpeg
{
11
12
Q_STATIC_LOGGING_CATEGORY
(
qLcFFmpegMuxer
,
"qt.multimedia.ffmpeg.muxer"
);
13
14
Muxer
::
Muxer
(
RecordingEngine
*encoder) : m_encoder(encoder)
15
{
16
setObjectName(QLatin1String(
"Muxer"
));
17
}
18
19
void
Muxer
::
addPacket
(AVPacketUPtr packet)
20
{
21
{
22
QMutexLocker locker = lockLoopData();
23
m_packetQueue.push(std::move(packet));
24
}
25
26
// qCDebug(qLcFFmpegEncoder) << "Muxer::addPacket" << packet->pts << packet->stream_index;
27
dataReady();
28
}
29
30
AVPacketUPtr
Muxer
::takePacket()
31
{
32
QMutexLocker locker = lockLoopData();
33
return
dequeueIfPossible(m_packetQueue);
34
}
35
36
bool
Muxer
::
init
()
37
{
38
qCDebug(qLcFFmpegMuxer) <<
"Muxer::init started thread."
;
39
return
true
;
40
}
41
42
void
Muxer
::
cleanup
()
43
{
44
while
(!m_packetQueue.empty())
45
processOne
(
)
;
46
47
const
int
status = av_interleaved_write_frame(m_encoder->avFormatContext(),
nullptr
);
48
if
(status < 0)
49
qCWarning(qLcFFmpegMuxer) <<
"Failed to flush muxer:"
<< AVError(status);
50
}
51
52
bool
QFFmpeg
::
Muxer
::
hasData
()
const
53
{
54
return
!m_packetQueue.empty();
55
}
56
57
void
Muxer
::
processOne
()
58
{
59
auto
packet = takePacket();
60
// qCDebug(qLcFFmpegEncoder) << "writing packet to file" << packet->pts << packet->duration <<
61
// packet->stream_index;
62
63
// from AVPacket Struct Reference:
64
// "The semantics of data ownership depends on the buf field. If it is set, the packet data is
65
// dynamically allocated and is valid indefinitely until a call to av_packet_unref() reduces the
66
// reference count to 0."
67
//
68
// from av_interleaved_write_frame:
69
// "If the packet is reference-counted, this function will take ownership of this reference and
70
// unreference it later when it sees fit. The caller must not access the data through this
71
// reference after this function returns. If the packet is not reference-counted, libavformat
72
// will make a copy."
73
//
74
// This means that av_interleaved_write_frame takes ownership of the AVBufferRef field, not the
75
// whole AVPacket.
76
77
const
int
status = av_interleaved_write_frame(m_encoder->avFormatContext(), packet.get());
78
if
(status < 0)
79
qCWarning(qLcFFmpegMuxer) <<
"Failed to write packet to file:"
<< AVError(status);
80
Q_ASSERT(packet->buf ==
nullptr
);
// av_interleaved_write_frame took ownership of the buffer
81
}
82
83
}
// namespace QFFmpeg
84
85
QT_END_NAMESPACE
QFFmpeg::Muxer
Definition
qffmpegmuxer_p.h:28
QFFmpeg::Muxer::init
bool init() override
Called on this thread when thread starts.
Definition
qffmpegmuxer.cpp:36
QFFmpeg::Muxer::cleanup
void cleanup() override
Called on this thread before thread exits.
Definition
qffmpegmuxer.cpp:42
QFFmpeg::Muxer::Muxer
Muxer(RecordingEngine *encoder)
Definition
qffmpegmuxer.cpp:14
QFFmpeg::Muxer::processOne
void processOne() override
Process one work item.
Definition
qffmpegmuxer.cpp:57
QFFmpeg::Muxer::addPacket
void addPacket(AVPacketUPtr packet)
Definition
qffmpegmuxer.cpp:19
QFFmpeg::Muxer::hasData
bool hasData() const override
Must return true when data is available for processing.
Definition
qffmpegmuxer.cpp:52
QFFmpeg::RecordingEngine
Definition
qffmpegrecordingengine_p.h:46
QFFmpeg
Definition
qandroidcacertificates.cpp:26
QFFmpeg::Q_STATIC_LOGGING_CATEGORY
Q_STATIC_LOGGING_CATEGORY(qLCAndroidCaCertificates, "qt.multimedia.ffmpeg.android.caCertificates")
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
plugins
multimedia
ffmpeg
recordingengine
qffmpegmuxer.cpp
Generated on
for Qt by
1.18.0