-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #905 from luxonis/video_encoder_frame
Video encoder frame
- Loading branch information
Showing
13 changed files
with
719 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
|
||
#include "depthai/pipeline/datatype/Buffer.hpp" | ||
|
||
// shared | ||
#include "depthai-shared/datatype/RawEncodedFrame.hpp" | ||
|
||
// optional | ||
#ifdef DEPTHAI_HAVE_OPENCV_SUPPORT | ||
#include <opencv2/opencv.hpp> | ||
#endif | ||
|
||
namespace dai { | ||
|
||
class EncodedFrame : public Buffer { | ||
std::shared_ptr<RawBuffer> serialize() const override; | ||
RawEncodedFrame& frame; | ||
|
||
public: | ||
// Raw* mirror | ||
using Profile = RawEncodedFrame::Profile; | ||
using FrameType = RawEncodedFrame::FrameType; | ||
|
||
/** | ||
* Construct EncodedFrame message. | ||
* Timestamp is set to now | ||
*/ | ||
EncodedFrame(); | ||
explicit EncodedFrame(std::shared_ptr<RawEncodedFrame> ptr); | ||
virtual ~EncodedFrame() = default; | ||
|
||
// getters | ||
/** | ||
* Retrieves instance number | ||
*/ | ||
unsigned int getInstanceNum() const; | ||
/** | ||
* Retrieves exposure time | ||
*/ | ||
std::chrono::microseconds getExposureTime() const; | ||
|
||
/** | ||
* Retrieves sensitivity, as an ISO value | ||
*/ | ||
int getSensitivity() const; | ||
|
||
/** | ||
* Retrieves white-balance color temperature of the light source, in kelvins | ||
*/ | ||
int getColorTemperature() const; | ||
|
||
/** | ||
* Retrieves lens position, range 0..255. Returns -1 if not available | ||
*/ | ||
int getLensPosition() const; | ||
/** | ||
* Retrieves the encoding quality | ||
*/ | ||
unsigned int getQuality() const; | ||
|
||
/** | ||
* Retrieves the encoding bitrate | ||
*/ | ||
unsigned int getBitrate() const; | ||
|
||
/** | ||
* Returns true if encoding is lossless (JPEG only) | ||
*/ | ||
bool getLossless() const; | ||
|
||
/** | ||
* Retrieves frame type (H26x only) | ||
*/ | ||
FrameType getFrameType() const; | ||
|
||
/** | ||
* Retrieves the encoding profile (JPEG, AVC or HEVC) | ||
*/ | ||
Profile getProfile() const; | ||
|
||
// setters | ||
/** | ||
* Retrieves image timestamp related to dai::Clock::now() | ||
*/ | ||
EncodedFrame& setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp); | ||
|
||
/** | ||
* Sets image timestamp related to dai::Clock::now() | ||
*/ | ||
EncodedFrame& setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp); | ||
|
||
/** | ||
* Specifies sequence number | ||
* | ||
* @param seq Sequence number | ||
*/ | ||
EncodedFrame& setSequenceNum(int64_t seq); | ||
|
||
/** | ||
* Instance number relates to the origin of the frame (which camera) | ||
* | ||
* @param instance Instance number | ||
*/ | ||
EncodedFrame& setInstanceNum(unsigned int instance); | ||
|
||
/** | ||
* Specifies the encoding quality | ||
* | ||
* @param quality Encoding quality | ||
*/ | ||
EncodedFrame& setQuality(unsigned int quality); | ||
|
||
/** | ||
* Specifies the encoding quality | ||
* | ||
* @param quality Encoding quality | ||
*/ | ||
EncodedFrame& setBitrate(unsigned int bitrate); | ||
|
||
/** | ||
* Specifies if encoding is lossless (JPEG only) | ||
* | ||
* @param lossless True if lossless | ||
*/ | ||
EncodedFrame& setLossless(bool lossless); | ||
|
||
/** | ||
* Specifies the frame type (H26x only) | ||
* | ||
* @param type Type of h26x frame (I, P, B) | ||
*/ | ||
EncodedFrame& setFrameType(FrameType type); | ||
|
||
/** | ||
* Specifies the encoding profile | ||
* | ||
* @param profile Encoding profile | ||
*/ | ||
EncodedFrame& setProfile(Profile profile); | ||
}; | ||
|
||
} // namespace dai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule depthai-shared
updated
3 files
+1 −0 | include/depthai-shared/datatype/DatatypeEnum.hpp | |
+55 −0 | include/depthai-shared/datatype/RawEncodedFrame.hpp | |
+2 −0 | src/datatype/DatatypeEnum.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "depthai/pipeline/datatype/EncodedFrame.hpp" | ||
|
||
#include "utility/H26xParsers.hpp" | ||
|
||
namespace dai { | ||
|
||
std::shared_ptr<RawBuffer> EncodedFrame::serialize() const { | ||
return raw; | ||
} | ||
|
||
EncodedFrame::EncodedFrame() : Buffer(std::make_shared<RawEncodedFrame>()), frame(*dynamic_cast<RawEncodedFrame*>(raw.get())) { | ||
// set timestamp to now | ||
setTimestamp(std::chrono::steady_clock::now()); | ||
} | ||
EncodedFrame::EncodedFrame(std::shared_ptr<RawEncodedFrame> ptr) : Buffer(std::move(ptr)), frame(*dynamic_cast<RawEncodedFrame*>(raw.get())) {} | ||
|
||
// getters | ||
unsigned int EncodedFrame::getInstanceNum() const { | ||
return frame.instanceNum; | ||
} | ||
std::chrono::microseconds EncodedFrame::getExposureTime() const { | ||
return std::chrono::microseconds(frame.cam.exposureTimeUs); | ||
} | ||
int EncodedFrame::getSensitivity() const { | ||
return frame.cam.sensitivityIso; | ||
} | ||
int EncodedFrame::getColorTemperature() const { | ||
return frame.cam.wbColorTemp; | ||
} | ||
int EncodedFrame::getLensPosition() const { | ||
return frame.cam.lensPosition; | ||
} | ||
unsigned int EncodedFrame::getQuality() const { | ||
return frame.quality; | ||
} | ||
unsigned int EncodedFrame::getBitrate() const { | ||
return frame.bitrate; | ||
} | ||
bool EncodedFrame::getLossless() const { | ||
return frame.lossless; | ||
} | ||
EncodedFrame::FrameType EncodedFrame::getFrameType() const { | ||
if(frame.type == FrameType::Unknown) { | ||
utility::SliceType frameType; | ||
switch(frame.profile) { | ||
case RawEncodedFrame::Profile::JPEG: | ||
frameType = utility::SliceType::I; | ||
break; | ||
case RawEncodedFrame::Profile::AVC: | ||
frameType = utility::getTypesH264(frame.data, true)[0]; | ||
break; | ||
case RawEncodedFrame::Profile::HEVC: | ||
frameType = utility::getTypesH265(frame.data, true)[0]; | ||
break; | ||
} | ||
switch(frameType) { | ||
case utility::SliceType::P: | ||
frame.type = FrameType::P; | ||
break; | ||
case utility::SliceType::B: | ||
frame.type = FrameType::B; | ||
break; | ||
case utility::SliceType::I: | ||
frame.type = FrameType::I; | ||
break; | ||
case utility::SliceType::SP: | ||
frame.type = FrameType::P; | ||
break; | ||
case utility::SliceType::SI: | ||
frame.type = FrameType::I; | ||
break; | ||
case utility::SliceType::Unknown: | ||
frame.type = FrameType::Unknown; | ||
break; | ||
} | ||
} | ||
return frame.type; | ||
} | ||
EncodedFrame::Profile EncodedFrame::getProfile() const { | ||
return frame.profile; | ||
} | ||
|
||
// setters | ||
EncodedFrame& EncodedFrame::setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp) { | ||
// Set timestamp from timepoint | ||
return static_cast<EncodedFrame&>(Buffer::setTimestamp(tp)); | ||
} | ||
EncodedFrame& EncodedFrame::setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp) { | ||
// Set timestamp from timepoint | ||
return static_cast<EncodedFrame&>(Buffer::setTimestampDevice(tp)); | ||
} | ||
EncodedFrame& EncodedFrame::setSequenceNum(int64_t sequenceNum) { | ||
return static_cast<EncodedFrame&>(Buffer::setSequenceNum(sequenceNum)); | ||
} | ||
EncodedFrame& EncodedFrame::setInstanceNum(unsigned int instanceNum) { | ||
frame.instanceNum = instanceNum; | ||
return *this; | ||
} | ||
EncodedFrame& EncodedFrame::setQuality(unsigned int quality) { | ||
frame.quality = quality; | ||
return *this; | ||
} | ||
EncodedFrame& EncodedFrame::setBitrate(unsigned int bitrate) { | ||
frame.bitrate = bitrate; | ||
return *this; | ||
} | ||
|
||
EncodedFrame& EncodedFrame::setLossless(bool lossless) { | ||
frame.lossless = lossless; | ||
return *this; | ||
} | ||
EncodedFrame& EncodedFrame::setFrameType(FrameType frameType) { | ||
frame.type = frameType; | ||
return *this; | ||
} | ||
EncodedFrame& EncodedFrame::setProfile(Profile profile) { | ||
frame.profile = profile; | ||
return *this; | ||
} | ||
|
||
} // namespace dai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.