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