Home | History | Annotate | Download | only in stagefright
      1 /*
      2  * Copyright (C) 2009 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 CAMERA_SOURCE_H_
     18 
     19 #define CAMERA_SOURCE_H_
     20 
     21 #include <media/stagefright/MediaBuffer.h>
     22 #include <media/stagefright/MediaSource.h>
     23 #include <utils/List.h>
     24 #include <utils/RefBase.h>
     25 #include <utils/threads.h>
     26 
     27 namespace android {
     28 
     29 class ICamera;
     30 class IMemory;
     31 class Camera;
     32 
     33 class CameraSource : public MediaSource, public MediaBufferObserver {
     34 public:
     35     static CameraSource *Create();
     36     static CameraSource *CreateFromCamera(const sp<Camera> &camera);
     37 
     38     virtual ~CameraSource();
     39 
     40     virtual status_t start(MetaData *params = NULL);
     41     virtual status_t stop();
     42 
     43     virtual sp<MetaData> getFormat();
     44 
     45     virtual status_t read(
     46             MediaBuffer **buffer, const ReadOptions *options = NULL);
     47 
     48     virtual void signalBufferReturned(MediaBuffer* buffer);
     49 
     50 private:
     51     friend class CameraSourceListener;
     52 
     53     sp<Camera> mCamera;
     54     sp<MetaData> mMeta;
     55 
     56     Mutex mLock;
     57     Condition mFrameAvailableCondition;
     58     Condition mFrameCompleteCondition;
     59     List<sp<IMemory> > mFramesReceived;
     60     List<sp<IMemory> > mFramesBeingEncoded;
     61     List<int64_t> mFrameTimes;
     62 
     63     int64_t mStartTimeUs;
     64     int64_t mFirstFrameTimeUs;
     65     int64_t mLastFrameTimestampUs;
     66     int32_t mNumFramesReceived;
     67     int32_t mNumFramesEncoded;
     68     int32_t mNumFramesDropped;
     69     int32_t mNumGlitches;
     70     int64_t mGlitchDurationThresholdUs;
     71     bool mCollectStats;
     72     bool mStarted;
     73 
     74     CameraSource(const sp<Camera> &camera);
     75 
     76     void dataCallbackTimestamp(
     77             int64_t timestampUs, int32_t msgType, const sp<IMemory> &data);
     78 
     79     void releaseQueuedFrames();
     80     void releaseOneRecordingFrame(const sp<IMemory>& frame);
     81 
     82     CameraSource(const CameraSource &);
     83     CameraSource &operator=(const CameraSource &);
     84 };
     85 
     86 }  // namespace android
     87 
     88 #endif  // CAMERA_SOURCE_H_
     89