summaryrefslogtreecommitdiff
path: root/v4l2_vdin.h (plain)
blob: a67e244b1b8b94e27c85bfd2af5c92a045ab7a19
1/*
2 * Copyright (C) 2013 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#include <signal.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <fcntl.h>
21#include <unistd.h>
22#include <errno.h>
23#include <sys/ioctl.h>
24#include <sys/mman.h>
25#include <sys/select.h>
26#include <linux/videodev2.h>
27#include <sys/time.h>
28
29#include <utils/KeyedVector.h>
30#include <cutils/properties.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <utils/threads.h>
34#include <android/native_window.h>
35#include <gralloc_priv.h>
36
37#include <hardware/aml_screen.h>
38
39namespace android {
40
41#define NB_BUFFER 6
42
43struct VideoInfo {
44 struct v4l2_capability cap;
45 struct v4l2_format format;
46 struct v4l2_buffer buf;
47 struct v4l2_requestbuffers rb;
48 long *mem[NB_BUFFER];
49 unsigned canvas[NB_BUFFER];
50 unsigned refcount[NB_BUFFER];
51 bool isStreaming;
52 int width;
53 int height;
54 int formatIn;
55 int framesizeIn;
56};
57enum State{
58 START,
59 PAUSE,
60 STOPING,
61 STOP,
62};
63
64enum FrameType{
65 NATIVE_WINDOW_DATA = 0x1,
66 CALL_BACK_DATA = 0x2,
67};
68
69typedef void (*olStateCB)(int state);
70
71typedef void (*app_data_callback)(void *user, aml_screen_buffer_info_t *buff_info);
72
73#define SCREENSOURCE_GRALLOC_USAGE GRALLOC_USAGE_HW_TEXTURE | \
74 GRALLOC_USAGE_HW_RENDER | \
75 GRALLOC_USAGE_SW_READ_RARELY | \
76 GRALLOC_USAGE_SW_WRITE_NEVER
77
78class vdin_screen_source {
79 public:
80 vdin_screen_source();
81 ~vdin_screen_source();
82 int init(int id);
83 int start();
84 int stop();
85 int pause();
86 int get_format();
87 int set_format(int width = 640, int height = 480, int color_format = V4L2_PIX_FMT_NV21);
88 int set_rotation(int degree);
89 int set_crop(int x, int y, int width, int height);
90 int get_amlvideo2_crop(int *x, int *y, int *width, int *height);
91 int set_amlvideo2_crop(int x, int y, int width, int height);
92 int aquire_buffer(aml_screen_buffer_info_t *buff_info);
93 // int inc_buffer_refcount(int* ptr);
94 int release_buffer(long* ptr);
95 int set_state_callback(olStateCB callback);
96 int set_data_callback(app_data_callback callback, void* user);
97 int set_preview_window(ANativeWindow* window);
98 int set_frame_rate(int frameRate);
99 int set_source_type(int sourceType);
100 int get_source_type();
101 int get_current_sourcesize(int * width,int * height);
102 int set_screen_mode(int mode);
103 int start_v4l2_device();
104 int stop_v4l2_device();
105 int set_port_type(int sourceType);
106 private:
107 int init_native_window();
108 int workThread();
109 private:
110 class WorkThread : public Thread {
111 vdin_screen_source* mSource;
112 public:
113 WorkThread(vdin_screen_source* source) :
114 Thread(false), mSource(source) { }
115 virtual void onFirstRef() {
116 run("vdin screen source work thread", PRIORITY_URGENT_DISPLAY);
117 }
118 virtual bool threadLoop() {
119 mSource->workThread();
120 // loop until we need to quit
121 return true;
122 }
123 };
124 private:
125 int mCurrentIndex;
126 KeyedVector<long *, long> mBufs;
127 KeyedVector<long *, long> mTemp_Bufs;
128 int mBufferCount;
129 int mFrameWidth;
130 int mFrameHeight;
131 int mBufferSize;
132 volatile int mState;
133 olStateCB mSetStateCB;
134 int mPixelFormat;
135 int mNativeWindowPixelFormat;
136 sp<ANativeWindow> mANativeWindow;
137 sp<WorkThread> mWorkThread;
138 mutable Mutex mLock;
139 int mCameraHandle;
140 struct VideoInfo *mVideoInfo;
141 int mFrameType;
142 app_data_callback mDataCB;
143 bool mOpen;
144 void *mUser;
145 long * src_temp[4];
146};
147
148}
149