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#ifndef QFFMPEGDEMUXER_P_H
4#define QFFMPEGDEMUXER_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "playbackengine/qffmpegplaybackengineobject_p.h"
18#include "private/qplatformmediaplayer_p.h"
19#include "playbackengine/qffmpegpacket_p.h"
20#include "playbackengine/qffmpegpositionwithoffset_p.h"
21
22#include <unordered_map>
23
24QT_BEGIN_NAMESPACE
25
26namespace QFFmpeg {
27
28class Demuxer : public PlaybackEngineObject
29{
30 Q_OBJECT
31public:
32 Demuxer(AVFormatContext *context, const PositionWithOffset &posWithOffset,
33 const StreamIndexes &streamIndexes, int loops);
34
35 using RequestingSignal = void (Demuxer::*)(Packet);
36 static RequestingSignal signalByTrackType(QPlatformMediaPlayer::TrackType trackType);
37
38 void setLoops(int loopsCount);
39
40public slots:
41 void onPacketProcessed(Packet);
42
43signals:
44 void requestProcessAudioPacket(Packet);
45 void requestProcessVideoPacket(Packet);
46 void requestProcessSubtitlePacket(Packet);
47 void firstPacketFound(TimePoint tp, qint64 trackPos);
48 void packetsBuffered();
49
50private:
51 bool canDoNextStep() const override;
52
53 void doNextStep() override;
54
55 void ensureSeeked();
56
57private:
58 struct StreamData
59 {
60 QPlatformMediaPlayer::TrackType trackType = QPlatformMediaPlayer::TrackType::NTrackTypes;
61 qint64 bufferedDuration = 0;
62 qint64 bufferedSize = 0;
63
64 qint64 maxSentPacketsPos = 0;
65 qint64 maxProcessedPacketPos = 0;
66
67 bool isDataLimitReached = false;
68 };
69
70 void updateStreamDataLimitFlag(StreamData &streamData);
71
72private:
73 AVFormatContext *m_context = nullptr;
74 bool m_seeked = false;
75 bool m_firstPacketFound = false;
76 std::unordered_map<int, StreamData> m_streams;
77 PositionWithOffset m_posWithOffset;
78 qint64 m_maxPacketsEndPos = 0;
79 QAtomicInt m_loops = QMediaPlayer::Once;
80 bool m_buffered = false;
81};
82
83} // namespace QFFmpeg
84
85QT_END_NAMESPACE // QFFMPEGDEMUXER_P_H
86
87#endif
88

source code of qtmultimedia/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegdemuxer_p.h