[feat] use encode thread to encode frame

This commit is contained in:
dijunkun
2025-03-25 17:18:52 +08:00
parent 160ee9feef
commit bcf01791f7
42 changed files with 269 additions and 492 deletions

View File

@@ -14,9 +14,9 @@ class DecodedFrame : public VideoFrame {
DecodedFrame(const uint8_t *buffer, size_t size, uint32_t width,
uint32_t height)
: VideoFrame(buffer, size, width, height) {}
DecodedFrame(const uint8_t *buffer, size_t size) : VideoFrame(buffer, size) {}
DecodedFrame(size_t size, uint32_t width, uint32_t height)
: VideoFrame(size, width, height) {}
DecodedFrame(const uint8_t *buffer, size_t size) : VideoFrame(buffer, size) {}
DecodedFrame() = default;
~DecodedFrame() = default;

View File

@@ -14,9 +14,9 @@ class EncodedFrame : public VideoFrame {
EncodedFrame(const uint8_t *buffer, size_t size, uint32_t width,
uint32_t height)
: VideoFrame(buffer, size, width, height) {}
EncodedFrame(const uint8_t *buffer, size_t size) : VideoFrame(buffer, size) {}
EncodedFrame(size_t size, uint32_t width, uint32_t height)
: VideoFrame(size, width, height) {}
EncodedFrame(const uint8_t *buffer, size_t size) : VideoFrame(buffer, size) {}
EncodedFrame() = default;
~EncodedFrame() = default;

0
src/frame/raw_frame.cpp Normal file
View File

32
src/frame/raw_frame.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-03-25
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _RAW_FRAME_H_
#define _RAW_FRAME_H_
#include "video_frame.h"
class RawFrame : public VideoFrame {
public:
RawFrame(const uint8_t *buffer, size_t size, uint32_t width, uint32_t height)
: VideoFrame(buffer, size, width, height) {}
RawFrame(size_t size, uint32_t width, uint32_t height)
: VideoFrame(size, width, height) {}
RawFrame(const uint8_t *buffer, size_t size) : VideoFrame(buffer, size) {}
RawFrame() = default;
~RawFrame() = default;
int64_t CapturedTimestamp() const { return captured_timestamp_us_; }
void SetCapturedTimestamp(int64_t captured_timestamp_us) {
captured_timestamp_us_ = captured_timestamp_us;
}
private:
int64_t captured_timestamp_us_ = 0;
};
#endif

View File

@@ -5,94 +5,40 @@
VideoFrame::VideoFrame() {}
VideoFrame::VideoFrame(size_t size) {
buffer_ = new uint8_t[size];
VideoFrame::VideoFrame(size_t size) : buffer_(size) {
size_ = size;
width_ = 0;
height_ = 0;
}
VideoFrame::VideoFrame(size_t size, uint32_t width, uint32_t height) {
buffer_ = new uint8_t[size];
VideoFrame::VideoFrame(size_t size, uint32_t width, uint32_t height)
: buffer_(size) {
size_ = size;
width_ = width;
height_ = height;
}
VideoFrame::VideoFrame(const uint8_t *buffer, size_t size) {
buffer_ = new uint8_t[size];
memcpy(buffer_, buffer, size);
VideoFrame::VideoFrame(const uint8_t *buffer, size_t size)
: buffer_(buffer, size) {
size_ = size;
width_ = 0;
height_ = 0;
}
VideoFrame::VideoFrame(const uint8_t *buffer, size_t size, uint32_t width,
uint32_t height) {
buffer_ = new uint8_t[size];
memcpy(buffer_, buffer, size);
uint32_t height)
: buffer_(buffer, size) {
size_ = size;
width_ = width;
height_ = height;
}
VideoFrame::VideoFrame(const VideoFrame &video_frame) {
if (video_frame.size_ > 0) {
buffer_ = new uint8_t[video_frame.size_];
memcpy(buffer_, video_frame.buffer_, video_frame.size_);
size_ = video_frame.size_;
width_ = video_frame.width_;
height_ = video_frame.height_;
}
}
VideoFrame::VideoFrame(const VideoFrame &video_frame) = default;
VideoFrame::VideoFrame(VideoFrame &&video_frame)
: buffer_((uint8_t *)std::move(video_frame.buffer_)),
size_(video_frame.size_),
width_(video_frame.width_),
height_(video_frame.height_) {
video_frame.buffer_ = nullptr;
video_frame.size_ = 0;
video_frame.width_ = 0;
video_frame.height_ = 0;
}
VideoFrame::VideoFrame(VideoFrame &&video_frame) = default;
VideoFrame &VideoFrame::operator=(const VideoFrame &video_frame) {
if (&video_frame != this) {
if (buffer_) {
delete buffer_;
buffer_ = nullptr;
}
buffer_ = new uint8_t[video_frame.size_];
memcpy(buffer_, video_frame.buffer_, video_frame.size_);
size_ = video_frame.size_;
width_ = video_frame.width_;
height_ = video_frame.height_;
}
return *this;
}
VideoFrame &VideoFrame::operator=(const VideoFrame &video_frame) = default;
VideoFrame &VideoFrame::operator=(VideoFrame &&video_frame) {
if (&video_frame != this) {
buffer_ = std::move(video_frame.buffer_);
video_frame.buffer_ = nullptr;
size_ = video_frame.size_;
video_frame.size_ = 0;
width_ = video_frame.width_;
video_frame.width_ = 0;
height_ = video_frame.height_;
video_frame.height_ = 0;
}
return *this;
}
VideoFrame &VideoFrame::operator=(VideoFrame &&video_frame) = default;
VideoFrame::~VideoFrame() {
if (buffer_) {
delete buffer_;
buffer_ = nullptr;
}
size_ = 0;
width_ = 0;
height_ = 0;
}
VideoFrame::~VideoFrame() = default;

View File

@@ -10,6 +10,8 @@
#include <cstddef>
#include <cstdint>
#include "copy_on_write_buffer.h"
enum VideoFrameType {
kEmptyFrame = 0,
kVideoFrameKey = 3,
@@ -20,8 +22,8 @@ class VideoFrame {
public:
VideoFrame();
VideoFrame(size_t size);
VideoFrame(size_t size, uint32_t width, uint32_t height);
VideoFrame(const uint8_t *buffer, size_t size);
VideoFrame(size_t size, uint32_t width, uint32_t height);
VideoFrame(const uint8_t *buffer, size_t size, uint32_t width,
uint32_t height);
VideoFrame(const VideoFrame &video_frame);
@@ -32,7 +34,7 @@ class VideoFrame {
~VideoFrame();
public:
const uint8_t *Buffer() const { return buffer_; }
const uint8_t *Buffer() const { return buffer_.data(); }
size_t Size() const { return size_; }
uint32_t Width() const { return width_; }
uint32_t Height() const { return height_; }
@@ -42,7 +44,7 @@ class VideoFrame {
void SetHeight(uint32_t height) { height_ = height; }
private:
uint8_t *buffer_ = nullptr;
CopyOnWriteBuffer buffer_;
size_t size_ = 0;
uint32_t width_ = 0;
uint32_t height_ = 0;