1 /* 2 * Copyright (C) 2018 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 package android.hardware.camera2.marshal.impl; 17 18 import android.hardware.camera2.marshal.Marshaler; 19 import android.hardware.camera2.marshal.MarshalQueryable; 20 import android.hardware.camera2.params.RecommendedStreamConfiguration; 21 import android.hardware.camera2.utils.TypeReference; 22 23 import static android.hardware.camera2.impl.CameraMetadataNative.*; 24 import static android.hardware.camera2.marshal.MarshalHelpers.*; 25 26 import java.nio.ByteBuffer; 27 28 /** 29 * Marshaler for {@code android.scaler.availableRecommendedStreamConfigurations} custom class 30 * {@link RecommendedStreamConfiguration} 31 * 32 * <p>Data is stored as {@code (width, height, format, input, usecaseBitmap)} tuples (int32).</p> 33 */ 34 public class MarshalQueryableRecommendedStreamConfiguration 35 implements MarshalQueryable<RecommendedStreamConfiguration> { 36 private static final int SIZE = SIZEOF_INT32 * 5; 37 38 private class MarshalerRecommendedStreamConfiguration 39 extends Marshaler<RecommendedStreamConfiguration> { MarshalerRecommendedStreamConfiguration( TypeReference<RecommendedStreamConfiguration> typeReference, int nativeType)40 protected MarshalerRecommendedStreamConfiguration( 41 TypeReference<RecommendedStreamConfiguration> typeReference, int nativeType) { 42 super(MarshalQueryableRecommendedStreamConfiguration.this, typeReference, nativeType); 43 } 44 45 @Override marshal(RecommendedStreamConfiguration value, ByteBuffer buffer)46 public void marshal(RecommendedStreamConfiguration value, ByteBuffer buffer) { 47 buffer.putInt(value.getWidth()); 48 buffer.putInt(value.getHeight()); 49 buffer.putInt(value.getFormat()); 50 buffer.putInt(value.isInput() ? 1 : 0); 51 buffer.putInt(value.getUsecaseBitmap()); 52 } 53 54 @Override unmarshal(ByteBuffer buffer)55 public RecommendedStreamConfiguration unmarshal(ByteBuffer buffer) { 56 int width = buffer.getInt(); 57 int height = buffer.getInt(); 58 int format = buffer.getInt(); 59 boolean input = buffer.getInt() != 0; 60 int usecaseBitmap = buffer.getInt(); 61 62 return new RecommendedStreamConfiguration(format, width, height, input, usecaseBitmap); 63 } 64 65 @Override getNativeSize()66 public int getNativeSize() { 67 return SIZE; 68 } 69 70 } 71 72 @Override createMarshaler( TypeReference<RecommendedStreamConfiguration> managedType, int nativeType)73 public Marshaler<RecommendedStreamConfiguration> createMarshaler( 74 TypeReference<RecommendedStreamConfiguration> managedType, int nativeType) { 75 return new MarshalerRecommendedStreamConfiguration(managedType, nativeType); 76 } 77 78 @Override isTypeMappingSupported(TypeReference<RecommendedStreamConfiguration> managedType, int nativeType)79 public boolean isTypeMappingSupported(TypeReference<RecommendedStreamConfiguration> managedType, 80 int nativeType) { 81 return nativeType == 82 TYPE_INT32 && managedType.getType().equals(RecommendedStreamConfiguration.class); 83 } 84 } 85