• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "video_process_result.h"
17 
18 #include "dp_log.h"
19 #include "dps.h"
20 #include "events_monitor.h"
21 #include "service_died_command.h"
22 #include "video_process_command.h"
23 
24 namespace OHOS {
25 namespace CameraStandard {
26 namespace DeferredProcessing {
VideoProcessResult(const int32_t userId)27 VideoProcessResult::VideoProcessResult(const int32_t userId) : userId_(userId)
28 {
29     DP_DEBUG_LOG("entered.");
30 }
31 
~VideoProcessResult()32 VideoProcessResult::~VideoProcessResult()
33 {
34     DP_DEBUG_LOG("entered.");
35 }
36 
OnProcessDone(const std::string & videoId)37 void VideoProcessResult::OnProcessDone(const std::string& videoId)
38 {
39     DP_DEBUG_LOG("DPS_VIDEO: OnProcessDone videoId: %{public}s", videoId.c_str());
40     auto ret = DPS_SendCommand<VideoProcessSuccessCommand>(userId_, videoId);
41     DP_CHECK_ERROR_PRINT_LOG(ret != DP_OK,
42         "process success videoId: %{public}s failed. ret: %{public}d", videoId.c_str(), ret);
43 }
44 
OnProcessDone(const std::string & videoId,std::unique_ptr<MediaUserInfo> userInfo)45 void VideoProcessResult::OnProcessDone(const std::string& videoId, std::unique_ptr<MediaUserInfo> userInfo)
46 {
47     DP_DEBUG_LOG("DPS_VIDEO: OnProcessDone videoId: %{public}s", videoId.c_str());
48     auto ret = DPS_SendCommand<VideoProcessSuccessCommand>(userId_, videoId, std::move(userInfo));
49     DP_CHECK_ERROR_PRINT_LOG(ret != DP_OK,
50         "process success videoId: %{public}s failed. ret: %{public}d", videoId.c_str(), ret);
51 }
52 
OnError(const std::string & videoId,DpsError errorCode)53 void VideoProcessResult::OnError(const std::string& videoId, DpsError errorCode)
54 {
55     DP_DEBUG_LOG("DPS_VIDEO: OnError videoId: %{public}s, error: %{public}d", videoId.c_str(), errorCode);
56     auto ret = DPS_SendCommand<VideoProcessFailedCommand>(userId_, videoId, errorCode);
57     DP_CHECK_ERROR_PRINT_LOG(ret != DP_OK,
58         "process error videoId: %{public}s failed. ret: %{public}d", videoId.c_str(), ret);
59 }
60 
OnStateChanged(HdiStatus hdiStatus)61 void VideoProcessResult::OnStateChanged(HdiStatus hdiStatus)
62 {
63     DP_DEBUG_LOG("DPS_VIDEO: OnStateChanged hdiStatus: %{public}d", hdiStatus);
64     EventsMonitor::GetInstance().NotifyVideoEnhanceStatus(hdiStatus);
65 }
66 
OnVideoSessionDied()67 void VideoProcessResult::OnVideoSessionDied()
68 {
69     DP_ERR_LOG("DPS_VIDEO: OnVideoSessionDied");
70     auto ret = DPS_SendCommand<VideoDiedCommand>(userId_);
71     DP_CHECK_ERROR_PRINT_LOG(ret != DP_OK, "process video session deied failed, ret: %{public}d", ret);
72 }
73 
ProcessVideoInfo(const std::string & videoId,const sptr<HDI::Camera::V1_0::MapDataSequenceable> & metaData)74 int32_t VideoProcessResult::ProcessVideoInfo(const std::string& videoId,
75     const sptr<HDI::Camera::V1_0::MapDataSequenceable>& metaData)
76 {
77     if (metaData == nullptr) {
78         OnProcessDone(videoId);
79         return DP_OK;
80     }
81 
82     auto userInfo = std::make_unique<MediaUserInfo>();
83     double scalingFactor;
84     if (GetMetadataValue(metaData, VideoMetadataKeys::SCALING_FACTOR, scalingFactor)) {
85         userInfo->scalingFactor = static_cast<float>(scalingFactor);
86     }
87     std::string stringValue;
88     if (GetMetadataValue(metaData, VideoMetadataKeys::INTERPOLATION_FRAME_PTS, stringValue)) {
89         userInfo->interpolationFramePts = stringValue;
90     }
91     if (GetMetadataValue(metaData, VideoMetadataKeys::STAGE_VID, stringValue)) {
92         userInfo->stageVid = stringValue;
93     }
94 
95     DP_INFO_LOG("DPS_VIDEO: scalingFactor: %{public}f, interpolationFramePts: %{public}s, stageVid: %{public}s",
96         userInfo->scalingFactor, userInfo->interpolationFramePts.c_str(), userInfo->stageVid.c_str());
97     OnProcessDone(videoId, std::move(userInfo));
98     return DP_OK;
99 }
100 } // namespace DeferredProcessing
101 } // namespace CameraStandard
102 } // namespace OHOS
103