• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "image_source_processor.h"
17 
18 #include "dscreen_errcode.h"
19 #include "dscreen_hisysevent.h"
20 #include "dscreen_hitrace.h"
21 #include "dscreen_log.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
ConfigureImageProcessor(const VideoParam & localParam,const VideoParam & remoteParam,const std::shared_ptr<IImageSourceProcessorListener> & listener)25 int32_t ImageSourceProcessor::ConfigureImageProcessor(const VideoParam &localParam, const VideoParam &remoteParam,
26     const std::shared_ptr<IImageSourceProcessorListener> &listener)
27 {
28     DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG);
29     imageEncoder_ = std::make_shared<ImageSourceEncoder>(listener);
30 
31     int32_t ret = imageEncoder_->ConfigureEncoder(localParam);
32     if (ret != DH_SUCCESS) {
33         DHLOGE("%s: Configure screen encoder failed ret: %d.", LOG_TAG, ret);
34         return ret;
35     }
36 
37     localParam_ = localParam;
38     remoteParam_ = remoteParam;
39     return DH_SUCCESS;
40 }
41 
ReleaseImageProcessor()42 int32_t ImageSourceProcessor::ReleaseImageProcessor()
43 {
44     DHLOGI("%s: ReleaseImageProcessor.", LOG_TAG);
45     if (imageEncoder_ == nullptr) {
46         DHLOGE("%s: Create screen encoder failed.", LOG_TAG);
47         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "ReleaseImageProcessor encoder is nullptr.");
48         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
49     }
50 
51     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_RELESSE_ENCODER_START);
52     int32_t ret = imageEncoder_->ReleaseEncoder();
53     FinishTrace(DSCREEN_HITRACE_LABEL);
54     if (ret != DH_SUCCESS) {
55         DHLOGE("%s: Release screen encoder failed ret: %d.", LOG_TAG, ret);
56         ReportOptFail(DSCREEN_OPT_FAIL, ret, "Release screen encoder failed.");
57         return ret;
58     }
59 
60     return DH_SUCCESS;
61 }
62 
StartImageProcessor()63 int32_t ImageSourceProcessor::StartImageProcessor()
64 {
65     DHLOGI("%s: StartImageProcessor.", LOG_TAG);
66     if (imageEncoder_ == nullptr) {
67         DHLOGE("%s: Create screen encoder failed.", LOG_TAG);
68         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StartImageProcessor encoder is nullptr.");
69         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
70     }
71 
72     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_START_ENCODER_START);
73     int32_t ret = imageEncoder_->StartEncoder();
74     FinishTrace(DSCREEN_HITRACE_LABEL);
75     if (ret != DH_SUCCESS) {
76         DHLOGE("%s: Start screen encoder failed ret: %d.", LOG_TAG, ret);
77         ReportOptFail(DSCREEN_OPT_FAIL, ret, "Start screen encoder failed.");
78         return ret;
79     }
80 
81     return DH_SUCCESS;
82 }
83 
StopImageProcessor()84 int32_t ImageSourceProcessor::StopImageProcessor()
85 {
86     DHLOGI("%s: StopImageProcessor.", LOG_TAG);
87     if (imageEncoder_ == nullptr) {
88         DHLOGE("%s: Create screen encoder failed.", LOG_TAG);
89         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StopImageProcessor encoder is nullptr.");
90         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
91     }
92 
93     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_STOP_ENCODER_START);
94     int32_t ret = imageEncoder_->StopEncoder();
95     FinishTrace(DSCREEN_HITRACE_LABEL);
96     if (ret != DH_SUCCESS) {
97         DHLOGE("%s: Stop screen encoder failed ret: %d.", LOG_TAG, ret);
98         ReportOptFail(DSCREEN_OPT_FAIL, ret, "Stop screen encoder failed.");
99         return ret;
100     }
101 
102     return DH_SUCCESS;
103 }
104 
GetImageSurface()105 sptr<Surface> &ImageSourceProcessor::GetImageSurface()
106 {
107     DHLOGI("%s: GetImageSurface.", LOG_TAG);
108     return imageEncoder_->GetInputSurface();
109 }
110 } // namespace DistributedHardware
111 } // namespace OHOS