File indexing completed on 2024-06-16 04:38:29

0001 /*
0002     SPDX-FileCopyrightText: 2003 Fabrice Bellard
0003     SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef PACKETQUEUE_H
0009 #define PACKETQUEUE_H
0010 
0011 #include <QObject>
0012 
0013 QT_FORWARD_DECLARE_CLASS(QMutex)
0014 QT_FORWARD_DECLARE_CLASS(QWaitCondition)
0015 
0016 extern "C" {
0017 #include "libavformat/avformat.h"
0018 }
0019 
0020 namespace SubtitleComposer {
0021 class PacketQueue
0022 {
0023 public:
0024     PacketQueue();
0025 
0026     /**
0027      * @brief enqueue a packet
0028      * @param pkt packet allocated with av_packet_alloc(), pkt will be set to nullptr
0029      * @return 0 if successful; <0 otherwise
0030      */
0031     int put(AVPacket **pkt);
0032     int putFlushPacket();
0033     int putNullPacket(int streamIndex);
0034     int init();
0035     void flush();
0036     void destroy();
0037     void abort();
0038     void start();
0039     /**
0040      * @brief dequeue a packet
0041      * @param pkt will be set to packet which must be freed with av_packet_free()
0042      * @param block
0043      * @param serial
0044      * @return <0 if aborted, 0 if no packet and >0 if packet
0045      */
0046     int get(AVPacket **pkt, int block, int *serial);
0047 
0048     inline int nbPackets() const { return m_nbPackets; }
0049     inline int size() const { return m_size; }
0050     inline int64_t duration() const { return m_duration; }
0051     inline bool abortRequested() const { return m_abortRequest; }
0052     inline int serial() const { return m_serial; }
0053 
0054 private:
0055     int put_private(AVPacket **pkt);
0056 
0057 private:
0058     struct PacketList {
0059         AVPacket *pkt;
0060         PacketList *next;
0061         int serial;
0062     };
0063 
0064     PacketList *m_firstPkt, *m_lastPkt;
0065     int m_nbPackets;
0066     int m_size;
0067     int64_t m_duration;
0068     bool m_abortRequest;
0069     int m_serial;
0070     QMutex *m_mutex;
0071     QWaitCondition *m_cond;
0072 
0073     friend class Decoder;
0074     friend class FrameQueue;
0075     friend class Clock;
0076 };
0077 }
0078 
0079 #endif // PACKETQUEUE_H