CameraSource.h revision fc20aab463f527ab3b0664986f0381a86b375884
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
27namespace android {
28
29class ICamera;
30class IMemory;
31class Camera;
32
33class CameraSource : public MediaSource, public MediaBufferObserver {
34public:
35    static CameraSource *Create();
36    static CameraSource *CreateFromCamera(const sp<Camera> &camera);
37
38    void enableTimeLapseMode(
39            int64_t timeBetweenTimeLapseFrameCaptureUs, int32_t videoFrameRate);
40    void disableTimeLapseMode();
41
42    virtual ~CameraSource();
43
44    virtual status_t start(MetaData *params = NULL);
45    virtual status_t stop();
46
47    virtual sp<MetaData> getFormat();
48
49    virtual status_t read(
50            MediaBuffer **buffer, const ReadOptions *options = NULL);
51
52    virtual void signalBufferReturned(MediaBuffer* buffer);
53
54private:
55    friend class CameraSourceListener;
56
57    sp<Camera> mCamera;
58    sp<MetaData> mMeta;
59
60    Mutex mLock;
61    Condition mFrameAvailableCondition;
62    Condition mFrameCompleteCondition;
63    List<sp<IMemory> > mFramesReceived;
64    List<sp<IMemory> > mFramesBeingEncoded;
65    List<int64_t> mFrameTimes;
66
67    int64_t mStartTimeUs;
68    int64_t mFirstFrameTimeUs;
69    int64_t mLastFrameTimestampUs;
70    int32_t mNumFramesReceived;
71    int32_t mNumFramesEncoded;
72    int32_t mNumFramesDropped;
73    int32_t mNumGlitches;
74    int64_t mGlitchDurationThresholdUs;
75    bool mCollectStats;
76    bool mStarted;
77
78    // Time between capture of two frames during time lapse recording
79    // Negative value indicates that timelapse is disabled.
80    int64_t mTimeBetweenTimeLapseFrameCaptureUs;
81    // Time between two frames in final video (1/frameRate)
82    int64_t mTimeBetweenTimeLapseVideoFramesUs;
83    // Real timestamp of the last encoded time lapse frame
84    int64_t mLastTimeLapseFrameRealTimestampUs;
85
86    CameraSource(const sp<Camera> &camera);
87
88    void dataCallbackTimestamp(
89            int64_t timestampUs, int32_t msgType, const sp<IMemory> &data);
90
91    void releaseQueuedFrames();
92    void releaseOneRecordingFrame(const sp<IMemory>& frame);
93
94    CameraSource(const CameraSource &);
95    CameraSource &operator=(const CameraSource &);
96};
97
98}  // namespace android
99
100#endif  // CAMERA_SOURCE_H_
101