modify distributed screen encoder type on RK & fix crash bug

Signed-off-by: sxzheng96 <zhengshuangxi2@huawei.com>
This commit is contained in:
sxzheng96
2022-03-17 00:46:52 +08:00
parent ff20155de6
commit 5ed15e0ead
11 changed files with 93 additions and 9 deletions
+4
View File
@@ -47,12 +47,14 @@ enum TaskType {
enum CodecType : uint8_t {
VIDEO_CODEC_TYPE_VIDEO_H264 = 0,
VIDEO_CODEC_TYPE_VIDEO_H265 = 1,
VIDEO_CODEC_TYPE_VIDEO_MPEG4 = 2,
};
enum VideoFormat : uint8_t {
VIDEO_DATA_FORMAT_YUVI420 = 0,
VIDEO_DATA_FORMAT_NV12 = 1,
VIDEO_DATA_FORMAT_NV21 = 2,
VIDEO_DATA_FORMAT_RGBA8888 = 3,
};
/* Screen package name */
@@ -112,6 +114,8 @@ const std::string KEY_ERR_CODE = "errCode";
const std::string KEY_ERR_CONTENT = "errContent";
const std::string KEY_VIDEO_PARAM = "videoParam";
const std::string KEY_MAPRELATION = "mapRelation";
const std::string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc";
const std::string CODEC_NAME_MPEG4 = "avenc_mpeg4";
constexpr float DEFAULT_DENSITY = 2.0;
constexpr int32_t DEFAULT_SCREEN_FLAGS = 0;
constexpr uint32_t DEFAULT_FPS = 30;
+1
View File
@@ -52,6 +52,7 @@ enum DScreenErrorCode {
ERR_DH_SCREEN_SA_INVALID_IPC_CALL = -50028,
ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -520029,
ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -520030,
ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -520031,
// Transport component error code
ERR_DH_SCREEN_TRANS_ERROR = -51000,
ERR_DH_SCREEN_TRANS_TIMEOUT = -51001,
+5 -2
View File
@@ -156,11 +156,14 @@ std::string DScreenHandler::QueryCodecInfo()
// query codec info
std::shared_ptr<Media::AVCodecList> codecList = Media::AVCodecListFactory::CreateAVCodecList();
std::vector<std::shared_ptr<Media::VideoCaps>> caps = codecList->GetVideoEncoderCaps();
json codecTypeArray = json::array();
for (const auto &cap : caps) {
std::shared_ptr<Media::AVCodecInfo> codecInfo = cap->GetCodecInfo();
codecInfoStr_.append(codecInfo->GetName());
codecInfoStr_.append(SEPERATOR);
codecTypeArray.push_back(codecInfo->GetName());
}
codecInfoStr_ = codecTypeArray.dump();
return codecInfoStr_;
}
@@ -47,7 +47,7 @@ private:
std::mutex windowIdMapMutex_;
};
class ScreenClientInputEventListener : public RefBase, public MMI::IInputEventConsumer {
class ScreenClientInputEventListener : public MMI::IInputEventConsumer {
public:
ScreenClientInputEventListener() = default;
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
@@ -23,6 +23,7 @@ ohos_shared_library("distributed_screen_source") {
"//utils/system/safwk/native/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
"${fwk_common_path}/utils/include",
"${mediastandard_path}/interfaces/innerkits/native/media/include",
]
include_dirs += [
@@ -57,6 +58,7 @@ ohos_shared_library("distributed_screen_source") {
deps = [
"//utils/native/base:utils",
"${mediastandard_path}/interfaces/innerkits/native/media:media_client",
"${common_path}:distributed_screen_utils",
"${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
@@ -97,6 +97,7 @@ private:
void HandleDisable(const std::string &taskId);
void HandleConnect();
void HandleDisconnect();
int32_t NegotiateCodecType(const std::string &remoteCodecInfoStr);
int32_t SetUp();
int32_t Start();
int32_t Stop();
@@ -15,6 +15,9 @@
#include "dscreen.h"
#include "avcodec_info.h"
#include "avcodec_list.h"
#include "dscreen_constants.h"
#include "dscreen_errcode.h"
#include "dscreen_log.h"
@@ -209,20 +212,68 @@ void DScreen::HandleEnable(const std::string &param, const std::string &taskId)
videoParam_->SetScreenWidth(attrJson[KEY_SCREEN_WIDTH]);
videoParam_->SetScreenHeight(attrJson[KEY_SCREEN_HEIGHT]);
videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_NV21);
videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_RGBA8888);
// negotiate codecType
int32_t ret = NegotiateCodecType(attrJson[KEY_CODECTYPE]);
if (ret != DH_SUCCESS) {
DHLOGE("negotiate codec type failed.");
dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED,
"negotiate codec type failed.");
return;
}
uint64_t screenId = ScreenMgrAdapter::GetInstance().CreateVirtualScreen(devId_, dhId_, videoParam_);
if (screenId == SCREEN_ID_INVALID) {
DHLOGE("create virtual screen failed.");
dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED,
"create virtual screen failed.");
return;
}
screenId_ = screenId;
SetState(ENABLED);
dscreenCallback_->OnRegResult(shared_from_this(), taskId, DH_SUCCESS, "");
}
int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr)
{
json remoteCodecArray = json::parse(remoteCodecInfoStr, nullptr, false);
if (remoteCodecArray.is_discarded() || !remoteCodecArray.is_array()) {
DHLOGE("remoteCodecInfoStrjson is invalid.");
return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL;
}
std::vector<std::string> localCodecArray;
// query local support encoder type
std::shared_ptr<Media::AVCodecList> codecList = Media::AVCodecListFactory::CreateAVCodecList();
std::vector<std::shared_ptr<Media::VideoCaps>> caps = codecList->GetVideoEncoderCaps();
for (const auto &cap : caps) {
std::shared_ptr<Media::AVCodecInfo> codecInfo = cap->GetCodecInfo();
localCodecArray.push_back(codecInfo->GetName());
}
std::vector<std::string> codecTypeCandidates;
for (const auto &remoteCodecType : remoteCodecArray) {
if (std::find(localCodecArray.begin(), localCodecArray.end(),
remoteCodecType) != localCodecArray.end()) {
codecTypeCandidates.push_back(remoteCodecType);
}
}
if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(),
CODEC_NAME_H264) != codecTypeCandidates.end()) {
videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264);
} else if(std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(),
CODEC_NAME_MPEG4) != codecTypeCandidates.end()) {
videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_MPEG4);
} else {
DHLOGI("codec type not support.");
return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL;
}
return DH_SUCCESS;
}
void DScreen::HandleDisable(const std::string &taskId)
{
DHLOGI("HandleDisable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
@@ -119,6 +119,9 @@ int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam)
case VIDEO_CODEC_TYPE_VIDEO_H265:
videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/hevc");
break;
case VIDEO_CODEC_TYPE_VIDEO_MPEG4:
videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/mp4v-es");
break;
default:
DHLOGE("%s: codecType is invalid!", LOG_TAG);
videoDecoder_ = nullptr;
@@ -154,6 +157,9 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam)
case VIDEO_CODEC_TYPE_VIDEO_H265:
imageFormat_.PutStringValue("codec_mime", "video/hevc");
break;
case VIDEO_CODEC_TYPE_VIDEO_MPEG4:
imageFormat_.PutStringValue("codec_mime", "video/mp4v-es");
break;
default:
DHLOGE("The current codec type does not support decoding.");
return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION;
@@ -168,6 +174,9 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam)
case VIDEO_DATA_FORMAT_NV21:
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21);
break;
case VIDEO_DATA_FORMAT_RGBA8888:
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA);
break;
default:
DHLOGE("The current pixel format does not support decoding.");
return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION;
@@ -140,14 +140,16 @@ int32_t ScreenSinkTrans::SetImageSurface(const sptr<Surface> &surface)
int32_t ScreenSinkTrans::CheckVideoParam(const VideoParam &param)
{
if ((param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H264) &&
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265)) {
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265) &&
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_MPEG4)) {
DHLOGE("%s: Invalid codec type.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
}
if ((param.GetVideoFormat() != VIDEO_DATA_FORMAT_YUVI420) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV12) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21)) {
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_RGBA8888)) {
DHLOGE("%s: Invalid video data format.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
}
@@ -122,6 +122,9 @@ int32_t ImageSourceEncoder::InitVideoEncoder(const VideoParam &configParam)
case VIDEO_CODEC_TYPE_VIDEO_H265:
videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/hevc");
break;
case VIDEO_CODEC_TYPE_VIDEO_MPEG4:
videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/mp4v-es");
break;
default:
DHLOGE("%s: codecType is invalid!", LOG_TAG);
videoEncoder_ = nullptr;
@@ -157,6 +160,9 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam)
case VIDEO_CODEC_TYPE_VIDEO_H265:
imageFormat_.PutStringValue("codec_mime", "video/hevc");
break;
case VIDEO_CODEC_TYPE_VIDEO_MPEG4:
imageFormat_.PutStringValue("codec_mime", "video/mp4v-es");
break;
default:
DHLOGE("%s: Codec type is invalid.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
@@ -171,6 +177,9 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam)
case VIDEO_DATA_FORMAT_NV21:
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21);
break;
case VIDEO_DATA_FORMAT_RGBA8888:
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA);
break;
default:
DHLOGE("%s: Video format is invalid.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
@@ -152,14 +152,16 @@ sptr<Surface> &ScreenSourceTrans::GetImageSurface()
int32_t ScreenSourceTrans::CheckVideoParam(const VideoParam &param)
{
if ((param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H264) &&
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265)) {
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265) &&
(param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_MPEG4)) {
DHLOGE("%s: Invalid codec type.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
}
if ((param.GetVideoFormat() != VIDEO_DATA_FORMAT_YUVI420) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV12) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21)) {
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21) &&
(param.GetVideoFormat() != VIDEO_DATA_FORMAT_RGBA8888)) {
DHLOGE("%s: Invalid video data format.", LOG_TAG);
return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM;
}