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>,
\r
7 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
23 /*===========================================================================================
\r
27 ========================================================================================== */
\r
28 #include "mm_player_capture.h"
\r
29 #include "mm_player_priv.h"
\r
31 #include <mm_util_imgp.h>
\r
33 /*---------------------------------------------------------------------------
\r
34 | LOCAL VARIABLE DEFINITIONS for internal |
\r
35 ---------------------------------------------------------------------------*/
\r
37 /*---------------------------------------------------------------------------
\r
38 | LOCAL FUNCTION PROTOTYPES: |
\r
39 ---------------------------------------------------------------------------*/
\r
40 static gboolean __mmplayer_video_capture_probe (GstPad *pad, GstBuffer *buffer, gpointer u_data);
\r
41 static int __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstBuffer *buffer);
\r
42 static void __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
52 int __mmplayer_initialize_video_capture(mm_player_t* player)
\r
54 return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
\r
55 /* create capture mutex */
\r
56 player->capture_thread_mutex = g_mutex_new();
\r
57 if ( ! player->capture_thread_mutex )
\r
59 debug_critical("Cannot create capture mutex\n");
\r
63 /* create capture cond */
\r
64 player->capture_thread_cond = g_cond_new();
\r
65 if ( ! player->capture_thread_cond )
\r
67 debug_critical("Cannot create capture cond\n");
\r
71 player->capture_thread_exit = FALSE;
\r
73 /* create video capture thread */
\r
74 player->capture_thread =
\r
75 g_thread_create (__mmplayer_capture_thread, (gpointer)player, TRUE, NULL);
\r
76 if ( ! player->capture_thread )
\r
81 return MM_ERROR_NONE;
\r
84 /* free capture thread */
\r
85 if ( player->capture_thread_cond &&
\r
86 player->capture_thread_mutex &&
\r
87 player->capture_thread )
\r
89 player->capture_thread_exit = TRUE;
\r
90 g_cond_signal( player->capture_thread_cond );
\r
92 g_mutex_free ( player->capture_thread_mutex );
\r
93 player->capture_thread_mutex = NULL;
\r
95 g_cond_free ( player->capture_thread_cond );
\r
96 player->capture_thread_cond = NULL;
\r
98 g_thread_join( player->capture_thread );
\r
99 player->capture_thread = NULL;
\r
102 /* capture thread */
\r
103 if ( player->capture_thread_mutex )
\r
104 g_mutex_free ( player->capture_thread_mutex );
\r
106 if ( player->capture_thread_cond )
\r
107 g_cond_free ( player->capture_thread_cond );
\r
109 return MM_ERROR_PLAYER_INTERNAL;
\r
113 __mmplayer_release_video_capture(mm_player_t* player)
\r
115 return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
\r
116 /* release capture thread */
\r
117 if ( player->capture_thread_cond &&
\r
118 player->capture_thread_mutex &&
\r
119 player->capture_thread )
\r
121 g_mutex_lock(player->capture_thread_mutex);
\r
122 player->capture_thread_exit = TRUE;
\r
123 g_cond_signal( player->capture_thread_cond );
\r
124 g_mutex_unlock(player->capture_thread_mutex);
\r
126 debug_log("waitting forcapture thread exit\n");
\r
127 g_thread_join ( player->capture_thread );
\r
128 g_mutex_free ( player->capture_thread_mutex );
\r
129 g_cond_free ( player->capture_thread_cond );
\r
130 debug_log("capture thread released\n");
\r
133 return MM_ERROR_NONE;
\r
137 __mmplayer_capture_thread(gpointer data)
\r
139 mm_player_t* player = (mm_player_t*) data;
\r
140 MMMessageParamType msg = {0, };
\r
141 unsigned char * linear_y_plane = NULL;
\r
142 unsigned char * linear_uv_plane = NULL;
\r
144 return_if_fail (player);
\r
148 g_mutex_lock(player->capture_thread_mutex);
\r
149 if ( player->capture_thread_exit )
\r
151 debug_log("exiting capture thread\n");
\r
155 debug_log("capture thread started. waiting for signal.\n");
\r
156 g_cond_wait( player->capture_thread_cond, player->capture_thread_mutex );
\r
158 if ( player->capture_thread_exit )
\r
160 debug_log("exiting capture thread\n");
\r
163 debug_log("capture thread is recieved signal.\n");
\r
165 /* NOTE: Don't use MMPLAYER_CMD_LOCK() here.
\r
166 * Because deadlock can be happened if other player api is used in message callback.
\r
168 if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED)
\r
170 /* Colorspace conversion : NV12T-> NV12-> RGB888 */
\r
172 int linear_y_plane_size;
\r
173 int linear_uv_plane_size;
\r
174 unsigned char * src_buffer = NULL;
\r
176 debug_log("w[0]=%d, w[1]=%d\n", player->captured.w[0], player->captured.w[1]);
\r
177 debug_log("h[0]=%d, h[1]=%d\n", player->captured.h[0], player->captured.h[1]);
\r
178 debug_log("s[0]=%d, s[1]=%d\n", player->captured.s[0], player->captured.s[1]);
\r
179 debug_log("e[0]=%d, e[1]=%d\n", player->captured.e[0], player->captured.e[1]);
\r
180 debug_log("a[0]=%p, a[1]=%p\n", player->captured.a[0], player->captured.a[1]);
\r
182 linear_y_plane_size = (player->captured.w[0] * player->captured.h[0]);
\r
183 linear_uv_plane_size = (player->captured.w[0] * player->captured.h[0]/2);
\r
184 linear_y_plane = (unsigned char*) g_try_malloc(linear_y_plane_size);
\r
186 if (linear_y_plane == NULL)
\r
188 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
191 linear_uv_plane = (unsigned char*) g_try_malloc(linear_uv_plane_size);
\r
193 if (linear_uv_plane == NULL)
\r
195 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
198 /* NV12 tiled to linear */
\r
199 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
200 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
202 MMPLAYER_FREEIF(player->captured.a[0]);
\r
203 MMPLAYER_FREEIF(player->captured.a[1]);
\r
205 src_buffer = (unsigned char*) g_try_malloc(linear_y_plane_size+linear_uv_plane_size);
\r
207 if (src_buffer == NULL)
\r
209 msg.code = MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
212 memset(src_buffer, 0x00, sizeof(linear_y_plane_size+linear_uv_plane_size));
\r
213 memcpy(src_buffer, linear_y_plane, linear_y_plane_size);
\r
214 memcpy(src_buffer+linear_y_plane_size, linear_uv_plane, linear_uv_plane_size);
\r
216 /* NV12 linear to RGB888 */
\r
217 ret = __mm_player_convert_colorspace(player, src_buffer, MM_UTIL_IMG_FMT_NV12,
\r
218 player->captured.w[0], player->captured.h[0], MM_UTIL_IMG_FMT_RGB888);
\r
220 if (ret != MM_ERROR_NONE)
\r
222 debug_error("failed to convert nv12 linear\n");
\r
226 MMPLAYER_FREEIF(src_buffer);
\r
227 MMPLAYER_FREEIF(linear_y_plane);
\r
228 MMPLAYER_FREEIF(linear_uv_plane);
\r
231 player->capture.fmt = MM_PLAYER_COLORSPACE_RGB888;
\r
232 msg.data = &player->capture;
\r
233 msg.size = player->capture.size;
\r
235 MMPLAYER_POST_MSG( player, MM_MESSAGE_VIDEO_CAPTURED, &msg );
\r
236 g_mutex_unlock(player->capture_thread_mutex);
\r
238 //MMPLAYER_FREEIF(player->capture.data);
\r
241 if (player->video_cs == MM_PLAYER_COLORSPACE_NV12_TILED)
\r
244 MMPLAYER_FREEIF(linear_y_plane);
\r
245 MMPLAYER_FREEIF(linear_uv_plane);
\r
246 MMPLAYER_FREEIF(player->captured.a[0]);
\r
247 MMPLAYER_FREEIF(player->captured.a[1]);
\r
250 msg.union_type = MM_MSG_UNION_CODE;
\r
252 MMPLAYER_POST_MSG( player, MM_MESSAGE_VIDEO_NOT_CAPTURED, &msg );
\r
253 g_mutex_unlock(player->capture_thread_mutex);
\r
257 g_mutex_unlock(player->capture_thread_mutex);
\r
263 _mmplayer_do_video_capture(MMHandleType hplayer)
\r
265 mm_player_t* player = (mm_player_t*) hplayer;
\r
266 int ret = MM_ERROR_NONE;
\r
267 GstPad *pad = NULL;
\r
271 return_val_if_fail(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
\r
273 /* capturing or not */
\r
274 if (player->video_capture_cb_probe_id || player->capture.data || player->captured.a[0] || player->captured.a[1])
\r
276 debug_warning("capturing... we can't do any more\n");
\r
277 return MM_ERROR_PLAYER_INVALID_STATE;
\r
280 /* check if video pipeline is linked or not */
\r
281 if (!player->pipeline->videobin || !player->sent_bos)
\r
283 debug_warning("not ready to capture\n");
\r
284 return MM_ERROR_PLAYER_INVALID_STATE;
\r
287 if (player->state != MM_PLAYER_STATE_PLAYING)
\r
289 if (player->state == MM_PLAYER_STATE_PAUSED) // get last buffer from video sink
\r
291 GstBuffer *buf = NULL;
\r
292 g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "last-buffer", &buf, NULL);
\r
296 ret = __mmplayer_get_video_frame_from_buffer(player, buf);
\r
297 gst_buffer_unref(buf);
\r
303 debug_warning("invalid state(%d) to capture.\n", player->state);
\r
304 return MM_ERROR_PLAYER_INVALID_STATE;
\r
308 pad = gst_element_get_static_pad(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "sink" );
\r
310 /* register probe */
\r
311 player->video_capture_cb_probe_id = gst_pad_add_buffer_probe (pad,
\r
312 G_CALLBACK (__mmplayer_video_capture_probe), player);
\r
314 gst_object_unref(GST_OBJECT(pad));
\r
323 * The output is fixed as RGB888
\r
326 __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstBuffer *buffer)
\r
328 gint yplane_size = 0;
\r
329 gint uvplane_size = 0;
\r
330 gint src_width = 0;
\r
331 gint src_height = 0;
\r
332 guint32 fourcc = 0;
\r
333 GstCaps *caps = NULL;
\r
334 GstStructure *structure = NULL;
\r
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_BUFFER_CAPS(buffer);
\r
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-yuv"))
\r
362 gst_structure_get_fourcc (structure, "format", &fourcc);
\r
367 case GST_MAKE_FOURCC ('S', 'T', '1', '2'):
\r
369 debug_msg ("captured format is ST12\n");
\r
371 MMPlayerMPlaneImage *proved = NULL;
\r
372 player->video_cs = MM_PLAYER_COLORSPACE_NV12_TILED;
\r
374 /* get video frame info from proved buffer */
\r
375 proved = (MMPlayerMPlaneImage *)GST_BUFFER_MALLOCDATA(buffer);
\r
377 if ( !proved || !proved->a[0] || !proved->a[1] )
\r
378 return MM_ERROR_PLAYER_INTERNAL;
\r
380 yplane_size = (proved->s[0] * proved->e[0]);
\r
381 uvplane_size = (proved->s[1] * proved->e[1]);
\r
383 memset(&player->captured, 0x00, sizeof(MMPlayerMPlaneImage));
\r
384 memcpy(&player->captured, proved, sizeof(MMPlayerMPlaneImage));
\r
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 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
\r
402 src_fmt = MM_UTIL_IMG_FMT_I420;
\r
413 else if (gst_structure_has_name(structure, "video/x-raw-rgb"))
\r
419 gboolean bigendian = FALSE;
\r
420 gboolean isbluefirst = FALSE;
\r
423 * The followings will be considered.
\r
424 * RGBx, xRGB, BGRx, xBGR
\r
429 gst_structure_get_int (structure, "bpp", &bpp);
\r
430 gst_structure_get_int (structure, "depth", &depth);
\r
431 gst_structure_get_int (structure, "endianness", &endianess);
\r
432 gst_structure_get_int (structure, "blue_mask", &blue_mask);
\r
434 if (endianess == 4321)
\r
437 if (blue_mask == -16777216)
\r
438 isbluefirst = TRUE;
\r
447 if (bigendian && isbluefirst)
\r
448 src_fmt = MM_UTIL_IMG_FMT_BGRX8888;
\r
469 __mm_player_convert_colorspace(player, GST_BUFFER_DATA(buffer), src_fmt, src_width, src_height, dst_fmt);
\r
472 /* do convert colorspace */
\r
473 g_cond_signal( player->capture_thread_cond );
\r
477 return MM_ERROR_NONE;
\r
480 debug_error("unknown format to capture\n");
\r
481 return MM_ERROR_PLAYER_INTERNAL;
\r
485 __mmplayer_video_capture_probe (GstPad *pad, GstBuffer *buffer, gpointer u_data)
\r
487 mm_player_t* player = (mm_player_t*) u_data;
\r
488 int ret = MM_ERROR_NONE;
\r
490 return_val_if_fail ( buffer, FALSE);
\r
493 ret = __mmplayer_get_video_frame_from_buffer(player, buffer);
\r
495 if ( ret != MM_ERROR_NONE)
\r
497 debug_error("faild to get video frame. %x\n", ret);
\r
501 /* remove probe to be called at one time */
\r
502 if (player->video_capture_cb_probe_id)
\r
504 gst_pad_remove_buffer_probe (pad, player->video_capture_cb_probe_id);
\r
505 player->video_capture_cb_probe_id = 0;
\r
514 __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
516 unsigned char *dst_data = NULL;
\r
517 unsigned int dst_size;
\r
518 int ret = MM_ERROR_NONE;
\r
520 return_val_if_fail(player, MM_ERROR_PLAYER_INTERNAL);
\r
521 ret = mm_util_get_image_size(dst_fmt, src_w, src_h, &dst_size);
\r
523 if (ret != MM_ERROR_NONE)
\r
525 debug_error("failed to get image size for capture, %d\n", ret);
\r
526 return MM_ERROR_PLAYER_INTERNAL;
\r
529 debug_log("width: %d, height: %d to capture, dest size: %d\n", src_w, src_h, dst_size);
\r
531 dst_data = (unsigned char*)g_malloc0(dst_size);
\r
535 debug_error("no free space to capture\n");
\r
536 return MM_ERROR_PLAYER_NO_FREE_SPACE;
\r
539 ret = mm_util_convert_colorspace(src_data, src_w, src_h, src_fmt, dst_data, dst_fmt);
\r
541 if (ret != MM_ERROR_NONE)
\r
543 debug_error("failed to convert for capture, %d\n", ret);
\r
544 return MM_ERROR_PLAYER_INTERNAL;
\r
547 player->capture.size = dst_size;
\r
548 player->capture.data = dst_data;
\r
550 return MM_ERROR_NONE;
\r
554 * Get tiled address of position(x,y)
\r
557 * width of tiled[in]
\r
560 * height of tiled[in]
\r
563 * x position of tield[in]
\r
566 * y position of tield[in]
\r
569 * address of tiled data
\r
572 tile_4x2_read(int x_size, int y_size, int x_pos, int y_pos)
\r
574 int pixel_x_m1, pixel_y_m1;
\r
575 int roundup_x, roundup_y;
\r
576 int linear_addr0, linear_addr1, bank_addr ;
\r
580 pixel_x_m1 = x_size -1;
\r
581 pixel_y_m1 = y_size -1;
\r
583 roundup_x = ((pixel_x_m1 >> 7) + 1);
\r
584 roundup_y = ((pixel_x_m1 >> 6) + 1);
\r
586 x_addr = x_pos >> 2;
\r
588 if ((y_size <= y_pos+32) && ( y_pos < y_size) &&
\r
589 (((pixel_y_m1 >> 5) & 0x1) == 0) && (((y_pos >> 5) & 0x1) == 0)) {
\r
590 linear_addr0 = (((y_pos & 0x1f) <<4) | (x_addr & 0xf));
\r
591 linear_addr1 = (((y_pos >> 6) & 0xff) * roundup_x + ((x_addr >> 6) & 0x3f));
\r
593 if (((x_addr >> 5) & 0x1) == ((y_pos >> 5) & 0x1))
\r
594 bank_addr = ((x_addr >> 4) & 0x1);
\r
596 bank_addr = 0x2 | ((x_addr >> 4) & 0x1);
\r
598 linear_addr0 = (((y_pos & 0x1f) << 4) | (x_addr & 0xf));
\r
599 linear_addr1 = (((y_pos >> 6) & 0xff) * roundup_x + ((x_addr >> 5) & 0x7f));
\r
601 if (((x_addr >> 5) & 0x1) == ((y_pos >> 5) & 0x1))
\r
602 bank_addr = ((x_addr >> 4) & 0x1);
\r
604 bank_addr = 0x2 | ((x_addr >> 4) & 0x1);
\r
607 linear_addr0 = linear_addr0 << 2;
\r
608 trans_addr = (linear_addr1 <<13) | (bank_addr << 11) | linear_addr0;
\r
614 * Converts tiled data to linear
\r
615 * Crops left, top, right, buttom
\r
616 * 1. Y of NV12T to Y of YUV420P
\r
617 * 2. Y of NV12T to Y of YUV420S
\r
618 * 3. UV of NV12T to UV of YUV420S
\r
620 * @param yuv420_dest
\r
621 * Y or UV plane address of YUV420[out]
\r
624 * Y or UV plane address of NV12T[in]
\r
626 * @param yuv420_width
\r
627 * Width of YUV420[in]
\r
629 * @param yuv420_height
\r
630 * Y: Height of YUV420, UV: Height/2 of YUV420[in]
\r
633 * Crop size of left
\r
639 * Crop size of right
\r
642 * Crop size of buttom
\r
645 csc_tiled_to_linear_crop(unsigned char *yuv420_dest, unsigned char *nv12t_src, int yuv420_width, int yuv420_height,
\r
646 int left, int top, int right, int buttom)
\r
649 int tiled_offset = 0, tiled_offset1 = 0;
\r
650 int linear_offset = 0;
\r
651 int temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0;
\r
653 temp3 = yuv420_width-right;
\r
654 temp1 = temp3-left;
\r
655 /* real width is greater than or equal 256 */
\r
656 if (temp1 >= 256) {
\r
657 for (i=top; i<yuv420_height-buttom; i=i+1) {
\r
663 /* odd fomula: 2+x+(x>>2)<<2+x_block_num*(y-1) */
\r
664 tiled_offset = temp4-1;
\r
665 temp1 = ((yuv420_width+127)>>7)<<7;
\r
666 tiled_offset = tiled_offset*(temp1>>6);
\r
667 tiled_offset = tiled_offset+temp3;
\r
668 tiled_offset = tiled_offset+2;
\r
669 temp1 = (temp3>>2)<<2;
\r
670 tiled_offset = tiled_offset+temp1;
\r
671 tiled_offset = tiled_offset<<11;
\r
672 tiled_offset1 = tiled_offset+2048*2;
\r
675 temp2 = ((yuv420_height+31)>>5)<<5;
\r
676 if ((i+32)<temp2) {
\r
677 /* even1 fomula: x+((x+2)>>2)<<2+x_block_num*y */
\r
679 temp1 = (temp1>>2)<<2;
\r
680 tiled_offset = temp3+temp1;
\r
681 temp1 = ((yuv420_width+127)>>7)<<7;
\r
682 tiled_offset = tiled_offset+temp4*(temp1>>6);
\r
683 tiled_offset = tiled_offset<<11;
\r
684 tiled_offset1 = tiled_offset+2048*6;
\r
687 /* even2 fomula: x+x_block_num*y */
\r
688 temp1 = ((yuv420_width+127)>>7)<<7;
\r
689 tiled_offset = temp4*(temp1>>6);
\r
690 tiled_offset = tiled_offset+temp3;
\r
691 tiled_offset = tiled_offset<<11;
\r
692 tiled_offset1 = tiled_offset+2048*2;
\r
698 tiled_offset = tiled_offset+64*(temp1);
\r
699 tiled_offset1 = tiled_offset1+64*(temp1);
\r
700 temp2 = yuv420_width-left-right;
\r
701 linear_offset = temp2*(i-top);
\r
702 temp3 = ((j+256)>>8)<<8;
\r
706 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset+temp1, 64-temp1);
\r
707 temp2 = ((left+63)>>6)<<6;
\r
708 temp3 = ((yuv420_width-right)>>6)<<6;
\r
709 if (temp2 == temp3) {
\r
710 temp2 = yuv420_width-right-(64-temp1);
\r
712 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset+2048, 64);
\r
713 memcpy(yuv420_dest+linear_offset+128-temp1, nv12t_src+tiled_offset1, 64);
\r
714 memcpy(yuv420_dest+linear_offset+192-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
715 linear_offset = linear_offset+256-temp1;
\r
716 } else if (temp3 > 128) {
\r
717 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset+2048+temp1, 64-temp1);
\r
718 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset1, 64);
\r
719 memcpy(yuv420_dest+linear_offset+128-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
720 linear_offset = linear_offset+192-temp1;
\r
721 } else if (temp3 > 64) {
\r
722 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset1+temp1, 64-temp1);
\r
723 memcpy(yuv420_dest+linear_offset+64-temp1, nv12t_src+tiled_offset1+2048, 64);
\r
724 linear_offset = linear_offset+128-temp1;
\r
725 } else if (temp3 > 0) {
\r
726 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset1+2048+temp1, 64-temp1);
\r
727 linear_offset = linear_offset+64-temp1;
\r
730 tiled_offset = tiled_offset+temp4*2048;
\r
733 temp2 = yuv420_width-right-256;
\r
734 for (; j<=temp2; j=j+256) {
\r
735 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
736 tiled_offset1 = tiled_offset1+temp4*2048;
\r
737 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
738 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, 64);
\r
739 tiled_offset = tiled_offset+temp4*2048;
\r
740 memcpy(yuv420_dest+linear_offset+192, nv12t_src+tiled_offset1+2048, 64);
\r
741 linear_offset = linear_offset+256;
\r
744 tiled_offset1 = tiled_offset1+temp4*2048;
\r
745 temp2 = yuv420_width-right-j;
\r
747 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
748 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
749 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, 64);
\r
750 memcpy(yuv420_dest+linear_offset+192, nv12t_src+tiled_offset1+2048, temp2-192);
\r
751 } else if (temp2 > 128) {
\r
752 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
753 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, 64);
\r
754 memcpy(yuv420_dest+linear_offset+128, nv12t_src+tiled_offset1, temp2-128);
\r
755 } else if (temp2 > 64) {
\r
756 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
757 memcpy(yuv420_dest+linear_offset+64, nv12t_src+tiled_offset+2048, temp2-64);
\r
759 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
762 } else if (temp1 >= 64) {
\r
763 for (i=top; i<(yuv420_height-buttom); i=i+1) {
\r
765 tiled_offset = tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
766 temp2 = ((j+64)>>6)<<6;
\r
768 linear_offset = temp1*(i-top);
\r
770 tiled_offset = tiled_offset+temp4;
\r
771 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
772 linear_offset = linear_offset+temp2;
\r
774 if ((j+64) <= temp3) {
\r
775 tiled_offset = tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
776 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
777 linear_offset = linear_offset+64;
\r
780 if ((j+64) <= temp3) {
\r
781 tiled_offset = tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
782 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 64);
\r
783 linear_offset = linear_offset+64;
\r
787 tiled_offset = tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
789 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, temp2);
\r
793 for (i=top; i<(yuv420_height-buttom); i=i+1) {
\r
794 linear_offset = temp1*(i-top);
\r
795 for (j=left; j<(yuv420_width-right); j=j+2) {
\r
796 tiled_offset = tile_4x2_read(yuv420_width, yuv420_height, j, i);
\r
798 tiled_offset = tiled_offset+temp4;
\r
799 memcpy(yuv420_dest+linear_offset, nv12t_src+tiled_offset, 2);
\r
800 linear_offset = linear_offset+2;
\r