Skip to content

Commit

Permalink
add isKeyframe method
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Nov 19, 2023
1 parent 0b4247c commit bfdd34d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions inc/H264_V4l2DeviceSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ class H264_V4L2DeviceSource : public H26X_V4L2DeviceSource
// overide V4L2DeviceSource
virtual std::list< std::pair<unsigned char*,size_t> > splitFrames(unsigned char* frame, unsigned frameSize);
virtual std::list< std::string > getInitFrames();
virtual bool isKeyFrame(const char*, int);
};
1 change: 1 addition & 0 deletions inc/H265_V4l2DeviceSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class H265_V4L2DeviceSource : public H26X_V4L2DeviceSource
// overide V4L2DeviceSource
virtual std::list< std::pair<unsigned char*,size_t> > splitFrames(unsigned char* frame, unsigned frameSize);
virtual std::list< std::string > getInitFrames();
virtual bool isKeyFrame(const char*, int);

protected:
std::string m_vps;
Expand Down
1 change: 1 addition & 0 deletions inc/V4L2DeviceSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/H264_V4l2DeviceSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions src/H265_V4l2DeviceSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit bfdd34d

Please sign in to comment.