1 /*****************************************************************************
2 * intf_beos.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: intf_beos.cpp,v 1.24 2001/04/12 11:10:16 tcastley Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tony@castley.net>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 #define MODULE_NAME beos
28 #include "modules_inner.h"
30 /*****************************************************************************
32 *****************************************************************************/
36 #include <stdlib.h> /* malloc(), free() */
38 #include <kernel/OS.h>
39 #include <storage/Path.h>
45 #include <StatusBar.h>
46 #include <Application.h>
50 #include <DirectWindow.h>
55 #include <FilePanel.h>
59 #include <Directory.h>
62 #include <StorageDefs.h>
64 #include <scsiprobe_driver.h>
75 #include "stream_control.h"
76 #include "input_ext-intf.h"
78 #include "interface.h"
79 #include "intf_playlist.h"
81 #include "audio_output.h"
87 #include "InterfaceWindow.h"
89 #include "TransportButton.h"
91 /*****************************************************************************
92 * intf_sys_t: description and status of FB interface
93 *****************************************************************************/
94 typedef struct intf_sys_s
96 InterfaceWindow * p_window;
100 /*****************************************************************************
102 *****************************************************************************/
104 InterfaceWindow::InterfaceWindow( BRect frame, const char *name , intf_thread_t *p_interface )
105 : BWindow(frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
106 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK |B_ASYNCHRONOUS_CONTROLS)
109 p_intf = p_interface;
114 SetName( "interface" );
115 SetTitle(VOUT_TITLE " (BeOS interface)");
116 BRect rect(0, 0, 0, 0);
119 menu_bar = new BMenuBar(rect, "main menu");
120 AddChild( menu_bar );
126 menu_bar->AddItem( m = new BMenu("File") );
127 menu_bar->ResizeToPreferred();
128 m->AddItem( new BMenuItem("Open File...", new BMessage(OPEN_FILE), 'O'));
129 cd_menu = new CDMenu("Open Disc");
131 m->AddSeparatorItem();
132 m->AddItem( new BMenuItem("About...", new BMessage(B_ABOUT_REQUESTED), 'A'));
133 m->AddItem( new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
135 menu_bar->AddItem (am = new BMenu("Audio") );
136 menu_bar->ResizeToPreferred();
137 am->AddItem( new LanguageMenu("Language", AUDIO_ES, p_intf) );
138 am->AddItem( new LanguageMenu("Subtitles", SPU_ES, p_intf) );
142 rect.top += menu_bar->Bounds().IntegerHeight()+1;
145 p_view = new BBox( rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER );
146 p_view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
150 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
151 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
152 xStart += kRewindBitmapWidth;
153 TransportButton* p_slow = new TransportButton(ButtonRect, B_EMPTY_STRING,
155 kPressedSkipBackBitmapBits,
156 kDisabledSkipBackBitmapBits,
157 new BMessage(SLOWER_PLAY));
158 p_view->AddChild( p_slow );
161 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
162 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kPlayButtonSize);
163 xStart += kPlayPauseBitmapWidth + 1.0;
164 PlayPauseButton* p_play = new PlayPauseButton(ButtonRect, B_EMPTY_STRING,
165 kPlayButtonBitmapBits,
166 kPressedPlayButtonBitmapBits,
167 kDisabledPlayButtonBitmapBits,
168 kPlayingPlayButtonBitmapBits,
169 kPressedPlayingPlayButtonBitmapBits,
170 kPausedPlayButtonBitmapBits,
171 kPressedPausedPlayButtonBitmapBits,
172 new BMessage(START_PLAYBACK));
174 p_view->AddChild( p_play );
175 p_play->SetPlaying();
178 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
179 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSkipButtonSize);
180 xStart += kRewindBitmapWidth;
181 TransportButton* p_fast = new TransportButton(ButtonRect, B_EMPTY_STRING,
182 kSkipForwardBitmapBits,
183 kPressedSkipForwardBitmapBits,
184 kDisabledSkipForwardBitmapBits,
185 new BMessage(FASTER_PLAY));
186 p_view->AddChild( p_fast );
189 ButtonRect.SetLeftTop(BPoint(xStart, yStart));
190 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kStopButtonSize);
191 xStart += kStopBitmapWidth;
192 TransportButton* p_stop = new TransportButton(ButtonRect, B_EMPTY_STRING,
193 kStopButtonBitmapBits,
194 kPressedStopButtonBitmapBits,
195 kDisabledStopButtonBitmapBits,
196 new BMessage(STOP_PLAYBACK));
197 p_view->AddChild( p_stop );
199 ButtonRect.SetLeftTop(BPoint(xStart + 5, yStart + 6));
200 ButtonRect.SetRightBottom(ButtonRect.LeftTop() + kSpeakerButtonSize);
201 xStart += kSpeakerIconBitmapWidth;
203 TransportButton* p_mute = new TransportButton(ButtonRect, B_EMPTY_STRING,
205 kPressedSpeakerIconBits,
207 new BMessage(VOLUME_MUTE));
209 p_view->AddChild( p_mute );
212 rgb_color fill_color = {0,255,0};
213 p_seek = new SeekSlider(BRect(5,2,255,15), this, 0, 100,
216 p_seek->UseFillColor(true, &fill_color);
217 p_view->AddChild( p_seek );
220 p_vol = new MediaSlider(BRect(xStart,20,255,30), new BMessage(VOLUME_CHG),
222 p_vol->SetValue(VOLUME_DEFAULT);
223 p_vol->UseFillColor(true, &fill_color);
224 p_view->AddChild( p_vol );
226 /* Set size and Show */
228 ResizeTo(260,50 + menu_bar->Bounds().IntegerHeight()+1);
232 InterfaceWindow::~InterfaceWindow()
236 /*****************************************************************************
237 * InterfaceWindow::MessageReceived
238 *****************************************************************************/
239 void InterfaceWindow::MessageReceived( BMessage * p_message )
241 int vol_val = p_vol->Value(); // remember the current volume
242 static int playback_status; // remember playback state
246 switch( p_message->what )
248 case B_ABOUT_REQUESTED:
249 alert = new BAlert(VOUT_TITLE, "BeOS " VOUT_TITLE "\n\n<www.videolan.org>", "Ok");
259 file_panel = new BFilePanel();
260 file_panel->SetTarget(this);
266 char device_method_and_name[B_FILE_NAME_LENGTH + 4];
267 if(p_message->FindString("device", device) != B_ERROR)
269 sprintf(device_method_and_name, "dvd:%s", *device);
270 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, device_method_and_name );
275 // this currently stops playback not nicely
276 if (p_intf->p_input != NULL )
278 // silence the sound, otherwise very horrible
279 if (p_main->p_aout != NULL)
281 p_main->p_aout->vol = 0;
284 input_SetStatus(p_intf->p_input, INPUT_STATUS_END);
288 // starts playing in normal mode
289 // if (p_intf->p_input != NULL )
291 // if (p_main->p_aout != NULL)
293 // p_main->p_aout->vol = vol_val;
296 // input_SetStatus(p_intf->p_input, INPUT_STATUS_PLAY);
297 // playback_status = PLAYING;
301 // pause the playback
302 if (p_intf->p_input != NULL )
304 // mute the volume if currently playing
305 if (playback_status == PLAYING)
307 if (p_main->p_aout != NULL)
309 p_main->p_aout->vol = 0;
311 playback_status = PAUSED;
314 // restore the volume
316 if (p_main->p_aout != NULL)
318 p_main->p_aout->vol = vol_val;
320 playback_status = PLAYING;
323 input_SetStatus(p_intf->p_input, INPUT_STATUS_PAUSE);
327 // cycle the fast playback modes
328 if (p_intf->p_input != NULL )
330 if (p_main->p_aout != NULL)
332 p_main->p_aout->vol = 0;
335 input_SetStatus(p_intf->p_input, INPUT_STATUS_FASTER);
339 // cycle the slow playback modes
340 if (p_intf->p_input != NULL )
342 if (p_main->p_aout != NULL)
344 p_main->p_aout->vol = 0;
347 input_SetStatus(p_intf->p_input, INPUT_STATUS_SLOWER);
351 // handled by semaphores;
355 if (p_main->p_aout != NULL)
357 p_main->p_aout->vol = vol_val;
362 if (p_main->p_aout != NULL)
364 if (p_main->p_aout->vol == 0)
366 p_vol->SetEnabled(true);
367 p_main->p_aout->vol = vol_val;
371 p_vol->SetEnabled(false);
372 p_main->p_aout->vol = 0;
378 int32 i = p_message->FindInt32("channel");
379 input_ChangeES(p_intf->p_input,
380 p_intf->p_input->stream.pp_es[i], 1);
383 case SELECT_SUBTITLE:
385 int32 i = p_message->FindInt32("subtitle");
386 input_ChangeES(p_intf->p_input,
387 p_intf->p_input->stream.pp_es[i], 2);
390 case B_REFS_RECEIVED:
394 if( p_message->FindRef( "refs", &ref ) == B_OK )
397 intf_PlaylistAdd( p_main->p_playlist,
398 PLAYLIST_END, path.Path() );
404 BWindow::MessageReceived( p_message );
409 /*****************************************************************************
410 * InterfaceWindow::QuitRequested
411 *****************************************************************************/
412 bool InterfaceWindow::QuitRequested()
419 /*****************************************************************************
421 *****************************************************************************/
422 CDMenu::CDMenu(const char *name)
427 /*****************************************************************************
429 *****************************************************************************/
434 /*****************************************************************************
435 * CDMenu::AttachedToWindow
436 *****************************************************************************/
437 void CDMenu::AttachedToWindow(void)
439 while (RemoveItem((long int)0) != NULL); // remove all items
441 BMenu::AttachedToWindow();
444 /*****************************************************************************
446 *****************************************************************************/
447 int CDMenu::GetCD(const char *directory)
450 dir.SetTo(directory);
451 if(dir.InitCheck() != B_NO_ERROR) {
456 while(dir.GetNextEntry(&entry) >= 0) {
461 if(entry.GetPath(&path) != B_NO_ERROR)
466 if(entry.GetRef(&e) != B_NO_ERROR)
469 if(entry.IsDirectory()) {
470 if(strcmp(e.name, "floppy") == 0)
471 continue; // ignore floppy (it is not silent)
472 int devfd = GetCD(name);
483 if(strcmp(e.name, "raw") != 0)
484 continue; // ignore partitions
486 devfd = open(name, O_RDONLY);
490 if(ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
491 if(g.device_type == B_CD) //ensure the drive is a CD-ROM
493 if(ioctl(devfd, B_GET_MEDIA_STATUS, &m, sizeof(m)) >= 0 )
494 if(m == B_NO_ERROR) //ensure media is present
497 msg = new BMessage(OPEN_DVD);
498 msg->AddString("device", name);
499 BMenuItem *menu_item;
500 menu_item = new BMenuItem(name, msg);
512 /*****************************************************************************
513 * LanguageMenu::LanguageMenu
514 *****************************************************************************/
515 LanguageMenu::LanguageMenu(const char *name, int menu_kind, intf_thread_t *p_interface)
519 p_intf = p_interface;
522 /*****************************************************************************
523 * LanguageMenu::~LanguageMenu
524 *****************************************************************************/
525 LanguageMenu::~LanguageMenu()
529 /*****************************************************************************
530 * LanguageMenu::AttachedToWindow
531 *****************************************************************************/
532 void LanguageMenu::AttachedToWindow(void)
534 while (RemoveItem((long int)0) != NULL); // remove all items
537 BMenu::AttachedToWindow();
540 /*****************************************************************************
541 * LanguageMenu::GetChannels
542 *****************************************************************************/
543 int LanguageMenu::GetChannels()
549 es_descriptor_t *p_es;
551 if (p_intf->p_input == NULL)
554 for (i = 0; i < p_intf->p_input->stream.i_selected_es_number; i++)
557 p_intf->p_input->stream.pp_selected_es[i]->i_cat)
559 p_es = p_intf->p_input->stream.pp_selected_es[i];
562 for (i = 0; i < p_intf->p_input->stream.i_es_number; i++)
564 if (kind == p_intf->p_input->stream.pp_es[i]->i_cat)
566 psz_name = p_intf->p_input->stream.pp_es[i]->psz_desc;
568 if (kind == AUDIO_ES) //audio
570 msg = new BMessage(SELECT_CHANNEL);
571 msg->AddInt32("channel", i);
575 msg = new BMessage(SELECT_SUBTITLE);
576 msg->AddInt32("subtitle", i);
578 BMenuItem *menu_item;
579 menu_item = new BMenuItem(psz_name, msg);
581 b_active = (p_es == p_intf->p_input->stream.pp_es[i]);
582 menu_item->SetMarked(b_active);
588 /*****************************************************************************
590 *****************************************************************************/
591 MediaSlider::MediaSlider(BRect frame,
595 :BSlider(frame, NULL, NULL, message, minValue, maxValue)
600 MediaSlider::~MediaSlider()
605 void MediaSlider::DrawThumb(void)
610 rgb_color black = {0,0,0};
614 v->SetHighColor(black);
616 v->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
617 r.InsetBy(r.IntegerWidth()/4, r.IntegerHeight()/(4 * r.IntegerWidth() / r.IntegerHeight()));
620 v->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
622 v->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT));
627 /*****************************************************************************
629 *****************************************************************************/
630 SeekSlider::SeekSlider(BRect frame,
631 InterfaceWindow *owner,
634 thumb_style thumbType = B_TRIANGLE_THUMB)
635 :MediaSlider(frame, NULL, minValue, maxValue)
641 SeekSlider::~SeekSlider()
645 /*****************************************************************************
646 * SeekSlider::MouseDown
647 *****************************************************************************/
648 void SeekSlider::MouseDown(BPoint where)
650 BSlider::MouseDown(where);
651 fOwner->fScrubSem = create_sem(1, "Vlc::fScrubSem");
655 /*****************************************************************************
656 * SeekSlider::MouseUp
657 *****************************************************************************/
658 void SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage *message)
660 BSlider::MouseMoved(where, code, message);
663 release_sem(fOwner->fScrubSem);
666 /*****************************************************************************
667 * SeekSlider::MouseUp
668 *****************************************************************************/
669 void SeekSlider::MouseUp(BPoint where)
671 BSlider::MouseUp(where);
672 delete_sem(fOwner->fScrubSem);
673 fOwner->fScrubSem = B_ERROR;
681 /*****************************************************************************
683 *****************************************************************************/
684 static int intf_Probe ( probedata_t *p_data );
685 static int intf_Open ( intf_thread_t *p_intf );
686 static void intf_Close ( intf_thread_t *p_intf );
687 static void intf_Run ( intf_thread_t *p_intf );
689 /*****************************************************************************
690 * Functions exported as capabilities. They are declared as static so that
691 * we don't pollute the namespace too much.
692 *****************************************************************************/
693 void _M( intf_getfunctions )( function_list_t * p_function_list )
695 p_function_list->pf_probe = intf_Probe;
696 p_function_list->functions.intf.pf_open = intf_Open;
697 p_function_list->functions.intf.pf_close = intf_Close;
698 p_function_list->functions.intf.pf_run = intf_Run;
701 /*****************************************************************************
702 * intf_Probe: probe the interface and return a score
703 *****************************************************************************
704 * This function tries to initialize Gnome and returns a score to the
705 * plugin manager so that it can select the best plugin.
706 *****************************************************************************/
707 static int intf_Probe( probedata_t *p_data )
709 if( TestMethod( INTF_METHOD_VAR, "beos" ) )
717 /*****************************************************************************
718 * intf_Open: initialize interface
719 *****************************************************************************/
720 static int intf_Open( intf_thread_t *p_intf )
723 screen = new BScreen();
724 BRect rect = screen->Frame();
725 rect.top = rect.bottom-100;
728 rect.right = rect.left + 350;
731 /* Allocate instance and initialize some members */
732 p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
733 if( p_intf->p_sys == NULL )
735 intf_ErrMsg("error: %s", strerror(ENOMEM));
738 p_intf->p_sys->i_key = -1;
740 /* Create the interface window */
741 p_intf->p_sys->p_window =
742 new InterfaceWindow( rect,
743 VOUT_TITLE " (BeOS interface)", p_intf );
744 if( p_intf->p_sys->p_window == 0 )
746 free( p_intf->p_sys );
747 intf_ErrMsg( "error: cannot allocate memory for InterfaceWindow" );
754 /*****************************************************************************
755 * intf_Close: destroy dummy interface
756 *****************************************************************************/
757 static void intf_Close( intf_thread_t *p_intf )
759 /* Destroy the interface window */
760 p_intf->p_sys->p_window->Lock();
761 p_intf->p_sys->p_window->Quit();
763 /* Destroy structure */
764 free( p_intf->p_sys );
768 /*****************************************************************************
769 * intf_Run: event loop
770 *****************************************************************************/
771 static void intf_Run( intf_thread_t *p_intf )
775 bool seekNeeded = false;
777 while( !p_intf->b_die )
780 /* Manage core vlc functions through the callback */
781 p_intf->pf_manage( p_intf );
783 /* Manage the slider */
784 if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL)
786 if (acquire_sem(p_intf->p_sys->p_window->fScrubSem) == B_OK)
793 uint32 seekTo = (p_intf->p_sys->p_window->p_seek->Value() *
794 p_intf->p_input->stream.p_selected_area->i_size) / 100;
795 input_Seek( p_intf->p_input, seekTo );
798 else if (p_intf->p_sys->p_window->Lock())
800 progress = (100. * p_intf->p_input->stream.p_selected_area->i_tell) /
801 p_intf->p_input->stream.p_selected_area->i_size;
802 p_intf->p_sys->p_window->p_seek->SetValue(progress);
803 p_intf->p_sys->p_window->Unlock();
808 msleep( INTF_IDLE_SLEEP );