优化解耦
This commit is contained in:
parent
3f0bbce41e
commit
54241237ec
@ -45,6 +45,8 @@ public:
|
||||
fps_ = config.ValueOr<int>("fps", 0);
|
||||
width_ = config.ValueOr<int>("width", 1920);
|
||||
height_ = config.ValueOr<int>("height", 1080);
|
||||
platform_ = config.ValueOr<std::string>("platform", "");
|
||||
hw_platform_ = config.ValueOr<std::string>("hw_platform", "");
|
||||
use_ffmpeg_ = config.ValueOr<bool>("use_ffmpeg", true);
|
||||
use_mpp_ = config.ValueOr<bool>("use_mpp", true);
|
||||
fallback_to_stub_on_fail_ = config.ValueOr<bool>("fallback_to_stub_on_fail", false);
|
||||
@ -123,7 +125,9 @@ private:
|
||||
static SimpleJson BuildDecoderConfig(const std::string& backend,
|
||||
AVCodecID codec_id,
|
||||
const uint8_t* extradata,
|
||||
size_t extradata_size) {
|
||||
size_t extradata_size,
|
||||
const std::string& platform,
|
||||
const std::string& hw_platform) {
|
||||
SimpleJson::Object obj;
|
||||
obj["backend"] = SimpleJson(backend);
|
||||
obj["codec_id"] = SimpleJson(static_cast<double>(codec_id));
|
||||
@ -132,6 +136,12 @@ private:
|
||||
} else if (codec_id == AV_CODEC_ID_HEVC) {
|
||||
obj["codec"] = SimpleJson(std::string("h265"));
|
||||
}
|
||||
if (!platform.empty()) {
|
||||
obj["platform"] = SimpleJson(platform);
|
||||
}
|
||||
if (!hw_platform.empty()) {
|
||||
obj["hw_platform"] = SimpleJson(hw_platform);
|
||||
}
|
||||
if (extradata && extradata_size > 0) {
|
||||
SimpleJson::Array arr;
|
||||
arr.reserve(extradata_size);
|
||||
@ -309,7 +319,8 @@ private:
|
||||
const auto* par = fmt_ctx->streams[video_stream]->codecpar;
|
||||
SimpleJson dec_cfg = BuildDecoderConfig("ffmpeg", par->codec_id,
|
||||
par->extradata,
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)));
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)),
|
||||
platform_, hw_platform_);
|
||||
auto decoder = HwFactory::CreateDecoder(dec_cfg);
|
||||
if (!decoder || decoder->Open(dec_cfg).Failed()) {
|
||||
LogError("[input_file] ffmpeg decoder open failed");
|
||||
@ -401,7 +412,8 @@ private:
|
||||
const auto* par = fmt_ctx->streams[video_stream]->codecpar;
|
||||
SimpleJson dec_cfg = BuildDecoderConfig("mpp", codec_id,
|
||||
par->extradata,
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)));
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)),
|
||||
platform_, hw_platform_);
|
||||
auto decoder = HwFactory::CreateDecoder(dec_cfg);
|
||||
if (!decoder || decoder->Open(dec_cfg).Failed()) {
|
||||
LogError("[input_file] mpp decoder open failed");
|
||||
@ -465,6 +477,9 @@ private:
|
||||
bool fallback_to_stub_on_fail_ = false;
|
||||
std::vector<int> cpu_affinity_;
|
||||
|
||||
std::string platform_;
|
||||
std::string hw_platform_;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
std::vector<std::shared_ptr<SpscQueue<FramePtr>>> out_queues_;
|
||||
std::thread worker_;
|
||||
|
||||
@ -49,6 +49,8 @@ public:
|
||||
fps_ = config.ValueOr<int>("fps", 25);
|
||||
width_ = config.ValueOr<int>("width", 1920);
|
||||
height_ = config.ValueOr<int>("height", 1080);
|
||||
platform_ = config.ValueOr<std::string>("platform", "");
|
||||
hw_platform_ = config.ValueOr<std::string>("hw_platform", "");
|
||||
use_ffmpeg_ = config.ValueOr<bool>("use_ffmpeg", false);
|
||||
use_mpp_ = config.ValueOr<bool>("use_mpp", true);
|
||||
ffmpeg_force_tcp_ = config.ValueOr<bool>("force_tcp", true);
|
||||
@ -122,7 +124,9 @@ private:
|
||||
static SimpleJson BuildDecoderConfig(const std::string& backend,
|
||||
AVCodecID codec_id,
|
||||
const uint8_t* extradata,
|
||||
size_t extradata_size) {
|
||||
size_t extradata_size,
|
||||
const std::string& platform,
|
||||
const std::string& hw_platform) {
|
||||
SimpleJson::Object obj;
|
||||
obj["backend"] = SimpleJson(backend);
|
||||
obj["codec_id"] = SimpleJson(static_cast<double>(codec_id));
|
||||
@ -131,6 +135,12 @@ private:
|
||||
} else if (codec_id == AV_CODEC_ID_HEVC) {
|
||||
obj["codec"] = SimpleJson(std::string("h265"));
|
||||
}
|
||||
if (!platform.empty()) {
|
||||
obj["platform"] = SimpleJson(platform);
|
||||
}
|
||||
if (!hw_platform.empty()) {
|
||||
obj["hw_platform"] = SimpleJson(hw_platform);
|
||||
}
|
||||
if (extradata && extradata_size > 0) {
|
||||
SimpleJson::Array arr;
|
||||
arr.reserve(extradata_size);
|
||||
@ -322,7 +332,8 @@ private:
|
||||
const auto* par = fmt_ctx->streams[video_stream]->codecpar;
|
||||
SimpleJson dec_cfg = BuildDecoderConfig("ffmpeg", par->codec_id,
|
||||
par->extradata,
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)));
|
||||
static_cast<size_t>(std::max(0, par->extradata_size)),
|
||||
platform_, hw_platform_);
|
||||
auto decoder = HwFactory::CreateDecoder(dec_cfg);
|
||||
if (!decoder || decoder->Open(dec_cfg).Failed()) {
|
||||
LogError("[input_rtsp] ffmpeg decoder open failed");
|
||||
@ -547,7 +558,8 @@ private:
|
||||
extra_size = static_cast<size_t>(bsf_ctx->par_out->extradata_size);
|
||||
}
|
||||
|
||||
SimpleJson dec_cfg = BuildDecoderConfig("mpp", codec_id, extra, extra_size);
|
||||
SimpleJson dec_cfg = BuildDecoderConfig("mpp", codec_id, extra, extra_size,
|
||||
platform_, hw_platform_);
|
||||
auto decoder = HwFactory::CreateDecoder(dec_cfg);
|
||||
if (!decoder || decoder->Open(dec_cfg).Failed()) {
|
||||
LogError("[input_rtsp] mpp decoder open failed");
|
||||
@ -696,6 +708,9 @@ private:
|
||||
bool use_mpp_ = true;
|
||||
bool ffmpeg_force_tcp_ = true;
|
||||
|
||||
std::string platform_;
|
||||
std::string hw_platform_;
|
||||
|
||||
int reconnect_sec_ = 5;
|
||||
int reconnect_backoff_max_sec_ = 30;
|
||||
bool fallback_to_stub_on_fail_ = false;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#include <algorithm>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
@ -642,6 +641,8 @@ public:
|
||||
fps_ = config.ValueOr<int>("fps", 25);
|
||||
gop_ = config.ValueOr<int>("gop", 50);
|
||||
bitrate_kbps_ = config.ValueOr<int>("bitrate_kbps", 4000);
|
||||
platform_ = config.ValueOr<std::string>("platform", "");
|
||||
hw_platform_ = config.ValueOr<std::string>("hw_platform", "");
|
||||
use_mpp_ = config.ValueOr<bool>("use_mpp", true);
|
||||
use_ffmpeg_mux_ = config.ValueOr<bool>("use_ffmpeg_mux", true);
|
||||
attach_encoded_meta_ = config.ValueOr<bool>("attach_encoded_meta", !output_queues_.empty());
|
||||
@ -1239,10 +1240,6 @@ private:
|
||||
|
||||
#if defined(RK3588_ENABLE_MPP)
|
||||
void ProcessMpp(FramePtr frame) {
|
||||
if (!encoder_) {
|
||||
encoder_ = HwFactory::CreateEncoder(SimpleJson(SimpleJson::Object{}));
|
||||
}
|
||||
|
||||
if (!encoder_ready_) {
|
||||
SimpleJson::Object enc_obj;
|
||||
enc_obj["backend"] = SimpleJson(std::string("mpp"));
|
||||
@ -1253,8 +1250,17 @@ private:
|
||||
enc_obj["width"] = SimpleJson(static_cast<double>(frame->width));
|
||||
enc_obj["height"] = SimpleJson(static_cast<double>(frame->height));
|
||||
enc_obj["pixel_format"] = SimpleJson(PixelFormatToString(frame->format));
|
||||
if (!platform_.empty()) {
|
||||
enc_obj["platform"] = SimpleJson(platform_);
|
||||
}
|
||||
if (!hw_platform_.empty()) {
|
||||
enc_obj["hw_platform"] = SimpleJson(hw_platform_);
|
||||
}
|
||||
SimpleJson enc_cfg(std::move(enc_obj));
|
||||
|
||||
if (!encoder_) {
|
||||
encoder_ = HwFactory::CreateEncoder(enc_cfg);
|
||||
}
|
||||
if (!encoder_ || encoder_->Open(enc_cfg).Failed()) {
|
||||
LogWarn("[publish] encoder init failed, fallback to stub");
|
||||
use_mpp_ = false;
|
||||
@ -1352,6 +1358,8 @@ private:
|
||||
int fps_ = 25;
|
||||
int gop_ = 50;
|
||||
int bitrate_kbps_ = 4000;
|
||||
std::string platform_;
|
||||
std::string hw_platform_;
|
||||
bool use_mpp_ = false;
|
||||
bool use_ffmpeg_mux_ = false;
|
||||
std::vector<OutputConfig> outputs_;
|
||||
|
||||
@ -399,6 +399,8 @@ public:
|
||||
fps_ = config.ValueOr<int>("fps", 25);
|
||||
bitrate_kbps_ = config.ValueOr<int>("bitrate_kbps", 2000);
|
||||
reuse_encoded_meta_ = config.ValueOr<bool>("reuse_encoded_meta", true);
|
||||
platform_ = config.ValueOr<std::string>("platform", "");
|
||||
hw_platform_ = config.ValueOr<std::string>("hw_platform", "");
|
||||
|
||||
input_queue_ = ctx.input_queue;
|
||||
if (!input_queue_) {
|
||||
@ -595,10 +597,7 @@ private:
|
||||
stream_->codecpar->format = AV_PIX_FMT_YUV420P;
|
||||
|
||||
if (!using_encoded_meta_) {
|
||||
if (!encoder_) {
|
||||
encoder_ = HwFactory::CreateEncoder(SimpleJson(SimpleJson::Object{}));
|
||||
}
|
||||
if (encoder_ && !encoder_ready_) {
|
||||
if (!encoder_ready_) {
|
||||
SimpleJson::Object enc_obj;
|
||||
enc_obj["backend"] = SimpleJson(std::string("mpp"));
|
||||
enc_obj["codec"] = SimpleJson(codec_);
|
||||
@ -608,9 +607,18 @@ private:
|
||||
enc_obj["width"] = SimpleJson(static_cast<double>(frame->width));
|
||||
enc_obj["height"] = SimpleJson(static_cast<double>(frame->height));
|
||||
enc_obj["pixel_format"] = SimpleJson(PixelFormatToString(frame->format));
|
||||
if (!platform_.empty()) {
|
||||
enc_obj["platform"] = SimpleJson(platform_);
|
||||
}
|
||||
if (!hw_platform_.empty()) {
|
||||
enc_obj["hw_platform"] = SimpleJson(hw_platform_);
|
||||
}
|
||||
SimpleJson enc_cfg(std::move(enc_obj));
|
||||
|
||||
if (encoder_->Open(enc_cfg).Failed()) {
|
||||
if (!encoder_) {
|
||||
encoder_ = HwFactory::CreateEncoder(enc_cfg);
|
||||
}
|
||||
if (!encoder_ || encoder_->Open(enc_cfg).Failed()) {
|
||||
encoder_.reset();
|
||||
} else {
|
||||
encoder_header_ = encoder_->ExtraData();
|
||||
@ -780,6 +788,8 @@ private:
|
||||
int fps_ = 25;
|
||||
int bitrate_kbps_ = 2000;
|
||||
bool reuse_encoded_meta_ = true;
|
||||
std::string platform_;
|
||||
std::string hw_platform_;
|
||||
|
||||
std::mutex mu_;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "hw/rk3588_defaults.h"
|
||||
#include "hw/rk3588_defaults.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user