Skip to content
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 22 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ add_library(${TARGET_CORE_NAME}
src/pipeline/node/UVC.cpp
src/pipeline/datatype/Buffer.cpp
src/pipeline/datatype/ImgFrame.cpp
src/pipeline/datatype/EncodedFrame.cpp
src/pipeline/datatype/ImageManipConfig.cpp
src/pipeline/datatype/CameraControl.cpp
src/pipeline/datatype/NNData.cpp
Expand Down
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "dc4563dc83f22b31325b5cb06b20188eb10601b0")
set(DEPTHAI_DEVICE_SIDE_COMMIT "bef7c80f56dc2401254908c44902565c6d37f603")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
114 changes: 114 additions & 0 deletions include/depthai/pipeline/datatype/EncodedFrame.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#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 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);

/**
* 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
5 changes: 5 additions & 0 deletions include/depthai/pipeline/node/VideoEncoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class VideoEncoder : public NodeCRTP<Node, VideoEncoder, VideoEncoderProperties>
*/
Output bitstream{*this, "bitstream", Output::Type::MSender, {{DatatypeEnum::ImgFrame, false}}};

/**
* Outputs EncodedFrame message that carries encoded (MJPEG, H264 or H265) frame data.
*/
Output out{*this, "out", Output::Type::MSender, {{DatatypeEnum::EncodedFrame, false}}};

// Sets default options for a specified size and profile
/**
* Sets a default preset based on specified frame rate and profile
Expand Down
2 changes: 1 addition & 1 deletion src/openvino/BlobReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "BlobFormat.hpp"

// TODO(themarpe)
//#include <vpu/model/data.hpp>
// #include <vpu/model/data.hpp>

namespace dai {

Expand Down
68 changes: 68 additions & 0 deletions src/pipeline/datatype/EncodedFrame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "depthai/pipeline/datatype/EncodedFrame.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

// getters
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 {
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::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
10 changes: 10 additions & 0 deletions src/pipeline/datatype/StreamMessageParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "depthai/pipeline/datatype/Buffer.hpp"
#include "depthai/pipeline/datatype/CameraControl.hpp"
#include "depthai/pipeline/datatype/EdgeDetectorConfig.hpp"
#include "depthai/pipeline/datatype/EncodedFrame.hpp"
#include "depthai/pipeline/datatype/FeatureTrackerConfig.hpp"
#include "depthai/pipeline/datatype/IMUData.hpp"
#include "depthai/pipeline/datatype/ImageManipConfig.hpp"
Expand All @@ -37,6 +38,7 @@
#include "depthai-shared/datatype/RawBuffer.hpp"
#include "depthai-shared/datatype/RawCameraControl.hpp"
#include "depthai-shared/datatype/RawEdgeDetectorConfig.hpp"
#include "depthai-shared/datatype/RawEncodedFrame.hpp"
#include "depthai-shared/datatype/RawFeatureTrackerConfig.hpp"
#include "depthai-shared/datatype/RawIMUData.hpp"
#include "depthai-shared/datatype/RawImageManipConfig.hpp"
Expand Down Expand Up @@ -122,6 +124,10 @@ std::shared_ptr<RawBuffer> StreamMessageParser::parseMessage(streamPacketDesc_t*
return parseDatatype<RawImgFrame>(metadataStart, serializedObjectSize, data);
break;

case DatatypeEnum::EncodedFrame:
return parseDatatype<RawEncodedFrame>(metadataStart, serializedObjectSize, data);
break;

case DatatypeEnum::NNData:
return parseDatatype<RawNNData>(metadataStart, serializedObjectSize, data);
break;
Expand Down Expand Up @@ -213,6 +219,10 @@ std::shared_ptr<ADatatype> StreamMessageParser::parseMessageToADatatype(streamPa
return std::make_shared<ImgFrame>(parseDatatype<RawImgFrame>(metadataStart, serializedObjectSize, data));
break;

case DatatypeEnum::EncodedFrame:
return std::make_shared<EncodedFrame>(parseDatatype<RawEncodedFrame>(metadataStart, serializedObjectSize, data));
break;

case DatatypeEnum::NNData:
return std::make_shared<NNData>(parseDatatype<RawNNData>(metadataStart, serializedObjectSize, data));
break;
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline/node/VideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VideoEncoder::VideoEncoder(const std::shared_ptr<PipelineImpl>& par, int64_t nod
VideoEncoder::VideoEncoder(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId, std::unique_ptr<Properties> props)
: NodeCRTP<Node, VideoEncoder, VideoEncoderProperties>(par, nodeId, std::move(props)) {
setInputRefs({&input});
setOutputRefs({&bitstream});
setOutputRefs({&bitstream, &out});
}
// node properties
void VideoEncoder::setNumFramesPool(int frames) {
Expand Down
4 changes: 2 additions & 2 deletions src/utility/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace dai {
std::wstring Path::convert_utf8_to_wide(const std::string& utf8string) {
//#pragma warning(suppress : 4996)
// #pragma warning(suppress : 4996)
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.from_bytes(utf8string);
}

std::string Path::u8string() const {
//#pragma warning(suppress : 4996)
// #pragma warning(suppress : 4996)
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes(_nativePath);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ dai_add_test(device_usbspeed_test src/device_usbspeed_test.cpp CONFORMING)
dai_add_test(device_usbspeed_test_17 src/device_usbspeed_test.cpp CONFORMING CXX_STANDARD 17)
dai_add_test(device_usbspeed_test_20 src/device_usbspeed_test.cpp CONFORMING CXX_STANDARD 20)

dai_add_test(encoded_frame_test src/encoded_frame_test.cpp CXX_STANDARD 17)

# Unlimited io connections test
dai_add_test(unlimited_io_connection_test src/unlimited_io_connection_test.cpp)

Expand Down
Loading