• 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_sink_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<IImageSinkProcessorListener> & imageListener)25 int32_t ImageSinkProcessor::ConfigureImageProcessor(
26     const VideoParam &localParam, const VideoParam &remoteParam,
27     const std::shared_ptr<IImageSinkProcessorListener> &imageListener)
28 {
29     DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG);
30     localParam_ = localParam;
31     remoteParam_ = remoteParam;
32 
33     imageDecoder_ = std::make_shared<ImageSinkDecoder>(imageListener);
34 
35     int32_t ret = imageDecoder_->ConfigureDecoder(localParam);
36     if (ret != DH_SUCCESS) {
37         DHLOGE("%s: ConfigureDecoder failed ret:%d.", LOG_TAG, ret);
38         return ret;
39     }
40 
41     return DH_SUCCESS;
42 }
43 
ReleaseImageProcessor()44 int32_t ImageSinkProcessor::ReleaseImageProcessor()
45 {
46     DHLOGI("%s: ReleaseImageProcessor.", LOG_TAG);
47     if (imageDecoder_ == nullptr) {
48         DHLOGE("%s: Decoder is null.", LOG_TAG);
49         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "ReleaseImageProcessor Decoder is null.");
50         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
51     }
52 
53     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_RELEASE_DECODER_START);
54     int32_t ret = imageDecoder_->ReleaseDecoder();
55     FinishTrace(DSCREEN_HITRACE_LABEL);
56     if (ret != DH_SUCCESS) {
57         DHLOGE("%s: ReleaseDecoder failed.", LOG_TAG);
58         ReportOptFail(DSCREEN_OPT_FAIL, ret, "ReleaseDecoder failed.");
59         return ret;
60     }
61 
62     return DH_SUCCESS;
63 }
64 
StartImageProcessor()65 int32_t ImageSinkProcessor::StartImageProcessor()
66 {
67     DHLOGI("%s: StartImageProcessor.", LOG_TAG);
68     if (imageDecoder_ == nullptr) {
69         DHLOGE("%s: Decoder is null.", LOG_TAG);
70         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StartImageProcessor Decoder is null.");
71         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
72     }
73 
74     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_START_DECODER_START);
75     int32_t ret = imageDecoder_->StartDecoder();
76     FinishTrace(DSCREEN_HITRACE_LABEL);
77     if (ret != DH_SUCCESS) {
78         DHLOGE("%s: StartDecoder failed ret:%d.", LOG_TAG, ret);
79         ReportOptFail(DSCREEN_OPT_FAIL, ret, "StartDecoder failed.");
80         return ret;
81     }
82 
83     return DH_SUCCESS;
84 }
85 
StopImageProcessor()86 int32_t ImageSinkProcessor::StopImageProcessor()
87 {
88     DHLOGI("%s: StopImageProcessor.", LOG_TAG);
89     if (imageDecoder_ == nullptr) {
90         DHLOGE("%s: Decoder is null.", LOG_TAG);
91         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StopImageProcessor Decoder is null.");
92         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
93     }
94 
95     StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_STOP_DECODER_START);
96     int32_t ret = imageDecoder_->StopDecoder();
97     FinishTrace(DSCREEN_HITRACE_LABEL);
98     if (ret != DH_SUCCESS) {
99         DHLOGE("%s: StopDecoder failed ret:%d.", LOG_TAG, ret);
100         ReportOptFail(DSCREEN_OPT_FAIL, ret, "StopDecoder failed.");
101         return ret;
102     }
103 
104     return DH_SUCCESS;
105 }
106 
SetImageSurface(sptr<Surface> & surface)107 int32_t ImageSinkProcessor::SetImageSurface(sptr<Surface> &surface)
108 {
109     DHLOGI("%s: SetImageSurface.", LOG_TAG);
110     if (imageDecoder_ == nullptr) {
111         DHLOGE("%s: Decoder is null.", LOG_TAG);
112         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "SetImageSurface Decoder is null.");
113         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
114     }
115 
116     int32_t ret = imageDecoder_->SetOutputSurface(surface);
117     if (ret != DH_SUCCESS) {
118         DHLOGE("%s: SetOutputSurface failed ret:%d.", LOG_TAG, ret);
119         ReportOptFail(DSCREEN_OPT_FAIL, ret, "SetOutputSurface failed.");
120         return ret;
121     }
122 
123     return DH_SUCCESS;
124 }
125 
ProcessImage(const std::shared_ptr<DataBuffer> & data)126 int32_t ImageSinkProcessor::ProcessImage(const std::shared_ptr<DataBuffer> &data)
127 {
128     DHLOGI("%s: ProcessImage.", LOG_TAG);
129     if (imageDecoder_ == nullptr) {
130         DHLOGE("%s: Decoder is null.", LOG_TAG);
131         ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "processImage Decoder is null.");
132         return ERR_DH_SCREEN_TRANS_NULL_VALUE;
133     }
134 
135     int32_t ret = imageDecoder_->InputScreenData(data);
136     if (ret != DH_SUCCESS) {
137         DHLOGE("%s: InputScreenData failed ret:%d.", LOG_TAG, ret);
138         ReportOptFail(DSCREEN_OPT_FAIL, ret, "InputScreenData failed.");
139         return ret;
140     }
141 
142     return DH_SUCCESS;
143 }
144 } // namespace DistributedHardware
145 } // namespace OHOS