blob: 9756e9d17530efa57308fd21385cc37a7c85d2dd [file] [log] [blame]
Chih-Wei Huang0d92eda2012-02-07 16:55:49 +08001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 */
8
9#ifndef _V4L2CAMERA_H
10#define _V4L2CAMERA_H
11
12#define NB_BUFFER 4
13
14#include <binder/MemoryBase.h>
15#include <binder/MemoryHeapBase.h>
16#include <utils/SortedVector.h>
17#include "uvc_compat.h"
18#include "SurfaceDesc.h"
19
20namespace android {
21
22struct vdIn {
23 struct v4l2_capability cap;
24 struct v4l2_format format; // Capture format being used
25 struct v4l2_buffer buf;
26 struct v4l2_requestbuffers rb;
27 struct v4l2_streamparm params; // v4l2 stream parameters struct
28 struct v4l2_jpegcompression jpegcomp; // v4l2 jpeg compression settings
29
30 void *mem[NB_BUFFER];
31 bool isStreaming;
32
33 void* tmpBuffer;
34
35 int outWidth; // Requested Output width
36 int outHeight; // Requested Output height
37 int outFrameSize; // The expected output framesize (in YUYV)
38 int capBytesPerPixel; // Capture bytes per pixel
39 int capCropOffset; // The offset in bytes to add to the captured buffer to get to the first pixel
40
41};
42
43class V4L2Camera {
44
45public:
46 V4L2Camera();
47 ~V4L2Camera();
48
49 int Open (const char *device);
50 void Close ();
51
52 int Init (int width, int height, int fps);
53 void Uninit ();
54
55 int StartStreaming ();
56 int StopStreaming ();
57
58 void GrabRawFrame (void *frameBuffer,int maxSize);
59
60 void getSize(int& width, int& height) const;
61 int getFps() const;
62
63 SortedVector<SurfaceSize> getAvailableSizes() const;
64 SortedVector<int> getAvailableFps() const;
65 const SurfaceDesc& getBestPreviewFmt() const;
66 const SurfaceDesc& getBestPictureFmt() const;
67
68private:
69 bool EnumFrameIntervals(int pixfmt, int width, int height);
70 bool EnumFrameSizes(int pixfmt);
71 bool EnumFrameFormats();
72 int saveYUYVtoJPEG(uint8_t* src, uint8_t* dst, int maxsize, int width, int height, int quality);
73
74private:
75 struct vdIn *videoIn;
76 int fd;
77
78 int nQueued;
79 int nDequeued;
80
81 SortedVector<SurfaceDesc> m_AllFmts; // Available video modes
82 SurfaceDesc m_BestPreviewFmt; // Best preview mode. maximum fps with biggest frame
83 SurfaceDesc m_BestPictureFmt; // Best picture format. maximum size
84
85};
86
87}; // namespace android
88
89#endif