From 3eaf3a9a64f5c2c72b33d08d3d36aa9e0012597f Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Fri, 15 Dec 2023 03:22:39 +0000 Subject: [PATCH 1/8] Media Refactor. add histreamer engine and extract common functions to media foundation. Signed-off-by: yuanjinghua Change-Id: I087fa3f3f15e544ed72f2987cc2fa4b4ab908e2e --- bundle.json | 10 - .../avplayer/media_data_source_callback.cpp | 2 +- frameworks/js/common/common_napi.h | 2 +- .../ringtone_player/ringtone_common_napi.h | 2 +- frameworks/native/soundpool/cache_buffer.cpp | 2 +- frameworks/native/soundpool/cache_buffer.h | 4 +- frameworks/native/soundpool/sound_parser.h | 2 +- interfaces/inner_api/native/BUILD.gn | 5 +- interfaces/inner_api/native/av_common.h | 2 +- .../inner_api/native/avcodec_audio_decoder.h | 4 +- .../inner_api/native/avcodec_audio_encoder.h | 4 +- interfaces/inner_api/native/avcodec_common.h | 2 +- .../inner_api/native/avcodec_video_decoder.h | 4 +- .../inner_api/native/avcodec_video_encoder.h | 4 +- .../inner_api/native/avmetadatahelper.h | 4 +- interfaces/inner_api/native/avsharedmemory.h | 75 -- interfaces/inner_api/native/format.h | 294 -------- .../inner_api/native/media_data_source.h | 71 -- .../inner_api/native/media_description.h | 2 +- interfaces/inner_api/native/player.h | 2 +- interfaces/inner_api/native/recorder.h | 2 +- services/engine/common/avcodeclist/BUILD.gn | 2 +- .../avcodeclist/avcodec_ability_singleton.h | 2 +- .../recorder_profiles_ability_singleton.h | 2 +- .../engine/gstreamer/avcodec/codec_common.h | 4 +- .../avcodec/format_processor/processor_base.h | 2 +- .../avcodec/sink_wrapper/sink_base.h | 4 +- .../sink_wrapper/sink_bytebuffer_impl.h | 2 +- .../gstreamer/avcodec/src_wrapper/src_base.h | 4 +- .../avmeta_elem_meta_collector.cpp | 2 +- .../avmeta_elem_meta_collector.h | 4 +- .../avmetadatahelper/avmeta_frame_converter.h | 2 +- services/engine/gstreamer/common/BUILD.gn | 4 +- .../common/appsrc_engine/appsrc_memory.h | 2 +- .../common/metadata/gst_meta_parser.h | 2 +- .../common/playbin_adapter/i_playbin_ctrler.h | 2 +- .../playbin_adapter/playbin_ctrler_base.cpp | 2 +- .../common/playbin_adapter/playbin_state.cpp | 2 +- services/engine/gstreamer/factory/BUILD.gn | 1 + .../gstreamer/player/player_track_parse.h | 2 +- .../gstreamer/plugins/codec/common/BUILD.gn | 1 + .../engine/gstreamer/plugins/common/BUILD.gn | 1 + .../plugins/common/gst_shmem_memory.h | 2 +- .../plugins/common/gst_shmem_pool.cpp | 2 +- .../plugins/common/gst_shmemory_wrap_memory.h | 2 +- services/engine/gstreamer/recorder/BUILD.gn | 1 + services/engine/histreamer/BUILD.gn | 45 ++ .../histreamer/avmetadatahelper/BUILD.gn | 86 +++ .../avmetadatahelper/avmetadata_collector.cpp | 141 ++++ .../avmetadatahelper/avmetadata_collector.h | 80 ++ .../avmetadatahelper_impl.cpp | 232 ++++++ .../avmetadatahelper/avmetadatahelper_impl.h | 74 ++ services/engine/histreamer/factory/BUILD.gn | 85 +++ .../histreamer/factory/engine_factory.cpp | 136 ++++ services/engine/histreamer/player/BUILD.gn | 86 +++ .../player/hiplayer_callback_looper.cpp | 214 ++++++ .../player/hiplayer_callback_looper.h | 87 +++ .../histreamer/player/hiplayer_impl.cpp | 705 ++++++++++++++++++ .../engine/histreamer/player/hiplayer_impl.h | 133 ++++ services/engine/histreamer/recorder/BUILD.gn | 82 ++ .../histreamer/recorder/hirecorder_impl.cpp | 449 +++++++++++ .../histreamer/recorder/hirecorder_impl.h | 132 ++++ .../histreamer/recorder/recorder_utils.h | 54 ++ services/include/i_avcodec_service.h | 2 +- services/include/i_avcodeclist_service.h | 2 +- services/include/i_avmetadatahelper_service.h | 2 +- services/include/i_screen_capture_service.h | 2 +- services/services/BUILD.gn | 3 +- .../avcodec/ipc/i_standard_avcodec_service.h | 2 +- .../ipc/i_standard_avcodeclist_service.h | 2 +- .../ipc/helper_listener_stub.h | 2 +- .../ipc/i_standard_avmetadatahelper_service.h | 2 +- .../services/common/avsharedmemory_ipc.cpp | 2 +- services/services/common/avsharedmemory_ipc.h | 2 +- .../services/engine_intf/i_avcodec_engine.h | 4 +- .../engine_intf/i_avcodeclist_engine.h | 4 +- .../player/ipc/player_listener_stub.h | 2 +- .../i_standard_recorder_profiles_service.h | 2 +- services/services/sa_media/ipc/media_parcel.h | 2 +- services/utils/BUILD.gn | 24 +- services/utils/avsharedmemorybase.cpp | 137 ---- services/utils/avsharedmemorypool.cpp | 2 +- services/utils/format.cpp | 346 --------- services/utils/include/avdatasrcmemory.h | 2 +- services/utils/include/avsharedmemorybase.h | 127 ---- services/utils/include/avsharedmemorypool.h | 2 +- .../avmetadatastub_fuzzer/BUILD.gn | 5 +- .../playerservicestub_fuzzer/BUILD.gn | 5 +- .../playerstub_fuzzer/BUILD.gn | 5 +- .../native/avformat/avformat_native_mock.h | 2 +- .../native/avmemory/avmemory_native_mock.h | 2 +- 91 files changed, 2902 insertions(+), 1170 deletions(-) delete mode 100644 interfaces/inner_api/native/avsharedmemory.h delete mode 100644 interfaces/inner_api/native/format.h delete mode 100644 interfaces/inner_api/native/media_data_source.h create mode 100644 services/engine/histreamer/BUILD.gn create mode 100644 services/engine/histreamer/avmetadatahelper/BUILD.gn create mode 100644 services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp create mode 100644 services/engine/histreamer/avmetadatahelper/avmetadata_collector.h create mode 100644 services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp create mode 100644 services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.h create mode 100644 services/engine/histreamer/factory/BUILD.gn create mode 100644 services/engine/histreamer/factory/engine_factory.cpp create mode 100644 services/engine/histreamer/player/BUILD.gn create mode 100644 services/engine/histreamer/player/hiplayer_callback_looper.cpp create mode 100644 services/engine/histreamer/player/hiplayer_callback_looper.h create mode 100644 services/engine/histreamer/player/hiplayer_impl.cpp create mode 100644 services/engine/histreamer/player/hiplayer_impl.h create mode 100644 services/engine/histreamer/recorder/BUILD.gn create mode 100644 services/engine/histreamer/recorder/hirecorder_impl.cpp create mode 100644 services/engine/histreamer/recorder/hirecorder_impl.h create mode 100644 services/engine/histreamer/recorder/recorder_utils.h delete mode 100644 services/utils/avsharedmemorybase.cpp delete mode 100644 services/utils/format.cpp delete mode 100644 services/utils/include/avsharedmemorybase.h diff --git a/bundle.json b/bundle.json index 729e8b506..11ef3afa5 100644 --- a/bundle.json +++ b/bundle.json @@ -90,16 +90,6 @@ ] }, "inner_kits": [ - { - "type": "so", - "name": "//foundation/multimedia/player_framework/services/utils:media_format", - "header": { - "header_files": [ - "format.h" - ], - "header_base": "//foundation/multimedia/player_framework/interfaces/inner_api/native" - } - }, { "type": "so", "name": "//foundation/multimedia/player_framework/services/utils:media_service_utils", diff --git a/frameworks/js/avplayer/media_data_source_callback.cpp b/frameworks/js/avplayer/media_data_source_callback.cpp index e41f90f9c..ab9ae27ae 100644 --- a/frameworks/js/avplayer/media_data_source_callback.cpp +++ b/frameworks/js/avplayer/media_data_source_callback.cpp @@ -14,7 +14,7 @@ */ #include "media_data_source_callback.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "media_dfx.h" #include "media_log.h" #include "media_errors.h" diff --git a/frameworks/js/common/common_napi.h b/frameworks/js/common/common_napi.h index 88d810e17..7fdf5e157 100644 --- a/frameworks/js/common/common_napi.h +++ b/frameworks/js/common/common_napi.h @@ -19,7 +19,7 @@ #include #include #include -#include "format.h" +#include "meta/format.h" #include "av_common.h" #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/frameworks/js/system_sound_manager/include/ringtone_player/ringtone_common_napi.h b/frameworks/js/system_sound_manager/include/ringtone_player/ringtone_common_napi.h index dc4fb904b..170c865b4 100644 --- a/frameworks/js/system_sound_manager/include/ringtone_player/ringtone_common_napi.h +++ b/frameworks/js/system_sound_manager/include/ringtone_player/ringtone_common_napi.h @@ -18,7 +18,7 @@ #include -#include "format.h" +#include "meta/format.h" #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/frameworks/native/soundpool/cache_buffer.cpp b/frameworks/native/soundpool/cache_buffer.cpp index a1c236f2e..4b6d5f665 100644 --- a/frameworks/native/soundpool/cache_buffer.cpp +++ b/frameworks/native/soundpool/cache_buffer.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace Media { -CacheBuffer::CacheBuffer(const MediaAVCodec::Format &trackFormat, +CacheBuffer::CacheBuffer(const Format &trackFormat, const std::deque> &cacheData, const size_t &cacheDataTotalSize, const int32_t &soundID, const int32_t &streamID) : trackFormat_(trackFormat), cacheData_(cacheData), cacheDataTotalSize_(cacheDataTotalSize), soundID_(soundID), streamID_(streamID), diff --git a/frameworks/native/soundpool/cache_buffer.h b/frameworks/native/soundpool/cache_buffer.h index 7a533b738..3e8d896ad 100644 --- a/frameworks/native/soundpool/cache_buffer.h +++ b/frameworks/native/soundpool/cache_buffer.h @@ -44,7 +44,7 @@ class CacheBuffer : public AudioStandard::AudioRendererWriteCallback, public std::enable_shared_from_this { public: - CacheBuffer(const MediaAVCodec::Format &trackFormat, + CacheBuffer(const Format &trackFormat, const std::deque> &cacheData, const size_t &cacheDataTotalSize, const int32_t &soundID, const int32_t &streamID); @@ -90,7 +90,7 @@ private: int32_t DealPlayParamsBeforePlay(const int32_t streamID, const PlayParams playParams); static AudioStandard::AudioRendererRate CheckAndAlignRendererRate(const int32_t rate); - MediaAVCodec::Format trackFormat_; + Format trackFormat_; std::deque> cacheData_; std::deque> reCombineCacheData_; size_t cacheDataTotalSize_; diff --git a/frameworks/native/soundpool/sound_parser.h b/frameworks/native/soundpool/sound_parser.h index 08e2f5139..b02ad501d 100644 --- a/frameworks/native/soundpool/sound_parser.h +++ b/frameworks/native/soundpool/sound_parser.h @@ -25,7 +25,7 @@ #include "avcodec_errors.h" #include "avdemuxer.h" #include "avsource.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "avcodec_codec_name.h" #include "cache_buffer.h" #include "isoundpool.h" diff --git a/interfaces/inner_api/native/BUILD.gn b/interfaces/inner_api/native/BUILD.gn index 7ad733f1f..584f58d4d 100644 --- a/interfaces/inner_api/native/BUILD.gn +++ b/interfaces/inner_api/native/BUILD.gn @@ -111,7 +111,6 @@ ohos_shared_library("media_client") { "$MEDIA_ROOT_DIR/services/services/sa_media/ipc/media_listener_stub.cpp", "$MEDIA_ROOT_DIR/services/services/sa_media/ipc/media_parcel.cpp", "$MEDIA_ROOT_DIR/services/services/sa_media/ipc/media_service_proxy.cpp", - "$MEDIA_ROOT_DIR/services/utils/avsharedmemorybase.cpp", ] if (multimedia_player_framework_support_player) { sources += [ @@ -172,9 +171,8 @@ ohos_shared_library("media_client") { ":media_client_ipc_config", ] - deps = [ "../../../services/utils:media_format" ] - public_configs = [ ":media_public_config" ] + deps = [ "$MEDIA_ROOT_DIR/services/utils:media_service_utils" ] external_deps = [ "audio_framework:audio_client", @@ -185,6 +183,7 @@ ohos_shared_library("media_client") { "ipc:ipc_single", "samgr:samgr_proxy", ] + public_external_deps = [ "histreamer:media_foundation" ] if (multimedia_player_framework_support_video) { external_deps += [ "graphic_2d:surface" ] diff --git a/interfaces/inner_api/native/av_common.h b/interfaces/inner_api/native/av_common.h index de9e813c2..6773b334c 100644 --- a/interfaces/inner_api/native/av_common.h +++ b/interfaces/inner_api/native/av_common.h @@ -17,7 +17,7 @@ #include #include -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/avcodec_audio_decoder.h b/interfaces/inner_api/native/avcodec_audio_decoder.h index af18f0644..8eb34f494 100644 --- a/interfaces/inner_api/native/avcodec_audio_decoder.h +++ b/interfaces/inner_api/native/avcodec_audio_decoder.h @@ -18,8 +18,8 @@ #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/avcodec_audio_encoder.h b/interfaces/inner_api/native/avcodec_audio_encoder.h index 834b70bf2..b92dc5ed3 100644 --- a/interfaces/inner_api/native/avcodec_audio_encoder.h +++ b/interfaces/inner_api/native/avcodec_audio_encoder.h @@ -18,8 +18,8 @@ #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/avcodec_common.h b/interfaces/inner_api/native/avcodec_common.h index 063d8c1ff..c65d3d66c 100644 --- a/interfaces/inner_api/native/avcodec_common.h +++ b/interfaces/inner_api/native/avcodec_common.h @@ -17,7 +17,7 @@ #include #include "av_common.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/avcodec_video_decoder.h b/interfaces/inner_api/native/avcodec_video_decoder.h index 72567866a..b4ed8636b 100644 --- a/interfaces/inner_api/native/avcodec_video_decoder.h +++ b/interfaces/inner_api/native/avcodec_video_decoder.h @@ -18,8 +18,8 @@ #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" #include "surface.h" namespace OHOS { diff --git a/interfaces/inner_api/native/avcodec_video_encoder.h b/interfaces/inner_api/native/avcodec_video_encoder.h index 506b348de..9235eed83 100644 --- a/interfaces/inner_api/native/avcodec_video_encoder.h +++ b/interfaces/inner_api/native/avcodec_video_encoder.h @@ -18,8 +18,8 @@ #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" #include "surface.h" namespace OHOS { diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index 4e6a9e8d6..1e778cc4d 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -20,8 +20,8 @@ #include #include #include -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" #include "media_data_source.h" #include "nocopyable.h" #include "pixel_map.h" diff --git a/interfaces/inner_api/native/avsharedmemory.h b/interfaces/inner_api/native/avsharedmemory.h deleted file mode 100644 index 2360a22dc..000000000 --- a/interfaces/inner_api/native/avsharedmemory.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2021 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 AVSHAREDMEMORY_H -#define AVSHAREDMEMORY_H - -#include -#include - -namespace OHOS { -namespace Media { -/** - * @brief Provides a unified interface to implement convenient memory sharing - * mechanism. For those platforms that do not support multi-process, it may - * simply encapsulate ordinary memory blocks, not really multi-process shareable memory. - */ -class AVSharedMemory { -public: - virtual ~AVSharedMemory() = default; - - /** - * @brief Enumerates the flag bits used to create a new shared memory. - */ - enum Flags : uint32_t { - /** - * This flag bit indicates that the remote process is allowed to read and write - * the shared memory. If no flags are specified, this is the default memory - * sharing policy. If the FLAGS_READ_ONLY bit is set, this flag bit is ignored. - */ - FLAGS_READ_WRITE = 0x1, - /** - * For platforms that support multiple processes, this flag bit indicates that the - * remote process can only read data in the shared memory. If this flag is not set, - * the remote process has both read and write permissions by default. Adding this - * flag does not affect the process that creates the memory, which always has the - * read and write permission on the shared memory. For platforms that do not support - * multi-processes, the memory read and write permission control capability may - * not be available. In this case, this flag is invalid. - */ - FLAGS_READ_ONLY = 0x2, - }; - - /** - * @brief Get the memory's virtual address - * @return the memory's virtual address if the memory is valid, otherwise nullptr. - */ - virtual uint8_t *GetBase() const = 0; - - /** - * @brief Get the memory's size - * @return the memory's size if the memory is valid, otherwise -1. - */ - virtual int32_t GetSize() const = 0; - - /** - * @brief Get the memory's flags set by the creator, refer to {@Flags} - * @return the memory's flags if the memory is valid, otherwise 0. - */ - virtual uint32_t GetFlags() const = 0; -}; -} // namespace Media -} // namespace OHOS -#endif // AVSHAREDMEMORY_H \ No newline at end of file diff --git a/interfaces/inner_api/native/format.h b/interfaces/inner_api/native/format.h deleted file mode 100644 index 7f91a2e6a..000000000 --- a/interfaces/inner_api/native/format.h +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (C) 2021 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 FORMAT_H -#define FORMAT_H - -#include -#include -#include - -namespace OHOS { -namespace Media { -enum FormatDataType : uint32_t { - /* None */ - FORMAT_TYPE_NONE, - /* Int32 */ - FORMAT_TYPE_INT32, - /* Int64 */ - FORMAT_TYPE_INT64, - /* Float */ - FORMAT_TYPE_FLOAT, - /* Double */ - FORMAT_TYPE_DOUBLE, - /* String */ - FORMAT_TYPE_STRING, - /* Addr */ - FORMAT_TYPE_ADDR, -}; - -struct FormatData { - FormatDataType type = FORMAT_TYPE_NONE; - union Val { - int32_t int32Val; - int64_t int64Val; - float floatVal; - double doubleVal; - } val = {0}; - std::string stringVal = ""; - uint8_t *addr = nullptr; - size_t size = 0; -}; - -class __attribute__((visibility("default"))) Format { -public: - Format() = default; - ~Format(); - - Format(const Format &rhs); - Format(Format &&rhs) noexcept; - Format &operator=(const Format &rhs); - Format &operator=(Format &&rhs) noexcept; - - /** - * @brief Sets metadata of the integer type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a 32-bit integer. - * @return Returns true if the setting is successful; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutIntValue(const std::string_view &key, int32_t value); - - /** - * @brief Sets metadata of the long integer type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a 64-bit integer. - * @return Returns true if the setting is successful; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutLongValue(const std::string_view &key, int64_t value); - - /** - * @brief Sets metadata of the single-precision floating-point type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a single-precision floating-point number. - * @return Returns true if the metadata is successfully set; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutFloatValue(const std::string_view &key, float value); - - /** - * @brief Sets metadata of the double-precision floating-point type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a double-precision floating-point number. - * @return Returns true if the setting is successful; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutDoubleValue(const std::string_view &key, double value); - - /** - * @brief Sets metadata of the string type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a string. - * @return Returns true if the metadata is successfully set; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutStringValue(const std::string_view &key, const std::string_view &value); - - /** - * @brief Sets metadata of the string type. - * - * @param key Indicates the metadata key. - * @param addr Indicates the metadata addr, which is a uint8_t *. - * @param size Indicates the metadata addr size, which is a size_t. - * @return Returns true if the metadata is successfully set; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size); - - /** - * @brief Sets metadata of the format vector type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value, which is a format vector. - * @return Returns true if the format vector is successfully set; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool PutFormatVector(const std::string_view &key, std::vector &value); - - /** - * @brief Obtains the metadata value of the integer type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a 32-bit integer. - * @return Returns true if the integer is successfully obtained; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetIntValue(const std::string_view &key, int32_t &value) const; - - /** - * @brief Obtains the metadata value of the long integer type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a 64-bit long integer. - * @return Returns true if the integer is successfully obtained; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetLongValue(const std::string_view &key, int64_t &value) const; - - /** - * @brief Obtains the metadata value of the single-precision floating-point type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a single-precision floating-point number. - * @return Returns true if the single-precision number is successfully obtained; returns - * false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetFloatValue(const std::string_view &key, float &value) const; - - /** - * @brief Obtains the metadata value of the double-precision floating-point type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a double-precision floating-point number. - * @return Returns true if the double-precision number is successfully obtained; returns - * false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetDoubleValue(const std::string_view &key, double &value) const; - - /** - * @brief Obtains the metadata value of the string type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a string. - * @return Returns true if the string is successfully obtained; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetStringValue(const std::string_view &key, std::string &value) const; - - /** - * @brief Obtains the metadata value of the string type. - * - * @param key Indicates the metadata key. - * @param addr Indicates the metadata addr to obtain, which is a uint8_t **. - * @param size Indicates the metadata addr size to obtain, which is a size_t. - * @return Returns true if the string is successfully obtained; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) const; - - /** - * @brief Obtains the metadata value of the format vector type. - * - * @param key Indicates the metadata key. - * @param value Indicates the metadata value to obtain, which is a format vector. - * @return Returns true if the format vector is successfully obtained; returns false otherwise. - * @since 1.0 - * @version 1.0 - */ - bool GetFormatVector(const std::string_view &key, std::vector &value) const; - - /** - * @brief Query whether the key exists in this Format. - * - * @param key Indicates the metadata key. - * @return true - * @return false - */ - bool ContainKey(const std::string_view &key) const; - - /** - * @brief Get the value type for the key if the key exists in this Format. - * - * @param key Indicates the metadata key. - * @return FormatDataType. If the key does not exists, return FORMAT_TYPE_NONE. - */ - FormatDataType GetValueType(const std::string_view &key) const; - - /** - * @brief Remove the key from the Format - * - * @param keys the key will be removed. - */ - void RemoveKey(const std::string_view &key); - - /** - * @brief A trick to enable the comparision between the std::string and std::string_view for - * std::map, the trick called Transparent Comparator. - * - */ - using FormatDataMap = std::map>; - - /** - * @brief Obtains the metadata map. - * - * @return Returns the map object. - * @since 1.0 - * @version 1.0 - */ - const FormatDataMap &GetFormatMap() const; - - /** - * @brief A trick to enable the comparision between the std::string and std::string_view for - * std::map, the trick called Transparent Comparator. - * - */ - using FormatVectorMap = std::map, std::less<>>; - - /** - * @brief Obtains the metadata vector map. - * - * @return Returns the map object. - * @since 1.0 - * @version 1.0 - */ - const FormatVectorMap &GetFormatVectorMap() const; - - /** - * @brief Convert the metadata map to string. - * - * @return Returns a converted string. - * @since 1.0 - * @version 1.0 - */ - std::string Stringify() const; - -private: - FormatDataMap formatMap_; - FormatVectorMap formatVecMap_; -}; -} // namespace Media -} // namespace OHOS -#endif // FORMAT_H diff --git a/interfaces/inner_api/native/media_data_source.h b/interfaces/inner_api/native/media_data_source.h deleted file mode 100644 index 8a87d4748..000000000 --- a/interfaces/inner_api/native/media_data_source.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2021 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 MEDIA_DATA_SOURCE_H_ -#define MEDIA_DATA_SOURCE_H_ - -#include "avsharedmemory.h" - -namespace OHOS { -namespace Media { -/** - * @brief Use with IMediaDataSource::ReadAt. - */ -enum MediaDataSourceError : int32_t { - /** - * use with ReadAt.the resource is cut off and player will end. - * And the player will complete buffers and return an error. - */ - SOURCE_ERROR_IO = -2, - /* use with ReadAt.the resource is eos and player will complete. */ - SOURCE_ERROR_EOF = -1, -}; - -/** - * @brief the mediaDataSource instance need set to player. - * - */ -class IMediaDataSource { -public: - virtual ~IMediaDataSource() = default; - - /** - * @brief Player use ReadAt to tell user the desired file position and length.(length is number of Bytes) - * Then usr filled the mem, and return the actual length of mem. - * @param mem The stream mem need to fill. see avsharedmemory.h. - * @param length The stream length player want to get. - * @param pos The stream pos player want get start. - * The length of the filled memory must match the actual length returned. - * @return The actual length of stream mem filled, if failed or no mem return MediaDataSourceError. - */ - virtual int32_t ReadAt(const std::shared_ptr &mem, uint32_t length, int64_t pos = -1) = 0; - - /** - * @brief Get the total size of the stream. - * If the user does not know the length of the stream, size should be assigned -1, - * player will use the datasource not seekable. - * @param size Total size of the stream. If no size set -1. - * @return MSERR_OK if ok; others if failed. see media_errors.h - */ - virtual int32_t GetSize(int64_t &size) = 0; - - // This interface has been deprecated - virtual int32_t ReadAt(int64_t pos, uint32_t length, const std::shared_ptr &mem) = 0; - // This interface has been deprecated - virtual int32_t ReadAt(uint32_t length, const std::shared_ptr &mem) = 0; -}; -} // namespace Media -} // namespace OHOS -#endif // MEDIA_DATA_SOURCE_H_ \ No newline at end of file diff --git a/interfaces/inner_api/native/media_description.h b/interfaces/inner_api/native/media_description.h index 6ab819114..c5d19049d 100644 --- a/interfaces/inner_api/native/media_description.h +++ b/interfaces/inner_api/native/media_description.h @@ -16,7 +16,7 @@ #ifndef MEDIA_DESCRIPTION_H #define MEDIA_DESCRIPTION_H -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/player.h b/interfaces/inner_api/native/player.h index d199dfa64..e557be53e 100644 --- a/interfaces/inner_api/native/player.h +++ b/interfaces/inner_api/native/player.h @@ -20,7 +20,7 @@ #ifndef SUPPORT_AUDIO_ONLY #include "surface.h" #endif -#include "format.h" +#include "meta/format.h" #include "media_data_source.h" #ifdef SUPPORT_DRM #include "foundation/multimedia/drm_framework/services/drm_service/ipc/i_keysession_service.h" diff --git a/interfaces/inner_api/native/recorder.h b/interfaces/inner_api/native/recorder.h index a2f97ae47..6eb4d0f1a 100644 --- a/interfaces/inner_api/native/recorder.h +++ b/interfaces/inner_api/native/recorder.h @@ -19,7 +19,7 @@ #include #include #include -#include "format.h" +#include "meta/format.h" #include "surface.h" #include "av_common.h" diff --git a/services/engine/common/avcodeclist/BUILD.gn b/services/engine/common/avcodeclist/BUILD.gn index e06a37335..41ab7b959 100644 --- a/services/engine/common/avcodeclist/BUILD.gn +++ b/services/engine/common/avcodeclist/BUILD.gn @@ -63,7 +63,6 @@ ohos_static_library("media_engine_common_avcodeclist") { deps = [ "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_format", "//third_party/libxml2:xml2", ] @@ -71,6 +70,7 @@ ohos_static_library("media_engine_common_avcodeclist") { "audio_framework:audio_client", "c_utils:utils", "hilog:libhilog", + "histreamer:media_foundation", ] subsystem_name = "multimedia" diff --git a/services/engine/common/avcodeclist/avcodec_ability_singleton.h b/services/engine/common/avcodeclist/avcodec_ability_singleton.h index d6289228c..86303e0e1 100644 --- a/services/engine/common/avcodeclist/avcodec_ability_singleton.h +++ b/services/engine/common/avcodeclist/avcodec_ability_singleton.h @@ -17,7 +17,7 @@ #define AVCODEABILITY_SINGLETON_H #include -#include "format.h" +#include "meta/format.h" #include "avcodec_info.h" namespace OHOS { namespace Media { diff --git a/services/engine/common/recorder_profiles/recorder_profiles_ability_singleton.h b/services/engine/common/recorder_profiles/recorder_profiles_ability_singleton.h index d10a3b744..6a7b17f0a 100644 --- a/services/engine/common/recorder_profiles/recorder_profiles_ability_singleton.h +++ b/services/engine/common/recorder_profiles/recorder_profiles_ability_singleton.h @@ -17,7 +17,7 @@ #define RECORDERPROFILESABILITY_SINGLETON_H #include -#include "format.h" +#include "meta/format.h" #include "recorder_profiles_xml_parser.h" namespace OHOS { diff --git a/services/engine/gstreamer/avcodec/codec_common.h b/services/engine/gstreamer/avcodec/codec_common.h index 9ce9b846c..1cc512661 100644 --- a/services/engine/gstreamer/avcodec/codec_common.h +++ b/services/engine/gstreamer/avcodec/codec_common.h @@ -22,8 +22,8 @@ #include "avcodec_info.h" #include "avcodec_common.h" #include "audio_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" #include "surface.h" namespace OHOS { diff --git a/services/engine/gstreamer/avcodec/format_processor/processor_base.h b/services/engine/gstreamer/avcodec/format_processor/processor_base.h index 124f4332b..eddc05f40 100644 --- a/services/engine/gstreamer/avcodec/format_processor/processor_base.h +++ b/services/engine/gstreamer/avcodec/format_processor/processor_base.h @@ -17,7 +17,7 @@ #define FORMAT_PROCESSOR_BASE_H #include "codec_common.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/services/engine/gstreamer/avcodec/sink_wrapper/sink_base.h b/services/engine/gstreamer/avcodec/sink_wrapper/sink_base.h index 5969d40e0..0b8df62bd 100644 --- a/services/engine/gstreamer/avcodec/sink_wrapper/sink_base.h +++ b/services/engine/gstreamer/avcodec/sink_wrapper/sink_base.h @@ -19,9 +19,9 @@ #include #include #include "avcodec_common.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "codec_common.h" -#include "format.h" +#include "meta/format.h" #include "i_avcodec_engine.h" #include "media_errors.h" #include "surface.h" diff --git a/services/engine/gstreamer/avcodec/sink_wrapper/sink_bytebuffer_impl.h b/services/engine/gstreamer/avcodec/sink_wrapper/sink_bytebuffer_impl.h index 40dfaf30e..717daedf0 100644 --- a/services/engine/gstreamer/avcodec/sink_wrapper/sink_bytebuffer_impl.h +++ b/services/engine/gstreamer/avcodec/sink_wrapper/sink_bytebuffer_impl.h @@ -19,7 +19,7 @@ #include "sink_base.h" #include #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "gst_shared_mem_sink.h" #include "nocopyable.h" diff --git a/services/engine/gstreamer/avcodec/src_wrapper/src_base.h b/services/engine/gstreamer/avcodec/src_wrapper/src_base.h index 8f265eedb..ddd82a9ed 100644 --- a/services/engine/gstreamer/avcodec/src_wrapper/src_base.h +++ b/services/engine/gstreamer/avcodec/src_wrapper/src_base.h @@ -19,9 +19,9 @@ #include #include #include "avcodec_common.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "codec_common.h" -#include "format.h" +#include "meta/format.h" #include "i_avcodec_engine.h" #include "media_errors.h" #include "surface.h" diff --git a/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.cpp b/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.cpp index 1a76295c4..e8dc5102d 100644 --- a/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.cpp +++ b/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.cpp @@ -17,7 +17,7 @@ #include #include #include "avmetadatahelper.h" -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" #include "av_common.h" #include "gst_meta_parser.h" #include "gst_utils.h" diff --git a/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.h b/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.h index eef428b25..4461bd673 100644 --- a/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.h +++ b/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.h @@ -24,8 +24,8 @@ #include #include #include -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" #include "nocopyable.h" namespace OHOS { diff --git a/services/engine/gstreamer/avmetadatahelper/avmeta_frame_converter.h b/services/engine/gstreamer/avmetadatahelper/avmeta_frame_converter.h index b3c820c31..8b16c1ac2 100644 --- a/services/engine/gstreamer/avmetadatahelper/avmeta_frame_converter.h +++ b/services/engine/gstreamer/avmetadatahelper/avmeta_frame_converter.h @@ -20,7 +20,7 @@ #include #include #include "i_avmetadatahelper_service.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "inner_msg_define.h" #include "gst_mem_sink.h" #include "gst_msg_processor.h" diff --git a/services/engine/gstreamer/common/BUILD.gn b/services/engine/gstreamer/common/BUILD.gn index a8c186cd5..32c574264 100644 --- a/services/engine/gstreamer/common/BUILD.gn +++ b/services/engine/gstreamer/common/BUILD.gn @@ -90,7 +90,6 @@ ohos_static_library("media_engine_gst_common") { ":media_gst_dfx", "../plugins/common:gst_media_common", "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_format", "//foundation/multimedia/player_framework/services/utils:media_service_utils", "//third_party/glib:glib", "//third_party/glib:gobject", @@ -103,6 +102,7 @@ ohos_static_library("media_engine_gst_common") { "c_utils:utils", "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", "ipc:ipc_single", ] @@ -171,7 +171,6 @@ ohos_static_library("media_gst_dfx") { deps = [ "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_format", "//third_party/glib:glib", "//third_party/glib:gobject", "//third_party/gstreamer/gstreamer:gstreamer", @@ -180,6 +179,7 @@ ohos_static_library("media_gst_dfx") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", ] diff --git a/services/engine/gstreamer/common/appsrc_engine/appsrc_memory.h b/services/engine/gstreamer/common/appsrc_engine/appsrc_memory.h index 1a0cc7b06..635253623 100644 --- a/services/engine/gstreamer/common/appsrc_engine/appsrc_memory.h +++ b/services/engine/gstreamer/common/appsrc_engine/appsrc_memory.h @@ -17,7 +17,7 @@ #define APPSRC_MEMORY_H #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "nocopyable.h" namespace OHOS { diff --git a/services/engine/gstreamer/common/metadata/gst_meta_parser.h b/services/engine/gstreamer/common/metadata/gst_meta_parser.h index 301aa78f3..272d30754 100644 --- a/services/engine/gstreamer/common/metadata/gst_meta_parser.h +++ b/services/engine/gstreamer/common/metadata/gst_meta_parser.h @@ -19,7 +19,7 @@ #include #include #include -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/services/engine/gstreamer/common/playbin_adapter/i_playbin_ctrler.h b/services/engine/gstreamer/common/playbin_adapter/i_playbin_ctrler.h index a5885919b..1de25a0a4 100644 --- a/services/engine/gstreamer/common/playbin_adapter/i_playbin_ctrler.h +++ b/services/engine/gstreamer/common/playbin_adapter/i_playbin_ctrler.h @@ -23,7 +23,7 @@ #include "playbin_msg_define.h" #include "playbin_sink_provider.h" #include "gst_appsrc_engine.h" -#include "format.h" +#include "meta/format.h" #ifdef SUPPORT_DRM #include "i_keysession_service.h" #include "i_mediadecryptmodule_service.h" diff --git a/services/engine/gstreamer/common/playbin_adapter/playbin_ctrler_base.cpp b/services/engine/gstreamer/common/playbin_adapter/playbin_ctrler_base.cpp index 0f996c2e8..a8d725f4f 100644 --- a/services/engine/gstreamer/common/playbin_adapter/playbin_ctrler_base.cpp +++ b/services/engine/gstreamer/common/playbin_adapter/playbin_ctrler_base.cpp @@ -21,7 +21,7 @@ #include "media_errors.h" #include "media_log.h" #include "player.h" -#include "format.h" +#include "meta/format.h" #include "uri_helper.h" #include "scope_guard.h" #include "playbin_state.h" diff --git a/services/engine/gstreamer/common/playbin_adapter/playbin_state.cpp b/services/engine/gstreamer/common/playbin_adapter/playbin_state.cpp index ffe98261e..3a6e0aebf 100644 --- a/services/engine/gstreamer/common/playbin_adapter/playbin_state.cpp +++ b/services/engine/gstreamer/common/playbin_adapter/playbin_state.cpp @@ -19,7 +19,7 @@ #include "media_errors.h" #include "media_log.h" #include "dumper.h" -#include "format.h" +#include "meta/format.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "PlayBinState"}; diff --git a/services/engine/gstreamer/factory/BUILD.gn b/services/engine/gstreamer/factory/BUILD.gn index c583f6f9b..ba9011663 100644 --- a/services/engine/gstreamer/factory/BUILD.gn +++ b/services/engine/gstreamer/factory/BUILD.gn @@ -83,6 +83,7 @@ ohos_static_library("media_engine_gst_factory") { "c_utils:utils", "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", "image_framework:image_native", ] diff --git a/services/engine/gstreamer/player/player_track_parse.h b/services/engine/gstreamer/player/player_track_parse.h index 7e830f766..426a2e6ea 100644 --- a/services/engine/gstreamer/player/player_track_parse.h +++ b/services/engine/gstreamer/player/player_track_parse.h @@ -23,7 +23,7 @@ #include #include #include -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/services/engine/gstreamer/plugins/codec/common/BUILD.gn b/services/engine/gstreamer/plugins/codec/common/BUILD.gn index 2be1aa745..94eb18909 100644 --- a/services/engine/gstreamer/plugins/codec/common/BUILD.gn +++ b/services/engine/gstreamer/plugins/codec/common/BUILD.gn @@ -89,6 +89,7 @@ ohos_static_library("gst_codec_plugins_common") { "c_utils:utils", "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", ] diff --git a/services/engine/gstreamer/plugins/common/BUILD.gn b/services/engine/gstreamer/plugins/common/BUILD.gn index ff76be33c..83e8e8ebb 100644 --- a/services/engine/gstreamer/plugins/common/BUILD.gn +++ b/services/engine/gstreamer/plugins/common/BUILD.gn @@ -102,6 +102,7 @@ ohos_shared_library("gst_media_common") { "graphic_2d:surface", "graphic_2d:sync_fence", "hilog:libhilog", + "histreamer:media_foundation", ] subsystem_name = "multimedia" diff --git a/services/engine/gstreamer/plugins/common/gst_shmem_memory.h b/services/engine/gstreamer/plugins/common/gst_shmem_memory.h index 2c83c19cd..f178f5fda 100644 --- a/services/engine/gstreamer/plugins/common/gst_shmem_memory.h +++ b/services/engine/gstreamer/plugins/common/gst_shmem_memory.h @@ -17,7 +17,7 @@ #define GST_SHMEM_MEMORY_H #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" typedef struct _GstShMemMemory GstShMemMemory; diff --git a/services/engine/gstreamer/plugins/common/gst_shmem_pool.cpp b/services/engine/gstreamer/plugins/common/gst_shmem_pool.cpp index a78421d80..da384d688 100644 --- a/services/engine/gstreamer/plugins/common/gst_shmem_pool.cpp +++ b/services/engine/gstreamer/plugins/common/gst_shmem_pool.cpp @@ -19,7 +19,7 @@ #include "media_log.h" #include "media_errors.h" #include "buffer_type_meta.h" -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" #include "scope_guard.h" using namespace OHOS; diff --git a/services/engine/gstreamer/plugins/common/gst_shmemory_wrap_memory.h b/services/engine/gstreamer/plugins/common/gst_shmemory_wrap_memory.h index 0ddaa6811..f33ce0269 100644 --- a/services/engine/gstreamer/plugins/common/gst_shmemory_wrap_memory.h +++ b/services/engine/gstreamer/plugins/common/gst_shmemory_wrap_memory.h @@ -18,7 +18,7 @@ #include #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" struct _GstShMemoryWrapMemory; using GstShMemoryWrapMemory = _GstShMemoryWrapMemory; diff --git a/services/engine/gstreamer/recorder/BUILD.gn b/services/engine/gstreamer/recorder/BUILD.gn index 649d47c94..b984e5ffd 100644 --- a/services/engine/gstreamer/recorder/BUILD.gn +++ b/services/engine/gstreamer/recorder/BUILD.gn @@ -92,6 +92,7 @@ ohos_static_library("media_engine_gst_recorder") { external_deps = [ "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", ] subsystem_name = "multimedia" diff --git a/services/engine/histreamer/BUILD.gn b/services/engine/histreamer/BUILD.gn new file mode 100644 index 000000000..c79cba1ff --- /dev/null +++ b/services/engine/histreamer/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (C) 2021 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. + +import("//build/ohos.gni") +import("//foundation/multimedia/player_framework/config.gni") + +group("media_engine_histreamer_package") { + deps = [ ":media_engine_histreamer" ] +} + +ohos_shared_library("media_engine_histreamer") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + deps = [ "factory:media_engine_histreamer_factory" ] + + if (multimedia_player_framework_support_recorder) { + deps += [ "recorder:media_engine_histreamer_recorder" ] + } + + if (multimedia_player_framework_support_player) { + deps += [ "player:media_engine_histreamer_player" ] + } + + if (multimedia_player_framework_support_metadata) { + deps += [ "avmetadatahelper:media_engine_histreamer_avmetadatahelper" ] + } + + relative_install_dir = "media" + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/services/engine/histreamer/avmetadatahelper/BUILD.gn b/services/engine/histreamer/avmetadatahelper/BUILD.gn new file mode 100644 index 000000000..e3137ad5b --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (C) 2023 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. + +import("//build/ohos.gni") + +config("media_engine_histreamer_avmetadatahelper_config") { + visibility = [ ":*" ] + + defines = [ + "HST_ANY_WITH_NO_RTTI", + "MEDIA_OHOS", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "//foundation/multimedia/player_framework/services/engine/histreamer/avmetadatahelper", + "//foundation/multimedia/player_framework/services/include", + "//foundation/multimedia/player_framework/services/utils/include", + "//foundation/multimedia/player_framework/interfaces/inner_api/native", + "//foundation/multimedia/player_framework/services/services/engine_intf", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/histreamer/interface/inner_api", + "//foundation/multimedia/av_codec/interfaces/inner_api/native", + "//foundation/multimedia/av_codec/interfaces", + "//foundation/multimedia/av_codec/services/media_engine/modules", + ] +} + +ohos_static_library("media_engine_histreamer_avmetadatahelper") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ + "avmetadata_collector.cpp", + "avmetadatahelper_impl.cpp", + ] + + configs = [ + ":media_engine_histreamer_avmetadatahelper_config", + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", + "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + ] + + deps = [ + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", + "//foundation/multimedia/player_framework/services/utils:media_service_utils", + ] + + external_deps = [ + "av_codec:av_codec_media_engine_filters", + "av_codec:av_codec_media_engine_modules", + "c_utils:utils", + "graphic_2d:surface", + "graphic_2d:sync_fence", + "hilog:libhilog", + "histreamer:media_foundation", + "image_framework:image_native", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp new file mode 100644 index 000000000..340116e9a --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2023 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 "avmetadata_collector.h" +#include +#include "meta/video_types.h" + +namespace OHOS { +namespace Media { +#define AVMETA_KEY_TO_X_MAP_ITEM(key, innerKey) { key, innerKey } + +static const std::unordered_map AVMETA_KEY_TO_X_MAP = { + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ALBUM, Tag::MEDIA_ALBUM), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ALBUM_ARTIST, Tag::MEDIA_ALBUM_ARTIST), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ARTIST, Tag::MEDIA_ARTIST), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_AUTHOR, Tag::MEDIA_AUTHOR), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_COMPOSER, Tag::MEDIA_COMPOSER), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DATE_TIME, Tag::MEDIA_DATE), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DATE_TIME_FORMAT, ""), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DURATION, Tag::MEDIA_DURATION), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_GENRE, Tag::MEDIA_GENRE), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_HAS_AUDIO, Tag::MEDIA_HAS_AUDIO), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_HAS_VIDEO, Tag::MEDIA_HAS_VIDEO), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_MIME_TYPE, Tag::MIME_TYPE), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_NUM_TRACKS, Tag::MEDIA_TRACK_COUNT), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_SAMPLE_RATE, Tag::AUDIO_SAMPLE_RATE), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_TITLE, Tag::MEDIA_TITLE), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_HEIGHT, Tag::VIDEO_HEIGHT), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_WIDTH, Tag::VIDEO_WIDTH), + AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_ORIENTATION, Tag::VIDEO_ROTATION), +}; + +AVMetaDataCollector::AVMetaDataCollector() +{ + MEDIA_LOG_D("enter ctor, instance: 0x%{public}06" PRIXPTR "", FAKE_POINTER(this)); +} + +AVMetaDataCollector::~AVMetaDataCollector() +{ + MEDIA_LOG_D("enter dtor, instance: 0x%{public}06" PRIXPTR "", FAKE_POINTER(this)); +} + +std::unordered_map AVMetaDataCollector::GetMetadata(const std::shared_ptr &globalInfo, + const std::vector> &trackInfos) +{ + FALSE_RETURN_V_MSG_E(globalInfo != nullptr && trackInfos.size() != 0, {}, "globalInfo or trackInfos are invalid."); + std::vector keys; + globalInfo->GetKeys(keys); + for (int32_t i = 0; i < keys.size(); i++) { + std::string strVal; + int32_t intVal; + if (globalInfo->GetData(keys[i], strVal)) { + MEDIA_LOG_I("globalMeta, key: %{public}s, val: %{public}s", keys[i].c_str(), strVal.c_str()); + } else { + globalInfo->GetData(keys[i], intVal); + MEDIA_LOG_I("globalMeta, key: %{public}s, val: %{public}d", keys[i].c_str(), intVal); + } + } + + Metadata metadata; + ConvertToAVMeta(globalInfo, metadata); + + size_t trackCount = trackInfos.size(); + for (size_t index = 0; index < trackCount; index++) { + std::shared_ptr meta = trackInfos[index]; + if (meta == nullptr) { + MEDIA_LOG_E("meta is invalid, index: %zu", index); + return metadata.tbl_; + } + + Plugin::MediaType mediaType; + if (!meta->GetData(Tag::MEDIA_TYPE, mediaType)) { + MEDIA_LOG_E("mediaType not found, index: %zu", index); + return metadata.tbl_; + } + + ConvertToAVMeta(meta, metadata); + } + MEDIA_LOG_I("fetch meta data map size: %{public}d", metadata.tbl_.size()); + auto it = metadata.tbl_.begin(); + while (it != metadata.tbl_.end()) { + MEDIA_LOG_I("metadata tbl, key: %{public}d, keyName: %{public}s, val: %{public}s", it->first, + AVMETA_KEY_TO_X_MAP.find(it->first)->second.c_str(), it->second.c_str()); + it++; + } + return metadata.tbl_; +} + +void AVMetaDataCollector::ConvertToAVMeta(const std::shared_ptr &innerMeta, Metadata &avmeta) const +{ + for (const auto &[avKey, innerKey] : AVMETA_KEY_TO_X_MAP) { + if (innerKey.compare("") == 0) { + continue; + } + + if (innerKey.compare(Tag::MIME_TYPE) == 0) { // only need the file mime type + continue; + } + + Any type = OHOS::Media::GetDefaultAnyValue(innerKey); + if (Any::IsSameTypeWith(type)) { + int32_t intVal; + if (innerMeta->GetData(innerKey, intVal)) { + avmeta.SetMeta(avKey, std::to_string(intVal)); + MEDIA_LOG_I("found innerKey: %{public}d, val: %{public}d", avKey, intVal); + } + } else if (Any::IsSameTypeWith(type)) { + std::string strVal; + if (innerMeta->GetData(innerKey, strVal)) { + avmeta.SetMeta(avKey, strVal); + MEDIA_LOG_I("found innerKey: %{public}d, val: %{public}s", avKey, strVal.c_str()); + } + } else if (Any::IsSameTypeWith(type)) { + Plugin::VideoRotation rotation; + if (innerMeta->GetData(innerKey, rotation)) { + avmeta.SetMeta(avKey, std::to_string(rotation)); + } + } else if (Any::IsSameTypeWith(type)) { + int64_t duration; + if (innerMeta->GetData(innerKey, duration)) { + avmeta.SetMeta(avKey, std::to_string(duration)); + } + } else { + MEDIA_LOG_E("not found type matched with innerKey: %{public}s", innerKey.c_str()); + } + } +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h new file mode 100644 index 000000000..5b1de3d81 --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2023 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 AVMETA_DATA_COLLECTOR_H +#define AVMETA_DATA_COLLECTOR_H + +#include +#include +#include +#include +#include +#include "media_errors.h" +#include "common/log.h" +#include "meta/media_types.h" +#include "meta/meta.h" +#include "meta/meta_key.h" +#include "avmetadatahelper.h" + +namespace OHOS { +namespace Media { +struct Metadata { + Metadata() = default; + ~Metadata() = default; + + void SetMeta(int32_t key, const std::string &value) + { + tbl_[key] = value; + } + + bool TryGetMeta(int32_t key, std::string &value) const + { + auto it = tbl_.find(key); + if (it == tbl_.end()) { + return false; + } + value = it->second; + return true; + } + + bool HasMeta(int32_t key) const + { + return tbl_.count(key) != 0; + } + + std::string GetMeta(int32_t key) const + { + if (tbl_.count(key) != 0) { + return tbl_.at(key); + } + return ""; + } + + std::unordered_map tbl_; +}; + +class AVMetaDataCollector : public NoCopyable { +public: + AVMetaDataCollector(); + ~AVMetaDataCollector(); + + std::unordered_map GetMetadata(const std::shared_ptr &globalInfo, + const std::vector> &trackInfos); + + void ConvertToAVMeta(const std::shared_ptr &innerMeta, Metadata &avmeta) const; +}; +} // namespace Media +} // namespace OHOS +#endif // AVMETA_DATA_COLLECTOR_H \ No newline at end of file diff --git a/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp new file mode 100644 index 000000000..e033e652b --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2023 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 "avmetadatahelper_impl.h" +#include "media_errors.h" +#include "common/log.h" +#include "common/media_source.h" +#include "uri_helper.h" +#include "meta/meta.h" +#include "meta/meta_key.h" + +namespace OHOS { +namespace Media { +static const std::set SUPPORTED_PIXELFORMAT = { + PixelFormat::RGB_565, PixelFormat::RGB_888, PixelFormat::RGBA_8888 +}; + +class HelperEventReceiver : public Pipeline::EventReceiver { +public: + HelperEventReceiver(AVMetadataHelperImpl* helperImpl) { + helperImpl_ = helperImpl; + } + + void OnEvent(const Event &event) { + helperImpl_->OnEvent(event); + } + +private: + AVMetadataHelperImpl* helperImpl_; +}; + +class HelperFilterCallback : public Pipeline::FilterCallback { +public: + HelperFilterCallback(AVMetadataHelperImpl* helperImpl) { + helperImpl_ = helperImpl; + } + + void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) { + helperImpl_->OnCallback(filter, cmd, outType); + } + +private: + AVMetadataHelperImpl* helperImpl_; +}; + +void AVMetadataHelperImpl::OnEvent(const Event &event) +{ +} + +void AVMetadataHelperImpl::OnCallback(std::shared_ptr filter, +const Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) +{ +} + +AVMetadataHelperImpl::AVMetadataHelperImpl() +{ + MEDIA_LOG_I("enter AVMetadataHelperImpl, instance: 0x%{public}06" PRIXPTR "", FAKE_POINTER(this)); + metaCollector_ = std::make_shared(); +} + +AVMetadataHelperImpl::~AVMetadataHelperImpl() +{ + MEDIA_LOG_I("enter ~AVMetadataHelperImpl, instance: 0x%{public}06" PRIXPTR "", FAKE_POINTER(this)); + Reset(); +} + +int32_t AVMetadataHelperImpl::SetSource(const std::string &uri, int32_t usage) +{ + if ((usage != AVMetadataUsage::AV_META_USAGE_META_ONLY) && + (usage != AVMetadataUsage::AV_META_USAGE_PIXEL_MAP)) { + MEDIA_LOG_E("Invalid avmetadatahelper usage: %{public}d", usage); + return MSERR_INVALID_VAL; + } + UriHelper uriHelper(uri); + if (uriHelper.UriType() != UriHelper::URI_TYPE_FILE && uriHelper.UriType() != UriHelper::URI_TYPE_FD) { + MEDIA_LOG_E("Unsupported uri type : %{public}s", uri.c_str()); + return MSERR_UNSUPPORT; + } + + usage_ = usage; + MEDIA_LOG_I("uri: %{public}s, usage: %{public}d", uri.c_str(), usage); + + if (usage == AVMetadataUsage::AV_META_USAGE_PIXEL_MAP) { + pipeline_ = std::make_shared(); + demuxerFilter_ = Pipeline::FilterFactory::Instance().CreateFilter("builtin.player.demuxer", + Pipeline::FilterType::FILTERTYPE_DEMUXER); + FALSE_RETURN_V(demuxerFilter_ != nullptr, MSERR_INVALID_VAL); + + std::shared_ptr eventReceiver = std::make_shared( + this); + std::shared_ptr filterCallback = std::make_shared( + this); + pipeline_->Init(eventReceiver, filterCallback); + videoDecoderFilter_ = Pipeline::FilterFactory::Instance().CreateFilter("builtin.player.videodecoder", + Pipeline::FilterType::FILTERTYPE_VDEC); + FALSE_RETURN_V(videoDecoderFilter_ != nullptr, MSERR_INVALID_VAL); + } else { + mediaDemuxer_ = std::make_shared(); + } + + Status ret = SetSourceInternel(uri, usage); + FALSE_RETURN_V_MSG_E(ret == Status::OK, MSERR_INVALID_VAL, "Failed to call SetSourceInternel"); + + MEDIA_LOG_I("set source success"); + return MSERR_OK; +} + +int32_t AVMetadataHelperImpl::SetSource(const std::shared_ptr &dataSrc) +{ + return MSERR_OK; +} + +std::string AVMetadataHelperImpl::ResolveMetadata(int32_t key) +{ + MEDIA_LOG_I("enter ResolveMetadata with key: %{public}d", key); + std::string result; + + int32_t ret = ExtractMetadata(); + FALSE_RETURN_V_MSG_E(ret == MSERR_OK, result, "Failed to call ExtractMetadata"); + + if (collectedMeta_.count(key) == 0 || collectedMeta_.at(key).empty()) { + MEDIA_LOG_E("The specified metadata %{public}d cannot be obtained from the specified stream.", key); + return result; + } + + MEDIA_LOG_I("exit ResolveMetadata with key"); + result = collectedMeta_[key]; + return result; +} + +std::unordered_map AVMetadataHelperImpl::ResolveMetadata() +{ + MEDIA_LOG_I("enter ResolveMetadata"); + + int32_t ret = ExtractMetadata(); + FALSE_RETURN_V_MSG_E(ret == MSERR_OK, {}, "Failed to call ExtractMetadata"); + + MEDIA_LOG_I("exit ResolveMetadata"); + return collectedMeta_; +} + +std::shared_ptr AVMetadataHelperImpl::FetchArtPicture() +{ + MEDIA_LOG_I("enter FetchArtPicture"); + return nullptr; +} + +std::shared_ptr AVMetadataHelperImpl::FetchFrameAtTime( + int64_t /* timeUs */, int32_t /* option */, const OutputConfiguration &/* param */) +{ + MEDIA_LOG_I("enter FetchFrameAtTime"); + return nullptr; +} + +Status AVMetadataHelperImpl::SetSourceInternel(const std::string &uri, int32_t usage) +{ + Reset(); + + Status ret; + if (usage_ == AVMetadataUsage::AV_META_USAGE_PIXEL_MAP) { + ret = demuxerFilter_->SetDataSource(std::make_shared(uri)); + } else { + ret = mediaDemuxer_->SetDataSource(std::make_shared(uri)); + } + FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "Failed to call SetDataSource"); + + ret = PrepareInternel(); + FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "Failed to call PrepareInternel"); + + return Status::OK; +} + +Status AVMetadataHelperImpl::PrepareInternel() +{ + Status ret = Status::OK; + if (usage_ == AVMetadataUsage::AV_META_USAGE_PIXEL_MAP) { + FALSE_RETURN_V_MSG_E(demuxerFilter_ != nullptr, Status::ERROR_INVALID_OPERATION, "set source firstly"); + ret = demuxerFilter_->Prepare(); + } + FALSE_RETURN_V_MSG_E(ret == Status::OK, Status::ERROR_INVALID_DATA, "prepare failed"); + return Status::OK; +} + +int32_t AVMetadataHelperImpl::ExtractMetadata() +{ + FALSE_RETURN_V_MSG_E(usage_ != AVMetadataUsage::AV_META_USAGE_PIXEL_MAP, MSERR_INVALID_OPERATION, "usage error"); + FALSE_RETURN_V_MSG_E(mediaDemuxer_ != nullptr, MSERR_INVALID_OPERATION, "mediaDemuxer_ is nullptr"); + + if (!hasCollectMeta_) { + const std::shared_ptr globalInfo = mediaDemuxer_->GetGlobalMetaInfo(); + const std::vector> trackInfos = mediaDemuxer_->GetStreamMetaInfo(); + collectedMeta_ = metaCollector_->GetMetadata(globalInfo, trackInfos); + hasCollectMeta_ = true; + } + return MSERR_OK; +} + +void AVMetadataHelperImpl::Reset() +{ + std::unique_lock lock(mutex_); + + if (demuxerFilter_ != nullptr) { + demuxerFilter_->Stop(); + hasCollectMeta_ = false; + } + + if (demuxerFilter_ != nullptr) { + demuxerFilter_->Reset(); + } + + if (mediaDemuxer_ != nullptr) { + mediaDemuxer_->Reset(); + } + + errHappened_ = false; + + firstFetch_ = true; +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.h b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.h new file mode 100644 index 000000000..7d6aaa22b --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2023 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 AVMETADATAHELPER_HST_IMPL_H +#define AVMETADATAHELPER_HST_IMPL_H + +#include +#include +#include "nocopyable.h" +#include "i_avmetadatahelper_service.h" +#include "i_avmetadatahelper_engine.h" +#include "common/status.h" +#include "pipeline/pipeline.h" +#include "filter/filter_factory.h" +#include "demuxer_filter.h" +#include "media_demuxer.h" +#include "codec_filter.h" +#include "avmetadata_collector.h" + +namespace OHOS { +namespace Media { +class AVMetadataHelperImpl : public IAVMetadataHelperEngine, public NoCopyable { +public: + AVMetadataHelperImpl(); + ~AVMetadataHelperImpl(); + + int32_t SetSource(const std::string &uri, int32_t usage) override; + int32_t SetSource(const std::shared_ptr &dataSrc) override; + std::string ResolveMetadata(int32_t key) override; + std::unordered_map ResolveMetadata() override; + std::shared_ptr FetchFrameAtTime( + int64_t timeUs, int32_t option, const OutputConfiguration ¶m) override; + std::shared_ptr FetchArtPicture() override; + + void OnEvent(const Event &event); + void OnCallback(std::shared_ptr filter, + const OHOS::Media::Pipeline::FilterCallBackCommand cmd, OHOS::Media::Pipeline::StreamType outType); + +private: + Status SetSourceInternel(const std::string &uri, int32_t usage); + Status PrepareInternel(); + int32_t ExtractMetadata(); + void Reset(); + + std::unordered_map collectedMeta_; + bool hasCollectMeta_ = false; + int32_t usage_ = AVMetadataUsage::AV_META_USAGE_PIXEL_MAP; + + std::mutex mutex_; + std::condition_variable cond_; + bool errHappened_ = false; + bool firstFetch_ = true; + + std::shared_ptr pipeline_; + std::shared_ptr demuxerFilter_; + std::shared_ptr videoDecoderFilter_; + std::shared_ptr mediaDemuxer_; + std::shared_ptr metaCollector_; +}; +} // namespace Media +} // namespace OHOS +#endif // AVMETADATAHELPER_HST_IMPL_H \ No newline at end of file diff --git a/services/engine/histreamer/factory/BUILD.gn b/services/engine/histreamer/factory/BUILD.gn new file mode 100644 index 000000000..bf5f6bf67 --- /dev/null +++ b/services/engine/histreamer/factory/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (C) 2021 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. + +import("//build/ohos.gni") +import("//foundation/multimedia/player_framework/config.gni") + +config("media_engine_histreamer_factory_config") { + visibility = [ ":*" ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/player_framework/services/include", + "//foundation/multimedia/player_framework/services/services/engine_intf", + "//foundation/multimedia/player_framework/services/engine/histreamer/player", + "//foundation/multimedia/player_framework/services/engine/histreamer/recorder", + "//foundation/multimedia/player_framework/services/engine/histreamer/avmetadatahelper", + "//foundation/multimedia/player_framework/services/utils/include", + "//foundation/multimedia/player_framework/interfaces/inner_api/native", + "//foundation/multimedia/histreamer/interface/inner_api", + "//foundation/multimedia/av_codec/interfaces/inner_api/native", + "//foundation/multimedia/av_codec/interfaces", + "//foundation/multimedia/histreamer/src", + "//foundation/multimedia/av_codec/services/media_engine/modules/source/audio_capture", + "//foundation/multimedia/av_codec/services/media_engine/modules/", + ] + defines = [ + "HST_ANY_WITH_NO_RTTI", + "MEDIA_OHOS", + ] + defines += player_framework_defines +} + +ohos_static_library("media_engine_histreamer_factory") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "engine_factory.cpp" ] + + configs = [ + ":media_engine_histreamer_factory_config", + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", + ] + + deps = [ "../../../dfx:media_service_log_dfx" ] + + external_deps = [ + "audio_framework:audio_client", + "av_codec:av_codec_media_engine_filters", + "av_codec:av_codec_media_engine_modules", + "c_utils:utils", + "graphic_2d:surface", + "graphic_2d:sync_fence", + "hilog:libhilog", + "histreamer:media_foundation", + "image_framework:image_native", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/services/engine/histreamer/factory/engine_factory.cpp b/services/engine/histreamer/factory/engine_factory.cpp new file mode 100644 index 000000000..36a6deea1 --- /dev/null +++ b/services/engine/histreamer/factory/engine_factory.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2021-2021 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 HISTREAMER_HST_ENGINE_FACTORY_H +#define HISTREAMER_HST_ENGINE_FACTORY_H + +#include "i_engine_factory.h" +#include "media_errors.h" +#include "common/log.h" +#include "hirecorder_impl.h" +#include "hiplayer_impl.h" +#include "avmetadatahelper_impl.h" + +namespace OHOS { +namespace Media { +class HstEngineFactory : public IEngineFactory { +public: + HstEngineFactory() = default; + ~HstEngineFactory() override = default; + + int32_t Score(Scene scene, const std::string& uri) override; +#ifdef SUPPORT_PLAYER + std::unique_ptr CreatePlayerEngine(int32_t uid = 0, int32_t pid = 0, uint32_t tokenId = 0) override; +#endif +#ifdef SUPPORT_RECORDER + std::unique_ptr CreateRecorderEngine(int32_t appUid, int32_t appPid, uint32_t appTokenId, + uint64_t appFullTokenId) override; +#endif +#ifdef SUPPORT_METADATA + std::unique_ptr CreateAVMetadataHelperEngine() override; +#endif +#ifdef SUPPORT_CODEC + std::unique_ptr CreateAVCodecEngine() override; + std::unique_ptr CreateAVCodecListEngine() override; +#endif +}; + +int32_t HstEngineFactory::Score(Scene scene, const std::string& uri) +{ + MEDIA_LOG_E("Score in"); + (void)uri; + // if (scene == Scene::SCENE_PLAYBACK || scene == Scene::SCENE_RECORDER) { + // char useHistreamer[10] = {0}; // 10 for system parameter usage + // auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer)); + // if (res == 1 && useHistreamer[0] == '1') { + // MEDIA_LOG_I("enable histreamer"); + // return MAX_SCORE; + // } + // } + return MAX_SCORE; +} + +#ifdef SUPPORT_RECORDER +std::unique_ptr HstEngineFactory::CreateRecorderEngine( + int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) +{ + MEDIA_LOG_E("CreateRecorderEngine enter."); + auto recorder = std::unique_ptr(new (std::nothrow) HiRecorderImpl( + appUid, appPid, appTokenId, appFullTokenId)); + if (recorder && recorder->Init() == 0) { + return recorder; + } + MEDIA_LOG_E("create recorder failed or recorder init failed"); + return nullptr; +} +#endif + +#ifdef SUPPORT_PLAYER +std::unique_ptr HstEngineFactory::CreatePlayerEngine(int32_t uid, int32_t pid, uint32_t tokenId) +{ + MEDIA_LOG_I("Hst CreatePlayerEngine enter."); + auto player = std::unique_ptr(new (std::nothrow) HiPlayerImpl( + uid, pid, tokenId, 0)); + if (player) { + return player; + } + MEDIA_LOG_E("create player failed"); + return nullptr; +} +#endif + +#ifdef SUPPORT_METADATA +std::unique_ptr HstEngineFactory::CreateAVMetadataHelperEngine() +{ + MEDIA_LOG_I("CreateAVMetadataHelperEngine enter."); + auto helper = std::unique_ptr(new (std::nothrow) AVMetadataHelperImpl()); + if (helper) { + return helper; + } + MEDIA_LOG_E("create AVMetadataHelperImpl failed"); + return nullptr; +} +#endif + +#ifdef SUPPORT_CODEC +std::unique_ptr HstEngineFactory::CreateAVCodecEngine() +{ + return nullptr; +} + +std::unique_ptr HstEngineFactory::CreateAVCodecListEngine() +{ + return nullptr; +} +#endif +} // namespace Media +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +#endif +__attribute__((visibility("default"))) OHOS::Media::IEngineFactory *CreateEngineFactory() +{ + // int32_t ret = OHOS::Media::GstLoader::Instance().SetUp(); + // if (ret != OHOS::Media::MSERR_OK) { + // MEDIA_LOGE("Gst Engine setup failed, ret = %{public}d", ret); + // return nullptr; + // } + return new (std::nothrow) OHOS::Media::HstEngineFactory(); +} +#ifdef __cplusplus +} +#endif +#endif // HISTREAMER_HST_ENGINE_FACTORY_H diff --git a/services/engine/histreamer/player/BUILD.gn b/services/engine/histreamer/player/BUILD.gn new file mode 100644 index 000000000..90cc74412 --- /dev/null +++ b/services/engine/histreamer/player/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (C) 2021 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. + +import("//build/ohos.gni") + +config("media_engine_histreamer_player_config") { + visibility = [ ":*" ] + + defines = [ + "HST_ANY_WITH_NO_RTTI", + "MEDIA_OHOS", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "//foundation/multimedia/player_framework/services/engine/histreamer/player", + "//foundation/multimedia/player_framework/services/utils/include", + "//foundation/multimedia/player_framework/interfaces/inner_api/native", + "//foundation/multimedia/player_framework/services/services/engine_intf", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/histreamer/interface/inner_api", + "//foundation/multimedia/av_codec/interfaces/inner_api/native", + "//foundation/multimedia/av_codec/interfaces", + "//foundation/multimedia/histreamer/src", + "//foundation/multimedia/av_codec/services/media_engine/modules/sink", + "//foundation/multimedia/av_codec/services/media_engine/modules", + ] +} + +ohos_static_library("media_engine_histreamer_player") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ + "hiplayer_callback_looper.cpp", + "hiplayer_impl.cpp", + ] + + configs = [ + ":media_engine_histreamer_player_config", + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", + "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + ] + + deps = [ + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", + "//foundation/multimedia/player_framework/services/utils:media_service_utils", + ] + + external_deps = [ + "av_codec:av_codec_media_engine_filters", + "av_codec:av_codec_media_engine_modules", + "c_utils:utils", + "graphic_2d:surface", + "graphic_2d:sync_fence", + "hilog:libhilog", + "histreamer:media_foundation", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/services/engine/histreamer/player/hiplayer_callback_looper.cpp b/services/engine/histreamer/player/hiplayer_callback_looper.cpp new file mode 100644 index 000000000..b7791f42f --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_callback_looper.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2022-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. + */ + +#define HST_LOG_TAG "CallbackLooper" + +#include "hiplayer_callback_looper.h" +#include +#include "common/log.h" +#include "osal/task/autolock.h" +//#include "foundation/utils/steady_clock.h" +//#include "media_errors.h" + +namespace OHOS { +namespace Media { +namespace { +constexpr int32_t WHAT_NONE = 0; +constexpr int32_t WHAT_MEDIA_PROGRESS = 1; +constexpr int32_t WHAT_INFO = 2; +constexpr int32_t WHAT_ERROR = 3; +} +HiPlayerCallbackLooper::HiPlayerCallbackLooper() : task_("callbackThread", OHOS::Media::TaskPriority::NORMAL) +{ + task_.RegisterJob([this] {LoopOnce();}); +} + +HiPlayerCallbackLooper::~HiPlayerCallbackLooper() +{ + Stop(); +} + +bool HiPlayerCallbackLooper::IsStarted() +{ + return taskStarted_; +} + +void HiPlayerCallbackLooper::Stop() +{ + if (taskStarted_) { + eventQueue_.Quit(); + task_.Stop(); + taskStarted_ = false; + } +} + +void HiPlayerCallbackLooper::StartWithPlayerEngineObs(const std::weak_ptr& obs) +{ + obs_ = obs; + if (!taskStarted_) { + task_.Start(); + taskStarted_ = true; + MEDIA_LOG_I("start callback looper"); + } +} +void HiPlayerCallbackLooper::SetPlayEngine(IPlayerEngine* engine) +{ + playerEngine_ = engine; +} + +void HiPlayerCallbackLooper::StartReportMediaProgress(int64_t updateIntervalMs) +{ + reportProgressIntervalMs_ = updateIntervalMs; + if (reportMediaProgress_) { // already set + return; + } + reportMediaProgress_ = true; + //eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, SteadyClock::GetCurrentTimeMs(), Plugin::Any())); +} + +void HiPlayerCallbackLooper::ManualReportMediaProgressOnce() +{ + //eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, SteadyClock::GetCurrentTimeMs(), Plugin::Any())); +} + +void HiPlayerCallbackLooper::StopReportMediaProgress() +{ + reportMediaProgress_ = false; +} + +void HiPlayerCallbackLooper::DoReportMediaProgress() +{ + auto obs = obs_.lock(); + if (obs) { + Format format; + int32_t currentPositionMs; + if (playerEngine_->GetCurrentTime(currentPositionMs) == 0) { + MEDIA_LOG_DD("EVENT_AUDIO_PROGRESS position updated: " PUBLIC_LOG_D32, currentPositionMs); + obs->OnInfo(INFO_TYPE_POSITION_UPDATE, currentPositionMs, format); + } else { + MEDIA_LOG_W("get player engine current time error"); + } + } + /*if (reportMediaProgress_) { + eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, + SteadyClock::GetCurrentTimeMs() + reportProgressIntervalMs_, Plugin::Any())); + }*/ +} + +void HiPlayerCallbackLooper::OnError(PlayerErrorType errorType, int32_t errorCode) +{ + /*eventQueue_.Enqueue(std::make_shared(WHAT_ERROR, SteadyClock::GetCurrentTimeMs(), + std::make_pair(errorType, errorCode)));*/ +} + +void HiPlayerCallbackLooper::DoReportError(const Any &error) +{ + auto obs = obs_.lock(); + if (obs != nullptr) { + auto ptr = AnyCast>(&error); + MEDIA_LOG_E("Report error, error type: " PUBLIC_LOG_D32 " error value: " PUBLIC_LOG_D32, + static_cast(ptr->first), static_cast(ptr->second)); + obs->OnError(ptr->first, ptr->second); + } +} + +void HiPlayerCallbackLooper::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) +{ + eventQueue_.Enqueue(std::make_shared(WHAT_INFO, 0, + std::make_tuple(type, extra, infoBody))); +} + +void HiPlayerCallbackLooper::DoReportInfo(const Any& info) +{ + auto obs = obs_.lock(); + if (obs != nullptr) { + auto ptr = AnyCast>(&info); + MEDIA_LOG_I("Report info, info type: " PUBLIC_LOG_D32 " info value: " PUBLIC_LOG_D32, + static_cast(std::get<0>(*ptr)), static_cast(std::get<1>(*ptr))); + obs->OnInfo(std::get<0>(*ptr), std::get<1>(*ptr), std::get<2>(*ptr)); // indexes + } +} + +void HiPlayerCallbackLooper::LoopOnce() +{ + auto item = eventQueue_.Next(); + switch (item->what) { + case WHAT_MEDIA_PROGRESS: + DoReportMediaProgress(); + break; + case WHAT_INFO: + DoReportInfo(item->detail); + break; + case WHAT_ERROR: + DoReportError(item->detail); + break; + default: + break; + } +} + +void HiPlayerCallbackLooper::EventQueue::Enqueue(const std::shared_ptr& event) +{ + if (event->what == WHAT_NONE) { + MEDIA_LOG_I("invalid event"); + } + OHOS::Media::AutoLock lock(queueMutex_); + if (quit_) { + MEDIA_LOG_W("event already quit"); + return; + } + auto ite = queue_.begin(); + for (; ite != queue_.end(); ite++) { + if ((*ite)->whenMs > event->whenMs) { + break; + } + } + auto pos = queue_.insert(ite, event); + if (pos == queue_.begin()) { + queueHeadUpdatedCond_.NotifyOne(); + } +} + +std::shared_ptr HiPlayerCallbackLooper::EventQueue::Next() +{ + OHOS::Media::AutoLock lock(queueMutex_); + // not empty + while (queue_.empty() && !quit_) { + queueHeadUpdatedCond_.Wait(lock); + } + + do { + if (quit_) { + return std::make_shared(WHAT_NONE, 0, Any()); + } + auto wakenAtTime = (*queue_.begin())->whenMs; + auto leftTime = wakenAtTime; + if (leftTime <= 0) { + auto first = *queue_.begin(); + queue_.erase(queue_.begin()); + return first; + } + queueHeadUpdatedCond_.WaitFor(lock, leftTime); + } while (1); +} + +void HiPlayerCallbackLooper::EventQueue::Quit() +{ + OHOS::Media::AutoLock lock(queueMutex_); + quit_ = true; + queueHeadUpdatedCond_.NotifyOne(); +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/services/engine/histreamer/player/hiplayer_callback_looper.h b/services/engine/histreamer/player/hiplayer_callback_looper.h new file mode 100644 index 000000000..b77756543 --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_callback_looper.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022-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 HISTREAMER_HIPLAYER_CALLBACKER_LOOPER_H +#define HISTREAMER_HIPLAYER_CALLBACKER_LOOPER_H + +#include +#include +#include "osal/task/task.h" +#include "i_player_engine.h" +#include "meta/any.h" + +namespace OHOS { +namespace Media { +class HiPlayerCallbackLooper : public IPlayerEngineObs { +public: + explicit HiPlayerCallbackLooper(); + ~HiPlayerCallbackLooper() override; + + bool IsStarted(); + + void Stop(); + + void StartWithPlayerEngineObs(const std::weak_ptr& obs); + + void SetPlayEngine(IPlayerEngine* engine); + + void StartReportMediaProgress(int64_t updateIntervalMs = 1000); + + void StopReportMediaProgress(); + + void ManualReportMediaProgressOnce(); + + void OnError(PlayerErrorType errorType, int32_t errorCode) override; + + void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) override; + +private: + + void LoopOnce(); + + void DoReportMediaProgress(); + void DoReportInfo(const Any& info); + void DoReportError(const Any& error); + + struct Event{ + Event(int32_t inWhat, int64_t inWhenMs, Any inAny): what(inWhat), whenMs(inWhenMs), + detail(std::move(inAny)) {} + int32_t what {0}; + int64_t whenMs {INT64_MAX}; + Any detail; + }; + class EventQueue { + public: + void Enqueue(const std::shared_ptr& event); + std::shared_ptr Next(); + void Quit(); + private: + OHOS::Media::Mutex queueMutex_ {}; + OHOS::Media::ConditionVariable queueHeadUpdatedCond_ {}; + std::list> queue_ {}; + bool quit_ {false}; + }; + + OHOS::Media::Task task_; + bool taskStarted_ {false}; + IPlayerEngine* playerEngine_ {}; + std::weak_ptr obs_ {}; + EventQueue eventQueue_ {}; + bool reportMediaProgress_ {false}; + int64_t reportProgressIntervalMs_ {100}; // default interval is 100 ms +}; +} // namespace Media +} // namespace OHOS +#endif // HISTREAMER_HIPLAYER_CALLBACKER_LOOPER_H diff --git a/services/engine/histreamer/player/hiplayer_impl.cpp b/services/engine/histreamer/player/hiplayer_impl.cpp new file mode 100644 index 000000000..a2082b73a --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -0,0 +1,705 @@ +/* + * Copyright (c) 2023-2023 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. + */ + +#define HST_LOG_TAG "HiPlayerImpl" + +#include "hiplayer_impl.h" +#include +#include +#include +#include "common/log.h" +#include "osal/utils/dump_buffer.h" +#include "filter/filter_factory.h" +#include "common/media_source.h" + +namespace { +const float MAX_MEDIA_VOLUME = 1.0f; // standard interface volume is between 0 to 1. +} + +namespace OHOS { +namespace Media { +using namespace Pipeline; +constexpr double EPSINON = 0.0001; +constexpr double SPEED_0_75_X = 0.75; +constexpr double SPEED_1_00_X = 1.00; +constexpr double SPEED_1_25_X = 1.25; +constexpr double SPEED_1_75_X = 1.75; +constexpr double SPEED_2_00_X = 2.00; +const std::pair g_statusPair[] = { + {Status::OK, MSERR_OK}, + {Status::ERROR_UNKNOWN, MSERR_UNKNOWN}, + {Status::ERROR_AGAIN, MSERR_UNKNOWN}, + {Status::ERROR_UNIMPLEMENTED, MSERR_UNSUPPORT}, + {Status::ERROR_INVALID_PARAMETER, MSERR_INVALID_VAL}, + {Status::ERROR_INVALID_OPERATION, MSERR_INVALID_OPERATION}, + {Status::ERROR_UNSUPPORTED_FORMAT, MSERR_UNSUPPORT_CONTAINER_TYPE}, + {Status::ERROR_NOT_EXISTED, MSERR_OPEN_FILE_FAILED}, + {Status::ERROR_TIMED_OUT, MSERR_EXT_TIMEOUT}, + {Status::ERROR_NO_MEMORY, MSERR_EXT_NO_MEMORY}, + {Status::ERROR_INVALID_STATE, MSERR_INVALID_STATE}, +}; +class PlayerEventReceiver : public EventReceiver { +public: + PlayerEventReceiver(HiPlayerImpl* hiPlayerImpl) { + hiPlayerImpl_ = hiPlayerImpl; + } + + void OnEvent(const Event &event) { + hiPlayerImpl_->OnEvent(event); + } + +private: + HiPlayerImpl* hiPlayerImpl_; +}; + +class PlayerFilterCallback : public FilterCallback { +public: + PlayerFilterCallback(HiPlayerImpl* hiPlayerImpl) { + hiPlayerImpl_ = hiPlayerImpl; + } + + void OnCallback(const std::shared_ptr& filter, FilterCallBackCommand cmd, StreamType outType) { + hiPlayerImpl_->OnCallback(filter, cmd, outType); + } + +private: + HiPlayerImpl* hiPlayerImpl_; +}; + +HiPlayerImpl::HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) + : appUid_(appUid), + appPid_(appPid), + appTokenId_(appTokenId), + appFullTokenId_(appFullTokenId) +{ + MEDIA_LOG_I("hiPlayerImpl ctor appUid " PUBLIC_LOG_D32 " appPid " PUBLIC_LOG_D32 " appTokenId " PUBLIC_LOG_D32 " appFullTokenId " PUBLIC_LOG_D64, + appUid_, appPid_, appTokenId_, appFullTokenId_); + pipeline_ = std::make_shared(); + // syncManager_ = std::make_shared(); +} + +HiPlayerImpl::~HiPlayerImpl() +{ + MEDIA_LOG_I("dtor called."); + pipeline_->Stop(); + audioSink_.reset(); +#ifdef VIDEO_SUPPORT + videoSink_.reset(); +#endif + //syncManager_.reset(); +} + +Status HiPlayerImpl::Init() +{ + MEDIA_LOG_I("Init entered."); + std::shared_ptr playerEventReceiver = std::make_shared( + this); + playerEventReceiver_ = playerEventReceiver; + std::shared_ptr playerFilterCallback = std::make_shared( + this); + playerFilterCallback_ = playerFilterCallback; + MEDIA_LOG_I("pipeline init start"); + pipeline_->Init(playerEventReceiver, playerFilterCallback); + MEDIA_LOG_I("Init End."); + return Status::OK; +} + +int32_t HiPlayerImpl::SetSource(const std::string& uri) +{ + MEDIA_LOG_I("SetSource entered source uri: " PUBLIC_LOG_S, uri.c_str()); + auto ret = Init(); + if (ret == Status::OK) { + url_ = uri; + ret = DoSetSource(std::make_shared(url_)); + } + if (ret != Status::OK) { + MEDIA_LOG_E("SetSource error: " PUBLIC_LOG_D32, ret); + } else { + OnStateChanged(PlayerStateId::INIT); + } + return TransStatus(ret); +} + +int32_t HiPlayerImpl::SetSource(const std::shared_ptr& dataSrc) +{ + MEDIA_LOG_I("SetSource entered source stream"); + auto ret = Init(); + if (ret == Status::OK) { + ret = DoSetSource(std::make_shared(dataSrc)); + } + if (ret != Status::OK) { + MEDIA_LOG_E("SetSource error: " PUBLIC_LOG_D32, ret); + } else { + OnStateChanged(PlayerStateId::INIT); + } + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Prepare() +{ + MEDIA_LOG_I("Prepare start"); + Status ret = pipeline_->Prepare(); + if (ret != Status::OK) { + return TransStatus(ret); + } + AutoLock lock(stateMutex_); + if (curState_ == PlayerStateId::PREPARING) { // Wait state change to ready + cond_.Wait(lock, [this] { return curState_ != PlayerStateId::READY; }); + } + if (curState_ == PlayerStateId::READY) { + ret = Status::OK; + Format format; + callbackLooper_.OnInfo(INFO_TYPE_STATE_CHANGE, PlayerStates::PLAYER_PREPARED, format); + } else { + ret = Status::ERROR_UNKNOWN; + } + MEDIA_LOG_I("Prepare End"); + return TransStatus(ret); +} + +int HiPlayerImpl::PrepareAsync() +{ + MEDIA_LOG_I("PrepareAsync Start"); + auto ret = pipeline_->Prepare(); + if (ret != Status::OK) { + MEDIA_LOG_E("Prepare async failed with error " PUBLIC_LOG_D32, ret); + } + MEDIA_LOG_I("PrepareAsync End"); + OnStateChanged(PlayerStateId::READY); + Format format; + callbackLooper_.OnInfo(INFO_TYPE_STATE_CHANGE, PlayerStates::PLAYER_PREPARED, format); + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Play() +{ + MEDIA_LOG_I("Play entered."); + auto ret {Status::OK}; + if (curState_ == PlayerStateId::READY) { + //syncManager_->Resume(); + ret = pipeline_->Start(); + } + if (ret == Status::OK) { + OnStateChanged(PlayerStateId::PLAYING); + } + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Pause() +{ + MEDIA_LOG_I("Pause entered."); + auto ret = pipeline_->Pause(); + // syncManager_->Pause(); + OnStateChanged(PlayerStateId::PAUSE); + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Stop() +{ + MEDIA_LOG_I("Stop entered."); + // close demuxer first to avoid concurrent problem + if (demuxer_ != nullptr) { + demuxer_->Stop(); + } + auto ret = Status::OK; + if (pipeline_ != nullptr) { + pipeline_->Stop(); + } + // syncManager_->Reset(); + OnStateChanged(PlayerStateId::STOPPED); + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Reset() +{ + MEDIA_LOG_I("Reset entered."); + Stop(); + auto ret = Resume(); + OnStateChanged(PlayerStateId::STOPPED); + return TransStatus(ret); +} + +int32_t HiPlayerImpl::Seek(int32_t mSeconds, PlayerSeekMode mode) +{ + MEDIA_LOG_I("Seek entered. mSeconds : " PUBLIC_LOG_D32 ", seekMode : " PUBLIC_LOG_D32, + mSeconds, static_cast(mode)); + int64_t hstTime = 0; + int32_t durationMs; + GetDuration(durationMs); + if (durationMs <= 0) { + MEDIA_LOG_E("Seek, invalid operation, source is unseekable or invalid"); + return (int32_t)Status::ERROR_INVALID_PARAMETER; + } + MEDIA_LOG_D("Seek durationMs : " PUBLIC_LOG_D32, durationMs); + if (mSeconds >= durationMs) { // if exceeds change to duration + mSeconds = durationMs; + } + mSeconds = mSeconds < 0 ? 0 : mSeconds; + int64_t seekPos = hstTime; + SeekMode seekMode; + switch (mode) { + case PlayerSeekMode::SEEK_NEXT_SYNC: + seekMode = Plugin::SeekMode::SEEK_NEXT_SYNC; + case PlayerSeekMode::SEEK_PREVIOUS_SYNC: + seekMode = Plugin::SeekMode::SEEK_PREVIOUS_SYNC; + case PlayerSeekMode::SEEK_CLOSEST_SYNC: + seekMode = Plugin::SeekMode::SEEK_CLOSEST_SYNC; + case PlayerSeekMode::SEEK_CLOSEST: + default: + seekMode = Plugin::SeekMode::SEEK_CLOSEST; + } + auto rtv = seekPos >= 0 ? Status::OK : Status::ERROR_INVALID_PARAMETER; + if (rtv == Status::OK) { + pipeline_->Flush(); + MEDIA_LOG_I("Do seek ..."); + int64_t realSeekTime = seekPos; + rtv = demuxer_->SeekTo(seekPos, seekMode, realSeekTime); + /* if (rtv == Status::OK) { + syncManager_->Seek(realSeekTime); + } */ + } + if (rtv != Status::OK) { + MEDIA_LOG_E("Seek done, seek error."); + } + return TransStatus(rtv); +} + +int32_t HiPlayerImpl::SetVolume(float leftVolume, float rightVolume) +{ + MEDIA_LOG_I("SetVolume entered."); + if (leftVolume < 0 || leftVolume > MAX_MEDIA_VOLUME || rightVolume < 0 || rightVolume > MAX_MEDIA_VOLUME) { + MEDIA_LOG_E("volume not valid, should be in range [0,100]"); + return (int32_t)Status::ERROR_INVALID_PARAMETER; + } + float volume = 0.0f; + if (leftVolume < 1e-6 && rightVolume >= 1e-6) { // 1e-6 + volume = rightVolume; + } else if (rightVolume < 1e-6 && leftVolume >= 1e-6) { // 1e-6 + volume = leftVolume; + } else { + volume = (leftVolume + rightVolume) / 2; // 2 + } + volume /= MAX_MEDIA_VOLUME; // normalize to 0~1 + Status ret = Status::OK; + ret = audioSink_->SetVolume(volume); + if (ret != Status::OK) { + MEDIA_LOG_E("SetVolume failed with error " PUBLIC_LOG_D32, static_cast(ret)); + } + return TransStatus(ret); +} + +int32_t HiPlayerImpl::SetVideoSurface(sptr surface) +{ + MEDIA_LOG_D("SetVideoSurface entered."); +#ifdef VIDEO_SUPPORT + FALSE_RETURN_V_MSG_E(surface != nullptr, (int32_t)(Status::ERROR_INVALID_PARAMETER), + "Set video surface failed, surface == nullptr"); + return TransStatus(videoSink_->SetVideoSurface(surface)); +#else + return TransStatus(Status::OK); +#endif +} + +int32_t HiPlayerImpl::SetLooping(bool loop) +{ + MEDIA_LOG_I("SetLooping entered, loop: " PUBLIC_LOG_D32, loop); + singleLoop_ = loop; + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::SetParameter(const Format& params) +{ + MEDIA_LOG_I("SetParameter entered."); +#ifdef VIDEO_SUPPORT + if (params.ContainKey(PlayerKeys::VIDEO_SCALE_TYPE)) { + int32_t videoScaleType = 0; + params.GetIntValue(PlayerKeys::VIDEO_SCALE_TYPE, videoScaleType); + return SetVideoScaleType(VideoScaleType(videoScaleType)); + } +#endif + if (params.ContainKey(PlayerKeys::CONTENT_TYPE) && params.ContainKey(PlayerKeys::STREAM_USAGE)) { + int32_t contentType; + int32_t streamUsage; + int32_t rendererFlag; + params.GetIntValue(PlayerKeys::CONTENT_TYPE, contentType); + params.GetIntValue(PlayerKeys::STREAM_USAGE, streamUsage); + params.GetIntValue(PlayerKeys::RENDERER_FLAG, rendererFlag); + return SetAudioRendererInfo(contentType, streamUsage, rendererFlag); + } + if (params.ContainKey(PlayerKeys::AUDIO_INTERRUPT_MODE)) { + int32_t interruptMode = 0; + params.GetIntValue(PlayerKeys::AUDIO_INTERRUPT_MODE, interruptMode); + return SetAudioInterruptMode(interruptMode); + } + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::SetObs(const std::weak_ptr& obs) +{ + MEDIA_LOG_I("SetObs entered."); + callbackLooper_.StartWithPlayerEngineObs(obs); + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::GetCurrentTime(int32_t& currentPositionMs) +{ + //currentPositionMs = syncManager_->GetMediaTimeNow(); + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::GetDuration(int32_t& durationMs) +{ + auto tmpMeta = demuxer_->GetGlobalMetaInfo(); + sourceMeta_ = tmpMeta; + int64_t duration = 0; + bool found = false; + if (tmpMeta->GetData(Tag::MEDIA_DURATION, duration)) { + found = true; + } else { + MEDIA_LOG_W("Get media duration failed."); + } + streamMeta_.clear(); + int64_t tmp = 0; + for (auto& streamMeta : demuxer_->GetStreamMetaInfo()) { + streamMeta_.push_back(streamMeta); + if (streamMeta->GetData(Tag::MEDIA_DURATION, tmp)) { + duration = std::max(duration, tmp); + found = true; + } else { + MEDIA_LOG_W("Get media duration failed."); + } + } + if (found) { + duration_ = duration; + } + durationMs = duration_; + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::SetPlaybackSpeed(PlaybackRateMode mode) +{ + MEDIA_LOG_I("SetPlaybackSpeed entered."); + double playbackSpeed = SPEED_1_00_X; + switch (mode) { + case SPEED_FORWARD_0_75_X: + playbackSpeed = SPEED_0_75_X; + case SPEED_FORWARD_1_00_X: + playbackSpeed = SPEED_1_00_X; + case SPEED_FORWARD_1_25_X: + playbackSpeed = SPEED_1_25_X; + case SPEED_FORWARD_1_75_X: + playbackSpeed = SPEED_1_75_X; + case SPEED_FORWARD_2_00_X: + playbackSpeed = SPEED_2_00_X; + default: + MEDIA_LOG_I("unknown mode:" PUBLIC_LOG_D32 ", return default speed(SPEED_1_00_X)", mode); + } + auto meta = std::make_shared(); + meta->SetData(Tag::MEDIA_PLAYBACK_SPEED, playbackSpeed); + demuxer_->SetParameter(meta); + Format format; + callbackLooper_.OnInfo(INFO_TYPE_SPEEDDONE, 0, format); + + int32_t currentPosMs = 0; + int32_t durationMs = 0; + NZERO_RETURN(GetDuration(durationMs)); + NZERO_RETURN(GetCurrentTime(currentPosMs)); + currentPosMs = std::min(currentPosMs, durationMs); + currentPosMs = currentPosMs < 0 ? 0 : currentPosMs; + callbackLooper_.OnInfo(INFO_TYPE_POSITION_UPDATE, currentPosMs, format); + MEDIA_LOG_D("SetPlaybackSpeed entered end."); + return MSERR_OK; +} +int32_t HiPlayerImpl::GetPlaybackSpeed(PlaybackRateMode& mode) +{ + MEDIA_LOG_I("GetPlaybackSpeed entered."); + double rate; + auto meta = std::make_shared(); + demuxer_->GetParameter(meta); + meta->GetData(Tag::MEDIA_PLAYBACK_SPEED, rate); + if (abs(rate - SPEED_0_75_X) < EPSINON) { + return SPEED_FORWARD_0_75_X; + } + if (abs(rate - SPEED_1_00_X) < EPSINON) { + return SPEED_FORWARD_1_00_X; + } + if (abs(rate - SPEED_1_25_X) < EPSINON) { + return SPEED_FORWARD_1_25_X; + } + if (abs(rate - SPEED_1_75_X) < EPSINON) { + return SPEED_FORWARD_1_75_X; + } + if (abs(rate - SPEED_2_00_X) < EPSINON) { + return SPEED_FORWARD_2_00_X; + } + return SPEED_FORWARD_1_00_X; +} + +int32_t HiPlayerImpl::GetVideoTrackInfo(std::vector& videoTrack) +{ + MEDIA_LOG_I("GetVideoTrackInfo entered."); +#ifdef VIDEO_SUPPORT + std::string mime; + std::vector> metaInfo = demuxer_->GetStreamMetaInfo(); + for (const auto& trackInfo : metaInfo) { + if (!(trackInfo->GetData(Tag::MIME_TYPE, mime))) { + MEDIA_LOG_W("Get MIME fail"); + } + if (IsVideoMime(mime)) { + Format videoTrackInfo {}; + videoTrackInfo.PutStringValue("codec_mime", mime); + videoTrackInfo.PutIntValue("track_type", MediaType::MEDIA_TYPE_VID); + uint32_t trackIndex; + trackInfo->GetData(Tag::TRACK_ID, trackIndex); + videoTrackInfo.PutIntValue("track_index", static_cast(trackIndex)); + int64_t bitRate; + trackInfo->GetData(Tag::MEDIA_BITRATE, bitRate); + videoTrackInfo.PutIntValue("bitrate", static_cast(bitRate)); + uint32_t frameRate; + trackInfo->GetData(Tag::VIDEO_FRAME_RATE, frameRate); + videoTrackInfo.PutIntValue("frame_rate", static_cast(frameRate)); + uint32_t height; + trackInfo->GetData(Tag::VIDEO_HEIGHT, height); + videoTrackInfo.PutIntValue("height", static_cast(height)); + uint32_t width; + trackInfo->GetData(Tag::VIDEO_WIDTH, width); + videoTrackInfo.PutIntValue("width", static_cast(width)); + videoTrack.push_back(videoTrackInfo); + } + } +#endif + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::GetAudioTrackInfo(std::vector& audioTrack) +{ + MEDIA_LOG_I("GetAudioTrackInfo entered."); + std::string mime; + std::vector> metaInfo = demuxer_->GetStreamMetaInfo(); + for (int trackIndex = 0; trackIndex < metaInfo.size(); trackIndex++) { + auto trackInfo = metaInfo[trackIndex]; + if (!(trackInfo->GetData(Tag::MIME_TYPE, mime))) { + MEDIA_LOG_W("Get MIME fail"); + } + if (mime.find("audio/") == 0) { + Format audioTrackInfo {}; + audioTrackInfo.PutStringValue("codec_mime", mime); + audioTrackInfo.PutIntValue("track_type", OHOS::Media::MediaType::MEDIA_TYPE_AUD); + audioTrackInfo.PutIntValue("track_index", static_cast(trackIndex)); + int64_t bitRate; + trackInfo->GetData(Tag::MEDIA_BITRATE, bitRate); + audioTrackInfo.PutIntValue("bitrate", static_cast(bitRate)); + int32_t audioChannels; + trackInfo->GetData(Tag::AUDIO_CHANNEL_COUNT, audioChannels); + audioTrackInfo.PutIntValue("channel_count", static_cast(audioChannels)); + int32_t audioSampleRate; + trackInfo->GetData(Tag::AUDIO_SAMPLE_RATE, audioSampleRate); + audioTrackInfo.PutIntValue("sample_rate", static_cast(audioSampleRate)); + audioTrack.push_back(audioTrackInfo); + } + } + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::GetVideoWidth() +{ +#ifdef VIDEO_SUPPORT + std::vector> metaInfo = demuxer_->GetStreamMetaInfo(); + for (const auto& trackInfo : metaInfo) { + if !(trackInfo->GetData(Tag::MIME, mime)) { + MEDIA_LOG_W("Get MIME fail"); + } + if (IsVideoMime(mime)) { + uint32_t width; + trackInfo->GetData(Tag::VIDEO_WIDTH, width); + videoWidth_ = width; + } + } + MEDIA_LOG_I("GetVideoWidth entered. video width: " PUBLIC_LOG_D32, videoWidth_); +#endif + return videoWidth_; +} + +int32_t HiPlayerImpl::GetVideoHeight() +{ +#ifdef VIDEO_SUPPORT + std::vector> metaInfo = demuxer_->GetStreamMetaInfo(); + for (const auto& trackInfo : metaInfo) { + if !(trackInfo->GetData(Tag::MIME, mime)) { + MEDIA_LOG_W("Get MIME fail"); + } + if (IsVideoMime(mime)) { + uint32_t height; + trackInfo->GetData(Tag::VIDEO_HEIGHT, height); + videoHeight_ = height; + } + } + MEDIA_LOG_I("GetVideoHeight entered. video height: " PUBLIC_LOG_D32, videoHeight_); +#endif + return videoHeight_; +} + +int32_t HiPlayerImpl::SetVideoScaleType(OHOS::Media::VideoScaleType videoScaleType) +{ + MEDIA_LOG_I("SetVideoScaleType entered."); +#ifdef VIDEO_SUPPORT + auto ret = videoSink_->SetParameter(static_cast(Tag::VIDEO_SCALE_TYPE), + static_cast(static_cast(videoScaleType))); + return TransStatus(ret); +#else + return TransStatus(Status::OK); +#endif +} + +int32_t HiPlayerImpl::SetAudioRendererInfo(const int32_t contentType, const int32_t streamUsage, + const int32_t rendererFlag) +{ + MEDIA_LOG_I("SetAudioRendererInfo entered."); + Plugin::AudioRenderInfo audioRenderInfo {contentType, streamUsage, rendererFlag}; + auto meta = std::make_shared(); + meta->SetData(Tag::AUDIO_RENDER_INFO, audioRenderInfo); + audioSink_->SetParameter(meta); + return TransStatus(Status::OK); +} + +int32_t HiPlayerImpl::SetAudioInterruptMode(const int32_t interruptMode) +{ + MEDIA_LOG_I("SetAudioInterruptMode entered."); + auto meta = std::make_shared(); + meta->SetData(Tag::AUDIO_INTERRUPT_MODE, interruptMode); + audioSink_->SetParameter(meta); + return TransStatus(Status::OK); +} + +int HiPlayerImpl::TransStatus(Status status) +{ + for (const auto& errPair : g_statusPair) { + if (errPair.first == status) { + return errPair.second; + } + } + return MSERR_UNKNOWN; +} + +void HiPlayerImpl::OnEvent(const Event &event) { + switch (event.type) { + case EventType::EVENT_ERROR: { + OnStateChanged(PlayerStateId::ERROR); + break; + } + case EventType::EVENT_READY: { + OnStateChanged(PlayerStateId::READY); + break; + } + case EventType::EVENT_COMPLETE: { + break; + } + default: + break; + } +} + +Status HiPlayerImpl::DoSetSource(const std::shared_ptr source) +{ + demuxer_ = FilterFactory::Instance().CreateFilter("builtin.player.demuxer", + FilterType::FILTERTYPE_DEMUXER); + demuxer_->Init(playerEventReceiver_, playerFilterCallback_); + auto ret = demuxer_->SetDataSource(source); + pipeline_->AddHeadFilters({demuxer_}); + return ret; +} + +Status HiPlayerImpl::Resume() +{ + // syncManager_->Resume(); + auto ret = pipeline_->Resume(); + return ret; +} + +void HiPlayerImpl::OnStateChanged(PlayerStateId state) +{ + curState_ = state; +} + +void HiPlayerImpl::OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, + StreamType outType) +{ + MEDIA_LOG_I("HiPlayerImpl::OnCallback filter, "); + if (cmd == FilterCallBackCommand::NEXT_FILTER_NEEDED) { + switch (outType) { + case StreamType::STREAMTYPE_RAW_AUDIO: + LinkAudioSinkFilter(filter, outType); + break; + case StreamType::STREAMTYPE_ENCODED_AUDIO: + LinkAudioDecoderFilter(filter, outType); + break; +#ifdef VIDEO_SUPPORT + case StreamType::STREAMTYPE_RAW_VIDEO: + LinkVideoSinkFilter(filter, outType); + break; + case StreamType::STREAMTYPE_ENCODED_VIDEO: + LinkVideoDecoderFilter(filter, outType); + break; +#endif + default: + break; + } + } +} + +Status HiPlayerImpl::LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type) { + MEDIA_LOG_I("HiPlayerImpl::LinkAudioDecoderFilter"); + if (audioDecoder_ == nullptr) { + audioDecoder_ = FilterFactory::Instance().CreateFilter("player.audiodecoder", + FilterType::FILTERTYPE_ADEC); + audioDecoder_->Init(playerEventReceiver_, playerFilterCallback_); + } + return pipeline_->LinkFilters(preFilter, {audioDecoder_}, type); +} + +Status HiPlayerImpl::LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type) { + MEDIA_LOG_I("HiPlayerImpl::LinkAudioSinkFilter"); + if (audioSink_ == nullptr) { + audioSink_ = FilterFactory::Instance().CreateFilter("player.audiosink", + FilterType::FILTERTYPE_ASINK); + audioSink_->Init(playerEventReceiver_, playerFilterCallback_); + } + // audioSink_->SetSyncCenter(syncManager_); + return pipeline_->LinkFilters(preFilter, {audioSink_}, type); +} +#ifdef VIDEO_SUPPORT +Status HiPlayerImpl::LinkVideoDecoderFilter(const std::shared_ptr& preFilter, StreamType type) { + MEDIA_LOG_I("HiPlayerImpl::LinkVideoDecoderFilter"); + if (videoDecoder_ == nullptr) { + videoDecoder_ = FilterFactory::Instance().CreateFilter("player.videodecoder", + FilterType::FILTERTYPE_VDEC); + videoDecoder_->Init(playerEventReceiver_, playerFilterCallback_); + } + return pipeline_->LinkFilters(preFilter, {videoDecoder_}, type); +} + +Status HiPlayerImpl::LinkVideoSinkFilter(const std::shared_ptr& preFilter, StreamType type) { + MEDIA_LOG_I("HiPlayerImpl::LinkVideoSinkFilter"); + if (videoSink_ == nullptr) { + videoSink_ = FilterFactory::Instance().CreateFilter("player.videosink", + FilterType::FILTERTYPE_VSINK); + videoSink_->Init(playerEventReceiver_, playerFilterCallback_); + } + // videoSink_->SetSyncCenter(syncManager_); + return pipeline_->LinkFilters(preFilter, {videoSink_}, type); +} +#endif +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/services/engine/histreamer/player/hiplayer_impl.h b/services/engine/histreamer/player/hiplayer_impl.h new file mode 100644 index 000000000..ae54172b4 --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_impl.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2023-2023 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 HI_PLAYER_IMPL_H +#define HI_PLAYER_IMPL_H + +#include +#include + +#include "hiplayer_callback_looper.h" +#include +#include "common/status.h" +#include "media_sync_manager.h" +#include "pipeline/pipeline.h" +#include "filter/filter_factory.h" +#include "demuxer_filter.h" +#include "codec_filter.h" +#include "audio_sink_filter.h" +#ifdef VIDEO_SUPPORT +#include "video_sink_filter.h" +#endif +#include "filter/filter.h" + +namespace OHOS { +namespace Media { +using namespace Pipeline; +enum class PlayerStateId { + IDLE = 0, + INIT = 1, + PREPARING = 2, + READY = 3, + PAUSE = 4, + PLAYING = 5, + STOPPED = 6, + EOS = 7, + ERROR = 8, +}; +class HiPlayerImpl : public IPlayerEngine, public std::enable_shared_from_this { + +public: + HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId); + ~HiPlayerImpl() override; + HiPlayerImpl(const HiPlayerImpl& other) = delete; + HiPlayerImpl& operator=(const HiPlayerImpl& other) = delete; + Status Init(); + // interface from PlayerInterface + int32_t SetSource(const std::string& uri) override; + int32_t SetSource(const std::shared_ptr& dataSrc) override; + int32_t Prepare() override; + int32_t PrepareAsync() override; + int32_t Play() override; + int32_t Pause() override; + int32_t Stop() override; + int32_t Reset() override; + int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override; + int32_t SetVolume(float leftVolume, float rightVolume) override; + int32_t SetVideoSurface(sptr surface) override; + int32_t SetLooping(bool loop) override; + int32_t SetParameter(const Format& params) override; + int32_t SetObs(const std::weak_ptr& obs) override; + int32_t GetCurrentTime(int32_t& currentPositionMs) override; + int32_t GetDuration(int32_t& durationMs) override; + int32_t SetPlaybackSpeed(PlaybackRateMode mode) override; + int32_t GetPlaybackSpeed(PlaybackRateMode& mode) override; + + int32_t GetVideoTrackInfo(std::vector& videoTrack) override; + int32_t GetAudioTrackInfo(std::vector& audioTrack) override; + int32_t GetVideoWidth() override; + int32_t GetVideoHeight() override; + int32_t SetVideoScaleType(OHOS::Media::VideoScaleType videoScaleType) override; + int32_t SetAudioRendererInfo(const int32_t contentType, const int32_t streamUsage, + const int32_t rendererFlag) override; + int32_t SetAudioInterruptMode(const int32_t interruptMode) override; + + // internal interfaces + int TransStatus(Status status); + void OnEvent(const Event &event); + void OnStateChanged(PlayerStateId state); + void OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, + StreamType outType); +private: + Status DoSetSource(const std::shared_ptr source); + Status Resume(); + Status LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type); + Status LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type); +#ifdef VIDEO_SUPPORT + Status LinkVideoDecoderFilter(const std::shared_ptr& preFilter, StreamType type); + Status LinkVideoSinkFilter(const std::shared_ptr& preFilter, StreamType type); +#endif + int32_t appUid_ {0}; + int32_t appPid_ {0}; + int32_t appTokenId_{0}; + int64_t appFullTokenId_{0}; + OHOS::Media::Mutex stateMutex_ {}; + OHOS::Media::ConditionVariable cond_ {}; + int64_t duration_ {-1}; + std::atomic singleLoop_ {false}; + + std::shared_ptr playerEventReceiver_; + std::shared_ptr playerFilterCallback_; + std::weak_ptr sourceMeta_ {}; + std::vector> streamMeta_ {}; + std::shared_ptr pipeline_; + std::shared_ptr demuxer_; + std::shared_ptr audioDecoder_; + std::shared_ptr audioSink_; +#ifdef VIDEO_SUPPORT + std::shared_ptr videoDecoder_; + std::shared_ptr videoSink_; +#endif + std::shared_ptr syncManager_; + std::atomic curState_; + HiPlayerCallbackLooper callbackLooper_ {}; + sptr surface_ {nullptr}; + std::string url_; + int32_t videoWidth_ {0}; + int32_t videoHeight_ {0}; +}; +} // namespace Media +} // namespace OHOS +#endif // HI_PLAYER_IMPL_H \ No newline at end of file diff --git a/services/engine/histreamer/recorder/BUILD.gn b/services/engine/histreamer/recorder/BUILD.gn new file mode 100644 index 000000000..a109a8de4 --- /dev/null +++ b/services/engine/histreamer/recorder/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (C) 2021 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. + +import("//build/ohos.gni") + +config("media_engine_histreamer_recorder_config") { + visibility = [ ":*" ] + + defines = [ + "HST_ANY_WITH_NO_RTTI", + "MEDIA_OHOS", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "//foundation/multimedia/player_framework/services/engine/histreamer/recorder", + "//foundation/multimedia/player_framework/services/utils/include", + "//foundation/multimedia/player_framework/interfaces/inner_api/native", + "//foundation/multimedia/player_framework/services/services/engine_intf", + "//commonlibrary/c_utils/base/include", + "//foundation/multimedia/histreamer/interface/inner_api", + "//foundation/multimedia/av_codec/interfaces/inner_api/native", + "//foundation/multimedia/av_codec/interfaces", + "//foundation/multimedia/histreamer/src", + "//foundation/multimedia/av_codec/services/media_engine/modules/source/audio_capture", + ] +} + +ohos_static_library("media_engine_histreamer_recorder") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "hirecorder_impl.cpp" ] + + configs = [ + ":media_engine_histreamer_recorder_config", + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", + "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + ] + + deps = [ + "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", + "//foundation/multimedia/player_framework/services/utils:media_service_utils", + ] + + external_deps = [ + "av_codec:av_codec_media_engine_filters", + "av_codec:av_codec_media_engine_modules", + "c_utils:utils", + "graphic_2d:surface", + "graphic_2d:sync_fence", + "hilog:libhilog", + "histreamer:media_foundation", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + subsystem_name = "multimedia" + part_name = "player_framework" +} diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp new file mode 100644 index 000000000..5caae4905 --- /dev/null +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -0,0 +1,449 @@ +/* + * Copyright (c) 2023-2023 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 "hirecorder_impl.h" +#include "meta/audio_types.h" + +namespace OHOS { +namespace Media { + class RecorderEventReceiver : public Pipeline::EventReceiver { + public: + RecorderEventReceiver(HiRecorderImpl *hiRecorderImpl) { + hiRecorderImpl_ = hiRecorderImpl; + } + + void OnEvent(const Event &event) { + hiRecorderImpl_->OnEvent(event); + } + + private: + HiRecorderImpl *hiRecorderImpl_; + }; + + class RecorderFilterCallback : public Pipeline::FilterCallback { + public: + RecorderFilterCallback(HiRecorderImpl *hiRecorderImpl) { + hiRecorderImpl_ = hiRecorderImpl; + } + + void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) { + hiRecorderImpl_->OnCallback(filter, cmd, outType); + } + + private: + HiRecorderImpl *hiRecorderImpl_; + }; + + HiRecorderImpl::HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) + : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) { + pipeline_ = std::make_shared(); + } + + HiRecorderImpl::~HiRecorderImpl() { + } + + int32_t HiRecorderImpl::Init() { + MEDIA_LOG_I("Init enter."); + recorderEventReceiver_ = std::make_shared(this); + recorderCallback_ = std::make_shared(this); + pipeline_->Init(recorderEventReceiver_, recorderCallback_); + return (int32_t)Status::OK; + } + + int32_t HiRecorderImpl::SetVideoSource(VideoSourceType source, int32_t &sourceId) { + MEDIA_LOG_I("SetVideoSource enter."); + sourceId = INVALID_SOURCE_ID; + FALSE_RETURN_V(source != VideoSourceType::VIDEO_SOURCE_BUTT, + (int32_t)Status::ERROR_INVALID_PARAMETER); + FALSE_RETURN_V(videoCount_ < static_cast(VIDEO_SOURCE_MAX_COUNT), + (int32_t)Status::ERROR_INVALID_OPERATION); + auto tempSourceId = SourceIdGenerator::GenerateVideoSourceId(videoCount_); + + videoEncoderFilter_ = Pipeline::FilterFactory::Instance().CreateFilter + ("videoEncoderFilter", Pipeline::FilterType::FILTERTYPE_VENC); + + Status ret = pipeline_->AddHeadFilters({videoEncoderFilter_}); + FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "AddFilters videoEncoder to pipeline fail"); + if (ret == Status::OK) { + videoCount_++; + videoSourceId_ = tempSourceId; + sourceId = videoSourceId_; + OnStateChanged(StateId::RECORDING_SETTING); + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::SetAudioSource(AudioSourceType source, int32_t &sourceId) { + MEDIA_LOG_I("SetAudioSource enter."); + sourceId = INVALID_SOURCE_ID; + FALSE_RETURN_V(source != AudioSourceType::AUDIO_SOURCE_INVALID, + (int32_t)Status::ERROR_INVALID_PARAMETER); + FALSE_RETURN_V(audioCount_ < static_cast(AUDIO_SOURCE_MAX_COUNT), + (int32_t)Status::ERROR_INVALID_OPERATION); + auto tempSourceId = SourceIdGenerator::GenerateAudioSourceId(audioCount_); + + audioCaptureFilter_ = Pipeline::FilterFactory::Instance().CreateFilter + ("audioCaptureFilter", Pipeline::FilterType::FILTERTYPE_SOURCE); + if (audioCaptureFilter_ == nullptr) { + MEDIA_LOG_E("HiRecorderImpl::audioCaptureFilter_ == nullptr"); + } + Status ret = pipeline_->AddHeadFilters({audioCaptureFilter_}); + FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "AddFilters audioCapture to pipeline fail"); + if (ret == Status::OK) { + audioCount_++; + audioSourceId_ = tempSourceId; + sourceId = static_cast(audioSourceId_); + OnStateChanged(StateId::RECORDING_SETTING); + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::SetOutputFormat(OutputFormatType format) { + MEDIA_LOG_I("SetOutputFormat enter. " PUBLIC_LOG_D32, static_cast(format)); + outputFormatType_ = format; + OnStateChanged(StateId::RECORDING_SETTING); + return (int32_t)Status::OK; + } + + int32_t HiRecorderImpl::SetObs(const std::weak_ptr &obs) { + MEDIA_LOG_I("SetObs enter."); + obs_ = obs; + return (int32_t)Status::OK; + } + + int32_t HiRecorderImpl::Configure(int32_t sourceId, const RecorderParam &recParam) { + MEDIA_LOG_I("Configure enter."); + FALSE_RETURN_V(outputFormatType_ != OutputFormatType::FORMAT_BUTT, + (int32_t)Status::ERROR_INVALID_OPERATION); + FALSE_RETURN_V(CheckParamType(sourceId, recParam), (int32_t)Status::ERROR_INVALID_PARAMETER); + switch (recParam.type) { + case RecorderPublicParamType::AUD_SAMPLERATE: + case RecorderPublicParamType::AUD_CHANNEL: + case RecorderPublicParamType::AUD_BITRATE: + case RecorderPublicParamType::AUD_ENC_FMT: + ConfigureAudio(recParam); + break; + case RecorderPublicParamType::VID_CAPTURERATE: + case RecorderPublicParamType::VID_RECTANGLE: + case RecorderPublicParamType::VID_BITRATE: + case RecorderPublicParamType::VID_FRAMERATE: + case RecorderPublicParamType::VID_ENC_FMT: + ConfigureVideo(recParam); + break; + case RecorderPublicParamType::OUT_PATH: + case RecorderPublicParamType::OUT_FD: + case RecorderPublicParamType::VID_ORIENTATION_HINT: + case RecorderPublicParamType::GEO_LOCATION: + ConfigureMuxer(recParam); + break; + default: + break; + } + OnStateChanged(StateId::RECORDING_SETTING); + return (int32_t)Status::OK; + } + + sptr HiRecorderImpl::GetSurface(int32_t sourceId) { + MEDIA_LOG_I("GetSurface enter."); + return videoEncoderFilter_->GetInputSurface(); + } + + int32_t HiRecorderImpl::Prepare() { + MEDIA_LOG_I("Prepare enter."); + if (audioCaptureFilter_) { + audioCaptureFilter_->Init(recorderEventReceiver_, recorderCallback_); + audioEncFormat_->Set(appTokenId_); + audioEncFormat_->Set(appUid_); + audioEncFormat_->Set(appPid_); + audioEncFormat_->Set(appFullTokenId_); + // audioEncFormat_->Set(AudioSampleFormat::SAMPLE_S16P); + audioCaptureFilter_->SetParameter(audioEncFormat_); + } + if (videoEncoderFilter_) { + videoEncoderFilter_->SetCodecFormat(videoEncFormat_); + videoEncoderFilter_->Init(recorderEventReceiver_, recorderCallback_); + videoEncoderFilter_->Configure(videoEncFormat_); + } + Status ret = pipeline_->Prepare(); + if (ret != Status::OK) { + return (int32_t)ret; + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::Start() { + MEDIA_LOG_I("Start enter."); + Status ret = Status::OK; + if (curState_ == StateId::PAUSE) { + ret = pipeline_->Resume(); + } else { + ret = pipeline_->Start(); + } + if (ret == Status::OK) { + OnStateChanged(StateId::RECORDING); + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::Pause() { + MEDIA_LOG_I("Pause enter."); + Status ret = Status::OK; + if (curState_ != StateId::READY) { + ret = pipeline_->Pause(); + } + if (ret == Status::OK) { + OnStateChanged(StateId::PAUSE); + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::Resume() { + MEDIA_LOG_I("Resume enter."); + Status ret = Status::OK; + ret = pipeline_->Resume(); + if (ret == Status::OK) { + OnStateChanged(StateId::RECORDING); + } + return (int32_t)ret; + } + + int32_t HiRecorderImpl::Stop(bool isDrainAll) { + MEDIA_LOG_I("Stop enter."); + Status ret = Status::OK; + if (curState_ == StateId::INIT || curState_ == StateId::READY) { + return (int32_t)Status::ERROR_INVALID_OPERATION; + } + outputFormatType_ = OutputFormatType::FORMAT_BUTT; + ret = audioCaptureFilter_->SendEos(); + ret = pipeline_->Stop(); + if (ret == Status::OK) { + OnStateChanged(StateId::INIT); + } + audioCount_ = 0; + videoCount_ = 0; + audioSourceId_ = 0; + videoSourceId_ = 0; + FALSE_RETURN_V_MSG_E(curState_ == StateId::INIT, ERR_UNKNOWN_REASON, "stop fail"); + return (int32_t)ret; + } + + int32_t HiRecorderImpl::Reset() { + MEDIA_LOG_I("Reset enter."); + Status ret = Status::OK; + if (curState_ == StateId::RECORDING) { + Stop(false); + } + ret = pipeline_->Stop(); + if (ret == Status::OK) { + OnStateChanged(StateId::INIT); + } + audioCount_ = 0; + videoCount_ = 0; + audioSourceId_ = 0; + videoSourceId_ = 0; + return (int32_t)ret; + } + + int32_t HiRecorderImpl::SetParameter(int32_t sourceId, const RecorderParam &recParam) { + MEDIA_LOG_I("SetParameter enter."); + return Configure(sourceId, recParam); + } + + void HiRecorderImpl::OnEvent(const Event &event) { + switch (event.type) { + case EventType::EVENT_ERROR: { + OnStateChanged(StateId::ERROR); + auto ptr = obs_.lock(); + if (ptr != nullptr) { + // ptr->OnError(IRecorderEngineObs::ErrorType::ERROR_INTERNAL, event.param); + } + break; + } + case EventType::EVENT_READY: { + OnStateChanged(StateId::READY); + break; + } + case EventType::EVENT_COMPLETE: { + break; + } + default: + break; + } + } + + void HiRecorderImpl::OnCallback(std::shared_ptr filter, const Pipeline::FilterCallBackCommand cmd, + Pipeline::StreamType outType) { + MEDIA_LOG_I("OnCallback enter."); + if (cmd == Pipeline::FilterCallBackCommand::NEXT_FILTER_NEEDED) { + switch (outType) { + case Pipeline::StreamType::STREAMTYPE_RAW_AUDIO: + audioEncoderFilter_ = Pipeline::FilterFactory::Instance().CreateFilter + ("audioEncoderFilter", Pipeline::FilterType::FILTERTYPE_AENC); + audioEncoderFilter_->SetCodecFormat(audioEncFormat_); + audioEncoderFilter_->Init(recorderEventReceiver_, recorderCallback_); + audioEncoderFilter_->Configure(audioEncFormat_); + pipeline_->LinkFilters(filter, {audioEncoderFilter_}, outType); + break; + case Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO: + if (muxerFilter_ == nullptr) { + muxerFilter_ = Pipeline::FilterFactory::Instance().CreateFilter + ("muxerFilter", Pipeline::FilterType::FILTERTYPE_MUXER); + muxerFilter_->Init(recorderEventReceiver_, recorderCallback_); + muxerFilter_->SetOutputParameter(appUid_, appPid_, fd_, outputFormatType_); + close(fd_); + fd_ = -1; + } + pipeline_->LinkFilters(filter, {muxerFilter_}, outType); + break; + case Pipeline::StreamType::STREAMTYPE_ENCODED_VIDEO: + if (muxerFilter_ == nullptr) { + muxerFilter_ = Pipeline::FilterFactory::Instance().CreateFilter + ("muxerFilter", Pipeline::FilterType::FILTERTYPE_MUXER); + muxerFilter_->Init(recorderEventReceiver_, recorderCallback_); + muxerFilter_->SetOutputParameter(appUid_, appPid_, fd_, outputFormatType_); + close(fd_); + fd_ = -1; + } + pipeline_->LinkFilters(filter, {muxerFilter_}, outType); + break; + default: + break; + } + } + } + + void HiRecorderImpl::ConfigureAudio(const RecorderParam &recParam) { + MEDIA_LOG_I("ConfigureAudio enter."); + switch (recParam.type) { + case RecorderPublicParamType::AUD_SAMPLERATE: { + AudSampleRate audSampleRate = static_cast(recParam); + audioEncFormat_->Set(audSampleRate.sampleRate); + break; + } + case RecorderPublicParamType::AUD_CHANNEL: { + AudChannel audChannel = static_cast(recParam); + audioEncFormat_->Set(audChannel.channel); + break; + } + case RecorderPublicParamType::AUD_BITRATE: { + AudBitRate audBitRate = static_cast(recParam); + audioEncFormat_->Set(audBitRate.bitRate); + break; + } + case RecorderPublicParamType::AUD_ENC_FMT: { + AudEnc audEnc = static_cast(recParam); + switch (audEnc.encFmt) { + case OHOS::Media::AudioCodecFormat::AUDIO_DEFAULT: + case OHOS::Media::AudioCodecFormat::AAC_LC: + audioEncFormat_->Set(Plugin::MimeType::AUDIO_AAC); + audioEncFormat_->Set(Plugin::AudioAacProfile::LC); + default: + break; + } + break; + } + default: { + break; + } + } + + } + + void HiRecorderImpl::ConfigureVideo(const RecorderParam &recParam) { + MEDIA_LOG_I("ConfigureVideo enter."); + switch (recParam.type) { + case RecorderPublicParamType::VID_RECTANGLE: { + VidRectangle vidRectangle = static_cast(recParam); + videoEncFormat_->Set(vidRectangle.width); + videoEncFormat_->Set(vidRectangle.height); + break; + } + case RecorderPublicParamType::VID_CAPTURERATE: { + CaptureRate captureRate = static_cast(recParam); + videoEncFormat_->Set(captureRate.capRate); + break; + } + case RecorderPublicParamType::VID_BITRATE: { + VidBitRate vidBitRate = static_cast(recParam); + videoEncFormat_->Set(vidBitRate.bitRate); + break; + } + case RecorderPublicParamType::VID_FRAMERATE: { + VidFrameRate vidFrameRate = static_cast(recParam); + videoEncFormat_->Set(vidFrameRate.frameRate); + break; + } + case RecorderPublicParamType::VID_ENC_FMT: { + videoEncFormat_ = std::make_shared(); + VidEnc vidEnc = static_cast(recParam); + switch (vidEnc.encFmt) { + case OHOS::Media::VideoCodecFormat::H264: + videoEncFormat_->Set(Plugin::MimeType::VIDEO_AVC); + videoEncFormat_->Set(Plugin::VideoH264Profile::BASELINE); + videoEncFormat_->Set(32); // 32: LEVEL 3.2 + break; + case OHOS::Media::VideoCodecFormat::MPEG4: + videoEncFormat_->Set(Plugin::MimeType::VIDEO_MPEG4); + break; + default: + break; + } + break; + } + default: + break; + } + } + + void HiRecorderImpl::ConfigureMuxer(const RecorderParam &recParam) { + MEDIA_LOG_I("ConfigureMuxer enter"); + switch (recParam.type) { + case RecorderPublicParamType::OUT_FD: { + OutFd outFd = static_cast(recParam); + fd_ = dup(outFd.fd); + MEDIA_LOG_I("ConfigureMuxer enter " PUBLIC_LOG_D32, fd_); + break; + } + case RecorderPublicParamType::MAX_DURATION: { + MaxDuration maxDuration = static_cast(recParam); + maxDuration_ = maxDuration.duration; + break; + } + case RecorderPublicParamType::MAX_SIZE: { + MaxFileSize maxFileSize = static_cast(recParam); + maxSize_ = maxFileSize.size; + break; + } + case RecorderPublicParamType::VID_ORIENTATION_HINT: + case RecorderPublicParamType::GEO_LOCATION: + default: + break; + } + } + + bool HiRecorderImpl::CheckParamType(int32_t sourceId, const RecorderParam &recParam) { + FALSE_RETURN_V((SourceIdGenerator::IsAudio(sourceId) && recParam.IsAudioParam() && + static_cast(audioSourceId_) == sourceId) || + (SourceIdGenerator::IsVideo(sourceId) && recParam.IsVideoParam() && + static_cast(videoSourceId_) == sourceId) || + ((sourceId == DUMMY_SOURCE_ID) && !(recParam.IsAudioParam() || recParam.IsVideoParam())), false); + return true; + } + + void HiRecorderImpl::OnStateChanged(StateId state) + { + curState_ = state; + } +} //namespace MEDIA +} //namespace OHOS diff --git a/services/engine/histreamer/recorder/hirecorder_impl.h b/services/engine/histreamer/recorder/hirecorder_impl.h new file mode 100644 index 000000000..bcc73ccb3 --- /dev/null +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023-2023 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 HI_RECORDER_IMPL_H +#define HI_RECORDER_IMPL_H + +#include "i_recorder_engine.h" +#include "recorder_utils.h" +#include "recorder_param.h" +#include "common/log.h" +#include "filter/filter_factory.h" +#include "osal/task/condition_variable.h" +#include "filter/filter.h" +#include "audio_capture_filter.h" +#include "encoder_filter.h" +#include "muxer_filter.h" +#include "osal/task/task.h" +#include "pipeline/pipeline.h" + +namespace OHOS { +namespace Media { + +enum class StateId { + INIT, + RECORDING_SETTING, + READY, + PAUSE, + RECORDING, + ERROR, + BUTT, +}; + +class HiRecorderImpl : public IRecorderEngine { +public: + HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId); + + ~HiRecorderImpl(); + + int32_t Init(); + + int32_t SetVideoSource(VideoSourceType source, int32_t &sourceId); + + int32_t SetAudioSource(AudioSourceType source, int32_t &sourceId); + + int32_t SetOutputFormat(OutputFormatType format); + + int32_t SetObs(const std::weak_ptr &obs); + + int32_t Configure(int32_t sourceId, const RecorderParam &recParam); + + sptr GetSurface(int32_t sourceId); + + int32_t Prepare(); + + int32_t Start(); + + int32_t Pause(); + + int32_t Resume(); + + int32_t Stop(bool isDrainAll); + + int32_t Reset(); + + int32_t SetParameter(int32_t sourceId, const RecorderParam &recParam); + + void OnEvent(const Event &event); + + void OnCallback(std::shared_ptr filter, const Pipeline::FilterCallBackCommand cmd, + Pipeline::StreamType outType); + +private: + void ConfigureAudioCapture(); + + void ConfigureAudio(const RecorderParam &recParam); + + void ConfigureVideo(const RecorderParam &recParam); + + void ConfigureMuxer(const RecorderParam &recParam); + + bool CheckParamType(int32_t sourceId, const RecorderParam &recParam); + + void OnStateChanged(StateId state); + + std::atomic audioCount_{0}; + std::atomic videoCount_{0}; + std::atomic audioSourceId_{0}; + std::atomic videoSourceId_{0}; + int32_t appUid_{0}; + int32_t appPid_{0}; + int32_t appTokenId_{0}; + int64_t appFullTokenId_{0}; + + std::shared_ptr pipeline_; + std::shared_ptr audioCaptureFilter_; + std::shared_ptr audioEncoderFilter_; + std::shared_ptr videoEncoderFilter_; + std::shared_ptr muxerFilter_; + + std::shared_ptr recorderEventReceiver_; + std::shared_ptr recorderCallback_; + + std::shared_ptr audioEncFormat_ = std::make_shared(); + std::shared_ptr videoEncFormat_ = std::make_shared(); + + std::atomic curState_; + + std::weak_ptr obs_{}; + OutputFormatType outputFormatType_{OutputFormatType::FORMAT_BUTT}; + int32_t fd_; + int64_t maxDuration_; + int64_t maxSize_; + + Mutex stateMutex_ {}; + ConditionVariable cond_ {}; + +}; +} //namespace MEDIA +} //namespace OHOS +#endif // HI_RECORDER_IMPL_H \ No newline at end of file diff --git a/services/engine/histreamer/recorder/recorder_utils.h b/services/engine/histreamer/recorder/recorder_utils.h new file mode 100644 index 000000000..fa5b119db --- /dev/null +++ b/services/engine/histreamer/recorder/recorder_utils.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023-2023 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 RECORDER_UTILS_H +#define RECORDER_UTILS_H + +#include + +namespace OHOS { +namespace Media { +constexpr uint8_t VIDEO_SOURCE_MAX_COUNT = 1; +constexpr uint8_t AUDIO_SOURCE_MAX_COUNT = 1; + +constexpr int32_t INVALID_SOURCE_ID = -1; + +struct SourceIdGenerator { + static const uint32_t SOURCE_MASK = 0xF00; + static const uint32_t VIDEO_MASK = 0x100; + static const uint32_t AUDIO_MASK = 0x200; + static const uint32_t INDEX_MASK = 0xFF; + + static int32_t GenerateAudioSourceId(uint32_t index) { + return static_cast(AUDIO_MASK + (INDEX_MASK & index)); + } + + static int32_t GenerateVideoSourceId(uint32_t index) { + return static_cast(VIDEO_MASK + (INDEX_MASK & index)); + } + + static int32_t IsAudio(int32_t sourceId) { + return ((sourceId > 0) && + ((static_cast(sourceId) & SOURCE_MASK) == AUDIO_MASK)); + } + + static int32_t IsVideo(int32_t sourceId) { + return ((sourceId > 0) && + ((static_cast(sourceId) & SOURCE_MASK) == VIDEO_MASK)); + } +}; +#endif // RECORDER_UTILS_H +} // Media +} // OHOS \ No newline at end of file diff --git a/services/include/i_avcodec_service.h b/services/include/i_avcodec_service.h index 5065a4f1d..8b832dd58 100644 --- a/services/include/i_avcodec_service.h +++ b/services/include/i_avcodec_service.h @@ -19,7 +19,7 @@ #include #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "refbase.h" #include "surface.h" diff --git a/services/include/i_avcodeclist_service.h b/services/include/i_avcodeclist_service.h index c9d70953a..7940c04d2 100644 --- a/services/include/i_avcodeclist_service.h +++ b/services/include/i_avcodeclist_service.h @@ -17,7 +17,7 @@ #define I_AVCODECLIST_SERVICE_H #include "avcodec_info.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/include/i_avmetadatahelper_service.h b/services/include/i_avmetadatahelper_service.h index 36ee3abee..1e9ecad76 100644 --- a/services/include/i_avmetadatahelper_service.h +++ b/services/include/i_avmetadatahelper_service.h @@ -17,7 +17,7 @@ #define IAVMETADATAHELPER_SERVICE_H #include "avmetadatahelper.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/include/i_screen_capture_service.h b/services/include/i_screen_capture_service.h index 7e6afa5e2..e4c9b3e4a 100644 --- a/services/include/i_screen_capture_service.h +++ b/services/include/i_screen_capture_service.h @@ -19,7 +19,7 @@ #include #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "refbase.h" #include "surface.h" #include "screen_capture.h" diff --git a/services/services/BUILD.gn b/services/services/BUILD.gn index 0536c4574..5cc2b150c 100644 --- a/services/services/BUILD.gn +++ b/services/services/BUILD.gn @@ -105,7 +105,6 @@ ohos_shared_library("media_service") { sources = [ "//foundation/multimedia/player_framework/frameworks/native/common/media_errors.cpp", - "//foundation/multimedia/player_framework/services/utils/avsharedmemorybase.cpp", "common/avsharedmemory_ipc.cpp", "factory/engine_factory_repo.cpp", "monitor/ipc/monitor_service_stub.cpp", @@ -183,7 +182,6 @@ ohos_shared_library("media_service") { deps = [ "//foundation/multimedia/player_framework/services/dfx:media_service_dfx", "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_format", "//foundation/multimedia/player_framework/services/utils:media_service_utils", "//third_party/libxml2:xml2", ] @@ -195,6 +193,7 @@ ohos_shared_library("media_service") { "hdf_core:libhdi", "hicollie:libhicollie", "hilog:libhilog", + "histreamer:media_foundation", "hitrace:hitrace_meter", "image_framework:image_native", "init:libbegetutil", diff --git a/services/services/avcodec/ipc/i_standard_avcodec_service.h b/services/services/avcodec/ipc/i_standard_avcodec_service.h index d544f9759..699db1817 100644 --- a/services/services/avcodec/ipc/i_standard_avcodec_service.h +++ b/services/services/avcodec/ipc/i_standard_avcodec_service.h @@ -22,7 +22,7 @@ #include "iremote_stub.h" #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "surface.h" namespace OHOS { diff --git a/services/services/avcodeclist/ipc/i_standard_avcodeclist_service.h b/services/services/avcodeclist/ipc/i_standard_avcodeclist_service.h index 0d5753b4b..eaf1bc929 100644 --- a/services/services/avcodeclist/ipc/i_standard_avcodeclist_service.h +++ b/services/services/avcodeclist/ipc/i_standard_avcodeclist_service.h @@ -21,7 +21,7 @@ #include "iremote_proxy.h" #include "iremote_stub.h" #include "avcodec_info.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/services/avmetadatahelper/ipc/helper_listener_stub.h b/services/services/avmetadatahelper/ipc/helper_listener_stub.h index 097d8b329..66969b77f 100644 --- a/services/services/avmetadatahelper/ipc/helper_listener_stub.h +++ b/services/services/avmetadatahelper/ipc/helper_listener_stub.h @@ -18,7 +18,7 @@ #include "i_standard_helper_listener.h" #include "avmetadatahelper.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/services/services/avmetadatahelper/ipc/i_standard_avmetadatahelper_service.h b/services/services/avmetadatahelper/ipc/i_standard_avmetadatahelper_service.h index 03ac58671..5756797c8 100644 --- a/services/services/avmetadatahelper/ipc/i_standard_avmetadatahelper_service.h +++ b/services/services/avmetadatahelper/ipc/i_standard_avmetadatahelper_service.h @@ -21,7 +21,7 @@ #include "iremote_proxy.h" #include "iremote_stub.h" #include "i_avmetadatahelper_service.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/services/common/avsharedmemory_ipc.cpp b/services/services/common/avsharedmemory_ipc.cpp index 93b5cb679..5e50b8085 100644 --- a/services/services/common/avsharedmemory_ipc.cpp +++ b/services/services/common/avsharedmemory_ipc.cpp @@ -15,7 +15,7 @@ #include "avsharedmemory_ipc.h" #include -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" #include "avdatasrcmemory.h" #include "media_errors.h" #include "media_log.h" diff --git a/services/services/common/avsharedmemory_ipc.h b/services/services/common/avsharedmemory_ipc.h index 91a41ba34..10d5d9bdb 100644 --- a/services/services/common/avsharedmemory_ipc.h +++ b/services/services/common/avsharedmemory_ipc.h @@ -17,7 +17,7 @@ #define AVSHAREDMEMORY_IPC_H #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/services/engine_intf/i_avcodec_engine.h b/services/services/engine_intf/i_avcodec_engine.h index 448bf0cb2..08d253ee7 100644 --- a/services/services/engine_intf/i_avcodec_engine.h +++ b/services/services/engine_intf/i_avcodec_engine.h @@ -23,8 +23,8 @@ #include "nocopyable.h" #include "avcodec_common.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" namespace OHOS { class Surface; diff --git a/services/services/engine_intf/i_avcodeclist_engine.h b/services/services/engine_intf/i_avcodeclist_engine.h index 2f1ccf134..dc39c1da6 100644 --- a/services/services/engine_intf/i_avcodeclist_engine.h +++ b/services/services/engine_intf/i_avcodeclist_engine.h @@ -23,8 +23,8 @@ #include #include "nocopyable.h" #include "avcodec_info.h" -#include "avsharedmemory.h" -#include "format.h" +#include "buffer/avsharedmemory.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/services/services/player/ipc/player_listener_stub.h b/services/services/player/ipc/player_listener_stub.h index 799b5d5ae..715531ea3 100644 --- a/services/services/player/ipc/player_listener_stub.h +++ b/services/services/player/ipc/player_listener_stub.h @@ -18,7 +18,7 @@ #include "i_standard_player_listener.h" #include "player.h" -#include "format.h" +#include "meta/format.h" #include "monitor_client_object.h" namespace OHOS { diff --git a/services/services/recorder_profiles/ipc/i_standard_recorder_profiles_service.h b/services/services/recorder_profiles/ipc/i_standard_recorder_profiles_service.h index cb483f083..57889ccba 100644 --- a/services/services/recorder_profiles/ipc/i_standard_recorder_profiles_service.h +++ b/services/services/recorder_profiles/ipc/i_standard_recorder_profiles_service.h @@ -21,7 +21,7 @@ #include "iremote_proxy.h" #include "iremote_stub.h" #include "i_recorder_profiles_service.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { diff --git a/services/services/sa_media/ipc/media_parcel.h b/services/services/sa_media/ipc/media_parcel.h index af9c902a3..8fce927a5 100644 --- a/services/services/sa_media/ipc/media_parcel.h +++ b/services/services/sa_media/ipc/media_parcel.h @@ -16,7 +16,7 @@ #ifndef MEDIA_PARCEL_H #define MEDIA_PARCEL_H -#include "format.h" +#include "meta/format.h" #include "message_parcel.h" namespace OHOS { diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn index 2a1f019da..b226c5efc 100644 --- a/services/utils/BUILD.gn +++ b/services/utils/BUILD.gn @@ -14,28 +14,6 @@ import("//build/ohos.gni") import("//foundation/multimedia/player_framework/config.gni") -ohos_static_library("media_format") { - sources = [ "format.cpp" ] - - include_dirs = [ - "//foundation/multimedia/player_framework/interfaces/inner_api/native", - "//foundation/multimedia/player_framework/services/utils/include", - "//commonlibrary/c_utils/base/include", - ] - - defines = [] - defines += player_framework_defines - deps = [ "//foundation/multimedia/player_framework/services/utils:media_service_utils" ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] - - subsystem_name = "multimedia" - part_name = "player_framework" -} - config("media_service_utils_public_config") { include_dirs = [ "include" ] } @@ -51,7 +29,6 @@ ohos_shared_library("media_service_utils") { sources = [ "avdatasrcmemory.cpp", - "avsharedmemorybase.cpp", "avsharedmemorypool.cpp", "media_dfx.cpp", "media_permission.cpp", @@ -103,6 +80,7 @@ ohos_shared_library("media_service_utils") { "c_utils:utils", "hicollie:libhicollie", "hilog:libhilog", + "histreamer:media_foundation", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbegetutil", diff --git a/services/utils/avsharedmemorybase.cpp b/services/utils/avsharedmemorybase.cpp deleted file mode 100644 index 8228eb20e..000000000 --- a/services/utils/avsharedmemorybase.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2021 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 "avsharedmemorybase.h" -#include -#include -#include "ashmem.h" -#include "media_errors.h" -#include "media_log.h" -#include "scope_guard.h" - -namespace { - constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVSharedMemoryBase"}; -} - -namespace OHOS { -namespace Media { -struct AVSharedMemoryBaseImpl : public AVSharedMemoryBase { -public: - AVSharedMemoryBaseImpl(int32_t fd, int32_t size, uint32_t flags, const std::string &name) - : AVSharedMemoryBase(fd, size, flags, name) {} -}; - -std::shared_ptr AVSharedMemoryBase::CreateFromLocal( - int32_t size, uint32_t flags, const std::string &name) -{ - std::shared_ptr memory = std::make_shared(size, flags, name); - int32_t ret = memory->Init(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "Create avsharedmemory failed, ret = %{public}d", ret); - - return memory; -} - -std::shared_ptr AVSharedMemoryBase::CreateFromRemote( - int32_t fd, int32_t size, uint32_t flags, const std::string &name) -{ - std::shared_ptr memory = std::make_shared(fd, size, flags, name); - int32_t ret = memory->Init(); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "Create avsharedmemory failed, ret = %{public}d", ret); - - return memory; -} - -AVSharedMemoryBase::AVSharedMemoryBase(int32_t size, uint32_t flags, const std::string &name) - : base_(nullptr), size_(size), flags_(flags), name_(name), fd_(-1) -{ - MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s", - FAKE_POINTER(this), name_.c_str()); -} - -AVSharedMemoryBase::AVSharedMemoryBase(int32_t fd, int32_t size, uint32_t flags, const std::string &name) - : base_(nullptr), size_(size), flags_(flags), name_(name), fd_(dup(fd)) -{ - MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s", - FAKE_POINTER(this), name_.c_str()); -} - -AVSharedMemoryBase::~AVSharedMemoryBase() -{ - MEDIA_LOGD("enter dtor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s", - FAKE_POINTER(this), name_.c_str()); - Close(); -} - -int32_t AVSharedMemoryBase::Init() -{ - ON_SCOPE_EXIT(0) { - MEDIA_LOGE("create avsharedmemory failed, name = %{public}s, size = %{public}d, " - "flags = 0x%{public}x, fd = %{public}d", - name_.c_str(), size_, flags_, fd_); - Close(); - }; - - CHECK_AND_RETURN_RET(size_ > 0, MSERR_INVALID_VAL); - - bool isRemote = false; - if (fd_ > 0) { - int size = AshmemGetSize(fd_); - CHECK_AND_RETURN_RET(size == size_, MSERR_INVALID_VAL); - isRemote = true; - } else { - fd_ = AshmemCreate(name_.c_str(), static_cast(size_)); - CHECK_AND_RETURN_RET(fd_ > 0, MSERR_INVALID_VAL); - } - - int32_t ret = MapMemory(isRemote); - CHECK_AND_RETURN_RET(ret == MSERR_OK, MSERR_INVALID_VAL); - - CANCEL_SCOPE_EXIT_GUARD(0); - return MSERR_OK; -} - -int32_t AVSharedMemoryBase::MapMemory(bool isRemote) -{ - unsigned int prot = PROT_READ | PROT_WRITE; - if (isRemote && (flags_ & FLAGS_READ_ONLY)) { - prot &= ~PROT_WRITE; - } - - int result = AshmemSetProt(fd_, static_cast(prot)); - CHECK_AND_RETURN_RET(result >= 0, MSERR_INVALID_OPERATION); - - void *addr = ::mmap(nullptr, static_cast(size_), static_cast(prot), MAP_SHARED, fd_, 0); - CHECK_AND_RETURN_RET(addr != MAP_FAILED, MSERR_INVALID_OPERATION); - - base_ = reinterpret_cast(addr); - return MSERR_OK; -} - -void AVSharedMemoryBase::Close() noexcept -{ - if (base_ != nullptr) { - (void)::munmap(base_, static_cast(size_)); - base_ = nullptr; - size_ = 0; - flags_ = 0; - } - - if (fd_ > 0) { - (void)::close(fd_); - fd_ = -1; - } -} -} // namespace Media -} // namespace OHOS diff --git a/services/utils/avsharedmemorypool.cpp b/services/utils/avsharedmemorypool.cpp index ac2cb9cde..2278c7124 100644 --- a/services/utils/avsharedmemorypool.cpp +++ b/services/utils/avsharedmemorypool.cpp @@ -14,7 +14,7 @@ */ #include "avsharedmemorypool.h" -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" #include "media_log.h" #include "media_errors.h" #include "scope_guard.h" diff --git a/services/utils/format.cpp b/services/utils/format.cpp deleted file mode 100644 index 8dc7bff0d..000000000 --- a/services/utils/format.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (C) 2021 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 "format.h" -#include "securec.h" -#include "media_log.h" -#include "media_errors.h" - -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "Format"}; -} - -namespace OHOS { -namespace Media { -void CopyFormatDataMap(const Format::FormatDataMap &from, Format::FormatDataMap &to) -{ - for (auto it = to.begin(); it != to.end(); ++it) { - if (it->second.type == FORMAT_TYPE_ADDR && it->second.addr != nullptr) { - free(it->second.addr); - it->second.addr = nullptr; - } - } - - to = from; - - for (auto it = to.begin(); it != to.end();) { - if (it->second.type != FORMAT_TYPE_ADDR || it->second.addr == nullptr) { - ++it; - continue; - } - - it->second.addr = reinterpret_cast(malloc(it->second.size)); - if (it->second.addr == nullptr) { - MEDIA_LOGE("malloc addr failed. Key: %{public}s", it->first.c_str()); - it = to.erase(it); - continue; - } - - errno_t err = memcpy_s(reinterpret_cast(it->second.addr), - it->second.size, reinterpret_cast(from.at(it->first).addr), it->second.size); - if (err != EOK) { - MEDIA_LOGE("memcpy addr failed. Key: %{public}s", it->first.c_str()); - free(it->second.addr); - it->second.addr = nullptr; - it = to.erase(it); - continue; - } - ++it; - } -} - -void CopyFormatVectorMap(const Format::FormatVectorMap &from, Format::FormatVectorMap &to) -{ - to = from; -} - -Format::~Format() -{ - for (auto it = formatMap_.begin(); it != formatMap_.end(); ++it) { - if (it->second.type == FORMAT_TYPE_ADDR && it->second.addr != nullptr) { - free(it->second.addr); - it->second.addr = nullptr; - } - } -} - -Format::Format(const Format &rhs) -{ - CHECK_AND_RETURN_LOG(&rhs != this, "Copying oneself is not supported"); - CopyFormatDataMap(rhs.formatMap_, formatMap_); - CopyFormatVectorMap(rhs.formatVecMap_, formatVecMap_); -} - -Format::Format(Format &&rhs) noexcept -{ - std::swap(formatMap_, rhs.formatMap_); - std::swap(formatVecMap_, rhs.formatVecMap_); -} - -Format &Format::operator=(const Format &rhs) -{ - CHECK_AND_RETURN_RET_LOG(&rhs != this, *this, "Copying oneself is not supported"); - CopyFormatDataMap(rhs.formatMap_, this->formatMap_); - CopyFormatVectorMap(rhs.formatVecMap_, this->formatVecMap_); - return *this; -} - -Format &Format::operator=(Format &&rhs) noexcept -{ - CHECK_AND_RETURN_RET_LOG(&rhs != this, *this, "Copying oneself is not supported"); - std::swap(this->formatMap_, rhs.formatMap_); - std::swap(this->formatVecMap_, rhs.formatVecMap_); - return *this; -} - -bool Format::PutIntValue(const std::string_view &key, int32_t value) -{ - FormatData data; - data.type = FORMAT_TYPE_INT32; - data.val.int32Val = value; - RemoveKey(key); - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::PutLongValue(const std::string_view &key, int64_t value) -{ - FormatData data; - data.type = FORMAT_TYPE_INT64; - data.val.int64Val = value; - RemoveKey(key); - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::PutFloatValue(const std::string_view &key, float value) -{ - FormatData data; - data.type = FORMAT_TYPE_FLOAT; - data.val.floatVal = value; - RemoveKey(key); - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::PutDoubleValue(const std::string_view &key, double value) -{ - FormatData data; - data.type = FORMAT_TYPE_DOUBLE; - data.val.doubleVal = value; - RemoveKey(key); - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::PutStringValue(const std::string_view &key, const std::string_view &value) -{ - FormatData data; - data.type = FORMAT_TYPE_STRING; - data.stringVal = value; - RemoveKey(key); - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::GetStringValue(const std::string_view &key, std::string &value) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_STRING, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - value = iter->second.stringVal; - return true; -} - -bool Format::GetIntValue(const std::string_view &key, int32_t &value) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_INT32, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - value = iter->second.val.int32Val; - return true; -} - -bool Format::GetLongValue(const std::string_view &key, int64_t &value) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_INT64, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - value = iter->second.val.int64Val; - return true; -} - -bool Format::GetFloatValue(const std::string_view &key, float &value) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_FLOAT, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - value = iter->second.val.floatVal; - return true; -} - -bool Format::GetDoubleValue(const std::string_view &key, double &value) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_DOUBLE, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - value = iter->second.val.doubleVal; - return true; -} - -bool Format::PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size) -{ - CHECK_AND_RETURN_RET_LOG(addr != nullptr, false, "put buffer error, addr is nullptr"); - constexpr size_t sizeMax = 1 * 1024 * 1024; - CHECK_AND_RETURN_RET_LOG(size <= sizeMax, false, - "PutBuffer input size too large. Key: %{public}s", key.data()); - - FormatData data; - data.type = FORMAT_TYPE_ADDR; - data.addr = reinterpret_cast(malloc(size)); - CHECK_AND_RETURN_RET_LOG(data.addr != nullptr, false, - "malloc addr failed. Key: %{public}s", key.data()); - - errno_t err = memcpy_s(reinterpret_cast(data.addr), size, reinterpret_cast(addr), size); - if (err != EOK) { - MEDIA_LOGE("PutBuffer memcpy addr failed. Key: %{public}s", key.data()); - free(data.addr); - return false; - } - - RemoveKey(key); - - data.size = size; - auto ret = formatMap_.insert(std::make_pair(key, data)); - return ret.second; -} - -bool Format::GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) const -{ - auto iter = formatMap_.find(key); - CHECK_AND_RETURN_RET_LOG(iter != formatMap_.end(), false, - "Format::GetFormat iter failed. Key: %{public}s", key.data()); - CHECK_AND_RETURN_RET_LOG(iter->second.type == FORMAT_TYPE_ADDR, false, - "Format::GetFormat type failed. Key: %{public}s", key.data()); - *addr = iter->second.addr; - size = iter->second.size; - return true; -} - -bool Format::PutFormatVector(const std::string_view &key, std::vector &value) -{ - RemoveKey(key); - auto ret = formatVecMap_.insert(std::make_pair(key, value)); - return ret.second; -} - -bool Format::GetFormatVector(const std::string_view &key, std::vector &value) const -{ - auto iter = formatVecMap_.find(key); - if (iter == formatVecMap_.end()) { - MEDIA_LOGE("Format::GetFormatVector failed. Key: %{public}s", key.data()); - return false; - } - value.assign(iter->second.begin(), iter->second.end()); - return true; -} - -bool Format::ContainKey(const std::string_view &key) const -{ - auto iter = formatMap_.find(key); - if (iter != formatMap_.end()) { - return true; - } - - return false; -} - -FormatDataType Format::GetValueType(const std::string_view &key) const -{ - auto iter = formatMap_.find(key); - if (iter == formatMap_.end()) { - return FORMAT_TYPE_NONE; - } - - return iter->second.type; -} - -void Format::RemoveKey(const std::string_view &key) -{ - auto iter = formatMap_.find(key); - if (iter != formatMap_.end()) { - if (iter->second.type == FORMAT_TYPE_ADDR && iter->second.addr != nullptr) { - free(iter->second.addr); - iter->second.addr = nullptr; - } - formatMap_.erase(iter); - } - - auto vecMapIter = formatVecMap_.find(key); - if (vecMapIter != formatVecMap_.end()) { - formatVecMap_.erase(vecMapIter); - } -} - -const Format::FormatDataMap &Format::GetFormatMap() const -{ - return formatMap_; -} - -const Format::FormatVectorMap &Format::GetFormatVectorMap() const -{ - return formatVecMap_; -} - -std::string Format::Stringify() const -{ - std::string outString; - for (auto iter = formatMap_.begin(); iter != formatMap_.end(); iter++) { - switch (GetValueType(iter->first)) { - case FORMAT_TYPE_INT32: - outString += iter->first + " = " + std::to_string(iter->second.val.int32Val) + " | "; - break; - case FORMAT_TYPE_INT64: - outString += iter->first + " = " + std::to_string(iter->second.val.int64Val) + " | "; - break; - case FORMAT_TYPE_FLOAT: - outString += iter->first + " = " + std::to_string(iter->second.val.floatVal) + " | "; - break; - case FORMAT_TYPE_DOUBLE: - outString += iter->first + " = " + std::to_string(iter->second.val.doubleVal) + " | "; - break; - case FORMAT_TYPE_STRING: - outString += iter->first + " = " + iter->second.stringVal + " | "; - break; - case FORMAT_TYPE_ADDR: - break; - default: - MEDIA_LOGE("Format::Stringify failed. Key: %{public}s", iter->first.c_str()); - } - } - return outString; -} -} // namespace Media -} // namespace OHOS \ No newline at end of file diff --git a/services/utils/include/avdatasrcmemory.h b/services/utils/include/avdatasrcmemory.h index f03492d39..4cfacb694 100644 --- a/services/utils/include/avdatasrcmemory.h +++ b/services/utils/include/avdatasrcmemory.h @@ -18,7 +18,7 @@ #include #include "nocopyable.h" -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" namespace OHOS { namespace Media { diff --git a/services/utils/include/avsharedmemorybase.h b/services/utils/include/avsharedmemorybase.h deleted file mode 100644 index c13636d19..000000000 --- a/services/utils/include/avsharedmemorybase.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 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 AVSHAREDMEMORYBASE_H -#define AVSHAREDMEMORYBASE_H - -#include -#include "nocopyable.h" -#include "avsharedmemory.h" - -namespace OHOS { -namespace Media { -class __attribute__((visibility("default"))) AVSharedMemoryBase - : public AVSharedMemory, public NoCopyable { -public: - /** - * @brief Construct a new AVSharedMemoryBase object. This function should only be used in the - * local process. - * - * @param size the memory's size, bytes. - * @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}. - * @param name the debug string - */ - static std::shared_ptr CreateFromLocal( - int32_t size, uint32_t flags, const std::string &name); - - /** - * @brief Construct a new AVSharedMemoryBase object. This function should only be used in the - * remote process. - * - * @param fd the memory's fd - * @param size the memory's size, bytes. - * @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}. - * @param name the debug string - */ - static std::shared_ptr CreateFromRemote( - int32_t fd, int32_t size, uint32_t flags, const std::string &name); - - ~AVSharedMemoryBase(); - - /** - * @brief Construct a new AVSharedMemoryBase object. This function should only be used in the - * local process. - * - * @param size the memory's size, bytes. - * @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}. - * @param name the debug string - */ - AVSharedMemoryBase(int32_t size, uint32_t flags, const std::string &name); - - /** - * @brief Intialize the memory. Call this interface firstly before the other interface. - * @return MSERR_OK if success, otherwise the errcode. - */ - int32_t Init(); - - /** - * @brief Get the memory's fd, which only valid when the underlying memory - * chunk is allocated through the ashmem. - * @return the memory's fd if the memory is allocated through the ashmem, otherwise -1. - */ - int32_t GetFd() const - { - return fd_; - } - - std::string GetName() const - { - return name_; - } - - /** - * @brief Get the memory's virtual address - * @return the memory's virtual address if the memory is valid, otherwise nullptr. - */ - virtual uint8_t *GetBase() const override - { - return base_; - } - - /** - * @brief Get the memory's size - * @return the memory's size if the memory is valid, otherwise -1. - */ - virtual int32_t GetSize() const override - { - return (base_ != nullptr) ? size_ : -1; - } - - /** - * @brief Get the memory's flags set by the creator, refer to {@Flags} - * @return the memory's flags if the memory is valid, otherwise 0. - */ - virtual uint32_t GetFlags() const final - { - return (base_ != nullptr) ? flags_ : 0; - } - -protected: - AVSharedMemoryBase(int32_t fd, int32_t size, uint32_t flags, const std::string &name); - -private: - int32_t MapMemory(bool isRemote); - void Close() noexcept; - - uint8_t *base_; - int32_t size_; - uint32_t flags_; - std::string name_; - int32_t fd_; -}; -} // namespace Media -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/services/utils/include/avsharedmemorypool.h b/services/utils/include/avsharedmemorypool.h index f1b189759..22a15d63a 100644 --- a/services/utils/include/avsharedmemorypool.h +++ b/services/utils/include/avsharedmemorypool.h @@ -22,7 +22,7 @@ #include #include #include "nocopyable.h" -#include "avsharedmemorybase.h" +#include "buffer/avsharedmemorybase.h" namespace OHOS { namespace Media { diff --git a/test/fuzztest/avmetadata_fuzztest/avmetadatastub_fuzzer/BUILD.gn b/test/fuzztest/avmetadata_fuzztest/avmetadatastub_fuzzer/BUILD.gn index 2ee196678..bafec71ec 100644 --- a/test/fuzztest/avmetadata_fuzztest/avmetadatastub_fuzzer/BUILD.gn +++ b/test/fuzztest/avmetadata_fuzztest/avmetadatastub_fuzzer/BUILD.gn @@ -61,10 +61,7 @@ ohos_fuzztest("AVmetadataStubFuzzTest") { "avmetadatastub_fuzzer.cpp", ] } - deps = [ - "../../../../services/services:media_service", - "../../../../services/utils:media_format", - ] + deps = [ "../../../../services/services:media_service" ] external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/BUILD.gn b/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/BUILD.gn index 1aecd59f9..3f3f5a208 100644 --- a/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/BUILD.gn +++ b/test/fuzztest/player_fuzztest/playerservicestub_fuzzer/BUILD.gn @@ -56,10 +56,7 @@ ohos_fuzztest("PlayerServiceStubFuzzTest") { if (multimedia_player_framework_support_player) { sources = [ "playerservicestub_fuzzer.cpp" ] } - deps = [ - "../../../../services/services:media_service", - "../../../../services/utils:media_format", - ] + deps = [ "../../../../services/services:media_service" ] external_deps = [ "c_utils:utils", "drivers_peripheral_display:hdi_gralloc_client", diff --git a/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn b/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn index 4fee175ae..25eba518b 100644 --- a/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn +++ b/test/fuzztest/player_fuzztest/playerstub_fuzzer/BUILD.gn @@ -62,10 +62,7 @@ ohos_fuzztest("PlayerStubFuzzTest") { "playerstub_fuzzer.cpp", ] } - deps = [ - "../../../../services/services:media_service", - "../../../../services/utils:media_format", - ] + deps = [ "../../../../services/services:media_service" ] external_deps = [ "c_utils:utils", "graphic_2d:surface", diff --git a/test/unittest/avcodec_test/native/avformat/avformat_native_mock.h b/test/unittest/avcodec_test/native/avformat/avformat_native_mock.h index e4d12792f..ecc7c5ac7 100644 --- a/test/unittest/avcodec_test/native/avformat/avformat_native_mock.h +++ b/test/unittest/avcodec_test/native/avformat/avformat_native_mock.h @@ -17,7 +17,7 @@ #define AVFORMAT_NATIVE_MOCK_H #include "avcodec_mock.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace Media { diff --git a/test/unittest/avcodec_test/native/avmemory/avmemory_native_mock.h b/test/unittest/avcodec_test/native/avmemory/avmemory_native_mock.h index a22ac59d9..56d71b99d 100644 --- a/test/unittest/avcodec_test/native/avmemory/avmemory_native_mock.h +++ b/test/unittest/avcodec_test/native/avmemory/avmemory_native_mock.h @@ -17,7 +17,7 @@ #define AVMEMORY_NATIVE_MOCK_H #include "avcodec_mock.h" -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" namespace OHOS { namespace Media { -- Gitee From f3c864a83d4c6652084286bc1cb474e965062199 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Fri, 15 Dec 2023 05:22:19 +0000 Subject: [PATCH 2/8] Media Refactor. solve compile dependency of histreamer:media_foundation Signed-off-by: yuanjinghua Change-Id: I174f8b3296895589d6ecd14d089ba55c1dbc3092 --- bundle.json | 1 + frameworks/js/system_sound_manager/BUILD.gn | 1 + services/engine/gstreamer/avcodec/BUILD.gn | 1 + services/engine/gstreamer/avmetadatahelper/BUILD.gn | 1 + services/engine/gstreamer/player/BUILD.gn | 1 + services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn | 1 + services/engine/gstreamer/plugins/sink/memsink/BUILD.gn | 1 + services/engine/gstreamer/plugins/source/memsource/BUILD.gn | 1 + 8 files changed, 8 insertions(+) diff --git a/bundle.json b/bundle.json index 11ef3afa5..830b7a5ee 100644 --- a/bundle.json +++ b/bundle.json @@ -55,6 +55,7 @@ "input", "memmgr_plugin", "hicollie", + "histreamer", "drivers_peripheral_codec", "drivers_peripheral_display", "hdf_core", diff --git a/frameworks/js/system_sound_manager/BUILD.gn b/frameworks/js/system_sound_manager/BUILD.gn index 66838cd24..9936449a7 100644 --- a/frameworks/js/system_sound_manager/BUILD.gn +++ b/frameworks/js/system_sound_manager/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("systemsoundmanager") { "audio_framework:audio_client", "c_utils:utils", "hilog:libhilog", + "histreamer:media_foundation", "ipc:ipc_single", "napi:ace_napi", "resource_management:global_resmgr", diff --git a/services/engine/gstreamer/avcodec/BUILD.gn b/services/engine/gstreamer/avcodec/BUILD.gn index 6ffa08105..aa545f1b2 100644 --- a/services/engine/gstreamer/avcodec/BUILD.gn +++ b/services/engine/gstreamer/avcodec/BUILD.gn @@ -108,6 +108,7 @@ ohos_static_library("media_engine_gst_avcodec") { "drivers_peripheral_display:hdi_gralloc_client", "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", ] subsystem_name = "multimedia" diff --git a/services/engine/gstreamer/avmetadatahelper/BUILD.gn b/services/engine/gstreamer/avmetadatahelper/BUILD.gn index ffdf2fe18..50a7d3a75 100644 --- a/services/engine/gstreamer/avmetadatahelper/BUILD.gn +++ b/services/engine/gstreamer/avmetadatahelper/BUILD.gn @@ -92,6 +92,7 @@ ohos_static_library("media_engine_gst_avmeta") { external_deps = [ "hilog:libhilog", + "histreamer:media_foundation", "image_framework:image_native", ] diff --git a/services/engine/gstreamer/player/BUILD.gn b/services/engine/gstreamer/player/BUILD.gn index 1dd53e511..c8d780e1b 100644 --- a/services/engine/gstreamer/player/BUILD.gn +++ b/services/engine/gstreamer/player/BUILD.gn @@ -100,6 +100,7 @@ ohos_static_library("media_engine_gst_player") { "graphic_2d:surface", "hilog:libhilog", "init:libbegetutil", + "histreamer:media_foundation", ] if (multimedia_player_framework_support_drm) { diff --git a/services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn b/services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn index 70d6085a9..a3c964b8f 100644 --- a/services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn +++ b/services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn @@ -120,6 +120,7 @@ ohos_shared_library("gst_codec_plugin_hdi") { "hdf_core:libhdf_utils", "hdf_core:libhdi", "hilog:libhilog", + "histreamer:media_foundation", ] relative_install_dir = "media/plugins" diff --git a/services/engine/gstreamer/plugins/sink/memsink/BUILD.gn b/services/engine/gstreamer/plugins/sink/memsink/BUILD.gn index 6f7fad028..20201f45a 100644 --- a/services/engine/gstreamer/plugins/sink/memsink/BUILD.gn +++ b/services/engine/gstreamer/plugins/sink/memsink/BUILD.gn @@ -91,6 +91,7 @@ ohos_shared_library("gst_mem_sink") { "graphic_2d:surface", "graphic_2d:sync_fence", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", ] diff --git a/services/engine/gstreamer/plugins/source/memsource/BUILD.gn b/services/engine/gstreamer/plugins/source/memsource/BUILD.gn index 28387dbec..922ff1d30 100644 --- a/services/engine/gstreamer/plugins/source/memsource/BUILD.gn +++ b/services/engine/gstreamer/plugins/source/memsource/BUILD.gn @@ -97,6 +97,7 @@ ohos_shared_library("gst_mem_src") { "graphic_2d:surface", "graphic_2d:sync_fence", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", ] -- Gitee From bfdcefbf62b8debd9ad83518d97646e4e2e60f02 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sat, 16 Dec 2023 08:30:21 +0000 Subject: [PATCH 3/8] Media Refactor. solve CI errors and warnings Signed-off-by: yuanjinghua Change-Id: Ie3822babc77389f868d0df6a7a461c75c31f12a3 --- config.gni | 3 + services/engine/gstreamer/player/BUILD.gn | 2 +- .../histreamer/avmetadatahelper/BUILD.gn | 28 +++--- .../avmetadatahelper/avmetadata_collector.cpp | 36 ++++---- .../avmetadatahelper_impl.cpp | 26 +++--- services/engine/histreamer/factory/BUILD.gn | 30 +++---- .../histreamer/factory/engine_factory.cpp | 19 +--- services/engine/histreamer/player/BUILD.gn | 30 +++---- .../player/hiplayer_callback_looper.cpp | 20 ++--- .../player/hiplayer_callback_looper.h | 2 +- .../histreamer/player/hiplayer_impl.cpp | 79 ++++++++--------- .../engine/histreamer/player/hiplayer_impl.h | 41 ++++----- services/engine/histreamer/recorder/BUILD.gn | 34 ++++---- .../histreamer/recorder/hirecorder_impl.cpp | 86 ++++++++++++------- .../histreamer/recorder/hirecorder_impl.h | 5 +- .../histreamer/recorder/recorder_utils.h | 12 ++- 16 files changed, 228 insertions(+), 225 deletions(-) diff --git a/config.gni b/config.gni index da8dd3800..6f125bad7 100644 --- a/config.gni +++ b/config.gni @@ -151,6 +151,9 @@ if (multimedia_player_framework_support_vibrator) { # Config path MEDIA_PLAYER_ROOT_DIR = "//foundation/multimedia/player_framework" MEDIA_PLAYER_AVCODEC = "//foundation/multimedia/av_codec" +MEDIA_PLAYER_HISTREAMER = "//foundation/multimedia/histreamer" + +MEDIA_PLAYER_C_UTILS = "//commonlibrary/c_utils" MEDIA_PLAYER_GRAPHIC = "//foundation/graphic/graphic_2d" # Fuzz test output path diff --git a/services/engine/gstreamer/player/BUILD.gn b/services/engine/gstreamer/player/BUILD.gn index c8d780e1b..1bbe39fd6 100644 --- a/services/engine/gstreamer/player/BUILD.gn +++ b/services/engine/gstreamer/player/BUILD.gn @@ -99,8 +99,8 @@ ohos_static_library("media_engine_gst_player") { "drivers_peripheral_display:hdi_gralloc_client", "graphic_2d:surface", "hilog:libhilog", - "init:libbegetutil", "histreamer:media_foundation", + "init:libbegetutil", ] if (multimedia_player_framework_support_drm) { diff --git a/services/engine/histreamer/avmetadatahelper/BUILD.gn b/services/engine/histreamer/avmetadatahelper/BUILD.gn index e3137ad5b..3b1e7711e 100644 --- a/services/engine/histreamer/avmetadatahelper/BUILD.gn +++ b/services/engine/histreamer/avmetadatahelper/BUILD.gn @@ -33,16 +33,16 @@ config("media_engine_histreamer_avmetadatahelper_config") { cflags_cc = cflags include_dirs = [ - "//foundation/multimedia/player_framework/services/engine/histreamer/avmetadatahelper", - "//foundation/multimedia/player_framework/services/include", - "//foundation/multimedia/player_framework/services/utils/include", - "//foundation/multimedia/player_framework/interfaces/inner_api/native", - "//foundation/multimedia/player_framework/services/services/engine_intf", - "//commonlibrary/c_utils/base/include", - "//foundation/multimedia/histreamer/interface/inner_api", - "//foundation/multimedia/av_codec/interfaces/inner_api/native", - "//foundation/multimedia/av_codec/interfaces", - "//foundation/multimedia/av_codec/services/media_engine/modules", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/avmetadatahelper", + "$MEDIA_PLAYER_ROOT_DIR/services/include", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_C_UTILS/base/include", + "$MEDIA_PLAYER_HISTREAMER/interface/inner_api", + "$MEDIA_PLAYER_AVCODEC/interfaces/inner_api/native", + "$MEDIA_PLAYER_AVCODEC/interfaces", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules", ] } @@ -59,13 +59,13 @@ ohos_static_library("media_engine_histreamer_avmetadatahelper") { configs = [ ":media_engine_histreamer_avmetadatahelper_config", - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", - "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", ] deps = [ - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_service_utils", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", ] external_deps = [ diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 340116e9a..190150022 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -22,24 +22,24 @@ namespace Media { #define AVMETA_KEY_TO_X_MAP_ITEM(key, innerKey) { key, innerKey } static const std::unordered_map AVMETA_KEY_TO_X_MAP = { - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ALBUM, Tag::MEDIA_ALBUM), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ALBUM_ARTIST, Tag::MEDIA_ALBUM_ARTIST), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_ARTIST, Tag::MEDIA_ARTIST), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_AUTHOR, Tag::MEDIA_AUTHOR), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_COMPOSER, Tag::MEDIA_COMPOSER), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DATE_TIME, Tag::MEDIA_DATE), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DATE_TIME_FORMAT, ""), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_DURATION, Tag::MEDIA_DURATION), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_GENRE, Tag::MEDIA_GENRE), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_HAS_AUDIO, Tag::MEDIA_HAS_AUDIO), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_HAS_VIDEO, Tag::MEDIA_HAS_VIDEO), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_MIME_TYPE, Tag::MIME_TYPE), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_NUM_TRACKS, Tag::MEDIA_TRACK_COUNT), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_SAMPLE_RATE, Tag::AUDIO_SAMPLE_RATE), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_TITLE, Tag::MEDIA_TITLE), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_HEIGHT, Tag::VIDEO_HEIGHT), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_WIDTH, Tag::VIDEO_WIDTH), - AVMETA_KEY_TO_X_MAP_ITEM(AV_KEY_VIDEO_ORIENTATION, Tag::VIDEO_ROTATION), + { AV_KEY_ALBUM, Tag::MEDIA_ALBUM }, + { AV_KEY_ALBUM_ARTIST, Tag::MEDIA_ALBUM_ARTIST }, + { AV_KEY_ARTIST, Tag::MEDIA_ARTIST }, + { AV_KEY_AUTHOR, Tag::MEDIA_AUTHOR }, + { AV_KEY_COMPOSER, Tag::MEDIA_COMPOSER }, + { AV_KEY_DATE_TIME, Tag::MEDIA_DATE }, + { AV_KEY_DATE_TIME_FORMAT, "" }, + { AV_KEY_DURATION, Tag::MEDIA_DURATION }, + { AV_KEY_GENRE, Tag::MEDIA_GENRE }, + { AV_KEY_HAS_AUDIO, Tag::MEDIA_HAS_AUDIO }, + { AV_KEY_HAS_VIDEO, Tag::MEDIA_HAS_VIDEO }, + { AV_KEY_MIME_TYPE, Tag::MIME_TYPE }, + { AV_KEY_NUM_TRACKS, Tag::MEDIA_TRACK_COUNT }, + { AV_KEY_SAMPLE_RATE, Tag::AUDIO_SAMPLE_RATE }, + { AV_KEY_TITLE, Tag::MEDIA_TITLE }, + { AV_KEY_VIDEO_HEIGHT, Tag::VIDEO_HEIGHT }, + { AV_KEY_VIDEO_WIDTH, Tag::VIDEO_WIDTH }, + { AV_KEY_VIDEO_ORIENTATION, Tag::VIDEO_ROTATION }, }; AVMetaDataCollector::AVMetaDataCollector() diff --git a/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp index e033e652b..45c1de0c3 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp @@ -29,11 +29,13 @@ static const std::set SUPPORTED_PIXELFORMAT = { class HelperEventReceiver : public Pipeline::EventReceiver { public: - HelperEventReceiver(AVMetadataHelperImpl* helperImpl) { + explicit HelperEventReceiver(AVMetadataHelperImpl* helperImpl) + { helperImpl_ = helperImpl; } - void OnEvent(const Event &event) { + void OnEvent(const Event &event) + { helperImpl_->OnEvent(event); } @@ -43,11 +45,14 @@ private: class HelperFilterCallback : public Pipeline::FilterCallback { public: - HelperFilterCallback(AVMetadataHelperImpl* helperImpl) { + explicit HelperFilterCallback(AVMetadataHelperImpl* helperImpl) + { helperImpl_ = helperImpl; } - void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) { + void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, + Pipeline::StreamType outType) + { helperImpl_->OnCallback(filter, cmd, outType); } @@ -60,7 +65,7 @@ void AVMetadataHelperImpl::OnEvent(const Event &event) } void AVMetadataHelperImpl::OnCallback(std::shared_ptr filter, -const Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) + const Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) { } @@ -94,8 +99,8 @@ int32_t AVMetadataHelperImpl::SetSource(const std::string &uri, int32_t usage) if (usage == AVMetadataUsage::AV_META_USAGE_PIXEL_MAP) { pipeline_ = std::make_shared(); - demuxerFilter_ = Pipeline::FilterFactory::Instance().CreateFilter("builtin.player.demuxer", - Pipeline::FilterType::FILTERTYPE_DEMUXER); + demuxerFilter_ = Pipeline::FilterFactory::Instance().CreateFilter( + "builtin.player.demuxer", Pipeline::FilterType::FILTERTYPE_DEMUXER); FALSE_RETURN_V(demuxerFilter_ != nullptr, MSERR_INVALID_VAL); std::shared_ptr eventReceiver = std::make_shared( @@ -103,8 +108,8 @@ int32_t AVMetadataHelperImpl::SetSource(const std::string &uri, int32_t usage) std::shared_ptr filterCallback = std::make_shared( this); pipeline_->Init(eventReceiver, filterCallback); - videoDecoderFilter_ = Pipeline::FilterFactory::Instance().CreateFilter("builtin.player.videodecoder", - Pipeline::FilterType::FILTERTYPE_VDEC); + videoDecoderFilter_ = Pipeline::FilterFactory::Instance().CreateFilter( + "builtin.player.videodecoder", Pipeline::FilterType::FILTERTYPE_VDEC); FALSE_RETURN_V(videoDecoderFilter_ != nullptr, MSERR_INVALID_VAL); } else { mediaDemuxer_ = std::make_shared(); @@ -158,7 +163,7 @@ std::shared_ptr AVMetadataHelperImpl::FetchArtPicture() } std::shared_ptr AVMetadataHelperImpl::FetchFrameAtTime( - int64_t /* timeUs */, int32_t /* option */, const OutputConfiguration &/* param */) + int64_t timeUs, int32_t option, const OutputConfiguration ¶m) { MEDIA_LOG_I("enter FetchFrameAtTime"); return nullptr; @@ -225,7 +230,6 @@ void AVMetadataHelperImpl::Reset() } errHappened_ = false; - firstFetch_ = true; } } // namespace Media diff --git a/services/engine/histreamer/factory/BUILD.gn b/services/engine/histreamer/factory/BUILD.gn index bf5f6bf67..4e5181209 100644 --- a/services/engine/histreamer/factory/BUILD.gn +++ b/services/engine/histreamer/factory/BUILD.gn @@ -29,20 +29,20 @@ config("media_engine_histreamer_factory_config") { cflags_cc = cflags include_dirs = [ - "//commonlibrary/c_utils/base/include", - "//foundation/multimedia/player_framework/services/include", - "//foundation/multimedia/player_framework/services/services/engine_intf", - "//foundation/multimedia/player_framework/services/engine/histreamer/player", - "//foundation/multimedia/player_framework/services/engine/histreamer/recorder", - "//foundation/multimedia/player_framework/services/engine/histreamer/avmetadatahelper", - "//foundation/multimedia/player_framework/services/utils/include", - "//foundation/multimedia/player_framework/interfaces/inner_api/native", - "//foundation/multimedia/histreamer/interface/inner_api", - "//foundation/multimedia/av_codec/interfaces/inner_api/native", - "//foundation/multimedia/av_codec/interfaces", - "//foundation/multimedia/histreamer/src", - "//foundation/multimedia/av_codec/services/media_engine/modules/source/audio_capture", - "//foundation/multimedia/av_codec/services/media_engine/modules/", + "$MEDIA_PLAYER_C_UTILS/base/include", + "$MEDIA_PLAYER_ROOT_DIR/services/include", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/recorder", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/avmetadatahelper", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_HISTREAMER/interface/inner_api", + "$MEDIA_PLAYER_AVCODEC/interfaces/inner_api/native", + "$MEDIA_PLAYER_AVCODEC/interfaces", + "$MEDIA_PLAYER_HISTREAMER/src", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/source/audio_capture", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/", ] defines = [ "HST_ANY_WITH_NO_RTTI", @@ -61,7 +61,7 @@ ohos_static_library("media_engine_histreamer_factory") { configs = [ ":media_engine_histreamer_factory_config", - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIRa_service_log_dfx_public_config", ] deps = [ "../../../dfx:media_service_log_dfx" ] diff --git a/services/engine/histreamer/factory/engine_factory.cpp b/services/engine/histreamer/factory/engine_factory.cpp index 36a6deea1..7f9c9b57a 100644 --- a/services/engine/histreamer/factory/engine_factory.cpp +++ b/services/engine/histreamer/factory/engine_factory.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ -#ifndef HISTREAMER_HST_ENGINE_FACTORY_H -#define HISTREAMER_HST_ENGINE_FACTORY_H - #include "i_engine_factory.h" #include "media_errors.h" #include "common/log.h" @@ -51,14 +48,6 @@ int32_t HstEngineFactory::Score(Scene scene, const std::string& uri) { MEDIA_LOG_E("Score in"); (void)uri; - // if (scene == Scene::SCENE_PLAYBACK || scene == Scene::SCENE_RECORDER) { - // char useHistreamer[10] = {0}; // 10 for system parameter usage - // auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer)); - // if (res == 1 && useHistreamer[0] == '1') { - // MEDIA_LOG_I("enable histreamer"); - // return MAX_SCORE; - // } - // } return MAX_SCORE; } @@ -123,14 +112,8 @@ extern "C" { #endif __attribute__((visibility("default"))) OHOS::Media::IEngineFactory *CreateEngineFactory() { - // int32_t ret = OHOS::Media::GstLoader::Instance().SetUp(); - // if (ret != OHOS::Media::MSERR_OK) { - // MEDIA_LOGE("Gst Engine setup failed, ret = %{public}d", ret); - // return nullptr; - // } return new (std::nothrow) OHOS::Media::HstEngineFactory(); } #ifdef __cplusplus } -#endif -#endif // HISTREAMER_HST_ENGINE_FACTORY_H +#endif \ No newline at end of file diff --git a/services/engine/histreamer/player/BUILD.gn b/services/engine/histreamer/player/BUILD.gn index 90cc74412..e8f27abe4 100644 --- a/services/engine/histreamer/player/BUILD.gn +++ b/services/engine/histreamer/player/BUILD.gn @@ -33,17 +33,17 @@ config("media_engine_histreamer_player_config") { cflags_cc = cflags include_dirs = [ - "//foundation/multimedia/player_framework/services/engine/histreamer/player", - "//foundation/multimedia/player_framework/services/utils/include", - "//foundation/multimedia/player_framework/interfaces/inner_api/native", - "//foundation/multimedia/player_framework/services/services/engine_intf", - "//commonlibrary/c_utils/base/include", - "//foundation/multimedia/histreamer/interface/inner_api", - "//foundation/multimedia/av_codec/interfaces/inner_api/native", - "//foundation/multimedia/av_codec/interfaces", - "//foundation/multimedia/histreamer/src", - "//foundation/multimedia/av_codec/services/media_engine/modules/sink", - "//foundation/multimedia/av_codec/services/media_engine/modules", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/player", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_C_UTILS/base/include", + "$MEDIA_PLAYER_HISTREAMER/interface/inner_api", + "$MEDIA_PLAYER_AVCODEC/interfaces/inner_api/native", + "$MEDIA_PLAYER_AVCODEC/interfaces", + "$MEDIA_PLAYER_HISTREAMER/src", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/sink", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules", ] } @@ -60,13 +60,13 @@ ohos_static_library("media_engine_histreamer_player") { configs = [ ":media_engine_histreamer_player_config", - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", - "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", ] deps = [ - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_service_utils", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", ] external_deps = [ diff --git a/services/engine/histreamer/player/hiplayer_callback_looper.cpp b/services/engine/histreamer/player/hiplayer_callback_looper.cpp index b7791f42f..848bde56f 100644 --- a/services/engine/histreamer/player/hiplayer_callback_looper.cpp +++ b/services/engine/histreamer/player/hiplayer_callback_looper.cpp @@ -19,8 +19,6 @@ #include #include "common/log.h" #include "osal/task/autolock.h" -//#include "foundation/utils/steady_clock.h" -//#include "media_errors.h" namespace OHOS { namespace Media { @@ -29,6 +27,10 @@ constexpr int32_t WHAT_NONE = 0; constexpr int32_t WHAT_MEDIA_PROGRESS = 1; constexpr int32_t WHAT_INFO = 2; constexpr int32_t WHAT_ERROR = 3; + +constexpr int32_t TUPLE_POS_0 = 0; +constexpr int32_t TUPLE_POS_1 = 1; +constexpr int32_t TUPLE_POS_2 = 2; } HiPlayerCallbackLooper::HiPlayerCallbackLooper() : task_("callbackThread", OHOS::Media::TaskPriority::NORMAL) { @@ -75,12 +77,10 @@ void HiPlayerCallbackLooper::StartReportMediaProgress(int64_t updateIntervalMs) return; } reportMediaProgress_ = true; - //eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, SteadyClock::GetCurrentTimeMs(), Plugin::Any())); } void HiPlayerCallbackLooper::ManualReportMediaProgressOnce() { - //eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, SteadyClock::GetCurrentTimeMs(), Plugin::Any())); } void HiPlayerCallbackLooper::StopReportMediaProgress() @@ -101,16 +101,10 @@ void HiPlayerCallbackLooper::DoReportMediaProgress() MEDIA_LOG_W("get player engine current time error"); } } - /*if (reportMediaProgress_) { - eventQueue_.Enqueue(std::make_shared(WHAT_MEDIA_PROGRESS, - SteadyClock::GetCurrentTimeMs() + reportProgressIntervalMs_, Plugin::Any())); - }*/ } void HiPlayerCallbackLooper::OnError(PlayerErrorType errorType, int32_t errorCode) { - /*eventQueue_.Enqueue(std::make_shared(WHAT_ERROR, SteadyClock::GetCurrentTimeMs(), - std::make_pair(errorType, errorCode)));*/ } void HiPlayerCallbackLooper::DoReportError(const Any &error) @@ -119,7 +113,7 @@ void HiPlayerCallbackLooper::DoReportError(const Any &error) if (obs != nullptr) { auto ptr = AnyCast>(&error); MEDIA_LOG_E("Report error, error type: " PUBLIC_LOG_D32 " error value: " PUBLIC_LOG_D32, - static_cast(ptr->first), static_cast(ptr->second)); + static_cast(ptr->first), static_cast(ptr->second)); obs->OnError(ptr->first, ptr->second); } } @@ -136,8 +130,8 @@ void HiPlayerCallbackLooper::DoReportInfo(const Any& info) if (obs != nullptr) { auto ptr = AnyCast>(&info); MEDIA_LOG_I("Report info, info type: " PUBLIC_LOG_D32 " info value: " PUBLIC_LOG_D32, - static_cast(std::get<0>(*ptr)), static_cast(std::get<1>(*ptr))); - obs->OnInfo(std::get<0>(*ptr), std::get<1>(*ptr), std::get<2>(*ptr)); // indexes + static_cast(std::get(*ptr)), static_cast(std::get(*ptr))); + obs->OnInfo(std::get(*ptr), std::get(*ptr), std::get(*ptr)); } } diff --git a/services/engine/histreamer/player/hiplayer_callback_looper.h b/services/engine/histreamer/player/hiplayer_callback_looper.h index b77756543..bfec03566 100644 --- a/services/engine/histreamer/player/hiplayer_callback_looper.h +++ b/services/engine/histreamer/player/hiplayer_callback_looper.h @@ -55,7 +55,7 @@ private: void DoReportInfo(const Any& info); void DoReportError(const Any& error); - struct Event{ + struct Event { Event(int32_t inWhat, int64_t inWhenMs, Any inAny): what(inWhat), whenMs(inWhenMs), detail(std::move(inAny)) {} int32_t what {0}; diff --git a/services/engine/histreamer/player/hiplayer_impl.cpp b/services/engine/histreamer/player/hiplayer_impl.cpp index a2082b73a..b2caf4106 100644 --- a/services/engine/histreamer/player/hiplayer_impl.cpp +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -16,13 +16,14 @@ #define HST_LOG_TAG "HiPlayerImpl" #include "hiplayer_impl.h" -#include -#include -#include + +#include "audio_info.h" +#include "av_common.h" #include "common/log.h" -#include "osal/utils/dump_buffer.h" -#include "filter/filter_factory.h" #include "common/media_source.h" +#include "filter/filter_factory.h" +#include "media_errors.h" +#include "osal/utils/dump_buffer.h" namespace { const float MAX_MEDIA_VOLUME = 1.0f; // standard interface volume is between 0 to 1. @@ -50,13 +51,16 @@ const std::pair g_statusPair[] = { {Status::ERROR_NO_MEMORY, MSERR_EXT_NO_MEMORY}, {Status::ERROR_INVALID_STATE, MSERR_INVALID_STATE}, }; + class PlayerEventReceiver : public EventReceiver { public: - PlayerEventReceiver(HiPlayerImpl* hiPlayerImpl) { + explicit PlayerEventReceiver(HiPlayerImpl* hiPlayerImpl) + { hiPlayerImpl_ = hiPlayerImpl; } - void OnEvent(const Event &event) { + void OnEvent(const Event &event) + { hiPlayerImpl_->OnEvent(event); } @@ -66,11 +70,13 @@ private: class PlayerFilterCallback : public FilterCallback { public: - PlayerFilterCallback(HiPlayerImpl* hiPlayerImpl) { + explicit PlayerFilterCallback(HiPlayerImpl* hiPlayerImpl) + { hiPlayerImpl_ = hiPlayerImpl; } - void OnCallback(const std::shared_ptr& filter, FilterCallBackCommand cmd, StreamType outType) { + void OnCallback(const std::shared_ptr& filter, FilterCallBackCommand cmd, StreamType outType) + { hiPlayerImpl_->OnCallback(filter, cmd, outType); } @@ -78,16 +84,12 @@ private: HiPlayerImpl* hiPlayerImpl_; }; -HiPlayerImpl::HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) - : appUid_(appUid), - appPid_(appPid), - appTokenId_(appTokenId), - appFullTokenId_(appFullTokenId) +HiPlayerImpl::HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) : + appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) { - MEDIA_LOG_I("hiPlayerImpl ctor appUid " PUBLIC_LOG_D32 " appPid " PUBLIC_LOG_D32 " appTokenId " PUBLIC_LOG_D32 " appFullTokenId " PUBLIC_LOG_D64, - appUid_, appPid_, appTokenId_, appFullTokenId_); + MEDIA_LOG_I("hiPlayerImpl ctor appUid " PUBLIC_LOG_D32 " appPid " PUBLIC_LOG_D32 " appTokenId " PUBLIC_LOG_D32 + " appFullTokenId " PUBLIC_LOG_D64, appUid_, appPid_, appTokenId_, appFullTokenId_); pipeline_ = std::make_shared(); - // syncManager_ = std::make_shared(); } HiPlayerImpl::~HiPlayerImpl() @@ -98,17 +100,14 @@ HiPlayerImpl::~HiPlayerImpl() #ifdef VIDEO_SUPPORT videoSink_.reset(); #endif - //syncManager_.reset(); } Status HiPlayerImpl::Init() { MEDIA_LOG_I("Init entered."); - std::shared_ptr playerEventReceiver = std::make_shared( - this); + std::shared_ptr playerEventReceiver = std::make_shared(this); playerEventReceiver_ = playerEventReceiver; - std::shared_ptr playerFilterCallback = std::make_shared( - this); + std::shared_ptr playerFilterCallback = std::make_shared(this); playerFilterCallback_ = playerFilterCallback; MEDIA_LOG_I("pipeline init start"); pipeline_->Init(playerEventReceiver, playerFilterCallback); @@ -188,7 +187,6 @@ int32_t HiPlayerImpl::Play() MEDIA_LOG_I("Play entered."); auto ret {Status::OK}; if (curState_ == PlayerStateId::READY) { - //syncManager_->Resume(); ret = pipeline_->Start(); } if (ret == Status::OK) { @@ -201,7 +199,6 @@ int32_t HiPlayerImpl::Pause() { MEDIA_LOG_I("Pause entered."); auto ret = pipeline_->Pause(); - // syncManager_->Pause(); OnStateChanged(PlayerStateId::PAUSE); return TransStatus(ret); } @@ -217,7 +214,6 @@ int32_t HiPlayerImpl::Stop() if (pipeline_ != nullptr) { pipeline_->Stop(); } - // syncManager_->Reset(); OnStateChanged(PlayerStateId::STOPPED); return TransStatus(ret); } @@ -234,7 +230,7 @@ int32_t HiPlayerImpl::Reset() int32_t HiPlayerImpl::Seek(int32_t mSeconds, PlayerSeekMode mode) { MEDIA_LOG_I("Seek entered. mSeconds : " PUBLIC_LOG_D32 ", seekMode : " PUBLIC_LOG_D32, - mSeconds, static_cast(mode)); + mSeconds, static_cast(mode)); int64_t hstTime = 0; int32_t durationMs; GetDuration(durationMs); @@ -266,9 +262,6 @@ int32_t HiPlayerImpl::Seek(int32_t mSeconds, PlayerSeekMode mode) MEDIA_LOG_I("Do seek ..."); int64_t realSeekTime = seekPos; rtv = demuxer_->SeekTo(seekPos, seekMode, realSeekTime); - /* if (rtv == Status::OK) { - syncManager_->Seek(realSeekTime); - } */ } if (rtv != Status::OK) { MEDIA_LOG_E("Seek done, seek error."); @@ -355,7 +348,6 @@ int32_t HiPlayerImpl::SetObs(const std::weak_ptr& obs) int32_t HiPlayerImpl::GetCurrentTime(int32_t& currentPositionMs) { - //currentPositionMs = syncManager_->GetMediaTimeNow(); return TransStatus(Status::OK); } @@ -556,7 +548,7 @@ int32_t HiPlayerImpl::SetVideoScaleType(OHOS::Media::VideoScaleType videoScaleTy MEDIA_LOG_I("SetVideoScaleType entered."); #ifdef VIDEO_SUPPORT auto ret = videoSink_->SetParameter(static_cast(Tag::VIDEO_SCALE_TYPE), - static_cast(static_cast(videoScaleType))); + static_cast(static_cast(videoScaleType))); return TransStatus(ret); #else return TransStatus(Status::OK); @@ -593,7 +585,8 @@ int HiPlayerImpl::TransStatus(Status status) return MSERR_UNKNOWN; } -void HiPlayerImpl::OnEvent(const Event &event) { +void HiPlayerImpl::OnEvent(const Event &event) +{ switch (event.type) { case EventType::EVENT_ERROR: { OnStateChanged(PlayerStateId::ERROR); @@ -614,7 +607,7 @@ void HiPlayerImpl::OnEvent(const Event &event) { Status HiPlayerImpl::DoSetSource(const std::shared_ptr source) { demuxer_ = FilterFactory::Instance().CreateFilter("builtin.player.demuxer", - FilterType::FILTERTYPE_DEMUXER); + FilterType::FILTERTYPE_DEMUXER); demuxer_->Init(playerEventReceiver_, playerFilterCallback_); auto ret = demuxer_->SetDataSource(source); pipeline_->AddHeadFilters({demuxer_}); @@ -623,7 +616,6 @@ Status HiPlayerImpl::DoSetSource(const std::shared_ptr source) Status HiPlayerImpl::Resume() { - // syncManager_->Resume(); auto ret = pipeline_->Resume(); return ret; } @@ -633,8 +625,7 @@ void HiPlayerImpl::OnStateChanged(PlayerStateId state) curState_ = state; } -void HiPlayerImpl::OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, - StreamType outType) +void HiPlayerImpl::OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, StreamType outType) { MEDIA_LOG_I("HiPlayerImpl::OnCallback filter, "); if (cmd == FilterCallBackCommand::NEXT_FILTER_NEEDED) { @@ -659,28 +650,30 @@ void HiPlayerImpl::OnCallback(std::shared_ptr filter, const FilterCallBa } } -Status HiPlayerImpl::LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type) { +Status HiPlayerImpl::LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type) +{ MEDIA_LOG_I("HiPlayerImpl::LinkAudioDecoderFilter"); if (audioDecoder_ == nullptr) { audioDecoder_ = FilterFactory::Instance().CreateFilter("player.audiodecoder", FilterType::FILTERTYPE_ADEC); - audioDecoder_->Init(playerEventReceiver_, playerFilterCallback_); + audioDecoder_->Init(playerEventReceiver_, playerFilterCallback_); } return pipeline_->LinkFilters(preFilter, {audioDecoder_}, type); } -Status HiPlayerImpl::LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type) { +Status HiPlayerImpl::LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type) +{ MEDIA_LOG_I("HiPlayerImpl::LinkAudioSinkFilter"); if (audioSink_ == nullptr) { audioSink_ = FilterFactory::Instance().CreateFilter("player.audiosink", FilterType::FILTERTYPE_ASINK); audioSink_->Init(playerEventReceiver_, playerFilterCallback_); } - // audioSink_->SetSyncCenter(syncManager_); return pipeline_->LinkFilters(preFilter, {audioSink_}, type); } #ifdef VIDEO_SUPPORT -Status HiPlayerImpl::LinkVideoDecoderFilter(const std::shared_ptr& preFilter, StreamType type) { +Status HiPlayerImpl::LinkVideoDecoderFilter(const std::shared_ptr& preFilter, StreamType type) +{ MEDIA_LOG_I("HiPlayerImpl::LinkVideoDecoderFilter"); if (videoDecoder_ == nullptr) { videoDecoder_ = FilterFactory::Instance().CreateFilter("player.videodecoder", @@ -690,14 +683,14 @@ Status HiPlayerImpl::LinkVideoDecoderFilter(const std::shared_ptr& preFi return pipeline_->LinkFilters(preFilter, {videoDecoder_}, type); } -Status HiPlayerImpl::LinkVideoSinkFilter(const std::shared_ptr& preFilter, StreamType type) { +Status HiPlayerImpl::LinkVideoSinkFilter(const std::shared_ptr& preFilter, StreamType type) +{ MEDIA_LOG_I("HiPlayerImpl::LinkVideoSinkFilter"); if (videoSink_ == nullptr) { videoSink_ = FilterFactory::Instance().CreateFilter("player.videosink", FilterType::FILTERTYPE_VSINK); videoSink_->Init(playerEventReceiver_, playerFilterCallback_); } - // videoSink_->SetSyncCenter(syncManager_); return pipeline_->LinkFilters(preFilter, {videoSink_}, type); } #endif diff --git a/services/engine/histreamer/player/hiplayer_impl.h b/services/engine/histreamer/player/hiplayer_impl.h index ae54172b4..2707020df 100644 --- a/services/engine/histreamer/player/hiplayer_impl.h +++ b/services/engine/histreamer/player/hiplayer_impl.h @@ -19,23 +19,24 @@ #include #include -#include "hiplayer_callback_looper.h" -#include +#include "audio_sink_filter.h" +#include "codec_filter.h" #include "common/status.h" +#include "demuxer_filter.h" +#include "filter/filter.h" +#include "filter/filter_factory.h" +#include "hiplayer_callback_looper.h" +#include "i_player_engine.h" #include "media_sync_manager.h" #include "pipeline/pipeline.h" -#include "filter/filter_factory.h" -#include "demuxer_filter.h" -#include "codec_filter.h" -#include "audio_sink_filter.h" #ifdef VIDEO_SUPPORT #include "video_sink_filter.h" #endif -#include "filter/filter.h" namespace OHOS { namespace Media { using namespace Pipeline; + enum class PlayerStateId { IDLE = 0, INIT = 1, @@ -47,8 +48,8 @@ enum class PlayerStateId { EOS = 7, ERROR = 8, }; -class HiPlayerImpl : public IPlayerEngine, public std::enable_shared_from_this { +class HiPlayerImpl : public IPlayerEngine, public std::enable_shared_from_this { public: HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId); ~HiPlayerImpl() override; @@ -99,19 +100,19 @@ private: Status LinkVideoDecoderFilter(const std::shared_ptr& preFilter, StreamType type); Status LinkVideoSinkFilter(const std::shared_ptr& preFilter, StreamType type); #endif - int32_t appUid_ {0}; - int32_t appPid_ {0}; + int32_t appUid_{0}; + int32_t appPid_{0}; int32_t appTokenId_{0}; int64_t appFullTokenId_{0}; - OHOS::Media::Mutex stateMutex_ {}; - OHOS::Media::ConditionVariable cond_ {}; - int64_t duration_ {-1}; + OHOS::Media::Mutex stateMutex_{}; + OHOS::Media::ConditionVariable cond_{}; + int64_t duration_{-1}; std::atomic singleLoop_ {false}; std::shared_ptr playerEventReceiver_; std::shared_ptr playerFilterCallback_; - std::weak_ptr sourceMeta_ {}; - std::vector> streamMeta_ {}; + std::weak_ptr sourceMeta_{}; + std::vector> streamMeta_{}; std::shared_ptr pipeline_; std::shared_ptr demuxer_; std::shared_ptr audioDecoder_; @@ -122,12 +123,12 @@ private: #endif std::shared_ptr syncManager_; std::atomic curState_; - HiPlayerCallbackLooper callbackLooper_ {}; + HiPlayerCallbackLooper callbackLooper_{}; sptr surface_ {nullptr}; std::string url_; - int32_t videoWidth_ {0}; - int32_t videoHeight_ {0}; + int32_t videoWidth_{0}; + int32_t videoHeight_{0}; }; -} // namespace Media -} // namespace OHOS +} // namespace Media +} // namespace OHOS #endif // HI_PLAYER_IMPL_H \ No newline at end of file diff --git a/services/engine/histreamer/recorder/BUILD.gn b/services/engine/histreamer/recorder/BUILD.gn index a109a8de4..eba71be7c 100644 --- a/services/engine/histreamer/recorder/BUILD.gn +++ b/services/engine/histreamer/recorder/BUILD.gn @@ -12,15 +12,11 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/multimedia/player_framework/config.gni") config("media_engine_histreamer_recorder_config") { visibility = [ ":*" ] - defines = [ - "HST_ANY_WITH_NO_RTTI", - "MEDIA_OHOS", - ] - cflags = [ "-O2", "-fPIC", @@ -33,16 +29,16 @@ config("media_engine_histreamer_recorder_config") { cflags_cc = cflags include_dirs = [ - "//foundation/multimedia/player_framework/services/engine/histreamer/recorder", - "//foundation/multimedia/player_framework/services/utils/include", - "//foundation/multimedia/player_framework/interfaces/inner_api/native", - "//foundation/multimedia/player_framework/services/services/engine_intf", - "//commonlibrary/c_utils/base/include", - "//foundation/multimedia/histreamer/interface/inner_api", - "//foundation/multimedia/av_codec/interfaces/inner_api/native", - "//foundation/multimedia/av_codec/interfaces", - "//foundation/multimedia/histreamer/src", - "//foundation/multimedia/av_codec/services/media_engine/modules/source/audio_capture", + "$MEDIA_PLAYER_ROOT_DIR/services/engine/histreamer/recorder", + "$MEDIA_PLAYER_ROOT_DIR/services/utils/include", + "$MEDIA_PLAYER_ROOT_DIR/interfaces/inner_api/native", + "$MEDIA_PLAYER_ROOT_DIR/services/services/engine_intf", + "$MEDIA_PLAYER_C_UTILS/base/include", + "$MEDIA_PLAYER_HISTREAMER/interface/inner_api", + "$MEDIA_PLAYER_AVCODEC/interfaces/inner_api/native", + "$MEDIA_PLAYER_AVCODEC/interfaces", + "$MEDIA_PLAYER_HISTREAMER/src", + "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/source/audio_capture", ] } @@ -56,13 +52,13 @@ ohos_static_library("media_engine_histreamer_recorder") { configs = [ ":media_engine_histreamer_recorder_config", - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx_public_config", - "//foundation/multimedia/player_framework/services/utils:media_service_utils_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", ] deps = [ - "//foundation/multimedia/player_framework/services/dfx:media_service_log_dfx", - "//foundation/multimedia/player_framework/services/utils:media_service_utils", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils", ] external_deps = [ diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp index 5caae4905..afa54f7dd 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.cpp +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -12,18 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "hirecorder_impl.h" + #include "meta/audio_types.h" namespace OHOS { namespace Media { class RecorderEventReceiver : public Pipeline::EventReceiver { public: - RecorderEventReceiver(HiRecorderImpl *hiRecorderImpl) { + explicit (HiRecorderImpl *hiRecorderImpl) + { hiRecorderImpl_ = hiRecorderImpl; } - void OnEvent(const Event &event) { + void OnEvent(const Event &event) + { hiRecorderImpl_->OnEvent(event); } @@ -33,11 +37,14 @@ namespace Media { class RecorderFilterCallback : public Pipeline::FilterCallback { public: - RecorderFilterCallback(HiRecorderImpl *hiRecorderImpl) { + explicit RecorderFilterCallback(HiRecorderImpl *hiRecorderImpl) + { hiRecorderImpl_ = hiRecorderImpl; } - void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, Pipeline::StreamType outType) { + void OnCallback(const std::shared_ptr& filter, Pipeline::FilterCallBackCommand cmd, + Pipeline::StreamType outType) + { hiRecorderImpl_->OnCallback(filter, cmd, outType); } @@ -46,14 +53,15 @@ namespace Media { }; HiRecorderImpl::HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) - : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) { + : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) + { pipeline_ = std::make_shared(); } - HiRecorderImpl::~HiRecorderImpl() { - } + HiRecorderImpl::~HiRecorderImpl() {} - int32_t HiRecorderImpl::Init() { + int32_t HiRecorderImpl::Init() + { MEDIA_LOG_I("Init enter."); recorderEventReceiver_ = std::make_shared(this); recorderCallback_ = std::make_shared(this); @@ -61,7 +69,8 @@ namespace Media { return (int32_t)Status::OK; } - int32_t HiRecorderImpl::SetVideoSource(VideoSourceType source, int32_t &sourceId) { + int32_t HiRecorderImpl::SetVideoSource(VideoSourceType source, int32_t &sourceId) + { MEDIA_LOG_I("SetVideoSource enter."); sourceId = INVALID_SOURCE_ID; FALSE_RETURN_V(source != VideoSourceType::VIDEO_SOURCE_BUTT, @@ -84,7 +93,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::SetAudioSource(AudioSourceType source, int32_t &sourceId) { + int32_t HiRecorderImpl::SetAudioSource(AudioSourceType source, int32_t &sourceId) + { MEDIA_LOG_I("SetAudioSource enter."); sourceId = INVALID_SOURCE_ID; FALSE_RETURN_V(source != AudioSourceType::AUDIO_SOURCE_INVALID, @@ -109,20 +119,23 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::SetOutputFormat(OutputFormatType format) { + int32_t HiRecorderImpl::SetOutputFormat(OutputFormatType format) + { MEDIA_LOG_I("SetOutputFormat enter. " PUBLIC_LOG_D32, static_cast(format)); outputFormatType_ = format; OnStateChanged(StateId::RECORDING_SETTING); return (int32_t)Status::OK; } - int32_t HiRecorderImpl::SetObs(const std::weak_ptr &obs) { + int32_t HiRecorderImpl::SetObs(const std::weak_ptr &obs) + { MEDIA_LOG_I("SetObs enter."); obs_ = obs; return (int32_t)Status::OK; } - int32_t HiRecorderImpl::Configure(int32_t sourceId, const RecorderParam &recParam) { + int32_t HiRecorderImpl::Configure(int32_t sourceId, const RecorderParam &recParam) + { MEDIA_LOG_I("Configure enter."); FALSE_RETURN_V(outputFormatType_ != OutputFormatType::FORMAT_BUTT, (int32_t)Status::ERROR_INVALID_OPERATION); @@ -154,12 +167,14 @@ namespace Media { return (int32_t)Status::OK; } - sptr HiRecorderImpl::GetSurface(int32_t sourceId) { + sptr HiRecorderImpl::GetSurface(int32_t sourceId) + { MEDIA_LOG_I("GetSurface enter."); return videoEncoderFilter_->GetInputSurface(); } - int32_t HiRecorderImpl::Prepare() { + int32_t HiRecorderImpl::Prepare() + { MEDIA_LOG_I("Prepare enter."); if (audioCaptureFilter_) { audioCaptureFilter_->Init(recorderEventReceiver_, recorderCallback_); @@ -167,7 +182,6 @@ namespace Media { audioEncFormat_->Set(appUid_); audioEncFormat_->Set(appPid_); audioEncFormat_->Set(appFullTokenId_); - // audioEncFormat_->Set(AudioSampleFormat::SAMPLE_S16P); audioCaptureFilter_->SetParameter(audioEncFormat_); } if (videoEncoderFilter_) { @@ -182,7 +196,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::Start() { + int32_t HiRecorderImpl::Start() + { MEDIA_LOG_I("Start enter."); Status ret = Status::OK; if (curState_ == StateId::PAUSE) { @@ -196,7 +211,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::Pause() { + int32_t HiRecorderImpl::Pause() + { MEDIA_LOG_I("Pause enter."); Status ret = Status::OK; if (curState_ != StateId::READY) { @@ -208,7 +224,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::Resume() { + int32_t HiRecorderImpl::Resume() + { MEDIA_LOG_I("Resume enter."); Status ret = Status::OK; ret = pipeline_->Resume(); @@ -218,7 +235,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::Stop(bool isDrainAll) { + int32_t HiRecorderImpl::Stop(bool isDrainAll) + { MEDIA_LOG_I("Stop enter."); Status ret = Status::OK; if (curState_ == StateId::INIT || curState_ == StateId::READY) { @@ -238,7 +256,8 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::Reset() { + int32_t HiRecorderImpl::Reset() + { MEDIA_LOG_I("Reset enter."); Status ret = Status::OK; if (curState_ == StateId::RECORDING) { @@ -255,12 +274,14 @@ namespace Media { return (int32_t)ret; } - int32_t HiRecorderImpl::SetParameter(int32_t sourceId, const RecorderParam &recParam) { + int32_t HiRecorderImpl::SetParameter(int32_t sourceId, const RecorderParam &recParam) + { MEDIA_LOG_I("SetParameter enter."); return Configure(sourceId, recParam); } - void HiRecorderImpl::OnEvent(const Event &event) { + void HiRecorderImpl::OnEvent(const Event &event) + { switch (event.type) { case EventType::EVENT_ERROR: { OnStateChanged(StateId::ERROR); @@ -283,7 +304,8 @@ namespace Media { } void HiRecorderImpl::OnCallback(std::shared_ptr filter, const Pipeline::FilterCallBackCommand cmd, - Pipeline::StreamType outType) { + Pipeline::StreamType outType) + { MEDIA_LOG_I("OnCallback enter."); if (cmd == Pipeline::FilterCallBackCommand::NEXT_FILTER_NEEDED) { switch (outType) { @@ -323,7 +345,8 @@ namespace Media { } } - void HiRecorderImpl::ConfigureAudio(const RecorderParam &recParam) { + void HiRecorderImpl::ConfigureAudio(const RecorderParam &recParam) + { MEDIA_LOG_I("ConfigureAudio enter."); switch (recParam.type) { case RecorderPublicParamType::AUD_SAMPLERATE: { @@ -360,7 +383,8 @@ namespace Media { } - void HiRecorderImpl::ConfigureVideo(const RecorderParam &recParam) { + void HiRecorderImpl::ConfigureVideo(const RecorderParam &recParam) + { MEDIA_LOG_I("ConfigureVideo enter."); switch (recParam.type) { case RecorderPublicParamType::VID_RECTANGLE: { @@ -406,7 +430,8 @@ namespace Media { } } - void HiRecorderImpl::ConfigureMuxer(const RecorderParam &recParam) { + void HiRecorderImpl::ConfigureMuxer(const RecorderParam &recParam) + { MEDIA_LOG_I("ConfigureMuxer enter"); switch (recParam.type) { case RecorderPublicParamType::OUT_FD: { @@ -432,7 +457,8 @@ namespace Media { } } - bool HiRecorderImpl::CheckParamType(int32_t sourceId, const RecorderParam &recParam) { + bool HiRecorderImpl::CheckParamType(int32_t sourceId, const RecorderParam &recParam) + { FALSE_RETURN_V((SourceIdGenerator::IsAudio(sourceId) && recParam.IsAudioParam() && static_cast(audioSourceId_) == sourceId) || (SourceIdGenerator::IsVideo(sourceId) && recParam.IsVideoParam() && @@ -445,5 +471,5 @@ namespace Media { { curState_ = state; } -} //namespace MEDIA -} //namespace OHOS +} // namespace MEDIA +} // namespace OHOS diff --git a/services/engine/histreamer/recorder/hirecorder_impl.h b/services/engine/histreamer/recorder/hirecorder_impl.h index bcc73ccb3..8b5954bcb 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.h +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -123,9 +123,8 @@ private: int64_t maxDuration_; int64_t maxSize_; - Mutex stateMutex_ {}; - ConditionVariable cond_ {}; - + Mutex stateMutex_{}; + ConditionVariable cond_{}; }; } //namespace MEDIA } //namespace OHOS diff --git a/services/engine/histreamer/recorder/recorder_utils.h b/services/engine/histreamer/recorder/recorder_utils.h index fa5b119db..2c9ee729c 100644 --- a/services/engine/histreamer/recorder/recorder_utils.h +++ b/services/engine/histreamer/recorder/recorder_utils.h @@ -31,20 +31,24 @@ struct SourceIdGenerator { static const uint32_t AUDIO_MASK = 0x200; static const uint32_t INDEX_MASK = 0xFF; - static int32_t GenerateAudioSourceId(uint32_t index) { + static int32_t GenerateAudioSourceId(uint32_t index) + { return static_cast(AUDIO_MASK + (INDEX_MASK & index)); } - static int32_t GenerateVideoSourceId(uint32_t index) { + static int32_t GenerateVideoSourceId(uint32_t index) + { return static_cast(VIDEO_MASK + (INDEX_MASK & index)); } - static int32_t IsAudio(int32_t sourceId) { + static int32_t IsAudio(int32_t sourceId) + { return ((sourceId > 0) && ((static_cast(sourceId) & SOURCE_MASK) == AUDIO_MASK)); } - static int32_t IsVideo(int32_t sourceId) { + static int32_t IsVideo(int32_t sourceId) + { return ((sourceId > 0) && ((static_cast(sourceId) & SOURCE_MASK) == VIDEO_MASK)); } -- Gitee From 5cc034e649032fe2f33870fb1eb95b8451fb7258 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sat, 16 Dec 2023 11:08:37 +0000 Subject: [PATCH 4/8] Media Refactor. solve ci warnings Signed-off-by: yuanjinghua Change-Id: Ia3069a63311578077b7e5372f599cabfc0d850cb --- .../histreamer/avmetadatahelper/avmetadata_collector.cpp | 2 -- services/engine/histreamer/factory/BUILD.gn | 2 +- .../{engine_factory.cpp => hst_engine_factory.cpp} | 0 services/engine/histreamer/player/hiplayer_impl.cpp | 4 ++-- services/engine/histreamer/recorder/hirecorder_impl.cpp | 5 ++--- services/engine/histreamer/recorder/hirecorder_impl.h | 4 ++-- services/engine/histreamer/recorder/recorder_utils.h | 8 ++++---- 7 files changed, 11 insertions(+), 14 deletions(-) rename services/engine/histreamer/factory/{engine_factory.cpp => hst_engine_factory.cpp} (100%) diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 190150022..7030e1c84 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -19,8 +19,6 @@ namespace OHOS { namespace Media { -#define AVMETA_KEY_TO_X_MAP_ITEM(key, innerKey) { key, innerKey } - static const std::unordered_map AVMETA_KEY_TO_X_MAP = { { AV_KEY_ALBUM, Tag::MEDIA_ALBUM }, { AV_KEY_ALBUM_ARTIST, Tag::MEDIA_ALBUM_ARTIST }, diff --git a/services/engine/histreamer/factory/BUILD.gn b/services/engine/histreamer/factory/BUILD.gn index 4e5181209..ebf776605 100644 --- a/services/engine/histreamer/factory/BUILD.gn +++ b/services/engine/histreamer/factory/BUILD.gn @@ -57,7 +57,7 @@ ohos_static_library("media_engine_histreamer_factory") { cfi_cross_dso = true debug = false } - sources = [ "engine_factory.cpp" ] + sources = [ "hst_engine_factory.cpp" ] configs = [ ":media_engine_histreamer_factory_config", diff --git a/services/engine/histreamer/factory/engine_factory.cpp b/services/engine/histreamer/factory/hst_engine_factory.cpp similarity index 100% rename from services/engine/histreamer/factory/engine_factory.cpp rename to services/engine/histreamer/factory/hst_engine_factory.cpp diff --git a/services/engine/histreamer/player/hiplayer_impl.cpp b/services/engine/histreamer/player/hiplayer_impl.cpp index b2caf4106..1b595be52 100644 --- a/services/engine/histreamer/player/hiplayer_impl.cpp +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -84,8 +84,8 @@ private: HiPlayerImpl* hiPlayerImpl_; }; -HiPlayerImpl::HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) : - appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) +HiPlayerImpl::HiPlayerImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) + : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) { MEDIA_LOG_I("hiPlayerImpl ctor appUid " PUBLIC_LOG_D32 " appPid " PUBLIC_LOG_D32 " appTokenId " PUBLIC_LOG_D32 " appFullTokenId " PUBLIC_LOG_D64, appUid_, appPid_, appTokenId_, appFullTokenId_); diff --git a/services/engine/histreamer/recorder/hirecorder_impl.cpp b/services/engine/histreamer/recorder/hirecorder_impl.cpp index afa54f7dd..793704696 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.cpp +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -53,7 +53,7 @@ namespace Media { }; HiRecorderImpl::HiRecorderImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId) - : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) + : appUid_(appUid), appPid_(appPid), appTokenId_(appTokenId), appFullTokenId_(appFullTokenId) { pipeline_ = std::make_shared(); } @@ -287,7 +287,7 @@ namespace Media { OnStateChanged(StateId::ERROR); auto ptr = obs_.lock(); if (ptr != nullptr) { - // ptr->OnError(IRecorderEngineObs::ErrorType::ERROR_INTERNAL, event.param); + MEDIA_LOG_I("OnEvent EVENT_ERROR obs is nullptr."); } break; } @@ -380,7 +380,6 @@ namespace Media { break; } } - } void HiRecorderImpl::ConfigureVideo(const RecorderParam &recParam) diff --git a/services/engine/histreamer/recorder/hirecorder_impl.h b/services/engine/histreamer/recorder/hirecorder_impl.h index 8b5954bcb..5edc97cdf 100644 --- a/services/engine/histreamer/recorder/hirecorder_impl.h +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -126,6 +126,6 @@ private: Mutex stateMutex_{}; ConditionVariable cond_{}; }; -} //namespace MEDIA -} //namespace OHOS +} // namespace MEDIA +} // namespace OHOS #endif // HI_RECORDER_IMPL_H \ No newline at end of file diff --git a/services/engine/histreamer/recorder/recorder_utils.h b/services/engine/histreamer/recorder/recorder_utils.h index 2c9ee729c..a946a7a5d 100644 --- a/services/engine/histreamer/recorder/recorder_utils.h +++ b/services/engine/histreamer/recorder/recorder_utils.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef RECORDER_UTILS_H -#define RECORDER_UTILS_H +#ifndef OHOS_MEDIA_RECORDER_UTILS_H +#define OHOS_MEDIA_RECORDER_UTILS_H #include @@ -53,6 +53,6 @@ struct SourceIdGenerator { ((static_cast(sourceId) & SOURCE_MASK) == VIDEO_MASK)); } }; -#endif // RECORDER_UTILS_H } // Media -} // OHOS \ No newline at end of file +} // OHOS +#endif // OHOS_MEDIA_RECORDER_UTILS_H \ No newline at end of file -- Gitee From a9d2ec757aa5578c6eb6d4acf4986e69b8fc707f Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sat, 16 Dec 2023 11:48:15 +0000 Subject: [PATCH 5/8] Media Refactor. solve ci error Signed-off-by: yuanjinghua Change-Id: I303588c35e51d4450e56812abbdef4cec84e8dad --- services/engine/histreamer/factory/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/engine/histreamer/factory/BUILD.gn b/services/engine/histreamer/factory/BUILD.gn index ebf776605..ec3ac4cce 100644 --- a/services/engine/histreamer/factory/BUILD.gn +++ b/services/engine/histreamer/factory/BUILD.gn @@ -61,10 +61,10 @@ ohos_static_library("media_engine_histreamer_factory") { configs = [ ":media_engine_histreamer_factory_config", - "$MEDIA_PLAYER_ROOT_DIRa_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", ] - deps = [ "../../../dfx:media_service_log_dfx" ] + deps = [ "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx" ] external_deps = [ "audio_framework:audio_client", -- Gitee From 33b450bd7ce9efb315ab0284ee804e8652f26462 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sat, 16 Dec 2023 12:51:26 +0000 Subject: [PATCH 6/8] Media Refactor. solve ci errors Signed-off-by: yuanjinghua Change-Id: I4d32f6c81cd230f70f89dde67d2f2d411a1ba8eb --- config.gni | 1 + services/engine/histreamer/avmetadatahelper/BUILD.gn | 6 +----- services/engine/histreamer/player/BUILD.gn | 6 +----- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/config.gni b/config.gni index 6f125bad7..71031844b 100644 --- a/config.gni +++ b/config.gni @@ -20,6 +20,7 @@ declare_args() { multimedia_player_framework_support_codec_js = false multimedia_player_framework_support_metadata = true multimedia_player_framework_support_gstreamer = true + multimedia_player_framework_support_histreamter = true multimedia_player_framework_support_video = true multimedia_player_framework_support_jsapi = true multimedia_player_framework_support_capi = true diff --git a/services/engine/histreamer/avmetadatahelper/BUILD.gn b/services/engine/histreamer/avmetadatahelper/BUILD.gn index 3b1e7711e..aefff3569 100644 --- a/services/engine/histreamer/avmetadatahelper/BUILD.gn +++ b/services/engine/histreamer/avmetadatahelper/BUILD.gn @@ -12,15 +12,11 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/multimedia/player_framework/config.gni") config("media_engine_histreamer_avmetadatahelper_config") { visibility = [ ":*" ] - defines = [ - "HST_ANY_WITH_NO_RTTI", - "MEDIA_OHOS", - ] - cflags = [ "-O2", "-fPIC", diff --git a/services/engine/histreamer/player/BUILD.gn b/services/engine/histreamer/player/BUILD.gn index e8f27abe4..53e51c50f 100644 --- a/services/engine/histreamer/player/BUILD.gn +++ b/services/engine/histreamer/player/BUILD.gn @@ -12,15 +12,11 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/multimedia/player_framework/config.gni") config("media_engine_histreamer_player_config") { visibility = [ ":*" ] - defines = [ - "HST_ANY_WITH_NO_RTTI", - "MEDIA_OHOS", - ] - cflags = [ "-O2", "-fPIC", -- Gitee From 77c04561d731d5b1bea56a4f8048311d3c45243e Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Mon, 18 Dec 2023 15:32:43 +0000 Subject: [PATCH 7/8] Media Refactor. update copyright date info Signed-off-by: yuanjinghua Change-Id: I193959b0d36945bb6ff0f886acf0c385e2bcfc64 --- services/engine/histreamer/BUILD.gn | 2 +- services/engine/histreamer/factory/BUILD.gn | 7 ++----- services/engine/histreamer/factory/hst_engine_factory.cpp | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/services/engine/histreamer/BUILD.gn b/services/engine/histreamer/BUILD.gn index c79cba1ff..83c363bec 100644 --- a/services/engine/histreamer/BUILD.gn +++ b/services/engine/histreamer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (C) 2023 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/engine/histreamer/factory/BUILD.gn b/services/engine/histreamer/factory/BUILD.gn index ec3ac4cce..c06fedea7 100644 --- a/services/engine/histreamer/factory/BUILD.gn +++ b/services/engine/histreamer/factory/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (C) 2023 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 @@ -44,10 +44,7 @@ config("media_engine_histreamer_factory_config") { "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/source/audio_capture", "$MEDIA_PLAYER_AVCODEC/services/media_engine/modules/", ] - defines = [ - "HST_ANY_WITH_NO_RTTI", - "MEDIA_OHOS", - ] + defines = [] defines += player_framework_defines } diff --git a/services/engine/histreamer/factory/hst_engine_factory.cpp b/services/engine/histreamer/factory/hst_engine_factory.cpp index 7f9c9b57a..0dd81b660 100644 --- a/services/engine/histreamer/factory/hst_engine_factory.cpp +++ b/services/engine/histreamer/factory/hst_engine_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 -- Gitee From da83f5a93b8e0fec5df730dabfb9918100b830d2 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Tue, 19 Dec 2023 15:56:50 +0800 Subject: [PATCH 8/8] Media Refactor. public_external_deps is not ready, use public_deps instead temporarily. Signed-off-by: yuanjinghua Change-Id: I96c12569987c1db1eb232d0c76c69105619d1241 --- interfaces/inner_api/native/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/native/BUILD.gn b/interfaces/inner_api/native/BUILD.gn index 584f58d4d..67ae57553 100644 --- a/interfaces/inner_api/native/BUILD.gn +++ b/interfaces/inner_api/native/BUILD.gn @@ -183,7 +183,7 @@ ohos_shared_library("media_client") { "ipc:ipc_single", "samgr:samgr_proxy", ] - public_external_deps = [ "histreamer:media_foundation" ] + public_deps = [ "$MEDIA_PLAYER_HISTREAMER/src:media_foundation" ] if (multimedia_player_framework_support_video) { external_deps += [ "graphic_2d:surface" ] -- Gitee