1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.15 2003/04/18 16:38:58 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);
299 VideoWindow::~VideoWindow()
303 teardownwindow = true;
304 wait_for_thread(fDrawThreadID, &result);
309 /*****************************************************************************
310 * VideoWindow::MessageReceived
311 *****************************************************************************/
313 VideoWindow::MessageReceived( BMessage *p_message )
315 switch( p_message->what )
317 case TOGGLE_FULL_SCREEN:
325 _SetVideoSize(p_message->what);
328 SetSyncToRetrace(!IsSyncedToRetrace());
333 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
336 fCachedFeel = winFeel;
337 if (winFeel == B_FLOATING_ALL_WINDOW_FEEL)
338 fSettings->AddFlags(VideoSettings::FLAG_ON_TOP_ALL);
340 fSettings->ClearFlags(VideoSettings::FLAG_ON_TOP_ALL);
345 SetCorrectAspectRatio(!CorrectAspectRatio());
348 // save a screen shot
349 if ( BBitmap* current = bitmap[i_buffer] )
351 // the following line might be tempting, but does not work for some overlay bitmaps!!!
352 // BBitmap* temp = new BBitmap( current );
353 // so we clone the bitmap ourselves
354 // however, we need to take care of potentially different padding!
355 // memcpy() is slow when reading from grafix memory, but what the heck...
356 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
357 if ( temp && temp->IsValid() )
359 int32 height = (int32)current->Bounds().Height();
360 uint8* dst = (uint8*)temp->Bits();
361 uint8* src = (uint8*)current->Bits();
362 int32 dstBpr = temp->BytesPerRow();
363 int32 srcBpr = current->BytesPerRow();
364 int32 validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
365 for ( int32 y = 0; y < height; y++ )
367 memcpy( dst, src, validBytes );
371 char* path = config_GetPsz( p_vout, "beos-screenshot-path" );
373 path = strdup( DEFAULT_SCREEN_SHOT_PATH );
374 int32 format = config_GetInt( p_vout, "beos-screenshot-format" );
375 _SaveScreenShot( temp, path, format );
384 BWindow::MessageReceived( p_message );
389 /*****************************************************************************
391 *****************************************************************************/
393 VideoWindow::Zoom(BPoint origin, float width, float height )
398 /*****************************************************************************
399 * VideoWindow::FrameMoved
400 *****************************************************************************/
402 VideoWindow::FrameMoved(BPoint origin)
409 /*****************************************************************************
410 * VideoWindow::FrameResized
411 *****************************************************************************/
413 VideoWindow::FrameResized( float width, float height )
415 int32 useWidth = CorrectAspectRatio() ? i_width : fTrueWidth;
416 int32 useHeight = CorrectAspectRatio() ? i_height : fTrueHeight;
417 float out_width, out_height;
418 float out_left, out_top;
419 float width_scale = width / useWidth;
420 float height_scale = height / useHeight;
422 if (width_scale <= height_scale)
424 out_width = (useWidth * width_scale);
425 out_height = (useHeight * width_scale);
427 out_top = (height - out_height) / 2;
429 else /* if the height is proportionally smaller */
431 out_width = (useWidth * height_scale);
432 out_height = (useHeight * height_scale);
434 out_left = (width - out_width) / 2;
436 view->MoveTo(out_left,out_top);
437 view->ResizeTo(out_width, out_height);
443 /*****************************************************************************
444 * VideoWindow::ScreenChanged
445 *****************************************************************************/
447 VideoWindow::ScreenChanged(BRect frame, color_space format)
449 BScreen screen(this);
451 screen.GetMode(&mode);
452 float refresh = (mode.timing.pixel_clock * 1000)
453 / ((mode.timing.h_total) * (mode.timing.v_total));
454 SetSyncToRetrace(refresh < MIN_AUTO_VSYNC_REFRESH);
457 /*****************************************************************************
458 * VideoWindow::Activate
459 *****************************************************************************/
461 VideoWindow::WindowActivated(bool active)
465 /*****************************************************************************
466 * VideoWindow::drawBuffer
467 *****************************************************************************/
469 VideoWindow::drawBuffer(int bufferIndex)
471 i_buffer = bufferIndex;
473 // sync to the screen if required
474 if (IsSyncedToRetrace())
476 BScreen screen(this);
477 screen.WaitForRetrace(22000);
479 if (fInitStatus >= B_OK && LockLooper())
481 // switch the overlay bitmap
485 view->SetViewOverlay(bitmap[i_buffer],
486 bitmap[i_buffer]->Bounds() ,
489 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
490 B_OVERLAY_TRANSFER_CHANNEL);
491 view->SetViewColor(key);
496 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
502 /*****************************************************************************
503 * VideoWindow::SetInterfaceShowing
504 *****************************************************************************/
506 VideoWindow::ToggleInterfaceShowing()
508 SetInterfaceShowing(!fInterfaceShowing);
511 /*****************************************************************************
512 * VideoWindow::SetInterfaceShowing
513 *****************************************************************************/
515 VideoWindow::SetInterfaceShowing(bool showIt)
517 BWindow* window = get_interface_window();
522 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
523 SetFeel(B_NORMAL_WINDOW_FEEL);
524 window->Activate(true);
529 SetFeel(fCachedFeel);
531 window->SendBehind(this);
533 fInterfaceShowing = showIt;
537 /*****************************************************************************
538 * VideoWindow::SetCorrectAspectRatio
539 *****************************************************************************/
541 VideoWindow::SetCorrectAspectRatio(bool doIt)
543 if (CorrectAspectRatio() != doIt)
546 fSettings->AddFlags(VideoSettings::FLAG_CORRECT_RATIO);
548 fSettings->ClearFlags(VideoSettings::FLAG_CORRECT_RATIO);
549 FrameResized(Bounds().Width(), Bounds().Height());
553 /*****************************************************************************
554 * VideoWindow::CorrectAspectRatio
555 *****************************************************************************/
557 VideoWindow::CorrectAspectRatio() const
559 return fSettings->HasFlags(VideoSettings::FLAG_CORRECT_RATIO);
562 /*****************************************************************************
563 * VideoWindow::ToggleFullScreen
564 *****************************************************************************/
566 VideoWindow::ToggleFullScreen()
568 SetFullScreen(!IsFullScreen());
571 /*****************************************************************************
572 * VideoWindow::SetFullScreen
573 *****************************************************************************/
575 VideoWindow::SetFullScreen(bool doIt)
579 BScreen screen(this);
580 BRect rect = screen.Frame();
583 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
584 be_app->ObscureCursor();
585 fInterfaceShowing = false;
586 fSettings->AddFlags(VideoSettings::FLAG_FULL_SCREEN);
590 MoveTo(winSize.left, winSize.top);
591 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
592 be_app->ShowCursor();
593 fInterfaceShowing = true;
594 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
598 /*****************************************************************************
599 * VideoWindow::IsFullScreen
600 *****************************************************************************/
602 VideoWindow::IsFullScreen() const
604 return fSettings->HasFlags(VideoSettings::FLAG_FULL_SCREEN);
607 /*****************************************************************************
608 * VideoWindow::SetSyncToRetrace
609 *****************************************************************************/
611 VideoWindow::SetSyncToRetrace(bool doIt)
614 fSettings->AddFlags(VideoSettings::FLAG_SYNC_RETRACE);
616 fSettings->ClearFlags(VideoSettings::FLAG_SYNC_RETRACE);
619 /*****************************************************************************
620 * VideoWindow::IsSyncedToRetrace
621 *****************************************************************************/
623 VideoWindow::IsSyncedToRetrace() const
625 return fSettings->HasFlags(VideoSettings::FLAG_SYNC_RETRACE);
629 /*****************************************************************************
630 * VideoWindow::_AllocateBuffers
631 *****************************************************************************/
633 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
635 // clear any old buffers
640 BRect bitmapFrame( 0, 0, width, height );
641 // read from config, if we are supposed to use overlay at all
642 int noOverlay = !config_GetInt( p_vout, "overlay" );
643 // test for overlay capability
644 for (int i = 0; i < COLOR_COUNT; i++)
646 if (noOverlay) break;
647 bitmap[0] = new BBitmap ( bitmapFrame,
648 B_BITMAP_WILL_OVERLAY |
649 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
650 colspace[i].colspace);
652 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
656 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
657 colspace[colspace_index].colspace);
658 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
659 colspace[colspace_index].colspace);
660 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
664 view->SetViewOverlay(bitmap[0],
665 bitmap[0]->Bounds() ,
668 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
669 view->SetViewColor(key);
670 SetTitle("VLC " PACKAGE_VERSION " (Overlay)");
676 *mode = BITMAP; // might want to try again with normal bitmaps
686 colspace_index = DEFAULT_COL; // B_RGB32
687 SetTitle( "VLC " PACKAGE_VERSION " (Bitmap)" );
688 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
689 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
690 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
692 // see if everything went well
693 status_t status = B_ERROR;
694 for (int32 i = 0; i < 3; i++)
697 status = bitmap[i]->InitCheck();
703 // clear bitmaps to black
704 for (int32 i = 0; i < 3; i++)
705 _BlankBitmap(bitmap[i]);
710 /*****************************************************************************
711 * VideoWindow::_FreeBuffers
712 *****************************************************************************/
714 VideoWindow::_FreeBuffers()
722 fInitStatus = B_ERROR;
725 /*****************************************************************************
726 * VideoWindow::_BlankBitmap
727 *****************************************************************************/
729 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
731 // no error checking (we do that earlier on and since it's a private function...
734 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
737 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
739 // we only handle weird colorspaces with special care
740 switch (bitmap->ColorSpace()) {
742 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
743 int32 height = bitmap->Bounds().IntegerHeight() + 1;
744 uint8* bits = (uint8*)bitmap->Bits();
745 int32 bpr = bitmap->BytesPerRow();
746 for (int32 y = 0; y < height; y++) {
747 // handle 2 bytes at a time
748 for (int32 i = 0; i < bpr; i += 2) {
760 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
761 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
762 int32 height = bitmap->Bounds().IntegerHeight() + 1;
763 uint8* bits = (uint8*)bitmap->Bits();
764 int32 bpr = bitmap->BytesPerRow();
765 for (int32 y = 0; y < height; y += 1) {
766 // handle 3 bytes at a time
767 for (int32 i = 0; i < bpr; i += 3) {
780 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
781 int32 height = bitmap->Bounds().IntegerHeight() + 1;
782 uint8* bits = (uint8*)bitmap->Bits();
783 int32 bpr = bitmap->BytesPerRow();
784 for (int32 y = 0; y < height; y += 1) {
785 // handle 2 bytes at a time
786 for (int32 i = 0; i < bpr; i += 2) {
797 memset(bitmap->Bits(), 0, bitmap->BitsLength());
802 /*****************************************************************************
803 * VideoWindow::_SetVideoSize
804 *****************************************************************************/
806 VideoWindow::_SetVideoSize(uint32 mode)
808 // let size depend on aspect correction
809 int32 width = CorrectAspectRatio() ? i_width : fTrueWidth;
810 int32 height = CorrectAspectRatio() ? i_height : fTrueHeight;
825 fSettings->ClearFlags(VideoSettings::FLAG_FULL_SCREEN);
826 ResizeTo(width, height);
829 /*****************************************************************************
830 * VideoWindow::_SetToSettings
831 *****************************************************************************/
833 VideoWindow::_SetToSettings()
836 uint32 mode = RESIZE_100;
837 switch (fSettings->VideoSize())
839 case VideoSettings::SIZE_50:
842 case VideoSettings::SIZE_200:
845 case VideoSettings::SIZE_100:
846 case VideoSettings::SIZE_OTHER:
850 bool fullscreen = IsFullScreen(); // remember settings
851 _SetVideoSize(mode); // because this will reset settings
852 // the fullscreen status is reflected in the settings,
853 // but not yet in the windows state
856 if (fSettings->HasFlags(VideoSettings::FLAG_ON_TOP_ALL))
857 fCachedFeel = B_FLOATING_ALL_WINDOW_FEEL;
859 fCachedFeel = B_NORMAL_WINDOW_FEEL;
860 SetFeel(fCachedFeel);
863 /*****************************************************************************
864 * VideoWindow::_SaveScreenShot
865 *****************************************************************************/
867 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
868 uint32 translatorID ) const
870 // make the info object from the parameters
871 screen_shot_info* info = new screen_shot_info;
872 info->bitmap = bitmap;
874 info->translatorID = translatorID;
875 info->width = CorrectAspectRatio() ? i_width : fTrueWidth;
876 info->height = CorrectAspectRatio() ? i_height : fTrueHeight;
877 // spawn a new thread to take care of the actual saving to disk
878 thread_id thread = spawn_thread( _save_screen_shot,
880 B_LOW_PRIORITY, (void*)info );
881 // start thread or do the job ourself if something went wrong
882 if ( thread < B_OK || resume_thread( thread ) < B_OK )
883 _save_screen_shot( (void*)info );
886 /*****************************************************************************
887 * VideoWindow::_save_screen_shot
888 *****************************************************************************/
890 VideoWindow::_save_screen_shot( void* cookie )
892 screen_shot_info* info = (screen_shot_info*)cookie;
893 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
895 // try to be as quick as possible creating the file (the user might have
896 // taken the next screen shot already!)
897 // make sure we have a unique name for the screen shot
898 BString path( info->path );
899 // create the folder if it doesn't exist
900 BString folder( info->path );
901 int32 pos = folder.FindLast("/");
904 pos++; // leave the last '/' in the string
905 if ( pos == path.Length() )
906 path << "vlc screenshot";
909 int32 removeChars = folder.Length() - pos;
910 folder.Remove( pos, removeChars );
912 create_directory( folder.String(), 0777 );
914 BEntry entry( path.String() );
915 int32 appendedNumber = 0;
916 if ( entry.Exists() && !entry.IsSymLink() )
918 // we would clobber an existing entry
919 bool foundUniqueName = false;
921 while ( !foundUniqueName ) {
922 BString newName( path.String() );
923 newName << " " << appendedNumber;
924 BEntry possiblyClobberedEntry( newName.String() );
925 if ( possiblyClobberedEntry.Exists()
926 && !possiblyClobberedEntry.IsSymLink() )
929 foundUniqueName = true;
932 if ( appendedNumber > 0 )
933 path << " " << appendedNumber;
934 // there is still a slight chance to clobber an existing
935 // file (if it was created in the "meantime"), but we take it...
936 BFile outFile( path.String(),
937 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
939 // make colorspace converted copy of bitmap
940 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
942 status_t status = convert_bitmap( info->bitmap, converted );
943 if ( status == B_OK )
945 BTranslatorRoster* roster = BTranslatorRoster::Default();
946 uint32 imageFormat = 0;
947 translator_id translator = 0;
950 // find suitable translator
951 translator_id* ids = NULL;
954 status = roster->GetAllTranslators( &ids, &count );
955 if ( status >= B_OK )
957 for ( int tix = 0; tix < count; tix++ )
959 const translation_format *formats = NULL;
960 int32 num_formats = 0;
962 status = roster->GetInputFormats( ids[tix],
963 &formats, &num_formats );
966 for ( int iix = 0; iix < num_formats; iix++ )
968 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
977 status = roster->GetOutputFormats( ids[tix],
978 &formats, &num_formats);
979 if ( status >= B_OK )
981 for ( int32 oix = 0; oix < num_formats; oix++ )
983 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
985 if ( formats[oix].type == info->translatorID )
988 imageFormat = formats[oix].type;
989 translator = ids[tix];
1000 // make bitmap stream
1001 BBitmapStream outStream( converted );
1003 status = outFile.InitCheck();
1004 if (status == B_OK) {
1005 status = roster->Translate( &outStream, NULL, NULL,
1006 &outFile, imageFormat );
1007 if ( status == B_OK )
1009 BNodeInfo nodeInfo( &outFile );
1010 if ( nodeInfo.InitCheck() == B_OK )
1012 translation_format* formats;
1014 status = roster->GetOutputFormats( translator,
1015 (const translation_format **) &formats,
1017 if ( status >= B_OK )
1019 const char * mime = NULL;
1020 for ( int ix = 0; ix < count; ix++ ) {
1021 if ( formats[ix].type == imageFormat ) {
1022 mime = formats[ix].MIME;
1027 nodeInfo.SetType( mime );
1032 outStream.DetachBitmap( &converted );
1040 delete info->bitmap;
1048 /*****************************************************************************
1050 *****************************************************************************/
1051 VLCView::VLCView(BRect bounds, vout_thread_t *p_vout_instance )
1052 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
1053 fLastMouseMovedTime(system_time()),
1054 fCursorHidden(false),
1055 fCursorInside(false),
1056 fIgnoreDoubleClick(false)
1058 p_vout = p_vout_instance;
1059 SetViewColor(B_TRANSPARENT_32_BIT);
1062 /*****************************************************************************
1064 *****************************************************************************/
1069 /*****************************************************************************
1070 * VLCVIew::AttachedToWindow
1071 *****************************************************************************/
1073 VLCView::AttachedToWindow()
1075 // in order to get keyboard events
1077 // periodically check if we want to hide the pointer
1078 Window()->SetPulseRate(1000000);
1081 /*****************************************************************************
1082 * VLCVIew::MouseDown
1083 *****************************************************************************/
1085 VLCView::MouseDown(BPoint where)
1087 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
1088 BMessage* msg = Window()->CurrentMessage();
1091 msg->FindInt32("clicks", &clicks);
1092 msg->FindInt32("buttons", (int32*)&buttons);
1096 if (buttons & B_PRIMARY_MOUSE_BUTTON)
1098 if (clicks == 2 && !fIgnoreDoubleClick)
1101 videoWindow->ToggleInterfaceShowing(); */
1102 fIgnoreDoubleClick = false;
1106 if (buttons & B_SECONDARY_MOUSE_BUTTON)
1108 // clicks will be 2 next time (if interval short enough)
1109 // even if the first click and the second
1110 // have not been made with the same mouse button
1111 fIgnoreDoubleClick = true;
1112 // launch popup menu
1113 BPopUpMenu *menu = new BPopUpMenu("context menu");
1114 menu->SetRadioMode(false);
1116 BMenuItem *halfItem = new BMenuItem("50%", new BMessage(RESIZE_50));
1117 menu->AddItem(halfItem);
1119 BMenuItem *origItem = new BMenuItem("100%", new BMessage(RESIZE_100));
1120 menu->AddItem(origItem);
1122 BMenuItem *doubleItem = new BMenuItem("200%", new BMessage(RESIZE_200));
1123 menu->AddItem(doubleItem);
1124 // Toggle FullScreen
1125 BMenuItem *zoomItem = new BMenuItem("Fullscreen", new BMessage(TOGGLE_FULL_SCREEN));
1126 zoomItem->SetMarked(videoWindow->IsFullScreen());
1127 menu->AddItem(zoomItem);
1129 menu->AddSeparatorItem();
1132 BMenuItem *vsyncItem = new BMenuItem("Vertical Sync", new BMessage(VERT_SYNC));
1133 vsyncItem->SetMarked(videoWindow->IsSyncedToRetrace());
1134 menu->AddItem(vsyncItem);
1135 // Correct Aspect Ratio
1136 BMenuItem *aspectItem = new BMenuItem("Correct Aspect Ratio", new BMessage(ASPECT_CORRECT));
1137 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
1138 menu->AddItem(aspectItem);
1140 menu->AddSeparatorItem();
1142 // Windwo Feel Items
1143 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
1144 winNormFeel->AddInt32("WinFeel", (int32)B_NORMAL_WINDOW_FEEL);
1145 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
1146 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
1147 menu->AddItem(normWindItem);
1149 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
1150 winFloatFeel->AddInt32("WinFeel", (int32)B_FLOATING_APP_WINDOW_FEEL);
1151 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
1152 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
1153 menu->AddItem(onTopWindItem);
1155 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
1156 winAllFeel->AddInt32("WinFeel", (int32)B_FLOATING_ALL_WINDOW_FEEL);
1157 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
1158 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
1159 menu->AddItem(allSpacesWindItem);*/
1161 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
1162 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
1163 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
1164 windowFeelMsg->AddInt32( "WinFeel", (int32)feel );
1165 BMenuItem *windowFeelItem = new BMenuItem( "Stay On Top", windowFeelMsg );
1166 windowFeelItem->SetMarked( onTop );
1167 menu->AddItem( windowFeelItem );
1169 menu->AddSeparatorItem();
1171 BMenuItem* screenShotItem = new BMenuItem( "Take Screen Shot",
1172 new BMessage( SCREEN_SHOT ) );
1173 menu->AddItem( screenShotItem );
1175 menu->SetTargetForItems( this );
1176 ConvertToScreen( &where );
1177 menu->Go( where, true, false, true );
1181 fLastMouseMovedTime = system_time();
1182 fCursorHidden = false;
1185 /*****************************************************************************
1187 *****************************************************************************/
1189 VLCView::MouseUp( BPoint where )
1192 val.b_bool = VLC_TRUE;
1193 var_Set( p_vout, "mouse-clicked", val );
1196 /*****************************************************************************
1197 * VLCVIew::MouseMoved
1198 *****************************************************************************/
1200 VLCView::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
1202 fLastMouseMovedTime = system_time();
1203 fCursorHidden = false;
1204 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1205 /* DVD navigation */
1206 unsigned int i_width, i_height, i_x, i_y;
1207 vout_PlacePicture( p_vout, (unsigned int)Bounds().Width(),
1208 (unsigned int)Bounds().Height(),
1209 &i_x, &i_y, &i_width, &i_height );
1211 val.i_int = ( (int)point.x - i_x ) * p_vout->render.i_width / i_width;
1212 var_Set( p_vout, "mouse-x", val );
1213 val.i_int = ( (int)point.y - i_y ) * p_vout->render.i_height / i_height;
1214 var_Set( p_vout, "mouse-y", val );
1215 val.b_bool = VLC_TRUE;
1216 var_Set( p_vout, "mouse-moved", val );
1219 /*****************************************************************************
1221 *****************************************************************************/
1225 // We are getting the pulse messages no matter if the mouse is over
1226 // this view. If we are in full screen mode, we want to hide the cursor
1227 // even if it is not.
1228 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1232 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1234 be_app->ObscureCursor();
1235 fCursorHidden = true;
1237 // hide the interface window as well if full screen
1238 if (videoWindow && videoWindow->IsFullScreen())
1239 videoWindow->SetInterfaceShowing(false);
1243 // Workaround to disable the screensaver in full screen:
1244 // we simulate an activity every 29 seconds
1245 if( videoWindow && videoWindow->IsFullScreen() &&
1246 system_time() - fLastMouseMovedTime > 29000000 )
1250 GetMouse(&where, &buttons, false);
1251 ConvertToScreen(&where);
1252 set_mouse_position((int32) where.x, (int32) where.y);
1256 /*****************************************************************************
1258 *****************************************************************************/
1260 VLCView::KeyDown(const char *bytes, int32 numBytes)
1262 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1263 BWindow* interfaceWindow = get_interface_window();
1264 if (videoWindow && numBytes > 0) {
1265 uint32 mods = modifiers();
1270 // toggle window and full screen mode
1271 // not passing on the tab key to the default KeyDown()
1272 // implementation also avoids loosing the keyboard focus
1273 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1276 // go back to window mode
1277 if (videoWindow->IsFullScreen())
1278 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1282 if (interfaceWindow)
1283 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1286 if (interfaceWindow)
1288 if (mods & B_SHIFT_KEY)
1290 interfaceWindow->PostMessage(NEXT_TITLE);
1293 interfaceWindow->PostMessage(NEXT_CHAPTER);
1297 if (interfaceWindow)
1299 if (mods & B_SHIFT_KEY)
1301 interfaceWindow->PostMessage(PREV_TITLE);
1304 interfaceWindow->PostMessage(PREV_CHAPTER);
1308 // previous file in playlist
1309 interfaceWindow->PostMessage(PREV_FILE);
1312 // next file in playlist
1313 interfaceWindow->PostMessage(NEXT_FILE);
1318 videoWindow->PostMessage( SCREEN_SHOT );
1321 BView::KeyDown(bytes, numBytes);
1327 /*****************************************************************************
1329 *****************************************************************************/
1331 VLCView::Draw(BRect updateRect)
1333 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1334 if ( window && window->mode == BITMAP )
1335 FillRect( updateRect );
1338 /*****************************************************************************
1340 *****************************************************************************/
1341 static int Init ( vout_thread_t * );
1342 static void End ( vout_thread_t * );
1343 // static int Manage ( vout_thread_t * );
1344 static void Display ( vout_thread_t *, picture_t * );
1346 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1347 static void BeosCloseDisplay( vout_thread_t *p_vout );
1349 /*****************************************************************************
1350 * OpenVideo: allocates BeOS video thread output method
1351 *****************************************************************************
1352 * This function allocates and initializes a BeOS vout method.
1353 *****************************************************************************/
1354 int E_(OpenVideo) ( vlc_object_t *p_this )
1356 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1358 /* Allocate structure */
1359 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1360 if( p_vout->p_sys == NULL )
1362 msg_Err( p_vout, "out of memory" );
1365 p_vout->p_sys->i_width = p_vout->render.i_width;
1366 p_vout->p_sys->i_height = p_vout->render.i_height;
1367 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1369 p_vout->pf_init = Init;
1370 p_vout->pf_end = End;
1371 p_vout->pf_manage = NULL;
1372 p_vout->pf_render = NULL;
1373 p_vout->pf_display = Display;
1378 /*****************************************************************************
1379 * Init: initialize BeOS video thread output method
1380 *****************************************************************************/
1381 int Init( vout_thread_t *p_vout )
1386 I_OUTPUTPICTURES = 0;
1388 /* Open and initialize device */
1389 if( BeosOpenDisplay( p_vout ) )
1391 msg_Err(p_vout, "vout error: can't open display");
1394 p_vout->output.i_width = p_vout->render.i_width;
1395 p_vout->output.i_height = p_vout->render.i_height;
1397 /* Assume we have square pixels */
1398 p_vout->output.i_aspect = p_vout->p_sys->i_width
1399 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1400 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1401 p_vout->p_sys->i_index = 0;
1403 p_vout->b_direct = 1;
1405 p_vout->output.i_rmask = 0x00ff0000;
1406 p_vout->output.i_gmask = 0x0000ff00;
1407 p_vout->output.i_bmask = 0x000000ff;
1409 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1412 /* Find an empty picture slot */
1413 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1416 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1418 p_pic = p_vout->p_picture + i_index;
1427 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1428 p_pic->p->i_lines = p_vout->p_sys->i_height;
1430 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1431 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1432 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1433 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1435 p_pic->i_status = DESTROYED_PICTURE;
1436 p_pic->i_type = DIRECT_PICTURE;
1438 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1446 /*****************************************************************************
1447 * End: terminate BeOS video thread output method
1448 *****************************************************************************/
1449 void End( vout_thread_t *p_vout )
1451 BeosCloseDisplay( p_vout );
1454 /*****************************************************************************
1455 * CloseVideo: destroy BeOS video thread output method
1456 *****************************************************************************
1457 * Terminate an output method created by DummyCreateOutputMethod
1458 *****************************************************************************/
1459 void E_(CloseVideo) ( vlc_object_t *p_this )
1461 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1463 free( p_vout->p_sys );
1466 /*****************************************************************************
1467 * Display: displays previously rendered output
1468 *****************************************************************************
1469 * This function send the currently rendered image to BeOS image, waits until
1470 * it is displayed and switch the two rendering buffers, preparing next frame.
1471 *****************************************************************************/
1472 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1474 VideoWindow * p_win = p_vout->p_sys->p_window;
1476 /* draw buffer if required */
1477 if (!p_win->teardownwindow)
1479 p_win->drawBuffer(p_vout->p_sys->i_index);
1482 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1483 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1486 /* following functions are local */
1488 /*****************************************************************************
1489 * BeosOpenDisplay: open and initialize BeOS device
1490 *****************************************************************************/
1491 static int BeosOpenDisplay( vout_thread_t *p_vout )
1494 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1495 p_vout->p_sys->i_height - 1,
1497 20 + p_vout->i_window_width - 1,
1498 50 + p_vout->i_window_height - 1 ),
1500 if( p_vout->p_sys->p_window == NULL )
1502 msg_Err( p_vout, "cannot allocate VideoWindow" );
1507 p_vout->p_sys->p_window->Show();
1513 /*****************************************************************************
1514 * BeosDisplay: close and reset BeOS device
1515 *****************************************************************************
1516 * Returns all resources allocated by BeosOpenDisplay and restore the original
1517 * state of the device.
1518 *****************************************************************************/
1519 static void BeosCloseDisplay( vout_thread_t *p_vout )
1521 VideoWindow * p_win = p_vout->p_sys->p_window;
1522 /* Destroy the video window */
1523 if( p_win != NULL && !p_win->teardownwindow)
1526 p_win->teardownwindow = true;