1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.car.evs; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 import android.car.Car; 24 import android.car.annotation.AddedInOrBefore; 25 import android.car.annotation.RequiredFeature; 26 import android.hardware.HardwareBuffer; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 30 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 31 32 import java.util.Objects; 33 34 /** 35 * Wraps around {@link android.hardware.HardwareBuffer} to embed additional metadata of the buffer 36 * from the Extended View System service. 37 * 38 * @hide 39 */ 40 @SystemApi 41 @RequiredFeature(Car.CAR_EVS_SERVICE) 42 public final class CarEvsBufferDescriptor implements Parcelable { 43 @AddedInOrBefore(majorVersion = 33) 44 public static final @NonNull Parcelable.Creator<CarEvsBufferDescriptor> CREATOR = 45 new Parcelable.Creator<CarEvsBufferDescriptor>() { 46 @NonNull 47 @Override 48 public CarEvsBufferDescriptor createFromParcel(final Parcel in) { 49 return new CarEvsBufferDescriptor(in); 50 } 51 52 @NonNull 53 @Override 54 public CarEvsBufferDescriptor[] newArray(final int size) { 55 return new CarEvsBufferDescriptor[size]; 56 } 57 }; 58 59 private final int mId; 60 61 @NonNull 62 private final HardwareBuffer mHardwareBuffer; 63 64 /** 65 * Creates a {@link CarEvsBufferDescriptor} given an unique identifier and 66 * {@link android.hardware.HardwareBuffer}. 67 * 68 * @param id A 32-bit integer to uniquely identify associated hardware buffer. 69 * @param buffer Hardware buffer that contains the imagery data from EVS service. 70 */ CarEvsBufferDescriptor(int id, @NonNull final HardwareBuffer buffer)71 public CarEvsBufferDescriptor(int id, @NonNull final HardwareBuffer buffer) { 72 Objects.requireNonNull(buffer, "HardwardBuffer cannot be null."); 73 74 mId = id; 75 mHardwareBuffer = buffer; 76 } 77 78 /** Parcelable methods */ CarEvsBufferDescriptor(final Parcel in)79 private CarEvsBufferDescriptor(final Parcel in) { 80 mId = in.readInt(); 81 mHardwareBuffer = Objects.requireNonNull(HardwareBuffer.CREATOR.createFromParcel(in)); 82 } 83 84 @Override 85 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 86 @AddedInOrBefore(majorVersion = 33) describeContents()87 public int describeContents() { 88 return 0; 89 } 90 91 @Override 92 @AddedInOrBefore(majorVersion = 33) writeToParcel(@onNull final Parcel dest, final int flags)93 public void writeToParcel(@NonNull final Parcel dest, final int flags) { 94 dest.writeInt(mId); 95 mHardwareBuffer.writeToParcel(dest, flags); 96 } 97 98 @Override 99 @AddedInOrBefore(majorVersion = 33) toString()100 public String toString() { 101 return "CarEvsBufferDescriptor: id = " + mId + ", buffer = " + mHardwareBuffer; 102 } 103 104 /** 105 * Returns an unique identifier of the hardware buffer described by this object. 106 * 107 * @return A 32-bit signed integer unique buffer identifier. 108 */ 109 @AddedInOrBefore(majorVersion = 33) getId()110 public int getId() { 111 return mId; 112 } 113 114 /** 115 * Returns a reference to {@link android.hardware.HardwareBuffer} registered 116 * to this descriptor. 117 * 118 * @return the registered {@link android.hardware.HardwareBuffer}. 119 */ 120 @NonNull 121 @AddedInOrBefore(majorVersion = 33) getHardwareBuffer()122 public HardwareBuffer getHardwareBuffer() { 123 return mHardwareBuffer; 124 } 125 } 126