Home | History | Annotate | Download | only in client2
      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_JPEGPROCESSOR_H
     18 #define ANDROID_SERVERS_CAMERA_CAMERA2_JPEGPROCESSOR_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 "camera/CameraMetadata.h"
     28 
     29 namespace android {
     30 
     31 class Camera2Client;
     32 class CameraDeviceBase;
     33 class MemoryHeapBase;
     34 
     35 namespace camera2 {
     36 
     37 class CaptureSequencer;
     38 struct Parameters;
     39 
     40 /***
     41  * Still image capture output image processing
     42  */
     43 class JpegProcessor:
     44             public Thread, public CpuConsumer::FrameAvailableListener,
     45             public camera3::Camera3StreamBufferListener {
     46   public:
     47     JpegProcessor(sp<Camera2Client> client, wp<CaptureSequencer> sequencer);
     48     ~JpegProcessor();
     49 
     50     // CpuConsumer listener implementation
     51     void onFrameAvailable(const BufferItem& item);
     52 
     53     // Camera3StreamBufferListener implementation
     54     void onBufferAcquired(const BufferInfo& bufferInfo) override;
     55     void onBufferReleased(const BufferInfo& bufferInfo) override;
     56 
     57     status_t updateStream(const Parameters &params);
     58     status_t deleteStream();
     59     int getStreamId() const;
     60 
     61     void dump(int fd, const Vector<String16>& args) const;
     62   private:
     63     static const nsecs_t kWaitDuration = 10000000; // 10 ms
     64     wp<CameraDeviceBase> mDevice;
     65     wp<CaptureSequencer> mSequencer;
     66     int mId;
     67 
     68     mutable Mutex mInputMutex;
     69     bool mCaptureDone;
     70     bool mCaptureSuccess;
     71     Condition mCaptureDoneSignal;
     72 
     73     enum {
     74         NO_STREAM = -1
     75     };
     76 
     77     int mCaptureStreamId;
     78     sp<CpuConsumer>    mCaptureConsumer;
     79     sp<Surface>        mCaptureWindow;
     80     sp<MemoryHeapBase> mCaptureHeap;
     81 
     82     virtual bool threadLoop();
     83 
     84     status_t processNewCapture(bool captureSuccess);
     85     size_t findJpegSize(uint8_t* jpegBuffer, size_t maxSize);
     86 
     87 };
     88 
     89 
     90 }; //namespace camera2
     91 }; //namespace android
     92 
     93 #endif
     94