summaryrefslogtreecommitdiff
path: root/v4l2_vdin.h (plain)
blob: 1d6ce2446abff9b910d2a200dc22d641e782fe5a
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 int displaymode;
57 int dimming_flag;
58};
59enum State{
60 START,
61 PAUSE,
62 STOPING,
63 STOP,
64};
65
66enum FrameType{
67 NATIVE_WINDOW_DATA = 0x1,
68 CALL_BACK_DATA = 0x2,
69};
70
71typedef void (*olStateCB)(int state);
72
73typedef void (*app_data_callback)(void *user, aml_screen_buffer_info_t *buff_info);
74
75#define SCREENSOURCE_GRALLOC_USAGE GRALLOC_USAGE_HW_TEXTURE | \
76 GRALLOC_USAGE_HW_RENDER | \
77 GRALLOC_USAGE_SW_READ_RARELY | \
78 GRALLOC_USAGE_SW_WRITE_NEVER
79/**
80 * set_port_type() parameter description:
81 portType is consisted by 32-bit binary.
82 bit 28 : start tvin service flag, 1 : enable, 0 : disable.
83 bit 24 : vdin device num : 0 or 1, which means use vdin0 or vdin1.
84 bit 15~0 : tvin port type --TVIN_PORT_VIU,TVIN_PORT_HDMI0...
85 (port type define in tvin.h)
86 */
87class vdin_screen_source {
88 public:
89 vdin_screen_source();
90 ~vdin_screen_source();
91 int init(int id);
92 int start();
93 int stop();
94 int pause();
95 int get_format();
96 int set_format(int width = 640, int height = 480, int color_format = V4L2_PIX_FMT_NV21);
97 int set_rotation(int degree);
98 int set_crop(int x, int y, int width, int height);
99 int get_amlvideo2_crop(int *x, int *y, int *width, int *height);
100 int set_amlvideo2_crop(int x, int y, int width, int height);
101 int aquire_buffer(aml_screen_buffer_info_t *buff_info);
102 // int inc_buffer_refcount(int* ptr);
103 int release_buffer(long* ptr);
104 int set_state_callback(olStateCB callback);
105 int set_data_callback(app_data_callback callback, void* user);
106 int set_preview_window(ANativeWindow* window);
107 int set_frame_rate(int frameRate);
108 int get_current_sourcesize(int * width,int * height);
109 int set_screen_mode(int mode);
110 int start_v4l2_device();
111 int stop_v4l2_device();
112 int get_port_type();
113 int set_port_type(unsigned int portType);
114 int set_mode(int display_mode);
115 int microdimming(long* src, unsigned char *dest);
116 private:
117 int init_native_window();
118 int workThread();
119 private:
120 class WorkThread : public Thread {
121 vdin_screen_source* mSource;
122 public:
123 WorkThread(vdin_screen_source* source) :
124 Thread(false), mSource(source) { }
125 virtual void onFirstRef() {
126 run("vdin screen source work thread", PRIORITY_URGENT_DISPLAY);
127 }
128 virtual bool threadLoop() {
129 mSource->workThread();
130 // loop until we need to quit
131 return true;
132 }
133 };
134 private:
135 int mCurrentIndex;
136 KeyedVector<long *, long> mBufs;
137 KeyedVector<long *, long> mTemp_Bufs;
138 int mBufferCount;
139 int mFrameWidth;
140 int mFrameHeight;
141 int mBufferSize;
142 unsigned int flex_ratio;
143 unsigned int flex_original;
144 int mFramecount = 0;
145 int m_FrameHeight = 0;
146 int m_FrameWidth = 0;
147 int m_rest = 0;
148 int m_displaymode;
149 volatile int mState;
150 olStateCB mSetStateCB;
151 int mPixelFormat;
152 int mNativeWindowPixelFormat;
153 sp<ANativeWindow> mANativeWindow;
154 sp<WorkThread> mWorkThread;
155 mutable Mutex mLock;
156 int mCameraHandle;
157 struct VideoInfo *mVideoInfo;
158 int mFrameType;
159 app_data_callback mDataCB;
160 bool mOpen;
161 void *mUser;
162 long * src_temp[4];
163};
164
165}