ImageStreamImpl.java revision a9f8690dec58c14a453bf3628d672d58b0132a40
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 17package com.android.camera.one.v2.sharedimagereader; 18 19import android.view.Surface; 20 21import com.android.camera.async.BufferQueue; 22import com.android.camera.async.BufferQueueController; 23import com.android.camera.async.ForwardingBufferQueue; 24import com.android.camera.async.Lifetime; 25import com.android.camera.one.v2.camera2proxy.ImageProxy; 26import com.android.camera.one.v2.core.ResourceAcquisitionFailedException; 27import com.android.camera.one.v2.sharedimagereader.imagedistributor.ImageDistributor; 28import com.android.camera.one.v2.sharedimagereader.imagedistributor.ImageStream; 29 30/** 31 * An ImageQueueCaptureStream which registers itself with the ImageDistributor 32 * when bound to begin receiving images. 33 */ 34class ImageStreamImpl extends ForwardingBufferQueue<ImageProxy> implements 35 ImageStream { 36 private final ImageDistributor mImageDistributor; 37 private final BufferQueueController<ImageProxy> mImageStreamController; 38 private final Surface mSurface; 39 private final Lifetime mLifetime; 40 41 public ImageStreamImpl(BufferQueue<ImageProxy> imageStream, 42 BufferQueueController<ImageProxy> imageStreamController, 43 ImageDistributor imageDistributor, Surface surface) { 44 super(imageStream); 45 mSurface = surface; 46 mImageDistributor = imageDistributor; 47 mImageStreamController = imageStreamController; 48 mLifetime = new Lifetime(); 49 mLifetime.add(imageStream); 50 mLifetime.add(mImageStreamController); 51 } 52 53 @Override 54 public Surface bind(BufferQueue<Long> timestamps) throws InterruptedException, 55 ResourceAcquisitionFailedException { 56 mLifetime.add(timestamps); 57 mImageDistributor.addRoute(timestamps, mImageStreamController); 58 return mSurface; 59 } 60 61 @Override 62 public void close() { 63 mLifetime.close(); 64 } 65} 66