blob: 7f757ca550d5f7c186065efec52b8be45aeb1f93
1 | #include "CAv.h" |
2 | #define LOG_TAG "CAv" |
3 | #include "../tvutils/tvutils.h" |
4 | #include <stdio.h> |
5 | #include <unistd.h> |
6 | #include <sys/types.h> |
7 | #include <sys/stat.h> |
8 | #include <sys/ioctl.h> |
9 | #include <fcntl.h> |
10 | #include <amstream.h> |
11 | CAv::CAv() |
12 | { |
13 | mpObserver = NULL; |
14 | mTvPlayDevId = 0; |
15 | mCurVideoLayerMuteState = -1; |
16 | mCurDisableVideoColor = -1; |
17 | mFdAmVideo = -1; |
18 | } |
19 | CAv::~CAv() |
20 | { |
21 | |
22 | } |
23 | int CAv::SetVideoWindow(int x, int y, int w, int h) |
24 | { |
25 | return AM_AV_SetVideoWindow (mTvPlayDevId, x, y, w, h ); |
26 | } |
27 | |
28 | int CAv::Open() |
29 | { |
30 | AM_AV_OpenPara_t para_av; |
31 | memset ( ¶_av, 0, sizeof ( AM_AV_OpenPara_t ) ); |
32 | int rt = AM_AV_Open ( mTvPlayDevId, ¶_av ); |
33 | if ( rt != AM_SUCCESS ) { |
34 | LOGD ( "%s, dvbplayer_open fail %d %d\n!" , __FUNCTION__, mTvPlayDevId, rt ); |
35 | return -1; |
36 | } |
37 | |
38 | //open audio channle output |
39 | AM_AOUT_OpenPara_t aout_para; |
40 | memset ( &aout_para, 0, sizeof ( AM_AOUT_OpenPara_t ) ); |
41 | rt = AM_AOUT_Open ( 0, &aout_para ); |
42 | |
43 | if ( AM_SUCCESS != rt ) { |
44 | LOGD ( "%s, BUG: CANN'T OPEN AOUT\n", __FUNCTION__); |
45 | } |
46 | // |
47 | mFdAmVideo = open ( PATH_VIDEO_AMVIDEO, O_RDWR ); |
48 | if ( mFdAmVideo < 0 ) { |
49 | LOGE ( "mFdAmVideo < 0, error(%s)!\n", strerror ( errno ) ); |
50 | return -1; |
51 | } |
52 | /*Register events*/ |
53 | AM_EVT_Subscribe ( mTvPlayDevId, AM_AV_EVT_AV_NO_DATA, av_evt_callback, this ); |
54 | AM_EVT_Subscribe ( mTvPlayDevId, AM_AV_EVT_AV_DATA_RESUME, av_evt_callback, this ); |
55 | AM_EVT_Subscribe ( mTvPlayDevId, AM_AV_EVT_VIDEO_SCAMBLED, av_evt_callback, this ); |
56 | AM_EVT_Subscribe ( mTvPlayDevId, AM_AV_EVT_AUDIO_SCAMBLED, av_evt_callback, this ); |
57 | AM_EVT_Subscribe ( mTvPlayDevId, AM_AV_EVT_VIDEO_NOT_SUPPORT, av_evt_callback, this ); |
58 | |
59 | return rt; |
60 | } |
61 | |
62 | int CAv::Close() |
63 | { |
64 | int iRet; |
65 | iRet = AM_AV_Close ( mTvPlayDevId ); |
66 | iRet = AM_AOUT_Close ( mTvPlayDevId ); |
67 | if (mFdAmVideo > 0) { |
68 | close(mFdAmVideo); |
69 | mFdAmVideo = -1; |
70 | } |
71 | return iRet; |
72 | } |
73 | |
74 | |
75 | int CAv::GetVideoStatus(AM_AV_VideoStatus_t *status) |
76 | { |
77 | return AM_AV_GetVideoStatus(mTvPlayDevId, status); |
78 | } |
79 | |
80 | int CAv::SwitchTSAudio(int apid, AM_AV_AFormat_t afmt) |
81 | { |
82 | return AM_AV_SwitchTSAudio (mTvPlayDevId, ( uint16_t ) apid, ( AM_AV_AFormat_t ) afmt ); |
83 | } |
84 | |
85 | int CAv::ResetAudioDecoder() |
86 | { |
87 | return AM_AV_ResetAudioDecoder ( mTvPlayDevId ); |
88 | } |
89 | |
90 | int CAv::SetTSSource(AM_AV_TSSource_t ts_source) |
91 | { |
92 | return AM_AV_SetTSSource ( mTvPlayDevId, ts_source ); |
93 | } |
94 | |
95 | int CAv::StartTS(uint16_t vpid, uint16_t apid, AM_AV_VFormat_t vfmt, AM_AV_AFormat_t afmt) |
96 | { |
97 | return AM_AV_StartTS ( mTvPlayDevId, vpid, apid, ( AM_AV_VFormat_t ) vfmt, ( AM_AV_AFormat_t ) afmt ); |
98 | } |
99 | |
100 | int CAv::StopTS() |
101 | { |
102 | return AM_AV_StopTS (mTvPlayDevId); |
103 | } |
104 | |
105 | int CAv::AudioGetOutputMode(AM_AOUT_OutputMode_t *mode) |
106 | { |
107 | return AM_AOUT_GetOutputMode ( 0, mode ); |
108 | } |
109 | |
110 | int CAv::AudioSetOutputMode(AM_AOUT_OutputMode_t mode) |
111 | { |
112 | return AM_AOUT_SetOutputMode ( 0, mode ); |
113 | } |
114 | |
115 | int CAv::EnableVideoBlackout() |
116 | { |
117 | return AM_AV_EnableVideoBlackout(mTvPlayDevId); |
118 | } |
119 | |
120 | int CAv::DisableVideoBlackout() |
121 | { |
122 | return AM_AV_DisableVideoBlackout(mTvPlayDevId); |
123 | } |
124 | |
125 | int CAv::DisableVideoWithBlueColor() |
126 | { |
127 | LOGD("DisableVideoWithBlueColor"); |
128 | if (mCurVideoLayerMuteState == 1 && mCurDisableVideoColor == DISABLE_VIDEO_COLOR_BLUE) { |
129 | LOGD("video is disable with blue, return"); |
130 | return 0; |
131 | } |
132 | mCurVideoLayerMuteState = 1; |
133 | mCurDisableVideoColor = DISABLE_VIDEO_COLOR_BLUE; |
134 | SetVideoScreenColor ( 0, 41, 240, 110 ); // Show blue with vdin0, postblending disabled |
135 | return AM_AV_DisableVideo(mTvPlayDevId); |
136 | } |
137 | |
138 | int CAv::DisableVideoWithBlackColor() |
139 | { |
140 | LOGD("DisableVideoWithBlackColor"); |
141 | if (mCurVideoLayerMuteState == 1 && mCurDisableVideoColor == DISABLE_VIDEO_COLOR_BLACK) { |
142 | LOGD("video is disable with black, return"); |
143 | return 0; |
144 | } |
145 | mCurDisableVideoColor = DISABLE_VIDEO_COLOR_BLACK; |
146 | mCurVideoLayerMuteState = 1; |
147 | SetVideoScreenColor ( 0, 16, 128, 128 ); // Show blue with vdin0, postblending disabled |
148 | return AM_AV_DisableVideo(mTvPlayDevId); |
149 | } |
150 | //auto enable, |
151 | int CAv::EnableVideoAuto() |
152 | { |
153 | LOGD("EnableVideo"); |
154 | if (mCurVideoLayerMuteState == 0) { |
155 | LOGD("video is enable, return"); |
156 | return 0; |
157 | } |
158 | mCurVideoLayerMuteState = 0; |
159 | SetVideoScreenColor ( 0, 16, 128, 128 ); // Show black with vdin0, postblending disabled |
160 | return ClearVideoBuffer();//disable video 2 |
161 | } |
162 | |
163 | //just enable video |
164 | int CAv::EnableVideoNow() |
165 | { |
166 | LOGD("EnableVideoNow"); |
167 | if (mCurVideoLayerMuteState == 0) { |
168 | LOGD("video is enable, return"); |
169 | return 0; |
170 | } |
171 | mCurVideoLayerMuteState = 0; |
172 | SetVideoScreenColor ( 3, 16, 128, 128 ); // Show blue with vdin0, postblending disabled |
173 | return AM_AV_EnableVideo(mTvPlayDevId); |
174 | } |
175 | |
176 | //call disable video 2 |
177 | int CAv::ClearVideoBuffer() |
178 | { |
179 | LOGD("ClearVideoBuffer"); |
180 | return AM_AV_ClearVideoBuffer(mTvPlayDevId); |
181 | } |
182 | int CAv::SetVideoScreenColor ( int vdin_blending_mask, int y, int u, int v ) |
183 | { |
184 | FILE *fp = NULL; |
185 | unsigned long value = 0; |
186 | |
187 | value = vdin_blending_mask << 24; |
188 | |
189 | value |= ( unsigned int ) ( y << 16 ) | ( unsigned int ) ( u << 8 ) | ( unsigned int ) ( v ); |
190 | |
191 | fp = fopen ( "/sys/class/video/test_screen", "w" ); |
192 | LOGD ( "~~~fopen~~~##VPP_SetVideoScreenColor##%s : vdin_blending_mask:%d,y:%d,u:%d,v:%d ##" , "/sys/class/video/test_screen", vdin_blending_mask, y, u, v); |
193 | |
194 | |
195 | if ( fp == NULL ) { |
196 | LOGE ( "Open /sys/class/video/test_screen error(%s)!\n", strerror ( errno ) ); |
197 | return -1; |
198 | } |
199 | |
200 | fprintf ( fp, "0x%lx", ( unsigned long ) value ); |
201 | |
202 | fclose ( fp ); |
203 | fp = NULL; |
204 | |
205 | return 0; |
206 | } |
207 | |
208 | int CAv::getVideoDisableValue() |
209 | { |
210 | LOGD("this fun is empty!!!!!!!!"); |
211 | return 0; |
212 | } |
213 | |
214 | int CAv::SetVideoLayerDisable ( int value ) |
215 | { |
216 | FILE *fp = NULL; |
217 | |
218 | fp = fopen ( "/sys/class/video/disable_video", "w" ); |
219 | LOGD ( "~~~fopen~~~##VPP_SetVideoLayerDisable##%s : %d ##" , "/sys/class/video/disable_video", value); |
220 | |
221 | if ( fp == NULL ) { |
222 | LOGE ( "Open /sys/class/video/disable_video error(%s)!\n", strerror ( errno ) ); |
223 | return -1; |
224 | } |
225 | |
226 | fprintf ( fp, "%d", value ); |
227 | |
228 | fclose ( fp ); |
229 | fp = NULL; |
230 | |
231 | return 0; |
232 | } |
233 | |
234 | |
235 | int CAv::setVideoScreenMode ( int value ) |
236 | { |
237 | FILE *fp = fopen ( "/sys/class/video/screen_mode", "w" ); |
238 | LOGD ( "setVideoScreenMode %d ##" , value); |
239 | if ( fp == NULL ) { |
240 | LOGE ( "Open /sys/class/video/screen_mode error(%s)!\n", strerror ( errno ) ); |
241 | return -1; |
242 | } |
243 | fprintf ( fp, "%d", value ); |
244 | fclose ( fp ); |
245 | return 0; |
246 | } |
247 | |
248 | int CAv::setVideoAxis ( int h, int v, int width, int height ) |
249 | { |
250 | FILE *fp = NULL; |
251 | fp = fopen ( "/sys/class/video/axis", "w" ); |
252 | LOGD ( "setVideoAxis##%s : %d %d %d %d ##" , "/sys/class/video/axis", h, v, width, height); |
253 | |
254 | if ( fp == NULL ) { |
255 | LOGE ( "Open /sys/class/video/axis ERROR(%s)!!\n", strerror ( errno ) ); |
256 | return -1; |
257 | } |
258 | fprintf ( fp, "%d %d %d %d", h, v, width, height ); |
259 | fclose ( fp ); |
260 | return 0; |
261 | } |
262 | |
263 | int CAv::getVideoScreenMode() |
264 | { |
265 | int value; |
266 | FILE *fp = fopen ( "/sys/class/video/screen_mode", "r+" ); |
267 | |
268 | if ( fp == NULL ) { |
269 | LOGE ( "Open /sys/class/video/screen_mode error(%s)!\n", strerror ( errno ) ); |
270 | return -1; |
271 | } |
272 | fscanf ( fp, "%d", &value ); |
273 | fclose ( fp ); |
274 | return value; |
275 | } |
276 | |
277 | video_display_resolution_t CAv::getVideoDisplayResolution() |
278 | { |
279 | char attrV[64]; |
280 | memset (attrV, 0x0, 64); |
281 | Tv_Utils_GetFileAttrStr ( "/sys/class/video/device_resolution", 64, attrV ); |
282 | video_display_resolution_t resolution; |
283 | if (strncasecmp(attrV, "1366x768", strlen ("1366x768")) == 0) { |
284 | resolution = VPP_DISPLAY_RESOLUTION_1366X768; |
285 | } else if (strncasecmp(attrV, "3840x2160", strlen ("3840x2160")) == 0) { |
286 | resolution = VPP_DISPLAY_RESOLUTION_3840X2160; |
287 | } else if (strncasecmp(attrV, "1920x1080", strlen ("1920x1080")) == 0) { |
288 | resolution = VPP_DISPLAY_RESOLUTION_1920X1080; |
289 | } else { |
290 | LOGW("video display resolution is = (%s) not define , default it", attrV); |
291 | resolution = VPP_DISPLAY_RESOLUTION_1920X1080; |
292 | } |
293 | |
294 | return resolution; |
295 | } |
296 | |
297 | void CAv::av_evt_callback ( int dev_no, int event_type, void *param, void *user_data ) |
298 | { |
299 | CAv *pAv = ( CAv * ) user_data; |
300 | if (NULL == pAv ) { |
301 | LOGD ( "%s, ERROR : av_evt_callback NULL == pTv\n", __FUNCTION__ ); |
302 | return ; |
303 | } |
304 | if ( pAv->mpObserver == NULL ) { |
305 | LOGD ( "%s, ERROR : mpObserver NULL == mpObserver\n", __FUNCTION__ ); |
306 | return; |
307 | } |
308 | switch ( event_type ) { |
309 | case AM_AV_EVT_AV_NO_DATA: |
310 | pAv->mCurAvEvent.type = AVEvent::EVENT_AV_STOP; |
311 | pAv->mCurAvEvent.param = ( int )param; |
312 | pAv->mpObserver->onEvent(pAv->mCurAvEvent); |
313 | break; |
314 | case AM_AV_EVT_AV_DATA_RESUME: |
315 | pAv->mCurAvEvent.type = AVEvent::EVENT_AV_RESUEM; |
316 | pAv->mCurAvEvent.param = ( int )param; |
317 | pAv->mpObserver->onEvent(pAv->mCurAvEvent); |
318 | break; |
319 | case AM_AV_EVT_VIDEO_SCAMBLED: |
320 | case AM_AV_EVT_AUDIO_SCAMBLED: |
321 | pAv->mCurAvEvent.type = AVEvent::EVENT_AV_SCAMBLED; |
322 | pAv->mCurAvEvent.param = ( int )param; |
323 | pAv->mpObserver->onEvent(pAv->mCurAvEvent); |
324 | break; |
325 | case AM_AV_EVT_VIDEO_NOT_SUPPORT: { |
326 | pAv->mCurAvEvent.type = AVEvent::EVENT_AV_UNSUPPORT; |
327 | pAv->mCurAvEvent.param = ( int )param; |
328 | pAv->mpObserver->onEvent(pAv->mCurAvEvent); |
329 | break; |
330 | } |
331 | default: |
332 | break; |
333 | } |
334 | LOGD ( "%s, av_evt_callback : dev_no %d type %d param = %d\n", __FUNCTION__, dev_no, pAv->mCurAvEvent.type , (int)param); |
335 | } |
336 | |
337 | int CAv::set3DMode(VIDEO_3D_MODE_T mode, int LR_switch, int mode_3D_TO_2D) |
338 | { |
339 | unsigned int cmd = MODE_3D_DISABLE; |
340 | switch (mode) { |
341 | case VIDEO_3D_MODE_DISABLE: |
342 | cmd = MODE_3D_DISABLE; |
343 | break; |
344 | case VIDEO_3D_MODE_AUTO: |
345 | cmd = MODE_3D_ENABLE | MODE_3D_AUTO; |
346 | break; |
347 | case VIDEO_3D_MODE_LR: |
348 | cmd = MODE_3D_ENABLE | MODE_3D_LR; |
349 | break; |
350 | case VIDEO_3D_MODE_TB: |
351 | cmd = MODE_3D_ENABLE | MODE_3D_TB; |
352 | break; |
353 | case VIDEO_3D_MODE_LA: |
354 | cmd = MODE_3D_ENABLE | MODE_3D_LA; |
355 | break; |
356 | case VIDEO_3D_MODE_FA: |
357 | cmd = MODE_3D_ENABLE | MODE_3D_FA; |
358 | break; |
359 | default: |
360 | cmd = MODE_3D_DISABLE; |
361 | break; |
362 | } |
363 | |
364 | if (LR_switch == 1) { |
365 | cmd = cmd | MODE_3D_LR_SWITCH; |
366 | } |
367 | |
368 | if (mode_3D_TO_2D == 1) { |
369 | cmd = cmd | MODE_3D_TO_2D_L; |
370 | } |
371 | |
372 | if (mode_3D_TO_2D == 2) { |
373 | cmd = cmd | MODE_3D_TO_2D_R; |
374 | } |
375 | LOGD("set 3d mode fd = %d cmd = 0x%x", mFdAmVideo, cmd); |
376 | int ret = ioctl(mFdAmVideo, AMSTREAM_IOC_SET_3D_TYPE , cmd); |
377 | if (ret < 0) { |
378 | LOGE("set3DMode error ( %s )", strerror ( errno )); |
379 | } |
380 | return 0; |
381 | } |
382 |