1 /* 2 * Copyright (C) 2012 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 #ifndef ANDROID_SERVERS_CAMERA_CAMERA2_CALLBACKPROCESSOR_H 18 #define ANDROID_SERVERS_CAMERA_CAMERA2_CALLBACKPROCESSOR_H 19 20 #include <utils/Thread.h> 21 #include <utils/String16.h> 22 #include <utils/Vector.h> 23 #include <utils/Mutex.h> 24 #include <utils/Condition.h> 25 #include <gui/CpuConsumer.h> 26 27 #include "api1/client2/Camera2Heap.h" 28 29 namespace android { 30 31 class Camera2Client; 32 class CameraDeviceBase; 33 34 namespace camera2 { 35 36 struct Parameters; 37 38 /*** 39 * Still image capture output image processing 40 */ 41 class CallbackProcessor: 42 public Thread, public CpuConsumer::FrameAvailableListener { 43 public: 44 CallbackProcessor(sp<Camera2Client> client); 45 ~CallbackProcessor(); 46 47 void onFrameAvailable(const BufferItem& item); 48 49 // Set to NULL to disable the direct-to-app callback window 50 status_t setCallbackWindow(sp<Surface> callbackWindow); 51 status_t updateStream(const Parameters ¶ms); 52 status_t deleteStream(); 53 int getStreamId() const; 54 55 void dump(int fd, const Vector<String16>& args) const; 56 private: 57 static const nsecs_t kWaitDuration = 10000000; // 10 ms 58 wp<Camera2Client> mClient; 59 wp<CameraDeviceBase> mDevice; 60 int mId; 61 62 mutable Mutex mInputMutex; 63 bool mCallbackAvailable; 64 Condition mCallbackAvailableSignal; 65 66 enum { 67 NO_STREAM = -1 68 }; 69 70 // True if mCallbackWindow is a remote consumer, false if just the local 71 // mCallbackConsumer 72 bool mCallbackToApp; 73 int mCallbackStreamId; 74 static const size_t kCallbackHeapCount = 6; 75 sp<CpuConsumer> mCallbackConsumer; 76 sp<Surface> mCallbackWindow; 77 sp<Camera2Heap> mCallbackHeap; 78 size_t mCallbackHeapHead, mCallbackHeapFree; 79 80 virtual bool threadLoop(); 81 82 status_t processNewCallback(sp<Camera2Client> &client); 83 // Used when shutting down 84 status_t discardNewCallback(); 85 86 // Convert from flexible YUV to NV21 or YV12 87 status_t convertFromFlexibleYuv(int32_t previewFormat, 88 uint8_t *dst, 89 const CpuConsumer::LockedBuffer &src, 90 uint32_t dstYStride, 91 uint32_t dstCStride) const; 92 }; 93 94 95 }; //namespace camera2 96 }; //namespace android 97 98 #endif 99