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 )
149 memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
151 p_vout->b_fullscreen = config_GetInt( p_vout, "fullscreen" );
152 p_vout->p_sys->i_mode = config_GetInt( p_vout, "overlay" ) ?
153 MODE_VIDEO_OVERLAY : MODE_VIDEO_MEM;
154 p_vout->p_sys->dim.w = p_vout->i_window_width;
155 p_vout->p_sys->dim.h = p_vout->i_window_height;
157 /* init display and create window */
158 if( QNXInitDisplay( p_vout ) || QNXCreateWnd( p_vout ) )
160 free( p_vout->p_sys );
164 p_vout->pf_init = QNXInit;
165 p_vout->pf_end = QNXEnd;
166 p_vout->pf_manage = QNXManage;
167 p_vout->pf_render = NULL;
168 p_vout->pf_display = QNXDisplay;
173 /*****************************************************************************
174 * QNXInit: initialize QNX video thread output method
175 *****************************************************************************
176 * This function create the buffers needed by the output thread. It is called
177 * at the beginning of the thread, but also each time the window is resized.
178 *****************************************************************************/
179 static int QNXInit( vout_thread_t *p_vout )
184 I_OUTPUTPICTURES = 0;
186 switch( p_vout->p_sys->i_mode )
188 case MODE_NORMAL_MEM:
189 case MODE_SHARED_MEM:
190 p_vout->output.i_width = p_vout->p_sys->dim.w;
191 p_vout->output.i_height = p_vout->p_sys->dim.h;
193 /* Assume we have square pixels */
194 p_vout->output.i_aspect = p_vout->p_sys->dim.w
195 * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
199 p_vout->output.i_width = p_vout->p_sys->dim.w;
200 p_vout->output.i_height = p_vout->p_sys->dim.h;
202 /* Assume we have square pixels */
203 p_vout->output.i_aspect = p_vout->p_sys->dim.w
204 * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;
207 case MODE_VIDEO_OVERLAY:
208 p_vout->output.i_width = p_vout->render.i_width;
209 p_vout->output.i_height = p_vout->render.i_height;
210 p_vout->output.i_aspect = p_vout->render.i_aspect;
212 if (ResizeOverlayOutput(p_vout))
219 /* This shouldn't happen ! */
223 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
224 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
228 /* Find an empty picture slot */
229 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
231 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
233 p_pic = p_vout->p_picture + i_index;
238 /* Allocate the picture */
239 if( p_pic == NULL || NewPicture( p_vout, p_pic, I_OUTPUTPICTURES ) )
244 p_pic->i_status = DESTROYED_PICTURE;
245 p_pic->i_type = DIRECT_PICTURE;
247 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
255 /*****************************************************************************
256 * QNXEnd: terminate QNX video thread output method
257 *****************************************************************************
258 * Destroy the buffers created by QNXInit. It is called at the end of
259 * the thread, but also each time the window is resized.
260 *****************************************************************************/
261 static void QNXEnd( vout_thread_t *p_vout )
265 /* Free the direct buffers we allocated */
266 for( i_index = I_OUTPUTPICTURES ; i_index ; )
269 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
273 /*****************************************************************************
274 * CloseVideo: destroy QNX video thread output method
275 *****************************************************************************
276 * Terminate an output method created by QNXCreate
277 *****************************************************************************/
278 void CloseVideo ( vlc_object_t *p_this )
280 vout_thread_t * p_vout = (vout_thread_t *)p_this;
282 /* destroy the window */
283 QNXDestroyWnd( p_vout );
285 /* destroy structure */
286 free( p_vout->p_sys );
289 /*****************************************************************************
290 * QNXManage: handle QNX events
291 *****************************************************************************
292 * This function should be called regularly by video output thread. It allows
293 * window resizing. It returns a non null value on error.
294 *****************************************************************************/
295 static int QNXManage( vout_thread_t *p_vout )
301 if (!vlc_object_alive (p_vout))
306 /* allocate buffer for event */
307 i_buflen = sizeof( PhEvent_t ) * 4;
308 if( ( p_event = malloc( i_buflen ) ) == NULL )
314 memset( p_event, 0, i_buflen );
315 i_ev = PhEventPeek( p_event, i_buflen );
317 if( i_ev == Ph_RESIZE_MSG )
321 i_buflen = PhGetMsgSize( p_event );
322 buf = realloc( p_event, i_buflen );
330 else if( i_ev == Ph_EVENT_MSG )
332 PtEventHandler( p_event );
334 if( p_event->type == Ph_EV_WM )
336 PhWindowEvent_t *p_ev = PhGetData( p_event );
338 switch( p_ev->event_f )
341 p_vout->p_libvlc->b_die = true;
345 p_vout->p_sys->pos.x = p_ev->pos.x;
346 p_vout->p_sys->pos.y = p_ev->pos.y;
351 p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
352 p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
353 p_vout->p_sys->dim.w = p_ev->size.w;
354 p_vout->p_sys->dim.h = p_ev->size.h;
355 p_vout->i_changes |= VOUT_SIZE_CHANGE;
359 else if( p_event->type == Ph_EV_KEY )
361 PhKeyEvent_t *p_ev = PhGetData( p_event );
362 long i_key = p_ev->key_sym;
364 if( ( p_ev->key_flags & Pk_KF_Key_Down ) &&
365 ( p_ev->key_flags & Pk_KF_Sym_Valid ) )
371 p_vout->p_libvlc->b_die = true;
376 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
385 } while( i_ev != -1 && i_ev != 0 );
392 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
396 p_vout->b_fullscreen = !p_vout->b_fullscreen;
397 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
399 if( p_vout->b_fullscreen )
401 p_vout->p_sys->old_pos.x = p_vout->p_sys->pos.x;
402 p_vout->p_sys->old_pos.y = p_vout->p_sys->pos.y;
403 p_vout->p_sys->pos.x = p_vout->p_sys->pos.y = 0;
404 dim.w = p_vout->p_sys->screen_dim.w + 1;
405 dim.h = p_vout->p_sys->screen_dim.h + 1;
409 p_vout->p_sys->pos.x = p_vout->p_sys->old_pos.x;
410 p_vout->p_sys->pos.y = p_vout->p_sys->old_pos.y;
411 dim.w = p_vout->p_sys->old_dim.w + 1;
412 dim.h = p_vout->p_sys->old_dim.h + 1;
415 /* modify render flags, border */
416 PtSetResource( p_vout->p_sys->p_window,
417 Pt_ARG_WINDOW_RENDER_FLAGS,
418 p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
419 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
421 /* set position and dimension */
422 PtSetResource( p_vout->p_sys->p_window,
423 Pt_ARG_POS, &p_vout->p_sys->pos, 0 );
424 PtSetResource( p_vout->p_sys->p_window,
425 Pt_ARG_DIM, &dim, 0 );
427 /* mark as damaged to force redraw */
428 PtDamageWidget( p_vout->p_sys->p_window );
434 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
436 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
438 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
440 ResizeOverlayOutput(p_vout);
445 p_vout->output.i_width = p_vout->p_sys->dim.w;
446 p_vout->output.i_height = p_vout->p_sys->dim.h;
447 p_vout->i_changes |= VOUT_YUV_CHANGE;
450 if( QNXInit( p_vout ) )
452 msg_Err( p_vout, "cannot resize display" );
458 msg_Dbg( p_vout, "video display resized (%dx%d)",
459 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h );
463 * position change, move video channel
465 if( b_repos && p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
467 ResizeOverlayOutput(p_vout);
470 return( i_ev == -1 );
473 /*****************************************************************************
474 * QNXDisplay: displays previously rendered output
475 *****************************************************************************
476 * This function send the currently rendered image to QNX server, wait until
477 * it is displayed and switch the two rendering buffer, preparing next frame.
478 *****************************************************************************/
479 static void QNXDisplay( vout_thread_t *p_vout, picture_t *p_pic )
481 if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
482 p_vout->p_sys->i_mode == MODE_SHARED_MEM )
484 PhPoint_t pos = { 0, 0 };
486 PgSetRegion( PtWidgetRid( p_vout->p_sys->p_window ) );
487 if (p_vout->p_sys->i_screen_depth == 8)
489 PgSetPalette( p_vout->p_sys->p_colors, 0, 0, 255, Pg_PALSET_SOFT, 0);
491 PgDrawPhImagemx( &pos, p_pic->p_sys->p_image, 0 );
494 else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM )
496 PhRect_t rc = { { 0, 0 }, { p_vout->output.i_width, p_vout->output.i_height } };
498 // PgSetRegion( PtWidgetRid ( p_vout->p_sys->p_window ) );
499 PgContextBlit( p_pic->p_sys->p_ctx[0], &rc, NULL, &rc );
504 /*****************************************************************************
505 * QNXInitDisplay: check screen resolution, depth, amount of video ram, etc
506 *****************************************************************************/
507 static int QNXInitDisplay( vout_thread_t * p_vout )
510 PgDisplaySettings_t cfg;
511 PgVideoModeInfo_t minfo;
513 /* get graphics card hw capabilities */
514 if( PgGetGraphicsHWCaps( &hwcaps ) != 0 )
516 msg_Err( p_vout, "unable to get gfx card capabilities" );
520 /* get current video mode */
521 if( PgGetVideoMode( &cfg ) != 0 )
523 msg_Err( p_vout, "unable to get current video mode" );
527 /* get video mode info */
528 if( PgGetVideoModeInfo( cfg.mode, &minfo ) != 0 )
530 msg_Err( p_vout, "unable to get info for video mode" );
534 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
537 PgScalerCaps_t vcaps;
539 if( ( p_vout->p_sys->p_channel =
540 PgCreateVideoChannel( Pg_VIDEO_CHANNEL_SCALER, 0 ) ) == NULL )
542 msg_Err( p_vout, "unable to create video channel" );
543 printf("errno = %d\n", errno);
544 p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
548 vcaps.size = sizeof( vcaps );
549 while( PgGetScalerCapabilities( p_vout->p_sys->p_channel,
552 printf("vcaps.format = 0x%x\n", vcaps.format);
553 if( vcaps.format == Pg_VIDEO_FORMAT_YV12 ||
554 vcaps.format == Pg_VIDEO_FORMAT_YUV420 ||
555 vcaps.format == Pg_VIDEO_FORMAT_YUY2 ||
556 vcaps.format == Pg_VIDEO_FORMAT_UYVY ||
557 vcaps.format == Pg_VIDEO_FORMAT_RGB555 ||
558 vcaps.format == Pg_VIDEO_FORMAT_RGB565 ||
559 vcaps.format == Pg_VIDEO_FORMAT_RGB8888 )
561 p_vout->p_sys->i_vc_flags = vcaps.flags;
562 p_vout->p_sys->i_vc_format = vcaps.format;
565 vcaps.size = sizeof( vcaps );
568 if( p_vout->p_sys->i_vc_format == 0 )
570 msg_Warn( p_vout, "need YV12, YUY2 or RGB8888 overlay" );
572 p_vout->p_sys->i_mode = MODE_NORMAL_MEM;
577 /* use video ram if we have enough available */
578 if( p_vout->p_sys->i_mode == MODE_NORMAL_MEM &&
579 (minfo.bits_per_pixel != 8) &&
580 hwcaps.currently_available_video_ram >=
581 ( ( minfo.width * minfo.height * minfo.bits_per_pixel * MAX_DIRECTBUFFERS) / 8 ) )
583 p_vout->p_sys->i_mode = MODE_VIDEO_MEM;
584 printf("Using video memory...\n");
587 p_vout->p_sys->i_img_type = minfo.type;
588 p_vout->p_sys->screen_dim.w = minfo.width;
589 p_vout->p_sys->screen_dim.h = minfo.height;
590 p_vout->p_sys->i_screen_depth = minfo.bits_per_pixel;
592 switch( p_vout->p_sys->i_screen_depth )
595 p_vout->output.i_chroma = VLC_CODEC_RGB8;
596 p_vout->p_sys->i_bytes_per_pixel = 1;
597 p_vout->output.pf_setpalette = SetPalette;
601 p_vout->output.i_chroma = VLC_CODEC_RGB15;
602 p_vout->p_sys->i_bytes_per_pixel = 2;
603 p_vout->output.i_rmask = 0x7c00;
604 p_vout->output.i_gmask = 0x03e0;
605 p_vout->output.i_bmask = 0x001f;
609 p_vout->output.i_chroma = VLC_CODEC_RGB16;
610 p_vout->p_sys->i_bytes_per_pixel = 2;
611 p_vout->output.i_rmask = 0xf800;
612 p_vout->output.i_gmask = 0x07e0;
613 p_vout->output.i_bmask = 0x001f;
617 p_vout->output.i_chroma = VLC_CODEC_RGB24;
618 p_vout->p_sys->i_bytes_per_pixel = 3;
619 p_vout->output.i_rmask = 0xff0000;
620 p_vout->output.i_gmask = 0x00ff00;
621 p_vout->output.i_bmask = 0x0000ff;
626 p_vout->output.i_chroma = VLC_CODEC_RGB32;
627 p_vout->p_sys->i_bytes_per_pixel = 4;
628 p_vout->output.i_rmask = 0xff0000;
629 p_vout->output.i_gmask = 0x00ff00;
630 p_vout->output.i_bmask = 0x0000ff;
637 /*****************************************************************************
638 * QNXCreateWnd: create and realize the main window
639 *****************************************************************************/
640 static int QNXCreateWnd( vout_thread_t * p_vout )
643 PhPoint_t pos = { 0, 0 };
644 PgColor_t color = Pg_BLACK;
646 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
648 if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
650 color = PgGetOverlayChromaColor();
654 /* fullscreen, set dimension */
655 if( p_vout->b_fullscreen )
657 p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;
658 p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;
659 p_vout->output.i_width = p_vout->p_sys->dim.w = p_vout->p_sys->screen_dim.w;
660 p_vout->output.i_height = p_vout->p_sys->dim.h = p_vout->p_sys->screen_dim.h;
663 /* set window parameters */
664 PtSetArg( &args[0], Pt_ARG_POS, &pos, 0 );
665 PtSetArg( &args[1], Pt_ARG_DIM, &p_vout->p_sys->dim, 0 );
666 PtSetArg( &args[2], Pt_ARG_FILL_COLOR, color, 0 );
667 PtSetArg( &args[3], Pt_ARG_WINDOW_TITLE, "VLC media player", 0 );
668 PtSetArg( &args[4], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_CLOSE );
669 PtSetArg( &args[5], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
670 Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_CLOSE );
671 PtSetArg( &args[6], Pt_ARG_WINDOW_RENDER_FLAGS,
672 p_vout->b_fullscreen ? Pt_FALSE : Pt_TRUE,
673 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE );
676 p_vout->p_sys->p_window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 7, args);
677 if( p_vout->p_sys->p_window == NULL )
679 msg_Err( p_vout, "unable to create window" );
683 /* realize the window widget */
684 if( PtRealizeWidget( p_vout->p_sys->p_window ) != 0 )
686 msg_Err( p_vout, "unable to realize window widget" );
687 PtDestroyWidget( p_vout->p_sys->p_window );
691 /* get window frame size */
692 if( PtWindowFrameSize( NULL, p_vout->p_sys->p_window,
693 &p_vout->p_sys->frame ) != 0 )
695 msg_Err( p_vout, "unable to get window frame size" );
696 PtDestroyWidget( p_vout->p_sys->p_window );
703 /*****************************************************************************
704 * QNXDestroyWnd: unrealize and destroy the main window
705 *****************************************************************************/
706 static int QNXDestroyWnd( vout_thread_t * p_vout )
708 /* destroy the window widget */
709 PtUnrealizeWidget( p_vout->p_sys->p_window );
710 // PtDestroyWidget( p_vout->p_sys->p_window );
712 /* destroy video channel */
713 if( p_vout->p_sys->i_mode == MODE_VIDEO_OVERLAY )
715 PgDestroyVideoChannel( p_vout->p_sys->p_channel );
722 /*****************************************************************************
723 * NewPicture: allocate a picture
724 *****************************************************************************
725 * Returns 0 on success, -1 otherwise
726 *****************************************************************************/
727 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic, int index )
729 /* We know the chroma, allocate a buffer which will be used
730 * directly by the decoder */
731 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
733 if( p_pic->p_sys == NULL )
738 switch( p_vout->p_sys->i_mode )
740 case MODE_NORMAL_MEM:
741 case MODE_SHARED_MEM:
742 /* create images for [shared] memory blit */
743 if( !( p_pic->p_sys->p_image = PhCreateImage( NULL,
744 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
745 p_vout->p_sys->i_img_type, NULL, 0,
746 p_vout->p_sys->i_mode == MODE_SHARED_MEM ) ) ) {
747 msg_Err( p_vout, "cannot create image" );
748 free( p_pic->p_sys );
752 p_pic->p->p_pixels = p_pic->p_sys->p_image->image;
753 p_pic->p->i_lines = p_pic->p_sys->p_image->size.h;
754 p_pic->p->i_visible_lines = p_pic->p_sys->p_image->size.h;
755 p_pic->p->i_pitch = p_pic->p_sys->p_image->bpl;
756 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
757 p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
758 * p_pic->p_sys->p_image->size.w;
763 /* create offscreen contexts for video memory blit */
764 if( ( p_pic->p_sys->p_ctx[0] = PdCreateOffscreenContext( 0,
765 p_vout->p_sys->dim.w, p_vout->p_sys->dim.h,
766 Pg_OSC_MEM_PAGE_ALIGN) ) == NULL )
768 msg_Err( p_vout, "unable to create offscreen context" );
769 free( p_pic->p_sys );
773 /* get context pointers */
774 if( ( p_pic->p_sys->p_buf[0] =
775 PdGetOffscreenContextPtr ( p_pic->p_sys->p_ctx[0] ) ) == NULL )
777 msg_Err( p_vout, "unable to get offscreen context ptr" );
778 PhDCRelease ( p_pic->p_sys->p_ctx[0] );
779 p_pic->p_sys->p_ctx[0] = NULL;
780 free( p_pic->p_sys );
784 p_vout->p_sys->i_bytes_per_line = p_pic->p_sys->p_ctx[0]->pitch;
785 memset( p_pic->p_sys->p_buf[0], 0,
786 p_vout->p_sys->i_bytes_per_line * p_vout->p_sys->dim.h );
788 p_pic->p->p_pixels = p_pic->p_sys->p_buf[0];
789 p_pic->p->i_lines = p_pic->p_sys->p_ctx[0]->dim.h;
790 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[0]->dim.h;
791 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[0]->pitch;
792 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
793 p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel
794 * p_pic->p_sys->p_ctx[0]->dim.w;
798 case MODE_VIDEO_OVERLAY:
801 p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane1;
802 p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane1;
803 p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane1;
807 p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane2;
808 p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane2;
809 p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane2;
812 p_pic->p_sys->p_buf[Y_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[Y_PLANE] );
813 if( p_pic->p_sys->p_buf[Y_PLANE] == NULL )
815 msg_Err( p_vout, "unable to get video channel ctx ptr" );
819 switch (p_vout->p_sys->i_vc_format)
821 case Pg_VIDEO_FORMAT_YUV420:
822 p_vout->output.i_chroma = VLC_CODEC_I420;
824 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
825 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
827 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
828 p_pic->p_sys->p_buf[V_PLANE] == NULL )
830 msg_Err( p_vout, "unable to get video channel ctx ptr" );
834 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
835 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
836 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
837 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
838 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
839 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
841 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
842 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
843 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
844 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
845 p_pic->p[U_PLANE].i_pixel_pitch = 1;
846 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
848 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
849 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
850 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
851 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
852 p_pic->p[V_PLANE].i_pixel_pitch = 1;
853 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
858 case Pg_VIDEO_FORMAT_YV12:
859 p_vout->output.i_chroma = VLC_CODEC_YV12;
861 p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] );
862 p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] );
864 if( p_pic->p_sys->p_buf[U_PLANE] == NULL ||
865 p_pic->p_sys->p_buf[V_PLANE] == NULL )
867 msg_Err( p_vout, "unable to get video channel ctx ptr" );
871 p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE];
872 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
873 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
874 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
875 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
876 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch;
878 p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE];
879 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
880 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h;
881 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch;
882 p_pic->p[U_PLANE].i_pixel_pitch = 1;
883 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch;
885 p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE];
886 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
887 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h;
888 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch;
889 p_pic->p[V_PLANE].i_pixel_pitch = 1;
890 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch;
895 case Pg_VIDEO_FORMAT_UYVY:
896 case Pg_VIDEO_FORMAT_YUY2:
897 if (p_vout->p_sys->i_vc_format == Pg_VIDEO_FORMAT_UYVY)
899 p_vout->output.i_chroma = VLC_CODEC_UYVY;
903 p_vout->output.i_chroma = VLC_CODEC_YUYV;
906 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
907 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
908 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
909 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
910 p_pic->p->i_pixel_pitch = 4;
911 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
916 case Pg_VIDEO_FORMAT_RGB555:
917 p_vout->output.i_chroma = VLC_CODEC_RGB15;
918 p_vout->output.i_rmask = 0x001f;
919 p_vout->output.i_gmask = 0x03e0;
920 p_vout->output.i_bmask = 0x7c00;
922 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
923 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
924 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
925 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
926 p_pic->p->i_pixel_pitch = 2;
927 p_pic->p->i_visible_pitch = 2 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
932 case Pg_VIDEO_FORMAT_RGB565:
933 p_vout->output.i_chroma = VLC_CODEC_RGB16;
934 p_vout->output.i_rmask = 0x001f;
935 p_vout->output.i_gmask = 0x07e0;
936 p_vout->output.i_bmask = 0xf800;
938 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
939 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
940 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
941 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
942 p_pic->p->i_pixel_pitch = 4;
943 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
948 case Pg_VIDEO_FORMAT_RGB8888:
949 p_vout->output.i_chroma = VLC_CODEC_RGB32;
950 p_vout->output.i_rmask = 0x000000ff;
951 p_vout->output.i_gmask = 0x0000ff00;
952 p_vout->output.i_bmask = 0x00ff0000;
954 p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE];
955 p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
956 p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h;
957 p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch;
958 p_pic->p->i_pixel_pitch = 4;
959 p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w;
966 switch( p_vout->output.i_chroma )
968 #ifdef MODULE_NAME_IS_xvideo
971 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
972 + p_pic->p_sys->p_image->offsets[0];
973 p_pic->p->i_lines = p_vout->output.i_height;
974 p_pic->p->i_visible_lines = p_vout->output.i_height;
975 /* XXX: this just looks so plain wrong... check it out ! */
976 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
977 p_pic->p->i_pixel_pitch = 4;
978 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
987 /* This shouldn't happen ! */
994 /*****************************************************************************
995 * FreePicture: destroy a picture allocated with NewPicture
996 *****************************************************************************
997 * Destroy XImage AND associated data. If using Shm, detach shared memory
998 * segment from server and process, then free it. The XDestroyImage manpage
999 * says that both the image structure _and_ the data pointed to by the
1000 * image structure are freed, so no need to free p_image->data.
1001 *****************************************************************************/
1002 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1004 if( ( p_vout->p_sys->i_mode == MODE_NORMAL_MEM ||
1005 p_vout->p_sys->i_mode == MODE_SHARED_MEM ) &&
1006 p_pic->p_sys->p_image )
1008 PhReleaseImage( p_pic->p_sys->p_image );
1009 free( p_pic->p_sys->p_image );
1011 else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM &&
1012 p_pic->p_sys->p_ctx[0] )
1014 PhDCRelease( p_pic->p_sys->p_ctx[0] );
1017 free( p_pic->p_sys );
1021 static int ResizeOverlayOutput(vout_thread_t *p_vout)
1023 int i_width, i_height, i_x, i_y;
1025 PgScalerProps_t props;
1027 props.size = sizeof( props );
1028 props.format = p_vout->p_sys->i_vc_format;
1029 props.flags = Pg_SCALER_PROP_SCALER_ENABLE |
1030 Pg_SCALER_PROP_DOUBLE_BUFFER;
1032 /* enable chroma keying if available */
1033 if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY )
1035 props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
1038 /* set viewport position */
1039 props.viewport.ul.x = p_vout->p_sys->pos.x;
1040 props.viewport.ul.y = p_vout->p_sys->pos.y;
1041 if( !p_vout->b_fullscreen )
1043 props.viewport.ul.x += p_vout->p_sys->frame.ul.x;
1044 props.viewport.ul.y += p_vout->p_sys->frame.ul.y;
1047 /* set viewport dimension */
1048 vout_PlacePicture( p_vout, p_vout->p_sys->dim.w,
1049 p_vout->p_sys->dim.h,
1050 &i_x, &i_y, &i_width, &i_height );
1052 props.viewport.ul.x += i_x;
1053 props.viewport.ul.y += i_y;
1054 props.viewport.lr.x = i_width + props.viewport.ul.x;
1055 props.viewport.lr.y = i_height + props.viewport.ul.y;
1057 /* set source dimension */
1058 props.src_dim.w = p_vout->output.i_width;
1059 props.src_dim.h = p_vout->output.i_height;
1061 /* configure scaler channel */
1062 i_ret = PgConfigScalerChannel( p_vout->p_sys->p_channel, &props );
1066 msg_Err( p_vout, "unable to configure video channel" );
1074 /*****************************************************************************
1075 * SetPalette: sets an 8 bpp palette
1076 *****************************************************************************
1077 * This function sets the palette given as an argument. It does not return
1078 * anything, but could later send information on which colors it was unable
1080 *****************************************************************************/
1081 static void SetPalette( vout_thread_t *p_vout,
1082 uint16_t *red, uint16_t *green, uint16_t *blue )
1086 /* allocate palette */
1087 for( i = 0; i < 255; i++ )
1089 /* kludge: colors are indexed reversely because color 255 seems
1090 * to be reserved for black even if we try to set it to white */
1091 p_vout->p_sys->p_colors[ i ] = PgRGB( red[ i ] >> 8, green[ i ] >> 8, blue[ i ] >> 8 );