CameraSource.h revision 20111aa043c5f404472bc63b90bc5aad906b1101
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 ICameraClient;
31class IMemory;
32
33class CameraSource : public MediaSource,
34                     public MediaBufferObserver {
35public:
36    static CameraSource *Create();
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 notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2);
49    virtual void dataCallback(int32_t msgType, const sp<IMemory>& data);
50
51    virtual void signalBufferReturned(MediaBuffer *buffer);
52
53private:
54    CameraSource(const sp<ICamera> &camera, const sp<ICameraClient> &client);
55
56    sp<ICamera> mCamera;
57    sp<ICameraClient> mCameraClient;
58
59    Mutex mLock;
60    Condition mFrameAvailableCondition;
61    List<sp<IMemory> > mFrames;
62
63    int mNumFrames;
64    bool mStarted;
65
66    CameraSource(const CameraSource &);
67    CameraSource &operator=(const CameraSource &);
68};
69
70}  // namespace android
71
72#endif  // CAMERA_SOURCE_H_
73