|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2023 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package chip.devicecontroller.cluster.structs |
| 18 | + |
| 19 | +import chip.devicecontroller.cluster.* |
| 20 | +import matter.tlv.ContextSpecificTag |
| 21 | +import matter.tlv.Tag |
| 22 | +import matter.tlv.TlvReader |
| 23 | +import matter.tlv.TlvWriter |
| 24 | + |
| 25 | +class WebRTCTransportProviderClusterWebRTCSessionStruct( |
| 26 | + val id: UInt, |
| 27 | + val peerNodeId: ULong, |
| 28 | + val peerFabricIndex: UInt, |
| 29 | + val streamType: UInt, |
| 30 | + val videoStreamID: UInt?, |
| 31 | + val audioStreamID: UInt?, |
| 32 | + val metadataOptions: UInt, |
| 33 | +) { |
| 34 | + override fun toString(): String = buildString { |
| 35 | + append("WebRTCTransportProviderClusterWebRTCSessionStruct {\n") |
| 36 | + append("\tid : $id\n") |
| 37 | + append("\tpeerNodeId : $peerNodeId\n") |
| 38 | + append("\tpeerFabricIndex : $peerFabricIndex\n") |
| 39 | + append("\tstreamType : $streamType\n") |
| 40 | + append("\tvideoStreamID : $videoStreamID\n") |
| 41 | + append("\taudioStreamID : $audioStreamID\n") |
| 42 | + append("\tmetadataOptions : $metadataOptions\n") |
| 43 | + append("}\n") |
| 44 | + } |
| 45 | + |
| 46 | + fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { |
| 47 | + tlvWriter.apply { |
| 48 | + startStructure(tlvTag) |
| 49 | + put(ContextSpecificTag(TAG_ID), id) |
| 50 | + put(ContextSpecificTag(TAG_PEER_NODE_ID), peerNodeId) |
| 51 | + put(ContextSpecificTag(TAG_PEER_FABRIC_INDEX), peerFabricIndex) |
| 52 | + put(ContextSpecificTag(TAG_STREAM_TYPE), streamType) |
| 53 | + if (videoStreamID != null) { |
| 54 | + put(ContextSpecificTag(TAG_VIDEO_STREAM_ID), videoStreamID) |
| 55 | + } else { |
| 56 | + putNull(ContextSpecificTag(TAG_VIDEO_STREAM_ID)) |
| 57 | + } |
| 58 | + if (audioStreamID != null) { |
| 59 | + put(ContextSpecificTag(TAG_AUDIO_STREAM_ID), audioStreamID) |
| 60 | + } else { |
| 61 | + putNull(ContextSpecificTag(TAG_AUDIO_STREAM_ID)) |
| 62 | + } |
| 63 | + put(ContextSpecificTag(TAG_METADATA_OPTIONS), metadataOptions) |
| 64 | + endStructure() |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + companion object { |
| 69 | + private const val TAG_ID = 1 |
| 70 | + private const val TAG_PEER_NODE_ID = 2 |
| 71 | + private const val TAG_PEER_FABRIC_INDEX = 3 |
| 72 | + private const val TAG_STREAM_TYPE = 4 |
| 73 | + private const val TAG_VIDEO_STREAM_ID = 5 |
| 74 | + private const val TAG_AUDIO_STREAM_ID = 6 |
| 75 | + private const val TAG_METADATA_OPTIONS = 7 |
| 76 | + |
| 77 | + fun fromTlv( |
| 78 | + tlvTag: Tag, |
| 79 | + tlvReader: TlvReader, |
| 80 | + ): WebRTCTransportProviderClusterWebRTCSessionStruct { |
| 81 | + tlvReader.enterStructure(tlvTag) |
| 82 | + val id = tlvReader.getUInt(ContextSpecificTag(TAG_ID)) |
| 83 | + val peerNodeId = tlvReader.getULong(ContextSpecificTag(TAG_PEER_NODE_ID)) |
| 84 | + val peerFabricIndex = tlvReader.getUInt(ContextSpecificTag(TAG_PEER_FABRIC_INDEX)) |
| 85 | + val streamType = tlvReader.getUInt(ContextSpecificTag(TAG_STREAM_TYPE)) |
| 86 | + val videoStreamID = |
| 87 | + if (!tlvReader.isNull()) { |
| 88 | + tlvReader.getUInt(ContextSpecificTag(TAG_VIDEO_STREAM_ID)) |
| 89 | + } else { |
| 90 | + tlvReader.getNull(ContextSpecificTag(TAG_VIDEO_STREAM_ID)) |
| 91 | + null |
| 92 | + } |
| 93 | + val audioStreamID = |
| 94 | + if (!tlvReader.isNull()) { |
| 95 | + tlvReader.getUInt(ContextSpecificTag(TAG_AUDIO_STREAM_ID)) |
| 96 | + } else { |
| 97 | + tlvReader.getNull(ContextSpecificTag(TAG_AUDIO_STREAM_ID)) |
| 98 | + null |
| 99 | + } |
| 100 | + val metadataOptions = tlvReader.getUInt(ContextSpecificTag(TAG_METADATA_OPTIONS)) |
| 101 | + |
| 102 | + tlvReader.exitContainer() |
| 103 | + |
| 104 | + return WebRTCTransportProviderClusterWebRTCSessionStruct( |
| 105 | + id, |
| 106 | + peerNodeId, |
| 107 | + peerFabricIndex, |
| 108 | + streamType, |
| 109 | + videoStreamID, |
| 110 | + audioStreamID, |
| 111 | + metadataOptions, |
| 112 | + ) |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments