diff --git a/bundle.json b/bundle.json index 729e8b506819aeb03b58993d3bf1d8f0df156566..830b7a5ee5acf6d593acb71b9b9e7222b564e951 100644 --- a/bundle.json +++ b/bundle.json @@ -55,6 +55,7 @@ "input", "memmgr_plugin", "hicollie", + "histreamer", "drivers_peripheral_codec", "drivers_peripheral_display", "hdf_core", @@ -90,16 +91,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/config.gni b/config.gni index da8dd38001880cfd72fd653f286810b973309ca9..71031844be94c7f0d5f6fb62115ab0bffe015b46 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 @@ -151,6 +152,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/frameworks/js/avplayer/media_data_source_callback.cpp b/frameworks/js/avplayer/media_data_source_callback.cpp index e41f90f9c4fe031ab55d92c177881e2b666a4221..ab9ae27ae856f506c94887387ad52d4742c67c2f 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 88d810e17c025432b074d5141c8df438f3c2e48d..7fdf5e1578deee040263fa742a815e4faf0cf2bc 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/BUILD.gn b/frameworks/js/system_sound_manager/BUILD.gn index 66838cd246aca8fcffe34474f4102665e079dfb9..9936449a7dfdb426b2e57778d5fecd7d09d23d2a 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/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 dc4fb904bacf3f684323c68ade6810f4bb05c9cb..170c865b4c9d004b0dbfd2e50b6a35608b4ac205 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 a1c236f2e18efb4e5cfcdf0bcf51bf08a6f9f4ab..4b6d5f665e242676babeef6612f283aef14ce3a1 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 7a533b738211ee76958691931b5674f9fde256ba..3e8d896add02f18f90d208c4f7fa6f247ea34479 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 08e2f5139443f1a8e40f38601a5d5bf9b4d5c254..b02ad501d6fc0be82a27a346d29f0840876c0ce6 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 7ad733f1f34d4a4de028e2fd77dd57ae29e09512..67ae57553678ed1851b3709908187b4540bf79ea 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_deps = [ "$MEDIA_PLAYER_HISTREAMER/src: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 de9e813c2f3657bfb0fb4b9655cbeecc726ec30a..6773b334cde23cbf5d2b03d554f6b5fcea8fbc9f 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 af18f06441a10ace89a74593bd6c38c9172f3721..8eb34f494c83139c6f979d110c912193f38c453e 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 834b70bf2f31b4a5f3d53d5e08912928870ccb0f..b92dc5ed32bf4b5af0727e711dfcbae395277b3e 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 063d8c1ff15404f75ce14a18748ea03a4b61d63b..c65d3d66c6e7701f7b06638dfbb5f636c8214e72 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 72567866a746a02110fe6974a8b46ae88b23a495..b4ed8636bd15c5415181039b0271229b1b55b8a8 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 506b348dee4b4e495830f825767b1446ab839446..9235eed83de309b43d5983e4acc345f739fc1089 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 4e6a9e8d65a5581fd3b4518ec3cdc44525c7b948..1e778cc4db241e188fa15180f55ceacf677dadd8 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 2360a22dc95c1a228d0e966797ba9b2163c1af62..0000000000000000000000000000000000000000 --- 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 7f91a2e6aeff52ef91d0a17382ec77a566e0a48d..0000000000000000000000000000000000000000 --- 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 8a87d4748cb44f0b74216755c895831386a57951..0000000000000000000000000000000000000000 --- 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 6ab81911485c4db8b5962f8e237ba9c389741f59..c5d19049dba96555d3ad1a1e8c9698246dbf8a48 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 d199dfa642f6943884a74b4b96bef57ed2cb49ad..e557be53e642d2dbb6189eeee07b0e693047c1e0 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 a2f97ae47f7177a78377f9b9c168876f1e60897e..6eb4d0f1a58854da1c51752d9e62176fb72e2936 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 e06a37335f5a8e289a87cc5c9ecc441a3b43bb90..41ab7b959ddc1607b3faa582eba03ac4e3f65950 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 d6289228c59d45d77f95973a7ee42321c6c81f6e..86303e0e18f53a297f9e03a83309e07829ca33e7 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 d10a3b744f38afb1b3ef6dba4e0c9378dd8dac22..6a7b17f0aa1ee2d4d55e55b02ae735cffa8122ab 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/BUILD.gn b/services/engine/gstreamer/avcodec/BUILD.gn index 6ffa081055d264ba561274172dfa1c99eafe87a1..aa545f1b2e4ffafd46f6c27ce558d5b8939ddb69 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/avcodec/codec_common.h b/services/engine/gstreamer/avcodec/codec_common.h index 9ce9b846c64d21c8c5ae106b54efc268847ca524..1cc5126615928b94c955f06f0af9979eddc8e21a 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 124f4332b82571cfff9e49b420eb53669edd3abe..eddc05f40e8b9f137a61a880d3b6a6949191d155 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 5969d40e06012c031cfed9daf2bd11b8b35bd3b6..0b8df62bd97aaa5e5af6da250d92880a9f79e4e2 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 40dfaf30e07d2a22ed6acda1707ac75f92dbd91a..717daedf03743aaea522ae08cf86c32a504b98c1 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 8f265eedb8e3240d8e64eae05e535a0ca5d57927..ddd82a9ed80d26cbfb9f31b8018a404fe0176669 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/BUILD.gn b/services/engine/gstreamer/avmetadatahelper/BUILD.gn index ffdf2fe180cd7f7a853c3c11ed0c029b638ab2c4..50a7d3a758d10b1d78df0d524d0ed85f3574f375 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/avmetadatahelper/avmeta_elem_meta_collector.cpp b/services/engine/gstreamer/avmetadatahelper/avmeta_elem_meta_collector.cpp index 1a76295c4cfaf6f68ab6e98f061b6d44da426d3e..e8dc5102da9e9ee28c36b6b88912abdcd7442257 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 eef428b25831ef9dcdd7dcc7bd872a2b75a78dd0..4461bd673e696deb2267ff8d6f2d5373e1bd8477 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 b3c820c311441d703849dae72ed177b14dced9c1..8b16c1ac2f8ca5bf2b154ceb1ca921243df9e7f8 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 a8c186cd52c4d3ce756a4abc95f87f73e96f2361..32c5742640268ff594bf7b6601c68c3c2e1a0e7b 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 1a0cc7b0617bc226982ab09e435411dc306ae784..635253623891fbc185ae4c2c69c51ba3977f7c3a 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 301aa78f34463e78ee9a52f580685b8d18f1b10f..272d307546b24bbbef2dc9c1eb5febc8116bb5bf 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 a5885919b9b093b4218bd3b13eea5aa524eb030d..1de25a0a47fe6fba80b4ee474c6a03408ae9f93d 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 0f996c2e8071aae14a1817cfb6f2daffa4323cd3..a8d725f4fd38f056b1eae06b988633b1deeee665 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 ffe98261ebdd0fec9ba367ec685b74c632f6a1ea..3a6e0aebf042e42c97fe594068a6272540654071 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 c583f6f9b094ddf6c1b6202f5b4956e347506c97..ba901166311ec65a90167af4153f59c2a7f0ded8 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/BUILD.gn b/services/engine/gstreamer/player/BUILD.gn index 1dd53e511c412c9a0ed6b71d637b0993fd18287d..1bbe39fd68e2be52834579b9d32dea9ec1268ef1 100644 --- a/services/engine/gstreamer/player/BUILD.gn +++ b/services/engine/gstreamer/player/BUILD.gn @@ -99,6 +99,7 @@ ohos_static_library("media_engine_gst_player") { "drivers_peripheral_display:hdi_gralloc_client", "graphic_2d:surface", "hilog:libhilog", + "histreamer:media_foundation", "init:libbegetutil", ] diff --git a/services/engine/gstreamer/player/player_track_parse.h b/services/engine/gstreamer/player/player_track_parse.h index 7e830f7663406a3aae5152fc81fe421fd9c43a4d..426a2e6eac2a8d553f78ad60754a852e97236ed3 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 2be1aa745e17606e05418ea37531a9fc04282138..94eb18909c11d59bedb402e5daf435f5c501bd16 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/codec/hdi_plugins/BUILD.gn b/services/engine/gstreamer/plugins/codec/hdi_plugins/BUILD.gn index 70d6085a983425c317cc322b20eaadad584114f2..a3c964b8f60bb1884fda68f4cc92bafd0b2f9d7c 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/common/BUILD.gn b/services/engine/gstreamer/plugins/common/BUILD.gn index ff76be33ceb0855407df81d12a4c466cf98d2f59..83e8e8ebb9997cfffc7b3f6f3fcae603a739212f 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 2c83c19cd2d491fea37ee1db5ac213974f61afd1..f178f5fda8e30c1602999a7a95099b0d447afa0d 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 a78421d80bda925b89c3c763b655f916e5b88e6a..da384d688d701297559c3c619b065abd61c0b973 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 0ddaa6811311f24c6c9c186a204629a5ee75bf27..f33ce0269c42866c7d12a5e733331078f28a64d5 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/plugins/sink/memsink/BUILD.gn b/services/engine/gstreamer/plugins/sink/memsink/BUILD.gn index 6f7fad02853aad82bc8129c476cceb54c98cc8f1..20201f45a73941522492dd6ae650146b2c21e2db 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 28387dbecd8d9864cdc0c29d25efbf0b64be77b1..922ff1d307b215999c9382602337e25d7fa05cc9 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", ] diff --git a/services/engine/gstreamer/recorder/BUILD.gn b/services/engine/gstreamer/recorder/BUILD.gn index 649d47c94762330e9e93f5e0f0d461004b1338f5..b984e5ffd103bae11a6709ce285497c37fe7eb1f 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 0000000000000000000000000000000000000000..83c363bece003695bf3aff6e7605aca336a4f6c1 --- /dev/null +++ b/services/engine/histreamer/BUILD.gn @@ -0,0 +1,45 @@ +# 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") +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 0000000000000000000000000000000000000000..aefff3569df66d8f32ad614d30abf709043a02f1 --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/BUILD.gn @@ -0,0 +1,82 @@ +# 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") +import("//foundation/multimedia/player_framework/config.gni") + +config("media_engine_histreamer_avmetadatahelper_config") { + visibility = [ ":*" ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "$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", + ] +} + +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", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", + ] + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/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 0000000000000000000000000000000000000000..7030e1c84c546c8a6f9083bea96fe5c972ea3242 --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -0,0 +1,139 @@ +/* + * 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 { +static const std::unordered_map AVMETA_KEY_TO_X_MAP = { + { 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() +{ + 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 0000000000000000000000000000000000000000..5b1de3d81a7903e0dafff3a01c89c672142b4ae3 --- /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 0000000000000000000000000000000000000000..45c1de0c334c27f3c74bccd5e07749c37807275b --- /dev/null +++ b/services/engine/histreamer/avmetadatahelper/avmetadatahelper_impl.cpp @@ -0,0 +1,236 @@ +/* + * 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: + explicit HelperEventReceiver(AVMetadataHelperImpl* helperImpl) + { + helperImpl_ = helperImpl; + } + + void OnEvent(const Event &event) + { + helperImpl_->OnEvent(event); + } + +private: + AVMetadataHelperImpl* helperImpl_; +}; + +class HelperFilterCallback : public Pipeline::FilterCallback { +public: + explicit 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 ¶m) +{ + 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 0000000000000000000000000000000000000000..7d6aaa22bb62052788e2e20d2447f9aaee6510c8 --- /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 0000000000000000000000000000000000000000..c06fedea78fba400ad03b84fde252f293b5da6f3 --- /dev/null +++ b/services/engine/histreamer/factory/BUILD.gn @@ -0,0 +1,82 @@ +# 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") +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 = [ + "$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 = [] + defines += player_framework_defines +} + +ohos_static_library("media_engine_histreamer_factory") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "hst_engine_factory.cpp" ] + + configs = [ + ":media_engine_histreamer_factory_config", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + ] + + deps = [ "$MEDIA_PLAYER_ROOT_DIR/services/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/hst_engine_factory.cpp b/services/engine/histreamer/factory/hst_engine_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0dd81b660fd31e51ec777b1a33cdb5052cf739d0 --- /dev/null +++ b/services/engine/histreamer/factory/hst_engine_factory.cpp @@ -0,0 +1,119 @@ +/* + * 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 "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; + 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() +{ + return new (std::nothrow) OHOS::Media::HstEngineFactory(); +} +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/services/engine/histreamer/player/BUILD.gn b/services/engine/histreamer/player/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..53e51c50f3ebd46eef3984c7990739d6be50c94e --- /dev/null +++ b/services/engine/histreamer/player/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") +import("//foundation/multimedia/player_framework/config.gni") + +config("media_engine_histreamer_player_config") { + visibility = [ ":*" ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "$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", + ] +} + +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", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", + ] + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/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 0000000000000000000000000000000000000000..848bde56f7997d45fb8578b7259cfc4db799154a --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_callback_looper.cpp @@ -0,0 +1,208 @@ +/* + * 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" + +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; + +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) +{ + 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; +} + +void HiPlayerCallbackLooper::ManualReportMediaProgressOnce() +{ +} + +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"); + } + } +} + +void HiPlayerCallbackLooper::OnError(PlayerErrorType errorType, int32_t 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(*ptr)), static_cast(std::get(*ptr))); + obs->OnInfo(std::get(*ptr), std::get(*ptr), std::get(*ptr)); + } +} + +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 0000000000000000000000000000000000000000..bfec035668eaa38e0711f00ba70d89301e52378d --- /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 0000000000000000000000000000000000000000..1b595be52f65936c83afa99e29dcf27f65f5f61d --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_impl.cpp @@ -0,0 +1,698 @@ +/* + * 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 "audio_info.h" +#include "av_common.h" +#include "common/log.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. +} + +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: + explicit PlayerEventReceiver(HiPlayerImpl* hiPlayerImpl) + { + hiPlayerImpl_ = hiPlayerImpl; + } + + void OnEvent(const Event &event) + { + hiPlayerImpl_->OnEvent(event); + } + +private: + HiPlayerImpl* hiPlayerImpl_; +}; + +class PlayerFilterCallback : public FilterCallback { +public: + explicit 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(); +} + +HiPlayerImpl::~HiPlayerImpl() +{ + MEDIA_LOG_I("dtor called."); + pipeline_->Stop(); + audioSink_.reset(); +#ifdef VIDEO_SUPPORT + videoSink_.reset(); +#endif +} + +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) { + 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(); + 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(); + } + 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) { + 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) +{ + 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() +{ + 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_); + } + 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_); + } + 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 0000000000000000000000000000000000000000..2707020dff1b42d65118f22271ef1f222c74f961 --- /dev/null +++ b/services/engine/histreamer/player/hiplayer_impl.h @@ -0,0 +1,134 @@ +/* + * 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 "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" +#ifdef VIDEO_SUPPORT +#include "video_sink_filter.h" +#endif + +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 0000000000000000000000000000000000000000..eba71be7c1b7a97ba6f4603f5b3adacee203dcdc --- /dev/null +++ b/services/engine/histreamer/recorder/BUILD.gn @@ -0,0 +1,78 @@ +# 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_recorder_config") { + visibility = [ ":*" ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-fexceptions", + "-fno-rtti", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + + include_dirs = [ + "$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", + ] +} + +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", + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx_public_config", + "$MEDIA_PLAYER_ROOT_DIR/services/utils:media_service_utils_public_config", + ] + + deps = [ + "$MEDIA_PLAYER_ROOT_DIR/services/dfx:media_service_log_dfx", + "$MEDIA_PLAYER_ROOT_DIR/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 0000000000000000000000000000000000000000..7937046966c2e28fd3b60f3a3d1b352d4f680040 --- /dev/null +++ b/services/engine/histreamer/recorder/hirecorder_impl.cpp @@ -0,0 +1,474 @@ +/* + * 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: + explicit (HiRecorderImpl *hiRecorderImpl) + { + hiRecorderImpl_ = hiRecorderImpl; + } + + void OnEvent(const Event &event) + { + hiRecorderImpl_->OnEvent(event); + } + + private: + HiRecorderImpl *hiRecorderImpl_; + }; + + class RecorderFilterCallback : public Pipeline::FilterCallback { + public: + explicit 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_); + 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) { + MEDIA_LOG_I("OnEvent EVENT_ERROR obs is nullptr."); + } + 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 0000000000000000000000000000000000000000..5edc97cdf66bc0f8db348ed84124996302fb064d --- /dev/null +++ b/services/engine/histreamer/recorder/hirecorder_impl.h @@ -0,0 +1,131 @@ +/* + * 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 0000000000000000000000000000000000000000..a946a7a5d9bf484c9a22772e0cb868c8cb5f6f55 --- /dev/null +++ b/services/engine/histreamer/recorder/recorder_utils.h @@ -0,0 +1,58 @@ +/* + * 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 OHOS_MEDIA_RECORDER_UTILS_H +#define OHOS_MEDIA_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)); + } +}; +} // Media +} // OHOS +#endif // OHOS_MEDIA_RECORDER_UTILS_H \ No newline at end of file diff --git a/services/include/i_avcodec_service.h b/services/include/i_avcodec_service.h index 5065a4f1d12d1213979b207d7924f3a4290ede1a..8b832dd58bc02fe92e6f68b2652e298fec25efdc 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 c9d70953a51837c69fd3acbacd7c13c56665248d..7940c04d22f9d871089a2358efecf09190bc7fc6 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 36ee3abeeb368232b711e64b3c6920e6ff74611f..1e9ecad7680d67ccc7ceced6de1570d3e5f169e7 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 7e6afa5e236aebf9985ecf90935e55c7dc5da346..e4c9b3e4a0f1d8662134eae105109ccaac169c8d 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 0536c457467ab07866b0472bb8c838ed312afcd1..5cc2b150c845e7400dc5546c9a4b6c8c1ec74284 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 d544f9759a88b327357a529bfdcc74732c62db49..699db181777a44517c024e82a9eba5d6140074b3 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 0d5753b4b24119187230c624cfcd8645b8144294..eaf1bc9291a2670c2a706e9da82ebea79a264856 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 097d8b3290cefc162b21f218c14d1e7b13f3a2d7..66969b77f5202fff67219e7ed883eb851b69274c 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 03ac586714eee4faf505f3bca16acf28c36420db..5756797c8dbbb3ab08d85cc052352dcdd9176d46 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 93b5cb679fd17552943179eabfd617bf99cf82bd..5e50b808541636f867a334bcdbabfaa6d04df0eb 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 91a41ba34577f64ff5e6cc28e158f14fa46625a7..10d5d9bdb0ca503fd203d99079b0c7b54dcedcab 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 448bf0cb2e78b56b8a4226ae3ec479bc545e53e9..08d253ee74fe2bdc8f1b8ce3f001e63408ec9cca 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 2f1ccf1348b69632c39ca2fcb3258e795775cdae..dc39c1da6edc35af690cd818b90ac9d91cd61dc3 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 799b5d5ae2fc42814bcbb34f70fa064c1fd66f25..715531ea30bdbcbd22449c3f99d0df5c1d664d14 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 cb483f083ddd175c82e9e40994f6d966140e603e..57889ccba21e92478ea80ffe20cdd4ff954d9baa 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 af9c902a32a66f1e1c12b6f8fd4fa815413f1412..8fce927a5b1b8396e554db65bec19d0955ed5e69 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 2a1f019da4b5b21f243b524d83fdb95e2a17a1c4..b226c5efcd1a5d60bf65be0e5e9a05ab3eb3e559 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 8228eb20e6a5e405e98935a8f2e99c04b8975622..0000000000000000000000000000000000000000 --- 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 ac2cb9cdeb111dfadb9ee53f7828f99bdb682a78..2278c71240dc13f035e08b898c7c66bfe6d0ddb9 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 8dc7bff0df13d54414277c90e41889dc85739afb..0000000000000000000000000000000000000000 --- 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 f03492d39739a31b967b943cc7e7d2c222bb5346..4cfacb6945683ab4f9647e68460ccf40854dd710 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 c13636d1973f0e5c44f76addfbd0ce96f6262b67..0000000000000000000000000000000000000000 --- 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 f1b189759887af03877fe07fe71dae9eee440bdd..22a15d63a0eb0e8ae9adbf9d1056d0b0c6ab4d93 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 2ee196678cdbdc6342ddd292735d5cdf057e50eb..bafec71ec8254ab6e46fefaeb79759cf1d6d80c9 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 1aecd59f9228f0665a488c7c02ff20b2f7841414..3f3f5a208e7199b1fad9327fcc22289b904f53ab 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 4fee175aed36ea4c349868007f3bf751b84462fa..25eba518bb2d2d6944d3adddead882c248dd3afe 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 e4d12792f0c72610ef6b0c5d16f43db03a622afe..ecc7c5ac779cb3b6b260b70341c1addd152f1a68 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 a22ac59d973e10d35afb1402433b7985e8114f56..56d71b99d498bcb865cc0d2e116ba819c9cfb64c 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 {