1 /*
2  * Copyright (c) 2021-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 #ifndef OHOS_DCAMERA_CODEC_EVENT_H
17 #define OHOS_DCAMERA_CODEC_EVENT_H
18 
19 #include <vector>
20 
21 #include "data_buffer.h"
22 #include "image_common_type.h"
23 #include "surface.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 enum class VideoCodecAction : int32_t {
28     NO_ACTION = 0,
29     ACTION_ONCE_AGAIN = 1,
30     ACTION_GET_DECODER_OUTPUT_BUFFER = 2,
31 };
32 
33 class CodecPacket {
34 public:
CodecPacket()35     CodecPacket() : videoCodec_(VideoCodecType::NO_CODEC) {}
CodecPacket(VideoCodecType videoCodec,const std::vector<std::shared_ptr<DataBuffer>> & multiDataBuffers)36     CodecPacket(VideoCodecType videoCodec, const std::vector<std::shared_ptr<DataBuffer>>& multiDataBuffers)
37         : videoCodec_(videoCodec), multiDataBuffers_(multiDataBuffers) {}
CodecPacket(const sptr<IConsumerSurface> & surface)38     CodecPacket(const sptr<IConsumerSurface>& surface)
39         : videoCodec_(VideoCodecType::NO_CODEC), surface_(surface) {}
40     ~CodecPacket() = default;
41 
SetVideoCodecType(VideoCodecType videoCodec)42     void SetVideoCodecType(VideoCodecType videoCodec)
43     {
44         videoCodec_ = videoCodec;
45     }
46 
GetVideoCodecType()47     VideoCodecType GetVideoCodecType() const
48     {
49         return videoCodec_;
50     }
51 
SetDataBuffers(std::vector<std::shared_ptr<DataBuffer>> & multiDataBuffers)52     void SetDataBuffers(std::vector<std::shared_ptr<DataBuffer>>& multiDataBuffers)
53     {
54         multiDataBuffers_ = multiDataBuffers;
55     }
56 
GetDataBuffers()57     std::vector<std::shared_ptr<DataBuffer>> GetDataBuffers() const
58     {
59         return multiDataBuffers_;
60     }
61 
SetSurface(sptr<IConsumerSurface> surface)62     void SetSurface(sptr<IConsumerSurface> surface)
63     {
64         surface_ = surface;
65     }
66 
GetSurface()67     sptr<IConsumerSurface> GetSurface() const
68     {
69         return surface_;
70     }
71 
72 private:
73     VideoCodecType videoCodec_;
74     std::vector<std::shared_ptr<DataBuffer>> multiDataBuffers_;
75     sptr<IConsumerSurface> surface_;
76 };
77 
78 class DCameraCodecEvent {
79 public:
DCameraCodecEvent(const std::shared_ptr<CodecPacket> & codecPacket)80     DCameraCodecEvent(const std::shared_ptr<CodecPacket>& codecPacket)
81         : codecPacket_(codecPacket), action_(VideoCodecAction::NO_ACTION) {}
DCameraCodecEvent(const std::shared_ptr<CodecPacket> & codecPacket,VideoCodecAction otherAction)82     DCameraCodecEvent(const std::shared_ptr<CodecPacket>& codecPacket,
83         VideoCodecAction otherAction)
84         : codecPacket_(codecPacket), action_(otherAction) {}
~DCameraCodecEvent()85     ~DCameraCodecEvent() {}
86 
GetCodecPacket()87     std::shared_ptr<CodecPacket> GetCodecPacket() const
88     {
89         return codecPacket_;
90     }
91 
GetAction()92     VideoCodecAction GetAction() const
93     {
94         return action_;
95     }
96 
97 private:
98     std::shared_ptr<CodecPacket> codecPacket_;
99     VideoCodecAction action_;
100 };
101 } // namespace DistributedHardware
102 } // namespace OHOS
103 #endif // OHOS_DCAMERA_CODEC_EVENT_H
104