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.core; 18 19 import android.os.Handler; 20 21 import com.android.camera.async.HandlerFactory; 22 import com.android.camera.async.Lifetime; 23 import com.android.camera.async.Observable; 24 import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionProxy; 25 26 public class FrameServerFactory { 27 private FrameServer mEphemeralFrameServer; 28 private FrameServer mFrameServer; 29 private Observable<Boolean> mReadyState; 30 FrameServerFactory(Lifetime lifetime, CameraCaptureSessionProxy cameraCaptureSession, HandlerFactory handlerFactory)31 public FrameServerFactory(Lifetime lifetime, CameraCaptureSessionProxy cameraCaptureSession, 32 HandlerFactory handlerFactory) { 33 // The camera handler will be created with a very very high thread 34 // priority because missing any input event potentially stalls the 35 // camera preview and HAL. 36 Handler cameraHandler = handlerFactory.create(lifetime, "CameraMetadataHandler", 37 Thread.MAX_PRIORITY); 38 39 // TODO Maybe enable closing the FrameServer along with the lifetime? 40 // It would allow clean reuse of the cameraCaptureSession with 41 // non-frameserver interaction. 42 mEphemeralFrameServer = new FrameServerImpl(new TagDispatchCaptureSession 43 (cameraCaptureSession, cameraHandler)); 44 45 ObservableFrameServer ofs = new ObservableFrameServer(mEphemeralFrameServer); 46 mFrameServer = ofs; 47 mReadyState = ofs; 48 } 49 50 /** 51 * @return The {@link FrameServer} to use for interactions with the camera 52 * device which should affect the ready-state. 53 */ provideFrameServer()54 public FrameServer provideFrameServer() { 55 return mFrameServer; 56 } 57 58 /** 59 * @return The {@link FrameServer} to use for interactions with the camera 60 * device which should not affect the ready-state (e.g. trivial 61 * interactions such as restarting the preview as well as 62 * interactions which should not block the ready-state, such as 63 * performing a tap-to-focus routine). 64 */ provideEphemeralFrameServer()65 public FrameServer provideEphemeralFrameServer() { 66 return mEphemeralFrameServer; 67 } 68 69 /** 70 * @return A hint as to whether or not a {@link FrameServer} session can be 71 * acquired immediately. 72 */ provideReadyState()73 public Observable<Boolean> provideReadyState() { 74 return mReadyState; 75 } 76 } 77