CameraSource.h revision 30ab66297501757d745b9ae10da61adcd891f497
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 ISurface;
32class Camera;
33
34class CameraSource : public MediaSource {
35public:
36    static CameraSource *Create();
37    static CameraSource *CreateFromICamera(const sp<ICamera> &icamera);
38
39    virtual ~CameraSource();
40
41    void setPreviewSurface(const sp<ISurface> &surface);
42
43    virtual status_t start(MetaData *params = NULL);
44    virtual status_t stop();
45
46    virtual sp<MetaData> getFormat();
47
48    virtual status_t read(
49            MediaBuffer **buffer, const ReadOptions *options = NULL);
50
51private:
52    friend class CameraSourceListener;
53
54    sp<Camera> mCamera;
55    sp<ISurface> mPreviewSurface;
56
57    Mutex mLock;
58    Condition mFrameAvailableCondition;
59    List<sp<IMemory> > mFrames;
60    List<int64_t> mFrameTimes;
61
62    int mWidth, mHeight;
63    int64_t mFirstFrameTimeUs;
64    int32_t mNumFrames;
65    bool mStarted;
66
67    CameraSource(const sp<Camera> &camera);
68
69    void dataCallback(int32_t msgType, const sp<IMemory> &data);
70
71    CameraSource(const CameraSource &);
72    CameraSource &operator=(const CameraSource &);
73};
74
75}  // namespace android
76
77#endif  // CAMERA_SOURCE_H_
78