From c60bfabf54141729b524eae5df16e8e1f97cdd49 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 01/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin --- .../avmetadatahelper_impl.cpp | 26 ++++++++- .../avmetadatahelper/avmetadatahelper_impl.h | 1 + .../inner_api/native/avmetadatahelper.h | 53 ++++++++++++++++++- .../av_thumbnail_generator.cpp | 7 ++- .../avmetadatahelper/av_thumbnail_generator.h | 1 + .../avmetadatahelper/avmetadata_collector.cpp | 27 ++++++++++ .../avmetadatahelper/avmetadata_collector.h | 1 + 7 files changed, 112 insertions(+), 4 deletions(-) diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp index 1708425d4..54d04aa52 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp @@ -110,6 +110,17 @@ static const std::unordered_map HDR_ { CM_BT2020_PQ_LIMIT, ColorManager::ColorSpaceName::BT2020_PQ_LIMIT }, }; +static const std::unordered_map VIDEOORIENTATIONTYPE_ROTATION_MAP = { + { Plugins::VideoOrientationType::FLIP_H, 0 }, + { Plugins::VideoOrientationType::FLIP_V, 0 }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, 0 }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, 0 }, + { Plugins::VideoOrientationType::FLIP_H_ROT180, 0 }, + { Plugins::VideoOrientationType::FLIP_V_ROT180, 0 }, + { Plugins::VideoOrientationType::FLIP_H_ROT270, 0 }, + { Plugins::VideoOrientationType::FLIP_V_ROT270, 0 }, +} + struct PixelMapMemHolder { bool isShmem; std::shared_ptr shmem; @@ -372,6 +383,11 @@ std::shared_ptr AVMetadataHelperImpl::CreatePixelMapYuv(const std::sha Plugins::VideoRotation rotation = Plugins::VideoRotation::VIDEO_ROTATION_0; bufferMeta->Get(rotation); pixelMapInfo.rotation = static_cast(rotation); + + Plugins::VideoOrientationType orientation = Plugins::VideoOrientationType::ROTATE_NONE; + bufferMeta->Get(orientation); + pixelMapInfo.orientation = static_cast(orientation); + bufferMeta->Get(pixelMapInfo.isHdr); if (pixelMapInfo.pixelFormat == PixelFormat::UNKNOWN) { @@ -907,7 +923,15 @@ std::shared_ptr AVMetadataHelperImpl::FetchFrameBase(int64_t timeUs, i DumpPixelMap(isDump_, pixelMap, DUMP_FILE_NAME_AFTER_SCLAE); - if (pixelMapInfo.rotation > 0) { + if (param.isSupportFlip && pixelMapInfo.orientation >= Plugins::VideoOrientationType::FLIP_H) { + MEDIA_LOGI("Support flip"); + pixelMapInfo.orientation % 2 == 0 ? pixelMap->flip(true, false) : pixelMap->flip(false, true); + auto it = VIDEOORIENTATIONTYPE_ROTATION_MAP.find(pixelMapInfo.orientation); + CHECK_AND_RETURN_RET_LOG(it != VIDEOORIENTATIONTYPE_ROTATION_MAP.end(), nullptr, + "can't find mapped orientation name in VIDEOORIENTATIONTYPE_ROTATION_MAP"); + pixelMap->rotate(it->second); + } else if (pixelMapInfo.rotation > 0) { + MEDIA_LOGI("Not support flip"); pixelMap->rotate(pixelMapInfo.rotation); } diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.h b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.h index 7d9819944..e84682cad 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.h +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.h @@ -60,6 +60,7 @@ public: private: struct PixelMapInfo { int32_t rotation = 0; + int32_t orientation = 0; PixelFormat pixelFormat = PixelFormat::NV12; bool isHdr = false; int32_t width = 0; diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index a1c532a08..07ed08909 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -98,6 +98,7 @@ static const std::map g_MetadataCodeMap = { {37, "videoWidth"}, {38, "videoOrientation"}, {39, "hdrType"}, + {44, "videoRotateOrientation"}, }; /** @@ -283,7 +284,7 @@ enum AVMetadataCode : int32_t { AV_KEY_VIDEO_WIDTH = 37, /** * The metadata key to retrieve the information about the video - * orientation. + * rotation. */ AV_KEY_VIDEO_ORIENTATION = 38, /** @@ -311,6 +312,11 @@ enum AVMetadataCode : int32_t { * Tracks info key-value map */ AV_KEY_TRACKS = 43, + /** + * The metadata key to retrieve the information about the video + * orientation. + */ + AV_KEY_VIDEO_ROTATE_ORIENTATION = 44, }; /** @@ -356,6 +362,46 @@ enum FrameScaleMode : int32_t { ASPECT_RATIO, }; +/** + * @brief Enumeration for video flip information. + * + * This enum defines rotation and flip information of the video. + */ +enum VideoOrientationType : int32_t { + /** + * No rotation or default + */ + TOP_LEFT = 1, + /** + * Flip horizontally + */ + TOP_RIGHT, + /** + * Rotation by 180 degrees + */ + BOTTOM_RIGHT, + /** + * Flip vertically + */ + BOTTOM_LEFT, + /** + * Flip horizontally and rotate 270 degrees + */ + LEFT_TOP, + /** + * Rotation by 90 degrees + */ + RIGHT_TOP + /** + * Flip horizontally and rotate 90 degrees + */ + RIGHT_BOTTOM, + /** + * Rotation by 270 degrees + */ + LEFT_BOTTOM, +} + /** * @brief Provides the definition of the returned pixelmap's configuration */ @@ -375,6 +421,11 @@ struct PixelMapParams { * RGB_565, RGB_888, RGBA_8888 are supported. */ PixelFormat colorFormat = PixelFormat::RGB_565; + /** + * Expected whether it supports flip, flase is the default value, + * indicating that flipping is not required, true indicates that flipping is required + */ + bool isSupportFlip = false; }; /** diff --git a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp index 0495e8e8e..fb019dd50 100644 --- a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp +++ b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp @@ -288,8 +288,10 @@ std::shared_ptr AVThumbnailGenerator::GetVideoTrackInfo() trackIndex_ = index; MEDIA_LOGI("0x%{public}06" PRIXPTR " GetTrackInfo success trackIndex_:%{public}zu, trackMime_:%{public}s", FAKE_POINTER(this), trackIndex_, trackMime_.c_str()); - if (trackInfos[index]->Get(rotation_)) { - MEDIA_LOGI("rotation %{public}d", static_cast(rotation_)); + if (trackInfos[index]->Get(rotation_) && + trackInfos[index]->Get(orientaton_)) { + MEDIA_LOGI("rotation is %{public}d, orientaton is %{public}d", static_cast(rotation_), + static_cast(orientaton_)); } return trackInfos[trackIndex_]; } @@ -575,6 +577,7 @@ void AVThumbnailGenerator::HandleFetchFrameYuvRes() avBuffer_->meta_->Set(width_); avBuffer_->meta_->Set(height_); avBuffer_->meta_->Set(rotation_); + avBuffer_->meta_->Set(orientation_); } } diff --git a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.h b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.h index 00b82f452..a0e49c77a 100644 --- a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.h +++ b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.h @@ -66,6 +66,7 @@ private: std::atomic_bool isBufferAvailable_{ false }; std::string trackMime_; Plugins::VideoRotation rotation_ = Plugins::VideoRotation::VIDEO_ROTATION_0; + Plugins::VideoOrientationType orientation_ = Plugins::VideoOrientationType::ROTATE_NONE ; size_t trackIndex_{0}; std::shared_ptr trackInfo_; std::mutex mutex_; diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 84e825d3c..6de7145bf 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -51,6 +51,21 @@ static const std::unordered_map fileTypeMap = { { Plugins::FileType::MPEGPS, "mpg" } }; +static const std::unordered_map videoOrientationTypeMap = { + { Plugins::VideoOrientationType::ROTATE_NONE, 1 }, + { Plugins::VideoOrientationType::ROTATE_90, 6 }, + { Plugins::VideoOrientationType::ROTATE_180, 3 }, + { Plugins::VideoOrientationType::ROTATE_270, 5 }, + { Plugins::VideoOrientationType::FLIP_H, 2 }, + { Plugins::VideoOrientationType::FLIP_V, 4 }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, 7 }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, 5 }, + { Plugins::VideoOrientationType::FLIP_H_ROT180, 4 }, + { Plugins::VideoOrientationType::FLIP_V_ROT180, 3 }, + { Plugins::VideoOrientationType::FLIP_H_ROT270, 5 }, + { Plugins::VideoOrientationType::FLIP_V_ROT270, 7 },S +} + static const std::unordered_map AVMETA_KEY_TO_X_MAP = { { AV_KEY_ALBUM, Tag::MEDIA_ALBUM }, { AV_KEY_ALBUM_ARTIST, Tag::MEDIA_ALBUM_ARTIST }, @@ -70,6 +85,7 @@ static const std::unordered_map AVMETA_KEY_TO_X_MAP = { { AV_KEY_VIDEO_HEIGHT, Tag::VIDEO_HEIGHT }, { AV_KEY_VIDEO_WIDTH, Tag::VIDEO_WIDTH }, { AV_KEY_VIDEO_ORIENTATION, Tag::VIDEO_ROTATION }, + { AV_KEY_VIDEO_ROTATE_ORIENTATION, Tag::VIDEO_ORIENTATION_TYPE }, { AV_KEY_VIDEO_IS_HDR_VIVID, Tag::VIDEO_IS_HDR_VIVID }, { AV_KEY_LOCATION_LONGITUDE, Tag::MEDIA_LONGITUDE}, { AV_KEY_LOCATION_LATITUDE, Tag::MEDIA_LATITUDE}, @@ -430,6 +446,7 @@ void AVMetaDataCollector::FormatAVMeta( } FormatMimeType(avmeta, globalInfo); FormatDateTime(avmeta, globalInfo); + FormatVideoRotateOrientation(avmeta, globalInfo); } void AVMetaDataCollector::FormatMimeType(Metadata &avmeta, const std::shared_ptr &globalInfo) @@ -468,6 +485,16 @@ void AVMetaDataCollector::FormatDateTime(Metadata &avmeta, const std::shared_ptr formattedDateTime.compare(date) != 0 ? formattedDateTime : TimeFormatUtils::FormatDataTimeByString(date)); } +void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta, const std::shared_ptr &globalInfo) +{ + Plugins::VideoOrientationType videoOrientationType; + globalInfo->GetData(Tag::VIDEO_ORIENTATION_TYPE, videoOrientationType); + auto it = videoOrientationTypeMap.find(videoOrientationType); + CHECK_AND_RETURN_LOG(it != videoOrientationTypeMap.end(), + "can't find mapped videoOrientationType name in videoOrientationTypeMap"); + avmeta.SetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION, std::to_string(it->second)); +} + void AVMetaDataCollector::SetEmptyStringIfNoData(Metadata &avmeta, int32_t avKey) const { if (!avmeta.HasMeta(avKey)) { diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h index 038cf3aac..f2806623f 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h @@ -96,6 +96,7 @@ private: void FormatAVMeta(Metadata &avmeta, int32_t imageTrackCount, const std::shared_ptr &globalInfo); void FormatMimeType(Metadata &avmeta, const std::shared_ptr &globalInfo); void FormatDateTime(Metadata &avmeta, const std::shared_ptr &globalInfo); + void FormatVideoRotateOrientation(Metadata &avmeta, const std::shared_ptr &globalInfo); void SetEmptyStringIfNoData(Metadata &avmeta, int32_t avKey) const; bool SetStringByValueType(const std::shared_ptr &innerMeta, Metadata &avmeta, int32_t avKey, std::string innerKey) const; -- Gitee From f313765ded2d7b9fbe5303fd1c3c18f1119196cc Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 02/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- interfaces/inner_api/native/avmetadatahelper.h | 2 +- .../avmetadatahelper/avmetadata_collector.cpp | 12 ++++++++---- .../avmetadatahelper/avmetadata_collector.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index 07ed08909..ab8939a2c 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -364,7 +364,7 @@ enum FrameScaleMode : int32_t { /** * @brief Enumeration for video flip information. - * + * * This enum defines rotation and flip information of the video. */ enum VideoOrientationType : int32_t { diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 6de7145bf..8f8c06451 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -63,7 +63,7 @@ static const std::unordered_map videoOrie { Plugins::VideoOrientationType::FLIP_H_ROT180, 4 }, { Plugins::VideoOrientationType::FLIP_V_ROT180, 3 }, { Plugins::VideoOrientationType::FLIP_H_ROT270, 5 }, - { Plugins::VideoOrientationType::FLIP_V_ROT270, 7 },S + { Plugins::VideoOrientationType::FLIP_V_ROT270, 7 }, } static const std::unordered_map AVMETA_KEY_TO_X_MAP = { @@ -485,10 +485,9 @@ void AVMetaDataCollector::FormatDateTime(Metadata &avmeta, const std::shared_ptr formattedDateTime.compare(date) != 0 ? formattedDateTime : TimeFormatUtils::FormatDataTimeByString(date)); } -void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta, const std::shared_ptr &globalInfo) +void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta) { - Plugins::VideoOrientationType videoOrientationType; - globalInfo->GetData(Tag::VIDEO_ORIENTATION_TYPE, videoOrientationType); + int videoOrientationType = stoi(avmeta->GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION)); auto it = videoOrientationTypeMap.find(videoOrientationType); CHECK_AND_RETURN_LOG(it != videoOrientationTypeMap.end(), "can't find mapped videoOrientationType name in videoOrientationTypeMap"); @@ -521,6 +520,11 @@ bool AVMetaDataCollector::SetStringByValueType(const std::shared_ptr &inne if (innerMeta->GetData(innerKey, rotation)) { avmeta.SetMeta(avKey, std::to_string(rotation)); } + } else if (Any::IsSameTypeWith(type)) { + Plugins::VideoOrientationType orientation; + if (innerMeta->GetData(innerKey, orientation)) { + avmeta.SetMeta(avKey, std::to_string(orientation)); + } } else if (Any::IsSameTypeWith(type)) { int64_t duration; if (innerMeta->GetData(innerKey, duration)) { diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h index f2806623f..9cf36ce76 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.h @@ -96,7 +96,7 @@ private: void FormatAVMeta(Metadata &avmeta, int32_t imageTrackCount, const std::shared_ptr &globalInfo); void FormatMimeType(Metadata &avmeta, const std::shared_ptr &globalInfo); void FormatDateTime(Metadata &avmeta, const std::shared_ptr &globalInfo); - void FormatVideoRotateOrientation(Metadata &avmeta, const std::shared_ptr &globalInfo); + void FormatVideoRotateOrientation(Metadata &avmeta); void SetEmptyStringIfNoData(Metadata &avmeta, int32_t avKey) const; bool SetStringByValueType(const std::shared_ptr &innerMeta, Metadata &avmeta, int32_t avKey, std::string innerKey) const; -- Gitee From cf877e5c87278596ce53b4345daf7ec8c351f2f2 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 03/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- .../engine/histreamer/avmetadatahelper/avmetadata_collector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 8f8c06451..e6e745d34 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -446,7 +446,7 @@ void AVMetaDataCollector::FormatAVMeta( } FormatMimeType(avmeta, globalInfo); FormatDateTime(avmeta, globalInfo); - FormatVideoRotateOrientation(avmeta, globalInfo); + FormatVideoRotateOrientation(avmeta); } void AVMetaDataCollector::FormatMimeType(Metadata &avmeta, const std::shared_ptr &globalInfo) -- Gitee From b1c0c976efc7ed86b6d8d178efc174d3c444d071 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 04/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- .../avmetadatahelper/avmetadatahelper_impl.cpp | 16 +++++++++------- interfaces/inner_api/native/avmetadatahelper.h | 6 +++--- .../avmetadatahelper/av_thumbnail_generator.cpp | 6 +++--- .../avmetadatahelper/avmetadata_collector.cpp | 9 +++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp index 54d04aa52..0c204a340 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp @@ -54,6 +54,8 @@ constexpr uint8_t COLORPRIMARIES_OFFSET = 0; constexpr uint8_t TRANSFUNC_OFFSET = 8; constexpr uint8_t MATRIX_OFFSET = 16; constexpr uint8_t RANGE_OFFSET = 21; + +constexpr uint8_t FLIP_NUM = 2; } namespace OHOS { @@ -113,12 +115,12 @@ static const std::unordered_map HDR_ static const std::unordered_map VIDEOORIENTATIONTYPE_ROTATION_MAP = { { Plugins::VideoOrientationType::FLIP_H, 0 }, { Plugins::VideoOrientationType::FLIP_V, 0 }, - { Plugins::VideoOrientationType::FLIP_H_ROT90, 0 }, - { Plugins::VideoOrientationType::FLIP_V_ROT90, 0 }, - { Plugins::VideoOrientationType::FLIP_H_ROT180, 0 }, - { Plugins::VideoOrientationType::FLIP_V_ROT180, 0 }, - { Plugins::VideoOrientationType::FLIP_H_ROT270, 0 }, - { Plugins::VideoOrientationType::FLIP_V_ROT270, 0 }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, 90 }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, 90 }, + { Plugins::VideoOrientationType::FLIP_H_ROT180, 180 }, + { Plugins::VideoOrientationType::FLIP_V_ROT180, 180 }, + { Plugins::VideoOrientationType::FLIP_H_ROT270, 270 }, + { Plugins::VideoOrientationType::FLIP_V_ROT270, 270 }, } struct PixelMapMemHolder { @@ -925,7 +927,7 @@ std::shared_ptr AVMetadataHelperImpl::FetchFrameBase(int64_t timeUs, i if (param.isSupportFlip && pixelMapInfo.orientation >= Plugins::VideoOrientationType::FLIP_H) { MEDIA_LOGI("Support flip"); - pixelMapInfo.orientation % 2 == 0 ? pixelMap->flip(true, false) : pixelMap->flip(false, true); + pixelMapInfo.orientation % FLIP_NUM == 0 ? pixelMap->flip(true, false) : pixelMap->flip(false, true); auto it = VIDEOORIENTATIONTYPE_ROTATION_MAP.find(pixelMapInfo.orientation); CHECK_AND_RETURN_RET_LOG(it != VIDEOORIENTATIONTYPE_ROTATION_MAP.end(), nullptr, "can't find mapped orientation name in VIDEOORIENTATIONTYPE_ROTATION_MAP"); diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index ab8939a2c..ce24767b5 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -391,7 +391,7 @@ enum VideoOrientationType : int32_t { /** * Rotation by 90 degrees */ - RIGHT_TOP + RIGHT_TOP, /** * Flip horizontally and rotate 90 degrees */ @@ -400,7 +400,7 @@ enum VideoOrientationType : int32_t { * Rotation by 270 degrees */ LEFT_BOTTOM, -} +}; /** * @brief Provides the definition of the returned pixelmap's configuration @@ -422,7 +422,7 @@ struct PixelMapParams { */ PixelFormat colorFormat = PixelFormat::RGB_565; /** - * Expected whether it supports flip, flase is the default value, + * Expected whether it supports flip, false is the default value, * indicating that flipping is not required, true indicates that flipping is required */ bool isSupportFlip = false; diff --git a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp index fb019dd50..3c5bd9274 100644 --- a/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp +++ b/services/engine/histreamer/avmetadatahelper/av_thumbnail_generator.cpp @@ -289,9 +289,9 @@ std::shared_ptr AVThumbnailGenerator::GetVideoTrackInfo() MEDIA_LOGI("0x%{public}06" PRIXPTR " GetTrackInfo success trackIndex_:%{public}zu, trackMime_:%{public}s", FAKE_POINTER(this), trackIndex_, trackMime_.c_str()); if (trackInfos[index]->Get(rotation_) && - trackInfos[index]->Get(orientaton_)) { - MEDIA_LOGI("rotation is %{public}d, orientaton is %{public}d", static_cast(rotation_), - static_cast(orientaton_)); + trackInfos[index]->Get(orientation_)) { + MEDIA_LOGI("rotation is %{public}d, orientation is %{public}d", static_cast(rotation_), + static_cast(orientation_)); } return trackInfos[trackIndex_]; } diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index e6e745d34..6d8aea31a 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -51,7 +51,7 @@ static const std::unordered_map fileTypeMap = { { Plugins::FileType::MPEGPS, "mpg" } }; -static const std::unordered_map videoOrientationTypeMap = { +static const std::unordered_map videoOrientationTypeMap = { { Plugins::VideoOrientationType::ROTATE_NONE, 1 }, { Plugins::VideoOrientationType::ROTATE_90, 6 }, { Plugins::VideoOrientationType::ROTATE_180, 3 }, @@ -61,10 +61,10 @@ static const std::unordered_map videoOrie { Plugins::VideoOrientationType::FLIP_H_ROT90, 7 }, { Plugins::VideoOrientationType::FLIP_V_ROT90, 5 }, { Plugins::VideoOrientationType::FLIP_H_ROT180, 4 }, - { Plugins::VideoOrientationType::FLIP_V_ROT180, 3 }, + { Plugins::VideoOrientationType::FLIP_V_ROT180, 2 }, { Plugins::VideoOrientationType::FLIP_H_ROT270, 5 }, { Plugins::VideoOrientationType::FLIP_V_ROT270, 7 }, -} +}; static const std::unordered_map AVMETA_KEY_TO_X_MAP = { { AV_KEY_ALBUM, Tag::MEDIA_ALBUM }, @@ -487,7 +487,8 @@ void AVMetaDataCollector::FormatDateTime(Metadata &avmeta, const std::shared_ptr void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta) { - int videoOrientationType = stoi(avmeta->GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION)); + Plugins::VideoOrientationType videoOrientationType = + static_cast(stoi(avmeta.GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION))); auto it = videoOrientationTypeMap.find(videoOrientationType); CHECK_AND_RETURN_LOG(it != videoOrientationTypeMap.end(), "can't find mapped videoOrientationType name in videoOrientationTypeMap"); -- Gitee From 9b23ed4fb61f41249055acf64415f0a90dfcfe23 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 05/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- .../avmetadatahelper_impl.cpp | 2 +- .../inner_api/native/avmetadatahelper.h | 10 ++++---- .../avmetadatahelper/avmetadata_collector.cpp | 24 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp index 0c204a340..8a9612db4 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp @@ -925,7 +925,7 @@ std::shared_ptr AVMetadataHelperImpl::FetchFrameBase(int64_t timeUs, i DumpPixelMap(isDump_, pixelMap, DUMP_FILE_NAME_AFTER_SCLAE); - if (param.isSupportFlip && pixelMapInfo.orientation >= Plugins::VideoOrientationType::FLIP_H) { + if (param.isSupportFlip && VIDEOORIENTATIONTYPE_ROTATION_MAP.count(pixelMapInfo.orientation) > 0) { MEDIA_LOGI("Support flip"); pixelMapInfo.orientation % FLIP_NUM == 0 ? pixelMap->flip(true, false) : pixelMap->flip(false, true); auto it = VIDEOORIENTATIONTYPE_ROTATION_MAP.find(pixelMapInfo.orientation); diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index ce24767b5..843eaddc8 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -377,7 +377,7 @@ enum VideoOrientationType : int32_t { */ TOP_RIGHT, /** - * Rotation by 180 degrees + * Rotate clockwise by 180 degrees */ BOTTOM_RIGHT, /** @@ -385,19 +385,19 @@ enum VideoOrientationType : int32_t { */ BOTTOM_LEFT, /** - * Flip horizontally and rotate 270 degrees + * Flip horizontally and rotate clockwise by 270 degrees */ LEFT_TOP, /** - * Rotation by 90 degrees + * Rotate clockwise by 90 degrees */ RIGHT_TOP, /** - * Flip horizontally and rotate 90 degrees + * Flip horizontally and rotate clockwise by 90 degrees */ RIGHT_BOTTOM, /** - * Rotation by 270 degrees + * Rotate clockwise by 270 degrees */ LEFT_BOTTOM, }; diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 6d8aea31a..984f8a92d 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -52,18 +52,18 @@ static const std::unordered_map fileTypeMap = { }; static const std::unordered_map videoOrientationTypeMap = { - { Plugins::VideoOrientationType::ROTATE_NONE, 1 }, - { Plugins::VideoOrientationType::ROTATE_90, 6 }, - { Plugins::VideoOrientationType::ROTATE_180, 3 }, - { Plugins::VideoOrientationType::ROTATE_270, 5 }, - { Plugins::VideoOrientationType::FLIP_H, 2 }, - { Plugins::VideoOrientationType::FLIP_V, 4 }, - { Plugins::VideoOrientationType::FLIP_H_ROT90, 7 }, - { Plugins::VideoOrientationType::FLIP_V_ROT90, 5 }, - { Plugins::VideoOrientationType::FLIP_H_ROT180, 4 }, - { Plugins::VideoOrientationType::FLIP_V_ROT180, 2 }, - { Plugins::VideoOrientationType::FLIP_H_ROT270, 5 }, - { Plugins::VideoOrientationType::FLIP_V_ROT270, 7 }, + { Plugins::VideoOrientationType::ROTATE_NONE, VideoRotateOrientationType::TOP_LEFT }, + { Plugins::VideoOrientationType::ROTATE_90, VideoRotateOrientationType::RIGHT_TOP }, + { Plugins::VideoOrientationType::ROTATE_180, VideoRotateOrientationType::BOTTOM_RIGHT }, + { Plugins::VideoOrientationType::ROTATE_270, VideoRotateOrientationType::LEFT_BOTTOM }, + { Plugins::VideoOrientationType::FLIP_H, VideoRotateOrientationType::TOP_RIGHT }, + { Plugins::VideoOrientationType::FLIP_V, VideoRotateOrientationType::BOTTOM_LEFT }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, VideoRotateOrientationType::RIGHT_BOTTOM }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, VideoRotateOrientationType::LEFT_TOP }, + { Plugins::VideoOrientationType::FLIP_H_ROT180, VideoRotateOrientationType::BOTTOM_LEFT }, + { Plugins::VideoOrientationType::FLIP_V_ROT180, VideoRotateOrientationType::TOP_RIGHT }, + { Plugins::VideoOrientationType::FLIP_H_ROT270, VideoRotateOrientationType::LEFT_TOP }, + { Plugins::VideoOrientationType::FLIP_V_ROT270, VideoRotateOrientationType::RIGHT_BOTTOM }, }; static const std::unordered_map AVMETA_KEY_TO_X_MAP = { -- Gitee From cce6accbfe233fe84df906ce3a8ec996ad67f546 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 06/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- interfaces/inner_api/native/avmetadatahelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/native/avmetadatahelper.h b/interfaces/inner_api/native/avmetadatahelper.h index 843eaddc8..be33b41e4 100644 --- a/interfaces/inner_api/native/avmetadatahelper.h +++ b/interfaces/inner_api/native/avmetadatahelper.h @@ -367,7 +367,7 @@ enum FrameScaleMode : int32_t { * * This enum defines rotation and flip information of the video. */ -enum VideoOrientationType : int32_t { +enum VideoRotateOrientationType : int32_t { /** * No rotation or default */ -- Gitee From c833c5b63ba9ce196ee30e9e1bdeddc1af64e1c3 Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 07/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp | 2 +- .../engine/histreamer/avmetadatahelper/avmetadata_collector.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp index 8a9612db4..5bfacadfa 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp @@ -121,7 +121,7 @@ static const std::unordered_map VIDEOORIENTATIONTYPE_ROTATION_ { Plugins::VideoOrientationType::FLIP_V_ROT180, 180 }, { Plugins::VideoOrientationType::FLIP_H_ROT270, 270 }, { Plugins::VideoOrientationType::FLIP_V_ROT270, 270 }, -} +}; struct PixelMapMemHolder { bool isShmem; diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 984f8a92d..7d5cef8d8 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -488,7 +488,7 @@ void AVMetaDataCollector::FormatDateTime(Metadata &avmeta, const std::shared_ptr void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta) { Plugins::VideoOrientationType videoOrientationType = - static_cast(stoi(avmeta.GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION))); + static_cast(std::stoi(avmeta.GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION))); auto it = videoOrientationTypeMap.find(videoOrientationType); CHECK_AND_RETURN_LOG(it != videoOrientationTypeMap.end(), "can't find mapped videoOrientationType name in videoOrientationTypeMap"); -- Gitee From 3903b54f6c20f208627044d4e218e3e09865a67d Mon Sep 17 00:00:00 2001 From: sunyin Date: Tue, 15 Jul 2025 15:53:32 +0800 Subject: [PATCH 08/15] =?UTF-8?q?AR20250625714736=20=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E5=A2=9E=E5=8A=A0=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyin Signed-off-by: SunYin --- .../avmetadatahelper_impl.cpp | 9 +-- .../unittest/src/avmetadata_unit_test.cpp | 63 +++++++++++++++++++ .../avmetadatahelper/avmetadata_collector.cpp | 23 ++++--- .../avmetadata_collector_unit_test.cpp | 14 +++++ test/unittest/resources/ohos_test.xml | 2 + 5 files changed, 98 insertions(+), 13 deletions(-) diff --git a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp index 5bfacadfa..db114e613 100644 --- a/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp +++ b/frameworks/native/avmetadatahelper/avmetadatahelper_impl.cpp @@ -115,12 +115,8 @@ static const std::unordered_map HDR_ static const std::unordered_map VIDEOORIENTATIONTYPE_ROTATION_MAP = { { Plugins::VideoOrientationType::FLIP_H, 0 }, { Plugins::VideoOrientationType::FLIP_V, 0 }, - { Plugins::VideoOrientationType::FLIP_H_ROT90, 90 }, - { Plugins::VideoOrientationType::FLIP_V_ROT90, 90 }, - { Plugins::VideoOrientationType::FLIP_H_ROT180, 180 }, - { Plugins::VideoOrientationType::FLIP_V_ROT180, 180 }, - { Plugins::VideoOrientationType::FLIP_H_ROT270, 270 }, - { Plugins::VideoOrientationType::FLIP_V_ROT270, 270 }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, 270 }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, 270 }, }; struct PixelMapMemHolder { @@ -925,6 +921,7 @@ std::shared_ptr AVMetadataHelperImpl::FetchFrameBase(int64_t timeUs, i DumpPixelMap(isDump_, pixelMap, DUMP_FILE_NAME_AFTER_SCLAE); + MEDIA_LOGI("Rotation is %{public}d, orientation is %{public}d", pixelMapInfo.rotation, pixelMapInfo.orientation); if (param.isSupportFlip && VIDEOORIENTATIONTYPE_ROTATION_MAP.count(pixelMapInfo.orientation) > 0) { MEDIA_LOGI("Support flip"); pixelMapInfo.orientation % FLIP_NUM == 0 ? pixelMap->flip(true, false) : pixelMap->flip(false, true); diff --git a/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp b/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp index 3a8371d9d..c35846d2c 100644 --- a/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp +++ b/frameworks/native/avmetadatahelper/test/unittest/src/avmetadata_unit_test.cpp @@ -891,6 +891,69 @@ HWTEST_F(AVMetadataUnitTest, FetchFrameYuv_API_0200, Level2) ASSERT_EQ(pixelMap->GetHeight(), 2336); } +/** + * @tc.number : FetchFrameYuv_API_0300 + * @tc.name : FetchFrameYuv bird.mp4 + * @tc.desc : FetchFrameYuv API +*/ +HWTEST_F(AVMetadataUnitTest, FetchFrameYuv_API_0300, Level2) +{ + std::string uri = AVMetadataTestBase::GetInstance().GetMountPath() + + std::string("bird.mp4"); + std::shared_ptr helper = std::make_shared(); + ASSERT_NE(nullptr, helper); + ASSERT_EQ(true, helper->CreateAVMetadataHelper()); + ASSERT_EQ(MSERR_OK, helper->SetSource(uri, 0, 0, AVMetadataUsage::AV_META_USAGE_PIXEL_MAP)); + int64_t time = 0; + PixelMapParams param; + param.isSupportFlip = true; + auto pixelMap = helper->FetchFrameYuv(time, 0, param); + ASSERT_EQ(pixelMap->GetWidth(), 640); + ASSERT_EQ(pixelMap->GetHeight(), 274); +} + +/** + * @tc.number : FetchFrameYuv_API_0400 + * @tc.name : FetchFrameYuv bird_hf.mp4 + * @tc.desc : FetchFrameYuv API +*/ +HWTEST_F(AVMetadataUnitTest, FetchFrameYuv_API_0400, Level2) +{ + std::string uri = AVMetadataTestBase::GetInstance().GetMountPath() + + std::string("bird_hf.mp4"); + std::shared_ptr helper = std::make_shared(); + ASSERT_NE(nullptr, helper); + ASSERT_EQ(true, helper->CreateAVMetadataHelper()); + ASSERT_EQ(MSERR_OK, helper->SetSource(uri, 0, 0, AVMetadataUsage::AV_META_USAGE_PIXEL_MAP)); + int64_t time = 0; + PixelMapParams param; + param.isSupportFlip = true; + auto pixelMap = helper->FetchFrameYuv(time, 0, param); + ASSERT_EQ(pixelMap->GetWidth(), 640); + ASSERT_EQ(pixelMap->GetHeight(), 274); +} + +/** + * @tc.number : FetchFrameYuv_API_0500 + * @tc.name : FetchFrameYuv bird_hf.mp4 + * @tc.desc : FetchFrameYuv API +*/ +HWTEST_F(AVMetadataUnitTest, FetchFrameYuv_API_0500, Level2) +{ + std::string uri = AVMetadataTestBase::GetInstance().GetMountPath() + + std::string("bird_hf.mp4"); + std::shared_ptr helper = std::make_shared(); + ASSERT_NE(nullptr, helper); + ASSERT_EQ(true, helper->CreateAVMetadataHelper()); + ASSERT_EQ(MSERR_OK, helper->SetSource(uri, 0, 0, AVMetadataUsage::AV_META_USAGE_PIXEL_MAP)); + int64_t time = 0; + PixelMapParams param; + param.isSupportFlip = true; + auto pixelMap = helper->FetchFrameYuv(time, 0, param); + ASSERT_EQ(pixelMap->GetWidth(), 640); + ASSERT_EQ(pixelMap->GetHeight(), 274); +} + /** * @tc.number : FetchScaledFrameYuv_API_0100 * @tc.name : FetchScaledFrameYuv H264_AAC.mp4 custom scaling diff --git a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp index 7d5cef8d8..79eff21d5 100644 --- a/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp +++ b/services/engine/histreamer/avmetadatahelper/avmetadata_collector.cpp @@ -53,17 +53,17 @@ static const std::unordered_map fileTypeMap = { static const std::unordered_map videoOrientationTypeMap = { { Plugins::VideoOrientationType::ROTATE_NONE, VideoRotateOrientationType::TOP_LEFT }, - { Plugins::VideoOrientationType::ROTATE_90, VideoRotateOrientationType::RIGHT_TOP }, + { Plugins::VideoOrientationType::ROTATE_90, VideoRotateOrientationType::LEFT_BOTTOM }, { Plugins::VideoOrientationType::ROTATE_180, VideoRotateOrientationType::BOTTOM_RIGHT }, - { Plugins::VideoOrientationType::ROTATE_270, VideoRotateOrientationType::LEFT_BOTTOM }, + { Plugins::VideoOrientationType::ROTATE_270, VideoRotateOrientationType::RIGHT_TOP }, { Plugins::VideoOrientationType::FLIP_H, VideoRotateOrientationType::TOP_RIGHT }, { Plugins::VideoOrientationType::FLIP_V, VideoRotateOrientationType::BOTTOM_LEFT }, - { Plugins::VideoOrientationType::FLIP_H_ROT90, VideoRotateOrientationType::RIGHT_BOTTOM }, - { Plugins::VideoOrientationType::FLIP_V_ROT90, VideoRotateOrientationType::LEFT_TOP }, + { Plugins::VideoOrientationType::FLIP_H_ROT90, VideoRotateOrientationType::LEFT_TOP }, + { Plugins::VideoOrientationType::FLIP_V_ROT90, VideoRotateOrientationType::RIGHT_BOTTOM }, { Plugins::VideoOrientationType::FLIP_H_ROT180, VideoRotateOrientationType::BOTTOM_LEFT }, { Plugins::VideoOrientationType::FLIP_V_ROT180, VideoRotateOrientationType::TOP_RIGHT }, - { Plugins::VideoOrientationType::FLIP_H_ROT270, VideoRotateOrientationType::LEFT_TOP }, - { Plugins::VideoOrientationType::FLIP_V_ROT270, VideoRotateOrientationType::RIGHT_BOTTOM }, + { Plugins::VideoOrientationType::FLIP_H_ROT270, VideoRotateOrientationType::RIGHT_BOTTOM }, + { Plugins::VideoOrientationType::FLIP_V_ROT270, VideoRotateOrientationType::LEFT_TOP }, }; static const std::unordered_map AVMETA_KEY_TO_X_MAP = { @@ -487,8 +487,17 @@ void AVMetaDataCollector::FormatDateTime(Metadata &avmeta, const std::shared_ptr void AVMetaDataCollector::FormatVideoRotateOrientation(Metadata &avmeta) { + std::string videoRotateOrientationType = avmeta.GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION); + MEDIA_LOGI("VideoRotateOrientationType is %{public}s", videoRotateOrientationType); + int32_t videoRotateOrientationTypeRet = Pligins::VideoOrientationType::ROTATE_NONE; + if (videoRotateOrientationType == "") { + MEDIA_LOGE("videoRotateOrientationType is empty"); + avmeta.SetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION, std::to_string(VideoRotateOrientationType::TOP_LEFT)); + return; + } + videoRotateOrientationTypeRet = std::stoi(videoRotateOrientationType); Plugins::VideoOrientationType videoOrientationType = - static_cast(std::stoi(avmeta.GetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION))); + static_cast(videoRotateOrientationTypeRet); auto it = videoOrientationTypeMap.find(videoOrientationType); CHECK_AND_RETURN_LOG(it != videoOrientationTypeMap.end(), "can't find mapped videoOrientationType name in videoOrientationTypeMap"); diff --git a/test/unittest/avmetadata_helper_test/avmetadata_collector_unit_test.cpp b/test/unittest/avmetadata_helper_test/avmetadata_collector_unit_test.cpp index 2ad8fb462..abe4c46d3 100644 --- a/test/unittest/avmetadata_helper_test/avmetadata_collector_unit_test.cpp +++ b/test/unittest/avmetadata_helper_test/avmetadata_collector_unit_test.cpp @@ -81,6 +81,7 @@ HWTEST_F(AVMetaDataCollectorUnitTest, ExtractMetadata, TestSize.Level1) globalMeta->SetData(Tag::MEDIA_FILE_TYPE, Plugins::FileType::MP4); videoMeta->SetData(Tag::VIDEO_ROTATION, Plugins::VideoRotation::VIDEO_ROTATION_0); + videoMeta->SetData(Tag::VIDEO_ORIENTATION_TYPE, Plugins::VideoOrientationType::ROTATE_NONE); videoMeta->SetData(Tag::VIDEO_HEIGHT, "480"); videoMeta->SetData(Tag::VIDEO_WIDTH, "720"); videoMeta->SetData(Tag::MIME_TYPE, "video/mp4"); @@ -290,6 +291,19 @@ HWTEST_F(AVMetaDataCollectorUnitTest, FormatDateTime, TestSize.Level1) avmetaDataCollector->FormatDateTime(avmeta, globalInfo); EXPECT_TRUE(avmeta.HasMeta(AV_KEY_DATE_TIME)); } + +/** + * @tc.name: FormatVideoRotateOrientation + * @tc.desc: FormatVideoRotateOrientation + * @tc.type: FUNC + */ +HWTEST_F(AVMetaDataCollectorUnitTest, FormatVideoRotateOrientation, TestSize.Level1) +{ + Metadata avmeta; + avmeta.SetMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION, ""); + avmetaDataCollector->FormatVideoRotateOrientation(avmeta); + EXPECT_TRUE(avmeta.HasMeta(AV_KEY_VIDEO_ROTATE_ORIENTATION)); +} /** * @tc.name: ConvertToAVMeta diff --git a/test/unittest/resources/ohos_test.xml b/test/unittest/resources/ohos_test.xml index 4defd6749..793e219de 100644 --- a/test/unittest/resources/ohos_test.xml +++ b/test/unittest/resources/ohos_test.xml @@ -562,6 +562,8 @@