blob: 57e2234418d99d01a56e977f0c0bc379a125eca0
1 | |
2 | #include <stdlib.h> |
3 | #include <fcntl.h> |
4 | #include <strings.h> |
5 | #include <sys/ioctl.h> |
6 | #include <asm/types.h> |
7 | #include <fcntl.h> |
8 | #include <unistd.h> |
9 | #include <errno.h> |
10 | #include <malloc.h> |
11 | #include <sys/stat.h> |
12 | #include <sys/types.h> |
13 | #include <time.h> |
14 | #include <sys/mman.h> |
15 | #include <stdio.h> |
16 | #include <stdlib.h> |
17 | #include <string.h> |
18 | #include <assert.h> |
19 | #include <linux/videodev2.h> |
20 | #include <dirent.h> |
21 | |
22 | #include <binder/MemoryHeapBase.h> |
23 | #include <binder/MemoryBase.h> |
24 | |
25 | //#include <media/stagefright/MediaSource.h> |
26 | //#include <media/stagefright/MediaBuffer.h> |
27 | //#include <OMX_IVCommon.h> |
28 | //#include <media/stagefright/MetaData.h> |
29 | //#include <media/stagefright/ScreenCatch.h> |
30 | using namespace android; |
31 | |
32 | |
33 | #include "CTvScreenCapture.h" |
34 | |
35 | #define CLEAR(x) memset (&(x), 0, sizeof (x)) |
36 | |
37 | int CTvScreenCapture::xioctl(int fd, int request, void *arg) |
38 | { |
39 | /* |
40 | int r = 0; |
41 | do { |
42 | r = ioctl(fd, request, arg); |
43 | } while (-1 == r && EINTR == errno); |
44 | |
45 | return r;*/ |
46 | |
47 | //for warning |
48 | fd = fd; |
49 | request = request; |
50 | arg = arg; |
51 | return 0; |
52 | } |
53 | |
54 | int CTvScreenCapture::OpenCamera(struct camera *pCameraDev) |
55 | { |
56 | /* |
57 | int iOutRet = 0, iRet; |
58 | struct stat st; |
59 | |
60 | do { |
61 | if (-1 == stat(pCameraDev->device_name, &st)) { |
62 | LOGD( "Cannot identify '%s'\n", pCameraDev->device_name); |
63 | iOutRet = FAILED; |
64 | break; |
65 | } |
66 | |
67 | if (!S_ISCHR(st.st_mode)) { |
68 | LOGD("%s is no device\n", pCameraDev->device_name); |
69 | iOutRet = FAILED; |
70 | break; |
71 | } |
72 | |
73 | pCameraDev->fd = open(pCameraDev->device_name, O_RDWR | O_NONBLOCK, 0); // O_NONBLOCK |
74 | if (SUCCEED > pCameraDev->fd) { |
75 | LOGD("Cannot open '%s'\n", pCameraDev->device_name); |
76 | iOutRet = FAILED; |
77 | break; |
78 | } |
79 | } while (FALSE); |
80 | |
81 | return iOutRet;*/ |
82 | |
83 | //for warning |
84 | pCameraDev = pCameraDev; |
85 | return 0; |
86 | } |
87 | |
88 | |
89 | int CTvScreenCapture::InitVCap(sp<IMemory> Mem) |
90 | { |
91 | /* |
92 | int iOutRet = FAILED; |
93 | |
94 | do { |
95 | m_pMem = Mem; |
96 | m_pData = (char *)m_pMem->pointer(); |
97 | LOGD("VVVVVVVVVVVVVVVVVVVVVVVVVVVVV %p\n", m_pData); |
98 | //default |
99 | } while (FALSE); |
100 | |
101 | return iOutRet;*/ |
102 | |
103 | //for warning |
104 | Mem = Mem; |
105 | return 0; |
106 | } |
107 | |
108 | int CTvScreenCapture::InitMmap(struct camera *cam) |
109 | { |
110 | /* |
111 | int iOutRet = SUCCEED, iRet; |
112 | struct v4l2_requestbuffers req; |
113 | |
114 | do { |
115 | CLEAR(req); |
116 | |
117 | req.count = 4; |
118 | req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
119 | req.memory = V4L2_MEMORY_MMAP; |
120 | |
121 | iRet = xioctl(cam->fd, VIDIOC_REQBUFS, &req); |
122 | if (FAILED == iRet) { |
123 | if (EINVAL == errno) { |
124 | LOGD("VIDIOC_REQBUFS %s does not support memory mapping\n", cam->device_name); |
125 | } |
126 | iOutRet = iRet; |
127 | break; |
128 | } |
129 | |
130 | if (req.count < 2) { |
131 | LOGD("Insufficient buffer memory on %s\n", cam->device_name); |
132 | iOutRet = FAILED; |
133 | break; |
134 | } |
135 | |
136 | cam->buffers = (struct buffer *)calloc(req.count, sizeof(*(cam->buffers))); |
137 | if (!cam->buffers) { |
138 | LOGD("Out of memory\n"); |
139 | iOutRet = FAILED; |
140 | break; |
141 | } |
142 | |
143 | for (m_capNumBuffers = 0; m_capNumBuffers < req.count; ++m_capNumBuffers) { |
144 | struct v4l2_buffer buf; |
145 | |
146 | CLEAR(buf); |
147 | |
148 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
149 | buf.memory = V4L2_MEMORY_MMAP; |
150 | buf.index = m_capNumBuffers; |
151 | |
152 | if (FAILED == xioctl(cam->fd, VIDIOC_QUERYBUF, &buf)) { |
153 | LOGD("VIDIOC_QUERYBUF ERROR\n"); |
154 | iOutRet = FAILED; |
155 | goto IS_ERROR; |
156 | } |
157 | |
158 | cam->buffers[m_capNumBuffers].length = buf.length; |
159 | cam->buffers[m_capNumBuffers].start = mmap(NULL \, |
160 | buf.length, PROT_READ | PROT_WRITE, |
161 | MAP_SHARED, cam->fd, buf.m.offset); |
162 | |
163 | if (MAP_FAILED == cam->buffers[m_capNumBuffers].start) { |
164 | iOutRet = FAILED; |
165 | break; |
166 | } |
167 | |
168 | |
169 | } |
170 | |
171 | LOGD("END m_capNumBuffers : %d\n", m_capNumBuffers); |
172 | } while (FALSE); |
173 | IS_ERROR: |
174 | return iOutRet;*/ |
175 | |
176 | //for warning |
177 | cam = cam; |
178 | return 0; |
179 | } |
180 | |
181 | int CTvScreenCapture::InitCamera(struct camera *cam) |
182 | { |
183 | /* |
184 | int iOutRet = SUCCEED, iRet; |
185 | struct v4l2_capability *cap = &(cam->v4l2_cap); |
186 | struct v4l2_cropcap *cropcap = &(cam->v4l2_cropcap); |
187 | struct v4l2_crop *crop = &(cam->crop); |
188 | struct v4l2_format *fmt = &(cam->v4l2_fmt); |
189 | unsigned int min; |
190 | |
191 | do { |
192 | iRet = xioctl(cam->fd, VIDIOC_QUERYCAP, cap); |
193 | if (FAILED == iRet) { |
194 | if (EINVAL == errno) { |
195 | LOGD("%s is no V4L2 device\n", cam->device_name); |
196 | } |
197 | iOutRet = iRet; |
198 | break; |
199 | } |
200 | |
201 | if (!(cap->capabilities & V4L2_CAP_VIDEO_CAPTURE)) { |
202 | LOGD("%s is no video capture device\n", cam->device_name); |
203 | iOutRet = FAILED; |
204 | break; |
205 | } |
206 | |
207 | if (!(cap->capabilities & V4L2_CAP_STREAMING)) { |
208 | LOGD("%s does not support streaming i/o\n", cam->device_name); |
209 | iOutRet = FAILED; |
210 | break; |
211 | } |
212 | |
213 | LOGD("VIDOOC_QUERYCAP camera driver is [%s] card is [%s] businfo is [%s] version is [%d]\n", cap->driver, |
214 | cap->card, cap->bus_info, cap->version); |
215 | |
216 | // Select video input, video standard and tune here. |
217 | |
218 | CLEAR(*cropcap); |
219 | cropcap->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
220 | |
221 | crop->c.width = cam->width; |
222 | crop->c.height = cam->height; |
223 | crop->c.left = 0; |
224 | crop->c.top = 0; |
225 | crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
226 | |
227 | CLEAR(*fmt); |
228 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
229 | fmt->fmt.pix.width = cam->width; |
230 | fmt->fmt.pix.height = cam->height; |
231 | fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_NV21; |
232 | fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; |
233 | iRet = xioctl(cam->fd, VIDIOC_S_FMT, fmt); |
234 | if (FAILED == iRet) { |
235 | iOutRet = iRet; |
236 | LOGD("VIDIOC_S_FMT is ERROR\n"); |
237 | break; |
238 | } |
239 | |
240 | // Note VIDIOC_S_FMT may change width and height. |
241 | // Buggy driver paranoia. |
242 | min = fmt->fmt.pix.width * 2; |
243 | LOGD("bytesperline : %d w:h [%d %d]\n", fmt->fmt.pix.bytesperline, fmt->fmt.pix.width, fmt->fmt.pix.height); |
244 | if (fmt->fmt.pix.bytesperline < min) { |
245 | fmt->fmt.pix.bytesperline = min; |
246 | } |
247 | |
248 | min = fmt->fmt.pix.bytesperline * fmt->fmt.pix.height; |
249 | if (fmt->fmt.pix.sizeimage < min) { |
250 | fmt->fmt.pix.sizeimage = min; |
251 | } |
252 | |
253 | iRet = InitMmap(cam); |
254 | if (FAILED == iRet) { |
255 | LOGD("INIT MMAP FAILED\n"); |
256 | iOutRet = iRet; |
257 | break; |
258 | } |
259 | } while (FALSE); |
260 | return iOutRet; |
261 | */ |
262 | |
263 | //for warning |
264 | cam = cam; |
265 | return 0; |
266 | } |
267 | |
268 | |
269 | int CTvScreenCapture::SetVideoParameter(int width, int height, int frame) |
270 | { |
271 | /* |
272 | int iOutRet = SUCCEED, iRet; |
273 | |
274 | do { |
275 | m_capV4l2Cam.device_name = "/dev/video11"; |
276 | m_capV4l2Cam.buffers = NULL; |
277 | m_capV4l2Cam.width = 1280; |
278 | m_capV4l2Cam.height = 720; |
279 | m_capV4l2Cam.display_depth = 24; //5; //RGB24 |
280 | m_capV4l2Cam.frame_number = 1; //fps |
281 | iOutRet = OpenCamera(&m_capV4l2Cam) ; |
282 | if (SUCCEED != iOutRet) { |
283 | LOGD("ERROR:::Open Camera device failed\n"); |
284 | break; |
285 | } |
286 | m_capV4l2Cam.width = width; |
287 | m_capV4l2Cam.height = height; |
288 | m_capV4l2Cam.frame_number = frame; |
289 | |
290 | iRet = InitCamera(&m_capV4l2Cam); |
291 | if (SUCCEED != iRet) { |
292 | iOutRet = iRet; |
293 | break; |
294 | } |
295 | |
296 | } while (FALSE); |
297 | |
298 | return iOutRet ;*/ |
299 | |
300 | //for warning |
301 | width = width; |
302 | height = height; |
303 | frame = frame; |
304 | return 0; |
305 | } |
306 | |
307 | int CTvScreenCapture::StartCapturing(struct camera *cam) |
308 | { |
309 | /* |
310 | unsigned int i; |
311 | int iOutRet = SUCCEED, iRet; |
312 | enum v4l2_buf_type type; |
313 | |
314 | do { |
315 | for (i = 0; i < m_capNumBuffers; ++i) { |
316 | struct v4l2_buffer buf; |
317 | |
318 | //CLEAR(buf); |
319 | |
320 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
321 | buf.memory = V4L2_MEMORY_MMAP; |
322 | buf.index = i; |
323 | |
324 | iRet = xioctl(cam->fd, VIDIOC_QBUF, &buf); |
325 | if (FAILED == iRet) { |
326 | iOutRet = iRet; |
327 | goto IS_ERROR; |
328 | } |
329 | } |
330 | |
331 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
332 | iRet = xioctl(cam->fd, VIDIOC_STREAMON, &type); |
333 | if (FAILED == iRet) { |
334 | iOutRet = iRet; |
335 | break; |
336 | } |
337 | } while (FALSE); |
338 | |
339 | IS_ERROR: |
340 | return iOutRet;*/ |
341 | |
342 | //for warning |
343 | cam = cam; |
344 | return 0; |
345 | } |
346 | |
347 | int CTvScreenCapture::VideoStart() |
348 | { |
349 | /* |
350 | int iOutRet = SUCCEED, iRet; |
351 | do { |
352 | iRet = StartCapturing(&m_capV4l2Cam); |
353 | if (FAILED == iRet) { |
354 | iOutRet = iRet; |
355 | break; |
356 | } |
357 | } while (FALSE); |
358 | |
359 | return iOutRet;*/ |
360 | |
361 | return 0; |
362 | } |
363 | |
364 | void CTvScreenCapture::yuv_to_rgb32(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb) |
365 | { |
366 | /* |
367 | register int r, g, b; |
368 | int rgb24; |
369 | |
370 | r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10; |
371 | g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u - 128) ) >> 10; |
372 | b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10; |
373 | |
374 | r = r > 255 ? 255 : r < 0 ? 0 : r; |
375 | g = g > 255 ? 255 : g < 0 ? 0 : g; |
376 | b = b > 255 ? 255 : b < 0 ? 0 : b; |
377 | |
378 | rgb24 = (int)((r << 16) | (g << 8) | b); |
379 | |
380 | //ARGB |
381 | *rgb = (unsigned char)r; |
382 | rgb ++; |
383 | *rgb = (unsigned char)g; |
384 | rgb++; |
385 | *rgb = (unsigned char)b; |
386 | rgb++; |
387 | *rgb = 0xff;*/ |
388 | |
389 | //for warning |
390 | y = y; |
391 | u = u; |
392 | v = v; |
393 | rgb = rgb; |
394 | } |
395 | |
396 | void CTvScreenCapture::nv21_to_rgb32(unsigned char *buf, unsigned char *rgb, int width, int height, int *len) |
397 | { |
398 | /* |
399 | int x, y, z = 0; |
400 | int h, w; |
401 | int blocks; |
402 | unsigned char Y1, Y2, U, V; |
403 | |
404 | *len = 0; |
405 | blocks = (width * height) * 2; |
406 | for (h = 0, z = 0; h < height; h += 2) { |
407 | for (y = 0; y < width * 2; y += 2) { |
408 | Y1 = buf[ h * width + y + 0]; |
409 | V = buf[ blocks / 2 + h * width / 2 + y % width + 0 ]; |
410 | Y2 = buf[ h * width + y + 1]; |
411 | U = buf[ blocks / 2 + h * width / 2 + y % width + 1 ]; |
412 | |
413 | yuv_to_rgb32(Y1, U, V, &rgb[z]); |
414 | yuv_to_rgb32(Y2, U, V, &rgb[z + 4]); |
415 | z += 8; |
416 | } |
417 | } |
418 | *len = z; |
419 | */ |
420 | |
421 | //for warning |
422 | buf = buf; |
423 | rgb = rgb; |
424 | width = width; |
425 | height = height; |
426 | len = len; |
427 | } |
428 | |
429 | int CTvScreenCapture::GetVideoData(int *length) |
430 | { |
431 | /* |
432 | int iOutRet = SUCCEED, iRet; |
433 | |
434 | *length = 0; |
435 | while (true) { |
436 | fd_set fds; |
437 | struct timeval tv; |
438 | FD_ZERO(&fds); |
439 | FD_SET(m_capV4l2Cam.fd, &fds); |
440 | // Timeout. |
441 | tv.tv_sec = 0; |
442 | tv.tv_usec = 30000; |
443 | iRet = select(m_capV4l2Cam.fd + 1, &fds, NULL, NULL, &tv); |
444 | if (FAILED == iRet) { |
445 | LOGD("select FAILED\n"); |
446 | if (EINTR == errno) { |
447 | LOGD("select FAILED Continue\n"); |
448 | continue; |
449 | } |
450 | } |
451 | |
452 | if (0 == iRet) { |
453 | LOGD("select timeout\n"); |
454 | continue ; |
455 | } |
456 | |
457 | struct v4l2_buffer buf; |
458 | CLEAR(buf); |
459 | |
460 | buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
461 | buf.memory = V4L2_MEMORY_MMAP; |
462 | iRet = xioctl(m_capV4l2Cam.fd, VIDIOC_DQBUF, &buf); |
463 | if (FAILED == iRet) { |
464 | if (errno == EAGAIN) { |
465 | LOGD("GetVideoData EAGAIN \n"); |
466 | } |
467 | continue; |
468 | } |
469 | |
470 | LOGD("DDDDDDDDDDAAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %d %d [width:%d] [height:%d]\n", buf.length, iRet, |
471 | m_capV4l2Cam.width, m_capV4l2Cam.height); |
472 | int tmpLen = 0; |
473 | nv21_to_rgb32((unsigned char *)m_capV4l2Cam.buffers[buf.index].start, (unsigned char *)m_pData, m_capV4l2Cam.width, m_capV4l2Cam.height, &tmpLen); |
474 | //memcpy(m_pData,m_capV4l2Cam.buffers[buf.index].start, buf.length +1); |
475 | *length = buf.length; |
476 | break; |
477 | } |
478 | |
479 | if (*length > 0) { |
480 | mCapEvt.mFrameWide = m_capV4l2Cam.width; |
481 | mCapEvt.mFrameHeight = m_capV4l2Cam.height; |
482 | mCapEvt.mFrameNum = 1; |
483 | mCapEvt.mFrameSize = *length; |
484 | } else { |
485 | mCapEvt.mFrameWide = 0; |
486 | mCapEvt.mFrameHeight = 0; |
487 | mCapEvt.mFrameNum = 0; |
488 | mCapEvt.mFrameSize = 0; |
489 | } |
490 | |
491 | if (NULL != mpObserver) { |
492 | mpObserver->onTvEvent(mCapEvt); |
493 | } |
494 | |
495 | return iOutRet;*/ |
496 | |
497 | //for warning |
498 | length = length; |
499 | return 0; |
500 | } |
501 | |
502 | int CTvScreenCapture::StopCapturing(struct camera *cam) |
503 | { |
504 | /* |
505 | int iOutRet = SUCCEED, iRet; |
506 | enum v4l2_buf_type type; |
507 | |
508 | do { |
509 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
510 | |
511 | iRet = xioctl(cam->fd, VIDIOC_STREAMOFF, &type); |
512 | if (FAILED == iRet) { |
513 | iOutRet = iRet; |
514 | break; |
515 | } |
516 | } while (FALSE); |
517 | return iOutRet;*/ |
518 | |
519 | //for warning |
520 | cam = cam; |
521 | return 0; |
522 | } |
523 | |
524 | int CTvScreenCapture::VideoStop() |
525 | { |
526 | /* |
527 | StopCapturing(&m_capV4l2Cam); |
528 | UninitCamera(&m_capV4l2Cam); |
529 | return SUCCEED;*/ |
530 | return 0; |
531 | } |
532 | |
533 | int CTvScreenCapture::UninitCamera(struct camera *cam) |
534 | { |
535 | /* |
536 | unsigned int i; |
537 | |
538 | for (i = 0; i < m_capNumBuffers; ++i) { |
539 | if (cam->buffers[i].start == NULL) { |
540 | break; |
541 | } |
542 | |
543 | if (FAILED == munmap(cam->buffers[i].start, cam->buffers[i].length)) { |
544 | LOGD("ERROR::munmap cam buffer failed\n"); |
545 | break; |
546 | } |
547 | } |
548 | |
549 | if (NULL != cam->buffers) |
550 | free(cam->buffers); |
551 | cam->buffers = NULL; |
552 | return SUCCEED;*/ |
553 | |
554 | //for warning |
555 | cam = cam; |
556 | return 0; |
557 | } |
558 | |
559 | int CTvScreenCapture::CloseCamera(struct camera *cam) |
560 | { |
561 | /* |
562 | int iOutRet = SUCCEED, iRet; |
563 | |
564 | do { |
565 | if (cam->fd > 0) { |
566 | iRet = close(cam->fd); |
567 | if (FAILED == iRet) { |
568 | iOutRet = iRet; |
569 | break; |
570 | } |
571 | |
572 | cam->fd = -1; |
573 | } |
574 | } while (FALSE); |
575 | |
576 | return iOutRet;*/ |
577 | |
578 | //for warning |
579 | cam = cam; |
580 | return 0; |
581 | } |
582 | |
583 | int CTvScreenCapture::DeinitVideoCap() |
584 | { |
585 | /* |
586 | CloseCamera(&m_capV4l2Cam); |
587 | return SUCCEED ; |
588 | */ |
589 | return 0; |
590 | } |
591 | |
592 | int CTvScreenCapture::AmvideocapCapFrame(char *buf, int size, int *w, int *h, int *ret_size) |
593 | { |
594 | /* |
595 | int iOutRet = SUCCEED, iRet; |
596 | int iDevFd = -1; |
597 | int format = FORMAT_S32_ABGR; |
598 | |
599 | do { |
600 | iDevFd = open(VIDEOCAPDEV, O_RDWR); |
601 | if (iDevFd < 0) { |
602 | LOGD("ERROR,open amvideocap0 failed\n"); |
603 | iOutRet = FAILED; |
604 | break; |
605 | } |
606 | |
607 | if ((w != NULL) && (*w > 0)) { |
608 | iRet = ioctl(iDevFd, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, *w); |
609 | if (iRet < 0) { |
610 | iOutRet = iRet; |
611 | break; |
612 | } |
613 | } |
614 | |
615 | if ((h != NULL) && (*h > 0)) { |
616 | iRet = ioctl(iDevFd, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, *h); |
617 | if (iRet < 0) { |
618 | iOutRet = iRet; |
619 | break; |
620 | } |
621 | } |
622 | |
623 | iRet = ioctl(iDevFd, AMVIDEOCAP_IOW_SET_WANTFRAME_FORMAT, format); |
624 | if (iRet < 0) { |
625 | iOutRet = iRet; |
626 | break; |
627 | } |
628 | |
629 | *ret_size = read(iDevFd, buf, size); |
630 | if (0 == *ret_size) { |
631 | LOGD("ERROR:: Cann't Read video data\n"); |
632 | iOutRet = FAILED; |
633 | *ret_size = 0; |
634 | break; |
635 | } |
636 | |
637 | LOGD("========== Got Data Size : %d ==============\n", *ret_size); |
638 | #if 0 |
639 | if (w != NULL) { |
640 | iRet = ioctl(iDevFd, AMVIDEOCAP_IOR_GET_FRAME_WIDTH, w); |
641 | } |
642 | |
643 | if (h != NULL) { |
644 | iRet = ioctl(iDevFd, AMVIDEOCAP_IOR_GET_FRAME_HEIGHT, h); |
645 | } |
646 | #endif |
647 | } while (FALSE); |
648 | |
649 | close(iDevFd); |
650 | return iOutRet;*/ |
651 | |
652 | //for warning |
653 | buf = buf; |
654 | size = size; |
655 | w = w; |
656 | h = h; |
657 | ret_size = ret_size; |
658 | return 0; |
659 | } |
660 | |
661 | int CTvScreenCapture::CapOsdAndVideoLayer(int width, int height) |
662 | { |
663 | /* |
664 | int iOutRet = SUCCEED, iRet; |
665 | status_t iStatus; |
666 | ScreenCatch *mScreenCatch = NULL; |
667 | MetaData *pMeta = NULL; |
668 | MediaBuffer *buffer = NULL; |
669 | int dataLen = 0; |
670 | |
671 | do { |
672 | mScreenCatch = new ScreenCatch(width, height, 32); |
673 | if (NULL == mScreenCatch) { |
674 | LOGD("ERROR!!! mScreenCatch is NULL\n"); |
675 | iOutRet = FAILED; |
676 | break; |
677 | } |
678 | |
679 | pMeta = new MetaData(); |
680 | if (NULL == pMeta) { |
681 | LOGD("ERROR!!! pMeta is NULL\n"); |
682 | iOutRet = FAILED; |
683 | break; |
684 | } |
685 | pMeta->setInt32(kKeyColorFormat, OMX_COLOR_Format32bitARGB8888); |
686 | |
687 | mScreenCatch->start(pMeta); |
688 | |
689 | while (true) { |
690 | iStatus = mScreenCatch->read(&buffer); |
691 | if (iStatus != OK ) { |
692 | usleep(1000); |
693 | continue; |
694 | } |
695 | |
696 | if (NULL == buffer) { |
697 | iOutRet = FAILED; |
698 | break; |
699 | } |
700 | |
701 | LOGD("DDDDDDDDDDAAAAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %d %d\n", buffer->size(), iStatus); |
702 | //nv21_to_rgb32((unsigned char*)buffer->data(),(unsigned char *)m_pData,width,height,&dataLen); |
703 | memcpy((unsigned char *)m_pData, (unsigned char *)buffer->data(), buffer->size()); |
704 | break; |
705 | } |
706 | } while (FALSE); |
707 | |
708 | if (dataLen > 0) { |
709 | mCapEvt.mFrameWide = width; |
710 | mCapEvt.mFrameHeight = height; |
711 | mCapEvt.mFrameNum = 1; |
712 | mCapEvt.mFrameSize = dataLen; |
713 | } else { |
714 | mCapEvt.mFrameWide = 0; |
715 | mCapEvt.mFrameHeight = 0; |
716 | mCapEvt.mFrameNum = 0; |
717 | mCapEvt.mFrameSize = 0; |
718 | } |
719 | |
720 | if (NULL != mpObserver) { |
721 | mpObserver->onTvEvent(mCapEvt); |
722 | } |
723 | |
724 | mScreenCatch->stop(); |
725 | |
726 | mScreenCatch->free(buffer); |
727 | buffer = NULL; |
728 | return iOutRet;*/ |
729 | |
730 | //for warning |
731 | width = width; |
732 | height = height; |
733 | return 0; |
734 | } |
735 | |
736 | int CTvScreenCapture::CapMediaPlayerVideoLayerOnly(int width, int height) |
737 | { |
738 | /* |
739 | int iOutRet = SUCCEED, iRet; |
740 | int ibufSize, iDataSize = 0; |
741 | int w, h; |
742 | |
743 | do { |
744 | ibufSize = width * height * 4; |
745 | w = width; |
746 | h = height; |
747 | |
748 | iRet = AmvideocapCapFrame(m_pData, ibufSize, &w, &h, &iDataSize); |
749 | if (SUCCEED != iRet) { |
750 | LOGD("AmvideocapCapFrame Cannt CapFram\n"); |
751 | iOutRet = iRet; |
752 | break; |
753 | } |
754 | |
755 | LOGD("GOT DDDDDDDDDAAAAAAAATTTTTTTTTTTAAAAAA Size : %d w:%d h: %d\n", iDataSize, w, h); |
756 | |
757 | if (iDataSize > 0) { |
758 | mCapEvt.mFrameWide = w; |
759 | mCapEvt.mFrameHeight = h; |
760 | mCapEvt.mFrameNum = 1; |
761 | mCapEvt.mFrameSize = iDataSize; |
762 | } else { |
763 | mCapEvt.mFrameWide = 0; |
764 | mCapEvt.mFrameHeight = 0; |
765 | mCapEvt.mFrameNum = 0; |
766 | mCapEvt.mFrameSize = 0; |
767 | } |
768 | |
769 | if (NULL != mpObserver) { |
770 | mpObserver->onTvEvent(mCapEvt); |
771 | } |
772 | } while (FALSE); |
773 | |
774 | return iOutRet;*/ |
775 | |
776 | //for warning |
777 | width = width; |
778 | height = height; |
779 | return 0; |
780 | } |
781 | |
782 | CTvScreenCapture::CTvScreenCapture() |
783 | { |
784 | /* |
785 | m_capNumBuffers = 0; |
786 | memset(&m_capV4l2Cam, 0x00, sizeof(camera)); |
787 | mpObserver = NULL;*/ |
788 | } |
789 | |
790 | CTvScreenCapture::~CTvScreenCapture() |
791 | { |
792 | /* |
793 | memset(&m_capV4l2Cam, 0x00, sizeof(camera)); |
794 | m_pData = NULL;*/ |
795 | } |
796 | |
797 |