CameraSource.h revision 653252be963c07c99109d20f942d1f30c52a9360
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    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
50private:
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 mFirstFrameTimeUs;
64    int64_t mLastFrameTimestampUs;
65    int32_t mNumFramesReceived;
66    int32_t mNumFramesEncoded;
67    int32_t mNumFramesDropped;
68    bool mStarted;
69
70    CameraSource(const sp<Camera> &camera);
71
72    void dataCallbackTimestamp(
73            int64_t timestampUs, int32_t msgType, const sp<IMemory> &data);
74
75    void releaseQueuedFrames();
76
77    CameraSource(const CameraSource &);
78    CameraSource &operator=(const CameraSource &);
79};
80
81}  // namespace android
82
83#endif  // CAMERA_SOURCE_H_
84