1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.25 2003/11/08 18:23:40 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tcastley@mail.powerup.com.au>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <stippi@yellowbites.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
34 #include <string.h> /* strerror() */
36 #include <Application.h>
37 #include <BitmapStream.h>
39 #include <Directory.h>
40 #include <DirectWindow.h>
42 #include <InterfaceKit.h>
45 #include <TranslatorRoster.h>
46 #include <WindowScreen.h>
54 #include "InterfaceWindow.h" // for load/save_settings()
55 #include "DrawingTidbits.h"
58 #include "VideoWindow.h"
60 /*****************************************************************************
61 * vout_sys_t: BeOS video output method descriptor
62 *****************************************************************************
63 * This structure is part of the video output thread descriptor.
64 * It describes the BeOS specific properties of an output thread.
65 *****************************************************************************/
68 VideoWindow * p_window;
73 // uint8_t *pp_buffer[3];
74 uint32_t source_chroma;
79 #define MOUSE_IDLE_TIMEOUT 2000000 // two seconds
80 #define MIN_AUTO_VSYNC_REFRESH 61 // Hz
81 #define DEFAULT_SCREEN_SHOT_FORMAT 'PNG '
82 #define DEFAULT_SCREEN_SHOT_PATH "/boot/home/vlc screenshot"
84 /*****************************************************************************
85 * beos_GetAppWindow : retrieve a BWindow pointer from the window name
86 *****************************************************************************/
88 beos_GetAppWindow(char *name)
93 for (index = 0 ; ; index++)
95 window = be_app->WindowAt(index);
98 if (window->LockWithTimeout(20000) == B_OK)
100 if (strcmp(window->Name(), name) == 0)
111 static int ConvertKey( int key )
121 /*****************************************************************************
122 * get_interface_window
123 *****************************************************************************/
125 get_interface_window()
127 return beos_GetAppWindow( "VLC " PACKAGE_VERSION );
130 class BackgroundView : public BView
133 BackgroundView(BRect frame, VLCView* view)
134 : BView(frame, "background",
135 B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE),
138 SetViewColor(kBlack);
140 virtual ~BackgroundView() {}
142 virtual void MouseDown(BPoint where)
144 // convert coordinates
145 where = fVideoView->ConvertFromParent(where);
147 fVideoView->MouseDown(where);
149 virtual void MouseMoved(BPoint where, uint32_t transit,
150 const BMessage* dragMessage)
152 // convert coordinates
153 where = fVideoView->ConvertFromParent(where);
155 fVideoView->MouseMoved(where, transit, dragMessage);
156 // notice: It might look like transit should be
157 // B_OUTSIDE_VIEW regardless, but leave it like this,
158 // otherwise, unwanted things will happen!
166 /*****************************************************************************
167 * VideoSettings constructor and destructor
168 *****************************************************************************/
169 VideoSettings::VideoSettings()
170 : fVideoSize( SIZE_100 ),
171 fFlags( FLAG_CORRECT_RATIO ),
172 fSettings( new BMessage( 'sett' ) )
174 // read settings from disk
175 status_t ret = load_settings( fSettings, "video_settings", "VideoLAN Client" );
179 if ( fSettings->FindInt32( "flags", (int32*)&flags ) == B_OK )
182 if ( fSettings->FindInt32( "video size", (int32*)&size ) == B_OK )
183 SetVideoSize( size );
187 fprintf( stderr, "error loading video settings: %s\n", strerror( ret ) );
189 // figure out if we should use vertical sync by default
190 BScreen screen(B_MAIN_SCREEN_ID);
191 if (screen.IsValid())
194 screen.GetMode(&mode);
195 float refresh = (mode.timing.pixel_clock * 1000)
196 / ((mode.timing.h_total)* (mode.timing.v_total));
197 if (refresh < MIN_AUTO_VSYNC_REFRESH)
198 AddFlags(FLAG_SYNC_RETRACE);
203 VideoSettings::VideoSettings( const VideoSettings& clone )
204 : fVideoSize( clone.VideoSize() ),
205 fFlags( clone.Flags() ),
211 VideoSettings::~VideoSettings()
215 // we are the default settings
216 // and write our settings to disk
217 if (fSettings->ReplaceInt32( "video size", VideoSize() ) != B_OK)
218 fSettings->AddInt32( "video size", VideoSize() );
219 if (fSettings->ReplaceInt32( "flags", Flags() ) != B_OK)
220 fSettings->AddInt32( "flags", Flags() );
222 status_t ret = save_settings( fSettings, "video_settings", "VideoLAN Client" );
224 fprintf( stderr, "error saving video settings: %s\n", strerror( ret ) );
229 // we are just a clone of the default settings
230 fDefaultSettings.SetVideoSize( VideoSize() );
231 fDefaultSettings.SetFlags( Flags() );
235 /*****************************************************************************
236 * VideoSettings::DefaultSettings
237 *****************************************************************************/
239 VideoSettings::DefaultSettings()
241 return &fDefaultSettings;
244 /*****************************************************************************
245 * VideoSettings::SetVideoSize
246 *****************************************************************************/
248 VideoSettings::SetVideoSize( uint32_t mode )
253 // static variable initialization
255 VideoSettings::fDefaultSettings;
258 /*****************************************************************************
259 * VideoWindow constructor and destructor
260 *****************************************************************************/
261 VideoWindow::VideoWindow(int v_width, int v_height, BRect frame,
262 vout_thread_t *p_videoout)
263 : BWindow(frame, NULL, B_TITLED_WINDOW, B_NOT_CLOSABLE | B_NOT_MINIMIZABLE),
264 i_width(frame.IntegerWidth()),
265 i_height(frame.IntegerHeight()),
268 teardownwindow(false),
270 fTrueHeight(v_height),
271 fCachedFeel(B_NORMAL_WINDOW_FEEL),
272 fInterfaceShowing(false),
273 fInitStatus(B_ERROR),
274 fSettings(new VideoSettings(*VideoSettings::DefaultSettings()))
278 // create the view to do the display
279 view = new VLCView( Bounds(), p_vout );
281 // create background view
282 BView *mainView = new BackgroundView( Bounds(), view );
284 mainView->AddChild(view);
286 // allocate bitmap buffers
287 for (int32_t i = 0; i < 3; i++)
289 fInitStatus = _AllocateBuffers(v_width, v_height, &mode);
291 // make sure we layout the view correctly
292 FrameResized(i_width, i_height);
294 if (fInitStatus >= B_OK && mode == OVERLAY)
296 overlay_restrictions r;
298 bitmap[1]->GetOverlayRestrictions(&r);
299 SetSizeLimits((i_width * r.min_width_scale), i_width * r.max_width_scale,
300 (i_height * r.min_height_scale), i_height * r.max_height_scale);
303 // vlc settings override settings from disk
304 if (config_GetInt(p_vout, "fullscreen"))
305 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
307 // add a few useful shortcuts
308 AddShortcut( 'f', 0, new BMessage( TOGGLE_FULL_SCREEN ) );
309 AddShortcut( '1', 0, new BMessage( RESIZE_50 ) );
310 AddShortcut( '2', 0, new BMessage( RESIZE_100 ) );
311 AddShortcut( '3', 0, new BMessage( RESIZE_200 ) );
313 // workaround for french keyboards
314 AddShortcut( '&', 0, new BMessage( RESIZE_50 ) );
315 AddShortcut( 'é', 0, new BMessage( RESIZE_100 ) );
316 // FIXME - this one doesn't work because 'é' is a multi-byte character
317 AddShortcut( '"', 0, new BMessage( RESIZE_200 ) );
322 VideoWindow::~VideoWindow()
326 teardownwindow = true;
327 wait_for_thread(fDrawThreadID, &result);
332 /*****************************************************************************
333 * VideoWindow::MessageReceived
334 *****************************************************************************/
336 VideoWindow::MessageReceived( BMessage *p_message )
338 switch( p_message->what )
341 SetInterfaceShowing( true );
343 case TOGGLE_FULL_SCREEN:
351 _SetVideoSize(p_message->what);
354 SetSyncToRetrace(!IsSyncedToRetrace());
359 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
362 fCachedFeel = winFeel;
363 if (winFeel == B_FLOATING_ALL_WINDOW_FEEL)
364 fSettings->AddFlags(VideoSettings::FLAG_ON_TOP_ALL);
366 fSettings->ClearFlags(VideoSettings::FLAG_ON_TOP_ALL);
371 SetCorrectAspectRatio(!CorrectAspectRatio());
374 // save a screen shot
375 if ( BBitmap* current = bitmap[i_buffer] )
377 // the following line might be tempting, but does not work for some overlay bitmaps!!!
378 // BBitmap* temp = new BBitmap( current );
379 // so we clone the bitmap ourselves
380 // however, we need to take care of potentially different padding!
381 // memcpy() is slow when reading from grafix memory, but what the heck...
382 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
383 if ( temp && temp->IsValid() )
385 int32_t height = (int32_t)current->Bounds().Height();
386 uint8_t* dst = (uint8_t*)temp->Bits();
387 uint8_t* src = (uint8_t*)current->Bits();
388 int32_t dstBpr = temp->BytesPerRow();
389 int32_t srcBpr = current->BytesPerRow();
390 int32_t validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
391 for ( int32_t y = 0; y < height; y++ )
393 memcpy( dst, src, validBytes );
397 char * path = config_GetPsz( p_vout, "beos-screenshotpath" );
399 path = strdup( DEFAULT_SCREEN_SHOT_PATH );
401 /* FIXME - we should check which translators are
402 actually available */
403 char * psz_format = config_GetPsz( p_vout, "beos-screenshotformat" );
404 int32_t format = DEFAULT_SCREEN_SHOT_FORMAT;
405 if( !strcmp( psz_format, "TGA" ) )
407 else if( !strcmp( psz_format, "PPM" ) )
409 else if( !strcmp( psz_format, "JPEG" ) )
411 else if( !strcmp( psz_format, "BMP" ) )
414 _SaveScreenShot( temp, path, format );
423 BWindow::MessageReceived( p_message );
428 /*****************************************************************************
430 *****************************************************************************/
432 VideoWindow::Zoom(BPoint origin, float width, float height )
437 /*****************************************************************************
438 * VideoWindow::FrameMoved
439 *****************************************************************************/
441 VideoWindow::FrameMoved(BPoint origin)
448 /*****************************************************************************
449 * VideoWindow::FrameResized
450 *****************************************************************************/
452 VideoWindow::FrameResized( float width, float height )
454 int32_t useWidth = CorrectAspectRatio() ? i_width : fTrueWidth;
455 int32_t useHeight = CorrectAspectRatio() ? i_height : fTrueHeight;
456 float out_width, out_height;
457 float out_left, out_top;
458 float width_scale = width / useWidth;
459 float height_scale = height / useHeight;
461 if (width_scale <= height_scale)
463 out_width = (useWidth * width_scale);
464 out_height = (useHeight * width_scale);
466 out_top = (height - out_height) / 2;
468 else /* if the height is proportionally smaller */
470 out_width = (useWidth * height_scale);
471 out_height = (useHeight * height_scale);
473 out_left = (width - out_width) / 2;
475 view->MoveTo(out_left,out_top);
476 view->ResizeTo(out_width, out_height);
482 /*****************************************************************************
483 * VideoWindow::ScreenChanged
484 *****************************************************************************/
486 VideoWindow::ScreenChanged(BRect frame, color_space format)
488 BScreen screen(this);
490 screen.GetMode(&mode);
491 float refresh = (mode.timing.pixel_clock * 1000)
492 / ((mode.timing.h_total) * (mode.timing.v_total));
493 SetSyncToRetrace(refresh < MIN_AUTO_VSYNC_REFRESH);
496 /*****************************************************************************
497 * VideoWindow::Activate
498 *****************************************************************************/
500 VideoWindow::WindowActivated(bool active)
504 /*****************************************************************************
505 * VideoWindow::drawBuffer
506 *****************************************************************************/
508 VideoWindow::drawBuffer(int bufferIndex)
510 i_buffer = bufferIndex;
512 // sync to the screen if required
513 if (IsSyncedToRetrace())
515 BScreen screen(this);
516 screen.WaitForRetrace(22000);
518 if (fInitStatus >= B_OK && LockLooper())
520 // switch the overlay bitmap
524 view->SetViewOverlay(bitmap[i_buffer],
525 bitmap[i_buffer]->Bounds() ,
528 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
529 B_OVERLAY_TRANSFER_CHANNEL);
530 view->SetViewColor(key);
535 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
541 /*****************************************************************************
542 * VideoWindow::SetInterfaceShowing
543 *****************************************************************************/
545 VideoWindow::ToggleInterfaceShowing()
547 SetInterfaceShowing(!fInterfaceShowing);
550 /*****************************************************************************
551 * VideoWindow::SetInterfaceShowing
552 *****************************************************************************/
554 VideoWindow::SetInterfaceShowing(bool showIt)
556 BWindow* window = get_interface_window();
561 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
562 SetFeel(B_NORMAL_WINDOW_FEEL);
563 window->Activate(true);
568 SetFeel(fCachedFeel);
570 window->SendBehind(this);
572 fInterfaceShowing = showIt;
576 /*****************************************************************************
577 * VideoWindow::SetCorrectAspectRatio
578 *****************************************************************************/
580 VideoWindow::SetCorrectAspectRatio(bool doIt)
582 if (CorrectAspectRatio() != doIt)
585 fSettings->AddFlags(VideoSettings::FLAG_CORRECT_RATIO);
587 fSettings->ClearFlags(VideoSettings::FLAG_CORRECT_RATIO);
588 FrameResized(Bounds().Width(), Bounds().Height());
592 /*****************************************************************************
593 * VideoWindow::CorrectAspectRatio
594 *****************************************************************************/
596 VideoWindow::CorrectAspectRatio() const
598 return fSettings->HasFlags(VideoSettings::FLAG_CORRECT_RATIO);
601 /*****************************************************************************
602 * VideoWindow::ToggleFullScreen
603 *****************************************************************************/
605 VideoWindow::ToggleFullScreen()
607 SetFullScreen(!IsFullScreen());
610 /*****************************************************************************
611 * VideoWindow::SetFullScreen
612 *****************************************************************************/
614 VideoWindow::SetFullScreen(bool doIt)
618 SetLook( B_NO_BORDER_WINDOW_LOOK );
619 BScreen screen(this);
620 BRect rect = screen.Frame();
623 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
624 be_app->ObscureCursor();
625 fInterfaceShowing = false;
626 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
630 SetLook( B_TITLED_WINDOW_LOOK );
631 MoveTo(winSize.left, winSize.top);
632 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
633 be_app->ShowCursor();
634 fInterfaceShowing = true;
635 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
639 /*****************************************************************************
640 * VideoWindow::IsFullScreen
641 *****************************************************************************/
643 VideoWindow::IsFullScreen() const
645 return fSettings->HasFlags(VideoSettings::FLAG_FULL_SCREEN);
648 /*****************************************************************************
649 * VideoWindow::SetSyncToRetrace
650 *****************************************************************************/
652 VideoWindow::SetSyncToRetrace(bool doIt)
655 fSettings->AddFlags(VideoSettings::FLAG_SYNC_RETRACE);
657 fSettings->ClearFlags(VideoSettings::FLAG_SYNC_RETRACE);
660 /*****************************************************************************
661 * VideoWindow::IsSyncedToRetrace
662 *****************************************************************************/
664 VideoWindow::IsSyncedToRetrace() const
666 return fSettings->HasFlags(VideoSettings::FLAG_SYNC_RETRACE);
670 /*****************************************************************************
671 * VideoWindow::_AllocateBuffers
672 *****************************************************************************/
674 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
676 // clear any old buffers
681 BRect bitmapFrame( 0, 0, width, height );
682 // read from config, if we are supposed to use overlay at all
683 int noOverlay = !config_GetInt( p_vout, "overlay" );
684 // test for overlay capability
685 for (int i = 0; i < COLOR_COUNT; i++)
687 if (noOverlay) break;
688 bitmap[0] = new BBitmap ( bitmapFrame,
689 B_BITMAP_WILL_OVERLAY |
690 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
691 colspace[i].colspace);
693 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
697 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
698 colspace[colspace_index].colspace);
699 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
700 colspace[colspace_index].colspace);
701 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
705 view->SetViewOverlay(bitmap[0],
706 bitmap[0]->Bounds() ,
709 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
710 view->SetViewColor(key);
711 SetTitle("VLC " PACKAGE_VERSION " (Overlay)");
717 *mode = BITMAP; // might want to try again with normal bitmaps
727 colspace_index = DEFAULT_COL; // B_RGB32
728 SetTitle( "VLC " PACKAGE_VERSION " (Bitmap)" );
729 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
730 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
731 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
733 // see if everything went well
734 status_t status = B_ERROR;
735 for (int32_t i = 0; i < 3; i++)
738 status = bitmap[i]->InitCheck();
744 // clear bitmaps to black
745 for (int32_t i = 0; i < 3; i++)
746 _BlankBitmap(bitmap[i]);
751 /*****************************************************************************
752 * VideoWindow::_FreeBuffers
753 *****************************************************************************/
755 VideoWindow::_FreeBuffers()
763 fInitStatus = B_ERROR;
766 /*****************************************************************************
767 * VideoWindow::_BlankBitmap
768 *****************************************************************************/
770 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
772 // no error checking (we do that earlier on and since it's a private function...
775 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
778 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
780 // we only handle weird colorspaces with special care
781 switch (bitmap->ColorSpace()) {
783 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
784 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
785 uint8_t* bits = (uint8_t*)bitmap->Bits();
786 int32_t bpr = bitmap->BytesPerRow();
787 for (int32_t y = 0; y < height; y++) {
788 // handle 2 bytes at a time
789 for (int32_t i = 0; i < bpr; i += 2) {
801 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
802 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
803 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
804 uint8_t* bits = (uint8_t*)bitmap->Bits();
805 int32_t bpr = bitmap->BytesPerRow();
806 for (int32_t y = 0; y < height; y += 1) {
807 // handle 3 bytes at a time
808 for (int32_t i = 0; i < bpr; i += 3) {
821 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
822 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
823 uint8_t* bits = (uint8_t*)bitmap->Bits();
824 int32_t bpr = bitmap->BytesPerRow();
825 for (int32_t y = 0; y < height; y += 1) {
826 // handle 2 bytes at a time
827 for (int32_t i = 0; i < bpr; i += 2) {
838 memset(bitmap->Bits(), 0, bitmap->BitsLength());
843 /*****************************************************************************
844 * VideoWindow::_SetVideoSize
845 *****************************************************************************/
847 VideoWindow::_SetVideoSize(uint32_t mode)
849 // let size depend on aspect correction
850 int32_t width = CorrectAspectRatio() ? i_width : fTrueWidth;
851 int32_t height = CorrectAspectRatio() ? i_height : fTrueHeight;
866 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
867 ResizeTo(width, height);
870 /*****************************************************************************
871 * VideoWindow::_SetToSettings
872 *****************************************************************************/
874 VideoWindow::_SetToSettings()
877 uint32_t mode = RESIZE_100;
878 switch (fSettings->VideoSize())
880 case VideoSettings::SIZE_50:
883 case VideoSettings::SIZE_200:
886 case VideoSettings::SIZE_100:
887 case VideoSettings::SIZE_OTHER:
891 bool fullscreen = IsFullScreen(); // remember settings
892 _SetVideoSize(mode); // because this will reset settings
893 // the fullscreen status is reflected in the settings,
894 // but not yet in the windows state
897 if (fSettings->HasFlags(VideoSettings::FLAG_ON_TOP_ALL))
898 fCachedFeel = B_FLOATING_ALL_WINDOW_FEEL;
900 fCachedFeel = B_NORMAL_WINDOW_FEEL;
901 SetFeel(fCachedFeel);
904 /*****************************************************************************
905 * VideoWindow::_SaveScreenShot
906 *****************************************************************************/
908 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
909 uint32_t translatorID ) const
911 // make the info object from the parameters
912 screen_shot_info* info = new screen_shot_info;
913 info->bitmap = bitmap;
915 info->translatorID = translatorID;
916 info->width = CorrectAspectRatio() ? i_width : fTrueWidth;
917 info->height = CorrectAspectRatio() ? i_height : fTrueHeight;
918 // spawn a new thread to take care of the actual saving to disk
919 thread_id thread = spawn_thread( _save_screen_shot,
921 B_LOW_PRIORITY, (void*)info );
922 // start thread or do the job ourself if something went wrong
923 if ( thread < B_OK || resume_thread( thread ) < B_OK )
924 _save_screen_shot( (void*)info );
927 /*****************************************************************************
928 * VideoWindow::_save_screen_shot
929 *****************************************************************************/
931 VideoWindow::_save_screen_shot( void* cookie )
933 screen_shot_info* info = (screen_shot_info*)cookie;
934 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
936 // try to be as quick as possible creating the file (the user might have
937 // taken the next screen shot already!)
938 // make sure we have a unique name for the screen shot
939 BString path( info->path );
940 // create the folder if it doesn't exist
941 BString folder( info->path );
942 create_directory( folder.String(), 0777 );
943 path << "/vlc screenshot";
944 BEntry entry( path.String() );
945 int32_t appendedNumber = 0;
946 if ( entry.Exists() && !entry.IsSymLink() )
948 // we would clobber an existing entry
949 bool foundUniqueName = false;
951 while ( !foundUniqueName ) {
952 BString newName( path.String() );
953 newName << " " << appendedNumber;
954 BEntry possiblyClobberedEntry( newName.String() );
955 if ( possiblyClobberedEntry.Exists()
956 && !possiblyClobberedEntry.IsSymLink() )
959 foundUniqueName = true;
962 if ( appendedNumber > 0 )
963 path << " " << appendedNumber;
964 // there is still a slight chance to clobber an existing
965 // file (if it was created in the "meantime"), but we take it...
966 BFile outFile( path.String(),
967 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
969 // make colorspace converted copy of bitmap
970 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
972 status_t status = convert_bitmap( info->bitmap, converted );
973 if ( status == B_OK )
975 BTranslatorRoster* roster = BTranslatorRoster::Default();
976 uint32_t imageFormat = 0;
977 translator_id translator = 0;
980 // find suitable translator
981 translator_id* ids = NULL;
984 status = roster->GetAllTranslators( &ids, &count );
985 if ( status >= B_OK )
987 for ( int tix = 0; tix < count; tix++ )
989 const translation_format *formats = NULL;
990 int32 num_formats = 0;
992 status = roster->GetInputFormats( ids[tix],
993 &formats, &num_formats );
996 for ( int iix = 0; iix < num_formats; iix++ )
998 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
1007 status = roster->GetOutputFormats( ids[tix],
1008 &formats, &num_formats);
1009 if ( status >= B_OK )
1011 for ( int32_t oix = 0; oix < num_formats; oix++ )
1013 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
1015 if ( formats[oix].type == info->translatorID )
1018 imageFormat = formats[oix].type;
1019 translator = ids[tix];
1030 // make bitmap stream
1031 BBitmapStream outStream( converted );
1033 status = outFile.InitCheck();
1034 if (status == B_OK) {
1035 status = roster->Translate( &outStream, NULL, NULL,
1036 &outFile, imageFormat );
1037 if ( status == B_OK )
1039 BNodeInfo nodeInfo( &outFile );
1040 if ( nodeInfo.InitCheck() == B_OK )
1042 translation_format* formats;
1044 status = roster->GetOutputFormats( translator,
1045 (const translation_format **) &formats,
1047 if ( status >= B_OK )
1049 const char * mime = NULL;
1050 for ( int ix = 0; ix < count; ix++ ) {
1051 if ( formats[ix].type == imageFormat ) {
1052 mime = formats[ix].MIME;
1057 nodeInfo.SetType( mime );
1062 outStream.DetachBitmap( &converted );
1070 delete info->bitmap;
1078 /*****************************************************************************
1080 *****************************************************************************/
1081 VLCView::VLCView(BRect bounds, vout_thread_t *p_vout_instance )
1082 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
1083 fLastMouseMovedTime(system_time()),
1084 fCursorHidden(false),
1085 fCursorInside(false),
1086 fIgnoreDoubleClick(false)
1088 p_vout = p_vout_instance;
1089 SetViewColor(B_TRANSPARENT_32_BIT);
1092 /*****************************************************************************
1094 *****************************************************************************/
1099 /*****************************************************************************
1100 * VLCVIew::AttachedToWindow
1101 *****************************************************************************/
1103 VLCView::AttachedToWindow()
1105 // in order to get keyboard events
1107 // periodically check if we want to hide the pointer
1108 Window()->SetPulseRate(1000000);
1111 /*****************************************************************************
1112 * VLCVIew::MouseDown
1113 *****************************************************************************/
1115 VLCView::MouseDown(BPoint where)
1117 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
1118 BMessage* msg = Window()->CurrentMessage();
1121 msg->FindInt32("clicks", &clicks);
1122 msg->FindInt32("buttons", (int32*)&buttons);
1126 if (buttons & B_PRIMARY_MOUSE_BUTTON)
1128 if (clicks == 2 && !fIgnoreDoubleClick)
1131 videoWindow->ToggleInterfaceShowing(); */
1132 fIgnoreDoubleClick = false;
1136 if (buttons & B_SECONDARY_MOUSE_BUTTON)
1138 // clicks will be 2 next time (if interval short enough)
1139 // even if the first click and the second
1140 // have not been made with the same mouse button
1141 fIgnoreDoubleClick = true;
1142 // launch popup menu
1143 BPopUpMenu *menu = new BPopUpMenu("context menu");
1144 menu->SetRadioMode(false);
1145 // In full screen, add an item to show/hide the interface
1146 if( videoWindow->IsFullScreen() )
1148 BMenuItem *intfItem =
1149 new BMenuItem( _("Show Interface"), new BMessage(SHOW_INTERFACE) );
1150 menu->AddItem( intfItem );
1153 BMenuItem *halfItem = new BMenuItem(_("50%"), new BMessage(RESIZE_50));
1154 menu->AddItem(halfItem);
1156 BMenuItem *origItem = new BMenuItem(_("100%"), new BMessage(RESIZE_100));
1157 menu->AddItem(origItem);
1159 BMenuItem *doubleItem = new BMenuItem(_("200%"), new BMessage(RESIZE_200));
1160 menu->AddItem(doubleItem);
1161 // Toggle FullScreen
1162 BMenuItem *zoomItem = new BMenuItem(_("Fullscreen"), new BMessage(TOGGLE_FULL_SCREEN));
1163 zoomItem->SetMarked(videoWindow->IsFullScreen());
1164 menu->AddItem(zoomItem);
1166 menu->AddSeparatorItem();
1169 BMenuItem *vsyncItem = new BMenuItem(_("Vertical Sync"), new BMessage(VERT_SYNC));
1170 vsyncItem->SetMarked(videoWindow->IsSyncedToRetrace());
1171 menu->AddItem(vsyncItem);
1172 // Correct Aspect Ratio
1173 BMenuItem *aspectItem = new BMenuItem(_("Correct Aspect Ratio"), new BMessage(ASPECT_CORRECT));
1174 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
1175 menu->AddItem(aspectItem);
1177 menu->AddSeparatorItem();
1179 // Windwo Feel Items
1180 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
1181 winNormFeel->AddInt32("WinFeel", (int32_t)B_NORMAL_WINDOW_FEEL);
1182 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
1183 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
1184 menu->AddItem(normWindItem);
1186 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
1187 winFloatFeel->AddInt32("WinFeel", (int32_t)B_FLOATING_APP_WINDOW_FEEL);
1188 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
1189 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
1190 menu->AddItem(onTopWindItem);
1192 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
1193 winAllFeel->AddInt32("WinFeel", (int32_t)B_FLOATING_ALL_WINDOW_FEEL);
1194 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
1195 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
1196 menu->AddItem(allSpacesWindItem);*/
1198 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
1199 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
1200 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
1201 windowFeelMsg->AddInt32( "WinFeel", (int32_t)feel );
1202 BMenuItem *windowFeelItem = new BMenuItem( _("Stay On Top"), windowFeelMsg );
1203 windowFeelItem->SetMarked( onTop );
1204 menu->AddItem( windowFeelItem );
1206 menu->AddSeparatorItem();
1208 BMenuItem* screenShotItem = new BMenuItem( _("Take Screen Shot"),
1209 new BMessage( SCREEN_SHOT ) );
1210 menu->AddItem( screenShotItem );
1212 menu->SetTargetForItems( this );
1213 ConvertToScreen( &where );
1214 BRect mouseRect( where.x - 5, where.y - 5,
1215 where.x + 5, where.y + 5 );
1216 menu->Go( where, true, false, mouseRect, true );
1220 fLastMouseMovedTime = system_time();
1221 fCursorHidden = false;
1224 /*****************************************************************************
1226 *****************************************************************************/
1228 VLCView::MouseUp( BPoint where )
1231 val.b_bool = VLC_TRUE;
1232 var_Set( p_vout, "mouse-clicked", val );
1235 /*****************************************************************************
1236 * VLCVIew::MouseMoved
1237 *****************************************************************************/
1239 VLCView::MouseMoved(BPoint point, uint32_t transit, const BMessage* dragMessage)
1241 fLastMouseMovedTime = system_time();
1242 fCursorHidden = false;
1243 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1244 /* DVD navigation */
1245 unsigned int i_width, i_height, i_x, i_y;
1246 vout_PlacePicture( p_vout, (unsigned int)Bounds().Width(),
1247 (unsigned int)Bounds().Height(),
1248 &i_x, &i_y, &i_width, &i_height );
1250 val.i_int = ( (int)point.x - i_x ) * p_vout->render.i_width / i_width;
1251 var_Set( p_vout, "mouse-x", val );
1252 val.i_int = ( (int)point.y - i_y ) * p_vout->render.i_height / i_height;
1253 var_Set( p_vout, "mouse-y", val );
1254 val.b_bool = VLC_TRUE;
1255 var_Set( p_vout, "mouse-moved", val );
1258 /*****************************************************************************
1260 *****************************************************************************/
1264 // We are getting the pulse messages no matter if the mouse is over
1265 // this view. If we are in full screen mode, we want to hide the cursor
1266 // even if it is not.
1267 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1271 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1273 be_app->ObscureCursor();
1274 fCursorHidden = true;
1276 // hide the interface window as well if full screen
1277 if (videoWindow && videoWindow->IsFullScreen())
1278 videoWindow->SetInterfaceShowing(false);
1282 // Workaround to disable the screensaver in full screen:
1283 // we simulate an activity every 29 seconds
1284 if( videoWindow && videoWindow->IsFullScreen() &&
1285 system_time() - fLastMouseMovedTime > 29000000 )
1289 GetMouse(&where, &buttons, false);
1290 ConvertToScreen(&where);
1291 set_mouse_position((int32_t) where.x, (int32_t) where.y);
1295 /*****************************************************************************
1297 *****************************************************************************/
1298 void VLCView::KeyDown( const char *bytes, int32 numBytes )
1300 VideoWindow * videoWindow = (VideoWindow *) Window();
1302 if( !videoWindow || numBytes < 1 )
1307 uint32_t mods = modifiers();
1315 val.i_int |= ConvertKey( *bytes );
1316 var_Set( p_vout->p_vlc, "key-pressed", val );
1321 /*****************************************************************************
1323 *****************************************************************************/
1325 VLCView::Draw(BRect updateRect)
1327 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1328 if ( window && window->mode == BITMAP )
1329 FillRect( updateRect );
1332 /*****************************************************************************
1334 *****************************************************************************/
1335 static int Init ( vout_thread_t * );
1336 static void End ( vout_thread_t * );
1337 // static int Manage ( vout_thread_t * );
1338 static void Display ( vout_thread_t *, picture_t * );
1340 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1341 static void BeosCloseDisplay( vout_thread_t *p_vout );
1343 /*****************************************************************************
1344 * OpenVideo: allocates BeOS video thread output method
1345 *****************************************************************************
1346 * This function allocates and initializes a BeOS vout method.
1347 *****************************************************************************/
1348 int E_(OpenVideo) ( vlc_object_t *p_this )
1350 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1352 /* Allocate structure */
1353 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1354 if( p_vout->p_sys == NULL )
1356 msg_Err( p_vout, "out of memory" );
1359 p_vout->p_sys->i_width = p_vout->render.i_width;
1360 p_vout->p_sys->i_height = p_vout->render.i_height;
1361 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1363 p_vout->pf_init = Init;
1364 p_vout->pf_end = End;
1365 p_vout->pf_manage = NULL;
1366 p_vout->pf_render = NULL;
1367 p_vout->pf_display = Display;
1372 /*****************************************************************************
1373 * Init: initialize BeOS video thread output method
1374 *****************************************************************************/
1375 int Init( vout_thread_t *p_vout )
1380 I_OUTPUTPICTURES = 0;
1382 /* Open and initialize device */
1383 if( BeosOpenDisplay( p_vout ) )
1385 msg_Err(p_vout, "vout error: can't open display");
1388 p_vout->output.i_width = p_vout->render.i_width;
1389 p_vout->output.i_height = p_vout->render.i_height;
1391 /* Assume we have square pixels */
1392 p_vout->output.i_aspect = p_vout->p_sys->i_width
1393 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1394 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1395 p_vout->p_sys->i_index = 0;
1397 p_vout->b_direct = 1;
1399 p_vout->output.i_rmask = 0x00ff0000;
1400 p_vout->output.i_gmask = 0x0000ff00;
1401 p_vout->output.i_bmask = 0x000000ff;
1403 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1406 /* Find an empty picture slot */
1407 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1410 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1412 p_pic = p_vout->p_picture + i_index;
1421 p_pic->p->p_pixels = (uint8_t*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1422 p_pic->p->i_lines = p_vout->p_sys->i_height;
1424 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1425 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1426 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1427 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1429 p_pic->i_status = DESTROYED_PICTURE;
1430 p_pic->i_type = DIRECT_PICTURE;
1432 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1440 /*****************************************************************************
1441 * End: terminate BeOS video thread output method
1442 *****************************************************************************/
1443 void End( vout_thread_t *p_vout )
1445 BeosCloseDisplay( p_vout );
1448 /*****************************************************************************
1449 * CloseVideo: destroy BeOS video thread output method
1450 *****************************************************************************
1451 * Terminate an output method created by DummyCreateOutputMethod
1452 *****************************************************************************/
1453 void E_(CloseVideo) ( vlc_object_t *p_this )
1455 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1457 free( p_vout->p_sys );
1460 /*****************************************************************************
1461 * Display: displays previously rendered output
1462 *****************************************************************************
1463 * This function send the currently rendered image to BeOS image, waits until
1464 * it is displayed and switch the two rendering buffers, preparing next frame.
1465 *****************************************************************************/
1466 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1468 VideoWindow * p_win = p_vout->p_sys->p_window;
1470 /* draw buffer if required */
1471 if (!p_win->teardownwindow)
1473 p_win->drawBuffer(p_vout->p_sys->i_index);
1476 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1477 p_pic->p->p_pixels = (uint8_t*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1480 /* following functions are local */
1482 /*****************************************************************************
1483 * BeosOpenDisplay: open and initialize BeOS device
1484 *****************************************************************************/
1485 static int BeosOpenDisplay( vout_thread_t *p_vout )
1488 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1489 p_vout->p_sys->i_height - 1,
1491 20 + p_vout->i_window_width - 1,
1492 50 + p_vout->i_window_height - 1 ),
1494 if( p_vout->p_sys->p_window == NULL )
1496 msg_Err( p_vout, "cannot allocate VideoWindow" );
1501 p_vout->p_sys->p_window->Show();
1507 /*****************************************************************************
1508 * BeosDisplay: close and reset BeOS device
1509 *****************************************************************************
1510 * Returns all resources allocated by BeosOpenDisplay and restore the original
1511 * state of the device.
1512 *****************************************************************************/
1513 static void BeosCloseDisplay( vout_thread_t *p_vout )
1515 VideoWindow * p_win = p_vout->p_sys->p_window;
1516 /* Destroy the video window */
1517 if( p_win != NULL && !p_win->teardownwindow)
1520 p_win->teardownwindow = true;