1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.17 2003/04/22 16:36:16 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;
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 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 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 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 fprintf( stderr, "%x\n", '&' );
304 AddShortcut( '&', 0, new BMessage( RESIZE_50 ) );
305 AddShortcut( 'é', 0, new BMessage( RESIZE_100 ) );
306 // FIXME - this one doesn't work because 'é' is a multi-byte character
307 AddShortcut( '"', 0, new BMessage( RESIZE_200 ) );
312 VideoWindow::~VideoWindow()
316 teardownwindow = true;
317 wait_for_thread(fDrawThreadID, &result);
322 /*****************************************************************************
323 * VideoWindow::MessageReceived
324 *****************************************************************************/
326 VideoWindow::MessageReceived( BMessage *p_message )
328 switch( p_message->what )
330 case TOGGLE_FULL_SCREEN:
338 _SetVideoSize(p_message->what);
341 SetSyncToRetrace(!IsSyncedToRetrace());
346 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
349 fCachedFeel = winFeel;
350 if (winFeel == B_FLOATING_ALL_WINDOW_FEEL)
351 fSettings->AddFlags(VideoSettings::FLAG_ON_TOP_ALL);
353 fSettings->ClearFlags(VideoSettings::FLAG_ON_TOP_ALL);
358 SetCorrectAspectRatio(!CorrectAspectRatio());
361 // save a screen shot
362 if ( BBitmap* current = bitmap[i_buffer] )
364 // the following line might be tempting, but does not work for some overlay bitmaps!!!
365 // BBitmap* temp = new BBitmap( current );
366 // so we clone the bitmap ourselves
367 // however, we need to take care of potentially different padding!
368 // memcpy() is slow when reading from grafix memory, but what the heck...
369 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
370 if ( temp && temp->IsValid() )
372 int32 height = (int32)current->Bounds().Height();
373 uint8* dst = (uint8*)temp->Bits();
374 uint8* src = (uint8*)current->Bits();
375 int32 dstBpr = temp->BytesPerRow();
376 int32 srcBpr = current->BytesPerRow();
377 int32 validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
378 for ( int32 y = 0; y < height; y++ )
380 memcpy( dst, src, validBytes );
384 char* path = config_GetPsz( p_vout, "beos-screenshot-path" );
386 path = strdup( DEFAULT_SCREEN_SHOT_PATH );
387 int32 format = config_GetInt( p_vout, "beos-screenshot-format" );
388 _SaveScreenShot( temp, path, format );
397 BWindow::MessageReceived( p_message );
402 /*****************************************************************************
404 *****************************************************************************/
406 VideoWindow::Zoom(BPoint origin, float width, float height )
411 /*****************************************************************************
412 * VideoWindow::FrameMoved
413 *****************************************************************************/
415 VideoWindow::FrameMoved(BPoint origin)
422 /*****************************************************************************
423 * VideoWindow::FrameResized
424 *****************************************************************************/
426 VideoWindow::FrameResized( float width, float height )
428 int32 useWidth = CorrectAspectRatio() ? i_width : fTrueWidth;
429 int32 useHeight = CorrectAspectRatio() ? i_height : fTrueHeight;
430 float out_width, out_height;
431 float out_left, out_top;
432 float width_scale = width / useWidth;
433 float height_scale = height / useHeight;
435 if (width_scale <= height_scale)
437 out_width = (useWidth * width_scale);
438 out_height = (useHeight * width_scale);
440 out_top = (height - out_height) / 2;
442 else /* if the height is proportionally smaller */
444 out_width = (useWidth * height_scale);
445 out_height = (useHeight * height_scale);
447 out_left = (width - out_width) / 2;
449 view->MoveTo(out_left,out_top);
450 view->ResizeTo(out_width, out_height);
456 /*****************************************************************************
457 * VideoWindow::ScreenChanged
458 *****************************************************************************/
460 VideoWindow::ScreenChanged(BRect frame, color_space format)
462 BScreen screen(this);
464 screen.GetMode(&mode);
465 float refresh = (mode.timing.pixel_clock * 1000)
466 / ((mode.timing.h_total) * (mode.timing.v_total));
467 SetSyncToRetrace(refresh < MIN_AUTO_VSYNC_REFRESH);
470 /*****************************************************************************
471 * VideoWindow::Activate
472 *****************************************************************************/
474 VideoWindow::WindowActivated(bool active)
478 /*****************************************************************************
479 * VideoWindow::drawBuffer
480 *****************************************************************************/
482 VideoWindow::drawBuffer(int bufferIndex)
484 i_buffer = bufferIndex;
486 // sync to the screen if required
487 if (IsSyncedToRetrace())
489 BScreen screen(this);
490 screen.WaitForRetrace(22000);
492 if (fInitStatus >= B_OK && LockLooper())
494 // switch the overlay bitmap
498 view->SetViewOverlay(bitmap[i_buffer],
499 bitmap[i_buffer]->Bounds() ,
502 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
503 B_OVERLAY_TRANSFER_CHANNEL);
504 view->SetViewColor(key);
509 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
515 /*****************************************************************************
516 * VideoWindow::SetInterfaceShowing
517 *****************************************************************************/
519 VideoWindow::ToggleInterfaceShowing()
521 SetInterfaceShowing(!fInterfaceShowing);
524 /*****************************************************************************
525 * VideoWindow::SetInterfaceShowing
526 *****************************************************************************/
528 VideoWindow::SetInterfaceShowing(bool showIt)
530 BWindow* window = get_interface_window();
535 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
536 SetFeel(B_NORMAL_WINDOW_FEEL);
537 window->Activate(true);
542 SetFeel(fCachedFeel);
544 window->SendBehind(this);
546 fInterfaceShowing = showIt;
550 /*****************************************************************************
551 * VideoWindow::SetCorrectAspectRatio
552 *****************************************************************************/
554 VideoWindow::SetCorrectAspectRatio(bool doIt)
556 if (CorrectAspectRatio() != doIt)
559 fSettings->AddFlags(VideoSettings::FLAG_CORRECT_RATIO);
561 fSettings->ClearFlags(VideoSettings::FLAG_CORRECT_RATIO);
562 FrameResized(Bounds().Width(), Bounds().Height());
566 /*****************************************************************************
567 * VideoWindow::CorrectAspectRatio
568 *****************************************************************************/
570 VideoWindow::CorrectAspectRatio() const
572 return fSettings->HasFlags(VideoSettings::FLAG_CORRECT_RATIO);
575 /*****************************************************************************
576 * VideoWindow::ToggleFullScreen
577 *****************************************************************************/
579 VideoWindow::ToggleFullScreen()
581 SetFullScreen(!IsFullScreen());
584 /*****************************************************************************
585 * VideoWindow::SetFullScreen
586 *****************************************************************************/
588 VideoWindow::SetFullScreen(bool doIt)
592 BScreen screen(this);
593 BRect rect = screen.Frame();
596 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
597 be_app->ObscureCursor();
598 fInterfaceShowing = false;
599 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
603 MoveTo(winSize.left, winSize.top);
604 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
605 be_app->ShowCursor();
606 fInterfaceShowing = true;
607 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
611 /*****************************************************************************
612 * VideoWindow::IsFullScreen
613 *****************************************************************************/
615 VideoWindow::IsFullScreen() const
617 return fSettings->HasFlags(VideoSettings::FLAG_FULL_SCREEN);
620 /*****************************************************************************
621 * VideoWindow::SetSyncToRetrace
622 *****************************************************************************/
624 VideoWindow::SetSyncToRetrace(bool doIt)
627 fSettings->AddFlags(VideoSettings::FLAG_SYNC_RETRACE);
629 fSettings->ClearFlags(VideoSettings::FLAG_SYNC_RETRACE);
632 /*****************************************************************************
633 * VideoWindow::IsSyncedToRetrace
634 *****************************************************************************/
636 VideoWindow::IsSyncedToRetrace() const
638 return fSettings->HasFlags(VideoSettings::FLAG_SYNC_RETRACE);
642 /*****************************************************************************
643 * VideoWindow::_AllocateBuffers
644 *****************************************************************************/
646 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
648 // clear any old buffers
653 BRect bitmapFrame( 0, 0, width, height );
654 // read from config, if we are supposed to use overlay at all
655 int noOverlay = !config_GetInt( p_vout, "overlay" );
656 // test for overlay capability
657 for (int i = 0; i < COLOR_COUNT; i++)
659 if (noOverlay) break;
660 bitmap[0] = new BBitmap ( bitmapFrame,
661 B_BITMAP_WILL_OVERLAY |
662 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
663 colspace[i].colspace);
665 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
669 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
670 colspace[colspace_index].colspace);
671 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
672 colspace[colspace_index].colspace);
673 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
677 view->SetViewOverlay(bitmap[0],
678 bitmap[0]->Bounds() ,
681 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
682 view->SetViewColor(key);
683 SetTitle("VLC " PACKAGE_VERSION " (Overlay)");
689 *mode = BITMAP; // might want to try again with normal bitmaps
699 colspace_index = DEFAULT_COL; // B_RGB32
700 SetTitle( "VLC " PACKAGE_VERSION " (Bitmap)" );
701 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
702 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
703 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
705 // see if everything went well
706 status_t status = B_ERROR;
707 for (int32 i = 0; i < 3; i++)
710 status = bitmap[i]->InitCheck();
716 // clear bitmaps to black
717 for (int32 i = 0; i < 3; i++)
718 _BlankBitmap(bitmap[i]);
723 /*****************************************************************************
724 * VideoWindow::_FreeBuffers
725 *****************************************************************************/
727 VideoWindow::_FreeBuffers()
735 fInitStatus = B_ERROR;
738 /*****************************************************************************
739 * VideoWindow::_BlankBitmap
740 *****************************************************************************/
742 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
744 // no error checking (we do that earlier on and since it's a private function...
747 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
750 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
752 // we only handle weird colorspaces with special care
753 switch (bitmap->ColorSpace()) {
755 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
756 int32 height = bitmap->Bounds().IntegerHeight() + 1;
757 uint8* bits = (uint8*)bitmap->Bits();
758 int32 bpr = bitmap->BytesPerRow();
759 for (int32 y = 0; y < height; y++) {
760 // handle 2 bytes at a time
761 for (int32 i = 0; i < bpr; i += 2) {
773 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
774 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
775 int32 height = bitmap->Bounds().IntegerHeight() + 1;
776 uint8* bits = (uint8*)bitmap->Bits();
777 int32 bpr = bitmap->BytesPerRow();
778 for (int32 y = 0; y < height; y += 1) {
779 // handle 3 bytes at a time
780 for (int32 i = 0; i < bpr; i += 3) {
793 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
794 int32 height = bitmap->Bounds().IntegerHeight() + 1;
795 uint8* bits = (uint8*)bitmap->Bits();
796 int32 bpr = bitmap->BytesPerRow();
797 for (int32 y = 0; y < height; y += 1) {
798 // handle 2 bytes at a time
799 for (int32 i = 0; i < bpr; i += 2) {
810 memset(bitmap->Bits(), 0, bitmap->BitsLength());
815 /*****************************************************************************
816 * VideoWindow::_SetVideoSize
817 *****************************************************************************/
819 VideoWindow::_SetVideoSize(uint32 mode)
821 // let size depend on aspect correction
822 int32 width = CorrectAspectRatio() ? i_width : fTrueWidth;
823 int32 height = CorrectAspectRatio() ? i_height : fTrueHeight;
838 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
839 ResizeTo(width, height);
842 /*****************************************************************************
843 * VideoWindow::_SetToSettings
844 *****************************************************************************/
846 VideoWindow::_SetToSettings()
849 uint32 mode = RESIZE_100;
850 switch (fSettings->VideoSize())
852 case VideoSettings::SIZE_50:
855 case VideoSettings::SIZE_200:
858 case VideoSettings::SIZE_100:
859 case VideoSettings::SIZE_OTHER:
863 bool fullscreen = IsFullScreen(); // remember settings
864 _SetVideoSize(mode); // because this will reset settings
865 // the fullscreen status is reflected in the settings,
866 // but not yet in the windows state
869 if (fSettings->HasFlags(VideoSettings::FLAG_ON_TOP_ALL))
870 fCachedFeel = B_FLOATING_ALL_WINDOW_FEEL;
872 fCachedFeel = B_NORMAL_WINDOW_FEEL;
873 SetFeel(fCachedFeel);
876 /*****************************************************************************
877 * VideoWindow::_SaveScreenShot
878 *****************************************************************************/
880 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
881 uint32 translatorID ) const
883 // make the info object from the parameters
884 screen_shot_info* info = new screen_shot_info;
885 info->bitmap = bitmap;
887 info->translatorID = translatorID;
888 info->width = CorrectAspectRatio() ? i_width : fTrueWidth;
889 info->height = CorrectAspectRatio() ? i_height : fTrueHeight;
890 // spawn a new thread to take care of the actual saving to disk
891 thread_id thread = spawn_thread( _save_screen_shot,
893 B_LOW_PRIORITY, (void*)info );
894 // start thread or do the job ourself if something went wrong
895 if ( thread < B_OK || resume_thread( thread ) < B_OK )
896 _save_screen_shot( (void*)info );
899 /*****************************************************************************
900 * VideoWindow::_save_screen_shot
901 *****************************************************************************/
903 VideoWindow::_save_screen_shot( void* cookie )
905 screen_shot_info* info = (screen_shot_info*)cookie;
906 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
908 // try to be as quick as possible creating the file (the user might have
909 // taken the next screen shot already!)
910 // make sure we have a unique name for the screen shot
911 BString path( info->path );
912 // create the folder if it doesn't exist
913 BString folder( info->path );
914 int32 pos = folder.FindLast("/");
917 pos++; // leave the last '/' in the string
918 if ( pos == path.Length() )
919 path << "vlc screenshot";
922 int32 removeChars = folder.Length() - pos;
923 folder.Remove( pos, removeChars );
925 create_directory( folder.String(), 0777 );
927 BEntry entry( path.String() );
928 int32 appendedNumber = 0;
929 if ( entry.Exists() && !entry.IsSymLink() )
931 // we would clobber an existing entry
932 bool foundUniqueName = false;
934 while ( !foundUniqueName ) {
935 BString newName( path.String() );
936 newName << " " << appendedNumber;
937 BEntry possiblyClobberedEntry( newName.String() );
938 if ( possiblyClobberedEntry.Exists()
939 && !possiblyClobberedEntry.IsSymLink() )
942 foundUniqueName = true;
945 if ( appendedNumber > 0 )
946 path << " " << appendedNumber;
947 // there is still a slight chance to clobber an existing
948 // file (if it was created in the "meantime"), but we take it...
949 BFile outFile( path.String(),
950 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
952 // make colorspace converted copy of bitmap
953 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
955 status_t status = convert_bitmap( info->bitmap, converted );
956 if ( status == B_OK )
958 BTranslatorRoster* roster = BTranslatorRoster::Default();
959 uint32 imageFormat = 0;
960 translator_id translator = 0;
963 // find suitable translator
964 translator_id* ids = NULL;
967 status = roster->GetAllTranslators( &ids, &count );
968 if ( status >= B_OK )
970 for ( int tix = 0; tix < count; tix++ )
972 const translation_format *formats = NULL;
973 int32 num_formats = 0;
975 status = roster->GetInputFormats( ids[tix],
976 &formats, &num_formats );
979 for ( int iix = 0; iix < num_formats; iix++ )
981 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
990 status = roster->GetOutputFormats( ids[tix],
991 &formats, &num_formats);
992 if ( status >= B_OK )
994 for ( int32 oix = 0; oix < num_formats; oix++ )
996 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
998 if ( formats[oix].type == info->translatorID )
1001 imageFormat = formats[oix].type;
1002 translator = ids[tix];
1013 // make bitmap stream
1014 BBitmapStream outStream( converted );
1016 status = outFile.InitCheck();
1017 if (status == B_OK) {
1018 status = roster->Translate( &outStream, NULL, NULL,
1019 &outFile, imageFormat );
1020 if ( status == B_OK )
1022 BNodeInfo nodeInfo( &outFile );
1023 if ( nodeInfo.InitCheck() == B_OK )
1025 translation_format* formats;
1027 status = roster->GetOutputFormats( translator,
1028 (const translation_format **) &formats,
1030 if ( status >= B_OK )
1032 const char * mime = NULL;
1033 for ( int ix = 0; ix < count; ix++ ) {
1034 if ( formats[ix].type == imageFormat ) {
1035 mime = formats[ix].MIME;
1040 nodeInfo.SetType( mime );
1045 outStream.DetachBitmap( &converted );
1053 delete info->bitmap;
1061 /*****************************************************************************
1063 *****************************************************************************/
1064 VLCView::VLCView(BRect bounds, vout_thread_t *p_vout_instance )
1065 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
1066 fLastMouseMovedTime(system_time()),
1067 fCursorHidden(false),
1068 fCursorInside(false),
1069 fIgnoreDoubleClick(false)
1071 p_vout = p_vout_instance;
1072 SetViewColor(B_TRANSPARENT_32_BIT);
1075 /*****************************************************************************
1077 *****************************************************************************/
1082 /*****************************************************************************
1083 * VLCVIew::AttachedToWindow
1084 *****************************************************************************/
1086 VLCView::AttachedToWindow()
1088 // in order to get keyboard events
1090 // periodically check if we want to hide the pointer
1091 Window()->SetPulseRate(1000000);
1094 /*****************************************************************************
1095 * VLCVIew::MouseDown
1096 *****************************************************************************/
1098 VLCView::MouseDown(BPoint where)
1100 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
1101 BMessage* msg = Window()->CurrentMessage();
1104 msg->FindInt32("clicks", &clicks);
1105 msg->FindInt32("buttons", (int32*)&buttons);
1109 if (buttons & B_PRIMARY_MOUSE_BUTTON)
1111 if (clicks == 2 && !fIgnoreDoubleClick)
1114 videoWindow->ToggleInterfaceShowing(); */
1115 fIgnoreDoubleClick = false;
1119 if (buttons & B_SECONDARY_MOUSE_BUTTON)
1121 // clicks will be 2 next time (if interval short enough)
1122 // even if the first click and the second
1123 // have not been made with the same mouse button
1124 fIgnoreDoubleClick = true;
1125 // launch popup menu
1126 BPopUpMenu *menu = new BPopUpMenu("context menu");
1127 menu->SetRadioMode(false);
1129 BMenuItem *halfItem = new BMenuItem(_("50%"), new BMessage(RESIZE_50));
1130 menu->AddItem(halfItem);
1132 BMenuItem *origItem = new BMenuItem(_("100%"), new BMessage(RESIZE_100));
1133 menu->AddItem(origItem);
1135 BMenuItem *doubleItem = new BMenuItem(_("200%"), new BMessage(RESIZE_200));
1136 menu->AddItem(doubleItem);
1137 // Toggle FullScreen
1138 BMenuItem *zoomItem = new BMenuItem(_("Fullscreen"), new BMessage(TOGGLE_FULL_SCREEN));
1139 zoomItem->SetMarked(videoWindow->IsFullScreen());
1140 menu->AddItem(zoomItem);
1142 menu->AddSeparatorItem();
1145 BMenuItem *vsyncItem = new BMenuItem(_("Vertical Sync"), new BMessage(VERT_SYNC));
1146 vsyncItem->SetMarked(videoWindow->IsSyncedToRetrace());
1147 menu->AddItem(vsyncItem);
1148 // Correct Aspect Ratio
1149 BMenuItem *aspectItem = new BMenuItem(_("Correct Aspect Ratio"), new BMessage(ASPECT_CORRECT));
1150 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
1151 menu->AddItem(aspectItem);
1153 menu->AddSeparatorItem();
1155 // Windwo Feel Items
1156 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
1157 winNormFeel->AddInt32("WinFeel", (int32)B_NORMAL_WINDOW_FEEL);
1158 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
1159 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
1160 menu->AddItem(normWindItem);
1162 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
1163 winFloatFeel->AddInt32("WinFeel", (int32)B_FLOATING_APP_WINDOW_FEEL);
1164 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
1165 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
1166 menu->AddItem(onTopWindItem);
1168 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
1169 winAllFeel->AddInt32("WinFeel", (int32)B_FLOATING_ALL_WINDOW_FEEL);
1170 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
1171 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
1172 menu->AddItem(allSpacesWindItem);*/
1174 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
1175 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
1176 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
1177 windowFeelMsg->AddInt32( "WinFeel", (int32)feel );
1178 BMenuItem *windowFeelItem = new BMenuItem( _("Stay On Top"), windowFeelMsg );
1179 windowFeelItem->SetMarked( onTop );
1180 menu->AddItem( windowFeelItem );
1182 menu->AddSeparatorItem();
1184 BMenuItem* screenShotItem = new BMenuItem( _("Take Screen Shot"),
1185 new BMessage( SCREEN_SHOT ) );
1186 menu->AddItem( screenShotItem );
1188 menu->SetTargetForItems( this );
1189 ConvertToScreen( &where );
1190 menu->Go( where, true, false, true );
1194 fLastMouseMovedTime = system_time();
1195 fCursorHidden = false;
1198 /*****************************************************************************
1200 *****************************************************************************/
1202 VLCView::MouseUp( BPoint where )
1205 val.b_bool = VLC_TRUE;
1206 var_Set( p_vout, "mouse-clicked", val );
1209 /*****************************************************************************
1210 * VLCVIew::MouseMoved
1211 *****************************************************************************/
1213 VLCView::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
1215 fLastMouseMovedTime = system_time();
1216 fCursorHidden = false;
1217 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1218 /* DVD navigation */
1219 unsigned int i_width, i_height, i_x, i_y;
1220 vout_PlacePicture( p_vout, (unsigned int)Bounds().Width(),
1221 (unsigned int)Bounds().Height(),
1222 &i_x, &i_y, &i_width, &i_height );
1224 val.i_int = ( (int)point.x - i_x ) * p_vout->render.i_width / i_width;
1225 var_Set( p_vout, "mouse-x", val );
1226 val.i_int = ( (int)point.y - i_y ) * p_vout->render.i_height / i_height;
1227 var_Set( p_vout, "mouse-y", val );
1228 val.b_bool = VLC_TRUE;
1229 var_Set( p_vout, "mouse-moved", val );
1232 /*****************************************************************************
1234 *****************************************************************************/
1238 // We are getting the pulse messages no matter if the mouse is over
1239 // this view. If we are in full screen mode, we want to hide the cursor
1240 // even if it is not.
1241 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1245 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1247 be_app->ObscureCursor();
1248 fCursorHidden = true;
1250 // hide the interface window as well if full screen
1251 if (videoWindow && videoWindow->IsFullScreen())
1252 videoWindow->SetInterfaceShowing(false);
1256 // Workaround to disable the screensaver in full screen:
1257 // we simulate an activity every 29 seconds
1258 if( videoWindow && videoWindow->IsFullScreen() &&
1259 system_time() - fLastMouseMovedTime > 29000000 )
1263 GetMouse(&where, &buttons, false);
1264 ConvertToScreen(&where);
1265 set_mouse_position((int32) where.x, (int32) where.y);
1269 /*****************************************************************************
1271 *****************************************************************************/
1273 VLCView::KeyDown(const char *bytes, int32 numBytes)
1275 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1276 BWindow* interfaceWindow = get_interface_window();
1277 if (videoWindow && numBytes > 0) {
1278 uint32 mods = modifiers();
1283 // toggle window and full screen mode
1284 // not passing on the tab key to the default KeyDown()
1285 // implementation also avoids loosing the keyboard focus
1286 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1289 // go back to window mode
1290 if (videoWindow->IsFullScreen())
1291 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1295 if (interfaceWindow)
1296 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1299 if (interfaceWindow)
1301 if (mods & B_SHIFT_KEY)
1303 interfaceWindow->PostMessage(NEXT_TITLE);
1306 interfaceWindow->PostMessage(NEXT_CHAPTER);
1310 if (interfaceWindow)
1312 if (mods & B_SHIFT_KEY)
1314 interfaceWindow->PostMessage(PREV_TITLE);
1317 interfaceWindow->PostMessage(PREV_CHAPTER);
1321 // previous file in playlist
1322 interfaceWindow->PostMessage(PREV_FILE);
1325 // next file in playlist
1326 interfaceWindow->PostMessage(NEXT_FILE);
1331 videoWindow->PostMessage( SCREEN_SHOT );
1334 BView::KeyDown(bytes, numBytes);
1340 /*****************************************************************************
1342 *****************************************************************************/
1344 VLCView::Draw(BRect updateRect)
1346 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1347 if ( window && window->mode == BITMAP )
1348 FillRect( updateRect );
1351 /*****************************************************************************
1353 *****************************************************************************/
1354 static int Init ( vout_thread_t * );
1355 static void End ( vout_thread_t * );
1356 // static int Manage ( vout_thread_t * );
1357 static void Display ( vout_thread_t *, picture_t * );
1359 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1360 static void BeosCloseDisplay( vout_thread_t *p_vout );
1362 /*****************************************************************************
1363 * OpenVideo: allocates BeOS video thread output method
1364 *****************************************************************************
1365 * This function allocates and initializes a BeOS vout method.
1366 *****************************************************************************/
1367 int E_(OpenVideo) ( vlc_object_t *p_this )
1369 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1371 /* Allocate structure */
1372 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1373 if( p_vout->p_sys == NULL )
1375 msg_Err( p_vout, "out of memory" );
1378 p_vout->p_sys->i_width = p_vout->render.i_width;
1379 p_vout->p_sys->i_height = p_vout->render.i_height;
1380 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1382 p_vout->pf_init = Init;
1383 p_vout->pf_end = End;
1384 p_vout->pf_manage = NULL;
1385 p_vout->pf_render = NULL;
1386 p_vout->pf_display = Display;
1391 /*****************************************************************************
1392 * Init: initialize BeOS video thread output method
1393 *****************************************************************************/
1394 int Init( vout_thread_t *p_vout )
1399 I_OUTPUTPICTURES = 0;
1401 /* Open and initialize device */
1402 if( BeosOpenDisplay( p_vout ) )
1404 msg_Err(p_vout, "vout error: can't open display");
1407 p_vout->output.i_width = p_vout->render.i_width;
1408 p_vout->output.i_height = p_vout->render.i_height;
1410 /* Assume we have square pixels */
1411 p_vout->output.i_aspect = p_vout->p_sys->i_width
1412 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1413 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1414 p_vout->p_sys->i_index = 0;
1416 p_vout->b_direct = 1;
1418 p_vout->output.i_rmask = 0x00ff0000;
1419 p_vout->output.i_gmask = 0x0000ff00;
1420 p_vout->output.i_bmask = 0x000000ff;
1422 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1425 /* Find an empty picture slot */
1426 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1429 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1431 p_pic = p_vout->p_picture + i_index;
1440 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1441 p_pic->p->i_lines = p_vout->p_sys->i_height;
1443 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1444 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1445 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1446 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1448 p_pic->i_status = DESTROYED_PICTURE;
1449 p_pic->i_type = DIRECT_PICTURE;
1451 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1459 /*****************************************************************************
1460 * End: terminate BeOS video thread output method
1461 *****************************************************************************/
1462 void End( vout_thread_t *p_vout )
1464 BeosCloseDisplay( p_vout );
1467 /*****************************************************************************
1468 * CloseVideo: destroy BeOS video thread output method
1469 *****************************************************************************
1470 * Terminate an output method created by DummyCreateOutputMethod
1471 *****************************************************************************/
1472 void E_(CloseVideo) ( vlc_object_t *p_this )
1474 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1476 free( p_vout->p_sys );
1479 /*****************************************************************************
1480 * Display: displays previously rendered output
1481 *****************************************************************************
1482 * This function send the currently rendered image to BeOS image, waits until
1483 * it is displayed and switch the two rendering buffers, preparing next frame.
1484 *****************************************************************************/
1485 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1487 VideoWindow * p_win = p_vout->p_sys->p_window;
1489 /* draw buffer if required */
1490 if (!p_win->teardownwindow)
1492 p_win->drawBuffer(p_vout->p_sys->i_index);
1495 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1496 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1499 /* following functions are local */
1501 /*****************************************************************************
1502 * BeosOpenDisplay: open and initialize BeOS device
1503 *****************************************************************************/
1504 static int BeosOpenDisplay( vout_thread_t *p_vout )
1507 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1508 p_vout->p_sys->i_height - 1,
1510 20 + p_vout->i_window_width - 1,
1511 50 + p_vout->i_window_height - 1 ),
1513 if( p_vout->p_sys->p_window == NULL )
1515 msg_Err( p_vout, "cannot allocate VideoWindow" );
1520 p_vout->p_sys->p_window->Show();
1526 /*****************************************************************************
1527 * BeosDisplay: close and reset BeOS device
1528 *****************************************************************************
1529 * Returns all resources allocated by BeosOpenDisplay and restore the original
1530 * state of the device.
1531 *****************************************************************************/
1532 static void BeosCloseDisplay( vout_thread_t *p_vout )
1534 VideoWindow * p_win = p_vout->p_sys->p_window;
1535 /* Destroy the video window */
1536 if( p_win != NULL && !p_win->teardownwindow)
1539 p_win->teardownwindow = true;