1 /*
2  * Copyright (c) 2021 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 "dcamera_sink_output_channel_listener.h"
17 
18 #include "distributed_hardware_log.h"
19 
20 namespace OHOS {
21 namespace DistributedHardware {
DCameraSinkOutputChannelListener(DCStreamType type,std::shared_ptr<DCameraSinkOutput> & output)22 DCameraSinkOutputChannelListener::DCameraSinkOutputChannelListener(
23     DCStreamType type, std::shared_ptr<DCameraSinkOutput>& output) : streamType_(type), output_(output)
24 {
25 }
26 
OnSessionState(int32_t state)27 void DCameraSinkOutputChannelListener::OnSessionState(int32_t state)
28 {
29     std::shared_ptr<DCameraSinkOutput> output = output_.lock();
30     if (output == nullptr) {
31         DHLOGE("DCameraSinkOutputChannelListener::OnSessionState output is null");
32         return;
33     }
34     output->OnSessionState(streamType_, state);
35 }
36 
OnSessionError(int32_t eventType,int32_t eventReason,std::string detail)37 void DCameraSinkOutputChannelListener::OnSessionError(int32_t eventType, int32_t eventReason, std::string detail)
38 {
39     std::shared_ptr<DCameraSinkOutput> output = output_.lock();
40     if (output == nullptr) {
41         DHLOGE("DCameraSinkOutputChannelListener::OnSessionError output is null");
42         return;
43     }
44     output->OnSessionError(streamType_, eventType, eventReason, detail);
45 }
46 
OnDataReceived(std::vector<std::shared_ptr<DataBuffer>> & buffers)47 void DCameraSinkOutputChannelListener::OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers)
48 {
49     std::shared_ptr<DCameraSinkOutput> output = output_.lock();
50     if (output == nullptr) {
51         DHLOGE("DCameraSinkOutputChannelListener::OnReceivedData output is null");
52         return;
53     }
54     output->OnDataReceived(streamType_, buffers);
55 }
56 } // namespace DistributedHardware
57 } // namespace OHOS