diff --git a/frameworks/native/common/avcodec_errors.cpp b/frameworks/native/common/avcodec_errors.cpp index 0ba00752f..6a93668f5 100644 --- a/frameworks/native/common/avcodec_errors.cpp +++ b/frameworks/native/common/avcodec_errors.cpp @@ -68,7 +68,8 @@ const std::map AVCS_ERRCODE_INFOS = { {AVCS_ERR_CONFIGURE_ERROR, "compression level incorrect in flac encoder"}, {AVCS_ERR_DECRYPT_FAILED, "decrypt protected content failed"}, {AVCS_ERR_CODEC_PARAM_INCORRECT, "video codec param check failed"}, - {AVCS_ERR_EXTEND_START, "extend start error code"}}; + {AVCS_ERR_EXTEND_START, "extend start error code"}, + {AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, "video unsupported color space conversion"}}; const std::map AVCSERRCODE_TO_OHAVCODECERRCODE = { {AVCS_ERR_OK, AV_ERR_OK}, @@ -119,6 +120,7 @@ const std::map AVCSERRCODE_TO_OHAVCODECERRC {AVCS_ERR_EXTEND_START, AV_ERR_EXTEND_START}, {AVCS_ERR_DECRYPT_FAILED, AV_ERR_DRM_DECRYPT_FAILED}, {AVCS_ERR_CODEC_PARAM_INCORRECT, AV_ERR_INVALID_VAL}, + {AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, AV_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION}, }; const std::map OHAVCODECERRCODE_INFOS = { @@ -180,6 +182,21 @@ const std::map STATUS_TO_AVCSERRCODE = { {Status::ERROR_IPC_SEND_REQUEST, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, {Status::ERROR_DRM_DECRYPT_FAILED, AVCodecServiceErrCode::AVCS_ERR_DECRYPT_FAILED}}; +const std::map VPEERROR_TO_AVCSERRCODE = { + {0, AVCodecServiceErrCode::AVCS_ERR_OK}, + {63635468, AVCodecServiceErrCode::AVCS_ERR_NO_MEMORY}, // 63635468: no memory + {63635494, AVCodecServiceErrCode::AVCS_ERR_INVALID_OPERATION}, // 63635494: opertation not be permitted + {63635478, AVCodecServiceErrCode::AVCS_ERR_INVALID_VAL}, // 63635478: invalid argument + {63635968, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, // 63635968: unknow error + {63635969, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, // 63635969: video processing engine init failed + {63635970, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, // 63635970: extension not found + {63635971, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, // 63635971: extension init failed + {63635972, AVCodecServiceErrCode::AVCS_ERR_UNKNOWN}, // 63635972: extension process failed + {63635973, + AVCodecServiceErrCode::AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION}, // 63635973: extension is not implemented + {63635974, AVCodecServiceErrCode::AVCS_ERR_INVALID_OPERATION}, // 63635974: not supported operation + {63635975, AVCodecServiceErrCode::AVCS_ERR_INVALID_STATE}}; // 63635975: the state is not support this operation + std::string ErrorMessageOk(const std::string ¶m1, const std::string ¶m2) { (void)param1; @@ -296,5 +313,14 @@ AVCodecServiceErrCode StatusToAVCodecServiceErrCode(Status code) return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN; } + +AVCodecServiceErrCode VPEErrorToAVCSError(int32_t code) +{ + if (VPEERROR_TO_AVCSERRCODE.count(code) != 0) { + return VPEERROR_TO_AVCSERRCODE.at(code); + } + + return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN; +} } // namespace MediaAVCodec } // namespace OHOS diff --git a/interfaces/inner_api/native/avcodec_errors.h b/interfaces/inner_api/native/avcodec_errors.h index 2c709262d..f35f1be20 100644 --- a/interfaces/inner_api/native/avcodec_errors.h +++ b/interfaces/inner_api/native/avcodec_errors.h @@ -73,9 +73,9 @@ typedef enum AVCodecServiceErrCode : ErrCode { AVCS_ERR_DATA_SOURCE_ERROR_UNKNOWN, // avcodec data source error unknow. AVCS_ERR_CODEC_PARAM_INCORRECT, // video codec param check failed. - AVCE_ERR_IPC_UNKNOWN, // avcodec ipc unknown err. - AVCE_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, // avcodec ipc err, get sub system ability failed. - AVCE_ERR_IPC_SET_DEATH_LISTENER_FAILED, // avcodec ipc err, set death listener failed. + AVCS_ERR_IPC_UNKNOWN, // avcodec ipc unknown err. + AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, // avcodec ipc err, get sub system ability failed. + AVCS_ERR_IPC_SET_DEATH_LISTENER_FAILED, // avcodec ipc err, set death listener failed. AVCS_ERR_CREATE_CODECLIST_STUB_FAILED, // create codeclist sub service failed. AVCS_ERR_CREATE_AVCODEC_STUB_FAILED, // create avcodec sub service failed. @@ -88,7 +88,8 @@ typedef enum AVCodecServiceErrCode : ErrCode { AVCS_ERR_INVALID_DATA, // Invalid data found when processing input AVCS_ERR_DECRYPT_FAILED, // drm decrypt failed AVCS_ERR_TRY_AGAIN, // try again later - AVCS_ERR_EMPTY_INPUT_FAILED, //there is somthing wrong for input buffer + AVCS_ERR_EMPTY_INPUT_FAILED, // there is somthing wrong for input buffer + AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, // video unsupport color space conversion AVCS_ERR_EXTEND_START = AVCS_ERR_OFFSET + 0xF000, // extend err start. } AVCodecServiceErrCode; @@ -98,6 +99,7 @@ __attribute__((visibility("default"))) std::string OHAVErrCodeToString(OH_AVErrC __attribute__((visibility("default"))) std::string AVCSErrorToOHAVErrCodeString(AVCodecServiceErrCode code); __attribute__((visibility("default"))) OH_AVErrCode AVCSErrorToOHAVErrCode(AVCodecServiceErrCode code); __attribute__((visibility("default"))) AVCodecServiceErrCode StatusToAVCodecServiceErrCode(Media::Status code); +__attribute__((visibility("default"))) AVCodecServiceErrCode VPEErrorToAVCSError(int32_t code); } // namespace MediaAVCodec } // namespace OHOS #endif // MEDIA_AVCODEC_ERRORS_H diff --git a/interfaces/kits/c/native_avcodec_base.h b/interfaces/kits/c/native_avcodec_base.h index 42fbcf30d..abed83eb5 100644 --- a/interfaces/kits/c/native_avcodec_base.h +++ b/interfaces/kits/c/native_avcodec_base.h @@ -631,12 +631,10 @@ extern const char *OH_MD_KEY_START_TIME; * The supported value is {@link OH_COLORSPACE_BT709_LIMIT}, see {@link OH_NativeBuffer_ColorSpace}. It is used in * {@link OH_VideoDecoder_Configure}. If the color space conversion capability is supported and this key is configured, * the video decoder will automatically transcode an HDR Vivid video to an SDR video with color space BT709. - * If the value of this key is not configured as {@link OH_COLORSPACE_BT709_LIMIT}, {@link OH_VideoDecoder_Configure} - * returns @{link AV_ERR_INVALID_VAL}. * If color space conversion capability is not supported, {@link OH_VideoDecoder_Configure} returns - * {@link AV_ERR_INVALID_VAL}. - * If the input video is not an HDR vivid video, an error {@link AV_ERR_UNSUPPORT} will be reported by callback - * function {@link OH_AVCodecOnError}. + * {@link AV_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION}. + * If the input video is not an HDR vivid video, an error {@link AV_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION} will be + * reported by callback function {@link OH_AVCodecOnError}. * * @syscap SystemCapability.Multimedia.Media.CodecBase * @since 12 diff --git a/interfaces/kits/c/native_avcodec_videodecoder.h b/interfaces/kits/c/native_avcodec_videodecoder.h index 7b0f264a1..da12e5b79 100644 --- a/interfaces/kits/c/native_avcodec_videodecoder.h +++ b/interfaces/kits/c/native_avcodec_videodecoder.h @@ -135,6 +135,8 @@ OH_AVErrCode OH_VideoDecoder_SetSurface(OH_AVCodec *codec, OHNativeWindow *windo * {@link AV_ERR_UNKNOWN}, unknown error. * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare. + * {@link AV_ERR_UNSUPPORT}, unsupported features. + * {@link AV_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION}, video unsupported color space conversion. * @since 9 * @version 1.0 */ diff --git a/services/services/codec/server/codec_param_checker.cpp b/services/services/codec/server/codec_param_checker.cpp index 9b0786b8a..0aa3ceee9 100644 --- a/services/services/codec/server/codec_param_checker.cpp +++ b/services/services/codec/server/codec_param_checker.cpp @@ -367,15 +367,17 @@ int32_t PostProcessingChecker(CapabilityData &capData, Format &format, CodecScen if (!hasColorSpace) { return AVCS_ERR_OK; } - CHECK_AND_RETURN_RET_LOG( - scenario == CodecScenario::CODEC_SCENARIO_DEC_NORMAL && capData.mimeType == CodecMimeType::VIDEO_HEVC && - capData.isVendor, - AVCS_ERR_INVALID_VAL, - "colorspace conversion is not available for the codec."); + CHECK_AND_RETURN_RET_LOG((colorSpace >= 0) && // 0: OH_COLORSAPCE_NONE + (colorSpace <= 31), // 31: OH_COLORSPACE_DISPLAY_BT2020_PQ + AVCS_ERR_INVALID_VAL, "The output color space %{public}d is invaild", colorSpace); + CHECK_AND_RETURN_RET_LOG(scenario == CodecScenario::CODEC_SCENARIO_DEC_NORMAL && + capData.mimeType == CodecMimeType::VIDEO_HEVC && capData.isVendor, + AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, + "colorspace conversion is not available for the codec."); constexpr int32_t colorSpaceBt709Limited = 8; // see OH_COLORSPACE_BT709_LIMITED in native_buffer.h; - CHECK_AND_RETURN_RET_LOG(colorSpace == colorSpaceBt709Limited, AVCS_ERR_INVALID_VAL, - "The output color space %{public}d is not supported", colorSpace); + CHECK_AND_RETURN_RET_LOG(colorSpace == colorSpaceBt709Limited, AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, + "The output color space %{public}d is not supported", colorSpace); PrintParam(true, MediaDescriptionKey::MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE, colorSpace); return AVCS_ERR_OK; diff --git a/services/services/codec/server/codec_server.cpp b/services/services/codec/server/codec_server.cpp index a965fa934..30d85635c 100644 --- a/services/services/codec/server/codec_server.cpp +++ b/services/services/codec/server/codec_server.cpp @@ -582,6 +582,8 @@ int32_t CodecServer::GetOutputFormat(Format &format) GetStatusDescription(status_).data()); CHECK_AND_RETURN_RET_LOG(codecBase_ != nullptr, AVCS_ERR_NO_MEMORY, "Codecbase is nullptr"); if (postProcessing_) { + int32_t ret = codecBase_->GetOutputFormat(format); + CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, ret, "GetOutputFormat failed"); return GetPostProcessingOutputFormat(format); } else { return codecBase_->GetOutputFormat(format); @@ -846,6 +848,9 @@ void CodecServer::OnError(int32_t errorType, int32_t errorCode) void CodecServer::OnOutputFormatChanged(const Format &format) { std::lock_guard lock(cbMutex_); + if (postProcessing_) { + return; + } if (videoCb_ != nullptr) { videoCb_->OnOutputFormatChanged(format); } @@ -1335,7 +1340,9 @@ void CodecServer::PostProcessingOnError(int32_t errorCode) if (!videoCb_) { AVCODEC_LOGD("Missing video callback"); } - videoCb_->OnError(AVCodecErrorType::AVCODEC_ERROR_INTERNAL, errorCode); + int32_t ret = VPEErrorToAVCSError(errorCode); + AVCODEC_LOGD("PostProcessingOnError, errorCodec:%{public}d -> %{public}d", errorCode, ret); + videoCb_->OnError(AVCodecErrorType::AVCODEC_ERROR_INTERNAL, ret); } void CodecServer::PostProcessingOnOutputBufferAvailable(uint32_t index, [[maybe_unused]] int32_t flag) diff --git a/services/services/codec/server/post_processing/controller.h b/services/services/codec/server/post_processing/controller.h index e74e4a9ea..495d621d1 100644 --- a/services/services/codec/server/post_processing/controller.h +++ b/services/services/codec/server/post_processing/controller.h @@ -106,6 +106,11 @@ public: return This()->FlushImpl(); } + int32_t GetOutputFormat(Media::Format& format) + { + return This()->GetOutputFormatImpl(format); + } + int32_t Reset() { return This()->ResetImpl(); @@ -215,6 +220,12 @@ private: return AVCS_ERR_UNKNOWN; } + int32_t GetOutputFormatImpl([[maybe_unused]] Media::Format &format) + { + AVCODEC_LOGE("Not implemented."); + return AVCS_ERR_UNKNOWN; + } + int32_t ResetImpl() { AVCODEC_LOGE("Not implemented."); diff --git a/services/services/codec/server/post_processing/dynamic_controller.cpp b/services/services/codec/server/post_processing/dynamic_controller.cpp index 030e310f5..cf6cd6f49 100644 --- a/services/services/codec/server/post_processing/dynamic_controller.cpp +++ b/services/services/codec/server/post_processing/dynamic_controller.cpp @@ -144,7 +144,16 @@ int32_t DynamicController::StopImpl() int32_t DynamicController::FlushImpl() { auto ret = interface_.Invoke(instance_); - CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Stop video processing failed."); + CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Flush video processing failed."); + return AVCS_ERR_OK; +} + +int32_t DynamicController::GetOutputFormatImpl(Media::Format &format) +{ + void *formatPtr = static_cast(&format); + auto ret = interface_.Invoke(instance_, formatPtr); + CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, + "GetOutputFormat video processing failed."); return AVCS_ERR_OK; } diff --git a/services/services/codec/server/post_processing/dynamic_controller.h b/services/services/codec/server/post_processing/dynamic_controller.h index fa03bafe0..ccb364d0e 100644 --- a/services/services/codec/server/post_processing/dynamic_controller.h +++ b/services/services/codec/server/post_processing/dynamic_controller.h @@ -44,6 +44,7 @@ public: int32_t StartImpl(); int32_t StopImpl(); int32_t FlushImpl(); + int32_t GetOutputFormatImpl(Media::Format& format); int32_t ResetImpl(); int32_t ReleaseImpl(); int32_t ReleaseOutputBufferImpl(uint32_t index, bool render); diff --git a/services/services/codec/server/post_processing/dynamic_interface_types.h b/services/services/codec/server/post_processing/dynamic_interface_types.h index 55c42ab7b..2df2ee461 100644 --- a/services/services/codec/server/post_processing/dynamic_interface_types.h +++ b/services/services/codec/server/post_processing/dynamic_interface_types.h @@ -42,6 +42,7 @@ using DynamicFlushFunc = int32_t(*)(DynamicColorSpaceConverterHandle*); using DynamicResetFunc = int32_t(*)(DynamicColorSpaceConverterHandle*); using DynamicReleaseFunc = int32_t(*)(DynamicColorSpaceConverterHandle*); using DynamicReleaseOutputBufferFunc = int32_t(*)(DynamicColorSpaceConverterHandle*, uint32_t, bool); +using DynamicGetOutputFormatFunc = int32_t(*)(DynamicColorSpaceConverterHandle*, void*); // function pointer types array using DynamicInterfaceFuncTypes = TypeArray< @@ -60,7 +61,8 @@ using DynamicInterfaceFuncTypes = TypeArray< DynamicFlushFunc, DynamicResetFunc, DynamicReleaseFunc, - DynamicReleaseOutputBufferFunc + DynamicReleaseOutputBufferFunc, + DynamicGetOutputFormatFunc >; // function symbols @@ -80,7 +82,8 @@ constexpr const char* DYNAMIC_INTERFACE_SYMBOLS[]{ "ColorSpaceConvertVideoFlush", "ColorSpaceConvertVideoReset", "ColorSpaceConvertVideoRelease", - "ColorSpaceConvertVideoReleaseOutputBuffer" + "ColorSpaceConvertVideoReleaseOutputBuffer", + "ColorSpaceConvertVideoGetOutputFormat" }; // function name enumeration @@ -100,7 +103,8 @@ enum class DynamicInterfaceName : size_t { FLUSH, RESET, RELEASE, - RELEASE_OUPUT_BUFFER + RELEASE_OUPUT_BUFFER, + GET_OUTPUT_FORMAT, }; // dynamic interface helper types diff --git a/services/services/codec/server/post_processing/post_processing.h b/services/services/codec/server/post_processing/post_processing.h index c85eea3b1..5223e74f8 100644 --- a/services/services/codec/server/post_processing/post_processing.h +++ b/services/services/codec/server/post_processing/post_processing.h @@ -203,14 +203,19 @@ public: void GetOutputFormat(Format& format) { - format = format_; + CHECK_AND_RETURN_LOG(controller_, "Post processing controller is null"); + AVCODEC_SYNC_TRACE; + int32_t ret = controller_->GetOutputFormat(format); + CHECK_AND_RETURN_LOG(ret == AVCS_ERR_OK, "GetOutputFormat failed"); + return; } private: int32_t Init(const Format& format) { controller_ = std::make_unique(); CHECK_AND_RETURN_RET_LOG(controller_, AVCS_ERR_NO_MEMORY, "Create post processing controller failed"); - CHECK_AND_RETURN_RET_LOG(controller_->LoadInterfaces(), AVCS_ERR_UNSUPPORT, "Initialize interfaces failed."); + CHECK_AND_RETURN_RET_LOG(controller_->LoadInterfaces(), AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION, + "Initialize interfaces failed."); CreateConfiguration(format); diff --git a/services/services/sa_avcodec/ipc/avcodec_service_proxy.cpp b/services/services/sa_avcodec/ipc/avcodec_service_proxy.cpp index e4d3c426b..9c9c58fa8 100644 --- a/services/services/sa_avcodec/ipc/avcodec_service_proxy.cpp +++ b/services/services/sa_avcodec/ipc/avcodec_service_proxy.cpp @@ -36,24 +36,24 @@ AVCodecServiceProxy::~AVCodecServiceProxy() int32_t AVCodecServiceProxy::GetSubSystemAbility(IStandardAVCodecService::AVCodecSystemAbility subSystemId, const sptr &listener, sptr &object) { - CHECK_AND_RETURN_RET_LOG(listener != nullptr, AVCE_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "listener is nullptr"); + CHECK_AND_RETURN_RET_LOG(listener != nullptr, AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "listener is nullptr"); MessageParcel data; MessageParcel reply; MessageOption option; bool ret = data.WriteInterfaceToken(AVCodecServiceProxy::GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(ret, AVCE_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "Failed to write descriptor"); + CHECK_AND_RETURN_RET_LOG(ret, AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "Failed to write descriptor"); (void)data.WriteInt32(static_cast(subSystemId)); (void)data.WriteRemoteObject(listener); int error = Remote()->SendRequest(static_cast(AVCodecServiceInterfaceCode::GET_SUBSYSTEM), data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == 0, AVCE_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, + CHECK_AND_RETURN_RET_LOG(error == 0, AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "Create av_codec proxy failed, error: %{public}d", error); object = reply.ReadRemoteObject(); - CHECK_AND_RETURN_RET_LOG(object != nullptr, AVCE_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "Remote object is nullptr"); + CHECK_AND_RETURN_RET_LOG(object != nullptr, AVCS_ERR_IPC_GET_SUB_SYSTEM_ABILITY_FAILED, "Remote object is nullptr"); return reply.ReadInt32(); } } // namespace MediaAVCodec diff --git a/services/services/sa_avcodec/server/avcodec_server.cpp b/services/services/sa_avcodec/server/avcodec_server.cpp index ac832609f..3da238f73 100644 --- a/services/services/sa_avcodec/server/avcodec_server.cpp +++ b/services/services/sa_avcodec/server/avcodec_server.cpp @@ -112,7 +112,7 @@ int32_t AVCodecServer::GetSubSystemAbility(IStandardAVCodecService::AVCodecSyste AVCodecServerManager::GetInstance().DestroyStubObject(*stubType, stubObject); stubObject = nullptr; AVCODEC_LOGE("SetDeathListener failed"); - return AVCE_ERR_IPC_SET_DEATH_LISTENER_FAILED; + return AVCS_ERR_IPC_SET_DEATH_LISTENER_FAILED; } return AVCS_ERR_OK;