diff --git a/common/include/utils/dcamera_utils_tools.h b/common/include/utils/dcamera_utils_tools.h index 13892032cad760f70ef002c1b8a9098d25f78bcc..bcd64cad70c7cf8b4acaa7290fe044a9865fb6f2 100644 --- a/common/include/utils/dcamera_utils_tools.h +++ b/common/include/utils/dcamera_utils_tools.h @@ -27,6 +27,7 @@ const std::string BASE_64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs int32_t GetLocalDeviceNetworkId(std::string& networkId); int64_t GetNowTimeStampMs(); int64_t GetNowTimeStampUs(); +int32_t GetAlignedHeight(int32_t width); std::string Base64Encode(const unsigned char *toEncode, unsigned int len); std::string Base64Decode(const std::string& basicString); bool IsBase64(unsigned char c); diff --git a/common/src/utils/dcamera_utils_tools.cpp b/common/src/utils/dcamera_utils_tools.cpp index 65a701ee09af6547900e7ebd6ca7cdab0aee5eca..ae03d8fbd1aae011c9b33c2396eb4819d2bf4e2f 100644 --- a/common/src/utils/dcamera_utils_tools.cpp +++ b/common/src/utils/dcamera_utils_tools.cpp @@ -57,6 +57,16 @@ int64_t GetNowTimeStampUs() return nowUs.count(); } +int32_t GetAlignedHeight(int32_t width) +{ + int32_t alignedBits = 32; + int32_t alignedHeight = width; + if (alignedHeight % alignedBits != 0) { + alignedHeight = ((alignedHeight / alignedBits) + 1) * alignedBits; + } + return alignedHeight; +} + std::string Base64Encode(const unsigned char *toEncode, unsigned int len) { std::string ret; diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index 62990b3e193af96de77e22408d10d548eacce87c..7daabadbaf1177460bc6a3f4dc0f87cf5175f121 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -36,7 +36,8 @@ ohos_shared_library("distributed_camera_data_process") { "include/eventbus", "include/pipeline", "include/utils", - "include/pipeline_node/multimedia_codec", + "include/pipeline_node/multimedia_codec/decoder", + "include/pipeline_node/multimedia_codec/encoder", "include/pipeline_node/colorspace_conversion", "include/pipeline_node/fpscontroller", "${common_path}/include/constants", @@ -50,20 +51,21 @@ ohos_shared_library("distributed_camera_data_process") { "src/pipeline/dcamera_pipeline_source.cpp", "src/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.cpp", "src/pipeline_node/fpscontroller/fps_controller_process.cpp", - "src/pipeline_node/multimedia_codec/decode_video_callback.cpp", - "src/pipeline_node/multimedia_codec/encode_video_callback.cpp", + "src/pipeline_node/multimedia_codec/decoder/decode_video_callback.cpp", + "src/pipeline_node/multimedia_codec/decoder/decode_surface_listener.cpp", + "src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp", "src/utils/image_common_type.cpp", ] if (device_name == "baltimore") { sources += [ - "src/pipeline_node/multimedia_codec/decode_data_process.cpp", - "src/pipeline_node/multimedia_codec/encode_data_process.cpp", + "src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp", + "src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp", ] } else { sources += [ - "src/pipeline_node/multimedia_codec/decode_data_process_common.cpp", - "src/pipeline_node/multimedia_codec/encode_data_process_common.cpp", + "src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp", + "src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp", ] } diff --git a/services/data_process/include/eventbus/dcamera_codec_event.h b/services/data_process/include/eventbus/dcamera_codec_event.h index 91a77be949940ec8944d935c3252ed7da414a80e..5ad47c4c34df471914efbd4794cdd542f2bab09c 100644 --- a/services/data_process/include/eventbus/dcamera_codec_event.h +++ b/services/data_process/include/eventbus/dcamera_codec_event.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/eventbus/dcamera_pipeline_event.h b/services/data_process/include/eventbus/dcamera_pipeline_event.h index 5c2534cb995bae1edf0c2748849aa3eeb0b04694..473e9d0fdd0d61add4c8ea77b9ca43e953aeb931 100644 --- a/services/data_process/include/eventbus/dcamera_pipeline_event.h +++ b/services/data_process/include/eventbus/dcamera_pipeline_event.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/interfaces/data_process_listener.h b/services/data_process/include/interfaces/data_process_listener.h index ce79eb8e68e3c05d6a1d62c3c3ed8eea66a3c5cf..9edba69d4417556a27f12355e5f48f1e4c132ca5 100644 --- a/services/data_process/include/interfaces/data_process_listener.h +++ b/services/data_process/include/interfaces/data_process_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/interfaces/idata_process_pipeline.h b/services/data_process/include/interfaces/idata_process_pipeline.h index 053c1af65b3304a4e2a0d9e1c6aa52f691db14d6..689e623e167ba4f7a5ecd67a2e7b0a419a89ac36 100644 --- a/services/data_process/include/interfaces/idata_process_pipeline.h +++ b/services/data_process/include/interfaces/idata_process_pipeline.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline/abstract_data_process.h b/services/data_process/include/pipeline/abstract_data_process.h index 7f18737c8f9b7b6f36458f08ccba36752a245aef..11d1fb4e26ae89fca9758fa3aa28e6f3ef8baeb0 100644 --- a/services/data_process/include/pipeline/abstract_data_process.h +++ b/services/data_process/include/pipeline/abstract_data_process.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline/dcamera_pipeline_sink.h b/services/data_process/include/pipeline/dcamera_pipeline_sink.h index 13df907dcc86a04b972654d1e625636f12f5c1c2..f49148c5ed055b6e7227aca2bc465f847dc0fe0c 100644 --- a/services/data_process/include/pipeline/dcamera_pipeline_sink.h +++ b/services/data_process/include/pipeline/dcamera_pipeline_sink.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline/dcamera_pipeline_source.h b/services/data_process/include/pipeline/dcamera_pipeline_source.h index 3e6651417f3bb7d17f38bccf3f87604adc3b804c..aeca8b4f80088d45cedc1912c447bbcfcc75566b 100644 --- a/services/data_process/include/pipeline/dcamera_pipeline_source.h +++ b/services/data_process/include/pipeline/dcamera_pipeline_source.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.h b/services/data_process/include/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.h index 515da2441d6c3c10790d83a368d4411edbba359c..5f950716b7aef74b4e8a3c293fd285a86730b50b 100644 --- a/services/data_process/include/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.h +++ b/services/data_process/include/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h b/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h index 1dec54d6a1bd48ccc94438ed541bddd4cddf6204..69263346652a3f92255df8e8e22a05b6ae6e0fc0 100644 --- a/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h +++ b/services/data_process/include/pipeline_node/fpscontroller/fps_controller_process.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -43,7 +43,7 @@ private: float CalculateFrameRate(int64_t nowMs); bool IsDropFrame(float incomingFps); bool ReduceFrameRateByUniformStrategy(int32_t incomingFps); - int32_t FpsControllerDone(std::vector> outputBuffers); + int32_t FpsControllerDone(std::vector>& outputBuffers); private: const static uint32_t MAX_TARGET_FRAME_RATE = 30; diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h similarity index 88% rename from services/data_process/include/pipeline_node/multimedia_codec/decode_data_process.h rename to services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h index 25430059d9bb0ff620a13e5c492a2793e3617a76..764f4777c5a1c2cfecd928587e3204afabcec0a1 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/decode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,6 +24,7 @@ #include #include "surface.h" +#include "ibuffer_consumer_listener.h" #include "media_errors.h" #include "avcodec_common.h" #include "format.h" @@ -78,26 +79,31 @@ private: int32_t InitDecoder(); int32_t InitDecoderMetadataFormat(); int32_t SetDecoderOutputSurface(); + int32_t StopVideoDecoder(); + void ReleaseVideoDecoder(); + void ReleaseDecoderSurface(); + void ReleaseCodecEvent(); int32_t FeedDecoderInputBuffer(); int64_t GetDecoderTimeStamp(); - int32_t GetAlignedHeight(); void CopyDecodedImage(const sptr& surBuf, int64_t timeStampUs, int32_t alignedWidth, int32_t alignedHeight); int32_t CopyYUVPlaneByRow(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo); int32_t CheckCopyImageInfo(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo); bool IsCorrectImageUnitInfo(const ImageUnitInfo& imgInfo); void PostOutputDataBuffers(std::shared_ptr& outputBuffer); - int32_t DecodeDone(std::vector> outputBuffers); + int32_t DecodeDone(std::vector>& outputBuffers); private: const static int32_t VIDEO_DECODER_QUEUE_MAX = 1000; const static int32_t MAX_YUV420_BUFFER_SIZE = 1920 * 1080 * 3 / 2 * 2; + const static int32_t MAX_RGB32_BUFFER_SIZE = 1920 * 1080 * 4 * 2; const static uint32_t MAX_FRAME_RATE = 30; const static uint32_t MIN_VIDEO_WIDTH = 320; const static uint32_t MIN_VIDEO_HEIGHT = 240; const static uint32_t MAX_VIDEO_WIDTH = 1920; const static uint32_t MAX_VIDEO_HEIGHT = 1080; const static int32_t FIRST_FRAME_INPUT_NUM = 2; + const static int32_t RGB32_MEMORY_COEFFICIENT = 4; std::mutex mtxDecoderState_; std::mutex mtxHoldCount_; @@ -126,21 +132,6 @@ private: std::queue> inputBuffersQueue_; std::queue availableInputIndexsQueue_; }; - -class DecodeSurfaceListener : public IBufferConsumerListener { -public: - DecodeSurfaceListener(sptr surface, std::weak_ptr decodeVideoNode) - : surface_(surface), decodeVideoNode_(decodeVideoNode) {} - ~DecodeSurfaceListener(); - - void OnBufferAvailable() override; - void SetSurface(const sptr& surface); - void SetDecodeVideoNode(const std::weak_ptr& decodeVideoNode); - -private: - sptr surface_; - std::weak_ptr decodeVideoNode_; -}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DECODE_DATA_PROCESS_H diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_surface_listener.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_surface_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..ef0e6bd72a19ca475b917e611db9389d3f97aed1 --- /dev/null +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_surface_listener.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DECODE_SURFACE_LISTENER_H +#define OHOS_DECODE_SURFACE_LISTENER_H + +#include "surface.h" +#include "ibuffer_consumer_listener.h" + +#include "decode_data_process.h" + +namespace OHOS { +namespace DistributedHardware { +class DecodeDataProcess; + +class DecodeSurfaceListener : public IBufferConsumerListener { +public: + DecodeSurfaceListener(sptr surface, std::weak_ptr decodeVideoNode) + : surface_(surface), decodeVideoNode_(decodeVideoNode) {} + ~DecodeSurfaceListener(); + + void OnBufferAvailable() override; + void SetSurface(const sptr& surface); + void SetDecodeVideoNode(const std::weak_ptr& decodeVideoNode); + sptr GetSurface() const; + std::shared_ptr GetDecodeVideoNode() const; + +private: + sptr surface_; + std::weak_ptr decodeVideoNode_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DECODE_SURFACE_LISTENER_H diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decode_video_callback.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_video_callback.h similarity index 97% rename from services/data_process/include/pipeline_node/multimedia_codec/decode_video_callback.h rename to services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_video_callback.h index cec129ebc2c856510a9c0e847e5acbb35a409565..0a35ee5180f21f83ae21cd37f634a66f2c221f62 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/decode_video_callback.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_video_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/pipeline_node/multimedia_codec/encode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h similarity index 96% rename from services/data_process/include/pipeline_node/multimedia_codec/encode_data_process.h rename to services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h index 29bb7a6b35dcd9aa612adde1b9076dd20a808b12..50e9f16da2fc087a0298926dc2f7db9e45cfe9f2 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/encode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_data_process.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -63,11 +63,13 @@ private: int32_t InitEncoder(); int32_t InitEncoderMetadataFormat(); int32_t InitEncoderBitrateFormat(); + int32_t StopVideoEncoder(); + void ReleaseVideoEncoder(); int32_t FeedEncoderInputBuffer(std::shared_ptr& inputBuffer); sptr GetEncoderInputSurfaceBuffer(); int64_t GetEncoderTimeStamp(); int32_t GetEncoderOutputBuffer(uint32_t index, Media::AVCodecBufferInfo info); - int32_t EncodeDone(std::vector> outputBuffers); + int32_t EncodeDone(std::vector>& outputBuffers); private: const static int32_t ENCODER_STRIDE_ALIGNMENT = 8; diff --git a/services/data_process/include/pipeline_node/multimedia_codec/encode_video_callback.h b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_video_callback.h similarity index 97% rename from services/data_process/include/pipeline_node/multimedia_codec/encode_video_callback.h rename to services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_video_callback.h index 34f6fc11addc5e41e5c15c4ec7198c61bca09845..0cffb62a707be8899616457667bc73fc1413efdf 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/encode_video_callback.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/encoder/encode_video_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/include/utils/image_common_type.h b/services/data_process/include/utils/image_common_type.h index 9e302d963528ea82704907755d8afd8d7d89d9a8..a176c85d2d19792d8bf3b403a4c5e8f0a689dac2 100644 --- a/services/data_process/include/utils/image_common_type.h +++ b/services/data_process/include/utils/image_common_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline/abstract_data_process.cpp b/services/data_process/src/pipeline/abstract_data_process.cpp index 0ee2e7ccf257a562c98a148130209496f5144d2f..f74065860f7528f9fd255908e169241abc4ed59a 100644 --- a/services/data_process/src/pipeline/abstract_data_process.cpp +++ b/services/data_process/src/pipeline/abstract_data_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp index afe508fa1773028ea23b6c6872eb297c330d7f4e..1d3577d3fb8a1bd1c79670af13fe799607b3cd42 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp index ddb80e5b89434d203c2e9f804c0fb06e3c6ba7be..ea746263d121fe04624371562213e6cffb9776c2 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.cpp b/services/data_process/src/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.cpp index 3a023effc625bbfcfdc12ffd5d94c99469de2d32..a4287bc1c86fef23940c180b72850aca387cc8fc 100644 --- a/services/data_process/src/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.cpp +++ b/services/data_process/src/pipeline_node/colorspace_conversion/convert_nv12_to_nv21.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp index daadcf5f7f1b1522f635459be07eecee3fd58575..4866fb7c4ae41eb4026f21e19c3260ccec57a21f 100644 --- a/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp +++ b/services/data_process/src/pipeline_node/fpscontroller/fps_controller_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -303,7 +303,7 @@ bool FpsControllerProcess::ReduceFrameRateByUniformStrategy(int32_t incomingFrmR return isDrop; } -int32_t FpsControllerProcess::FpsControllerDone(std::vector> outputBuffers) +int32_t FpsControllerProcess::FpsControllerDone(std::vector>& outputBuffers) { if (outputBuffers.empty()) { DHLOGE("The received data buffers is empty."); diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp similarity index 91% rename from services/data_process/src/pipeline_node/multimedia_codec/decode_data_process.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp index da8a0af7326666615ef8a981c76977b0d08a65de..3833a4911871fb41ffc97476f0e0d01a6f5be4a4 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,6 +20,7 @@ #include "convert_nv12_to_nv21.h" #include "dcamera_utils_tools.h" +#include "decode_surface_listener.h" #include "decode_video_callback.h" namespace OHOS { @@ -57,21 +58,11 @@ int32_t DecodeDataProcess::InitNode() ReleaseProcessNode(); return err; } - alignedHeight_ = GetAlignedHeight(); + alignedHeight_ = GetAlignedHeight(static_cast(sourceConfig_.GetHeight())); isDecoderProcess_ = true; return DCAMERA_OK; } -int32_t DecodeDataProcess::GetAlignedHeight() -{ - int32_t alignedBits = 32; - int32_t alignedHeight = static_cast(sourceConfig_.GetHeight()); - if (alignedHeight % alignedBits != 0) { - alignedHeight = ((alignedHeight / alignedBits) + 1) * alignedBits; - } - return alignedHeight; -} - bool DecodeDataProcess::IsInDecoderRange(const VideoConfigParams& curConfig) { return (curConfig.GetWidth() >= MIN_VIDEO_WIDTH || curConfig.GetWidth() <= MAX_VIDEO_WIDTH || @@ -158,8 +149,8 @@ int32_t DecodeDataProcess::InitDecoderMetadataFormat() } metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); metadataFormat_.PutIntValue("max_input_size", MAX_YUV420_BUFFER_SIZE); - metadataFormat_.PutIntValue("width", (int32_t)sourceConfig_.GetWidth()); - metadataFormat_.PutIntValue("height", (int32_t)sourceConfig_.GetHeight()); + metadataFormat_.PutIntValue("width", static_cast(sourceConfig_.GetWidth())); + metadataFormat_.PutIntValue("height", static_cast(sourceConfig_.GetHeight())); metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); return DCAMERA_OK; } @@ -206,43 +197,94 @@ int32_t DecodeDataProcess::SetDecoderOutputSurface() return DCAMERA_OK; } -void DecodeDataProcess::ReleaseProcessNode() +int32_t DecodeDataProcess::StopVideoDecoder() { - DHLOGD("Start release [%d] node : DecodeNode.", nodeRank_); - isDecoderProcess_ = false; - if (nextDataProcess_ != nullptr) { - nextDataProcess_->ReleaseProcessNode(); + if (videoDecoder_ == nullptr) { + DHLOGE("The video decoder does not exist before StopVideoDecoder."); + return DCAMERA_BAD_VALUE; + } + + bool isSuccess = true; + int32_t ret = videoDecoder_->Flush(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder flush failed. Error type: %d.", ret); + isSuccess = isSuccess && false; + } + ret = videoDecoder_->Stop(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder stop failed. Error type: %d.", ret); + isSuccess = isSuccess && false; + } + if (!isSuccess) { + return DCAMERA_BAD_OPERATE; + } + return DCAMERA_OK; +} + +void DecodeDataProcess::ReleaseVideoDecoder() +{ + std::lock_guard lck(mtxDecoderState_); + DHLOGD("Start release videoDecoder."); + if (videoDecoder_ == nullptr) { + DHLOGE("The video decoder does not exist before ReleaseVideoDecoder."); + decodeVideoCallback_ = nullptr; + return; + } + int32_t ret = StopVideoDecoder(); + if (ret != DCAMERA_OK) { + DHLOGE("StopVideoDecoder failed."); + } + ret = videoDecoder_->Release(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder release failed. Error type: %d.", ret); + } + videoDecoder_ = nullptr; + decodeVideoCallback_ = nullptr; +} + +void DecodeDataProcess::ReleaseDecoderSurface() +{ + if (decodeConsumerSurface_ == nullptr) { + decodeProducerSurface_ = nullptr; + DHLOGE("The decode consumer surface does not exist before UnregisterConsumerListener."); + return; + } + int32_t ret = decodeConsumerSurface_->UnregisterConsumerListener(); + if (ret != SURFACE_ERROR_OK) { + DHLOGE("Unregister consumer listener failed. Error type: %d.", ret); } - if (eventBusDecode_ != nullptr && eventBusPipeline_ != nullptr) { - DHLOGD("Start release DecodeNode eventBusDecode_ and eventBusPipeline_."); - DCameraCodecEvent codecEvent(*this, std::make_shared()); + decodeConsumerSurface_ = nullptr; + decodeProducerSurface_ = nullptr; +} + +void DecodeDataProcess::ReleaseCodecEvent() +{ + DCameraCodecEvent codecEvent(*this, std::make_shared()); + if (eventBusDecode_ != nullptr) { eventBusDecode_->RemoveHandler(codecEvent.GetType(), eventBusRegHandleDecode_); + eventBusRegHandleDecode_ = nullptr; eventBusDecode_ = nullptr; + } + if (eventBusPipeline_ != nullptr) { eventBusPipeline_->RemoveHandler(codecEvent.GetType(), eventBusRegHandlePipeline2Decode_); + eventBusRegHandlePipeline2Decode_ = nullptr; eventBusPipeline_ = nullptr; } + DHLOGD("Release DecodeNode eventBusDecode and eventBusPipeline end."); +} - { - std::lock_guard lck(mtxDecoderState_); - if (videoDecoder_ != nullptr) { - DHLOGD("Start release videoDecoder."); - videoDecoder_->Flush(); - videoDecoder_->Stop(); - videoDecoder_->Release(); - videoDecoder_ = nullptr; - decodeVideoCallback_ = nullptr; - } - } - if (decodeConsumerSurface_ != nullptr) { - int32_t ret = decodeConsumerSurface_->UnregisterConsumerListener(); - if (ret != SURFACE_ERROR_OK) { - DHLOGE("Unregister consumer listener failed. Error type: %d.", ret); - } - decodeConsumerSurface_ = nullptr; - decodeProducerSurface_ = nullptr; - decodeSurfaceListener_ = nullptr; +void DecodeDataProcess::ReleaseProcessNode() +{ + DHLOGD("Start release [%d] node : DecodeNode.", nodeRank_); + isDecoderProcess_ = false; + if (nextDataProcess_ != nullptr) { + nextDataProcess_->ReleaseProcessNode(); } + ReleaseCodecEvent(); + ReleaseVideoDecoder(); + ReleaseDecoderSurface(); + processType_ = ""; std::queue> emptyBuffersQueue; inputBuffersQueue_.swap(emptyBuffersQueue); @@ -555,7 +597,7 @@ void DecodeDataProcess::PostOutputDataBuffers(std::shared_ptr& outpu DHLOGD("Send video decoder output asynchronous DCameraCodecEvents success."); } -int32_t DecodeDataProcess::DecodeDone(std::vector> outputBuffers) +int32_t DecodeDataProcess::DecodeDone(std::vector>& outputBuffers) { DHLOGD("Decoder Done."); if (outputBuffers.empty()) { @@ -681,32 +723,5 @@ VideoConfigParams DecodeDataProcess::GetTargetConfig() const { return targetConfig_; } - -void DecodeSurfaceListener::OnBufferAvailable() -{ - DHLOGD("DecodeSurfaceListener : OnBufferAvailable."); - std::shared_ptr targetDecoderNode = decodeVideoNode_.lock(); - if (targetDecoderNode == nullptr) { - DHLOGE("decodeVideoNode_ is nullptr."); - return; - } - targetDecoderNode->GetDecoderOutputBuffer(surface_); -} - -void DecodeSurfaceListener::SetSurface(const sptr& surface) -{ - surface_ = surface; -} - -void DecodeSurfaceListener::SetDecodeVideoNode(const std::weak_ptr& decodeVideoNode) -{ - decodeVideoNode_ = decodeVideoNode; -} - -DecodeSurfaceListener::~DecodeSurfaceListener() -{ - DHLOGD("DecodeSurfaceListener : ~DecodeSurfaceListener."); - surface_ = nullptr; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp similarity index 76% rename from services/data_process/src/pipeline_node/multimedia_codec/decode_data_process_common.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp index 77de79800399b974ed4373e11d9994e200d37047..a481480169d71869fc883d67c1c0a98f6022cfc4 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,6 +20,7 @@ #include "convert_nv12_to_nv21.h" #include "dcamera_utils_tools.h" +#include "decode_surface_listener.h" #include "decode_video_callback.h" namespace OHOS { @@ -57,21 +58,11 @@ int32_t DecodeDataProcess::InitNode() ReleaseProcessNode(); return err; } - alignedHeight_ = GetAlignedHeight(); + alignedHeight_ = GetAlignedHeight(static_cast(sourceConfig_.GetHeight())); isDecoderProcess_ = true; return DCAMERA_OK; } -int32_t DecodeDataProcess::GetAlignedHeight() -{ - int32_t alignedBits = 32; - int32_t alignedHeight = static_cast(sourceConfig_.GetHeight()); - if (alignedHeight % alignedBits != 0) { - alignedHeight = ((alignedHeight / alignedBits) + 1) * alignedBits; - } - return alignedHeight; -} - bool DecodeDataProcess::IsInDecoderRange(const VideoConfigParams& curConfig) { return (curConfig.GetWidth() >= MIN_VIDEO_WIDTH || curConfig.GetWidth() <= MAX_VIDEO_WIDTH || @@ -145,13 +136,11 @@ int32_t DecodeDataProcess::InitDecoderMetadataFormat() DHLOGD("Common Init video decoder metadata format."); processType_ = "video/mp4v-es"; metadataFormat_.PutStringValue("codec_mime", processType_); - - int32_t width = (int32_t)sourceConfig_.GetWidth(); - int32_t height = (int32_t)sourceConfig_.GetHeight(); + metadataFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); - metadataFormat_.PutIntValue("max_input_size", width * height * 4 * 2); - metadataFormat_.PutIntValue("width", width); - metadataFormat_.PutIntValue("height", height); + metadataFormat_.PutIntValue("max_input_size", MAX_RGB32_BUFFER_SIZE); + metadataFormat_.PutIntValue("width", static_cast(sourceConfig_.GetWidth())); + metadataFormat_.PutIntValue("height", static_cast(sourceConfig_.GetHeight())); metadataFormat_.PutIntValue("frame_rate", MAX_FRAME_RATE); return DCAMERA_OK; } @@ -198,43 +187,94 @@ int32_t DecodeDataProcess::SetDecoderOutputSurface() return DCAMERA_OK; } -void DecodeDataProcess::ReleaseProcessNode() +int32_t DecodeDataProcess::StopVideoDecoder() { - DHLOGD("Start release [%d] node : DecodeNode.", nodeRank_); - isDecoderProcess_ = false; - if (nextDataProcess_ != nullptr) { - nextDataProcess_->ReleaseProcessNode(); + if (videoDecoder_ == nullptr) { + DHLOGE("The video decoder does not exist before StopVideoDecoder."); + return DCAMERA_BAD_VALUE; } - if (eventBusDecode_ != nullptr && eventBusPipeline_ != nullptr) { - DHLOGD("Start release DecodeNode eventBusDecode_ and eventBusPipeline_."); - DCameraCodecEvent codecEvent(*this, std::make_shared()); + + bool isSuccess = true; + int32_t ret = videoDecoder_->Flush(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder flush failed. Error type: %d.", ret); + isSuccess = isSuccess && false; + } + ret = videoDecoder_->Stop(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder stop failed. Error type: %d.", ret); + isSuccess = isSuccess && false; + } + if (!isSuccess) { + return DCAMERA_BAD_OPERATE; + } + return DCAMERA_OK; +} + +void DecodeDataProcess::ReleaseVideoDecoder() +{ + std::lock_guard lck(mtxDecoderState_); + DHLOGD("Start release videoDecoder."); + if (videoDecoder_ == nullptr) { + DHLOGE("The video decoder does not exist before ReleaseVideoDecoder."); + decodeVideoCallback_ = nullptr; + return; + } + int32_t ret = StopVideoDecoder(); + if (ret != DCAMERA_OK) { + DHLOGE("StopVideoDecoder failed."); + } + ret = videoDecoder_->Release(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoDecoder release failed. Error type: %d.", ret); + } + videoDecoder_ = nullptr; + decodeVideoCallback_ = nullptr; +} + +void DecodeDataProcess::ReleaseDecoderSurface() +{ + if (decodeConsumerSurface_ == nullptr) { + decodeProducerSurface_ = nullptr; + DHLOGE("The decode consumer surface does not exist before UnregisterConsumerListener."); + return; + } + int32_t ret = decodeConsumerSurface_->UnregisterConsumerListener(); + if (ret != SURFACE_ERROR_OK) { + DHLOGE("Unregister consumer listener failed. Error type: %d.", ret); + } + decodeConsumerSurface_ = nullptr; + decodeProducerSurface_ = nullptr; +} + +void DecodeDataProcess::ReleaseCodecEvent() +{ + DCameraCodecEvent codecEvent(*this, std::make_shared()); + if (eventBusDecode_ != nullptr) { eventBusDecode_->RemoveHandler(codecEvent.GetType(), eventBusRegHandleDecode_); + eventBusRegHandleDecode_ = nullptr; eventBusDecode_ = nullptr; + } + if (eventBusPipeline_ != nullptr) { eventBusPipeline_->RemoveHandler(codecEvent.GetType(), eventBusRegHandlePipeline2Decode_); + eventBusRegHandlePipeline2Decode_ = nullptr; eventBusPipeline_ = nullptr; } + DHLOGD("Release DecodeNode eventBusDecode and eventBusPipeline end."); +} - { - std::lock_guard lck(mtxDecoderState_); - if (videoDecoder_ != nullptr) { - DHLOGD("Start release videoDecoder."); - videoDecoder_->Flush(); - videoDecoder_->Stop(); - videoDecoder_->Release(); - videoDecoder_ = nullptr; - decodeVideoCallback_ = nullptr; - } - } - if (decodeConsumerSurface_ != nullptr) { - int32_t ret = decodeConsumerSurface_->UnregisterConsumerListener(); - if (ret != SURFACE_ERROR_OK) { - DHLOGE("Unregister consumer listener failed. Error type: %d.", ret); - } - decodeConsumerSurface_ = nullptr; - decodeProducerSurface_ = nullptr; - decodeSurfaceListener_ = nullptr; +void DecodeDataProcess::ReleaseProcessNode() +{ + DHLOGD("Start release [%d] node : DecodeNode.", nodeRank_); + isDecoderProcess_ = false; + if (nextDataProcess_ != nullptr) { + nextDataProcess_->ReleaseProcessNode(); } + ReleaseCodecEvent(); + ReleaseVideoDecoder(); + ReleaseDecoderSurface(); + processType_ = ""; std::queue> emptyBuffersQueue; inputBuffersQueue_.swap(emptyBuffersQueue); @@ -268,8 +308,7 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& DHLOGE("video decoder input buffers queue over flow."); return DCAMERA_INDEX_OVERFLOW; } - int32_t bufferSize = 1920 * 1808 * 4 * 2; - if (inputBuffers[0]->Size() > bufferSize) { + if (inputBuffers[0]->Size() > MAX_RGB32_BUFFER_SIZE) { DHLOGE("DecodeNode input buffer size %d error.", inputBuffers[0]->Size()); return DCAMERA_MEMORY_OPT_ERROR; } @@ -405,7 +444,8 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int6 DHLOGE("surface buffer is null!"); return; } - size_t validDecodedImageSize = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * 4); + size_t validDecodedImageSize = static_cast(sourceConfig_.GetWidth() * sourceConfig_.GetHeight() * + RGB32_MEMORY_COEFFICIENT); size_t surfaceBufSize = static_cast(surBuf->GetSize()); if (validDecodedImageSize > surfaceBufSize) { DHLOGE("Buffer size error, validDecodedImageSize %d, surBufSize %d.", @@ -428,90 +468,6 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int6 PostOutputDataBuffers(bufferOutput); } -int32_t DecodeDataProcess::CopyYUVPlaneByRow(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo) -{ - int32_t ret = CheckCopyImageInfo(srcImgInfo, dstImgInfo); - if (ret != DCAMERA_OK) { - DHLOGE("Check CopyImageUnitInfo failed."); - return ret; - } - errno_t err = EOK; - int32_t srcDataOffset = 0; - int32_t dstDataOffset = 0; - for (int32_t yh = 0; yh < dstImgInfo.height; yh++) { - err = memcpy_s(dstImgInfo.imgData + dstDataOffset, dstImgInfo.chromaOffset - dstDataOffset, - srcImgInfo.imgData + srcDataOffset, dstImgInfo.width); - if (err != EOK) { - DHLOGE("memcpy_s YPlane in line[%d] failed.", yh); - return DCAMERA_MEMORY_OPT_ERROR; - } - dstDataOffset += dstImgInfo.alignedWidth; - srcDataOffset += srcImgInfo.alignedWidth; - } - DHLOGD("Copy Yplane end, dstDataOffset %d, srcDataOffset %d, validYPlaneSize %d.", - dstDataOffset, srcDataOffset, dstImgInfo.chromaOffset); - - int32_t y2UvRatio = 2; - dstDataOffset = dstImgInfo.chromaOffset; - srcDataOffset = srcImgInfo.chromaOffset; - for (int32_t uvh = 0; uvh < dstImgInfo.height / y2UvRatio; uvh++) { - err = memcpy_s(dstImgInfo.imgData + dstDataOffset, dstImgInfo.imgSize - dstDataOffset, - srcImgInfo.imgData + srcDataOffset, dstImgInfo.width); - if (err != EOK) { - DHLOGE("memcpy_s UVPlane in line[%d] failed.", uvh); - return DCAMERA_MEMORY_OPT_ERROR; - } - dstDataOffset += dstImgInfo.alignedWidth; - srcDataOffset += srcImgInfo.alignedWidth; - } - DHLOGD("Copy UVplane end, dstDataOffset %d, srcDataOffset %d.", dstDataOffset, srcDataOffset); - return DCAMERA_OK; -} - -int32_t DecodeDataProcess::CheckCopyImageInfo(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo) -{ - if (srcImgInfo.imgData == nullptr || dstImgInfo.imgData == nullptr) { - DHLOGE("The imgData of srcImgInfo or the imgData of dstImgInfo are null!"); - return DCAMERA_BAD_VALUE; - } - if (srcImgInfo.colorFormat != dstImgInfo.colorFormat) { - DHLOGE("CopyInfo error : srcImgInfo colorFormat %d, dstImgInfo colorFormat %d.", - srcImgInfo.colorFormat, dstImgInfo.colorFormat); - return DCAMERA_BAD_VALUE; - } - - if (!IsCorrectImageUnitInfo(srcImgInfo)) { - DHLOGE("srcImginfo fail: width %d, height %d, alignedWidth %d, alignedHeight %d, chromaOffset %lld, " + - "imgSize %lld.", srcImgInfo.width, srcImgInfo.height, srcImgInfo.alignedWidth, srcImgInfo.alignedHeight, - srcImgInfo.chromaOffset, srcImgInfo.imgSize); - return DCAMERA_BAD_VALUE; - } - if (!IsCorrectImageUnitInfo(dstImgInfo)) { - DHLOGE("dstImginfo fail: width %d, height %d, alignedWidth %d, alignedHeight %d, chromaOffset %lld, " + - "imgSize %lld.", dstImgInfo.width, dstImgInfo.height, dstImgInfo.alignedWidth, dstImgInfo.alignedHeight, - dstImgInfo.chromaOffset, dstImgInfo.imgSize); - return DCAMERA_BAD_VALUE; - } - - if (dstImgInfo.width > srcImgInfo.alignedWidth || dstImgInfo.height > srcImgInfo.alignedHeight) { - DHLOGE("Comparison ImgInfo fail: dstwidth %d, dstheight %d, srcAlignedWidth %d, srcAlignedHeight %d.", - dstImgInfo.width, dstImgInfo.height, srcImgInfo.alignedWidth, srcImgInfo.alignedHeight); - return DCAMERA_BAD_VALUE; - } - return DCAMERA_OK; -} - -bool DecodeDataProcess::IsCorrectImageUnitInfo(const ImageUnitInfo& imgInfo) -{ - int32_t y2UvRatio = 2; - int32_t bytesPerPixel = 3; - size_t expectedImgSize = static_cast(imgInfo.alignedWidth * imgInfo.alignedHeight * - bytesPerPixel / y2UvRatio); - size_t expectedChromaOffset = static_cast(imgInfo.alignedWidth * imgInfo.alignedHeight); - return (imgInfo.width <= imgInfo.alignedWidth && imgInfo.height <= imgInfo.alignedHeight && - imgInfo.imgSize >= expectedImgSize && imgInfo.chromaOffset == expectedChromaOffset); -} - void DecodeDataProcess::PostOutputDataBuffers(std::shared_ptr& outputBuffer) { if (eventBusDecode_ == nullptr || outputBuffer == nullptr) { @@ -527,7 +483,7 @@ void DecodeDataProcess::PostOutputDataBuffers(std::shared_ptr& outpu DHLOGD("Send video decoder output asynchronous DCameraCodecEvents success."); } -int32_t DecodeDataProcess::DecodeDone(std::vector> outputBuffers) +int32_t DecodeDataProcess::DecodeDone(std::vector>& outputBuffers) { DHLOGD("Decoder Done."); if (outputBuffers.empty()) { @@ -644,32 +600,5 @@ VideoConfigParams DecodeDataProcess::GetTargetConfig() const { return targetConfig_; } - -void DecodeSurfaceListener::OnBufferAvailable() -{ - DHLOGD("DecodeSurfaceListener : OnBufferAvailable."); - std::shared_ptr targetDecoderNode = decodeVideoNode_.lock(); - if (targetDecoderNode == nullptr) { - DHLOGE("decodeVideoNode_ is nullptr."); - return; - } - targetDecoderNode->GetDecoderOutputBuffer(surface_); -} - -void DecodeSurfaceListener::SetSurface(const sptr& surface) -{ - surface_ = surface; -} - -void DecodeSurfaceListener::SetDecodeVideoNode(const std::weak_ptr& decodeVideoNode) -{ - decodeVideoNode_ = decodeVideoNode; -} - -DecodeSurfaceListener::~DecodeSurfaceListener() -{ - DHLOGD("DecodeSurfaceListener : ~DecodeSurfaceListener."); - surface_ = nullptr; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_surface_listener.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_surface_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09fdb94dca08b9435828f5e50a09419224fedbc3 --- /dev/null +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_surface_listener.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "decode_surface_listener.h" + +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +DecodeSurfaceListener::~DecodeSurfaceListener() +{ + DHLOGD("DecodeSurfaceListener : ~DecodeSurfaceListener."); + surface_ = nullptr; +} + +void DecodeSurfaceListener::OnBufferAvailable() +{ + DHLOGD("DecodeSurfaceListener : OnBufferAvailable."); + std::shared_ptr targetDecoderNode = decodeVideoNode_.lock(); + if (targetDecoderNode == nullptr) { + DHLOGE("decodeVideoNode_ is nullptr."); + return; + } + targetDecoderNode->GetDecoderOutputBuffer(surface_); +} + +void DecodeSurfaceListener::SetSurface(const sptr& surface) +{ + surface_ = surface; +} + +void DecodeSurfaceListener::SetDecodeVideoNode(const std::weak_ptr& decodeVideoNode) +{ + decodeVideoNode_ = decodeVideoNode; +} + +sptr DecodeSurfaceListener::GetSurface() const +{ + return surface_; +} + +std::shared_ptr DecodeSurfaceListener::GetDecodeVideoNode() const +{ + std::shared_ptr targetDecoderNode = decodeVideoNode_.lock(); + if (targetDecoderNode == nullptr) { + DHLOGE("decodeVideoNode_ is nullptr."); + } + return targetDecoderNode; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decode_video_callback.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_video_callback.cpp similarity index 98% rename from services/data_process/src/pipeline_node/multimedia_codec/decode_video_callback.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_video_callback.cpp index 04b1bcc631a7ea9f348dd0f8581eb70afbb4cf98..7f718fbbc1156f88eda3aeacea601ba409dd89ab 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decode_video_callback.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_video_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp similarity index 92% rename from services/data_process/src/pipeline_node/multimedia_codec/encode_data_process.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp index 7327f30dddbd0aa8d36db09ce5a78413af528630..1be2a44e2fc46cbc8988a90dffd1ff9eade6f7f6 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -214,6 +214,49 @@ int32_t EncodeDataProcess::InitEncoderBitrateFormat() return DCAMERA_OK; } +int32_t EncodeDataProcess::StopVideoEncoder() +{ + if (videoEncoder_ == nullptr) { + DHLOGE("The video encoder does not exist before StopVideoEncoder."); + return DCAMERA_BAD_VALUE; + } + int32_t ret = videoEncoder_->Flush(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder flush failed. Error type: %d.", ret); + return DCAMERA_BAD_OPERATE; + } + ret = videoEncoder_->Stop(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder stop failed. Error type: %d.", ret); + return DCAMERA_BAD_OPERATE; + } + return DCAMERA_OK; +} + +void EncodeDataProcess::ReleaseVideoEncoder() +{ + std::lock_guard lck(mtxEncoderState_); + DHLOGD("Start release videoEncoder."); + if (videoEncoder_ == nullptr) { + DHLOGE("The video encoder does not exist before ReleaseVideoEncoder."); + encodeProducerSurface_ = nullptr; + encodeVideoCallback_ = nullptr; + return; + } + + int32_t ret = StopVideoEncoder(); + if (ret != DCAMERA_OK) { + DHLOGE("StopVideoEncoder failed."); + } + ret = videoEncoder_->Release(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder release failed. Error type: %d.", ret); + } + encodeProducerSurface_ = nullptr; + videoEncoder_ = nullptr; + encodeVideoCallback_ = nullptr; +} + void EncodeDataProcess::ReleaseProcessNode() { DHLOGD("Start release [%d] node : EncodeNode.", nodeRank_); @@ -222,18 +265,7 @@ void EncodeDataProcess::ReleaseProcessNode() nextDataProcess_->ReleaseProcessNode(); } - { - std::lock_guard lck(mtxEncoderState_); - if (videoEncoder_ != nullptr) { - DHLOGD("Start release videoEncoder."); - videoEncoder_->Flush(); - videoEncoder_->Stop(); - videoEncoder_->Release(); - encodeProducerSurface_ = nullptr; - videoEncoder_ = nullptr; - encodeVideoCallback_ = nullptr; - } - } + ReleaseVideoEncoder(); waitEncoderOutputCount_ = 0; lastFeedEncoderInputBufferTimeUs_ = 0; @@ -400,7 +432,7 @@ int32_t EncodeDataProcess::GetEncoderOutputBuffer(uint32_t index, Media::AVCodec return EncodeDone(nextInputBuffers); } -int32_t EncodeDataProcess::EncodeDone(std::vector> outputBuffers) +int32_t EncodeDataProcess::EncodeDone(std::vector>& outputBuffers) { DHLOGD("Encoder done."); if (outputBuffers.empty()) { diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp similarity index 92% rename from services/data_process/src/pipeline_node/multimedia_codec/encode_data_process_common.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp index cadc5177a41eeeec85f0fef96055d84f67445f02..57104a69fb4b2319cfd61c41e4f5719af921eeb3 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_data_process_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -192,6 +192,49 @@ int32_t EncodeDataProcess::InitEncoderBitrateFormat() return DCAMERA_OK; } +int32_t EncodeDataProcess::StopVideoEncoder() +{ + if (videoEncoder_ == nullptr) { + DHLOGE("The video encoder does not exist before StopVideoEncoder."); + return DCAMERA_BAD_VALUE; + } + int32_t ret = videoEncoder_->Flush(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder flush failed. Error type: %d.", ret); + return DCAMERA_BAD_OPERATE; + } + ret = videoEncoder_->Stop(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder stop failed. Error type: %d.", ret); + return DCAMERA_BAD_OPERATE; + } + return DCAMERA_OK; +} + +void EncodeDataProcess::ReleaseVideoEncoder() +{ + std::lock_guard lck(mtxEncoderState_); + DHLOGD("Start release videoEncoder."); + if (videoEncoder_ == nullptr) { + DHLOGE("The video encoder does not exist before ReleaseVideoEncoder."); + encodeProducerSurface_ = nullptr; + encodeVideoCallback_ = nullptr; + return; + } + + int32_t ret = StopVideoEncoder(); + if (ret != DCAMERA_OK) { + DHLOGE("StopVideoEncoder failed."); + } + ret = videoEncoder_->Release(); + if (ret != Media::MediaServiceErrCode::MSERR_OK) { + DHLOGE("VideoEncoder release failed. Error type: %d.", ret); + } + encodeProducerSurface_ = nullptr; + videoEncoder_ = nullptr; + encodeVideoCallback_ = nullptr; +} + void EncodeDataProcess::ReleaseProcessNode() { DHLOGD("Start release [%d] node : EncodeNode.", nodeRank_); @@ -200,18 +243,7 @@ void EncodeDataProcess::ReleaseProcessNode() nextDataProcess_->ReleaseProcessNode(); } - { - std::lock_guard lck(mtxEncoderState_); - if (videoEncoder_ != nullptr) { - DHLOGD("Start release videoEncoder."); - videoEncoder_->Flush(); - videoEncoder_->Stop(); - videoEncoder_->Release(); - encodeProducerSurface_ = nullptr; - videoEncoder_ = nullptr; - encodeVideoCallback_ = nullptr; - } - } + ReleaseVideoEncoder(); waitEncoderOutputCount_ = 0; lastFeedEncoderInputBufferTimeUs_ = 0; @@ -360,7 +392,7 @@ int32_t EncodeDataProcess::GetEncoderOutputBuffer(uint32_t index, Media::AVCodec return EncodeDone(nextInputBuffers); } -int32_t EncodeDataProcess::EncodeDone(std::vector> outputBuffers) +int32_t EncodeDataProcess::EncodeDone(std::vector>& outputBuffers) { DHLOGD("Encoder done."); if (outputBuffers.empty()) { diff --git a/services/data_process/src/pipeline_node/multimedia_codec/encode_video_callback.cpp b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp similarity index 98% rename from services/data_process/src/pipeline_node/multimedia_codec/encode_video_callback.cpp rename to services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp index ed3214184e47bb5fd8a8472657253458731a76ae..0990e7775282efaa838a5a65f0cf9403e50566f6 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/encode_video_callback.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/encoder/encode_video_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/data_process/src/utils/image_common_type.cpp b/services/data_process/src/utils/image_common_type.cpp index 5990cb404323966e887a3d98b2d05eb457da6af1..9cff6d050913f41c283708c89eed23e3dfd15787 100644 --- a/services/data_process/src/utils/image_common_type.cpp +++ b/services/data_process/src/utils/image_common_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at