4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
\r
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
22 /*===========================================================================================
\r
26 ========================================================================================== */
\r
27 #include "mm_player_capture.h"
\r
28 #include "mm_player_priv.h"
\r
30 #include <mm_util_imgp.h>
\r
31 #include <gst/video/video-info.h>
33 /*---------------------------------------------------------------------------
\r
34 | LOCAL VARIABLE DEFINITIONS for internal |
\r
35 ---------------------------------------------------------------------------*/
\r
37 /*---------------------------------------------------------------------------
\r
38 | LOCAL FUNCTION PROTOTYPES: |
\r
39 ---------------------------------------------------------------------------*/
\r
40 static GstPadProbeReturn __mmplayer_video_capture_probe (GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
41 static int __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuffer *buffer);
42 static gpointer __mmplayer_capture_thread(gpointer data);
\r
43 static void __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src, int yuv420_width, int yuv420_height, int left, int top, int right, int buttom);
\r
44 static int __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos);
\r
45 static int __mm_player_convert_colorspace(mm_player_t* player, unsigned char* src_data, mm_util_img_format src_fmt, unsigned int src_w, unsigned int src_h, mm_util_img_format dst_fmt);
\r
47 /*===========================================================================================
\r
49 | FUNCTION DEFINITIONS |
\r
51 ========================================================================================== */
\r
53 _mmplayer_initialize_video_capture(mm_player_t* player)
\r
55 return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
\r
56 /* create capture mutex */
\r
57 player->capture_thread_mutex = g_mutex_new();
\r
58 if ( ! player->capture_thread_mutex )
\r
60 debug_critical("Cannot create capture mutex");
\r
64 /* create capture cond */
\r
65 player->capture_thread_cond = g_cond_new();
\r
66 if ( ! player->capture_thread_cond )
\r
68 debug_critical("Cannot create capture cond");
\r
72 player->capture_thread_exit = FALSE;
\r
74 /* create video capture thread */
\r
75 player->capture_thread =
\r
76 g_thread_create (__mmplayer_capture_thread, (gpointer)player, TRUE, NULL);
\r
77 if ( ! player->capture_thread )
\r
82 return MM_ERROR_NONE;
\r
85 /* capture thread */
\r
86 if ( player->capture_thread_mutex )
\r
87 g_mutex_free ( player->capture_thread_mutex );
\r
89 if ( player->capture_thread_cond )
\r
90 g_cond_free ( player->capture_thread_cond );
\r
92 return MM_ERROR_PLAYER_INTERNAL;
\r
96 _mmplayer_release_video_capture(mm_player_t* player)
\r
98 return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
\r
99 /* release capture thread */
\r
100 if ( player->capture_thread_cond &&
\r
101 player->capture_thread_mutex &&
\r
102 player->capture_thread )
\r
104 g_mutex_lock(player->capture_thread_mutex);
\r
105 player->capture_thread_exit = TRUE;
\r
106 g_cond_signal( player->capture_thread_cond );
\r
107 g_mutex_unlock(player->capture_thread_mutex);
\r
109 debug_log("waitting for capture thread exit");
\r
110 g_thread_join ( player->capture_thread );
\r
111 g_mutex_free ( player->capture_thread_mutex );
\r
112 g_cond_free ( player->capture_thread_cond );
\r
113 debug_log("capture thread released");
\r
116 return MM_ERROR_NONE;
\r
120 _mmplayer_do_video_capture(MMHandleType hplayer)
\r
122 mm_player_t* player = (mm_player_t*) hplayer;
\r
123 int ret = MM_ERROR_NONE;
\r
124 GstPad *pad = NULL;
\r
128 return_val_if_fail(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
\r
130 /* capturing or not */
\r
131 if (player->video_capture_cb_probe_id || player->capture.data || player->captured.a[0] || player->captured.a[1])
\r
133 debug_warning("capturing... we can't do any more");
\r
134 return MM_ERROR_PLAYER_INVALID_STATE;
\r
137 /* check if video pipeline is linked or not */
\r
138 if (!player->pipeline->videobin || !player->sent_bos)
\r
140 debug_warning("not ready to capture");
\r
141 return MM_ERROR_PLAYER_INVALID_STATE;
\r
144 pad = gst_element_get_static_pad(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "sink" );
145 if (player->state != MM_PLAYER_STATE_PLAYING)
\r
147 if (player->state == MM_PLAYER_STATE_PAUSED) // get last buffer from video sink
\r
149 GstSample *sample = NULL;
150 g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "last-sample", &sample, NULL);
153 GstBuffer *buf = NULL;
\r
154 buf = gst_sample_get_buffer(sample);
157 ret = __mmplayer_get_video_frame_from_buffer(player, pad, buf);
158 gst_buffer_unref(buf);
\r
160 gst_sample_unref(sample);
166 debug_warning("invalid state(%d) to capture", player->state);
\r
167 return MM_ERROR_PLAYER_INVALID_STATE;
\r
171 /* register probe */
\r
172 player->video_capture_cb_probe_id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
\r
173 __mmplayer_video_capture_probe, player, NULL);
\r
175 gst_object_unref(GST_OBJECT(pad));
\r
183 __mmplayer_capture_thread(gpointer data)
\r
185 mm_player_t* player = (mm_player_t*) data;
\r
186 MMMessageParamType msg = {0, };
\r
187 unsigned char * linear_y_plane = NULL;
\r
188 unsigned char * linear_uv_plane = NULL;
\r
190 return_val_if_fail(player, NULL);
\r
192 while (!player->capture_thread_exit)
\r
194 debug_log("capture thread started. waiting for signal");
\r
196 g_mutex_lock(player->capture_thread_mutex);
\r
197 g_cond_wait( player->capture_thread_cond, player->capture_thread_mutex );
\r
199 if ( player->capture_thread_exit )
\r
201 debug_log("exiting capture thread");
\r
204 debug_log("capture thread is recieved signal");
\r
206 /* NOTE: Don't use MMPLAYER_CMD_LOCK() here.
\r
207 * Because deadlock can be happened if other player api is used in message callback.
\r
209 if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED)
\r
211 /* Colorspace conversion : NV12T-> NV12-> RGB888 */
\r
213 int linear_y_plane_size;
\r
214 int linear_uv_plane_size;
\r
215 unsigned char * src_buffer = NULL;
\r
217 debug_log("w[0]=%d, w[1]=%d", player->captured.w[0], player->captured.w[1]);
\r
218 debug_log("h[0]=%d, h[1]=%d", player->captured.h[0], player->captured.h[1]);
\r
219 debug_log("s[0]=%d, s[1]=%d", player->captured.s[0], player->captured.s[1]);
\r
220 debug_log("e[0]=%d, e[1]=%d", player->captured.e[0], player->captured.e[1]);
\r
221 debug_log("a[0]=%p, a[1]=%p", player->captured.a[0], player->captured.a[1]);
\r
224 if (mm_attrs_get_int_by_name(player->attrs, "content_video_width", &(player->captured.w[0])) != MM_ERROR_NONE)
\r
226 debug_error("failed to get content width attribute");
\r
230 if (mm_attrs_get_int_by_name(player->attrs, "content_video_height", &(player->captured.h[0])) != MM_ERROR_NONE)
\r
232 debug_error("failed to get content height attribute");
\r
237 linear_y_plane_size = (player->captured.w[0] * player->captured.h[0]);
\r
238 linear_uv_plane_size = (player->captured.w[0] * player->captured.h[0]/2);
\r
240 linear_y_plane = (unsigned char*) g_try_malloc(linear_y_plane_size);
\r
241 if (linear_y_plane == NULL)
\r
243 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
247 linear_uv_plane = (unsigned char*) g_try_malloc(linear_uv_plane_size);
\r
248 if (linear_uv_plane == NULL)
\r
250 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
253 /* NV12 tiled to linear */
\r
254 __csc_tiled_to_linear_crop(linear_y_plane, player->captured.a[0], player->captured.w[0], player->captured.h[0], 0,0,0,0);
\r
255 __csc_tiled_to_linear_crop(linear_uv_plane, player->captured.a[1], player->captured.w[0], player->captured.h[0]/2, 0,0,0,0);
\r
257 MMPLAYER_FREEIF(player->captured.a[0]);
\r
258 MMPLAYER_FREEIF(player->captured.a[1]);
\r
260 src_buffer = (unsigned char*) g_try_malloc(linear_y_plane_size+linear_uv_plane_size);
\r
262 if (src_buffer == NULL)
\r
264 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
267 memset(src_buffer, 0x00, linear_y_plane_size+linear_uv_plane_size);
\r
268 memcpy(src_buffer, linear_y_plane, linear_y_plane_size);
\r
269 memcpy(src_buffer+linear_y_plane_size, linear_uv_plane, linear_uv_plane_size);
\r
271 /* NV12 linear to RGB888 */
\r
272 ret = __mm_player_convert_colorspace(player, src_buffer, MM_UTIL_IMG_FMT_NV12,
\r
273 player->captured.w[0], player->captured.h[0], MM_UTIL_IMG_FMT_RGB888);
\r
275 if (ret != MM_ERROR_NONE)
\r
277 debug_error("failed to convert nv12 linear");
\r
281 MMPLAYER_FREEIF(src_buffer);
\r
282 MMPLAYER_FREEIF(linear_y_plane);
\r
283 MMPLAYER_FREEIF(linear_uv_plane);
\r
286 player->capture.fmt = MM_PLAYER_COLORSPACE_RGB888;
\r
287 msg.data = &player->capture;
\r
288 msg.size = player->capture.size;
\r
290 if (player->cmd >= MMPLAYER_COMMAND_START)
\r
292 MMPLAYER_POST_MSG( player, MM_MESSAGE_VIDEO_CAPTURED, &msg );
\r
293 debug_log("returned from capture message callback");
\r
296 g_mutex_unlock(player->capture_thread_mutex);
\r
298 //MMPLAYER_FREEIF(player->capture.data);
\r
301 if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED)
\r
304 MMPLAYER_FREEIF(linear_y_plane);
\r
305 MMPLAYER_FREEIF(linear_uv_plane);
\r
306 MMPLAYER_FREEIF(player->captured.a[0]);
\r
307 MMPLAYER_FREEIF(player->captured.a[1]);
\r
310 msg.union_type = MM_MSG_UNION_CODE;
\r
312 g_mutex_unlock(player->capture_thread_mutex);
\r
313 MMPLAYER_POST_MSG( player, MM_MESSAGE_VIDEO_NOT_CAPTURED, &msg );
\r
317 g_mutex_unlock(player->capture_thread_mutex);
\r
322 * The output is fixed as RGB888
\r
325 __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuffer *buffer)
327 gint yplane_size = 0;
\r
328 gint uvplane_size = 0;
\r
329 gint src_width = 0;
\r
330 gint src_height = 0;
\r
331 GstCaps *caps = NULL;
\r
332 GstStructure *structure = NULL;
\r
333 GstMapInfo mapinfo = GST_MAP_INFO_INIT;
334 GstMemory *memory = 0;
335 mm_util_img_format src_fmt = MM_UTIL_IMG_FMT_YUV420;
\r
336 mm_util_img_format dst_fmt = MM_UTIL_IMG_FMT_RGB888; // fixed
\r
340 return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
\r
341 return_val_if_fail ( buffer, MM_ERROR_INVALID_ARGUMENT );
\r
344 caps = gst_pad_get_current_caps(pad);
346 return_val_if_fail ( caps, MM_ERROR_INVALID_ARGUMENT );
\r
347 debug_log("caps to capture: %s\n", gst_caps_to_string(caps));
\r
349 structure = gst_caps_get_structure (caps, 0);
\r
351 return_val_if_fail (structure != NULL, MM_ERROR_PLAYER_INTERNAL);
\r
353 /* init capture image buffer */
\r
354 memset(&player->capture, 0x00, sizeof(MMPlayerVideoCapture));
\r
356 gst_structure_get_int (structure, "width", &src_width);
\r
357 gst_structure_get_int (structure, "height", &src_height);
\r
359 /* check rgb or yuv */
\r
360 if (gst_structure_has_name(structure, "video/x-raw"))
363 if(!g_strcmp0(gst_structure_get_string(structure, "format"), "ST12"))
365 debug_msg ("captured format is ST12\n");
367 MMPlayerMPlaneImage *proved = NULL;
\r
368 player->video_cs = MM_PLAYER_COLORSPACE_NV12_TILED;
\r
370 /* get video frame info from proved buffer */
\r
371 memory = gst_buffer_get_memory(buffer, 1);
372 gst_memory_map(memory, &mapinfo, GST_MAP_READ);
373 proved = (MMPlayerMPlaneImage *)mapinfo.data;
374 gst_memory_unmap(memory, &mapinfo);
376 if ( !proved || !proved->a[0] || !proved->a[1] )
377 return MM_ERROR_PLAYER_INTERNAL;
379 yplane_size = proved->y_size;
380 uvplane_size = proved->uv_size;
382 debug_msg ("yplane_size=%d, uvplane_size=%d\n",yplane_size,uvplane_size);
383 memset(&player->captured, 0x00, sizeof(MMPlayerMPlaneImage));
384 memcpy(&player->captured, proved, sizeof(MMPlayerMPlaneImage));
386 player->captured.a[0] = g_try_malloc(yplane_size);
\r
387 if ( !player->captured.a[0] )
\r
388 return MM_ERROR_SOUND_NO_FREE_SPACE;
\r
390 player->captured.a[1] = g_try_malloc(uvplane_size);
\r
391 if ( !player->captured.a[1] )
\r
392 return MM_ERROR_SOUND_NO_FREE_SPACE;
\r
394 memcpy(player->captured.a[0], proved->a[0], yplane_size);
\r
395 memcpy(player->captured.a[1], proved->a[1], uvplane_size);
\r
400 GstVideoInfo format_info;
401 gst_video_info_from_caps(&format_info, caps);
402 switch (GST_VIDEO_INFO_FORMAT(&format_info))
\r
404 case GST_VIDEO_FORMAT_I420:
405 src_fmt = MM_UTIL_IMG_FMT_I420;
408 case GST_VIDEO_FORMAT_BGRA:
409 src_fmt = MM_UTIL_IMG_FMT_BGRA8888;
412 case GST_VIDEO_FORMAT_BGRx:
413 src_fmt = MM_UTIL_IMG_FMT_BGRX8888;
426 gst_buffer_map(buffer, &mapinfo, GST_MAP_READ);
427 __mm_player_convert_colorspace(player, mapinfo.data, src_fmt, src_width, src_height, dst_fmt);
428 gst_buffer_unmap(buffer, &mapinfo);
431 /* do convert colorspace */
\r
432 g_cond_signal( player->capture_thread_cond );
\r
436 return MM_ERROR_NONE;
\r
439 debug_error("unknown format to capture\n");
\r
440 return MM_ERROR_PLAYER_INTERNAL;
\r
443 static GstPadProbeReturn
444 __mmplayer_video_capture_probe (GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
446 mm_player_t* player = (mm_player_t*) u_data;
\r
447 GstBuffer *buffer = NULL;
448 int ret = MM_ERROR_NONE;
\r
450 return_val_if_fail ( info->data, GST_PAD_PROBE_REMOVE);
453 buffer = gst_pad_probe_info_get_buffer(info);
454 ret = __mmplayer_get_video_frame_from_buffer(player, pad, buffer);
456 if ( ret != MM_ERROR_NONE)
\r
458 debug_error("faild to get video frame. %x\n", ret);
\r
459 return GST_PAD_PROBE_REMOVE;
462 /* remove probe to be called at one time */
\r
463 if (player->video_capture_cb_probe_id)
\r
465 gst_pad_remove_probe (pad, player->video_capture_cb_probe_id);
\r
466 player->video_capture_cb_probe_id = 0;
\r
471 return GST_PAD_PROBE_OK;
475 __mm_player_convert_colorspace(mm_player_t* player, unsigned char* src_data, mm_util_img_format src_fmt, unsigned int src_w, unsigned int src_h, mm_util_img_format dst_fmt)
\r
477 unsigned char *dst_data = NULL;
\r
478 unsigned int dst_size;
\r
479 int ret = MM_ERROR_NONE;
\r
481 return_val_if_fail(player, MM_ERROR_PLAYER_INTERNAL);
\r
482 ret = mm_util_get_image_size(dst_fmt, src_w, src_h, &dst_size);
\r
484 if (ret != MM_ERROR_NONE)
\r
486 debug_error("failed to get image size for capture, %d\n", ret);
\r
487 return MM_ERROR_PLAYER_INTERNAL;
\r
490 debug_log("width: %d, height: %d to capture, dest size: %d\n", src_w, src_h, dst_size);
\r
492 dst_data = (unsigned char*)g_malloc0(dst_size);
\r
496 debug_error("no free space to capture\n");
\r
497 return MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
500 ret = mm_util_convert_colorspace(src_data, src_w, src_h, src_fmt, dst_data, dst_fmt);
\r
502 if (ret != MM_ERROR_NONE)
\r
504 debug_error("failed to convert for capture, %d\n", ret);
\r
505 return MM_ERROR_PLAYER_INTERNAL;
\r
508 player->capture.size = dst_size;
\r
509 player->capture.data = dst_data;
\r
511 return MM_ERROR_NONE;
\r
515 * Get tiled address of position(x,y)
\r
518 * width of tiled[in]
\r
521 * height of tiled[in]
\r
524 * x position of tield[in]
\r
527 * y position of tield[in]
\r
530 * address of tiled data
\r
533 __tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos)
\r
535 int pixel_x_m1, pixel_y_m1;
\r
536 int roundup_x, roundup_y;
\r
537 int linear_addr0, linear_addr1, bank_addr ;
\r
541 pixel_x_m1 = x_size -1;
\r
542 pixel_y_m1 = y_size -1;
\r
544 roundup_x = ((pixel_x_m1 >> 7) + 1);
\r
545 roundup_y = ((pixel_x_m1 >> 6) + 1);
\r
547 x_addr = x_pos >> 2;
\r
549 if ((y_size <= y_pos+32) && ( y_pos < y_size) &&
\r
550 (((pixel_y_m1 >> 5) & 0x1) == 0) && (((y_pos >> 5) & 0x1) == 0)) {
\r
551 linear_addr0 = (((y_pos & 0x1f) <<4) | (x_addr & 0xf));
\r
552 linear_addr1 = (((y_pos >> 6) & 0xff) * roundup_x + ((x_addr >> 6) & 0x3f));
\r
554 if (((x_addr >> 5) & 0x1) == ((y_pos >> 5) & 0x1))
\r
555 bank_addr = ((x_addr >> 4) & 0x1);
\r
557 bank_addr = 0x2 | ((x_addr >> 4) & 0x1);
\r
559 linear_addr0 = (((y_pos & 0x1f) << 4) | (x_addr & 0xf));
\r
560 linear_addr1 = (((y_pos >> 6) & 0xff) * roundup_x + ((x_addr >> 5) & 0x7f));
\r
562 if (((x_addr >> 5) & 0x1) == ((y_pos >> 5) & 0x1))
\r
563 bank_addr = ((x_addr >> 4) & 0x1);
\r
565 bank_addr = 0x2 | ((x_addr >> 4) & 0x1);
\r
568 linear_addr0 = linear_addr0 << 2;
\r
569 trans_addr = (linear_addr1 <<13) | (bank_addr << 11) | linear_addr0;
\r
575 * Converts tiled data to linear
\r
576 * Crops left, top, right, buttom
\r
577 * 1. Y of NV12T to Y of YUV420P
\r
578 * 2. Y of NV12T to Y of YUV420S
\r
579 * 3. UV of NV12T to UV of YUV420S
\r
581 * @param yuv420_dest
\r
582 * Y or UV plane address of YUV420[out]
\r
585 * Y or UV plane address of NV12T[in]
\r
587 * @param yuv420_width
\r
588 * Width of YUV420[in]
\r
590 * @param yuv420_height
\r
591 * Y: Height of YUV420, UV: Height/2 of YUV420[in]
\r
594 * Crop size of left
\r
600 * Crop size of right
\r
603 * Crop size of buttom
\r
606 __csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src, int yuv420_width, int yuv420_height,
\r
607 int left, int top, int right, int buttom)
\r
610 int tiled_offset = 0, tiled_offset1 = 0;
\r
611 int linear_offset = 0;
\r
612 int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
\r
614 temp3 = yuv420_width-right;
\r
615 temp1 = temp3-left;
\r
616 /* real width is greater than or equal 256 */
\r
617 if (temp1 >= 256) {
\r
618 for (i=top; i<yuv420_height-buttom; i=i+1) {
\r
624 /* odd fomula: 2+x+(x>>2)<<2+x_block_num*(y-1) */
\r
625 tiled_offset = temp4-1;
\r
626 temp1 = ((yuv420_width+127)>>7)<<7;
\r
627 tiled_offset = tiled_offset*(temp1>>6);
\r
628 tiled_offset = tiled_offset+temp3;
\r
629 tiled_offset = tiled_offset+2;
\r
630 temp1 = (temp3>>2)<<2;
\r
631 tiled_offset = tiled_offset+temp1;
\r
632 tiled_offset = tiled_offset<<11;
\r
633 tiled_offset1 = tiled_offset+2048*2;
\r
636 temp2 = ((yuv420_height+31)>>5)<<5;
\r
637 if ((i+32)<temp2) {
\r
638 /* even1 fomula: x+((x+2)>>2)<<2+x_block_num*y */
\r
640 temp1 = (temp1>>2)<<2;
\r
641 tiled_offset = temp3+temp1;
\r
642 temp1 = ((yuv420_width+127)>>7)<<7;
\r
643 tiled_offset = tiled_offset+temp4*(temp1>>6);
\r
644 tiled_offset = tiled_offset<<11;
\r
645 tiled_offset1 = tiled_offset+2048*6;
\r
648 /* even2 fomula: x+x_block_num*y */
\r
649 temp1 = ((yuv420_width+127)>>7)<<7;
\r
650 tiled_offset = temp4*(temp1>>6);
\r
651 tiled_offset = tiled_offset+temp3;
\r
652 tiled_offset = tiled_offset<<11;
\r
653 tiled_offset1 = tiled_offset+2048*2;
\r
659 tiled_offset = tiled_offset+64*(temp1);
\r
660 tiled_offset1 = tiled_offset1+64*(temp1);
\r
661 temp2 = yuv420_width-left-right;
\r
662 linear_offset = temp2*(i-top);
\r
663 temp3 = ((j+256)>>8)<<8;
\r
667 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset+temp1, 64-temp1);
\r
668 temp2 = ((left+63)>>6)<<6;
\r
669 temp3 = ((yuv420_width-right)>>6)<<6;
\r
670 if (temp2 == temp3) {
\r
671 temp2 = yuv420_width-right-(64-temp1);
\r
673 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset+2048, 64);
\r
674 memcpy(yuv420_dest+linear_offset+128-temp1, nv12t_src+tiled_offset1, 64);
\r
675 memcpy(yuv420_dest+linear_offset+192-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
676 linear_offset = linear_offset+256-temp1;
\r
677 } else if (temp3 > 128) {
\r
678 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset+2048+temp1, 64-temp1);
\r
679 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset1, 64);
\r
680 memcpy(yuv420_dest+linear_offset+128-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
681 linear_offset = linear_offset+192-temp1;
\r
682 } else if (temp3 > 64) {
\r
683 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset1+temp1, 64-temp1);
\r
684 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
685 linear_offset = linear_offset+128-temp1;
\r
686 } else if (temp3 > 0) {
\r
687 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset1+2048+temp1, 64-temp1);
\r
688 linear_offset = linear_offset+64-temp1;
\r
691 tiled_offset = tiled_offset+temp4*2048;
\r
694 temp2 = yuv420_width-right-256;
\r
695 for (; j<=temp2; j=j+256) {
\r
696 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
697 tiled_offset1 = tiled_offset1+temp4*2048;
\r
698 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
699 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, 64);
\r
700 tiled_offset = tiled_offset+temp4*2048;
\r
701 memcpy(yuv420_dest+linear_offset+192, nv12t_src+tiled_offset1+2048, 64);
\r
702 linear_offset = linear_offset+256;
\r
705 tiled_offset1 = tiled_offset1+temp4*2048;
\r
706 temp2 = yuv420_width-right-j;
\r
708 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
709 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
710 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, 64);
\r
711 memcpy(yuv420_dest+linear_offset+192, nv12t_src+tiled_offset1+2048, temp2-192);
\r
712 } else if (temp2 > 128) {
\r
713 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
714 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
715 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, temp2-128);
\r
716 } else if (temp2 > 64) {
\r
717 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
718 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, temp2-64);
\r
720 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
723 } else if (temp1 >= 64) {
\r
724 for (i=top; i<(yuv420_height-buttom); i=i+1) {
\r
726 tiled_offset = __tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
727 temp2 = ((j+64)>>6)<<6;
\r
729 linear_offset = temp1*(i-top);
\r
731 tiled_offset = tiled_offset+temp4;
\r
732 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
733 linear_offset = linear_offset+temp2;
\r
735 if ((j+64) <= temp3) {
\r
736 tiled_offset = __tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
737 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
738 linear_offset = linear_offset+64;
\r
741 if ((j+64) <= temp3) {
\r
742 tiled_offset = __tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
743 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
744 linear_offset = linear_offset+64;
\r
748 tiled_offset = __tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
750 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
754 for (i=top; i<(yuv420_height-buttom); i=i+1) {
\r
755 linear_offset = temp1*(i-top);
\r
756 for (j=left; j<(yuv420_width-right); j=j+2) {
\r
757 tiled_offset = __tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
759 tiled_offset = tiled_offset+temp4;
\r
760 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 2);
\r
761 linear_offset = linear_offset+2;
\r