Home | History | Annotate | Download | only in commands
      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 
     17 package com.android.camera.one.v2.commands;
     18 
     19 import android.hardware.camera2.CameraAccessException;
     20 
     21 import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException;
     22 import com.android.camera.one.v2.core.FrameServer;
     23 import com.android.camera.one.v2.core.RequestBuilder;
     24 import com.android.camera.one.v2.core.ResourceAcquisitionFailedException;
     25 
     26 import java.util.Arrays;
     27 
     28 /**
     29  * Sends repeating preview requests to a {@link FrameServer}.
     30  */
     31 public class PreviewCommand implements CameraCommand {
     32     private final FrameServer mFrameServer;
     33     private final RequestBuilder.Factory mBuilderFactory;
     34     private final int mRequestType;
     35 
     36     /**
     37      * Constructs a Preview. Note that it is the responsibility of the
     38      * {@link RequestBuilder.Factory} to attach the relevant
     39      * {@link com.android.camera.one.v2.core.CaptureStream}s, such as the
     40      * viewfinder surface.
     41      */
     42     public PreviewCommand(FrameServer frameServer, RequestBuilder.Factory builder,
     43             int requestType) {
     44         mFrameServer = frameServer;
     45         mBuilderFactory = builder;
     46         mRequestType = requestType;
     47     }
     48 
     49     public void run() throws InterruptedException, CameraAccessException,
     50             CameraCaptureSessionClosedException, ResourceAcquisitionFailedException {
     51         try (FrameServer.Session session = mFrameServer.createExclusiveSession()) {
     52             RequestBuilder photoRequest = mBuilderFactory.create(mRequestType);
     53             session.submitRequest(Arrays.asList(photoRequest.build()),
     54                     FrameServer.RequestType.REPEATING);
     55         }
     56     }
     57 }
     58