Home | History | Annotate | Download | only in impl
      1 /*
      2  * Copyright (C) 2014 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.HighSpeedVideoConfiguration;
     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.control.availableHighSpeedVideoConfigurations} custom class
     30  * {@link HighSpeedVideoConfiguration}
     31  *
     32  * <p>Data is stored as {@code (width, height, fpsMin, fpsMax)} tuples (int32).</p>
     33  */
     34 public class MarshalQueryableHighSpeedVideoConfiguration
     35         implements MarshalQueryable<HighSpeedVideoConfiguration> {
     36     private static final int SIZE = SIZEOF_INT32 * 4;
     37 
     38     private class MarshalerHighSpeedVideoConfiguration
     39             extends Marshaler<HighSpeedVideoConfiguration> {
     40         protected MarshalerHighSpeedVideoConfiguration(
     41                 TypeReference<HighSpeedVideoConfiguration> typeReference,
     42                 int nativeType) {
     43             super(MarshalQueryableHighSpeedVideoConfiguration.this, typeReference, nativeType);
     44         }
     45 
     46         @Override
     47         public void marshal(HighSpeedVideoConfiguration value, ByteBuffer buffer) {
     48             buffer.putInt(value.getWidth());
     49             buffer.putInt(value.getHeight());
     50             buffer.putInt(value.getFpsMin());
     51             buffer.putInt(value.getFpsMax());
     52         }
     53 
     54         @Override
     55         public HighSpeedVideoConfiguration unmarshal(ByteBuffer buffer) {
     56             int width = buffer.getInt();
     57             int height = buffer.getInt();
     58             int fpsMin = buffer.getInt();
     59             int fpsMax = buffer.getInt();
     60 
     61             return new HighSpeedVideoConfiguration(width, height, fpsMin, fpsMax);
     62         }
     63 
     64         @Override
     65         public int getNativeSize() {
     66             return SIZE;
     67         }
     68 
     69     }
     70 
     71     @Override
     72     public Marshaler<HighSpeedVideoConfiguration> createMarshaler(
     73             TypeReference<HighSpeedVideoConfiguration> managedType, int nativeType) {
     74         return new MarshalerHighSpeedVideoConfiguration(managedType, nativeType);
     75     }
     76 
     77     @Override
     78     public boolean isTypeMappingSupported(TypeReference<HighSpeedVideoConfiguration> managedType,
     79             int nativeType) {
     80         return nativeType == TYPE_INT32 &&
     81                 managedType.getType().equals(HighSpeedVideoConfiguration.class);
     82     }
     83 }
     84