• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2008, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #ifndef ANDROID_HARDWARE_FAKECAMERA_H
19 #define ANDROID_HARDWARE_FAKECAMERA_H
20 
21 #include <sys/types.h>
22 #include <stdint.h>
23 
24 namespace android {
25 
26 /*
27  * FakeCamera is used in the CameraHardwareStub to provide a fake video feed
28  * when the system does not have a camera in hardware.
29  * The fake video is a moving black and white checkerboard background with a
30  * bouncing gray square in the foreground.
31  * This class is not thread-safe.
32  *
33  * TODO: Since the major methods provides a raw/uncompressed video feed, rename
34  * this class to RawVideoSource.
35  */
36 
37 class FakeCamera {
38 public:
39     FakeCamera(int width, int height);
40     ~FakeCamera();
41 
42     void setSize(int width, int height);
43     void getNextFrameAsYuv422(uint8_t *buffer);
44     // Write to the fd a string representing the current state.
45     void dump(int fd) const;
46 
47 private:
48     // TODO: remove the uint16_t buffer param everywhere since it is a field of
49     // this class.
50     void getNextFrameAsRgb565(uint16_t *buffer);
51 
52     void drawSquare(uint16_t *buffer, int x, int y, int size, int color, int shadow);
53     void drawCheckerboard(uint16_t *buffer, int size);
54 
55     static const int kRed = 0xf800;
56     static const int kGreen = 0x07c0;
57     static const int kBlue = 0x003e;
58 
59     int         mWidth, mHeight;
60     int         mCounter;
61     int         mCheckX, mCheckY;
62     uint16_t    *mTmpRgb16Buffer;
63 };
64 
65 }; // namespace android
66 
67 #endif // ANDROID_HARDWARE_FAKECAMERA_H
68