From bfdd34d45b16201f14c764d5dd81a03333c06337 Mon Sep 17 00:00:00 2001 From: Michel Promonet Date: Sun, 19 Nov 2023 15:12:21 +0100 Subject: [PATCH] add isKeyframe method --- inc/H264_V4l2DeviceSource.h | 1 + inc/H265_V4l2DeviceSource.h | 1 + inc/V4L2DeviceSource.h | 1 + src/H264_V4l2DeviceSource.cpp | 10 ++++++++++ src/H265_V4l2DeviceSource.cpp | 10 ++++++++++ 5 files changed, 23 insertions(+) diff --git a/inc/H264_V4l2DeviceSource.h b/inc/H264_V4l2DeviceSource.h index c62e519..a3020cd 100644 --- a/inc/H264_V4l2DeviceSource.h +++ b/inc/H264_V4l2DeviceSource.h @@ -29,4 +29,5 @@ class H264_V4L2DeviceSource : public H26X_V4L2DeviceSource // overide V4L2DeviceSource virtual std::list< std::pair > splitFrames(unsigned char* frame, unsigned frameSize); virtual std::list< std::string > getInitFrames(); + virtual bool isKeyFrame(const char*, int); }; diff --git a/inc/H265_V4l2DeviceSource.h b/inc/H265_V4l2DeviceSource.h index 7ff5ed7..7436739 100644 --- a/inc/H265_V4l2DeviceSource.h +++ b/inc/H265_V4l2DeviceSource.h @@ -29,6 +29,7 @@ class H265_V4L2DeviceSource : public H26X_V4L2DeviceSource // overide V4L2DeviceSource virtual std::list< std::pair > splitFrames(unsigned char* frame, unsigned frameSize); virtual std::list< std::string > getInitFrames(); + virtual bool isKeyFrame(const char*, int); protected: std::string m_vps; diff --git a/inc/V4L2DeviceSource.h b/inc/V4L2DeviceSource.h index ddc7433..5bf5773 100755 --- a/inc/V4L2DeviceSource.h +++ b/inc/V4L2DeviceSource.h @@ -80,6 +80,7 @@ class V4L2DeviceSource: public FramedSource DeviceInterface* getDevice() { return m_device; } void postFrame(char * frame, int frameSize, const timeval &ref); virtual std::list< std::string > getInitFrames() { return std::list< std::string >(); } + virtual bool isKeyFrame(const char*, int) { return false; } protected: diff --git a/src/H264_V4l2DeviceSource.cpp b/src/H264_V4l2DeviceSource.cpp index 071f5b8..88ab09e 100644 --- a/src/H264_V4l2DeviceSource.cpp +++ b/src/H264_V4l2DeviceSource.cpp @@ -78,3 +78,13 @@ std::list< std::string > H264_V4L2DeviceSource::getInitFrames() { frameList.push_back(this->getFrameWithMarker(m_pps)); return frameList; } + +bool H264_V4L2DeviceSource::isKeyFrame(const char* buffer, int size) { + bool res = false; + if (size > 4) + { + int frameType = buffer[4]&0x1F; + res = (frameType == 5); + } + return res; +} \ No newline at end of file diff --git a/src/H265_V4l2DeviceSource.cpp b/src/H265_V4l2DeviceSource.cpp index 13b4a4f..d77bc84 100644 --- a/src/H265_V4l2DeviceSource.cpp +++ b/src/H265_V4l2DeviceSource.cpp @@ -76,3 +76,13 @@ std::list< std::string > H265_V4L2DeviceSource::getInitFrames() { frameList.push_back(this->getFrameWithMarker(m_pps)); return frameList; } + +bool H265_V4L2DeviceSource::isKeyFrame(const char* buffer, int size) { + bool res = false; + if (size > 4) + { + int frameType = (buffer[4]&0x7E)>>1; + res = (frameType == 19 || frameType == 20); + } + return res; +} \ No newline at end of file