1 /*****************************************************************************
2 * vout.c: QNX RTOS video output display method
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 the VideoLAN team
6 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
7 * Pascal Levesque <Pascal.Levesque@mindready.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
29 #include <photon/PtWidget.h>
30 #include <photon/PtWindow.h>
31 #include <photon/PtLabel.h>
32 #include <photon/PdDirect.h>
38 #include <vlc_common.h>
39 #include <vlc_interface.h>
42 /*****************************************************************************
43 * vout_sys_t: video output QNX method descriptor
44 *****************************************************************************
45 * This structure is part of the video output thread descriptor.
46 * It describes the QNX specific properties of an output thread. QNX video
47 * output is performed through regular resizable windows. Windows can be
48 * dynamically resized to adapt to the size of the streams.
49 *****************************************************************************/
50 #define MAX_DIRECTBUFFERS 2
52 #define MODE_NORMAL_MEM 0
53 #define MODE_SHARED_MEM 1
54 #define MODE_VIDEO_MEM 2
55 #define MODE_VIDEO_OVERLAY 3
63 PtWidget_t * p_window;
65 /* Color palette for 8bpp */
66 PgColor_t p_colors[255];
68 /* [shared] memory blit */
71 /* video memory blit */
74 PgVideoChannel_t * p_channel;
79 int i_bytes_per_pixel;
82 /* position & dimensions */
92 /*****************************************************************************
93 * picture_sys_t: direct buffer method descriptor
94 *****************************************************************************
95 * This structure is part of the picture descriptor, it describes the
96 * XVideo specific properties of a direct buffer.
97 *****************************************************************************/
100 /* [shared] memory blit */
103 /* video memory blit and video overlay */
104 PdOffscreenContext_t * p_ctx[3]; /* 0: y, 1: u, 2: v */
109 /*****************************************************************************
111 *****************************************************************************/
112 static int QNXInit ( vout_thread_t * );
113 static void QNXEnd ( vout_thread_t * );
114 static int QNXManage ( vout_thread_t * );
115 static void QNXDisplay ( vout_thread_t *, picture_t * );
117 static int QNXInitDisplay ( vout_thread_t * );
118 static int QNXCreateWnd ( vout_thread_t * );
119 static int QNXDestroyWnd ( vout_thread_t * );
121 static int NewPicture ( vout_thread_t *, picture_t *, int );
122 static void FreePicture ( vout_thread_t *, picture_t * );
123 static int ResizeOverlayOutput ( vout_thread_t * );
124 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
126 /*****************************************************************************
127 * OpenVideo: allocate QNX video thread output method
128 *****************************************************************************
129 * This function allocate and initialize a QNX vout method. It uses some of the
130 * vout properties to choose the window size, and change them according to the
131 * actual properties of the display.
132 *****************************************************************************/
133 int OpenVideo ( vlc_object_t *p_this )
135 vout_thread_t * p_vout = (vout_thread_t *)p_this;
137 /* init connection to photon */
138 if( PtInit( "/dev/photon" ) != 0 )
140 msg_Err( p_vout, "unable to connect to photon" );
144 /* allocate structure */
145 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
146 if( p_vout->p_sys == NULL )
148 msg_Err( p_vout, "out of memory" );
152 memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
154 p_vout->b_fullscreen = config_GetInt( p_vout, "fullscreen" );
155 p_vout->p_sys->i_mode = config_GetInt( p_vout, "overlay" ) ?
156 MODE_VIDEO_OVERLAY : MODE_VIDEO_MEM;
157 p_vout->p_sys->dim.w = p_vout->i_window_width;
158 p_vout->p_sys->dim.h = p_vout->i_window_height;
160 /* init display and create window */
161 if( QNXInitDisplay( p_vout ) || QNXCreateWnd( p_vout ) )
163 free( p_vout->p_sys );
167 p_vout->pf_init = QNXInit;
168 p_vout->pf_end = QNXEnd;
169 p_vout->pf_manage = QNXManage;
170 p_vout->pf_render = NULL;
171 p_vout->pf_display = QNXDisplay;
176 /*****************************************************************************
177 * QNXInit: initialize QNX video thread output method
178 *****************************************************************************
179 * This function create the buffers needed by the output thread. It is called
180 * at the beginning of the thread, but also each time the window is resized.
181 *****************************************************************************/
182 static int QNXInit( vout_thread_t *p_vout )
187 I_OUTPUTPICTURES = 0;
189 switch( p_vout->p_sys->i_mode )
191 case MODE_NORMAL_MEM:
192 case MODE_SHARED_MEM:
193 p_vout->output.i_width = p_vout->p_sys->dim.w;
194 p_vout->output.i_height = p_vout->p_sys->dim.h;
196 /* Assume we have square pixels */
197 p_vout->output.i_aspect = p_vout->p_sys->dim.w
198 * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
202 p_vout->output.i_width = p_vout->p_sys->dim.w;
203 p_vout->output.i_height = p_vout->p_sys->dim.h;
205 /* Assume we have square pixels */
206 p_vout->output.i_aspect = p_vout->p_sys->dim.w
207 * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
210 case MODE_VIDEO_OVERLAY:
211 p_vout->output.i_width = p_vout->render.i_width;
212 p_vout->output.i_height = p_vout->render.i_height;
213 p_vout->output.i_aspect = p_vout->render.i_aspect;
215 if (ResizeOverlayOutput(p_vout))
222 /* This shouldn't happen ! */
226 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
227 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
231 /* Find an empty picture slot */
232 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
234 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
236 p_pic = p_vout->p_picture + i_index;
241 /* Allocate the picture */
242 if( p_pic == NULL || NewPicture( p_vout, p_pic, I_OUTPUTPICTURES ) )
247 p_pic->i_status = DESTROYED_PICTURE;
248 p_pic->i_type = DIRECT_PICTURE;
250 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
258 /*****************************************************************************
259 * QNXEnd: terminate QNX video thread output method
260 *****************************************************************************
261 * Destroy the buffers created by QNXInit. It is called at the end of
262 * the thread, but also each time the window is resized.
263 *****************************************************************************/
264 static void QNXEnd( vout_thread_t *p_vout )
268 /* Free the direct buffers we allocated */
269 for( i_index = I_OUTPUTPICTURES ; i_index ; )
272 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
276 /*****************************************************************************
277 * CloseVideo: destroy QNX video thread output method
278 *****************************************************************************
279 * Terminate an output method created by QNXCreate
280 *****************************************************************************/
281 void CloseVideo ( vlc_object_t *p_this )
283 vout_thread_t * p_vout = (vout_thread_t *)p_this;
285 /* destroy the window */
286 QNXDestroyWnd( p_vout );
288 /* destroy structure */
289 free( p_vout->p_sys );
292 /*****************************************************************************
293 * QNXManage: handle QNX events
294 *****************************************************************************
295 * This function should be called regularly by video output thread. It allows
296 * window resizing. It returns a non null value on error.
297 *****************************************************************************/
298 static int QNXManage( vout_thread_t *p_vout )
304 if (!vlc_object_alive (p_vout))
309 /* allocate buffer for event */
310 i_buflen = sizeof( PhEvent_t ) * 4;
311 if( ( p_event = malloc( i_buflen ) ) == NULL )
313 msg_Err( p_vout, "out of memory" );
320 memset( p_event, 0, i_buflen );
321 i_ev = PhEventPeek( p_event, i_buflen );
323 if( i_ev == Ph_RESIZE_MSG )
325 i_buflen = PhGetMsgSize( p_event );
326 if( ( p_event = realloc( p_event, i_buflen ) ) == NULL )
328 msg_Err( p_vout, "out of memory" );
332 else if( i_ev == Ph_EVENT_MSG )
334 PtEventHandler( p_event );
336 if( p_event->type == Ph_EV_WM )
338 PhWindowEvent_t *p_ev = PhGetData( p_event );
340 switch( p_ev->event_f )
343 p_vout->p_libvlc->b_die = true;
347 p_vout->p_sys->pos.x = p_ev->pos.x;
348 p_vout->p_sys->pos.y = p_ev->pos.y;
353 p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
354 p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
355 p_vout->p_sys->dim.w = p_ev->size.w;
356 p_vout->p_sys->dim.h = p_ev->size.h;
357 p_vout->i_changes |= VOUT_SIZE_CHANGE;
361 else if( p_event->type == Ph_EV_KEY )
363 PhKeyEvent_t *p_ev = PhGetData( p_event );
364 long i_key = p_ev->key_sym;
366 if( ( p_ev->key_flags & Pk_KF_Key_Down ) &&
367 ( p_ev->key_flags & Pk_KF_Sym_Valid ) )
373 p_vout->p_libvlc->b_die = true;
378 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
387 } while( i_ev != -1 && i_ev != 0 );
394 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
398 p_vout->b_fullscreen = !p_vout->b_fullscreen;
399 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
401 if( p_vout->b_fullscreen )
403 p_vout->p_sys->old_pos.x = p_vout->p_sys->pos.x;
404 p_vout->p_sys->old_pos.y = p_vout->p_sys->pos.y;
405 p_vout->p_sys->pos.x = p_vout->p_sys->pos.y = 0;
406 dim.w = p_vout->p_sys->screen_dim.w + 1;
407 dim.h = p_vout->p_sys->screen_dim.h + 1;
411 p_vout->p_sys->pos.x = p_vout->p_sys->old_pos.x;
412 p_vout->p_sys->pos.y = p_vout->p_sys->old_pos.y;
413 dim.w = p_vout->p_sys->old_dim.w + 1;
414 dim.h = p_vout->p_sys->old_dim.h + 1;
417 /* modify render flags, border */
418 PtSetResource( p_vout->p_sys->p_window,
419 Pt_ARG_WINDOW_RENDER_FLAGS,
420 p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
421 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
423 /* set position and dimension */
424 PtSetResource( p_vout->p_sys->p_window,
425 Pt_ARG_POS, &p_vout->p_sys->pos, 0 );
426 PtSetResource( p_vout->p_sys->p_window,
427 Pt_ARG_DIM, &dim, 0 );
429 /* mark as damaged to force redraw */
430 PtDamageWidget( p_vout->p_sys->p_window );
436 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
438 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
440 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
442 ResizeOverlayOutput(p_vout);
447 p_vout->output.i_width = p_vout->p_sys->dim.w;
448 p_vout->output.i_height = p_vout->p_sys->dim.h;
449 p_vout->i_changes |= VOUT_YUV_CHANGE;
452 if( QNXInit( p_vout ) )
454 msg_Err( p_vout, "cannot resize display" );
460 msg_Dbg( p_vout, "video display resized (%dx%d)",
461 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h );
465 * position change, move video channel
467 if( b_repos && p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
469 ResizeOverlayOutput(p_vout);
472 return( i_ev == -1 );
475 /*****************************************************************************
476 * QNXDisplay: displays previously rendered output
477 *****************************************************************************
478 * This function send the currently rendered image to QNX server, wait until
479 * it is displayed and switch the two rendering buffer, preparing next frame.
480 *****************************************************************************/
481 static void QNXDisplay( vout_thread_t *p_vout, picture_t *p_pic )
483 if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
484 p_vout->p_sys->i_mode == MODE_SHARED_MEM )
486 PhPoint_t pos = { 0, 0 };
488 PgSetRegion( PtWidgetRid( p_vout->p_sys->p_window ) );
489 if (p_vout->p_sys->i_screen_depth == 8)
491 PgSetPalette( p_vout->p_sys->p_colors, 0, 0, 255, Pg_PALSET_SOFT, 0);
493 PgDrawPhImagemx( &pos, p_pic->p_sys->p_image, 0 );
496 else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM )
498 PhRect_t rc = { { 0, 0 }, { p_vout->output.i_width, p_vout->output.i_height } };
500 // PgSetRegion( PtWidgetRid ( p_vout->p_sys->p_window ) );
501 PgContextBlit( p_pic->p_sys->p_ctx[0], &rc, NULL, &rc );
506 /*****************************************************************************
507 * QNXInitDisplay: check screen resolution, depth, amount of video ram, etc
508 *****************************************************************************/
509 static int QNXInitDisplay( vout_thread_t * p_vout )
512 PgDisplaySettings_t cfg;
513 PgVideoModeInfo_t minfo;
515 /* get graphics card hw capabilities */
516 if( PgGetGraphicsHWCaps( &hwcaps ) != 0 )
518 msg_Err( p_vout, "unable to get gfx card capabilities" );
522 /* get current video mode */
523 if( PgGetVideoMode( &cfg ) != 0 )
525 msg_Err( p_vout, "unable to get current video mode" );
529 /* get video mode info */
530 if( PgGetVideoModeInfo( cfg.mode, &minfo ) != 0 )
532 msg_Err( p_vout, "unable to get info for video mode" );
536 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
539 PgScalerCaps_t vcaps;
541 if( ( p_vout->p_sys->p_channel =
542 PgCreateVideoChannel( Pg_VIDEO_CHANNEL_SCALER, 0 ) ) == NULL )
544 msg_Err( p_vout, "unable to create video channel" );
545 printf("errno = %d\n", errno);
546 p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
550 vcaps.size = sizeof( vcaps );
551 while( PgGetScalerCapabilities( p_vout->p_sys->p_channel,
554 printf("vcaps.format = 0x%x\n", vcaps.format);
555 if( vcaps.format == Pg_VIDEO_FORMAT_YV12 ||
556 vcaps.format == Pg_VIDEO_FORMAT_YUV420 ||
557 vcaps.format == Pg_VIDEO_FORMAT_YUY2 ||
558 vcaps.format == Pg_VIDEO_FORMAT_UYVY ||
559 vcaps.format == Pg_VIDEO_FORMAT_RGB555 ||
560 vcaps.format == Pg_VIDEO_FORMAT_RGB565 ||
561 vcaps.format == Pg_VIDEO_FORMAT_RGB8888 )
563 p_vout->p_sys->i_vc_flags = vcaps.flags;
564 p_vout->p_sys->i_vc_format = vcaps.format;
567 vcaps.size = sizeof( vcaps );
570 if( p_vout->p_sys->i_vc_format == 0 )
572 msg_Warn( p_vout, "need YV12, YUY2 or RGB8888 overlay" );
574 p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
579 /* use video ram if we have enough available */
580 if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM &&
581 (minfo.bits_per_pixel != 8) &&
582 hwcaps.currently_available_video_ram >=
583 ( ( minfo.width * minfo.height * minfo.bits_per_pixel * MAX_DIRECTBUFFERS) / 8 ) )
585 p_vout->p_sys->i_mode = MODE_VIDEO_MEM;
586 printf("Using video memory...\n");
589 p_vout->p_sys->i_img_type = minfo.type;
590 p_vout->p_sys->screen_dim.w = minfo.width;
591 p_vout->p_sys->screen_dim.h = minfo.height;
592 p_vout->p_sys->i_screen_depth = minfo.bits_per_pixel;
594 switch( p_vout->p_sys->i_screen_depth )
597 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
598 p_vout->p_sys->i_bytes_per_pixel = 1;
599 p_vout->output.pf_setpalette = SetPalette;
603 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
604 p_vout->p_sys->i_bytes_per_pixel = 2;
605 p_vout->output.i_rmask = 0x7c00;
606 p_vout->output.i_gmask = 0x03e0;
607 p_vout->output.i_bmask = 0x001f;
611 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
612 p_vout->p_sys->i_bytes_per_pixel = 2;
613 p_vout->output.i_rmask = 0xf800;
614 p_vout->output.i_gmask = 0x07e0;
615 p_vout->output.i_bmask = 0x001f;
619 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
620 p_vout->p_sys->i_bytes_per_pixel = 3;
621 p_vout->output.i_rmask = 0xff0000;
622 p_vout->output.i_gmask = 0x00ff00;
623 p_vout->output.i_bmask = 0x0000ff;
628 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
629 p_vout->p_sys->i_bytes_per_pixel = 4;
630 p_vout->output.i_rmask = 0xff0000;
631 p_vout->output.i_gmask = 0x00ff00;
632 p_vout->output.i_bmask = 0x0000ff;
639 /*****************************************************************************
640 * QNXCreateWnd: create and realize the main window
641 *****************************************************************************/
642 static int QNXCreateWnd( vout_thread_t * p_vout )
645 PhPoint_t pos = { 0, 0 };
646 PgColor_t color = Pg_BLACK;
648 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
650 if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
652 color = PgGetOverlayChromaColor();
656 /* fullscreen, set dimension */
657 if( p_vout->b_fullscreen )
659 p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
660 p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
661 p_vout->output.i_width = p_vout->p_sys->dim.w = p_vout->p_sys->screen_dim.w;
662 p_vout->output.i_height = p_vout->p_sys->dim.h = p_vout->p_sys->screen_dim.h;
665 /* set window parameters */
666 PtSetArg( &args[0], Pt_ARG_POS, &pos, 0 );
667 PtSetArg( &args[1], Pt_ARG_DIM, &p_vout->p_sys->dim, 0 );
668 PtSetArg( &args[2], Pt_ARG_FILL_COLOR, color, 0 );
669 PtSetArg( &args[3], Pt_ARG_WINDOW_TITLE, "VLC media player", 0 );
670 PtSetArg( &args[4], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE );
671 PtSetArg( &args[5], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
672 Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_CLOSE );
673 PtSetArg( &args[6], Pt_ARG_WINDOW_RENDER_FLAGS,
674 p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
675 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
678 p_vout->p_sys->p_window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 7, args);
679 if( p_vout->p_sys->p_window == NULL )
681 msg_Err( p_vout, "unable to create window" );
685 /* realize the window widget */
686 if( PtRealizeWidget( p_vout->p_sys->p_window ) != 0 )
688 msg_Err( p_vout, "unable to realize window widget" );
689 PtDestroyWidget( p_vout->p_sys->p_window );
693 /* get window frame size */
694 if( PtWindowFrameSize( NULL, p_vout->p_sys->p_window,
695 &p_vout->p_sys->frame ) != 0 )
697 msg_Err( p_vout, "unable to get window frame size" );
698 PtDestroyWidget( p_vout->p_sys->p_window );
705 /*****************************************************************************
706 * QNXDestroyWnd: unrealize and destroy the main window
707 *****************************************************************************/
708 static int QNXDestroyWnd( vout_thread_t * p_vout )
710 /* destroy the window widget */
711 PtUnrealizeWidget( p_vout->p_sys->p_window );
712 // PtDestroyWidget( p_vout->p_sys->p_window );
714 /* destroy video channel */
715 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
717 PgDestroyVideoChannel( p_vout->p_sys->p_channel );
724 /*****************************************************************************
725 * NewPicture: allocate a picture
726 *****************************************************************************
727 * Returns 0 on success, -1 otherwise
728 *****************************************************************************/
729 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic, int index )
731 /* We know the chroma, allocate a buffer which will be used
732 * directly by the decoder */
733 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
735 if( p_pic->p_sys == NULL )
740 switch( p_vout->p_sys->i_mode )
742 case MODE_NORMAL_MEM:
743 case MODE_SHARED_MEM:
744 /* create images for [shared] memory blit */
745 if( !( p_pic->p_sys->p_image = PhCreateImage( NULL,
746 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
747 p_vout->p_sys->i_img_type, NULL, 0,
748 p_vout->p_sys->i_mode == MODE_SHARED_MEM ) ) ) {
749 msg_Err( p_vout, "cannot create image" );
750 free( p_pic->p_sys );
754 p_pic->p->p_pixels = p_pic->p_sys->p_image->image;
755 p_pic->p->i_lines = p_pic->p_sys->p_image->size.h;
756 p_pic->p->i_visible_lines = p_pic->p_sys->p_image->size.h;
757 p_pic->p->i_pitch = p_pic->p_sys->p_image->bpl;
758 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
759 p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
760 * p_pic->p_sys->p_image->size.w;
765 /* create offscreen contexts for video memory blit */
766 if( ( p_pic->p_sys->p_ctx[0] = PdCreateOffscreenContext( 0,
767 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
768 Pg_OSC_MEM_PAGE_ALIGN) ) == NULL )
770 msg_Err( p_vout, "unable to create offscreen context" );
771 free( p_pic->p_sys );
775 /* get context pointers */
776 if( ( p_pic->p_sys->p_buf[0] =
777 PdGetOffscreenContextPtr ( p_pic->p_sys->p_ctx[0] ) ) == NULL )
779 msg_Err( p_vout, "unable to get offscreen context ptr" );
780 PhDCRelease ( p_pic->p_sys->p_ctx[0] );
781 p_pic->p_sys->p_ctx[0] = NULL;
782 free( p_pic->p_sys );
786 p_vout->p_sys->i_bytes_per_line = p_pic->p_sys->p_ctx[0]->pitch;
787 memset( p_pic->p_sys->p_buf[0], 0,
788 p_vout->p_sys->i_bytes_per_line * p_vout->p_sys->dim.h );
790 p_pic->p->p_pixels = p_pic->p_sys->p_buf[0];
791 p_pic->p->i_lines = p_pic->p_sys->p_ctx[0]->dim.h;
792 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[0]->dim.h;
793 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[0]->pitch;
794 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
795 p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
796 * p_pic->p_sys->p_ctx[0]->dim.w;
800 case MODE_VIDEO_OVERLAY:
803 p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane1;
804 p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane1;
805 p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane1;
809 p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane2;
810 p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane2;
811 p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane2;
814 p_pic->p_sys->p_buf[Y_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[Y_PLANE] );
815 if( p_pic->p_sys->p_buf[Y_PLANE] == NULL )
817 msg_Err( p_vout, "unable to get video channel ctx ptr" );
821 switch (p_vout->p_sys->i_vc_format)
823 case Pg_VIDEO_FORMAT_YUV420:
824 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
826 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
827 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
829 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
830 p_pic->p_sys->p_buf[V_PLANE] == NULL )
832 msg_Err( p_vout, "unable to get video channel ctx ptr" );
836 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
837 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
838 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
839 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
840 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
841 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
843 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
844 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
845 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
846 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
847 p_pic->p[U_PLANE].i_pixel_pitch = 1;
848 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
850 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
851 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
852 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
853 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
854 p_pic->p[V_PLANE].i_pixel_pitch = 1;
855 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
860 case Pg_VIDEO_FORMAT_YV12:
861 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
863 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
864 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
866 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
867 p_pic->p_sys->p_buf[V_PLANE] == NULL )
869 msg_Err( p_vout, "unable to get video channel ctx ptr" );
873 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
874 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
875 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
876 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
877 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
878 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
880 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
881 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
882 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
883 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
884 p_pic->p[U_PLANE].i_pixel_pitch = 1;
885 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
887 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
888 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
889 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
890 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
891 p_pic->p[V_PLANE].i_pixel_pitch = 1;
892 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
897 case Pg_VIDEO_FORMAT_UYVY:
898 case Pg_VIDEO_FORMAT_YUY2:
899 if (p_vout->p_sys->i_vc_format == Pg_VIDEO_FORMAT_UYVY)
901 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
905 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
908 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
909 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
910 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
911 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
912 p_pic->p->i_pixel_pitch = 4;
913 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
918 case Pg_VIDEO_FORMAT_RGB555:
919 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
920 p_vout->output.i_rmask = 0x001f;
921 p_vout->output.i_gmask = 0x03e0;
922 p_vout->output.i_bmask = 0x7c00;
924 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
925 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
926 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
927 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
928 p_pic->p->i_pixel_pitch = 2;
929 p_pic->p->i_visible_pitch = 2 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
934 case Pg_VIDEO_FORMAT_RGB565:
935 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
936 p_vout->output.i_rmask = 0x001f;
937 p_vout->output.i_gmask = 0x07e0;
938 p_vout->output.i_bmask = 0xf800;
940 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
941 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
942 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
943 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
944 p_pic->p->i_pixel_pitch = 4;
945 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
950 case Pg_VIDEO_FORMAT_RGB8888:
951 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
952 p_vout->output.i_rmask = 0x000000ff;
953 p_vout->output.i_gmask = 0x0000ff00;
954 p_vout->output.i_bmask = 0x00ff0000;
956 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
957 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
958 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
959 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
960 p_pic->p->i_pixel_pitch = 4;
961 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
968 switch( p_vout->output.i_chroma )
970 #ifdef MODULE_NAME_IS_xvideo
971 case VLC_FOURCC('Y','2','1','1'):
973 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
974 + p_pic->p_sys->p_image->offsets[0];
975 p_pic->p->i_lines = p_vout->output.i_height;
976 p_pic->p->i_visible_lines = p_vout->output.i_height;
977 /* XXX: this just looks so plain wrong... check it out ! */
978 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
979 p_pic->p->i_pixel_pitch = 4;
980 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
989 /* This shouldn't happen ! */
996 /*****************************************************************************
997 * FreePicture: destroy a picture allocated with NewPicture
998 *****************************************************************************
999 * Destroy XImage AND associated data. If using Shm, detach shared memory
1000 * segment from server and process, then free it. The XDestroyImage manpage
1001 * says that both the image structure _and_ the data pointed to by the
1002 * image structure are freed, so no need to free p_image->data.
1003 *****************************************************************************/
1004 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1006 if( ( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
1007 p_vout->p_sys->i_mode == MODE_SHARED_MEM ) &&
1008 p_pic->p_sys->p_image )
1010 PhReleaseImage( p_pic->p_sys->p_image );
1011 free( p_pic->p_sys->p_image );
1013 else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM &&
1014 p_pic->p_sys->p_ctx[0] )
1016 PhDCRelease( p_pic->p_sys->p_ctx[0] );
1019 free( p_pic->p_sys );
1023 static int ResizeOverlayOutput(vout_thread_t *p_vout)
1025 int i_width, i_height, i_x, i_y;
1027 PgScalerProps_t props;
1029 props.size = sizeof( props );
1030 props.format = p_vout->p_sys->i_vc_format;
1031 props.flags = Pg_SCALER_PROP_SCALER_ENABLE |
1032 Pg_SCALER_PROP_DOUBLE_BUFFER;
1034 /* enable chroma keying if available */
1035 if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
1037 props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
1040 /* set viewport position */
1041 props.viewport.ul.x = p_vout->p_sys->pos.x;
1042 props.viewport.ul.y = p_vout->p_sys->pos.y;
1043 if( !p_vout->b_fullscreen )
1045 props.viewport.ul.x += p_vout->p_sys->frame.ul.x;
1046 props.viewport.ul.y += p_vout->p_sys->frame.ul.y;
1049 /* set viewport dimension */
1050 vout_PlacePicture( p_vout, p_vout->p_sys->dim.w,
1051 p_vout->p_sys->dim.h,
1052 &i_x, &i_y, &i_width, &i_height );
1054 props.viewport.ul.x += i_x;
1055 props.viewport.ul.y += i_y;
1056 props.viewport.lr.x = i_width + props.viewport.ul.x;
1057 props.viewport.lr.y = i_height + props.viewport.ul.y;
1059 /* set source dimension */
1060 props.src_dim.w = p_vout->output.i_width;
1061 props.src_dim.h = p_vout->output.i_height;
1063 /* configure scaler channel */
1064 i_ret = PgConfigScalerChannel( p_vout->p_sys->p_channel, &props );
1068 msg_Err( p_vout, "unable to configure video channel" );
1076 /*****************************************************************************
1077 * SetPalette: sets an 8 bpp palette
1078 *****************************************************************************
1079 * This function sets the palette given as an argument. It does not return
1080 * anything, but could later send information on which colors it was unable
1082 *****************************************************************************/
1083 static void SetPalette( vout_thread_t *p_vout,
1084 uint16_t *red, uint16_t *green, uint16_t *blue )
1088 /* allocate palette */
1089 for( i = 0; i < 255; i++ )
1091 /* kludge: colors are indexed reversely because color 255 seems
1092 * to be reserved for black even if we try to set it to white */
1093 p_vout->p_sys->p_colors[ i ] = PgRGB( red[ i ] >> 8, green[ i ] >> 8, blue[ i ] >> 8 );