29 : m_context(
context), m_posWithOffset(posWithOffset)
31 qCDebug(qLcDemuxer) <<
"Create demuxer."
32 <<
"pos:" << posWithOffset.
pos <<
"loop offset:" << posWithOffset.
offset.
pos
33 <<
"loop index:" << posWithOffset.
offset.
index <<
"loops:" << loops;
40 if (streamIndexes[
i] >= 0) {
42 qCDebug(qLcDemuxer) <<
"Activate demuxing stream" <<
i <<
", trackType:" << trackType;
43 m_streams[streamIndexes[
i]] = { trackType };
53 if (av_read_frame(m_context, packet.
avPacket()) < 0) {
56 if (m_loops >= 0 && m_posWithOffset.
offset.
index >= m_loops) {
57 qCDebug(qLcDemuxer) <<
"finish demuxing";
61 m_posWithOffset.
pos = 0;
68 <<
"Offset:" << m_posWithOffset.
offset.
pos;
74 const auto streamIndex = packet.
avPacket()->stream_index;
75 const auto stream = m_context->streams[streamIndex];
77 auto it = m_streams.find(streamIndex);
79 if (
it != m_streams.end()) {
80 const auto packetEndPos =
82 m_endPts = std::max(m_endPts, m_posWithOffset.
offset.
pos + packetEndPos);
85 it->second.bufferingSize += packet.
avPacket()->size;
101 const auto streamIndex = packet.
avPacket()->stream_index;
102 auto it = m_streams.find(streamIndex);
104 if (
it != m_streams.end()) {
105 it->second.bufferingTime -=
107 it->second.bufferingSize -= packet.
avPacket()->size;
121 auto checkBufferingTime = [](
const auto &streamIndexToData) {
126 return std::all_of(m_streams.begin(), m_streams.end(), checkBufferingTime);
129void Demuxer::ensureSeeked()
131 if (std::exchange(m_seeked,
true))
134 const qint64 seekPos = m_posWithOffset.
pos * AV_TIME_BASE / 1000000;
135 auto err = av_seek_frame(m_context, -1, seekPos, AVSEEK_FLAG_BACKWARD);
165 qCDebug(qLcDemuxer) <<
"setLoops to demuxer" << loopsCount;
166 m_loops = loopsCount;
173#include "moc_qffmpegdemuxer_p.cpp"
Demuxer(AVFormatContext *context, const PositionWithOffset &posWithOffset, const StreamIndexes &streamIndexes, int loops)
void setLoops(int loopsCount)
void doNextStep() override
void requestProcessVideoPacket(Packet)
void(Demuxer::*)(Packet) RequestingSignal
void onPacketProcessed(Packet)
void requestProcessAudioPacket(Packet)
void requestProcessSubtitlePacket(Packet)
static RequestingSignal signalByTrackType(QPlatformMediaPlayer::TrackType trackType)
bool canDoNextStep() const override
virtual bool canDoNextStep() const
void error(int code, const QString &errorString)
void setAtEnd(bool isAtEnd)
void scheduleNextStep(bool allowDoImmediatelly=true)
QSet< QString >::iterator it
std::array< int, 3 > StreamIndexes
QString err2str(int errnum)
std::unique_ptr< AVPacket, AVDeleter< decltype(&av_packet_free), &av_packet_free > > AVPacketUPtr
std::optional< qint64 > mul(qint64 a, AVRational b)
static qint64 streamTimeToUs(const AVStream *stream, qint64 time)
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE constexpr qint64 MaxBufferingTimeUs
static constexpr qint64 MaxBufferingSize
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
AVPacket * avPacket() const