-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video encoder frame #905
Merged
Merged
Video encoder frame #905
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
440d7b1
Added host side EncodedFrame with parsing and output handling
asahtik a63cf88
Bugfixes
asahtik 19e2cbe
Merge branch 'develop' of github.com:luxonis/depthai-core into video_…
asahtik 8fd2365
Moved timestamps to buffer
asahtik 32e3200
Merge develop
asahtik 60c0b29
EncFrm fixes
asahtik fd35a88
Added tests, bugfixes
asahtik acb82a5
clangformat
asahtik f4e89f5
Bump device
asahtik 4a9ee8d
Bump device again
asahtik 1c406a9
Merge resolution
asahtik 16b4d98
Merge resolution
asahtik 4338f13
Added fields to EncodedFrame
asahtik 797638a
Bump shared
asahtik d519eed
Moved frame type extraction into a getter
asahtik 34ffec9
Merge branch 'develop' of github.com:luxonis/depthai-core into video_…
asahtik 79c1d67
Bump shared
asahtik af9de8c
Bump device
asahtik 06672b7
Bump device
asahtik b910590
clangformat
asahtik 437cc34
Merge branch 'develop' of github.com:luxonis/depthai-core into video_…
asahtik 3d85f9f
Applied suggestions
asahtik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and
warning: ‘frameType’ may be used uninitialized [-Wmaybe-uninitialized]