mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-07-29 17:31:45 +08:00
del: 移除安卓支持
This commit is contained in:
@@ -24,7 +24,7 @@ bool is_software_h264(const std::string &name) {
|
||||
// Exclude all hardware encoders
|
||||
static const char* hw_suffixes[] = {
|
||||
"nvenc", "amf", "qsv", "vaapi", "rkmpp",
|
||||
"v4l2m2m", "videotoolbox", "mediacodec", "_mf"
|
||||
"v4l2m2m", "videotoolbox", "_mf"
|
||||
};
|
||||
for (const auto& suffix : hw_suffixes) {
|
||||
if (name.find(suffix) != std::string::npos) return false;
|
||||
@@ -37,7 +37,7 @@ bool is_software_hevc(const std::string &name) {
|
||||
if (name != "hevc" && name != "libx265") return false;
|
||||
static const char* hw_suffixes[] = {
|
||||
"nvenc", "amf", "qsv", "vaapi", "rkmpp",
|
||||
"v4l2m2m", "videotoolbox", "mediacodec", "_mf"
|
||||
"v4l2m2m", "videotoolbox", "_mf"
|
||||
};
|
||||
for (const auto& suffix : hw_suffixes) {
|
||||
if (name.find(suffix) != std::string::npos) return false;
|
||||
@@ -100,13 +100,8 @@ void set_av_codec_ctx(AVCodecContext *c, const std::string &name, int kbs,
|
||||
c->color_primaries = AVCOL_PRI_SMPTE170M;
|
||||
c->color_trc = AVCOL_TRC_SMPTE170M;
|
||||
|
||||
// WebRTC SDP advertises constrained baseline. Keep most hardware and software
|
||||
// encoders on the same browser-friendly H264 profile. Android MediaCodec is
|
||||
// deliberately excluded because older vendor OMX encoders can reject explicit
|
||||
// profile/level combinations during configure().
|
||||
if (name.find("mediacodec") != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
// WebRTC SDP advertises constrained baseline. Keep hardware and software
|
||||
// encoders on the same browser-friendly H264 profile.
|
||||
if (name.find("h264") != std::string::npos) {
|
||||
c->profile = AV_PROFILE_H264_CONSTRAINED_BASELINE;
|
||||
} else if (name.find("hevc") != std::string::npos) {
|
||||
@@ -310,9 +305,6 @@ bool set_quality(void *priv_data, const std::string &name, int quality) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Do not force MediaCodec level here. Some Android TV vendor encoders,
|
||||
// including older Amlogic OMX implementations, reject explicit level values
|
||||
// even when they support the requested resolution and bitrate.
|
||||
// libx264 software encoder presets
|
||||
if (is_software_h264(name)) {
|
||||
const char* preset = nullptr;
|
||||
@@ -367,7 +359,7 @@ struct CodecOptions {
|
||||
};
|
||||
|
||||
bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
|
||||
int q) {
|
||||
int /*q*/) {
|
||||
if (name.find("qsv") != std::string::npos) {
|
||||
// https://github.com/LizardByte/Sunshine/blob/3e47cd3cc8fd37a7a88be82444ff4f3c0022856b/src/video.cpp#L1635
|
||||
c->strict_std_compliance = FF_COMPLIANCE_UNOFFICIAL;
|
||||
@@ -375,9 +367,6 @@ bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
|
||||
std::vector<CodecOptions> codecs = {
|
||||
{"nvenc", "rc", {{RC_CBR, "cbr"}, {RC_VBR, "vbr"}}},
|
||||
{"amf", "rc", {{RC_CBR, "cbr"}, {RC_VBR, "vbr_latency"}}},
|
||||
{"mediacodec",
|
||||
"bitrate_mode",
|
||||
{{RC_CBR, "cbr"}, {RC_VBR, "vbr"}, {RC_CQ, "cq"}}},
|
||||
// {"videotoolbox", "constant_bit_rate", {{RC_CBR, "1"}}},
|
||||
};
|
||||
|
||||
@@ -392,13 +381,6 @@ bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
|
||||
it->second + " failed, ret = " + av_err2str(ret));
|
||||
return false;
|
||||
}
|
||||
if (name.find("mediacodec") != std::string::npos) {
|
||||
if (rc == RC_CQ) {
|
||||
if (q >= 0 && q <= 51) {
|
||||
c->global_quality = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -448,13 +430,6 @@ bool set_others(void *priv_data, const std::string &name) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (name.find("mediacodec") != std::string::npos) {
|
||||
if ((ret = av_opt_set_int(priv_data, "ndk_codec", 1, 0)) < 0) {
|
||||
LOG_ERROR(std::string("mediacodec set ndk_codec failed, ret = ") +
|
||||
av_err2str(ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// NOTE: Removed idr_interval = INT_MAX for VAAPI.
|
||||
// This was disabling automatic keyframe generation.
|
||||
// The encoder should respect c->gop_size for keyframe interval.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Minimal FFmpeg RAM MJPEG decoder (RKMPP only) -> NV12 in CPU memory.
|
||||
// FFmpeg RAM decoder with optional RKMPP hardware-frame support.
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
@@ -54,9 +54,11 @@ public:
|
||||
thread_count_ = thread_count > 0 ? thread_count : 1;
|
||||
callback_ = callback;
|
||||
|
||||
#ifdef ONE_KVM_FFMPEG_RKMPP
|
||||
if (name_.find("rkmpp") != std::string::npos) {
|
||||
hw_device_type_ = AV_HWDEVICE_TYPE_RKMPP;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
~FFmpegRamDecoder() {}
|
||||
@@ -137,13 +139,6 @@ public:
|
||||
av_buffer_unref(&frames_ref);
|
||||
}
|
||||
|
||||
if (name_.find("mediacodec") != std::string::npos && c_->priv_data) {
|
||||
if ((ret = av_opt_set_int(c_->priv_data, "ndk_codec", 1, 0)) < 0) {
|
||||
LOG_WARN(std::string("mediacodec decoder ndk_codec option failed, ret = ") +
|
||||
av_err2str(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = avcodec_open2(c_, codec, NULL)) < 0) {
|
||||
set_last_error(std::string("avcodec_open2 failed, ret = ") + av_err2str(ret));
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,7 @@ extern "C" {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -21,6 +22,13 @@ extern "C" {
|
||||
#include "win.h"
|
||||
#endif
|
||||
|
||||
static thread_local std::string g_encoder_last_error;
|
||||
|
||||
static void set_encoder_last_error(const std::string &message) {
|
||||
g_encoder_last_error = message;
|
||||
LOG_ERROR(message);
|
||||
}
|
||||
|
||||
static int calculate_offset_length(int pix_fmt, int height, const int *linesize,
|
||||
int *offset, int *length) {
|
||||
switch (pix_fmt) {
|
||||
@@ -122,7 +130,6 @@ public:
|
||||
AVFrame *frame_ = NULL;
|
||||
AVPacket *pkt_ = NULL;
|
||||
std::string name_;
|
||||
std::string mc_name_; // for mediacodec
|
||||
|
||||
int width_ = 0;
|
||||
int height_ = 0;
|
||||
@@ -145,14 +152,12 @@ public:
|
||||
AVPixelFormat hw_pixfmt_ = AV_PIX_FMT_NONE;
|
||||
AVBufferRef *hw_device_ctx_ = NULL;
|
||||
AVFrame *hw_frame_ = NULL;
|
||||
AVFrame *borrowed_frame_ = NULL;
|
||||
|
||||
FFmpegRamEncoder(const char *name, const char *mc_name, int width, int height,
|
||||
FFmpegRamEncoder(const char *name, int width, int height,
|
||||
int pixfmt, int align, int fps, int gop, int rc, int quality,
|
||||
int kbs, int q, int thread_count, int gpu,
|
||||
RamEncodeCallback callback) {
|
||||
name_ = name;
|
||||
mc_name_ = mc_name ? mc_name : "";
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
pixfmt_ = (AVPixelFormat)pixfmt;
|
||||
@@ -184,12 +189,13 @@ public:
|
||||
}
|
||||
|
||||
bool init(int *linesize, int *offset, int *length) {
|
||||
g_encoder_last_error.clear();
|
||||
const AVCodec *codec = NULL;
|
||||
|
||||
int ret;
|
||||
|
||||
if (!(codec = avcodec_find_encoder_by_name(name_.c_str()))) {
|
||||
LOG_ERROR(std::string("Codec ") + name_ + " not found");
|
||||
set_encoder_last_error(std::string("Codec ") + name_ + " not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -252,12 +258,6 @@ public:
|
||||
LOG_ERROR(std::string("Could not allocate video packet"));
|
||||
return false;
|
||||
}
|
||||
borrowed_frame_ = av_frame_alloc();
|
||||
if (!borrowed_frame_) {
|
||||
LOG_ERROR(std::string("Could not allocate borrowed video frame"));
|
||||
return false;
|
||||
}
|
||||
|
||||
/* resolution must be a multiple of two */
|
||||
c_->width = width_;
|
||||
c_->height = height_;
|
||||
@@ -277,19 +277,9 @@ public:
|
||||
util_encode::set_gpu(c_->priv_data, name_, gpu_);
|
||||
util_encode::force_hw(c_->priv_data, name_);
|
||||
util_encode::set_others(c_->priv_data, name_);
|
||||
if (name_.find("mediacodec") != std::string::npos) {
|
||||
if (mc_name_.length() > 0) {
|
||||
LOG_INFO(std::string("mediacodec codec_name: ") + mc_name_);
|
||||
if ((ret = av_opt_set(c_->priv_data, "codec_name", mc_name_.c_str(),
|
||||
0)) < 0) {
|
||||
LOG_ERROR(std::string("mediacodec codec_name failed, ret = ") + av_err2str(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = avcodec_open2(c_, codec, NULL)) < 0) {
|
||||
LOG_ERROR(std::string("avcodec_open2 failed, ret = ") + av_err2str(ret) +
|
||||
", name: " + name_);
|
||||
set_encoder_last_error(std::string("avcodec_open2 failed, ret = ") +
|
||||
av_err2str(ret) + ", name: " + name_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -307,14 +297,6 @@ public:
|
||||
int encode(const uint8_t *data, int length, const void *obj, uint64_t ms) {
|
||||
int ret;
|
||||
|
||||
if (can_borrow_input(length)) {
|
||||
AVFrame *borrowed = wrap_borrowed_frame(data, length);
|
||||
if (!borrowed) {
|
||||
return -1;
|
||||
}
|
||||
return do_encode(borrowed, obj, ms);
|
||||
}
|
||||
|
||||
if ((ret = av_frame_make_writable(frame_)) != 0) {
|
||||
LOG_ERROR(std::string("av_frame_make_writable failed, ret = ") + av_err2str(ret));
|
||||
return ret;
|
||||
@@ -350,8 +332,6 @@ public:
|
||||
av_frame_free(&frame_);
|
||||
if (hw_frame_)
|
||||
av_frame_free(&hw_frame_);
|
||||
if (borrowed_frame_)
|
||||
av_frame_free(&borrowed_frame_);
|
||||
if (hw_device_ctx_)
|
||||
av_buffer_unref(&hw_device_ctx_);
|
||||
if (c_)
|
||||
@@ -610,65 +590,6 @@ private:
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool can_borrow_input(int data_length) const {
|
||||
if (hw_device_type_ != AV_HWDEVICE_TYPE_NONE) {
|
||||
return false;
|
||||
}
|
||||
if (name_.find("mediacodec") == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
switch (pixfmt_) {
|
||||
case AV_PIX_FMT_NV12:
|
||||
case AV_PIX_FMT_NV21:
|
||||
return data_length >= width_ * height_ * 3 / 2;
|
||||
case AV_PIX_FMT_YUV420P:
|
||||
return data_length >= width_ * height_ * 3 / 2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AVFrame *wrap_borrowed_frame(const uint8_t *data, int data_length) {
|
||||
if (!borrowed_frame_) {
|
||||
return NULL;
|
||||
}
|
||||
av_frame_unref(borrowed_frame_);
|
||||
borrowed_frame_->format = pixfmt_;
|
||||
borrowed_frame_->width = width_;
|
||||
borrowed_frame_->height = height_;
|
||||
|
||||
const int y_size = width_ * height_;
|
||||
const int uv_size = y_size / 4;
|
||||
switch (pixfmt_) {
|
||||
case AV_PIX_FMT_NV12:
|
||||
case AV_PIX_FMT_NV21:
|
||||
if (data_length < y_size + y_size / 2) {
|
||||
LOG_ERROR("wrap_borrowed_frame: NV12/NV21 data length error");
|
||||
return NULL;
|
||||
}
|
||||
borrowed_frame_->data[0] = const_cast<uint8_t *>(data);
|
||||
borrowed_frame_->data[1] = const_cast<uint8_t *>(data + y_size);
|
||||
borrowed_frame_->linesize[0] = width_;
|
||||
borrowed_frame_->linesize[1] = width_;
|
||||
break;
|
||||
case AV_PIX_FMT_YUV420P:
|
||||
if (data_length < y_size + uv_size * 2) {
|
||||
LOG_ERROR("wrap_borrowed_frame: YUV420P data length error");
|
||||
return NULL;
|
||||
}
|
||||
borrowed_frame_->data[0] = const_cast<uint8_t *>(data);
|
||||
borrowed_frame_->data[1] = const_cast<uint8_t *>(data + y_size);
|
||||
borrowed_frame_->data[2] = const_cast<uint8_t *>(data + y_size + uv_size);
|
||||
borrowed_frame_->linesize[0] = width_;
|
||||
borrowed_frame_->linesize[1] = width_ / 2;
|
||||
borrowed_frame_->linesize[2] = width_ / 2;
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
return borrowed_frame_;
|
||||
}
|
||||
|
||||
int bytes_per_pixel(int pix_fmt) {
|
||||
switch (pix_fmt) {
|
||||
case AV_PIX_FMT_YUYV422:
|
||||
@@ -687,14 +608,14 @@ private:
|
||||
} // namespace
|
||||
|
||||
extern "C" FFmpegRamEncoder *
|
||||
ffmpeg_ram_new_encoder(const char *name, const char *mc_name, int width,
|
||||
ffmpeg_ram_new_encoder(const char *name, int width,
|
||||
int height, int pixfmt, int align, int fps, int gop,
|
||||
int rc, int quality, int kbs, int q, int thread_count,
|
||||
int gpu, int *linesize, int *offset, int *length,
|
||||
RamEncodeCallback callback) {
|
||||
FFmpegRamEncoder *encoder = NULL;
|
||||
try {
|
||||
encoder = new FFmpegRamEncoder(name, mc_name, width, height, pixfmt, align,
|
||||
encoder = new FFmpegRamEncoder(name, width, height, pixfmt, align,
|
||||
fps, gop, rc, quality, kbs, q, thread_count,
|
||||
gpu, callback);
|
||||
if (encoder) {
|
||||
@@ -772,3 +693,7 @@ extern "C" void ffmpeg_ram_request_keyframe(FFmpegRamEncoder *encoder) {
|
||||
LOG_ERROR(std::string("ffmpeg_ram_request_keyframe failed, ") + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" const char *ffmpeg_ram_encoder_last_error(void) {
|
||||
return g_encoder_last_error.c_str();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ typedef void (*RamEncodePacketCallback)(void *packet, const uint8_t *data,
|
||||
typedef void (*RamDecodeCallback)(const uint8_t *data, int len, int width,
|
||||
int height, int pixfmt, const void *obj);
|
||||
|
||||
void *ffmpeg_ram_new_encoder(const char *name, const char *mc_name, int width,
|
||||
void *ffmpeg_ram_new_encoder(const char *name, int width,
|
||||
int height, int pixfmt, int align, int fps,
|
||||
int gop, int rc, int quality, int kbs, int q,
|
||||
int thread_count, int gpu, int *linesize,
|
||||
@@ -31,6 +31,7 @@ int ffmpeg_ram_get_linesize_offset_length(int pix_fmt, int width, int height,
|
||||
int *length);
|
||||
int ffmpeg_ram_set_bitrate(void *encoder, int kbs);
|
||||
void ffmpeg_ram_request_keyframe(void *encoder);
|
||||
const char *ffmpeg_ram_encoder_last_error(void);
|
||||
|
||||
void *ffmpeg_ram_new_decoder(const char *name, int width, int height,
|
||||
int sw_pixfmt, int thread_count,
|
||||
|
||||
Reference in New Issue
Block a user