p26001-store-acs-soc-fw-app/video/core/Packet.h
2026-09-28 21:33:04 +08:00

126 lines
2.6 KiB
C++

#ifndef AE3F35DC_04CA_417F_8D57_CADC8913678F
#define AE3F35DC_04CA_417F_8D57_CADC8913678F
/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include "NotificationQueue.h"
#include <Poco/SharedPtr.h>
#include "SerialCode.h"
#if defined(USING_FFMPEG)
extern "C"
{
#include <libavcodec/packet.h>
#include <libavutil/mem.h>
}
#endif
namespace Video
{
namespace Core
{
/*
*******************************************************************************
* CLASS DECLARE
*******************************************************************************
*/
class Packet
{
public:
using Ptr = Poco::SharedPtr<Packet>;
static const uint32_t FLAG_IS_VIDEO;
static const uint32_t FLAG_IS_KEY;
static const uint32_t FLAG_IS_AAC_HEADER;
static const uint32_t FLAG_IS_SEI;
public:
Packet();
Packet(const SerialCode& code, uint32_t flags, uint8_t* data, uint32_t length, int64_t pts, int64_t dts);
#if defined(USING_FFMPEG)
Packet(const SerialCode& code, bool isVideo, AVPacket** packet);
#endif
Packet(const Packet& other);
virtual ~Packet();
virtual void moveTo(AVPacket** packet);
bool isVideo() const;
bool isKeyFrame() const;
Ptr clone();
const SerialCode& serialCode();
const uint8_t* data();
uint32_t length();
uint64_t pts();
uint64_t dts();
uint32_t flags();
Poco::SharedPtr<uint8_t>& sharedData();
protected:
#if defined(USING_FFMPEG)
AVPacket* buildAVPacket();
virtual void convertToAVPacket(AVPacket* pPacket);
#endif
private:
SerialCode _code;
uint32_t _flags;
int64_t _pts, _dts;
Poco::SharedPtr<uint8_t> _pData;
uint32_t _length;
#if defined(USING_FFMPEG)
AVPacket* _pAVPacket;
#endif
};
using PacketQueue = NotificationQueue<Packet>;
inline bool Packet::isVideo() const
{
return (_flags & FLAG_IS_VIDEO) > 0;
}
inline bool Packet::isKeyFrame() const
{
return (_flags & FLAG_IS_KEY) > 0;
}
inline Packet::Ptr Packet::clone()
{
return new Packet(*this);
}
inline uint32_t Packet::length()
{
return _length;
}
inline uint64_t Packet::pts()
{
return _pts;
}
inline uint64_t Packet::dts()
{
return _dts;
}
inline uint32_t Packet::flags()
{
return _flags;
}
inline const SerialCode& Packet::serialCode()
{
return _code;
}
inline Poco::SharedPtr<uint8_t>& Packet::sharedData()
{
return _pData;
}
}
}
#endif