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