Fix relative include paths
[libvpx.git] / vp8 / decoder / x86 / onyxdxv.c
blobed38e2b9a8afbe4e7db1c21c743ff70fa7c0783d
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 /****************************************************************************
14 * Module Title : onyxdxv.c
16 * Description : VP80 interface to DXV.
18 *****************************************************************************
20 /****************************************************************************
21 * Header Files
22 ****************************************************************************/
23 #include <math.h> // For Abs()
24 #include "vp8/common/pragmas.h"
26 #include "vpxdxv.h"
27 #include "vpxdxv_plugin.h"
29 #include "vp8/decoder/onyxd_int.h"
30 #include "vp8/common/onyx.h"
31 #include "vp8/common/codec_common_interface.h"
32 #include "vpx_scale/vpxscale.h"
33 #include "vpx_mem/vpx_mem.h"
34 #include "vp8/common/postproc.h"
35 #include "vp8/common/vpxblit.h"
36 #include "vp8/common/g_common.h"
37 #include "vpx_scale/yv12extend.h"
39 #include <limits.h>
40 #include <stdio.h>
41 #include "scale_mode.h"
42 #include "onyx_pb_interface.h"
44 /****************************************************************************
45 * Macros
46 ****************************************************************************/
48 #define VP8_FOURCC DXL_MKFOURCC( 'V', 'P', '8', '0')
50 extern void vp8_blit_text(const char *msg, unsigned char *address, const int pitch);
53 /****************************************************************************
54 * Typedefs
55 ****************************************************************************/
57 typedef struct // YUV buffer configuration structure
59 int y_width;
60 int y_height;
61 int y_stride;
63 int uv_width;
64 int uv_height;
65 int uv_stride;
67 char *y_buffer;
68 char *u_buffer;
69 char *v_buffer;
71 char *uv_start;
72 int uv_dst_area;
73 int uv_used_area;
75 unsigned char *y_ptr_scrn;
76 unsigned char *u_ptr_scrn;
77 unsigned char *v_ptr_scrn;
80 } DXV_YUV_BUFFER_CONFIG;
83 typedef void ((*vp8blit_func)(unsigned char *, int, YUV_BUFFER_CONFIG *));
85 /* define an x_image structure based on the core x_image struct */
86 typedef struct t_ximage_codec
88 DXV_YUV_BUFFER_CONFIG frame_buffer;
89 VP8D_COMP *my_pbi;
90 VP8_COMMON *common;
91 int owned;
92 int decompressed_once;
94 int sizeof_pixel;
95 vp8blit_func blitter;
97 unsigned int ppl_tag;
98 unsigned int bd_tag;
99 unsigned int *supported_output_format_list;
101 int cpu_free;
102 int postproc;
103 int add_noise;
104 int deinterlace;
106 int post_proc2time;
107 int post_proc4time;
109 int hs;
110 int hr;
111 int vs;
112 int vr;
113 YV12_BUFFER_CONFIG this_buffer;
114 YV12_BUFFER_CONFIG scaled_buffer;
115 YV12_BUFFER_CONFIG *passed_in_buffer;
117 int avgq;
118 int ppcount;
121 } VP8_XIMAGE, *VP8_XIMAGE_HANDLE;
124 /****************************************************************************
125 * Modul Statics
126 ****************************************************************************/
127 static unsigned int g_vp8_preferred_output_format_list[] =
129 VPXDXV_YUY2,
130 VPXDXV_UYVY,
131 VPXDXV_RGB8888,
132 VPXDXV_RGB888,
133 VPXDXV_RGB555,
134 VPXDXV_RGB565,
135 VPXDXV_YV12,
136 VPXDXV_I420,
138 // VPXDXV_YV12,
139 // VPXDXV_YUY2,
140 // VPXDXV_RGB565,
141 // VPXDXV_UYVY,
145 /****************************************************************************
146 * Forward declarationss
147 ****************************************************************************/
148 void onyx_set_parameter(XIMAGE_HANDLE src, int Command, unsigned int Parameter);
150 static int onyx_get_output_format(XIMAGE_HANDLE src, unsigned int *bd_tag);
151 static int onyx_set_output_format(XIMAGE_HANDLE src, unsigned int bd_tag);
153 static int vpx_get_size_of_pixel(unsigned int bd);
155 /****************************************************************************
156 * Imports
157 ****************************************************************************/
159 #define __Clamp255(x) (unsigned char) ( (x) < 0 ? 0 : ( (x) <= 255 ? (x) : 255 ) )
162 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169 void
170 convert_yv12_buffer_types(YV12_BUFFER_CONFIG *source, DXV_YUV_BUFFER_CONFIG *dest)
172 dest->y_buffer = (char *)source->y_buffer;
173 dest->u_buffer = (char *)source->u_buffer;
174 dest->v_buffer = (char *)source->v_buffer;
175 dest->y_width = source->y_width;
176 dest->y_height = source->y_height;
177 dest->y_stride = source->y_stride;
178 dest->uv_width = source->uv_width;
179 dest->uv_height = source->uv_height;
180 dest->uv_stride = source->uv_stride;
184 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189 int onyx_blit
191 XIMAGE_HANDLE src,
192 VSCREEN_HANDLE v_screen,
193 DXV_YUV_BUFFER_CONFIG *frame_buffer,
194 int x,
195 int y
198 VP8_XIMAGE_HANDLE tab = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
199 VP8D_COMP *pbi;
200 VP8_COMMON *common = tab->common;
201 pbi = tab->my_pbi;
203 if (v_screen) /* if there is a v_screen, blit to it */
205 unsigned char *ptr_scrn;
206 int this_pitch, vs_height, vs_width;
207 unsigned int start_tick, stop_tick;
209 vpxdxv_get_vscreen_attributes(v_screen, (void **)&ptr_scrn, &vs_width, &vs_height, &this_pitch);
211 if (ptr_scrn)
213 int w, h;
215 int p_size;
216 int view_x, view_y, view_w;
217 int hs, hr, vs, vr;
218 int neww, newh;
219 int cw, ch;
220 int microseconds_available = (int)(1000000 / 30);
222 microseconds_available = microseconds_available * tab->cpu_free / 100;
224 if (pbi)
226 microseconds_available -= pbi->decode_microseconds;
228 if (tab->cpu_free == 0)
229 microseconds_available = INT_MAX;
231 if (tab->post_proc2time == 0)
232 tab->post_proc2time = pbi->decode_microseconds * 1 / 2;
234 if (tab->post_proc4time == 0)
235 tab->post_proc4time = pbi->decode_microseconds;
239 if (tab->ppcount == 0)
241 tab->post_proc2time = 0;
242 tab->post_proc4time = 0;
243 tab->ppcount = 64;
245 else
247 tab->ppcount --;
250 vpxdxv_get_vscreen_view(v_screen, &view_x, &view_y, &view_w, NULL);
252 Scale2Ratio(common->horiz_scale, &hr, &hs);
253 Scale2Ratio(common->vert_scale, &vr, &vs);
255 if (tab->postproc && tab->passed_in_buffer == 0)
257 int show_text = 0;
259 unsigned char message[512];
261 int pp = tab->postproc;
262 int q = (tab->avgq + 4) / 8;
263 int noise = 0;
265 vp8_clear_system_state();
267 if (pp >= 1000)
269 pp -= 1000;
270 noise = pp / 100;
271 pp = pp - noise * 100;
274 if (pp >= 300)
276 pp -= 300;
277 show_text = 3;
279 else if (pp >= 200)
281 pp -= 200;
282 show_text = 2;
284 else if (pp >= 100)
286 pp -= 100;
287 show_text = 1;
290 if (pbi && (pbi->mb.segmentation_enabled & SEGMENT_PF) && tab->deinterlace)
292 de_interlace(common->frame_to_show->y_buffer, common->post_proc_buffer.y_buffer,
293 common->post_proc_buffer.y_width, common->post_proc_buffer.y_height,
294 common->post_proc_buffer.y_stride);
296 de_interlace(common->frame_to_show->u_buffer, common->post_proc_buffer.u_buffer,
297 common->post_proc_buffer.uv_width, common->post_proc_buffer.uv_height,
298 common->post_proc_buffer.uv_stride);
299 de_interlace(common->frame_to_show->v_buffer, common->post_proc_buffer.v_buffer,
300 common->post_proc_buffer.uv_width, common->post_proc_buffer.uv_height,
301 common->post_proc_buffer.uv_stride);
303 else
305 if (pp >= 10 && pp <= 20)
307 q = q + (pp - 15) * 10;
309 if (q < 0)
310 q = 0;
313 start_tick = vp8_get_high_res_timer_tick();
315 if (pp > 3 && tab->post_proc4time < microseconds_available)
317 vp8_deblock_and_de_macro_block(common->frame_to_show, &common->post_proc_buffer, q, 1, 0);
319 stop_tick = vp8_get_high_res_timer_tick();
321 if (pbi)
322 tab->post_proc4time = vp8_get_time_in_micro_sec(start_tick, stop_tick);
325 else if (pp > 0 && tab->post_proc2time < microseconds_available)
327 vp8_deblock(common->frame_to_show, &common->post_proc_buffer, q , 1, 0);
328 stop_tick = vp8_get_high_res_timer_tick();
330 if (pbi)
331 tab->post_proc2time = vp8_get_time_in_micro_sec(start_tick, stop_tick);
333 else
335 vp8_yv12_copy_frame(common->frame_to_show, &common->post_proc_buffer);
340 vp8_clear_system_state();
342 if (tab->add_noise == 1)
345 vp8_plane_add_noise(common->post_proc_buffer.y_buffer,
346 common->post_proc_buffer.y_width, common->post_proc_buffer.y_height,
347 common->post_proc_buffer.y_stride, 63 - q, noise);
351 if (show_text == 1)
353 #ifdef PACKET_TESTING
355 VP8_HEADER *oh2 = (VP8_HEADER *) pbi->Source;
356 sprintf(message, "%8d %d%d%d%d%d size:%d\n",
357 oh2->frame_number ,
358 oh2->update_gold ,
359 oh2->update_last ,
360 oh2->uses_gold ,
361 oh2->uses_last ,
362 oh2->type,
363 vpxdxv_get_ximage_csize(src));
365 #else
366 sprintf(message, "F:%1ldG:%1ldQ:%3ldF:%3ld,%3ldP:%d_s:%6ld,N:%d,",
367 (common->frame_type == KEY_FRAME),
368 common->refresh_golden_frame,
369 common->base_qindex,
370 common->filter_level,
372 tab->postproc,
373 vpxdxv_get_ximage_csize(src), noise);
374 #endif
376 vp8_blit_text(message, common->post_proc_buffer.y_buffer, common->post_proc_buffer.y_stride);
379 else if (show_text == 2)
381 int i, j;
382 unsigned char *y_ptr;
383 YV12_BUFFER_CONFIG *post = &common->post_proc_buffer;
384 int mb_rows = post->y_height >> 4;
385 int mb_cols = post->y_width >> 4;
386 int mb_index = 0;
387 MODE_INFO *mi = common->mi;
389 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
391 // vp8_filter each macro block
392 for (i = 0; i < mb_rows; i++)
394 for (j = 0; j < mb_cols; j++)
396 char zz[4];
398 if (pp == 4)
399 sprintf(zz, "%c", mi[mb_index].mbmi.mode + 'a');
400 else
401 sprintf(zz, "%c", mi[mb_index].mbmi.ref_frame + 'a');
403 vp8_blit_text(zz, y_ptr, post->y_stride);
404 mb_index ++;
405 y_ptr += 16;
408 mb_index ++; //border
409 y_ptr += post->y_stride * 16 - post->y_width;
413 else if (show_text == 3)
415 int i, j;
416 unsigned char *y_ptr;
417 YV12_BUFFER_CONFIG *post = &common->post_proc_buffer;
418 int mb_rows = post->y_height >> 4;
419 int mb_cols = post->y_width >> 4;
420 int mb_index = 0;
421 MODE_INFO *mi = common->mi;
423 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
425 // vp8_filter each macro block
426 for (i = 0; i < mb_rows; i++)
428 for (j = 0; j < mb_cols; j++)
430 char zz[4];
432 if (j == 0)
433 sprintf(zz, "%c", '0' + i % 10);
434 else
435 sprintf(zz, "%c", '0' + j % 10);
437 vp8_blit_text(zz, y_ptr, post->y_stride);
438 mb_index ++;
439 y_ptr += 16;
442 y_ptr += post->y_stride * 16 - post->y_width;
447 vpx_memcpy(&tab->this_buffer, &common->post_proc_buffer, sizeof(YV12_BUFFER_CONFIG));
449 else
451 vpx_memcpy(&tab->this_buffer, common->frame_to_show, sizeof(YV12_BUFFER_CONFIG));
455 /* get a frame pointer to the scaled and postprocessed reconstructed buffer */
456 if (tab->passed_in_buffer == 0)
458 if (common->horiz_scale != NORMAL || common->vert_scale != NORMAL)
460 neww = hs * tab->this_buffer.y_width / hr;
461 newh = vs * tab->this_buffer.y_height / vr;
463 neww += neww & 1;
465 if (tab->hs != hs || tab->hr != hr || tab->vs != vs || tab->vr != vr)
467 vp8_yv12_alloc_frame_buffer(&tab->scaled_buffer, neww, newh , 8);
470 vp8_yv12_scale_or_center(&tab->this_buffer,
471 &tab->scaled_buffer,
472 neww, newh, SCALE_TO_FIT, hs, hr, vs, vr);
474 convert_yv12_buffer_types(&tab->scaled_buffer, frame_buffer);
476 cw = hs * common->Width / hr;
477 ch = vs * common->Height / vr;
480 else
482 convert_yv12_buffer_types(&tab->this_buffer, frame_buffer);
484 cw = common->Width;
485 ch = common->Height;
488 else
490 convert_yv12_buffer_types(tab->passed_in_buffer, frame_buffer);
491 cw = common->Width;
492 ch = common->Height;
493 tab->passed_in_buffer = 0;
496 frame_buffer->y_width = cw;
497 frame_buffer->y_height = ch;
498 frame_buffer->uv_width = cw / 2;
499 frame_buffer->uv_height = ch / 2;
501 p_size = vpx_get_size_of_pixel(tab->bd_tag);
503 /* remember to offset if requested */
504 y += view_y;
505 x += view_x ;
507 /* for planar destinations */
508 w = view_w;
509 h = vs_height;
511 if (w < frame_buffer->y_width)
513 frame_buffer->y_width = w;
514 frame_buffer->uv_width = (w + 1) / 2;
517 if (h < frame_buffer->y_height)
519 frame_buffer->y_height = h;
520 frame_buffer->uv_height = (h + 1) / 2;
523 if (frame_buffer->y_width < view_w)
524 x += (view_w - frame_buffer->y_width) / 2;
526 if (x & 1)
527 x -= 1;
529 if (frame_buffer->y_height < vs_height)
530 y += (vs_height - frame_buffer->y_height) / 2;
533 ptr_scrn += (x * p_size) + (y * this_pitch);
535 frame_buffer->y_stride *= -1;
536 frame_buffer->uv_stride *= -1;
538 if (tab->bd_tag == VPXDXV_YV12 || tab->bd_tag == VPXDXV_I420)
540 if (this_pitch < 0)
542 frame_buffer->uv_start = (char *)(ptr_scrn + abs(this_pitch) + abs(this_pitch) * h / 4 + this_pitch / 2);
543 frame_buffer->uv_dst_area = abs((this_pitch * h) / 4);
544 frame_buffer->uv_used_area = 0;
546 else
548 frame_buffer->uv_start = (char *)(ptr_scrn + (this_pitch * h));
549 frame_buffer->uv_dst_area = (((this_pitch + 1) / 2) * ((h + 1) / 2));
550 frame_buffer->uv_used_area = (((this_pitch + 1) / 2) * frame_buffer->uv_height);
554 if ((pbi->mb.segmentation_enabled & SEGMENT_PF) && (tab->bd_tag != VPXDXV_YV12 && tab->bd_tag != VPXDXV_I420))
556 int ypitch = frame_buffer->y_stride;
557 int uvpitch = frame_buffer->uv_stride;
559 frame_buffer->y_stride <<= 1;
560 frame_buffer->y_height >>= 1;
561 frame_buffer->uv_stride <<= 1;
562 frame_buffer->uv_height >>= 1;
564 ptr_scrn += this_pitch;
565 frame_buffer->y_buffer -= ypitch;
566 frame_buffer->u_buffer -= uvpitch;
567 frame_buffer->v_buffer -= uvpitch;
568 tab->blitter(ptr_scrn, 2 * this_pitch, (YUV_BUFFER_CONFIG *)(&tab->frame_buffer));
570 ptr_scrn -= this_pitch;
571 frame_buffer->y_buffer += ypitch;
572 frame_buffer->u_buffer += uvpitch;
573 frame_buffer->v_buffer += uvpitch;
574 tab->blitter(ptr_scrn, 2 * this_pitch, (YUV_BUFFER_CONFIG *)(&tab->frame_buffer));
577 else
579 /* blit the screen */
580 tab->blitter(ptr_scrn, this_pitch, (YUV_BUFFER_CONFIG *)(&tab->frame_buffer));
581 vpx_log("Decoder: Frame shown \n");
585 else
586 vpx_log("Decoder: Frame not shown scrn pointer 0\n");
588 else
589 vpx_log("Decoder: Frame not shown vscreen 0\n");
591 return DXV_OK;
593 /****************************************************************************
595 * ROUTINE : onyx_decompress
597 * INPUTS : None
599 * OUTPUTS : None
601 * RETURNS : None.
603 * FUNCTION :
605 * SPECIAL NOTES :
607 ****************************************************************************/
608 static
609 int onyx_decompress(XIMAGE_HANDLE src, VSCREEN_HANDLE v_screen)
611 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
612 unsigned char *c_addr;
613 unsigned int c_size;
614 int w, h, x, y;
615 int vp8_rv;
617 c_addr = vpxdxv_get_ximage_cdata_addr(src);
618 c_size = vpxdxv_get_ximage_csize(src);
619 vpxdxv_get_ximage_xywh(src, &x, &y, &w, &h);
621 // if we have a compressed frame decompress it ( otherwise we'll just redo
622 // the scaling and postprocessing from the last frame )
623 if (c_addr)
625 if (c_size != 0)
627 int flags;
628 int ret_val;
630 int f;
632 // decode the frame
633 ret_val = vp8d_decompress_frame((VP8D_PTR) this_algorithm_base->my_pbi,
634 c_size,
635 (char *) c_addr,
636 &this_algorithm_base->this_buffer,
637 &flags);
640 f = this_algorithm_base->my_pbi->common.filter_level * 10 / 6;
642 if (this_algorithm_base->my_pbi->common.frame_type == KEY_FRAME)
643 this_algorithm_base->avgq = 8 * f;
644 else
645 this_algorithm_base->avgq = this_algorithm_base->avgq * 7 / 8 + f;
649 if (ret_val != 0)
651 if (ret_val == -1)
652 return DXV_VERSION_CONFLICT;
653 else
654 return DXV_BAD_DATA;
661 vp8_rv = onyx_blit(src, v_screen, &this_algorithm_base->frame_buffer, x, y);
664 return vp8_rv;
667 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
668 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
670 static
671 int vp8_ximagedestroy(XIMAGE_HANDLE src)
673 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
675 if (this_algorithm_base)
678 vp8_yv12_de_alloc_frame_buffer(&this_algorithm_base->scaled_buffer);
680 /* safety check in case stopdecode was not called */
681 if (this_algorithm_base->owned)
682 vp8dx_remove_decompressor((VP8D_PTR)(this_algorithm_base->my_pbi));
684 duck_free(this_algorithm_base);
687 return DXV_OK;
690 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
693 static int
694 onyx_get_post_proc(XIMAGE_HANDLE src, unsigned int *ppl)
696 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
698 if (this_algorithm_base)
700 *ppl = this_algorithm_base->ppl_tag;
702 return DXV_OK;
705 return DXV_NULL_BASE;
708 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
709 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
711 static int
712 onyx_set_post_proc(XIMAGE_HANDLE src, unsigned int ppl)
714 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
716 if (this_algorithm_base)
718 this_algorithm_base->ppl_tag = ppl;
720 return DXV_OK;
723 return DXV_NULL_BASE;
726 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
729 static
730 int vp8_ximagestop_decode(XIMAGE_HANDLE src)
732 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
734 if (this_algorithm_base)
737 vp8_yv12_de_alloc_frame_buffer(&this_algorithm_base->scaled_buffer);
739 if (this_algorithm_base->owned)
740 vp8dx_remove_decompressor((VP8D_PTR)(this_algorithm_base->my_pbi));
742 this_algorithm_base->owned = 0;
745 return DXV_OK;
750 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
751 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
753 static
754 int vp8_ximagestart_decode
756 XIMAGE_HANDLE src
759 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
760 XIMAGE_INFO_PTR xinfo = vpxdxv_get_ximage_info(src);
761 VP8D_CONFIG ocf;
763 if (xinfo)
765 ocf.Width = xinfo->width;
766 ocf.Height = xinfo->height;
769 if (this_algorithm_base->common == 0)
771 this_algorithm_base->my_pbi = (VP8D_COMP *) vp8dx_create_decompressor(&ocf);
772 this_algorithm_base->owned = 1;
773 this_algorithm_base->common = &this_algorithm_base->my_pbi->common;
774 this_algorithm_base->avgq = 0;
778 this_algorithm_base->passed_in_buffer = 0;
779 this_algorithm_base->post_proc2time = 0;
780 this_algorithm_base->post_proc4time = 0;
781 this_algorithm_base->ppcount = 64;
783 return DXV_OK;
786 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
787 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
789 static
790 DXV_HANDLE vp8_ximagecreate(XIMAGE_HANDLE src)
792 VP8_XIMAGE_HANDLE this_algorithm_base;
794 /* create a new algorithm base container */
795 this_algorithm_base = (VP8_XIMAGE_HANDLE)duck_calloc(1, sizeof(VP8_XIMAGE), DMEM_GENERAL);
797 if (this_algorithm_base == NULL)
798 return NULL;
800 vp8_scale_machine_specific_config();
802 vpxdxv_register_ximage_start_decode(src, vp8_ximagestart_decode);
804 vpxdxv_register_ximage_stop_decode(src, vp8_ximagestop_decode);
806 vpxdxv_register_ximage_destroy(src, vp8_ximagedestroy);
808 vpxdxv_register_ximage_dx(src, onyx_decompress);
810 vpxdxv_register_ximage_set_parameter(src, onyx_set_parameter);
812 vpxdxv_register_ximage_output_format_func(src,
813 onyx_get_output_format,
814 onyx_set_output_format);
816 vpxdxv_register_ximage_post_proc_level_func(src,
817 onyx_get_post_proc,
818 onyx_set_post_proc);
820 return (DXV_HANDLE)this_algorithm_base;
824 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
825 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
828 static int store_output_list(unsigned int supported, int count,
829 unsigned int *outlist)
831 int i = 0, j = 0,
832 ret = DXV_OK;
834 while (i < count)
836 while (supported && !(supported & 0x01))
838 supported >>= 1;
839 ++j;
842 *(outlist + i) = g_vp8_preferred_output_format_list[j];
843 ++i;
844 ++j;
845 supported >>= 1;
849 return ret;
853 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
854 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
856 static int onyx_get_output_list(XIMAGE_INFO_PTR xinfo, unsigned int *outlist,
857 unsigned int *size)
859 int i,
860 ret = DXV_INVALID_REQUEST;
861 unsigned int supported = 0,
862 count = 0;
863 (void)xinfo;
865 if (size)
867 for (i = 0; i < sizeof(g_vp8_preferred_output_format_list) / sizeof(unsigned int) && i < 32; ++i)
869 if (vpx_get_blitter(g_vp8_preferred_output_format_list[i]) != (void *)0xffffffff)
871 supported |= (1 << i);
872 ++count;
876 if (outlist)
878 if (count && ((count + 1) == (*size / sizeof(int))))
879 ret = store_output_list(supported, count, outlist);
880 else
881 *outlist = 0;
883 else
885 *size = (count + 1) * sizeof(int);
886 ret = DXV_OK;
890 return ret;
894 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
895 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
897 int onyx_init(void)
899 int vp8_rv;
901 /* register VPX blitters based on cpu */
902 vpx_set_blit();
904 vp8_rv = vpxdxv_register_ximage(vp8_ximagecreate, onyx_get_output_list, VP8_FOURCC);
905 return vp8_rv;
907 return DXV_OK;
910 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
911 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
913 int onyx_exit(void)
916 vpxdxv_un_register_ximage(VP8_FOURCC);
918 return DXV_OK;
920 /****************************************************************************
922 * ROUTINE : onyx_set_parameter
924 * INPUTS : XIMAGE_HANDLE src :
925 * int Command :
926 * unsigned long Parameter :
928 * OUTPUTS : None.
930 * RETURNS : void
932 * FUNCTION :
935 * SPECIAL NOTES : None.
937 ****************************************************************************/
938 void onyx_set_parameter(XIMAGE_HANDLE src, int Command, unsigned int Parameter)
940 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
942 switch (Command)
944 case PBC_SET_CPUFREE:
945 this_algorithm_base->cpu_free = Parameter;
946 break;
947 case PBC_SET_POSTPROC:
948 this_algorithm_base->postproc = Parameter;
949 break;
951 case PBC_SET_BLITBUFF:
952 this_algorithm_base->passed_in_buffer = (YV12_BUFFER_CONFIG *) Parameter;
953 break;
955 case PBC_SET_REFERENCEFRAME:
957 VP8_XIMAGE_HANDLE tab = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
958 VP8D_COMP *pbi;
959 pbi = tab->my_pbi;
960 vp8_yv12_copy_frame((YV12_BUFFER_CONFIG *) Parameter, &pbi->common.last_frame);
962 break;
964 case PBC_SET_COMMON:
966 if (Parameter)
968 this_algorithm_base->common = (VP8_COMMON *)Parameter;
971 break;
972 case PBC_SET_ADDNOISE:
973 this_algorithm_base->add_noise = Parameter;
974 break;
975 case PBC_SET_DEINTERLACEMODE:
976 this_algorithm_base->deinterlace = Parameter;
977 break;
982 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
983 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
985 static int
986 onyx_get_output_format(XIMAGE_HANDLE src, unsigned int *format_tag)
988 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
990 if (this_algorithm_base)
992 *format_tag = this_algorithm_base->bd_tag;
993 return DXV_OK;
996 return DXV_NULL_BASE;
1000 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1001 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1003 static int
1004 onyx_set_output_format(XIMAGE_HANDLE src, unsigned int bd_tag)
1006 VP8_XIMAGE_HANDLE this_algorithm_base = (VP8_XIMAGE_HANDLE)vpxdxv_get_algorithm_base_ptr(src);
1007 int i;
1008 unsigned int bd_tag_found;
1010 if (this_algorithm_base)
1012 i = 0;
1013 bd_tag_found = 0;
1015 while (g_vp8_preferred_output_format_list[i] != 0)
1017 if (g_vp8_preferred_output_format_list[i] == bd_tag)
1019 bd_tag_found = 1;
1020 break;
1023 i++;
1026 if (bd_tag_found)
1028 this_algorithm_base->blitter = (vp8blit_func)vpx_get_blitter(bd_tag);
1029 this_algorithm_base->bd_tag = bd_tag;
1030 return DXV_OK;
1033 return DXV_INVALID_BLIT;
1036 return DXV_NULL_BASE;
1040 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1041 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1044 vpx_get_size_of_pixel(unsigned int bd)
1046 int vp8_rv;
1048 switch (bd)
1050 case VPXDXV_YV12:
1051 case VPXDXV_I420:
1052 vp8_rv = 1;
1053 break;
1055 #ifdef _ENABLE_SPLIT_PIXEL_
1056 case VPXDXV_SPLIT565:
1057 #endif
1058 case VPXDXV_RGB555:
1059 case VPXDXV_RGB565:
1060 case VPXDXV_YUY2:
1061 case VPXDXV_UYVY:
1062 case VPXDXV_YVYU:
1063 vp8_rv = 2;
1064 break;
1066 case VPXDXV_RGB888:
1067 vp8_rv = 3;
1068 break;
1070 case VPXDXV_RGB8888:
1071 vp8_rv = 4;
1072 break;
1074 default:
1075 vp8_rv = -1;
1076 break;
1079 return vp8_rv;