1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.24 2003/11/04 11:11:30 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>
53 #include "InterfaceWindow.h" // for load/save_settings()
54 #include "DrawingTidbits.h"
57 #include "VideoWindow.h"
59 /*****************************************************************************
60 * vout_sys_t: BeOS video output method descriptor
61 *****************************************************************************
62 * This structure is part of the video output thread descriptor.
63 * It describes the BeOS specific properties of an output thread.
64 *****************************************************************************/
67 VideoWindow * p_window;
72 // uint8_t *pp_buffer[3];
73 uint32_t source_chroma;
78 #define MOUSE_IDLE_TIMEOUT 2000000 // two seconds
79 #define MIN_AUTO_VSYNC_REFRESH 61 // Hz
80 #define DEFAULT_SCREEN_SHOT_FORMAT 'PNG '
81 #define DEFAULT_SCREEN_SHOT_PATH "/boot/home/vlc screenshot"
83 /*****************************************************************************
84 * beos_GetAppWindow : retrieve a BWindow pointer from the window name
85 *****************************************************************************/
87 beos_GetAppWindow(char *name)
92 for (index = 0 ; ; index++)
94 window = be_app->WindowAt(index);
97 if (window->LockWithTimeout(20000) == B_OK)
99 if (strcmp(window->Name(), name) == 0)
110 /*****************************************************************************
111 * get_interface_window
112 *****************************************************************************/
114 get_interface_window()
116 return beos_GetAppWindow( "VLC " PACKAGE_VERSION );
119 class BackgroundView : public BView
122 BackgroundView(BRect frame, VLCView* view)
123 : BView(frame, "background",
124 B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE),
127 SetViewColor(kBlack);
129 virtual ~BackgroundView() {}
131 virtual void MouseDown(BPoint where)
133 // convert coordinates
134 where = fVideoView->ConvertFromParent(where);
136 fVideoView->MouseDown(where);
138 virtual void MouseMoved(BPoint where, uint32_t transit,
139 const BMessage* dragMessage)
141 // convert coordinates
142 where = fVideoView->ConvertFromParent(where);
144 fVideoView->MouseMoved(where, transit, dragMessage);
145 // notice: It might look like transit should be
146 // B_OUTSIDE_VIEW regardless, but leave it like this,
147 // otherwise, unwanted things will happen!
155 /*****************************************************************************
156 * VideoSettings constructor and destructor
157 *****************************************************************************/
158 VideoSettings::VideoSettings()
159 : fVideoSize( SIZE_100 ),
160 fFlags( FLAG_CORRECT_RATIO ),
161 fSettings( new BMessage( 'sett' ) )
163 // read settings from disk
164 status_t ret = load_settings( fSettings, "video_settings", "VideoLAN Client" );
168 if ( fSettings->FindInt32( "flags", (int32*)&flags ) == B_OK )
171 if ( fSettings->FindInt32( "video size", (int32*)&size ) == B_OK )
172 SetVideoSize( size );
176 fprintf( stderr, "error loading video settings: %s\n", strerror( ret ) );
178 // figure out if we should use vertical sync by default
179 BScreen screen(B_MAIN_SCREEN_ID);
180 if (screen.IsValid())
183 screen.GetMode(&mode);
184 float refresh = (mode.timing.pixel_clock * 1000)
185 / ((mode.timing.h_total)* (mode.timing.v_total));
186 if (refresh < MIN_AUTO_VSYNC_REFRESH)
187 AddFlags(FLAG_SYNC_RETRACE);
192 VideoSettings::VideoSettings( const VideoSettings& clone )
193 : fVideoSize( clone.VideoSize() ),
194 fFlags( clone.Flags() ),
200 VideoSettings::~VideoSettings()
204 // we are the default settings
205 // and write our settings to disk
206 if (fSettings->ReplaceInt32( "video size", VideoSize() ) != B_OK)
207 fSettings->AddInt32( "video size", VideoSize() );
208 if (fSettings->ReplaceInt32( "flags", Flags() ) != B_OK)
209 fSettings->AddInt32( "flags", Flags() );
211 status_t ret = save_settings( fSettings, "video_settings", "VideoLAN Client" );
213 fprintf( stderr, "error saving video settings: %s\n", strerror( ret ) );
218 // we are just a clone of the default settings
219 fDefaultSettings.SetVideoSize( VideoSize() );
220 fDefaultSettings.SetFlags( Flags() );
224 /*****************************************************************************
225 * VideoSettings::DefaultSettings
226 *****************************************************************************/
228 VideoSettings::DefaultSettings()
230 return &fDefaultSettings;
233 /*****************************************************************************
234 * VideoSettings::SetVideoSize
235 *****************************************************************************/
237 VideoSettings::SetVideoSize( uint32_t mode )
242 // static variable initialization
244 VideoSettings::fDefaultSettings;
247 /*****************************************************************************
248 * VideoWindow constructor and destructor
249 *****************************************************************************/
250 VideoWindow::VideoWindow(int v_width, int v_height, BRect frame,
251 vout_thread_t *p_videoout)
252 : BWindow(frame, NULL, B_TITLED_WINDOW, B_NOT_CLOSABLE | B_NOT_MINIMIZABLE),
253 i_width(frame.IntegerWidth()),
254 i_height(frame.IntegerHeight()),
257 teardownwindow(false),
259 fTrueHeight(v_height),
260 fCachedFeel(B_NORMAL_WINDOW_FEEL),
261 fInterfaceShowing(false),
262 fInitStatus(B_ERROR),
263 fSettings(new VideoSettings(*VideoSettings::DefaultSettings()))
267 // create the view to do the display
268 view = new VLCView( Bounds(), p_vout );
270 // create background view
271 BView *mainView = new BackgroundView( Bounds(), view );
273 mainView->AddChild(view);
275 // allocate bitmap buffers
276 for (int32_t i = 0; i < 3; i++)
278 fInitStatus = _AllocateBuffers(v_width, v_height, &mode);
280 // make sure we layout the view correctly
281 FrameResized(i_width, i_height);
283 if (fInitStatus >= B_OK && mode == OVERLAY)
285 overlay_restrictions r;
287 bitmap[1]->GetOverlayRestrictions(&r);
288 SetSizeLimits((i_width * r.min_width_scale), i_width * r.max_width_scale,
289 (i_height * r.min_height_scale), i_height * r.max_height_scale);
292 // vlc settings override settings from disk
293 if (config_GetInt(p_vout, "fullscreen"))
294 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
296 // add a few useful shortcuts
297 AddShortcut( 'f', 0, new BMessage( TOGGLE_FULL_SCREEN ) );
298 AddShortcut( '1', 0, new BMessage( RESIZE_50 ) );
299 AddShortcut( '2', 0, new BMessage( RESIZE_100 ) );
300 AddShortcut( '3', 0, new BMessage( RESIZE_200 ) );
302 // workaround for french keyboards
303 AddShortcut( '&', 0, new BMessage( RESIZE_50 ) );
304 AddShortcut( 'é', 0, new BMessage( RESIZE_100 ) );
305 // FIXME - this one doesn't work because 'é' is a multi-byte character
306 AddShortcut( '"', 0, new BMessage( RESIZE_200 ) );
311 VideoWindow::~VideoWindow()
315 teardownwindow = true;
316 wait_for_thread(fDrawThreadID, &result);
321 /*****************************************************************************
322 * VideoWindow::MessageReceived
323 *****************************************************************************/
325 VideoWindow::MessageReceived( BMessage *p_message )
327 switch( p_message->what )
330 SetInterfaceShowing( true );
332 case TOGGLE_FULL_SCREEN:
340 _SetVideoSize(p_message->what);
343 SetSyncToRetrace(!IsSyncedToRetrace());
348 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
351 fCachedFeel = winFeel;
352 if (winFeel == B_FLOATING_ALL_WINDOW_FEEL)
353 fSettings->AddFlags(VideoSettings::FLAG_ON_TOP_ALL);
355 fSettings->ClearFlags(VideoSettings::FLAG_ON_TOP_ALL);
360 SetCorrectAspectRatio(!CorrectAspectRatio());
363 // save a screen shot
364 if ( BBitmap* current = bitmap[i_buffer] )
366 // the following line might be tempting, but does not work for some overlay bitmaps!!!
367 // BBitmap* temp = new BBitmap( current );
368 // so we clone the bitmap ourselves
369 // however, we need to take care of potentially different padding!
370 // memcpy() is slow when reading from grafix memory, but what the heck...
371 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
372 if ( temp && temp->IsValid() )
374 int32_t height = (int32_t)current->Bounds().Height();
375 uint8_t* dst = (uint8_t*)temp->Bits();
376 uint8_t* src = (uint8_t*)current->Bits();
377 int32_t dstBpr = temp->BytesPerRow();
378 int32_t srcBpr = current->BytesPerRow();
379 int32_t validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
380 for ( int32_t y = 0; y < height; y++ )
382 memcpy( dst, src, validBytes );
386 char * path = config_GetPsz( p_vout, "beos-screenshotpath" );
388 path = strdup( DEFAULT_SCREEN_SHOT_PATH );
390 /* FIXME - we should check which translators are
391 actually available */
392 char * psz_format = config_GetPsz( p_vout, "beos-screenshotformat" );
393 int32_t format = DEFAULT_SCREEN_SHOT_FORMAT;
394 if( !strcmp( psz_format, "TGA" ) )
396 else if( !strcmp( psz_format, "PPM" ) )
398 else if( !strcmp( psz_format, "JPEG" ) )
400 else if( !strcmp( psz_format, "BMP" ) )
403 _SaveScreenShot( temp, path, format );
412 BWindow::MessageReceived( p_message );
417 /*****************************************************************************
419 *****************************************************************************/
421 VideoWindow::Zoom(BPoint origin, float width, float height )
426 /*****************************************************************************
427 * VideoWindow::FrameMoved
428 *****************************************************************************/
430 VideoWindow::FrameMoved(BPoint origin)
437 /*****************************************************************************
438 * VideoWindow::FrameResized
439 *****************************************************************************/
441 VideoWindow::FrameResized( float width, float height )
443 int32_t useWidth = CorrectAspectRatio() ? i_width : fTrueWidth;
444 int32_t useHeight = CorrectAspectRatio() ? i_height : fTrueHeight;
445 float out_width, out_height;
446 float out_left, out_top;
447 float width_scale = width / useWidth;
448 float height_scale = height / useHeight;
450 if (width_scale <= height_scale)
452 out_width = (useWidth * width_scale);
453 out_height = (useHeight * width_scale);
455 out_top = (height - out_height) / 2;
457 else /* if the height is proportionally smaller */
459 out_width = (useWidth * height_scale);
460 out_height = (useHeight * height_scale);
462 out_left = (width - out_width) / 2;
464 view->MoveTo(out_left,out_top);
465 view->ResizeTo(out_width, out_height);
471 /*****************************************************************************
472 * VideoWindow::ScreenChanged
473 *****************************************************************************/
475 VideoWindow::ScreenChanged(BRect frame, color_space format)
477 BScreen screen(this);
479 screen.GetMode(&mode);
480 float refresh = (mode.timing.pixel_clock * 1000)
481 / ((mode.timing.h_total) * (mode.timing.v_total));
482 SetSyncToRetrace(refresh < MIN_AUTO_VSYNC_REFRESH);
485 /*****************************************************************************
486 * VideoWindow::Activate
487 *****************************************************************************/
489 VideoWindow::WindowActivated(bool active)
493 /*****************************************************************************
494 * VideoWindow::drawBuffer
495 *****************************************************************************/
497 VideoWindow::drawBuffer(int bufferIndex)
499 i_buffer = bufferIndex;
501 // sync to the screen if required
502 if (IsSyncedToRetrace())
504 BScreen screen(this);
505 screen.WaitForRetrace(22000);
507 if (fInitStatus >= B_OK && LockLooper())
509 // switch the overlay bitmap
513 view->SetViewOverlay(bitmap[i_buffer],
514 bitmap[i_buffer]->Bounds() ,
517 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
518 B_OVERLAY_TRANSFER_CHANNEL);
519 view->SetViewColor(key);
524 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
530 /*****************************************************************************
531 * VideoWindow::SetInterfaceShowing
532 *****************************************************************************/
534 VideoWindow::ToggleInterfaceShowing()
536 SetInterfaceShowing(!fInterfaceShowing);
539 /*****************************************************************************
540 * VideoWindow::SetInterfaceShowing
541 *****************************************************************************/
543 VideoWindow::SetInterfaceShowing(bool showIt)
545 BWindow* window = get_interface_window();
550 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
551 SetFeel(B_NORMAL_WINDOW_FEEL);
552 window->Activate(true);
557 SetFeel(fCachedFeel);
559 window->SendBehind(this);
561 fInterfaceShowing = showIt;
565 /*****************************************************************************
566 * VideoWindow::SetCorrectAspectRatio
567 *****************************************************************************/
569 VideoWindow::SetCorrectAspectRatio(bool doIt)
571 if (CorrectAspectRatio() != doIt)
574 fSettings->AddFlags(VideoSettings::FLAG_CORRECT_RATIO);
576 fSettings->ClearFlags(VideoSettings::FLAG_CORRECT_RATIO);
577 FrameResized(Bounds().Width(), Bounds().Height());
581 /*****************************************************************************
582 * VideoWindow::CorrectAspectRatio
583 *****************************************************************************/
585 VideoWindow::CorrectAspectRatio() const
587 return fSettings->HasFlags(VideoSettings::FLAG_CORRECT_RATIO);
590 /*****************************************************************************
591 * VideoWindow::ToggleFullScreen
592 *****************************************************************************/
594 VideoWindow::ToggleFullScreen()
596 SetFullScreen(!IsFullScreen());
599 /*****************************************************************************
600 * VideoWindow::SetFullScreen
601 *****************************************************************************/
603 VideoWindow::SetFullScreen(bool doIt)
607 SetLook( B_NO_BORDER_WINDOW_LOOK );
608 BScreen screen(this);
609 BRect rect = screen.Frame();
612 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
613 be_app->ObscureCursor();
614 fInterfaceShowing = false;
615 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
619 SetLook( B_TITLED_WINDOW_LOOK );
620 MoveTo(winSize.left, winSize.top);
621 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
622 be_app->ShowCursor();
623 fInterfaceShowing = true;
624 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
628 /*****************************************************************************
629 * VideoWindow::IsFullScreen
630 *****************************************************************************/
632 VideoWindow::IsFullScreen() const
634 return fSettings->HasFlags(VideoSettings::FLAG_FULL_SCREEN);
637 /*****************************************************************************
638 * VideoWindow::SetSyncToRetrace
639 *****************************************************************************/
641 VideoWindow::SetSyncToRetrace(bool doIt)
644 fSettings->AddFlags(VideoSettings::FLAG_SYNC_RETRACE);
646 fSettings->ClearFlags(VideoSettings::FLAG_SYNC_RETRACE);
649 /*****************************************************************************
650 * VideoWindow::IsSyncedToRetrace
651 *****************************************************************************/
653 VideoWindow::IsSyncedToRetrace() const
655 return fSettings->HasFlags(VideoSettings::FLAG_SYNC_RETRACE);
659 /*****************************************************************************
660 * VideoWindow::_AllocateBuffers
661 *****************************************************************************/
663 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
665 // clear any old buffers
670 BRect bitmapFrame( 0, 0, width, height );
671 // read from config, if we are supposed to use overlay at all
672 int noOverlay = !config_GetInt( p_vout, "overlay" );
673 // test for overlay capability
674 for (int i = 0; i < COLOR_COUNT; i++)
676 if (noOverlay) break;
677 bitmap[0] = new BBitmap ( bitmapFrame,
678 B_BITMAP_WILL_OVERLAY |
679 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
680 colspace[i].colspace);
682 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
686 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
687 colspace[colspace_index].colspace);
688 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
689 colspace[colspace_index].colspace);
690 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
694 view->SetViewOverlay(bitmap[0],
695 bitmap[0]->Bounds() ,
698 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
699 view->SetViewColor(key);
700 SetTitle("VLC " PACKAGE_VERSION " (Overlay)");
706 *mode = BITMAP; // might want to try again with normal bitmaps
716 colspace_index = DEFAULT_COL; // B_RGB32
717 SetTitle( "VLC " PACKAGE_VERSION " (Bitmap)" );
718 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
719 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
720 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
722 // see if everything went well
723 status_t status = B_ERROR;
724 for (int32_t i = 0; i < 3; i++)
727 status = bitmap[i]->InitCheck();
733 // clear bitmaps to black
734 for (int32_t i = 0; i < 3; i++)
735 _BlankBitmap(bitmap[i]);
740 /*****************************************************************************
741 * VideoWindow::_FreeBuffers
742 *****************************************************************************/
744 VideoWindow::_FreeBuffers()
752 fInitStatus = B_ERROR;
755 /*****************************************************************************
756 * VideoWindow::_BlankBitmap
757 *****************************************************************************/
759 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
761 // no error checking (we do that earlier on and since it's a private function...
764 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
767 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
769 // we only handle weird colorspaces with special care
770 switch (bitmap->ColorSpace()) {
772 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
773 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
774 uint8_t* bits = (uint8_t*)bitmap->Bits();
775 int32_t bpr = bitmap->BytesPerRow();
776 for (int32_t y = 0; y < height; y++) {
777 // handle 2 bytes at a time
778 for (int32_t i = 0; i < bpr; i += 2) {
790 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
791 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
792 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
793 uint8_t* bits = (uint8_t*)bitmap->Bits();
794 int32_t bpr = bitmap->BytesPerRow();
795 for (int32_t y = 0; y < height; y += 1) {
796 // handle 3 bytes at a time
797 for (int32_t i = 0; i < bpr; i += 3) {
810 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
811 int32_t height = bitmap->Bounds().IntegerHeight() + 1;
812 uint8_t* bits = (uint8_t*)bitmap->Bits();
813 int32_t bpr = bitmap->BytesPerRow();
814 for (int32_t y = 0; y < height; y += 1) {
815 // handle 2 bytes at a time
816 for (int32_t i = 0; i < bpr; i += 2) {
827 memset(bitmap->Bits(), 0, bitmap->BitsLength());
832 /*****************************************************************************
833 * VideoWindow::_SetVideoSize
834 *****************************************************************************/
836 VideoWindow::_SetVideoSize(uint32_t mode)
838 // let size depend on aspect correction
839 int32_t width = CorrectAspectRatio() ? i_width : fTrueWidth;
840 int32_t height = CorrectAspectRatio() ? i_height : fTrueHeight;
855 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
856 ResizeTo(width, height);
859 /*****************************************************************************
860 * VideoWindow::_SetToSettings
861 *****************************************************************************/
863 VideoWindow::_SetToSettings()
866 uint32_t mode = RESIZE_100;
867 switch (fSettings->VideoSize())
869 case VideoSettings::SIZE_50:
872 case VideoSettings::SIZE_200:
875 case VideoSettings::SIZE_100:
876 case VideoSettings::SIZE_OTHER:
880 bool fullscreen = IsFullScreen(); // remember settings
881 _SetVideoSize(mode); // because this will reset settings
882 // the fullscreen status is reflected in the settings,
883 // but not yet in the windows state
886 if (fSettings->HasFlags(VideoSettings::FLAG_ON_TOP_ALL))
887 fCachedFeel = B_FLOATING_ALL_WINDOW_FEEL;
889 fCachedFeel = B_NORMAL_WINDOW_FEEL;
890 SetFeel(fCachedFeel);
893 /*****************************************************************************
894 * VideoWindow::_SaveScreenShot
895 *****************************************************************************/
897 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
898 uint32_t translatorID ) const
900 // make the info object from the parameters
901 screen_shot_info* info = new screen_shot_info;
902 info->bitmap = bitmap;
904 info->translatorID = translatorID;
905 info->width = CorrectAspectRatio() ? i_width : fTrueWidth;
906 info->height = CorrectAspectRatio() ? i_height : fTrueHeight;
907 // spawn a new thread to take care of the actual saving to disk
908 thread_id thread = spawn_thread( _save_screen_shot,
910 B_LOW_PRIORITY, (void*)info );
911 // start thread or do the job ourself if something went wrong
912 if ( thread < B_OK || resume_thread( thread ) < B_OK )
913 _save_screen_shot( (void*)info );
916 /*****************************************************************************
917 * VideoWindow::_save_screen_shot
918 *****************************************************************************/
920 VideoWindow::_save_screen_shot( void* cookie )
922 screen_shot_info* info = (screen_shot_info*)cookie;
923 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
925 // try to be as quick as possible creating the file (the user might have
926 // taken the next screen shot already!)
927 // make sure we have a unique name for the screen shot
928 BString path( info->path );
929 // create the folder if it doesn't exist
930 BString folder( info->path );
931 create_directory( folder.String(), 0777 );
932 path << "/vlc screenshot";
933 BEntry entry( path.String() );
934 int32_t appendedNumber = 0;
935 if ( entry.Exists() && !entry.IsSymLink() )
937 // we would clobber an existing entry
938 bool foundUniqueName = false;
940 while ( !foundUniqueName ) {
941 BString newName( path.String() );
942 newName << " " << appendedNumber;
943 BEntry possiblyClobberedEntry( newName.String() );
944 if ( possiblyClobberedEntry.Exists()
945 && !possiblyClobberedEntry.IsSymLink() )
948 foundUniqueName = true;
951 if ( appendedNumber > 0 )
952 path << " " << appendedNumber;
953 // there is still a slight chance to clobber an existing
954 // file (if it was created in the "meantime"), but we take it...
955 BFile outFile( path.String(),
956 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
958 // make colorspace converted copy of bitmap
959 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
961 status_t status = convert_bitmap( info->bitmap, converted );
962 if ( status == B_OK )
964 BTranslatorRoster* roster = BTranslatorRoster::Default();
965 uint32_t imageFormat = 0;
966 translator_id translator = 0;
969 // find suitable translator
970 translator_id* ids = NULL;
973 status = roster->GetAllTranslators( &ids, &count );
974 if ( status >= B_OK )
976 for ( int tix = 0; tix < count; tix++ )
978 const translation_format *formats = NULL;
979 int32 num_formats = 0;
981 status = roster->GetInputFormats( ids[tix],
982 &formats, &num_formats );
985 for ( int iix = 0; iix < num_formats; iix++ )
987 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
996 status = roster->GetOutputFormats( ids[tix],
997 &formats, &num_formats);
998 if ( status >= B_OK )
1000 for ( int32_t oix = 0; oix < num_formats; oix++ )
1002 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
1004 if ( formats[oix].type == info->translatorID )
1007 imageFormat = formats[oix].type;
1008 translator = ids[tix];
1019 // make bitmap stream
1020 BBitmapStream outStream( converted );
1022 status = outFile.InitCheck();
1023 if (status == B_OK) {
1024 status = roster->Translate( &outStream, NULL, NULL,
1025 &outFile, imageFormat );
1026 if ( status == B_OK )
1028 BNodeInfo nodeInfo( &outFile );
1029 if ( nodeInfo.InitCheck() == B_OK )
1031 translation_format* formats;
1033 status = roster->GetOutputFormats( translator,
1034 (const translation_format **) &formats,
1036 if ( status >= B_OK )
1038 const char * mime = NULL;
1039 for ( int ix = 0; ix < count; ix++ ) {
1040 if ( formats[ix].type == imageFormat ) {
1041 mime = formats[ix].MIME;
1046 nodeInfo.SetType( mime );
1051 outStream.DetachBitmap( &converted );
1059 delete info->bitmap;
1067 /*****************************************************************************
1069 *****************************************************************************/
1070 VLCView::VLCView(BRect bounds, vout_thread_t *p_vout_instance )
1071 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
1072 fLastMouseMovedTime(system_time()),
1073 fCursorHidden(false),
1074 fCursorInside(false),
1075 fIgnoreDoubleClick(false)
1077 p_vout = p_vout_instance;
1078 SetViewColor(B_TRANSPARENT_32_BIT);
1081 /*****************************************************************************
1083 *****************************************************************************/
1088 /*****************************************************************************
1089 * VLCVIew::AttachedToWindow
1090 *****************************************************************************/
1092 VLCView::AttachedToWindow()
1094 // in order to get keyboard events
1096 // periodically check if we want to hide the pointer
1097 Window()->SetPulseRate(1000000);
1100 /*****************************************************************************
1101 * VLCVIew::MouseDown
1102 *****************************************************************************/
1104 VLCView::MouseDown(BPoint where)
1106 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
1107 BMessage* msg = Window()->CurrentMessage();
1110 msg->FindInt32("clicks", &clicks);
1111 msg->FindInt32("buttons", (int32*)&buttons);
1115 if (buttons & B_PRIMARY_MOUSE_BUTTON)
1117 if (clicks == 2 && !fIgnoreDoubleClick)
1120 videoWindow->ToggleInterfaceShowing(); */
1121 fIgnoreDoubleClick = false;
1125 if (buttons & B_SECONDARY_MOUSE_BUTTON)
1127 // clicks will be 2 next time (if interval short enough)
1128 // even if the first click and the second
1129 // have not been made with the same mouse button
1130 fIgnoreDoubleClick = true;
1131 // launch popup menu
1132 BPopUpMenu *menu = new BPopUpMenu("context menu");
1133 menu->SetRadioMode(false);
1134 // In full screen, add an item to show/hide the interface
1135 if( videoWindow->IsFullScreen() )
1137 BMenuItem *intfItem =
1138 new BMenuItem( _("Show Interface"), new BMessage(SHOW_INTERFACE) );
1139 menu->AddItem( intfItem );
1142 BMenuItem *halfItem = new BMenuItem(_("50%"), new BMessage(RESIZE_50));
1143 menu->AddItem(halfItem);
1145 BMenuItem *origItem = new BMenuItem(_("100%"), new BMessage(RESIZE_100));
1146 menu->AddItem(origItem);
1148 BMenuItem *doubleItem = new BMenuItem(_("200%"), new BMessage(RESIZE_200));
1149 menu->AddItem(doubleItem);
1150 // Toggle FullScreen
1151 BMenuItem *zoomItem = new BMenuItem(_("Fullscreen"), new BMessage(TOGGLE_FULL_SCREEN));
1152 zoomItem->SetMarked(videoWindow->IsFullScreen());
1153 menu->AddItem(zoomItem);
1155 menu->AddSeparatorItem();
1158 BMenuItem *vsyncItem = new BMenuItem(_("Vertical Sync"), new BMessage(VERT_SYNC));
1159 vsyncItem->SetMarked(videoWindow->IsSyncedToRetrace());
1160 menu->AddItem(vsyncItem);
1161 // Correct Aspect Ratio
1162 BMenuItem *aspectItem = new BMenuItem(_("Correct Aspect Ratio"), new BMessage(ASPECT_CORRECT));
1163 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
1164 menu->AddItem(aspectItem);
1166 menu->AddSeparatorItem();
1168 // Windwo Feel Items
1169 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
1170 winNormFeel->AddInt32("WinFeel", (int32_t)B_NORMAL_WINDOW_FEEL);
1171 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
1172 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
1173 menu->AddItem(normWindItem);
1175 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
1176 winFloatFeel->AddInt32("WinFeel", (int32_t)B_FLOATING_APP_WINDOW_FEEL);
1177 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
1178 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
1179 menu->AddItem(onTopWindItem);
1181 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
1182 winAllFeel->AddInt32("WinFeel", (int32_t)B_FLOATING_ALL_WINDOW_FEEL);
1183 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
1184 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
1185 menu->AddItem(allSpacesWindItem);*/
1187 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
1188 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
1189 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
1190 windowFeelMsg->AddInt32( "WinFeel", (int32_t)feel );
1191 BMenuItem *windowFeelItem = new BMenuItem( _("Stay On Top"), windowFeelMsg );
1192 windowFeelItem->SetMarked( onTop );
1193 menu->AddItem( windowFeelItem );
1195 menu->AddSeparatorItem();
1197 BMenuItem* screenShotItem = new BMenuItem( _("Take Screen Shot"),
1198 new BMessage( SCREEN_SHOT ) );
1199 menu->AddItem( screenShotItem );
1201 menu->SetTargetForItems( this );
1202 ConvertToScreen( &where );
1203 BRect mouseRect( where.x - 5, where.y - 5,
1204 where.x + 5, where.y + 5 );
1205 menu->Go( where, true, false, mouseRect, true );
1209 fLastMouseMovedTime = system_time();
1210 fCursorHidden = false;
1213 /*****************************************************************************
1215 *****************************************************************************/
1217 VLCView::MouseUp( BPoint where )
1220 val.b_bool = VLC_TRUE;
1221 var_Set( p_vout, "mouse-clicked", val );
1224 /*****************************************************************************
1225 * VLCVIew::MouseMoved
1226 *****************************************************************************/
1228 VLCView::MouseMoved(BPoint point, uint32_t transit, const BMessage* dragMessage)
1230 fLastMouseMovedTime = system_time();
1231 fCursorHidden = false;
1232 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1233 /* DVD navigation */
1234 unsigned int i_width, i_height, i_x, i_y;
1235 vout_PlacePicture( p_vout, (unsigned int)Bounds().Width(),
1236 (unsigned int)Bounds().Height(),
1237 &i_x, &i_y, &i_width, &i_height );
1239 val.i_int = ( (int)point.x - i_x ) * p_vout->render.i_width / i_width;
1240 var_Set( p_vout, "mouse-x", val );
1241 val.i_int = ( (int)point.y - i_y ) * p_vout->render.i_height / i_height;
1242 var_Set( p_vout, "mouse-y", val );
1243 val.b_bool = VLC_TRUE;
1244 var_Set( p_vout, "mouse-moved", val );
1247 /*****************************************************************************
1249 *****************************************************************************/
1253 // We are getting the pulse messages no matter if the mouse is over
1254 // this view. If we are in full screen mode, we want to hide the cursor
1255 // even if it is not.
1256 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1260 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1262 be_app->ObscureCursor();
1263 fCursorHidden = true;
1265 // hide the interface window as well if full screen
1266 if (videoWindow && videoWindow->IsFullScreen())
1267 videoWindow->SetInterfaceShowing(false);
1271 // Workaround to disable the screensaver in full screen:
1272 // we simulate an activity every 29 seconds
1273 if( videoWindow && videoWindow->IsFullScreen() &&
1274 system_time() - fLastMouseMovedTime > 29000000 )
1278 GetMouse(&where, &buttons, false);
1279 ConvertToScreen(&where);
1280 set_mouse_position((int32_t) where.x, (int32_t) where.y);
1284 /*****************************************************************************
1286 *****************************************************************************/
1288 VLCView::KeyDown(const char *bytes, int32_t numBytes)
1290 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1291 BWindow* interfaceWindow = get_interface_window();
1292 if (videoWindow && numBytes > 0) {
1293 uint32_t mods = modifiers();
1298 // toggle window and full screen mode
1299 // not passing on the tab key to the default KeyDown()
1300 // implementation also avoids loosing the keyboard focus
1301 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1304 // go back to window mode
1305 if (videoWindow->IsFullScreen())
1306 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1310 if (interfaceWindow)
1311 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1314 if (interfaceWindow)
1316 if (mods & B_SHIFT_KEY)
1318 interfaceWindow->PostMessage(NEXT_TITLE);
1321 interfaceWindow->PostMessage(NEXT_CHAPTER);
1325 if (interfaceWindow)
1327 if (mods & B_SHIFT_KEY)
1329 interfaceWindow->PostMessage(PREV_TITLE);
1332 interfaceWindow->PostMessage(PREV_CHAPTER);
1336 // previous file in playlist
1337 interfaceWindow->PostMessage(PREV_FILE);
1340 // next file in playlist
1341 interfaceWindow->PostMessage(NEXT_FILE);
1346 videoWindow->PostMessage( SCREEN_SHOT );
1349 BView::KeyDown(bytes, numBytes);
1355 /*****************************************************************************
1357 *****************************************************************************/
1359 VLCView::Draw(BRect updateRect)
1361 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1362 if ( window && window->mode == BITMAP )
1363 FillRect( updateRect );
1366 /*****************************************************************************
1368 *****************************************************************************/
1369 static int Init ( vout_thread_t * );
1370 static void End ( vout_thread_t * );
1371 // static int Manage ( vout_thread_t * );
1372 static void Display ( vout_thread_t *, picture_t * );
1374 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1375 static void BeosCloseDisplay( vout_thread_t *p_vout );
1377 /*****************************************************************************
1378 * OpenVideo: allocates BeOS video thread output method
1379 *****************************************************************************
1380 * This function allocates and initializes a BeOS vout method.
1381 *****************************************************************************/
1382 int E_(OpenVideo) ( vlc_object_t *p_this )
1384 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1386 /* Allocate structure */
1387 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1388 if( p_vout->p_sys == NULL )
1390 msg_Err( p_vout, "out of memory" );
1393 p_vout->p_sys->i_width = p_vout->render.i_width;
1394 p_vout->p_sys->i_height = p_vout->render.i_height;
1395 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1397 p_vout->pf_init = Init;
1398 p_vout->pf_end = End;
1399 p_vout->pf_manage = NULL;
1400 p_vout->pf_render = NULL;
1401 p_vout->pf_display = Display;
1406 /*****************************************************************************
1407 * Init: initialize BeOS video thread output method
1408 *****************************************************************************/
1409 int Init( vout_thread_t *p_vout )
1414 I_OUTPUTPICTURES = 0;
1416 /* Open and initialize device */
1417 if( BeosOpenDisplay( p_vout ) )
1419 msg_Err(p_vout, "vout error: can't open display");
1422 p_vout->output.i_width = p_vout->render.i_width;
1423 p_vout->output.i_height = p_vout->render.i_height;
1425 /* Assume we have square pixels */
1426 p_vout->output.i_aspect = p_vout->p_sys->i_width
1427 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1428 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1429 p_vout->p_sys->i_index = 0;
1431 p_vout->b_direct = 1;
1433 p_vout->output.i_rmask = 0x00ff0000;
1434 p_vout->output.i_gmask = 0x0000ff00;
1435 p_vout->output.i_bmask = 0x000000ff;
1437 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1440 /* Find an empty picture slot */
1441 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1444 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1446 p_pic = p_vout->p_picture + i_index;
1455 p_pic->p->p_pixels = (uint8_t*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1456 p_pic->p->i_lines = p_vout->p_sys->i_height;
1458 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1459 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1460 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1461 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1463 p_pic->i_status = DESTROYED_PICTURE;
1464 p_pic->i_type = DIRECT_PICTURE;
1466 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1474 /*****************************************************************************
1475 * End: terminate BeOS video thread output method
1476 *****************************************************************************/
1477 void End( vout_thread_t *p_vout )
1479 BeosCloseDisplay( p_vout );
1482 /*****************************************************************************
1483 * CloseVideo: destroy BeOS video thread output method
1484 *****************************************************************************
1485 * Terminate an output method created by DummyCreateOutputMethod
1486 *****************************************************************************/
1487 void E_(CloseVideo) ( vlc_object_t *p_this )
1489 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1491 free( p_vout->p_sys );
1494 /*****************************************************************************
1495 * Display: displays previously rendered output
1496 *****************************************************************************
1497 * This function send the currently rendered image to BeOS image, waits until
1498 * it is displayed and switch the two rendering buffers, preparing next frame.
1499 *****************************************************************************/
1500 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1502 VideoWindow * p_win = p_vout->p_sys->p_window;
1504 /* draw buffer if required */
1505 if (!p_win->teardownwindow)
1507 p_win->drawBuffer(p_vout->p_sys->i_index);
1510 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1511 p_pic->p->p_pixels = (uint8_t*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1514 /* following functions are local */
1516 /*****************************************************************************
1517 * BeosOpenDisplay: open and initialize BeOS device
1518 *****************************************************************************/
1519 static int BeosOpenDisplay( vout_thread_t *p_vout )
1522 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1523 p_vout->p_sys->i_height - 1,
1525 20 + p_vout->i_window_width - 1,
1526 50 + p_vout->i_window_height - 1 ),
1528 if( p_vout->p_sys->p_window == NULL )
1530 msg_Err( p_vout, "cannot allocate VideoWindow" );
1535 p_vout->p_sys->p_window->Show();
1541 /*****************************************************************************
1542 * BeosDisplay: close and reset BeOS device
1543 *****************************************************************************
1544 * Returns all resources allocated by BeosOpenDisplay and restore the original
1545 * state of the device.
1546 *****************************************************************************/
1547 static void BeosCloseDisplay( vout_thread_t *p_vout )
1549 VideoWindow * p_win = p_vout->p_sys->p_window;
1550 /* Destroy the video window */
1551 if( p_win != NULL && !p_win->teardownwindow)
1554 p_win->teardownwindow = true;