1 /* 2 * Copyright (c) 2023-2025 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_AV_TRANSPORT_TYPES_H 17 #define OHOS_AV_TRANSPORT_TYPES_H 18 19 #include <string> 20 #include <unistd.h> 21 #include "parcel.h" 22 #include "message_parcel.h" 23 24 namespace OHOS { 25 namespace DistributedHardware { 26 const std::string OWNER_NAME_D_CAMERA = "ohos.dhardware.dcamera"; 27 const std::string OWNER_NAME_D_SCREEN = "ohos.dhardware.dscreen"; 28 const std::string OWNER_NAME_D_MIC = "ohos.dhardware.daudio.dmic"; 29 const std::string OWNER_NAME_D_SPEAKER = "ohos.dhardware.daudio.dspeaker"; 30 const std::string OWNER_NAME_D_VIRMODEM_MIC = "ohos.dhardware.dcall.dmic"; 31 const std::string OWNER_NAME_D_VIRMODEM_SPEAKER = "ohos.dhardware.dcall.dspeaker"; 32 33 const std::string SCENE_TYPE_D_MIC = "dmic_stream"; 34 const std::string SCENE_TYPE_D_SCREEN = "dscreen_stream"; 35 const std::string SCENE_TYPE_D_SPEAKER = "dspeaker_stream"; 36 const std::string SCENE_TYPE_D_CAMERA_STR = "dcamera_stream"; 37 const std::string SCENE_TYPE_D_CAMERA_PIC = "dcamera_picture"; 38 39 const std::string PKG_NAME_DH_FWK = "ohos.dhardware"; 40 const std::string PKG_NAME_D_AUDIO = "ohos.dhardware.daudio"; 41 const std::string PKG_NAME_D_CALL = "ohos.dhardware.dcall"; 42 const std::string PKG_NAME_D_CAMERA = "ohos.dhardware.dcamera"; 43 const std::string PKG_NAME_D_SCREEN = "ohos.dhardware.dscreen"; 44 45 const std::string MIME_VIDEO_RAW = "video/raw"; 46 const std::string MIME_VIDEO_H264 = "video/avc"; 47 const std::string MIME_VIDEO_H265 = "video/hevc"; 48 49 const std::string VIDEO_FORMAT_NV12 = "nv12"; 50 const std::string VIDEO_FORMAT_NV21 = "nv21"; 51 const std::string VIDEO_FORMAT_JEPG = "jpeg"; 52 const std::string VIDEO_FORMAT_YUVI420 = "yuvi420"; 53 const std::string VIDEO_FORMAT_RGBA8888 = "rgba8888"; 54 55 enum struct TransRole : uint32_t { 56 AV_SENDER = 0, 57 AV_RECEIVER = 1, 58 UNKNOWN = 2 59 }; 60 61 enum struct AvSyncFlag : uint32_t { 62 MASTER = 0, 63 SLAVE = 1, 64 UNKNOWN = 2 65 }; 66 67 enum struct TransStrategy : uint32_t { 68 LOW_LATANCY_STRATEGY, 69 LOW_JITTER_STRATEGY 70 }; 71 72 struct ChannelAttribute { 73 TransStrategy strategy; 74 }; 75 76 enum struct BufferDataType : uint32_t { 77 AUDIO = 0, 78 VIDEO_STREAM, 79 PICTURE, 80 UNKNOW, 81 }; 82 83 enum struct StateId : uint32_t { 84 IDLE = 0, 85 INITIALIZED = 1, 86 CH_CREATED = 2, 87 STARTED = 3, 88 PLAYING = 4, 89 STOPPED = 5, 90 BUTT, 91 }; 92 93 enum struct TagSection : uint8_t { 94 REGULAR = 1, 95 D_AUDIO = 2, 96 D_VIDEO = 3, 97 MAX_SECTION = 64 98 }; 99 100 enum struct AVTransTag : uint32_t { 101 INVALID = 0, 102 SECTION_REGULAR_START = static_cast<uint8_t>(TagSection::REGULAR) << 16U, 103 SECTION_D_AUDIO_START = static_cast<uint8_t>(TagSection::D_AUDIO) << 16U, 104 SECTION_D_VIDEO_START = static_cast<uint8_t>(TagSection::D_VIDEO) << 16U, 105 106 /* -------------------- regular tag -------------------- */ 107 FRAME_NUMBER = SECTION_REGULAR_START + 1, 108 BUFFER_DATA_TYPE, 109 PRE_TIMESTAMP, 110 CUR_TIMESTAMP, 111 ENGINE_READY, 112 ENGINE_PAUSE, 113 ENGINE_RESUME, 114 START_AV_SYNC, 115 STOP_AV_SYNC, 116 TIME_SYNC_RESULT, 117 SHARED_MEMORY_FD, 118 119 /* -------------------- d_audio tag -------------------- */ 120 AUDIO_CHANNELS = SECTION_D_AUDIO_START + 1, 121 AUDIO_SAMPLE_RATE, 122 AUDIO_CODEC_TYPE, 123 AUDIO_CHANNEL_MASK, 124 AUDIO_SAMPLE_FORMAT, 125 AUDIO_FRAME_SIZE, 126 AUDIO_STREAM_USAGE, 127 AUDIO_RENDER_FLAGS, 128 AUDIO_CONTENT_TYPE, 129 AUDIO_CHANNEL_LAYOUT, 130 AUDIO_BIT_RATE, 131 132 /* -------------------- d_video tag -------------------- */ 133 VIDEO_WIDTH = SECTION_D_VIDEO_START + 1, 134 VIDEO_HEIGHT, 135 VIDEO_CODEC_TYPE, 136 VIDEO_PIXEL_FORMAT, 137 VIDEO_FRAME_RATE, 138 VIDEO_BIT_RATE, 139 }; 140 141 enum struct EventType : uint32_t { 142 EVENT_CHANNEL_OPENED = 0, 143 EVENT_CHANNEL_OPEN_FAIL = 1, 144 EVENT_CHANNEL_CLOSED = 2, 145 EVENT_START_SUCCESS = 3, 146 EVENT_START_FAIL = 4, 147 EVENT_STOP_SUCCESS = 5, 148 EVENT_STOP_FAIL = 6, 149 EVENT_ENGINE_ERROR = 7, 150 EVENT_REMOTE_ERROR = 8, 151 EVENT_DATA_RECEIVED = 9, 152 EVENT_TIME_SYNC_RESULT = 10, 153 EVENT_ADD_STREAM = 11, 154 EVENT_REMOVE_STREAM = 12, 155 }; 156 157 struct AVTransEvent { 158 EventType type; 159 std::string content; 160 std::string peerDevId; 161 }; 162 163 struct AVTransEventExt : public AVTransEvent, public Parcelable { 164 using AVTransEvent::AVTransEvent; AVTransEventExtAVTransEventExt165 explicit AVTransEventExt() {} 166 virtual ~AVTransEventExt() = default; AVTransEventExtAVTransEventExt167 explicit AVTransEventExt(const AVTransEvent& AVTransEvent) 168 { 169 type = AVTransEvent.type; 170 content = AVTransEvent.content; 171 peerDevId = AVTransEvent.peerDevId; 172 } 173 MarshallingAVTransEventExt174 virtual bool Marshalling(Parcel &parcel) const override 175 { 176 if (!parcel.WriteUint32((uint32_t)type)) { 177 return false; 178 } 179 if (!parcel.WriteString(content)) { 180 return false; 181 } 182 if (!parcel.WriteString(peerDevId)) { 183 return false; 184 } 185 return true; 186 } 187 UnmarshallingAVTransEventExt188 static AVTransEventExt *Unmarshalling(Parcel &parcel) 189 { 190 AVTransEventExt *avTransEvent = new (std::nothrow) AVTransEventExt(); 191 if (avTransEvent == nullptr) { 192 return nullptr; 193 } 194 uint32_t typeValue = parcel.ReadUint32(); 195 std::string contentValue = parcel.ReadString(); 196 std::string peerDevIdValue = parcel.ReadString(); 197 avTransEvent->type = static_cast<EventType>(typeValue); 198 avTransEvent->content = contentValue; 199 avTransEvent->peerDevId = peerDevIdValue; 200 201 return avTransEvent; 202 } 203 }; 204 205 struct AVStreamInfo { 206 std::string sceneType; 207 std::string peerDevId; 208 }; 209 } // namespace DistributedHardware 210 } // namespace OHOS 211 #endif // OHOS_AV_TRANSPORT_TYPES_H