diff options
Diffstat (limited to 'avmedia/source')
79 files changed, 15255 insertions, 0 deletions
diff --git a/avmedia/source/framework/makefile.mk b/avmedia/source/framework/makefile.mk new file mode 100644 index 000000000000..4185f3cbfc49 --- /dev/null +++ b/avmedia/source/framework/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmedia +TARGET=framework + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Resources --------------------------------- + +SRS1NAME=$(TARGET) +SRC1FILES =\ + mediacontrol.src + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/mediaitem.obj \ + $(SLO)$/mediamisc.obj \ + $(SLO)$/mediacontrol.obj \ + $(SLO)$/mediatoolbox.obj \ + $(SLO)$/mediaplayer.obj \ + $(SLO)$/soundhandler.obj + +EXCEPTIONSFILES = \ + $(SLO)$/mediatoolbox.obj \ + $(SLO)$/soundhandler.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/avmedia/source/framework/mediacontrol.cxx b/avmedia/source/framework/mediacontrol.cxx new file mode 100644 index 000000000000..2eb18cb164d9 --- /dev/null +++ b/avmedia/source/framework/mediacontrol.cxx @@ -0,0 +1,631 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediacontrol.hxx" +#include "mediacontrol.hrc" +#include "mediamisc.hxx" +#include <avmedia/mediawindow.hxx> +#include <avmedia/mediaplayer.hxx> +#include "helpids.hrc" +#include <tools/time.hxx> +#include <vcl/svapp.hxx> +#include <vcl/lstbox.hxx> +#include <unotools/syslocale.hxx> +#include <sfx2/viewfrm.hxx> +#include <math.h> +#include <algorithm> + +#define AVMEDIA_TIMEOUT 100 +#define AVMEDIA_TIME_RANGE 2048 +#define AVMEDIA_DB_RANGE -40 +#define AVMEDIA_LINEINCREMENT 1.0 +#define AVMEDIA_PAGEINCREMENT 10.0 + +#define AVMEDIA_TOOLBOXITEM_PLAY 0x0001 +#define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002 +#define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004 +#define AVMEDIA_TOOLBOXITEM_STOP 0x0008 +#define AVMEDIA_TOOLBOXITEM_MUTE 0x0010 +#define AVMEDIA_TOOLBOXITEM_LOOP 0x0011 +#define AVMEDIA_TOOLBOXITEM_ZOOM 0x0012 +#define AVMEDIA_TOOLBOXITEM_OPEN 0x0014 +#define AVMEDIA_TOOLBOXITEM_INSERT 0x0018 + +#define AVMEDIA_ZOOMLEVEL_50 0 +#define AVMEDIA_ZOOMLEVEL_100 1 +#define AVMEDIA_ZOOMLEVEL_200 2 +#define AVMEDIA_ZOOMLEVEL_FIT 3 +#define AVMEDIA_ZOOMLEVEL_SCALED 4 +#define AVMEDIA_ZOOMLEVEL_INVALID 65535 + +namespace avmedia +{ + +// ---------------- +// - MediaControl - +// --------------- + +MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) : + Control( pParent ), + maImageList( AVMEDIA_RESID( AVMEDIA_IMGLST ) ), + maItem( 0, AVMEDIA_SETMASK_ALL ), + maPlayToolBox( this, WB_3DLOOK ), + maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ), + maMuteToolBox( this, WB_3DLOOK ), + maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ), + maZoomToolBox( this, WB_3DLOOK ), + mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ), + maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ), + meControlStyle( eControlStyle ), + mbLocked( false ) +{ + const String aTimeText( RTL_CONSTASCII_USTRINGPARAM( " 00:00:00/00:00:00 " ) ); + + SetBackground(); + SetPaintTransparent( TRUE ); + SetParentClipMode( PARENTCLIPMODE_NOCLIP ); + + if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle ) + { + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), String( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), String( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT ); + + maPlayToolBox.InsertSeparator(); + } + else + { + mpZoomListBox->SetBackground(); + + maZoomToolBox.SetBackground(); + maZoomToolBox.SetPaintTransparent( TRUE ); + maPlayToolBox.SetBackground(); + maPlayToolBox.SetPaintTransparent( TRUE ); + maMuteToolBox.SetBackground(); + maMuteToolBox.SetPaintTransparent( TRUE ); + + } + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), String( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), String( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), String( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP ); + + maPlayToolBox.InsertSeparator(); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), String( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP ); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maPlayToolBox.InsertSeparator(); + + maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() ); + maPlayToolBox.Show(); + maMinSize = maPlayToolBox.GetSizePixel(); + + maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) ); + maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) ); + maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) ); + maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER ); + maTimeSlider.SetUpdateMode( true ); + maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) ); + maTimeSlider.Show(); + maMinSize.Width() += maTimeSlider.GetSizePixel().Width(); + + maTimeEdit.SetText( aTimeText ); + maTimeEdit.SetUpdateMode( true ); + maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) ); + maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() ); + maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT ); + maTimeEdit.Disable(); + maTimeEdit.Show(); + maMinSize.Width() += maTimeEdit.GetSizePixel().Width(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maMuteToolBox.InsertSeparator(); + + maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), String( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) ); + maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE ); + + maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() ); + maMuteToolBox.Show(); + maMinSize.Width() += maMuteToolBox.GetSizePixel().Width(); + + maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) ); + maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) ); + maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) ); + maVolumeSlider.SetUpdateMode( true ); + maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER ); + maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) ); + maVolumeSlider.Show(); + maMinSize.Width() += maVolumeSlider.GetSizePixel().Width(); + + mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT ); + mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) ); + mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX ); + + maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) ); + maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX ); + + maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox ); + maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() ); + maZoomToolBox.Show(); + maMinSize.Width() += maZoomToolBox.GetSizePixel().Width(); + + if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle ) + { + maMinSize.Width() = 256; + maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET; + } + + maTimer.SetTimeout( AVMEDIA_TIMEOUT ); + maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) ); + maTimer.Start(); +} + +// ------------------------------------------------------------------------------ + +MediaControl::~MediaControl() +{ + maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL ); + delete mpZoomListBox; +} + +// ------------------------------------------------------------------------------ + +const Size& MediaControl::getMinSizePixel() const +{ + return maMinSize; +} + +// ------------------------------------------------------------------------------ + +void MediaControl::Resize() +{ + Point aPos( 0, 0 ); + const sal_Int32 nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width(); + const sal_Int32 nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width(); + const sal_Int32 nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width(); + const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width(); + const sal_Int32 nTimeEditWidth = maTimeEdit.GetSizePixel().Width(); + const sal_Int32 nTimeSliderHeight = maTimeSlider.GetSizePixel().Height(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + { + const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) - + nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth; + + maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() ); + + aPos.X() += nPlayToolBoxWidth; + maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) ); + + aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET; + maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() ); + + aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET; + maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() ); + + aPos.X() += nMuteToolBoxWidth; + maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() ); + + aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET; + maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() ); + } + else + { + const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth; + + maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) ); + + aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET; + maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() ); + + aPos.X() = 0; + aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET; + maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() ); + + aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET; + maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() ); + + aPos.X() += nMuteToolBoxWidth; + maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() ); + + aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth; + maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::setState( const MediaItem& rItem ) +{ + if( !mbLocked ) + { + maItem.merge( rItem ); + + implUpdateToolboxes(); + implUpdateTimeSlider(); + implUpdateVolumeSlider(); + implUpdateTimeField( maItem.getTime() ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::getState( MediaItem& rItem ) const +{ + rItem.merge( maItem ); +} + +// ------------------------------------------------------------------------------ + +void MediaControl::update() +{ +} + +// ------------------------------------------------------------------------------ + +void MediaControl::execute( const MediaItem& ) +{ +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateToolboxes() +{ + const bool bValidURL = ( maItem.getURL().getLength() > 0 ); + + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL ); + maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL ); + + if( !bValidURL || !IsEnabled() ) + { + mpZoomListBox->Disable(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maPlayToolBox.Disable(); + + maMuteToolBox.Disable(); + } + else + { + maPlayToolBox.Enable(); + maMuteToolBox.Enable(); + + if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() ) + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false ); + } + else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) ) + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false ); + } + else + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true ); + } + + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() ); + maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() ); + + if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() ) + { + USHORT nSelectEntryPos ; + + switch( maItem.getZoom() ) + { + case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break; + case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break; + case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break; + case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break; + case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break; + + default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break; + } + + if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID ) + { + mpZoomListBox->Enable(); + mpZoomListBox->SelectEntryPos( nSelectEntryPos ); + } + else + mpZoomListBox->Disable(); + } + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateTimeSlider() +{ + if( !maItem.getURL().getLength() || !IsEnabled() ) + maTimeSlider.Disable(); + else + { + maTimeSlider.Enable(); + + const double fDuration = maItem.getDuration(); + + if( fDuration > 0.0 ) + { + const double fTime = ::std::min( maItem.getTime(), fDuration ); + + if( !maTimeSlider.GetLineSize() ) + maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) ); + + if( !maTimeSlider.GetPageSize() ) + maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) ); + + maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) ); + } + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateVolumeSlider() +{ + if( !maItem.getURL().getLength() || !IsEnabled() ) + maVolumeSlider.Disable(); + else + { + maVolumeSlider.Enable(); + + const sal_Int32 nVolumeDB = maItem.getVolumeDB(); + + maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ), + static_cast< sal_Int32 >( 0 ) ) ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateTimeField( double fCurTime ) +{ + if( maItem.getURL().getLength() > 0 ) + { + String aTimeString; + + SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); + + aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) ); + aTimeString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " )); + aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) ); + + if( maTimeEdit.GetText() != aTimeString ) + maTimeEdit.SetText( aTimeString ); + } +} + +// ------------------------------------------------------------------------------ + +Image MediaControl::implGetImage( sal_Int32 nImageId ) const +{ + return maImageList.GetImage( static_cast< USHORT >( nImageId ) ); +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeHdl, Slider*, p ) +{ + mbLocked = true; + maTimer.Stop(); + implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE ); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p ) +{ + MediaItem aExecItem; + + aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE ); + execute( aExecItem ); + update(); + maTimer.Start(); + mbLocked = false; + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p ) +{ + MediaItem aExecItem; + + aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) ); + execute( aExecItem ); + update(); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implVolumeEndHdl, Slider*, EMPTYARG ) +{ + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p ) +{ + if( p ) + { + MediaItem aExecItem; + + switch( p->GetCurItemId() ) + { + case( AVMEDIA_TOOLBOXITEM_OPEN ): + { + ::rtl::OUString aURL; + + if( ::avmedia::MediaWindow::executeMediaURLDialog( GetParent(), aURL, false ) ) + { + if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) ) + ::avmedia::MediaWindow::executeFormatErrorBox( this ); + else + { + aExecItem.setURL( aURL ); + aExecItem.setState( MEDIASTATE_PLAY ); + } + } + } + break; + + case( AVMEDIA_TOOLBOXITEM_INSERT ): + { + MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW(); + + if( pFloater ) + pFloater->dispatchCurrentURL(); + } + break; + + case( AVMEDIA_TOOLBOXITEM_PLAY ): + case( AVMEDIA_TOOLBOXITEM_PLAYFFW ): + { + aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY ); + + if( maItem.getTime() == maItem.getDuration() ) + aExecItem.setTime( 0.0 ); + else + aExecItem.setTime( maItem.getTime() ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_PAUSE ): + { + aExecItem.setState( MEDIASTATE_PAUSE ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_STOP ): + { + aExecItem.setState( MEDIASTATE_STOP ); + aExecItem.setTime( 0.0 ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_MUTE ): + { + aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_LOOP ): + { + aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) ); + } + break; + + default: + break; + } + + if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE ) + execute( aExecItem ); + } + + update(); + p->Invalidate( INVALIDATE_UPDATE ); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p ) +{ + if( p ) + { + MediaItem aExecItem; + ::com::sun::star::media::ZoomLevel eLevel; + + switch( p->GetSelectEntryPos() ) + { + case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break; + case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break; + case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break; + case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break; + case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break; + + default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break; + } + + aExecItem.setZoom( eLevel ); + execute( aExecItem ); + update(); + } + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeoutHdl, Timer*, EMPTYARG ) +{ + update(); + maTimer.Start(); + + return 0; +} + +} diff --git a/avmedia/source/framework/mediacontrol.hrc b/avmedia/source/framework/mediacontrol.hrc new file mode 100644 index 000000000000..081958ccd42c --- /dev/null +++ b/avmedia/source/framework/mediacontrol.hrc @@ -0,0 +1,53 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define AVMEDIA_STR_PLAY 1024 +#define AVMEDIA_STR_PAUSE 1025 +#define AVMEDIA_STR_STOP 1026 +#define AVMEDIA_STR_ENDLESS 1027 +#define AVMEDIA_STR_ZOOM 1028 +#define AVMEDIA_STR_ZOOM_50 1029 +#define AVMEDIA_STR_ZOOM_100 1030 +#define AVMEDIA_STR_ZOOM_200 1031 +#define AVMEDIA_STR_ZOOM_FIT 1032 +#define AVMEDIA_STR_MUTE 1033 +#define AVMEDIA_STR_OPEN 1034 +#define AVMEDIA_STR_INSERT 1035 +#define AVMEDIA_STR_MEDIAPLAYER 1036 + +#define AVMEDIA_IMG_OPEN 2048 +#define AVMEDIA_IMG_PLAY 2049 +#define AVMEDIA_IMG_PAUSE 2050 +#define AVMEDIA_IMG_STOP 2051 +#define AVMEDIA_IMG_ENDLESS 2052 +#define AVMEDIA_IMG_INSERT 2053 +#define AVMEDIA_IMG_MUTE 2054 + +#define AVMEDIA_IMGLST 3072 +#define AVMEDIA_IMGLST_HC 3073 +#define AVMEDIA_IMGLST_L 3074 +#define AVMEDIA_IMGLST_L_HC 3075 diff --git a/avmedia/source/framework/mediacontrol.src b/avmedia/source/framework/mediacontrol.src new file mode 100644 index 000000000000..2ad203e2c34f --- /dev/null +++ b/avmedia/source/framework/mediacontrol.src @@ -0,0 +1,193 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediacontrol.hrc" + +String AVMEDIA_STR_OPEN +{ + Text[en-US] = "Open"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_INSERT +{ + Text [ en-US ] = "Apply" ; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_PLAY +{ + Text[en-US] = "Play"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_PAUSE +{ + Text[en-US] = "Pause"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_STOP +{ + Text[en-US] = "Stop"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ENDLESS +{ + Text[en-US] = "Repeat"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_MUTE +{ + Text[en-US] = "Mute"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM +{ + Text[en-US] = "View"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_50 +{ + Text[en-US] = "50%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_100 +{ + Text[en-US] = "100%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_200 +{ + Text[en-US] = "200%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_FIT +{ + Text[en-US] = "Scaled"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_MEDIAPLAYER +{ + Text[en-US] = "Media Player"; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST +{ + Prefix = "av"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_L +{ + Prefix = "avl"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_HC +{ + Prefix = "avh"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_L_HC +{ + Prefix = "avlh"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx new file mode 100644 index 000000000000..f9f85eb1ee66 --- /dev/null +++ b/avmedia/source/framework/mediaitem.cxx @@ -0,0 +1,329 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediaitem.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace ::com::sun::star; + +namespace avmedia +{ + +// ------------- +// - MediaItem - +// ------------- + +TYPEINIT1_AUTOFACTORY( MediaItem, ::SfxPoolItem ); + ::rtl::OUString maURL; + sal_uInt32 mnMaskSet; + MediaState meState; + double mfTime; + double mfDuration; + sal_Int16 mnVolumeDB; + sal_Bool mbLoop; + sal_Bool mbMute; + ::com::sun::star::media::ZoomLevel meZoom; + +// ------------------------------------------------------------------------------ + +MediaItem::MediaItem( USHORT _nWhich, sal_uInt32 nMaskSet ) : + SfxPoolItem( _nWhich ), + mnMaskSet( nMaskSet ), + meState( MEDIASTATE_STOP ), + mfTime( 0.0 ), + mfDuration( 0.0 ), + mnVolumeDB( 0 ), + mbLoop( false ), + mbMute( false ), + meZoom( ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE ) +{ +} + +// ------------------------------------------------------------------------------ + +MediaItem::MediaItem( const MediaItem& rItem ) : + SfxPoolItem( rItem ), + maURL( rItem.maURL ), + mnMaskSet( rItem.mnMaskSet ), + meState( rItem.meState ), + mfTime( rItem.mfTime ), + mfDuration( rItem.mfDuration ), + mnVolumeDB( rItem.mnVolumeDB ), + mbLoop( rItem.mbLoop ), + mbMute( rItem.mbMute ), + meZoom( rItem.meZoom ) +{ +} + +// ------------------------------------------------------------------------------ + +MediaItem::~MediaItem() +{ +} + +// ------------------------------------------------------------------------------ + +int MediaItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_ASSERT( SfxPoolItem::operator==(rItem), "unequal types" ); + return( mnMaskSet == static_cast< const MediaItem& >( rItem ).mnMaskSet && + maURL == static_cast< const MediaItem& >( rItem ).maURL && + meState == static_cast< const MediaItem& >( rItem ).meState && + mfDuration == static_cast< const MediaItem& >( rItem ).mfDuration && + mfTime == static_cast< const MediaItem& >( rItem ).mfTime && + mnVolumeDB == static_cast< const MediaItem& >( rItem ).mnVolumeDB && + mbLoop == static_cast< const MediaItem& >( rItem ).mbLoop && + mbMute == static_cast< const MediaItem& >( rItem ).mbMute && + meZoom == static_cast< const MediaItem& >( rItem ).meZoom ); +} + +// ------------------------------------------------------------------------------ + +SfxPoolItem* MediaItem::Clone( SfxItemPool* ) const +{ + return new MediaItem( *this ); +} + +//------------------------------------------------------------------------ + +SfxItemPresentation MediaItem::GetPresentation( SfxItemPresentation, + SfxMapUnit, + SfxMapUnit, + XubString& rText, + const IntlWrapper * ) const +{ + rText.Erase(); + return SFX_ITEM_PRESENTATION_NONE; +} + +//------------------------------------------------------------------------ + +BOOL MediaItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const +{ + uno::Sequence< uno::Any > aSeq( 9 ); + + aSeq[ 0 ] <<= maURL; + aSeq[ 1 ] <<= mnMaskSet; + aSeq[ 2 ] <<= static_cast< sal_Int32 >( meState ); + aSeq[ 3 ] <<= mfTime; + aSeq[ 4 ] <<= mfDuration; + aSeq[ 5 ] <<= mnVolumeDB; + aSeq[ 6 ] <<= mbLoop; + aSeq[ 7 ] <<= mbMute; + aSeq[ 8 ] <<= meZoom; + + rVal <<= aSeq; + + return true; +} + +//------------------------------------------------------------------------ + +BOOL MediaItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE ) +{ + uno::Sequence< uno::Any > aSeq; + BOOL bRet = false; + + if( ( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ) ) + { + sal_Int32 nInt32 = 0; + + aSeq[ 0 ] >>= maURL; + aSeq[ 1 ] >>= mnMaskSet; + aSeq[ 2 ] >>= nInt32; meState = static_cast< MediaState >( nInt32 ); + aSeq[ 3 ] >>= mfTime; + aSeq[ 4 ] >>= mfDuration; + aSeq[ 5 ] >>= mnVolumeDB; + aSeq[ 6 ] >>= mbLoop; + aSeq[ 7 ] >>= mbMute; + aSeq[ 8 ] >>= meZoom; + + bRet = true; + } + + return bRet; +} + +//------------------------------------------------------------------------ + +void MediaItem::merge( const MediaItem& rMediaItem ) +{ + const sal_uInt32 nMaskSet = rMediaItem.getMaskSet(); + + if( AVMEDIA_SETMASK_URL & nMaskSet ) + setURL( rMediaItem.getURL() ); + + if( AVMEDIA_SETMASK_STATE & nMaskSet ) + setState( rMediaItem.getState() ); + + if( AVMEDIA_SETMASK_DURATION & nMaskSet ) + setDuration( rMediaItem.getDuration() ); + + if( AVMEDIA_SETMASK_TIME & nMaskSet ) + setTime( rMediaItem.getTime() ); + + if( AVMEDIA_SETMASK_LOOP & nMaskSet ) + setLoop( rMediaItem.isLoop() ); + + if( AVMEDIA_SETMASK_MUTE & nMaskSet ) + setMute( rMediaItem.isMute() ); + + if( AVMEDIA_SETMASK_VOLUMEDB & nMaskSet ) + setVolumeDB( rMediaItem.getVolumeDB() ); + + if( AVMEDIA_SETMASK_ZOOM & nMaskSet ) + setZoom( rMediaItem.getZoom() ); +} + +//------------------------------------------------------------------------ + +sal_uInt32 MediaItem::getMaskSet() const +{ + return mnMaskSet; +} + +//------------------------------------------------------------------------ + +void MediaItem::setURL( const ::rtl::OUString& rURL ) +{ + maURL = rURL; + mnMaskSet |= AVMEDIA_SETMASK_URL; +} + +//------------------------------------------------------------------------ + +const ::rtl::OUString& MediaItem::getURL() const +{ + return maURL; +} + +//------------------------------------------------------------------------ + +void MediaItem::setState( MediaState eState ) +{ + meState = eState; + mnMaskSet |= AVMEDIA_SETMASK_STATE; +} + +//------------------------------------------------------------------------ + +MediaState MediaItem::getState() const +{ + return meState; +} + +//------------------------------------------------------------------------ + +void MediaItem::setDuration( double fDuration ) +{ + mfDuration = fDuration; + mnMaskSet |= AVMEDIA_SETMASK_DURATION; +} + +//------------------------------------------------------------------------ + +double MediaItem::getDuration() const +{ + return mfDuration; +} + +//------------------------------------------------------------------------ + +void MediaItem::setTime( double fTime ) +{ + mfTime = fTime; + mnMaskSet |= AVMEDIA_SETMASK_TIME; +} + +//------------------------------------------------------------------------ + +double MediaItem::getTime() const +{ + return mfTime; +} + +//------------------------------------------------------------------------ + +void MediaItem::setLoop( sal_Bool bLoop ) +{ + mbLoop = bLoop; + mnMaskSet |= AVMEDIA_SETMASK_LOOP; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::isLoop() const +{ + return mbLoop; +} + +//------------------------------------------------------------------------ + +void MediaItem::setMute( sal_Bool bMute ) +{ + mbMute = bMute; + mnMaskSet |= AVMEDIA_SETMASK_MUTE; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::isMute() const +{ + return mbMute; +} + +//------------------------------------------------------------------------ + +void MediaItem::setVolumeDB( sal_Int16 nDB ) +{ + mnVolumeDB = nDB; + mnMaskSet |= AVMEDIA_SETMASK_VOLUMEDB; +} + +//------------------------------------------------------------------------ + +sal_Int16 MediaItem::getVolumeDB() const +{ + return mnVolumeDB; +} + +//------------------------------------------------------------------------ + +void MediaItem::setZoom( ::com::sun::star::media::ZoomLevel eZoom ) +{ + meZoom = eZoom; + mnMaskSet |= AVMEDIA_SETMASK_ZOOM; +} + +//------------------------------------------------------------------------ + +::com::sun::star::media::ZoomLevel MediaItem::getZoom() const +{ + return meZoom; +} + +} diff --git a/avmedia/source/framework/mediamisc.cxx b/avmedia/source/framework/mediamisc.cxx new file mode 100644 index 000000000000..b7807e767c6d --- /dev/null +++ b/avmedia/source/framework/mediamisc.cxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/resmgr.hxx> +#include <svl/solar.hrc> +#include <vcl/svapp.hxx> + +namespace avmedia { + +ResMgr* GetResMgr() +{ + static ResMgr* pResMgr = NULL; + + if( !pResMgr ) + { + ByteString aResMgrName( "avmedia" ); + + pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + } + + return pResMgr; +} + +} // namespace avemdia diff --git a/avmedia/source/framework/mediaplayer.cxx b/avmedia/source/framework/mediaplayer.cxx new file mode 100644 index 000000000000..caab783c6a7c --- /dev/null +++ b/avmedia/source/framework/mediaplayer.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediaplayer.hxx> +#include <avmedia/mediawindow.hxx> +#include <avmedia/mediaitem.hxx> +#include "mediamisc.hxx" +#include "mediacontrol.hrc" +#include "helpids.hrc" + +#include <svl/stritem.hxx> +#include <sfx2/app.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> + +namespace avmedia +{ + +// --------------- +// - MediaPlayer - +// --------------- + +MediaPlayer::MediaPlayer( Window* _pParent, USHORT nId, SfxBindings* _pBindings, SfxChildWinInfo* pInfo ) : + SfxChildWindow( _pParent, nId ) +{ + pWindow = new MediaFloater( _pBindings, this, _pParent ); + eChildAlignment = SFX_ALIGN_NOALIGNMENT; + static_cast< MediaFloater* >( pWindow )->Initialize( pInfo ); +}; + +// ----------------------------------------------------------------------------- + +MediaPlayer::~MediaPlayer() +{ +} + +// ----------------------------------------------------------------------------- + +SFX_IMPL_DOCKINGWINDOW( MediaPlayer, SID_AVMEDIA_PLAYER ) + +// ---------------- +// - MediaFloater - +// ---------------- + +MediaFloater::MediaFloater( SfxBindings* _pBindings, SfxChildWindow* pCW, Window* pParent ) : + SfxDockingWindow( _pBindings, pCW, pParent, WB_CLOSEABLE | WB_MOVEABLE | WB_SIZEABLE | WB_DOCKABLE ), + mpMediaWindow( new MediaWindow( this, true ) ) +{ + const Size aSize( 378, 256 ); + + SetPosSizePixel( Point( 0, 0 ), aSize ); + SetMinOutputSizePixel( aSize ); + SetText( String( AVMEDIA_RESID( AVMEDIA_STR_MEDIAPLAYER ) ) ); + implInit(); + mpMediaWindow->show(); +} + +// ----------------------------------------------------------------------------- + +MediaFloater::~MediaFloater() +{ + delete mpMediaWindow; + mpMediaWindow = NULL; +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::implInit() +{ +} + +// ------------------------------------------------------------------------- + +void MediaFloater::Resize() +{ + SfxDockingWindow::Resize(); + + if( mpMediaWindow ) + mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::ToggleFloatingMode() +{ + ::avmedia::MediaItem aRestoreItem; + + mpMediaWindow->updateMediaItem( aRestoreItem ); + delete mpMediaWindow; + mpMediaWindow = NULL; + + SfxDockingWindow::ToggleFloatingMode(); + + mpMediaWindow = new MediaWindow( this, true ); + + mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); + mpMediaWindow->executeMediaItem( aRestoreItem ); + + Window* pWindow = mpMediaWindow->getWindow(); + + if( pWindow ) + pWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW ); + + mpMediaWindow->show(); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::setURL( const ::rtl::OUString& rURL, bool bPlayImmediately ) +{ + if( mpMediaWindow ) + { + mpMediaWindow->setURL( rURL ); + + if( mpMediaWindow->isValid() && bPlayImmediately ) + mpMediaWindow->start(); + } +} + +// ----------------------------------------------------------------------------- + +const ::rtl::OUString& MediaFloater::getURL() const +{ + static const ::rtl::OUString aEmptyStr; + return( mpMediaWindow ? mpMediaWindow->getURL() : aEmptyStr ); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::dispatchCurrentURL() +{ + SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); + + if( pDispatcher ) + { + const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, getURL() ); + pDispatcher->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_RECORD, &aMediaURLItem, 0L ); + } +} + +} diff --git a/avmedia/source/framework/mediatoolbox.cxx b/avmedia/source/framework/mediatoolbox.cxx new file mode 100644 index 000000000000..2da70b056bfc --- /dev/null +++ b/avmedia/source/framework/mediatoolbox.cxx @@ -0,0 +1,168 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediatoolbox.hxx> +#include <avmedia/mediaitem.hxx> +#include "mediacontrol.hxx" + +#include <sfx2/app.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/sfxsids.hrc> + +using namespace ::com::sun::star; + +namespace avmedia +{ + +// ----------------------- +// - MediaToolboxControl - +// ----------------------- + +class MediaToolBoxControl_Impl : public MediaControl +{ +public: + + MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ); + ~MediaToolBoxControl_Impl(); + + void update(); + void execute( const MediaItem& rItem ); + +private: + + MediaToolBoxControl* mpToolBoxControl; +}; + +// --------------------------------------------------------------------- + +MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ) : + MediaControl( &rParent, MEDIACONTROLSTYLE_SINGLELINE ), + mpToolBoxControl( &rControl ) +{ + SetSizePixel( getMinSizePixel() ); +} + +// --------------------------------------------------------------------- + +MediaToolBoxControl_Impl::~MediaToolBoxControl_Impl() +{ +} + +// --------------------------------------------------------------------- + +void MediaToolBoxControl_Impl::update() +{ + mpToolBoxControl->implUpdateMediaControl(); +} + +// --------------------------------------------------------------------- + +void MediaToolBoxControl_Impl::execute( const MediaItem& rItem ) +{ + mpToolBoxControl->implExecuteMediaControl( rItem ); +} + +// ----------------------- +// - MediaToolBoxControl - +// ----------------------- + +SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl, ::avmedia::MediaItem ); + +// ----------------------------------------------------------------------------- + +MediaToolBoxControl::MediaToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) : + SfxToolBoxControl( nSlotId, nId, rTbx ) +{ + rTbx.Invalidate(); +} + +// ----------------------------------------------------------------------------- + +MediaToolBoxControl::~MediaToolBoxControl() +{ +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::StateChanged( USHORT /* nSID */, SfxItemState eState, const SfxPoolItem* pState ) + +{ + MediaToolBoxControl_Impl* pCtrl = static_cast< MediaToolBoxControl_Impl* >( GetToolBox().GetItemWindow( GetId() ) ); + + DBG_ASSERT( pCtrl, "MediaToolBoxControl::StateChanged: media control not found" ); + + if( eState == SFX_ITEM_DISABLED ) + { + pCtrl->Enable( false, false ); + pCtrl->SetText( String() ); + + const MediaItem aEmptyMediaItem( 0, AVMEDIA_SETMASK_ALL ); + pCtrl->setState( aEmptyMediaItem ); + } + else + { + pCtrl->Enable( true, false ); + + const MediaItem* pMediaItem = PTR_CAST( MediaItem, pState ); + + if( pMediaItem && ( SFX_ITEM_AVAILABLE == eState ) ) + pCtrl->setState( *pMediaItem ); + } +} + +// ----------------------------------------------------------------------------- + +Window* MediaToolBoxControl::CreateItemWindow( Window *pParent ) +{ + return( pParent ? new MediaToolBoxControl_Impl( *pParent, *this ) : NULL ); +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::implUpdateMediaControl() +{ + updateStatus( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ) ); +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::implExecuteMediaControl( const MediaItem& rItem ) +{ + MediaItem aExecItem( SID_AVMEDIA_TOOLBOX ); + uno::Sequence< beans::PropertyValue > aArgs( 1 ); + uno::Any aAny; + + aExecItem.merge( rItem ); + aExecItem.QueryValue( aAny ); + aArgs[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AVMediaToolBox" ) ); + aArgs[ 0 ].Value = aAny; + + Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ), aArgs ); +} + +} diff --git a/avmedia/source/framework/soundhandler.cxx b/avmedia/source/framework/soundhandler.cxx new file mode 100644 index 000000000000..d24ae795fd76 --- /dev/null +++ b/avmedia/source/framework/soundhandler.cxx @@ -0,0 +1,563 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ + +#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_ +#include "soundhandler.hxx" +#endif + +#ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_ +#include <comphelper/mediadescriptor.hxx> +#endif + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/frame/DispatchResultState.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <comphelper/sequenceashashmap.hxx> +#include <rtl/ustrbuf.hxx> + +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/factory.hxx> + +//_________________________________________________________________________________________________________________ +// namespace +//_________________________________________________________________________________________________________________ + +namespace avmedia{ + +//_________________________________________________________________________________________________________________ +// non exported const +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// non exported definitions +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// declarations +//_________________________________________________________________________________________________________________ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** + +void SAL_CALL SoundHandler::acquire() throw() +{ + /* Don't use mutex in methods of XInterface! */ + OWeakObject::acquire(); +} + +void SAL_CALL SoundHandler::release() throw() +{ + /* Don't use mutex in methods of XInterface! */ + OWeakObject::release(); +} + +css::uno::Any SAL_CALL SoundHandler::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException ) +{ + /* Attention: Don't use mutex or guard in this method!!! Is a method of XInterface. */ + /* Ask for my own supported interfaces ...*/ + css::uno::Any aReturn( ::cppu::queryInterface( aType, + static_cast< css::lang::XTypeProvider* >(this), + static_cast< css::lang::XServiceInfo* >(this), + static_cast< css::frame::XNotifyingDispatch* >(this), + static_cast< css::frame::XDispatch* >(this), + static_cast< css::document::XExtendedFilterDetection* >(this))); + /* If searched interface not supported by this class ... */ + if ( aReturn.hasValue() == sal_False ) + { + /* ... ask baseclass for interfaces! */ + aReturn = OWeakObject::queryInterface( aType ); + } + /* Return result of this search. */ + return aReturn; +} + +css::uno::Sequence< sal_Int8 > SAL_CALL SoundHandler::getImplementationId() throw( css::uno::RuntimeException ) +{ + /* Create one Id for all instances of this class. */ + /* Use ethernet address to do this! (sal_True) */ + /* Optimize this method */ + /* We initialize a static variable only one time. And we don't must use a mutex at every call! */ + /* For the first call; pID is NULL - for the second call pID is different from NULL! */ + static ::cppu::OImplementationId* pID = NULL ; + if ( pID == NULL ) + { + /* Ready for multithreading; get global mutex for first call of this method only! see before */ + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + /* Control these pointer again ... it can be, that another instance will be faster then these! */ + if ( pID == NULL ) + { + /* Create a new static ID ... */ + static ::cppu::OImplementationId aID( sal_False ); + /* ... and set his address to static pointer! */ + pID = &aID ; + } + } + return pID->getImplementationId(); +} + +css::uno::Sequence< css::uno::Type > SAL_CALL SoundHandler::getTypes() throw( css::uno::RuntimeException ) +{ + /* Optimize this method ! */ + /* We initialize a static variable only one time. */ + /* And we don't must use a mutex at every call! */ + /* For the first call; pTypeCollection is NULL - */ + /* for the second call pTypeCollection is different from NULL! */ + static ::cppu::OTypeCollection* pTypeCollection = NULL ; + if ( pTypeCollection == NULL ) + { + /* Ready for multithreading; get global mutex for first call of this method only! see before */ + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + /* Control these pointer again ... it can be, that another instance will be faster then these! */ + if ( pTypeCollection == NULL ) + { + /* Create a static typecollection ... */ + static ::cppu::OTypeCollection aTypeCollection + ( + ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XNotifyingDispatch >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XDispatch >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::document::XExtendedFilterDetection >*)NULL ) + ); + /* ... and set his address to static pointer! */ + pTypeCollection = &aTypeCollection ; + } + } + return pTypeCollection->getTypes(); +} + +#define DECLARE_ASCII( SASCIIVALUE ) \ + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) + +#define IMPLEMENTATIONNAME_SOUNDHANDLER DECLARE_ASCII("com.sun.star.comp.framework.SoundHandler") +#define SERVICENAME_CONTENTHANDLER DECLARE_ASCII("com.sun.star.frame.ContentHandler") + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +::rtl::OUString SAL_CALL SoundHandler::getImplementationName() throw( css::uno::RuntimeException ) +{ + return impl_getStaticImplementationName(); +} + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +sal_Bool SAL_CALL SoundHandler::supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ) +{ + /* Set default return value. */ + sal_Bool bReturn = sal_False ; + /* Get names of all supported servicenames. */ + css::uno::Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames(); + const ::rtl::OUString* pArray = seqServiceNames.getConstArray(); + sal_Int32 nCounter = 0; + sal_Int32 nLength = seqServiceNames.getLength(); + /* Search for right name in list. */ + while ( + ( nCounter < nLength ) && + ( bReturn == sal_False ) + ) + { + /* Is name was found, say "YES, SERVICE IS SUPPORTED." and break loop. */ + if ( pArray[nCounter] == sServiceName ) + { + bReturn = sal_True ; + } + /* Else step to next element in list. */ + ++nCounter; + } + /* Return state of search. */ + return bReturn; +} + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +css::uno::Sequence< ::rtl::OUString > SAL_CALL SoundHandler::getSupportedServiceNames() throw( css::uno::RuntimeException ) +{ + return impl_getStaticSupportedServiceNames(); +} + +/*===========================================================================================================*/ +/* Helper for XServiceInfo */ +/*===========================================================================================================*/ +css::uno::Sequence< ::rtl::OUString > SoundHandler::impl_getStaticSupportedServiceNames() +{ + css::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 ); + seqServiceNames.getArray() [0] = SERVICENAME_CONTENTHANDLER; + return seqServiceNames; +} + +/*===========================================================================================================*/ +/* Helper for XServiceInfo */ +/*===========================================================================================================*/ +::rtl::OUString SoundHandler::impl_getStaticImplementationName() +{ + return IMPLEMENTATIONNAME_SOUNDHANDLER; +} + +css::uno::Reference< css::uno::XInterface > SAL_CALL SoundHandler::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ) +{ + /* create new instance of service */ + SoundHandler* pClass = new SoundHandler( xServiceManager ); + /* hold it alive by increasing his ref count!!! */ + css::uno::Reference< css::uno::XInterface > xService( static_cast< ::cppu::OWeakObject* >(pClass), css::uno::UNO_QUERY ); + /* initialize new service instance ... he can use his own refcount ... we hold it! */ + pClass->impl_initService(); + /* return new created service as reference */ + return xService; +} + +css::uno::Reference< css::lang::XSingleServiceFactory > SoundHandler::impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) +{ + css::uno::Reference< css::lang::XSingleServiceFactory > xReturn ( cppu::createSingleFactory ( + xServiceManager, + SoundHandler::impl_getStaticImplementationName(), + SoundHandler::impl_createInstance, + SoundHandler::impl_getStaticSupportedServiceNames() + ) + ); + return xReturn; +} + +void SAL_CALL SoundHandler::impl_initService() +{ +} + + +/*-************************************************************************************************************//** + @short standard ctor + @descr These initialize a new instance of this class with needed informations for work. + + @seealso using at owner + + @param "xFactory", reference to service manager for creation of new services + @return - + + @onerror Show an assertion and do nothing else. + @threadsafe yes +*//*-*************************************************************************************************************/ +SoundHandler::SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) + // Init baseclasses first + : ThreadHelpBase ( ) + , ::cppu::OWeakObject ( ) + // Init member + , m_bError ( false ) + , m_xFactory ( xFactory ) +{ + m_aUpdateTimer.SetTimeoutHdl(LINK(this, SoundHandler, implts_PlayerNotify)); +} + +/*-************************************************************************************************************//** + @short standard dtor + @descr - + + @seealso - + + @param - + @return - + + @onerror - + @threadsafe - +*//*-*************************************************************************************************************/ +SoundHandler::~SoundHandler() +{ + if (m_xListener.is()) + { + css::frame::DispatchResultEvent aEvent; + aEvent.State = css::frame::DispatchResultState::FAILURE; + m_xListener->dispatchFinished(aEvent); + m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >(); + } +} + +/*-************************************************************************************************************//** + @interface ::com::sun::star::frame::XDispatch + + @short try to load audio file + @descr This method try to load given audio file by URL and play it. We use vcl/Sound class to do that. + Playing of sound is asynchron everytime. + + @attention We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started + in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count + will decreased to 0 and will die. The only solution is to use own reference to our implementation. + But we do it for realy started jobs only and release it during call back of vcl. + + @seealso class vcl/Sound + @seealso method implts_PlayerNotify() + + @param "aURL" , URL to dispatch. + @param "lArguments", list of optional arguments. + @return - + + @onerror We do nothing. + @threadsafe yes +*//*-*************************************************************************************************************/ +void SAL_CALL SoundHandler::dispatchWithNotification(const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lDescriptor, + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException) +{ + // SAFE { + const ::vos::OGuard aLock( m_aLock ); + + { + //close streams otherwise on windows we can't reopen the file in the + //media player when we pass the url to directx as it'll already be open + ::comphelper::MediaDescriptor aDescriptor(lDescriptor); + + css::uno::Reference< css::io::XInputStream > xInputStream = + aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_INPUTSTREAM(), + css::uno::Reference< css::io::XInputStream >()); + if (xInputStream.is()) xInputStream->closeInput(); + } + + // If player currently used for other dispatch() requests ... + // cancel it by calling stop()! + m_aUpdateTimer.Stop(); + if (m_xPlayer.is()) + { + if (m_xPlayer->isPlaying()) + m_xPlayer->stop(); + m_xPlayer.clear(); + } + + // Try to initialize player. + m_xListener = xListener; + try + { + m_bError = false; + m_xPlayer.set( avmedia::MediaWindow::createPlayer( aURL.Complete ), css::uno::UNO_QUERY_THROW ); + // OK- we can start async playing ... + // Count this request and initialize self-holder against dieing by uno ref count ... + m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); + m_xPlayer->start(); + m_aUpdateTimer.SetTimeout( 200 ); + m_aUpdateTimer.Start(); + } + catch( css::uno::Exception& e ) + { + m_bError = true; + (void)e; + m_xPlayer.clear(); + } + + // } SAFE +} + +void SAL_CALL SoundHandler::dispatch( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ) +{ + dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >()); +} + +/*-************************************************************************************************************//** + @interface ::com::sun::star::document::XExtendedFilterDetection + + @short try to detect file (given as argument included in "lDescriptor") + @descr We try to detect, if given file could be handled by this class and is a well known one. + If it is - we return right internal type name - otherwise we return nothing! + So call can search for another detect service and ask him too. + + @attention a) We don't need any mutex here ... because we don't use any member! + b) Dont' use internal player instance "m_pPlayer" to detect given sound file! + It's not neccessary to do that ... and we can use temp. variable to do the same. + This way is easy - we don't must synchronize it with currently played sounds! + Another reason to do so ... We are a listener on our internal ma_Player object. + If you would call "IsSoundFile()" on this instance, he would call us back and + we make some uneccssary things ... + + @seealso - + + @param "lDescriptor", description of file to detect + @return Internal type name which match this file ... or nothing if it is unknown. + + @onerror We return nothing. + @threadsafe yes +*//*-*************************************************************************************************************/ +::rtl::OUString SAL_CALL SoundHandler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException ) +{ + // Our default is "nothing". So we can return it, if detection failed or fily type is realy unknown. + ::rtl::OUString sTypeName; + + // Analyze given descriptor to find filename or input stream or ... + ::comphelper::MediaDescriptor aDescriptor(lDescriptor); + ::rtl::OUString sURL = aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString()); + + if ( + (sURL.getLength() ) && + (avmedia::MediaWindow::isMediaURL(sURL)) + ) + { + // If the file type is supported depends on the OS, so... + // I think we can the following ones: + // a) look for given extension of url to map our type decision HARD CODED!!! + // b) return preferred type every time... it's easy :-) + sTypeName = ::rtl::OUString::createFromAscii("wav_Wave_Audio_File"); + aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName; + aDescriptor >> lDescriptor; + } + + // Return our decision. + return sTypeName; +} + +/*-************************************************************************************************************//** + @short call back of sound player + @descr Our player call us back to give us some informations. + We use this informations to callback our might existing listener. + + @seealso method dispatchWithNotification() + + @param - + @return 0 everytime ... it doesnt matter for us. + + @onerror - + @threadsafe yes +*//*-*************************************************************************************************************/ +IMPL_LINK( SoundHandler, implts_PlayerNotify, void*, EMPTYARG ) +{ + // SAFE { + ::vos::OClearableGuard aLock( m_aLock ); + + if (m_xPlayer.is() && m_xPlayer->isPlaying() && m_xPlayer->getMediaTime() < m_xPlayer->getDuration()) + { + m_aUpdateTimer.Start(); + return 0L; + } + m_xPlayer.clear(); + + // We use m_xSelfHold to let us die ... but we must live till real finishing of this method too!!! + // So we SHOULD use another "self-holder" temp. to provide that ... + css::uno::Reference< css::uno::XInterface > xOperationHold = m_xSelfHold; + m_xSelfHold = css::uno::Reference< css::uno::XInterface >(); + + // notify might existing listener + // And forget this listener! + // Because the corresponding dispatch was finished. + if (m_xListener.is()) + { + css::frame::DispatchResultEvent aEvent; + if (!m_bError) + aEvent.State = css::frame::DispatchResultState::SUCCESS; + else + aEvent.State = css::frame::DispatchResultState::FAILURE; + m_xListener->dispatchFinished(aEvent); + m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >(); + } + + // } SAFE + //release aLock before end of method at which point xOperationHold goes out of scope and pThis dies + aLock.clear(); + return 0; +} + +} // namespace framework + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + rtl::OUString sKeyName = DECLARE_ASCII( "/" ); + sKeyName += avmedia::SoundHandler::impl_getStaticImplementationName(); + sKeyName += DECLARE_ASCII( "/UNO/SERVICES" ); + css::uno::Reference< css::registry::XRegistryKey > xNewKey( + static_cast< css::registry::XRegistryKey* >( pRegistryKey )->createKey(sKeyName)); + + if ( xNewKey.is() == sal_True ) + { + css::uno::Sequence< ::rtl::OUString > seqServiceNames = avmedia::SoundHandler::impl_getStaticSupportedServiceNames(); + const ::rtl::OUString* pArray = seqServiceNames.getArray(); + sal_Int32 nLength = seqServiceNames.getLength(); + for ( sal_Int32 nCounter = 0; nCounter < nLength; ++nCounter ) + xNewKey->createKey( pArray[nCounter] ); + } + + bRet = sal_True; + } + catch( css::registry::InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory(const sal_Char* pImplementationName, void* pServiceManager, void* /*pRegistryKey*/ ) +{ + void* pReturn = NULL; + if (pServiceManager != NULL ) + { + /* Define variables which are used in following macros. */ + css::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory; + css::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager; + xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ; + + if ( avmedia::SoundHandler::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) ) + xFactory = avmedia::SoundHandler::impl_createFactory( xServiceManager ); + + if ( xFactory.is() == sal_True ) + { + xFactory->acquire(); + pReturn = xFactory.get(); + } + } + /* Return with result of this operation. */ + return pReturn; +} diff --git a/avmedia/source/framework/soundhandler.hxx b/avmedia/source/framework/soundhandler.hxx new file mode 100644 index 000000000000..55d30536d8ce --- /dev/null +++ b/avmedia/source/framework/soundhandler.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ +#define __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ + +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XNotifyingDispatch.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/media/XPlayer.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/util/URL.hpp> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + +//_________________________________________________________________________________________________________________ +// other includes +//_________________________________________________________________________________________________________________ +#include <cppuhelper/weak.hxx> + +#include <vcl/timer.hxx> +#include <tools/link.hxx> +#include <avmedia/mediawindow.hxx> +#include <vos/mutex.hxx> + +namespace css = ::com::sun::star; + +//_________________________________________________________________________________________________________________ +// namespace +//_________________________________________________________________________________________________________________ + +namespace avmedia{ + +//_________________________________________________________________________________________________________________ +// exported const +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// exported definitions +//_________________________________________________________________________________________________________________ + +struct ThreadHelpBase +{ + public: + mutable ::vos::OMutex m_aLock; +}; + +/*-************************************************************************************************************//** + @short handler to detect and play sounds ("wav" and "au" only!) + @descr Register this implementation as a content handler to detect and/or play wav- and au-sounds. + It doesn't depend from the target platform. But one instance of this class + can play one sound at the same time only. Means every new dispatch request will stop the + might still running one. So we support one operation/one URL/one listener at the same time + only. + + @devstatus ready + @threadsafe yes +*//*-*************************************************************************************************************/ +class SoundHandler : // interfaces + public css::lang::XTypeProvider + , public css::lang::XServiceInfo + , public css::frame::XNotifyingDispatch // => XDispatch + , public css::document::XExtendedFilterDetection + // baseclasses + // Order is neccessary for right initialization! + , private ThreadHelpBase + , public ::cppu::OWeakObject +{ + //------------------------------------------------------------------------------------------------------------- + // public methods + //------------------------------------------------------------------------------------------------------------- + public: + + //--------------------------------------------------------------------------------------------------------- + // constructor / destructor + //--------------------------------------------------------------------------------------------------------- + SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); + virtual ~SoundHandler( ); + + //--------------------------------------------------------------------------------------------------------- + // XInterface, XTypeProvider, XServiceInfo + //--------------------------------------------------------------------------------------------------------- + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException ); + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes () throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw( css::uno::RuntimeException ); + + + /* interface XServiceInfo */ + virtual ::rtl::OUString SAL_CALL getImplementationName ( ) throw( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService ( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames ( ) throw( css::uno::RuntimeException ); + /* Helper for XServiceInfo */ + static css::uno::Sequence< ::rtl::OUString > SAL_CALL impl_getStaticSupportedServiceNames( ); + static ::rtl::OUString SAL_CALL impl_getStaticImplementationName ( ); + /* Helper for registry */ + static css::uno::Reference< css::uno::XInterface > SAL_CALL impl_createInstance ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ); + static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL impl_createFactory ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); + /* Helper for initialization of service by using own reference! */ + virtual void SAL_CALL impl_initService ( ); + + //--------------------------------------------------------------------------------------------------------- + // XNotifyingDispatch + //--------------------------------------------------------------------------------------------------------- + virtual void SAL_CALL dispatchWithNotification(const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments, + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException); + + //--------------------------------------------------------------------------------------------------------- + // XDispatch + //--------------------------------------------------------------------------------------------------------- + virtual void SAL_CALL dispatch ( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ); + // not supported ! + virtual void SAL_CALL addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , + const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; + virtual void SAL_CALL removeStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , + const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; + + //--------------------------------------------------------------------------------------------------------- + // XExtendedFilterDetection + //--------------------------------------------------------------------------------------------------------- + virtual ::rtl::OUString SAL_CALL detect ( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException ); + + //------------------------------------------------------------------------------------------------------------- + // protected methods + //------------------------------------------------------------------------------------------------------------- + protected: + + //------------------------------------------------------------------------------------------------------------- + // private methods + //------------------------------------------------------------------------------------------------------------- + private: + DECL_LINK( implts_PlayerNotify, void* ); + + //------------------------------------------------------------------------------------------------------------- + // variables + // (should be private everyway!) + //------------------------------------------------------------------------------------------------------------- + private: + + bool m_bError; + css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory ; /// global uno service factory to create new services + css::uno::Reference< css::uno::XInterface > m_xSelfHold ; /// we must protect us against dieing during async(!) dispatch() call! + css::uno::Reference< css::media::XPlayer > m_xPlayer ; /// uses avmedia player to play sounds ... + + css::uno::Reference< css::frame::XDispatchResultListener > m_xListener ; + Timer m_aUpdateTimer; + +}; // class SoundHandler + +} // namespace avmedia + +#endif // #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ diff --git a/avmedia/source/framework/soundhandler.xml b/avmedia/source/framework/soundhandler.xml new file mode 100644 index 000000000000..fceeffbde0e3 --- /dev/null +++ b/avmedia/source/framework/soundhandler.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> + +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + + <module-name> avmedia </module-name> + + <component-description> + <author> Andreas Schluens </author> + <name> com.sun.star.comp.framework.SoundHandler </name> + <description> + Implements a handler service to detect and/or play audio files. + supported formats: wav/au + </description> + <loader-name> com.sun.star.loader.SharedLibrary </loader-name> + <language> c++ </language> + <status value="final"/> + <supported-service> com.sun.star.frame.ContentHandler </supported-service> + </component-description> + + <project-build-dependency> cppu </project-build-dependency> + <project-build-dependency> cppuhelper </project-build-dependency> + <project-build-dependency> vos </project-build-dependency> + <project-build-dependency> sal </project-build-dependency> + <project-build-dependency> tools </project-build-dependency> + <project-build-dependency> svtools </project-build-dependency> + <project-build-dependency> toolkit </project-build-dependency> + <project-build-dependency> sv </project-build-dependency> + <project-build-dependency> comphelper </project-build-dependency> + <project-build-dependency> unotools </project-build-dependency> + <project-build-dependency> ucbhelper </project-build-dependency> + <project-build-dependency> svl </project-build-dependency> + <project-build-dependency> sot </project-build-dependency> + + <runtime-module-dependency> cppu2 </runtime-module-dependency> + <runtime-module-dependency> cppuhelper </runtime-module-dependency> + <runtime-module-dependency> vos2$(COM) </runtime-module-dependency> + <runtime-module-dependency> sal2 </runtime-module-dependency> + <runtime-module-dependency> tl </runtime-module-dependency> + <runtime-module-dependency> svt </runtime-module-dependency> + <runtime-module-dependency> svl </runtime-module-dependency> + <runtime-module-dependency> tk </runtime-module-dependency> + <runtime-module-dependency> sv </runtime-module-dependency> + <runtime-module-dependency> comphelp2 </runtime-module-dependency> + <runtime-module-dependency> utl </runtime-module-dependency> + <runtime-module-dependency> ucb </runtime-module-dependency> + <runtime-module-dependency> sot </runtime-module-dependency> + +</module-description> diff --git a/avmedia/source/gstreamer/exports.dxp b/avmedia/source/gstreamer/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/avmedia/source/gstreamer/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/avmedia/source/gstreamer/gstcommon.hxx b/avmedia/source/gstreamer/gstcommon.hxx new file mode 100644 index 000000000000..83bb818aefdc --- /dev/null +++ b/avmedia/source/gstreamer/gstcommon.hxx @@ -0,0 +1,68 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _GSTCOMMON_HXX +#define _GSTCOMMON_HXX + +#include <osl/mutex.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <tools/stream.hxx> +#include <tools/string.hxx> +#include <tools/urlobj.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/media/XManager.hpp> + +#include <memory> + +#define AVMEDIA_GSTREAMER_MANAGER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Manager_GStreamer" +#define AVMEDIA_GSTREAMER_MANAGER_SERVICENAME "com.sun.star.media.Manager_GStreamer" + +#define AVMEDIA_GSTREAMER_PLAYER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Player_GStreamer" +#define AVMEDIA_GSTREAMER_PLAYER_SERVICENAME "com.sun.star.media.Player_GStreamer" + +#define AVMEDIA_GSTREAMER_WINDOW_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Window_GStreamer" +#define AVMEDIA_GSTREAMER_WINDOW_SERVICENAME "com.sun.star.media.Window_GStreamer" + +#define AVMEDIA_GSTREAMER_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_GStreamer" +#define AVMEDIA_GSTREAMER_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_GStreamer" + +#endif // _GSTCOMMOM_HXX diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx new file mode 100644 index 000000000000..bd55e11f8afe --- /dev/null +++ b/avmedia/source/gstreamer/gstframegrabber.cxx @@ -0,0 +1,307 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "gstframegrabber.hxx" +#include "gstplayer.hxx" + +#include <vcl/graph.hxx> +#include <vcl/bmpacc.hxx> + +using namespace ::com::sun::star; + +namespace avmedia { namespace gst { + +const gulong GRAB_TIMEOUT = 10000000; + +// ---------------- +// - FrameGrabber - +// ---------------- + +FrameGrabber::FrameGrabber( GString* pURI ) : + Player( pURI ), + mpFrameMutex( g_mutex_new() ), + mpFrameCond( g_cond_new() ), + mpLastPixbuf( NULL ), + mbIsInGrabMode( false ) +{ +} + +// ------------------------------------------------------------------------------ + +FrameGrabber::~FrameGrabber() +{ + if( g_atomic_pointer_get( &mpPlayer ) ) + { + implQuitThread(); + } + + // thread has ended, so that no more synchronization is necessary + if( mpLastPixbuf ) + { + g_object_unref( mpLastPixbuf ); + mpLastPixbuf = NULL; + } + + g_cond_free( mpFrameCond ); + g_mutex_free( mpFrameMutex ); +} + +// ------------------------------------------------------------------------------ + +FrameGrabber* FrameGrabber::create( const GString* pURI ) +{ + FrameGrabber* pFrameGrabber = NULL; + + if( pURI && pURI->len ) + { + // safely initialize GLib threading framework + try + { + if( !g_thread_supported() ) + { + g_thread_init( NULL ); + } + } + catch( ... ) + {} + + if( g_thread_supported() ) + { + pFrameGrabber = new FrameGrabber( g_string_new( pURI->str ) ); + + // wait until thread signals that it has finished initialization + if( pFrameGrabber->mpThread ) + { + g_mutex_lock( pFrameGrabber->mpMutex ); + + while( !pFrameGrabber->implIsInitialized() ) + { + g_cond_wait( pFrameGrabber->mpCond, pFrameGrabber->mpMutex ); + } + + g_mutex_unlock( pFrameGrabber->mpMutex ); + } + + GstElement* pPixbufSink = gst_element_factory_make( "gdkpixbufsink", NULL ); + + // check if player pipeline and GdkPixbufSink could be initialized + if( !pFrameGrabber->mpPlayer || !pPixbufSink ) + { + delete pFrameGrabber; + pFrameGrabber = NULL; + } + else + { + g_object_set( pFrameGrabber->mpPlayer, "audio-sink", gst_element_factory_make( "fakesink", NULL ), NULL ); + g_object_set( pFrameGrabber->mpPlayer, "video-sink", pPixbufSink, NULL ); + } + } + } + + return( pFrameGrabber ); +} + +// ------------------------------------------------------------------------------ + +gboolean FrameGrabber::busCallback( GstBus* pBus, GstMessage* pMsg ) +{ + bool bDone = false; + + if( pMsg && pMsg->structure ) + { + GstStructure* pStruct = pMsg->structure; + const gchar* pStructName = gst_structure_get_name( pStruct ); + + if( ( ::std::string( pStructName ).find( "pixbuf" ) != ::std::string::npos ) && + gst_structure_has_field ( pStruct, "pixbuf") ) + { + bool bFrameGrabbed = false; + + g_mutex_lock( mpFrameMutex ); + + if( mbIsInGrabMode && ( getMediaTime() >= mfGrabTime ) ) + { + OSL_TRACE( "Grabbing frame at %fs", getMediaTime() ); + + if( mpLastPixbuf ) + { + g_object_unref( mpLastPixbuf ); + mpLastPixbuf = NULL; + } + + mpLastPixbuf = GDK_PIXBUF( g_value_dup_object( gst_structure_get_value( pStruct, "pixbuf" ) ) ); + bFrameGrabbed = true; + } + + g_mutex_unlock( mpFrameMutex ); + + if( bFrameGrabbed ) + { + g_cond_signal( mpFrameCond ); + } + + bDone = true; + } + } + + return( bDone || Player::busCallback( pBus, pMsg ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime ) + throw (uno::RuntimeException) +{ + uno::Reference< graphic::XGraphic > xRet; + + if( implInitPlayer() ) + { + OSL_TRACE( "Trying to grab frame at %fs", fMediaTime ); + + GTimeVal aTimeoutTime; + + g_get_current_time( &aTimeoutTime ); + g_time_val_add( &aTimeoutTime, GRAB_TIMEOUT ); + setMediaTime( fMediaTime ); + start(); + + if( isPlaying() ) + { + g_mutex_lock( mpFrameMutex ); + + mbIsInGrabMode = true; + mfGrabTime = fMediaTime; + g_cond_timed_wait( mpFrameCond, mpFrameMutex, &aTimeoutTime ); + mbIsInGrabMode = false; + + g_mutex_unlock( mpFrameMutex ); + + stop(); + } + + OSL_ENSURE( g_atomic_pointer_get( &mpLastPixbuf ), "FrameGrabber timed out without receiving a Pixbuf" ); + + if( g_atomic_pointer_get( &mpLastPixbuf ) ) + { + OSL_TRACE( "FrameGrabber received a GdkPixbuf"); + + g_mutex_lock( mpFrameMutex ); + + const int nWidth = gdk_pixbuf_get_width( mpLastPixbuf ); + const int nHeight = gdk_pixbuf_get_height( mpLastPixbuf ); + const int nChannels = gdk_pixbuf_get_n_channels( mpLastPixbuf ); + const guchar* pBuffer = gdk_pixbuf_get_pixels( mpLastPixbuf ); + + if( pBuffer && ( nWidth > 0 ) && ( nHeight > 0 ) ) + { + Bitmap aFrame( Size( nWidth, nHeight), 24 ); + bool bInit = false; + + if( ( gdk_pixbuf_get_colorspace( mpLastPixbuf ) == GDK_COLORSPACE_RGB ) && + ( nChannels >= 3 ) && ( nChannels <= 4 ) && + ( gdk_pixbuf_get_bits_per_sample( mpLastPixbuf ) == 8 ) ) + { + BitmapWriteAccess* pAcc = aFrame.AcquireWriteAccess(); + + if( pAcc ) + { + BitmapColor aPixel( 0, 0, 0 ); + const int nRowStride = gdk_pixbuf_get_rowstride( mpLastPixbuf ); + const bool bAlpha = ( nChannels == 4 ); + + for( int nRow = 0; nRow < nHeight; ++nRow ) + { + guchar* pCur = const_cast< guchar* >( pBuffer + nRow * nRowStride ); + + for( int nCol = 0; nCol < nWidth; ++nCol ) + { + aPixel.SetRed( *pCur++ ); + aPixel.SetGreen( *pCur++ ); + aPixel.SetBlue( *pCur++ ); + + // ignore alpha channel + if( bAlpha ) + { + ++pCur; + } + + pAcc->SetPixel( nRow, nCol, aPixel ); + } + } + + aFrame.ReleaseAccess( pAcc ); + bInit = true; + } + } + + if( !bInit ) + { + aFrame.Erase( Color( COL_BLACK ) ); + } + + xRet = Graphic( aFrame ).GetXGraphic(); + } + + g_object_unref( mpLastPixbuf ); + mpLastPixbuf = NULL; + + g_mutex_unlock( mpFrameMutex ); + } + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_FRAMEGRABBER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_GSTREAMER_FRAMEGRABBER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_GSTREAMER_FRAMEGRABBER_SERVICENAME ) ); + + return aRet; +} + +} // namespace win +} // namespace avmedia diff --git a/avmedia/source/gstreamer/gstframegrabber.hxx b/avmedia/source/gstreamer/gstframegrabber.hxx new file mode 100644 index 000000000000..9a7ec1b74102 --- /dev/null +++ b/avmedia/source/gstreamer/gstframegrabber.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _FRAMEGRABBER_HXX +#define _FRAMEGRABBER_HXX + +#include "gstplayer.hxx" +#include <gdk-pixbuf/gdk-pixbuf.h> + +#ifndef _COM_SUN_STAR_MEDIA_XFRAMEGRABBER_HDL_ +#include "com/sun/star/media/XFrameGrabber.hdl" +#endif + +namespace avmedia { namespace gst { + +// ---------------- +// - FrameGrabber - +// ---------------- + +class FrameGrabber : public Player, + public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XFrameGrabber, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + // static create method instead of public Ctor + static FrameGrabber* create( const GString* pUri ); + + ~FrameGrabber(); + + // XFrameGrabber + virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +protected: FrameGrabber( GString* pURI = NULL ); + + virtual gboolean busCallback( GstBus* pBus, + GstMessage* pMsg ); + +private: FrameGrabber( const FrameGrabber& ); + FrameGrabber& operator=( const FrameGrabber& ); + + GMutex* mpFrameMutex; + GCond* mpFrameCond; + GdkPixbuf* mpLastPixbuf; + double mfGrabTime; + bool mbIsInGrabMode; +}; + +} // namespace gst +} // namespace avmedia + +#endif // _FRAMEGRABBER_HXX diff --git a/avmedia/source/gstreamer/gstmanager.cxx b/avmedia/source/gstreamer/gstmanager.cxx new file mode 100644 index 000000000000..61ee4ce22cd8 --- /dev/null +++ b/avmedia/source/gstreamer/gstmanager.cxx @@ -0,0 +1,85 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "gstmanager.hxx" +#include "gstplayer.hxx" + +using namespace ::com::sun::star; + +namespace avmedia +{ +namespace gst +{ +// ---------------- +// - Manager - +// ---------------- + +Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{} + +// ------------------------------------------------------------------------------ + +Manager::~Manager() +{} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const ::rtl::OUString& rURL ) + throw( uno::RuntimeException ) +{ + return( ::avmedia::gst::Player::create( rURL ) ); +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Manager::getImplementationName() + throw( uno::RuntimeException ) +{ + return( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_MANAGER_IMPLEMENTATIONNAME ) ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Manager::supportsService( const ::rtl::OUString& ServiceName ) + throw( uno::RuntimeException ) +{ + return( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( AVMEDIA_GSTREAMER_MANAGER_SERVICENAME ) ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Manager::getSupportedServiceNames() + throw( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aRet( 1 ); + aRet[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_MANAGER_SERVICENAME ) ); + + return( aRet ); +} +} // namespace gst +} // namespace avmedia diff --git a/avmedia/source/gstreamer/gstmanager.hxx b/avmedia/source/gstreamer/gstmanager.hxx new file mode 100644 index 000000000000..9f80e8c1a901 --- /dev/null +++ b/avmedia/source/gstreamer/gstmanager.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _GSTMANAGER_HXX +#define _GSTMANAGER_HXX + +#include "gstcommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XMANAGER_HDL_ +#include "com/sun/star/media/XManager.hdl" +#endif + +// ----------- +// - Manager - +// ----------- + +namespace avmedia +{ +namespace gst +{ +class Manager : public ::cppu::WeakImplHelper2< ::com::sun::star::media::XManager, + ::com::sun::star::lang::XServiceInfo > +{ +public: Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Manager(); + + // XManager + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > SAL_CALL createPlayer( + const ::rtl::OUString& aURL ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException ); + + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; +}; +} // namespace gst +} // namespace avmedia + +#endif // _GSTMANAGER_HXX diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx new file mode 100644 index 000000000000..f082cfc5c513 --- /dev/null +++ b/avmedia/source/gstreamer/gstplayer.cxx @@ -0,0 +1,938 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "gstplayer.hxx" +#include "gstwindow.hxx" +#include "gstframegrabber.hxx" +#include <stdio.h> +#include <unistd.h> +#include <math.h> +#include <string> +#include <gst/gstelement.h> +#include <gst/interfaces/xoverlay.h> + + +// maximum timeout time in nanoseconds +#define GST_MAX_TIMEOUT (2500 * GST_MSECOND) + +using namespace ::com::sun::star; + +namespace avmedia +{ +namespace gst +{ +const double NANO_TIME_FACTOR = 1000000000.0; + +const long VIDEO_DEFAULT_WIDTH = 256; +const long VIDEO_DEFAULT_HEIGHT = 192; + +// ---------------- +// - GstBusSource - +// ---------------- + +struct GstBusSource : public GSource +{ + GstBus* mpBus; + + GstBusSource() : + mpBus( NULL ) + {} + + ~GstBusSource() + {} +}; + +// --------------- +// - Player - +// --------------- +Player::Player( GString* pURI ) : + mpMutex( g_mutex_new() ), + mpCond( g_cond_new() ), + mpThread( NULL ), + mpContext( NULL ), + mpLoop( NULL ), + mpPlayer( NULL ), + mpURI( pURI ), + mpPlayerWindow( NULL ), + mnIsVideoSource( 0 ), + mnVideoWidth( 0 ), + mnVideoHeight( 0 ), + mnInitialized( 0 ), + mnVolumeDB( 0 ), + mnLooping( 0 ), + mnQuit( 0 ), + mnVideoWindowSet( 0 ), + mnInitFail( 0 ) +{ + // initialize GStreamer framework only once + static bool bGstInitialized = false; + + if( !bGstInitialized ) + { + gst_init( NULL, NULL ); + bGstInitialized = true; + } + + if( pURI ) + { + OSL_TRACE( ">>> --------------------------------" ); + OSL_TRACE( ">>> Creating Player object with URL: %s", pURI->str ); + + mpThread = g_thread_create( Player::implThreadFunc, this, true, NULL ); + } +} + +// ------------------------------------------------------------------------------ + +Player::~Player() +{ + if( g_atomic_pointer_get( &mpPlayer ) ) + { + implQuitThread(); + } + + // cleanup + g_cond_free( mpCond ); + g_mutex_free( mpMutex ); + g_string_free( mpURI, false ); +} + +// ------------------------------------------------------------------------------ +Player* Player::create( const ::rtl::OUString& rURL ) +{ + Player* pPlayer = NULL; + + if( rURL.getLength() ) + { + // safely initialize GLib threading framework + try + { + if( !g_thread_supported() ) + { + g_thread_init( NULL ); + } + } + catch( ... ) + {} + + if( g_thread_supported() ) + { + const INetURLObject aURL( rURL ); + + if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) + { + GString* pURI = g_string_new( ::rtl::OUStringToOString( + aURL.GetMainURL( INetURLObject::NO_DECODE ), + RTL_TEXTENCODING_UTF8 ).getStr() ); + + if( pURI->len ) + { + pPlayer = new Player( pURI ); + + // wait until thread signals that it has finished initialization + if( pPlayer->mpThread ) + { + g_mutex_lock( pPlayer->mpMutex ); + + while( !pPlayer->implIsInitialized() ) + { + g_cond_wait( pPlayer->mpCond, pPlayer->mpMutex ); + } + + g_mutex_unlock( pPlayer->mpMutex ); + } + + // check if player pipeline could be initialized + if( !pPlayer->mpPlayer ) + { + delete pPlayer; + pPlayer = NULL; + } + } + else + { + g_string_free( pURI, false ); + } + } + } + } + + return( pPlayer ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::start() + throw( uno::RuntimeException ) +{ + if( implInitPlayer() && !isPlaying() ) + { + gst_element_set_state( mpPlayer, GST_STATE_PLAYING ); + } +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::stop() + throw( uno::RuntimeException ) +{ + if( implInitPlayer() && isPlaying() ) + { + gst_element_set_state( mpPlayer, GST_STATE_PAUSED ); + } +} + +// ------------------------------------------------------------------------------ +sal_Bool SAL_CALL Player::isPlaying() + throw( uno::RuntimeException ) +{ + GstState aState = GST_STATE_NULL; + + if( mpPlayer ) + { + gst_element_get_state( mpPlayer, &aState, NULL, GST_MAX_TIMEOUT ); + } + + return( GST_STATE_PLAYING == aState ); +} + +// ------------------------------------------------------------------------------ +double SAL_CALL Player::getDuration() + throw( uno::RuntimeException ) +{ + gint64 nDuration = 0; + + if( implInitPlayer() ) + { + GstFormat aFormat = GST_FORMAT_TIME; + + if( !gst_element_query_duration( mpPlayer, &aFormat, &nDuration ) || + ( GST_FORMAT_TIME != aFormat ) || + ( nDuration < 0 ) ) + { + nDuration = 0; + } + } + + return( static_cast< double >( nDuration ) / NANO_TIME_FACTOR ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setMediaTime( double fTime ) + throw( uno::RuntimeException ) +{ + if( implInitPlayer() ) + { + fTime = ::std::min( ::std::max( fTime, 0.0 ), getDuration() ); + + gst_element_seek_simple( mpPlayer, GST_FORMAT_TIME, + (GstSeekFlags) ( GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT ), + static_cast< gint64 >( fTime * NANO_TIME_FACTOR ) ); + } +} + +// ------------------------------------------------------------------------------ +double SAL_CALL Player::getMediaTime() + throw( uno::RuntimeException ) +{ + double fRet = 0.0; + + if( implInitPlayer() ) + { + GstFormat aFormat = GST_FORMAT_TIME; + gint64 nCurTime = 0; + + if( gst_element_query_position( mpPlayer, &aFormat, &nCurTime ) && + ( GST_FORMAT_TIME == aFormat ) && + ( nCurTime >= 0 ) ) + { + fRet = static_cast< double >( nCurTime ) / NANO_TIME_FACTOR; + } + } + + return( fRet ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setStopTime( double /* fTime */ ) + throw( uno::RuntimeException ) +{ + OSL_TRACE( "GStreamer method avmedia::gst::Player::setStopTime needs to be implemented" ); + + /* Currently no need for implementation since higher levels of code don't use this method at all + !!! TODO: needs to be implemented if this functionality is needed at a later point of time + if( implInitPlayer() ) + { + } + + */ +} + +// ------------------------------------------------------------------------------ +double SAL_CALL Player::getStopTime() + throw( uno::RuntimeException ) +{ + /* + Currently no need for implementation since higher levels of code don't set a stop time ATM + !!! TODO: needs to be fully implemented if this functionality is needed at a later point of time + */ + + return( getDuration() ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setRate( double /* fRate */ ) + throw( uno::RuntimeException ) +{ + OSL_TRACE( "GStreamer method avmedia::gst::Player::setRate needs to be implemented" ); + + /* Currently no need for implementation since higher levels of code don't use this method at all + !!! TODO: needs to be implemented if this functionality is needed at a later point of time + */ +} + +// ------------------------------------------------------------------------------ +double SAL_CALL Player::getRate() + throw( uno::RuntimeException ) +{ + /* + Currently no need for implementation since higher levels of code don't set a different rate than 1 ATM + !!! TODO: needs to be fully implemented if this functionality is needed at a later point of time + */ + + return( 1.0 ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) + throw( uno::RuntimeException ) +{ + if( bSet && !isPlaybackLoop() ) + g_atomic_int_inc( &mnLooping ); + else if( !bSet && isPlaybackLoop() ) + g_atomic_int_dec_and_test( &mnLooping ); +} + +// ------------------------------------------------------------------------------ +sal_Bool SAL_CALL Player::isPlaybackLoop() + throw( uno::RuntimeException ) +{ + return( g_atomic_int_get( &mnLooping ) > 0 ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setMute( sal_Bool bSet ) + throw( uno::RuntimeException ) +{ + if( implInitPlayer() && ( bSet != isMute() ) ) + { + if( bSet ) + { + g_object_set( mpPlayer, "volume", 0.0, NULL ); + } + else + { + setVolumeDB( mnVolumeDB ); + } + } +} + +// ------------------------------------------------------------------------------ +sal_Bool SAL_CALL Player::isMute() + throw( uno::RuntimeException ) +{ + gdouble fGstVolume = 1.0; + + if( implInitPlayer() ) + { + g_object_get( mpPlayer, "volume", &fGstVolume, NULL ); + } + + return( 0.0 == fGstVolume ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) + throw( uno::RuntimeException ) +{ + if( implInitPlayer() ) + { + g_mutex_lock( mpMutex ); + mnVolumeDB = nVolumeDB; + g_mutex_unlock( mpMutex ); + + // maximum gain for gstreamer volume is 10 + double fGstVolume = pow( 10.0, static_cast< double >( ::std::min( + nVolumeDB, static_cast< sal_Int16 >( 20 ) ) / 20.0 ) ); + + g_object_set( mpPlayer, "volume", fGstVolume, NULL ); + } +} + +// ------------------------------------------------------------------------------ +sal_Int16 SAL_CALL Player::getVolumeDB() + throw( uno::RuntimeException ) +{ + return( static_cast< sal_Int16 >( g_atomic_int_get( &mnVolumeDB ) ) ); +} + +// ------------------------------------------------------------------------------ +awt::Size SAL_CALL Player::getPreferredPlayerWindowSize() + throw( uno::RuntimeException ) +{ + awt::Size aSize( 0, 0 ); + + if( implInitPlayer() && ( g_atomic_int_get( &mnIsVideoSource ) > 0 ) ) + { + aSize.Width = g_atomic_int_get( &mnVideoWidth ); + aSize.Height = g_atomic_int_get( &mnVideoHeight ); + + // if we have a video source, but no size is given => use default size + if( ( aSize.Width <= 0 ) || ( aSize.Height <= 0 ) ) + { + aSize.Width = VIDEO_DEFAULT_WIDTH; + aSize.Height = VIDEO_DEFAULT_HEIGHT; + } + } + + OSL_TRACE( ">>> Requested preferred video size is: %d x %d pixel", aSize.Width, aSize.Height ); + + return( aSize ); +} + +// ------------------------------------------------------------------------------ +uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( + const uno::Sequence< uno::Any >& rArguments ) + throw( uno::RuntimeException ) +{ + uno::Reference< ::media::XPlayerWindow > xRet; + awt::Size aSize( getPreferredPlayerWindowSize() ); + + OSL_ENSURE( !g_atomic_pointer_get( &mpPlayerWindow ), "::avmedia::gst::Player already has a player window" ); + + if( ( aSize.Width > 0 ) && ( aSize.Height > 0 ) ) + { + Window* pPlayerWindow = new Window( *this ); + + xRet = pPlayerWindow; + + if( !pPlayerWindow->create( rArguments ) ) + { + xRet.clear(); + } + else + { + // try to use gconf user configurable video sink first + GstElement* pVideoSink = gst_element_factory_make( "gconfvideosink", NULL ); + + if( ( NULL != pVideoSink ) || + ( NULL != ( pVideoSink = gst_element_factory_make( "autovideosink", NULL ) ) ) || + ( NULL != ( pVideoSink = gst_element_factory_make( "xvimagesink", NULL ) ) ) || + ( NULL != ( pVideoSink = gst_element_factory_make( "ximagesink", NULL ) ) ) ) + { + GstState aOldState = GST_STATE_NULL; + + mpPlayerWindow = pPlayerWindow; + gst_element_get_state( mpPlayer, &aOldState, NULL, GST_MAX_TIMEOUT ); + gst_element_set_state( mpPlayer, GST_STATE_READY ); + g_object_set( mpPlayer, "video-sink", pVideoSink, NULL ); + gst_element_set_state( mpPlayer, aOldState ); + } + } + } + + return( xRet ); +} + +// ------------------------------------------------------------------------------ +uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber() + throw( ::com::sun::star::uno::RuntimeException ) +{ + FrameGrabber* pFrameGrabber = NULL; + const awt::Size aPrefSize( getPreferredPlayerWindowSize() ); + + if( ( aPrefSize.Width > 0 ) && ( aPrefSize.Height > 0 ) ) + { + pFrameGrabber = FrameGrabber::create( mpURI ); + } + + return( pFrameGrabber ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::dispose() + throw( uno::RuntimeException ) +{ + if( mpPlayer ) + { + stop(); + implQuitThread(); + } + + OSL_ASSERT( NULL == mpPlayer ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::addEventListener( const uno::Reference< lang::XEventListener >& /*rxListener*/ ) + throw( uno::RuntimeException ) +{} + +// ------------------------------------------------------------------------------ +void SAL_CALL Player::removeEventListener( const uno::Reference< lang::XEventListener >& /*rxListener*/ ) + throw( uno::RuntimeException ) +{} + +// ------------------------------------------------------------------------------ +::rtl::OUString SAL_CALL Player::getImplementationName() + throw( uno::RuntimeException ) +{ + return( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_PLAYER_IMPLEMENTATIONNAME ) ) ); +} + +// ------------------------------------------------------------------------------ +sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName ) + throw( uno::RuntimeException ) +{ + return( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( AVMEDIA_GSTREAMER_PLAYER_SERVICENAME ) ) ); +} + +// ------------------------------------------------------------------------------ +uno::Sequence< ::rtl::OUString > SAL_CALL Player::getSupportedServiceNames() + throw( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aRet( 1 ); + aRet[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_PLAYER_SERVICENAME ) ); + + return( aRet ); +} + +// ------------------------------------------------------------------------------ +void Player::implQuitThread() +{ + if( mpThread ) + { + // set quit flag to 1 so that the main loop will be quit in idle + // handler the next time it is called from the thread's main loop + g_atomic_int_inc( &mnQuit ); + + // wait until loop and as such the thread has quit + g_thread_join( mpThread ); + mpThread = NULL; + } +} + +// ------------------------------------------------------------------------------ +bool Player::implInitPlayer() +{ + bool bRet = false; + + if( mpPlayer && (mnInitFail < 3) ) + { + GstState aState = GST_STATE_NULL; + + if( gst_element_get_state( mpPlayer, &aState, NULL, GST_MAX_TIMEOUT ) == GST_STATE_CHANGE_SUCCESS ) + { + bRet = ( GST_STATE_PAUSED == aState ) || ( GST_STATE_PLAYING == aState ); + + if( !bRet ) + { + gst_element_set_state( mpPlayer, GST_STATE_PAUSED ); + bRet = ( gst_element_get_state( mpPlayer, &aState, NULL, + GST_MAX_TIMEOUT ) == GST_STATE_CHANGE_SUCCESS ) && + ( GST_STATE_PAUSED == aState ); + } + } + + if( ! bRet ) + mnInitFail++; + } + + return( bRet ); +} + +// ------------------------------------------------------------------------------ +gboolean Player::implBusPrepare( GSource* pSource, + gint* pTimeout ) +{ + if( pTimeout ) + { + *pTimeout = 0; + } + + return( implBusCheck( pSource ) ); +} + +// ------------------------------------------------------------------------------ +gboolean Player::implBusCheck( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + return( pBusSource && + GST_IS_BUS( pBusSource->mpBus ) && + gst_bus_have_pending( GST_BUS_CAST( pBusSource->mpBus ) ) ); +} + +// ------------------------------------------------------------------------------ +gboolean Player::implBusDispatch( GSource* pSource, + GSourceFunc /*aCallback*/, + gpointer pData ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + gboolean bRet = false; + + if( pData && pBusSource && GST_IS_BUS( pBusSource->mpBus ) ) + { + GstMessage* pMsg = gst_bus_pop( pBusSource->mpBus ); + + if( pMsg ) + { + bRet = static_cast< Player* >( pData )->busCallback( pBusSource->mpBus, pMsg ); + gst_message_unref( pMsg ); + } + } + + return( bRet ); +} + +// ------------------------------------------------------------------------------ +void Player::implBusFinalize( GSource* pSource ) +{ + GstBusSource* pBusSource = static_cast< GstBusSource* >( pSource ); + + if( pBusSource && pBusSource->mpBus ) + { + gst_object_unref( pBusSource->mpBus ); + pBusSource->mpBus = NULL; + } +} + +// ------------------------------------------------------------------------------ +gboolean Player::busCallback( GstBus* /*pBus*/, + GstMessage* pMsg ) +{ + if( pMsg && mpLoop ) + { + switch( GST_MESSAGE_TYPE( pMsg ) ) + { + case ( GST_MESSAGE_EOS ): + { + if( g_atomic_int_get( &mnLooping ) > 0 ) + { + setMediaTime( 0.0 ); + start(); + } + else + { + stop(); + } + } + break; + + case ( GST_MESSAGE_ERROR ): + { + gchar* pDebug; + GError* pErr; + + gst_message_parse_error( pMsg, &pErr, &pDebug ); + fprintf( stderr, "Error: %s\n", pErr->message ); + + g_free( pDebug ); + g_error_free( pErr ); + } + break; + + default: + { + break; + } + } + } + + return( true ); +} + +// ------------------------------------------------------------------------------ +gboolean Player::implIdleFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->idle() : true ); +} + +// ------------------------------------------------------------------------------ +gpointer Player::implThreadFunc( gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->run() : NULL ); +} + +// ------------------------------------------------------------------------------ +GstBusSyncReply Player::implHandleCreateWindowFunc( GstBus* pBus, + GstMessage* pMsg, + gpointer pData ) +{ + return( pData ? static_cast< Player* >( pData )->handleCreateWindow( pBus, pMsg ) : GST_BUS_PASS ); +} + +// ------------------------------------------------------------------------------ +void Player::implHandleNewElementFunc( GstBin* /* pBin */, + GstElement* pElement, + gpointer pData ) +{ + if( pElement ) + { +#ifdef DEBUG + gchar* pElementName = gst_element_get_name( pElement ); + + if( pElementName ) + { + OSL_TRACE( ">>> Bin has element: %s", pElementName ); + g_free( pElementName ); + } +#endif + + if( GST_IS_BIN( pElement ) ) + { + // set this handler in case we have a GstBin element + g_signal_connect( GST_BIN( pElement ), "element-added", + G_CALLBACK( Player::implHandleNewElementFunc ), pData ); + } + + // watch for all pads that are going to be added to this element; + g_signal_connect( pElement, "pad-added", + G_CALLBACK( Player::implHandleNewPadFunc ), pData ); + } +} + +// ------------------------------------------------------------------------------ +void Player::implHandleNewPadFunc( GstElement* pElement, + GstPad* pPad, + gpointer pData ) +{ + Player* pPlayer = static_cast< Player* >( pData ); + + if( pPlayer && pElement && pPad ) + { +#ifdef DEBUG + gchar* pElementName = gst_element_get_name( pElement ); + gchar* pPadName = gst_pad_get_name( pPad ); + + OSL_TRACE( ">>> Element %s has pad: %s", pElementName, pPadName ); + + g_free( pPadName ); + g_free( pElementName ); +#endif + + GstCaps* pCaps = gst_pad_get_caps( pPad ); + + // we are interested only in getting video properties + // width and height or if we have a video source at all + if( pCaps ) + { + for( gint i = 0, nSize = gst_caps_get_size( pCaps ); i < nSize; ++i ) + { + const GstStructure* pStruct = gst_caps_get_structure( pCaps, i ); + + if( pStruct ) + { + const gchar* pStructName = gst_structure_get_name( pStruct ); + +#ifdef DEBUG + OSL_TRACE( "\t>>> Pad has structure: %s", pStructName ); + + for( gint n = 0, nFields = gst_structure_n_fields( pStruct ); n < nFields; ++n ) + { + OSL_TRACE( "\t\t>>> Structure has field: %s", gst_structure_nth_field_name( pStruct, n ) ); + } +#endif + + // just look for structures having 'video' in their names + if( ::std::string( pStructName ).find( "video" ) != ::std::string::npos ) + { + g_atomic_int_inc( &pPlayer->mnIsVideoSource ); + + for( gint n = 0, nFields = gst_structure_n_fields( pStruct ); n < nFields; ++n ) + { + const gchar* pFieldName = gst_structure_nth_field_name( pStruct, n ); + gint nValue; + + if( ( ::std::string( pFieldName ).find( "width" ) != ::std::string::npos ) && + gst_structure_get_int( pStruct, pFieldName, &nValue ) ) + { + const gint nDiff = nValue - g_atomic_int_get( &pPlayer->mnVideoWidth ); + g_atomic_int_add( &pPlayer->mnVideoWidth, ::std::max( nDiff, 0 ) ); + } + else if( ( ::std::string( pFieldName ).find( "height" ) != ::std::string::npos ) && + gst_structure_get_int( pStruct, pFieldName, &nValue ) ) + { + const gint nDiff = nValue - g_atomic_int_get( &pPlayer->mnVideoHeight ); + g_atomic_int_add( &pPlayer->mnVideoHeight, ::std::max( nDiff, 0 ) ); + } + } + } + } + } + + gst_caps_unref( pCaps ); + } + } +} + +// ------------------------------------------------------------------------------ +gboolean Player::idle() +{ + // test if main loop should quit and set flag mnQuit to 1 + bool bQuit = g_atomic_int_compare_and_exchange( &mnQuit, 1, 1 ); + + if( bQuit ) + { + // set mnQuit back to 0 to avoid mutiple g_main_loop_quit calls + // in case Player::idle() is called again later; + // the flag should have been set only once within Ctor called from + // the application thread + g_atomic_int_dec_and_test( &mnQuit ); + g_main_loop_quit( mpLoop ); + } + + // don't eat up all cpu time + usleep( 1000 ); + + return( true ); +} + +// ------------------------------------------------------------------------------ +gpointer Player::run() +{ + static GSourceFuncs aSourceFuncs = + { + Player::implBusPrepare, + Player::implBusCheck, + Player::implBusDispatch, + Player::implBusFinalize, + NULL, + NULL + }; + + if( NULL != ( mpPlayer = gst_element_factory_make( "playbin", NULL ) ) ) + { + // initialization + // no mutex necessary since initialization + // is synchronous until loop is started + mpContext = g_main_context_new(); + mpLoop = g_main_loop_new( mpContext, false ); + + // add idle callback + GSource* pIdleSource = g_idle_source_new(); + g_source_set_callback( pIdleSource, Player::implIdleFunc, this, NULL ); + g_source_attach( pIdleSource, mpContext ); + + // add bus callback + GSource* pBusSource = g_source_new( &aSourceFuncs, sizeof( GstBusSource ) ); + static_cast< GstBusSource* >( pBusSource )->mpBus = gst_pipeline_get_bus( GST_PIPELINE( mpPlayer ) ); + g_source_set_callback( pBusSource, NULL, this, NULL ); + g_source_attach( pBusSource, mpContext ); + + // add bus sync handler to intercept video window creation for setting our own window + gst_bus_set_sync_handler( static_cast< GstBusSource* >( pBusSource )->mpBus, + Player::implHandleCreateWindowFunc, this ); + + // watch for all elements (and pads) that will be added to the playbin, + // in order to retrieve properties like video width and height + g_signal_connect( GST_BIN( mpPlayer ), "element-added", + G_CALLBACK( Player::implHandleNewElementFunc ), this ); + + // set source URI for player + g_object_set( mpPlayer, "uri", mpURI->str, NULL ); + + // set video fake sink first, since we only create a player without window here + // and don't want to have the gstreamer default window appearing + g_object_set( mpPlayer, "video-sink", gst_element_factory_make( "fakesink", NULL ), NULL ); + + // set state of player to READY or destroy object in case of FAILURE + if( gst_element_set_state( mpPlayer, GST_STATE_READY ) == GST_STATE_CHANGE_FAILURE ) + { + gst_object_unref( mpPlayer ); + mpPlayer = NULL; + } + + g_atomic_int_add( &mnInitialized, 1 ); + g_cond_signal( mpCond ); + + // run the main loop + g_main_loop_run( mpLoop ); + + // clenanup + // no mutex necessary since other thread joined us (this thread) + // after setting the quit flag + if( mpPlayer ) + { + gst_element_set_state( mpPlayer, GST_STATE_NULL ); + gst_object_unref( mpPlayer ); + mpPlayer = NULL; + } + + g_main_loop_unref( mpLoop ); + mpLoop = NULL; + + g_source_destroy( pBusSource ); + g_source_unref( pBusSource ); + + g_source_destroy( pIdleSource ); + g_source_unref( pIdleSource ); + + g_main_context_unref( mpContext ); + mpContext = NULL; + } + else + { + g_atomic_int_add( &mnInitialized, 1 ); + g_cond_signal( mpCond ); + } + + return( NULL ); +} + +// ------------------------------------------------------------------------------ +GstBusSyncReply Player::handleCreateWindow( GstBus* /* pBus */, + GstMessage* pMsg ) +{ + GstBusSyncReply eRet = GST_BUS_PASS; + + if( pMsg && + ( GST_MESSAGE_TYPE( pMsg ) == GST_MESSAGE_ELEMENT ) && + gst_structure_has_name( pMsg->structure, "prepare-xwindow-id" ) && + g_atomic_pointer_get( &mpPlayerWindow ) ) + { + OSL_TRACE( ">>> Got Request to create XOverlay" ); + + gst_x_overlay_set_xwindow_id( GST_X_OVERLAY( GST_MESSAGE_SRC( pMsg ) ), + static_cast< Window* >( g_atomic_pointer_get( + &mpPlayerWindow ) )->getXWindowHandle() ); + + gst_message_unref( pMsg ); + eRet = GST_BUS_DROP; + } + + return( eRet ); +} +} // namespace gst +} // namespace avmedia diff --git a/avmedia/source/gstreamer/gstplayer.hxx b/avmedia/source/gstreamer/gstplayer.hxx new file mode 100644 index 000000000000..d751e381258d --- /dev/null +++ b/avmedia/source/gstreamer/gstplayer.hxx @@ -0,0 +1,236 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _GSTPLAYER_HXX +#define _GSTPLAYER_HXX + +#include "gstcommon.hxx" +#include <glib.h> +#include <glib/gatomic.h> + +// necessary for mixed environments with GStreamer-0.10 and GLib versions < 2.8 +#ifndef G_GNUC_NULL_TERMINATED +#if __GNUC__ >= 4 +#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__)) +#else +#define G_GNUC_NULL_TERMINATED +#endif +#endif + +struct _GOptionGroup; +typedef struct _GOptionGroup GOptionGroup; + +#include <gst/gst.h> +#include "com/sun/star/media/XPlayer.hdl" + +namespace avmedia +{ +namespace gst +{ +class Window; + +// --------------- +// - Player_Impl - +// --------------- + +class Player : public ::cppu::WeakImplHelper3< ::com::sun::star::media::XPlayer, + ::com::sun::star::lang::XComponent, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + // static create method instead of public Ctor + static Player* create( const ::rtl::OUString& rURL ); + + ~Player(); + + // XPlayer + virtual void SAL_CALL start() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL stop() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isPlaying() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL getDuration() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setMediaTime( double fTime ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL getMediaTime() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setStopTime( double fTime ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL getStopTime() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setRate( double fRate ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL getRate() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isPlaybackLoop() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setMute( sal_Bool bSet ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL isMute() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL getVolumeDB() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber() + throw( ::com::sun::star::uno::RuntimeException ); + + // XComponent + virtual void SAL_CALL dispose() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException ); + + +protected: + + Player( GString* pURI = NULL ); + + virtual gboolean busCallback( GstBus* pBus, + GstMessage* pMsg ); + + virtual gboolean idle(); + + virtual gpointer run(); + + virtual GstBusSyncReply handleCreateWindow( GstBus* pBus, + GstMessage* pMsg ); + + void implQuitThread(); + + bool implInitPlayer(); + + bool implIsInitialized() const + { + return( g_atomic_int_get( &mnInitialized ) > 0 ); + } + + +private: + + Player( const Player& ); + + Player& operator=( const Player& ); + + static gboolean implBusPrepare( GSource* pSource, + gint* pTimeout ); + + static gboolean implBusCheck( GSource* pSource ); + + static gboolean implBusDispatch( GSource* pSource, + GSourceFunc aCallback, + gpointer pData ); + + static void implBusFinalize( GSource* pSource ); + + static gboolean implIdleFunc( gpointer pData ); + + static gpointer implThreadFunc( gpointer pData ); + + static GstBusSyncReply implHandleCreateWindowFunc( GstBus* pBus, + GstMessage* pMsg, + gpointer pDData ); + + static void implHandleNewElementFunc( GstBin* pBin, + GstElement* pElement, + gpointer pData ); + + static void implHandleNewPadFunc( GstElement* pElem, + GstPad* pPad, + gpointer pData ); + +protected: + + GMutex* mpMutex; + GCond* mpCond; + GThread* mpThread; + GMainContext* mpContext; + GMainLoop* mpLoop; + GstElement* mpPlayer; + GString* mpURI; + +private: + + ::avmedia::gst::Window* mpPlayerWindow; + gint mnIsVideoSource; + gint mnVideoWidth; + gint mnVideoHeight; + gint mnInitialized; + gint mnVolumeDB; + gint mnLooping; + gint mnQuit; + gint mnVideoWindowSet; + gint mnInitFail; +}; +} // namespace gst +} // namespace avmedia + +#endif // _GSTPLAYER_HXX diff --git a/avmedia/source/gstreamer/gstuno.cxx b/avmedia/source/gstreamer/gstuno.cxx new file mode 100644 index 000000000000..adcda63fcd9c --- /dev/null +++ b/avmedia/source/gstreamer/gstuno.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "gstcommon.hxx" +#include "gstmanager.hxx" + +using namespace ::com::sun::star; + +// ------------------- +// - factory methods - +// ------------------- + +static uno::Reference< uno::XInterface > SAL_CALL create_MediaPlayer( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) +{ + return uno::Reference< uno::XInterface >( *new ::avmedia::gst::Manager( rxFact ) ); +} + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* /* pServiceManager */, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + uno::Reference< registry::XRegistryKey > xNewKey1( + static_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( + ::rtl::OUString::createFromAscii( + "/" AVMEDIA_GSTREAMER_MANAGER_IMPLEMENTATIONNAME "/UNO/SERVICES/" + AVMEDIA_GSTREAMER_MANAGER_SERVICENAME ) ) ); + + bRet = sal_True; + } + catch( registry::InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ ) +{ + uno::Reference< lang::XSingleServiceFactory > xFactory; + void* pRet = 0; + + if( rtl_str_compare( pImplName, AVMEDIA_GSTREAMER_MANAGER_IMPLEMENTATIONNAME ) == 0 ) + { + const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( AVMEDIA_GSTREAMER_MANAGER_SERVICENAME ) ); + + xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory( + reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), + ::rtl::OUString::createFromAscii( AVMEDIA_GSTREAMER_MANAGER_IMPLEMENTATIONNAME ), + create_MediaPlayer, uno::Sequence< ::rtl::OUString >( &aServiceName, 1 ) ) ); + } + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} diff --git a/avmedia/source/gstreamer/gstwindow.cxx b/avmedia/source/gstreamer/gstwindow.cxx new file mode 100644 index 000000000000..3b24e9974a3f --- /dev/null +++ b/avmedia/source/gstreamer/gstwindow.cxx @@ -0,0 +1,668 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/prex.h> +#include <tools/postx.h> + +#include <com/sun/star/awt/SystemPointer.hdl> + +#include "gstwindow.hxx" +#include "gstplayer.hxx" +#include <vcl/syschild.hxx> +#include <vcl/sysdata.hxx> + +using namespace ::com::sun::star; + +namespace avmedia +{ +namespace gst +{ +// --------------------- +// - PlayerChildWindow - +// --------------------- + +class PlayerChildWindow : public SystemChildWindow +{ +public: + + PlayerChildWindow( Window* pParent ); + ~PlayerChildWindow(); + +protected: + + virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void MouseButtonUp( const MouseEvent& rMEvt ); + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void KeyUp( const KeyEvent& rKEvt ); + virtual void Command( const CommandEvent& rCEvt ); +}; + +// --------------------------------------------------------------------- + +PlayerChildWindow::PlayerChildWindow( Window* pParent ) : + SystemChildWindow( pParent, WB_CLIPCHILDREN ) +{ +} + +// --------------------------------------------------------------------- + +PlayerChildWindow::~PlayerChildWindow() +{ +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::MouseMove( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseMove( rMEvt ); + GetParent()->MouseMove( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::MouseButtonDown( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseButtonDown( rMEvt ); + GetParent()->MouseButtonDown( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::MouseButtonUp( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseButtonUp( rMEvt ); + GetParent()->MouseButtonUp( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::KeyInput( const KeyEvent& rKEvt ) +{ + SystemChildWindow::KeyInput( rKEvt ); + GetParent()->KeyInput( rKEvt ); +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::KeyUp( const KeyEvent& rKEvt ) +{ + SystemChildWindow::KeyUp( rKEvt ); + GetParent()->KeyUp( rKEvt ); +} + +// --------------------------------------------------------------------- + +void PlayerChildWindow::Command( const CommandEvent& rCEvt ) +{ + const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ), + rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetData() ); + + SystemChildWindow::Command( rCEvt ); + GetParent()->Command( aTransformedEvent ); +} + +// --------------- +// - Window - +// --------------- +Window::Window( ::avmedia::gst::Player& rPlayer ) : + maListeners( maMutex ), + maWindowRect( 0, 0, 0, 0 ), + mrPlayer( rPlayer ), + mpPlayerWindow( NULL ), + meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ), + mnPointerType( awt::SystemPointer::ARROW ) +{} + +// ------------------------------------------------------------------------------ + +Window::~Window() +{ + dispose(); +} + +// ------------------------------------------------------------------------------ + +void Window::implLayoutVideoWindow() +{ + if( mpPlayerWindow && ( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel ) ) + { + awt::Size aPrefSize( mrPlayer.getPreferredPlayerWindowSize() ); + awt::Rectangle aRect = getPosSize(); + int nW = aRect.Width, nH = aRect.Height; + int nVideoW = nW, nVideoH = nH; + int nX = 0, nY = 0, nWidth = 0, nHeight = 0; + bool bDone = false, bZoom = false; + + if( media::ZoomLevel_ORIGINAL == meZoomLevel ) + { + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_4 == meZoomLevel ) + { + aPrefSize.Width >>= 2; + aPrefSize.Height >>= 2; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_2 == meZoomLevel ) + { + aPrefSize.Width >>= 1; + aPrefSize.Height >>= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_2_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 1; + aPrefSize.Height <<= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_4_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 2; + aPrefSize.Height <<= 2; + bZoom = true; + } + else if( media::ZoomLevel_FIT_TO_WINDOW == meZoomLevel ) + { + nWidth = nVideoW; + nHeight = nVideoH; + bDone = true; + } + + if( bZoom ) + { + if( ( aPrefSize.Width <= nVideoW ) && ( aPrefSize.Height <= nVideoH ) ) + { + nX = ( nVideoW - aPrefSize.Width ) >> 1; + nY = ( nVideoH - aPrefSize.Height ) >> 1; + nWidth = aPrefSize.Width; + nHeight = aPrefSize.Height; + bDone = true; + } + } + + if( !bDone ) + { + if( ( aPrefSize.Width > 0 ) && ( aPrefSize.Height > 0 ) && ( nVideoW > 0 ) && ( nVideoH > 0 ) ) + { + double fPrefWH = (double) aPrefSize.Width / aPrefSize.Height; + + if( fPrefWH < ( (double) nVideoW / nVideoH ) ) + { + nVideoW = (int) ( nVideoH * fPrefWH ); + } + else + { + nVideoH = (int) ( nVideoW / fPrefWH ); + } + + nX = ( nW - nVideoW ) >> 1; + nY = ( nH - nVideoH ) >> 1; + nWidth = nVideoW; + nHeight = nVideoH; + } + else + { + nX = nY = nWidth = nHeight = 0; + } + } + + mpPlayerWindow->SetPosSizePixel( Point( nX, nY ), Size( nWidth, nHeight ) ); + } +} + +// ------------------------------------------------------------------------------ + +bool Window::create( const uno::Sequence< uno::Any >& rArguments ) +{ + OSL_ASSERT( !mpPlayerWindow ); + OSL_ENSURE( rArguments.getLength() > 2, +"::avmedia::gst::Windiow::create: GStreamer backend needs \ +valid parent SystemChildWindow pointer (sal_IntPtr) as third Any \ +value in sequence of arguments" ); + + bool bRet = false; + + if( !mpPlayerWindow && ( rArguments.getLength() > 2 ) ) + { + SystemChildWindow* pParentWindow = NULL; + sal_IntPtr pIntPtr = NULL; + + // we are not interested in the first argument, which is a pure X11 window handle; + // this backend relies on a SystemChildWindow as parent for the PlayerWindow, given + // as third Sal_IntPtr value within the argument Sequence + rArguments[ 1 ] >>= maWindowRect; + + rArguments[ 2 ] >>= pIntPtr; + pParentWindow = reinterpret_cast< SystemChildWindow* >( pIntPtr ); + + if( pParentWindow ) + { + meZoomLevel = media::ZoomLevel_ORIGINAL; + + mpPlayerWindow = new PlayerChildWindow( pParentWindow ); + mpPlayerWindow->SetBackground( Color( COL_BLACK ) ); + mpPlayerWindow->SetPosSizePixel( Point( maWindowRect.X, maWindowRect.Y ), + Size( maWindowRect.Width, maWindowRect.Height ) ); + mpPlayerWindow->Show(); + + bRet = true; + } + } + + return( bRet ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::update() + throw( uno::RuntimeException ) +{ + if( mpPlayerWindow ) + { + mpPlayerWindow->Invalidate( INVALIDATE_UPDATE ); + mpPlayerWindow->Sync(); + } +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) + throw(uno::RuntimeException) +{ + bool bRet = false; + + if( ( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel ) && + ( media::ZoomLevel_NOT_AVAILABLE != eZoomLevel ) ) + { + if( eZoomLevel != meZoomLevel ) + { + meZoomLevel = eZoomLevel; + implLayoutVideoWindow(); + } + + bRet = true; + } + + return( bRet ); +} + +// ------------------------------------------------------------------------------ + +media::ZoomLevel SAL_CALL Window::getZoomLevel() + throw( uno::RuntimeException ) +{ + return( meZoomLevel ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) + throw( uno::RuntimeException ) +{ + if( mpPlayerWindow ) + { + Pointer ePointer = POINTER_ARROW; + + switch( nPointerType ) + { + case (awt::SystemPointer::CROSS) : + { + ePointer = POINTER_CROSS; + } + break; + + case (awt::SystemPointer::HAND) : + { + ePointer = POINTER_HAND; + } + break; + + case (awt::SystemPointer::MOVE) : + { + ePointer = POINTER_MOVE; + } + break; + + case (awt::SystemPointer::WAIT) : + { + ePointer = POINTER_WAIT; + } + break; + + default: + break; + } + + mpPlayerWindow->SetPointer( ePointer ); + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPosSize( sal_Int32 nX, + sal_Int32 nY, + sal_Int32 nWidth, + sal_Int32 nHeight, + sal_Int16 /* Flags */ ) + throw( uno::RuntimeException ) +{ + maWindowRect.X = nX; + maWindowRect.Y = nY; + maWindowRect.Width = nWidth; + maWindowRect.Height = nHeight; + + implLayoutVideoWindow(); +} + +// ------------------------------------------------------------------------------ + +awt::Rectangle SAL_CALL Window::getPosSize() + throw( uno::RuntimeException ) +{ + return( maWindowRect ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setVisible( sal_Bool bVisible ) + throw( uno::RuntimeException ) +{ + if( mpPlayerWindow ) + { + bVisible ? mpPlayerWindow->Show() : mpPlayerWindow->Hide(); + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setEnable( sal_Bool bEnable ) + throw( uno::RuntimeException ) +{ + if( mpPlayerWindow ) + { + mpPlayerWindow->Enable( bEnable ); + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setFocus() + throw( uno::RuntimeException ) +{ + if( mpPlayerWindow ) + { + mpPlayerWindow->GrabFocus(); + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::dispose() + throw( uno::RuntimeException ) +{ + delete mpPlayerWindow; + mpPlayerWindow = NULL; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw( uno::RuntimeException ) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& + xListener ) + throw( uno::RuntimeException ) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = + maListeners.getContainer( getCppuType( ( uno::Reference< awt::XMouseListener >* ) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + { + uno::Reference< awt::XMouseListener >( aIter.next(), + uno::UNO_QUERY )->mousePressed( rEvt ); + } + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = + maListeners.getContainer( getCppuType( ( uno::Reference< awt::XMouseListener >* ) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + { + uno::Reference< awt::XMouseListener >( aIter.next(), + uno::UNO_QUERY )->mouseReleased( rEvt ); + } + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = + maListeners.getContainer( getCppuType( ( uno::Reference< awt::XMouseMotionListener >* ) + 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + { + uno::Reference< awt::XMouseMotionListener >( aIter.next(), + uno::UNO_QUERY )->mouseMoved( rEvt ); + } + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = + maListeners.getContainer( getCppuType( ( uno::Reference< awt::XFocusListener >* ) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + { + uno::Reference< awt::XFocusListener >( aIter.next(), + uno::UNO_QUERY )->focusGained( rEvt ); + } + } +} + +// ------------------------------------------------------------------------------ + +long Window::getXWindowHandle() const +{ + return( mpPlayerWindow ? mpPlayerWindow->GetSystemData()->aWindow : 0 ); +} + + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Window::getImplementationName() + throw( uno::RuntimeException ) +{ + return( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + AVMEDIA_GSTREAMER_WINDOW_IMPLEMENTATIONNAME ) ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) + throw( uno::RuntimeException ) +{ + return( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( + AVMEDIA_GSTREAMER_WINDOW_SERVICENAME ) ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames() + throw( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aRet( 1 ); + aRet[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_GSTREAMER_WINDOW_SERVICENAME ) ); + + return( aRet ); +} +} // namespace gst +} // namespace avmedia diff --git a/avmedia/source/gstreamer/gstwindow.hxx b/avmedia/source/gstreamer/gstwindow.hxx new file mode 100644 index 000000000000..3a55fca9c8bf --- /dev/null +++ b/avmedia/source/gstreamer/gstwindow.hxx @@ -0,0 +1,197 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _GSTWINDOW_HXX +#define _GSTWINDOW_HXX + +#include "gstcommon.hxx" +#include <cppuhelper/interfacecontainer.h> + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYERWINDOW_HDL_ +#include "com/sun/star/media/XPlayerWindow.hdl" +#endif + +namespace avmedia +{ +namespace gst +{ + +class PlayerChildWindow; + +// --------------- +// - Window - +// --------------- + +class Player; + +class Window : public ::cppu::WeakImplHelper2< ::com::sun::star::media::XPlayerWindow, + ::com::sun::star::lang::XServiceInfo > +{ + friend class Player; + +public: Window( ::avmedia::gst::Player& rPlayer ); + ~Window(); + + bool create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + + // XPlayerWindow + virtual void SAL_CALL update() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL setZoomLevel( ::com::sun::star::media::ZoomLevel ZoomLevel ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::media::ZoomLevel SAL_CALL getZoomLevel() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setPointerType( sal_Int32 nPointerType ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XWindow + virtual void SAL_CALL setPosSize( sal_Int32 X, + sal_Int32 Y, + sal_Int32 Width, + sal_Int32 Height, + sal_Int16 Flags ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setVisible( sal_Bool Visible ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setEnable( sal_Bool Enable ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL setFocus() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addWindowListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeWindowListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addFocusListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeFocusListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addKeyListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeKeyListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addMouseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeMouseListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addMouseMotionListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeMouseMotionListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addPaintListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removePaintListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XComponent + virtual void SAL_CALL dispose() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL addEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL removeEventListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException ); + + +public: + + void fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + + void fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + + void fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + + void fireKeyPressedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + + void fireKeyReleasedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + + void fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ); + +protected: + + long getXWindowHandle() const; + +private: + + ::osl::Mutex maMutex; + ::cppu::OMultiTypeInterfaceContainerHelper maListeners; + ::com::sun::star::awt::Rectangle maWindowRect; + Player& mrPlayer; + PlayerChildWindow* mpPlayerWindow; + ::com::sun::star::media::ZoomLevel meZoomLevel; + sal_Int32 mnPointerType; + + void implLayoutVideoWindow(); +}; +} // namespace gst +} // namespace avmedia + +#endif // _GSTWINDOW_HXX diff --git a/avmedia/source/gstreamer/makefile.mk b/avmedia/source/gstreamer/makefile.mk new file mode 100644 index 000000000000..2f22c7333778 --- /dev/null +++ b/avmedia/source/gstreamer/makefile.mk @@ -0,0 +1,71 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmediagst +TARGET=avmediagst + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +# --- Files ---------------------------------- + +.IF "$(GUI)" == "UNX" && "$(GUIBASE)"!="aqua" && "$(ENABLE_GSTREAMER)" != "" + +PKGCONFIG_MODULES=gtk+-2.0 gstreamer-0.10 gstreamer-interfaces-0.10 +.INCLUDE : pkg_config.mk + +SLOFILES= \ + $(SLO)$/gstuno.obj \ + $(SLO)$/gstmanager.obj \ + $(SLO)$/gstwindow.obj \ + $(SLO)$/gstplayer.obj \ + $(SLO)$/gstframegrabber.obj + +EXCEPTIONSFILES= \ + $(SLO)$/gstuno.obj \ + $(SLO)$/gstplayer.obj \ + $(SLO)$/gstframegrabber.obj + +SHL1TARGET=$(TARGET) +SHL1STDLIBS= $(CPPULIB) $(SALLIB) $(COMPHELPERLIB) $(CPPUHELPERLIB) $(TOOLSLIB) $(VCLLIB) +SHL1STDLIBS+=$(PKGCONFIG_LIBS) +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +.ENDIF + +.INCLUDE : target.mk diff --git a/avmedia/source/inc/mediamisc.hxx b/avmedia/source/inc/mediamisc.hxx new file mode 100644 index 000000000000..f33bd46568c8 --- /dev/null +++ b/avmedia/source/inc/mediamisc.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +class ResMgr; + +#define AVMEDIA_RESID( nId ) ResId( nId, * ::avmedia::GetResMgr() ) + +#ifdef WNT + +#define AVMEDIA_MANAGER_SERVICE_NAME "com.sun.star.comp.avmedia.Manager_DirectX" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED sal_False + +#define AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1 "" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED_FALLBACK1 sal_False + +#else +#ifdef QUARTZ + +#define AVMEDIA_MANAGER_SERVICE_NAME "com.sun.star.comp.avmedia.Manager_QuickTime" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED sal_False + +#define AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1 "" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED_FALLBACK1 sal_False + +#else + +#define AVMEDIA_MANAGER_SERVICE_NAME "com.sun.star.comp.avmedia.Manager_GStreamer" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED sal_False + +#define AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1 "com.sun.star.comp.avmedia.Manager_Java" +#define AVMEDIA_MANAGER_SERVICE_IS_JAVABASED_FALLBACK1 sal_True + +#endif +#endif + +namespace avmedia +{ + ResMgr* GetResMgr(); +} diff --git a/avmedia/source/java/FrameGrabber.java b/avmedia/source/java/FrameGrabber.java new file mode 100644 index 000000000000..1a0deda4ce57 --- /dev/null +++ b/avmedia/source/java/FrameGrabber.java @@ -0,0 +1,190 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XEventListener; +import com.sun.star.awt.*; +import com.sun.star.media.*; +import com.sun.star.graphic.*; + +// ----------------- +// - Player Window - +// ----------------- + +public class FrameGrabber implements com.sun.star.lang.XServiceInfo, + com.sun.star.media.XFrameGrabber +{ + private com.sun.star.lang.XMultiServiceFactory maFactory = null; + private javax.media.Player maPlayer = null; + private javax.media.control.FrameGrabbingControl maFrameGrabbingControl = null; + + // ------------------------------------------------------------------------- + + public FrameGrabber( com.sun.star.lang.XMultiServiceFactory aFactory, String aURL ) + { + maFactory = aFactory; + + try + { + maPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); + } + catch( java.net.MalformedURLException e ) + { + } + catch( java.io.IOException e ) + { + } + catch( javax.media.NoPlayerException e ) + { + } + catch( javax.media.CannotRealizeException e ) + { + } + catch( java.lang.Exception e ) + { + } + + if( maPlayer != null ) + { + maFrameGrabbingControl = (javax.media.control.FrameGrabbingControl) maPlayer.getControl( + "javax.media.control.FrameGrabbingControl" ); + } + } + + // ------------------------------------------------------------------------- + + public com.sun.star.graphic.XGraphic implImageToXGraphic( java.awt.Image aImage ) + { + com.sun.star.graphic.XGraphic aRet = null; + + if( maFactory != null && aImage != null ) + { + if( aImage instanceof java.awt.image.BufferedImage ) + { + java.io.File aTempFile = null; + + try + { + aTempFile = java.io.File.createTempFile( "sv0", ".png" ); + + if( aTempFile.canWrite() ) + { + javax.imageio.ImageIO.write( (java.awt.image.BufferedImage) aImage, "png", aTempFile ); + + com.sun.star.graphic.XGraphicProvider aProvider = + (com.sun.star.graphic.XGraphicProvider) UnoRuntime.queryInterface( + com.sun.star.graphic.XGraphicProvider.class, + maFactory.createInstance("com.sun.star.graphic.GraphicProvider") ); + + if( aProvider != null ) + { + com.sun.star.beans.PropertyValue[] aArgs = new com.sun.star.beans.PropertyValue[ 1 ]; + + aArgs[ 0 ] = new com.sun.star.beans.PropertyValue(); + aArgs[ 0 ].Name = "URL"; + aArgs[ 0 ].Value = "file://" + aTempFile.toString(); + + aRet = aProvider.queryGraphic( aArgs ); + } + } + } + catch( java.lang.IllegalArgumentException aExcp ) + { + } + catch( java.io.IOException aExcp ) + { + } + catch( com.sun.star.uno.Exception aExcp ) + { + } + + if( aTempFile != null ) + aTempFile.delete(); + } + } + + return aRet; + } + + // ----------------- + // - XFrameGrabber - + // ----------------- + + public synchronized com.sun.star.graphic.XGraphic grabFrame( double fMediaTime ) + { + com.sun.star.graphic.XGraphic aRet = null; + + if( maFrameGrabbingControl != null ) + { + if( fMediaTime >= 0.0 && fMediaTime <= maPlayer.getDuration().getSeconds() ) + { + maPlayer.setMediaTime( new javax.media.Time( fMediaTime ) ); + + javax.media.Buffer aBuffer = maFrameGrabbingControl.grabFrame(); + + if( aBuffer != null && aBuffer.getFormat() instanceof javax.media.format.VideoFormat ) + { + aRet = implImageToXGraphic( new javax.media.util.BufferToImage( + (javax.media.format.VideoFormat) aBuffer.getFormat() ). + createImage( aBuffer ) ); + } + } + } + + return aRet; + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.FrameGrabber_Java"; + private static final String s_serviceName = "com.sun.star.media.FrameGrabber_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/Manager.java b/avmedia/source/java/Manager.java new file mode 100644 index 000000000000..47707478fd5b --- /dev/null +++ b/avmedia/source/java/Manager.java @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +// media +import com.sun.star.media.*; + +public class Manager implements com.sun.star.lang.XServiceInfo, + com.sun.star.lang.XTypeProvider, + com.sun.star.media.XManager + +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + + // ------------------------------------------------------------------------- + + public Manager( com.sun.star.lang.XMultiServiceFactory aFactory ) + { + maFactory = aFactory; + } + + // ------------ + // - XManager - + // ------------ + + public com.sun.star.media.XPlayer createPlayer( String aURL ) + { + javax.media.Player aPlayer = null; + + try + { + aPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); + } + catch( java.net.MalformedURLException e ) + { + } + catch( java.io.IOException e ) + { + } + catch( javax.media.NoPlayerException e ) + { + } + catch( javax.media.CannotRealizeException e ) + { + } + catch( java.lang.Exception e ) + { + } + + if( aPlayer != null ) + { + return new Player( maFactory, aPlayer, aURL ); + } + else + return null; + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; + private static final String s_serviceName = "com.sun.star.media.Manager_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + // ----------------- + // - XTypeProvider - + // ----------------- + protected byte[] maImplementationId; + + public com.sun.star.uno.Type[] getTypes() + { + com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[ 3 ]; + + retValue[ 0 ]= new com.sun.star.uno.Type( com.sun.star.lang.XServiceInfo.class ); + retValue[ 1 ]= new com.sun.star.uno.Type( com.sun.star.lang.XTypeProvider.class ); + retValue[ 2 ]= new com.sun.star.uno.Type( com.sun.star.media.XManager.class ); + + return retValue; + } + + // ------------------------------------------------------------------------- + + synchronized public byte[] getImplementationId() + { + if( maImplementationId == null) + { + maImplementationId = new byte[ 16 ]; + + int hash = hashCode(); + + maImplementationId[ 0 ] = (byte)(hash & 0xff); + maImplementationId[ 1 ] = (byte)((hash >>> 8) & 0xff); + maImplementationId[ 2 ] = (byte)((hash >>> 16) & 0xff); + maImplementationId[ 3 ] = (byte)((hash >>>24) & 0xff); + } + + return maImplementationId; + } +} diff --git a/avmedia/source/java/MediaUno.java b/avmedia/source/java/MediaUno.java new file mode 100644 index 000000000000..ca7a164586d8 --- /dev/null +++ b/avmedia/source/java/MediaUno.java @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +public class MediaUno +{ + private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; + private static final String s_serviceName = "com.sun.star.media.Manager_Java"; + + // ------------------------------------------------------------------------- + + public MediaUno() + { + } + + // ------------------------------------------------------------------------- + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + try + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + Class.forName( "Manager" ), s_serviceName, multiFactory, regKey ); + } + catch( java.lang.ClassNotFoundException exception ) + { + } + } + + return null; + } + + // ------------------------------------------------------------------------- + + public static boolean __writeRegistryServiceInfo( + com.sun.star.registry.XRegistryKey regKey ) + { + return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( + s_implName, s_serviceName, regKey ); + } +} diff --git a/avmedia/source/java/Player.java b/avmedia/source/java/Player.java new file mode 100644 index 000000000000..be3b3d62d367 --- /dev/null +++ b/avmedia/source/java/Player.java @@ -0,0 +1,325 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +// awt +import com.sun.star.awt.*; + +// media +import com.sun.star.media.*; + +public class Player implements javax.media.ControllerListener, + com.sun.star.lang.XServiceInfo, + com.sun.star.media.XPlayer, + com.sun.star.lang.XComponent + + +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + private String maURL; + private javax.media.Player maPlayer; + private javax.media.GainControl maGainControl; + private boolean mbStarted = false; + private boolean mbLooping = false; + + // ------------------------------------------------------------------------- + + public Player( com.sun.star.lang.XMultiServiceFactory aFactory, + javax.media.Player aPlayer, String aURL ) + { + maFactory = aFactory; + maURL = aURL; + maPlayer = aPlayer; + maPlayer.addControllerListener( this ); + maGainControl = maPlayer.getGainControl(); + } + + // ------------------------------------------------------------------------- + + public synchronized void controllerUpdate( javax.media.ControllerEvent aEvt ) + { + if( aEvt instanceof javax.media.EndOfMediaEvent || + aEvt instanceof javax.media.StopAtTimeEvent ) + { + mbStarted = false; + + if( mbLooping ) + { + setMediaTime( 0.0 ); + start(); + } + else if( aEvt instanceof javax.media.EndOfMediaEvent ) + setMediaTime( getDuration() ); + } + } + + // ----------- + // - XPlayer - + // ----------- + + public synchronized void start() + { + if( !mbStarted ) + { + maPlayer.start(); + mbStarted = true; + } + } + + // ------------------------------------------------------------------------- + + public synchronized void stop() + { + if( mbStarted ) + { + maPlayer.stop(); + mbStarted = false; + } + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isPlaying() + { + return mbStarted; + } + + // ------------------------------------------------------------------------- + + public synchronized double getDuration() + { + return maPlayer.getDuration().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setMediaTime( double fTime ) + { + if( fTime >= 0.0 && fTime <= getDuration() ) + maPlayer.setMediaTime( new javax.media.Time( fTime ) ); + } + + // ------------------------------------------------------------------------- + + public synchronized double getMediaTime() + { + return maPlayer.getMediaTime().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setStopTime( double fTime ) + { + boolean bOldStarted = mbStarted; + + if( mbStarted ) + stop(); + + maPlayer.setStopTime( new javax.media.Time( fTime ) ); + + if( bOldStarted ) + start(); + } + + // ------------------------------------------------------------------------- + + public synchronized double getStopTime() + { + return maPlayer.getStopTime().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setRate( double fRate ) + { + boolean bOldStarted = mbStarted; + + if( mbStarted ) + stop(); + + maPlayer.setRate( (float) fRate ); + + if( bOldStarted ) + start(); + } + + // ------------------------------------------------------------------------- + + public synchronized double getRate() + { + return (double) maPlayer.getRate(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setPlaybackLoop( boolean bSet ) + { + mbLooping = bSet; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isPlaybackLoop() + { + return mbLooping; + } + + // ------------------------------------------------------------------------- + + public synchronized void setVolumeDB( short nVolumeDB ) + { + if( maGainControl != null ) + maGainControl.setDB( nVolumeDB ); + } + + // ------------------------------------------------------------------------- + + public synchronized short getVolumeDB() + { + return( maGainControl != null ? (short) maGainControl.getDB() : 0 ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setMute( boolean bSet ) + { + if( maGainControl != null ) + maGainControl.setMute( bSet ); + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isMute() + { + return( maGainControl != null ? maGainControl.getMute() : false ); + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.awt.Size getPreferredPlayerWindowSize() + { + java.awt.Component aVisualComponent = maPlayer.getVisualComponent(); + com.sun.star.awt.Size aSize = new com.sun.star.awt.Size( 0, 0 ); + + if( aVisualComponent != null ) + { + java.awt.Dimension aDim = aVisualComponent.getPreferredSize(); + + aSize.Width = Math.max( aDim.width, 0 ); + aSize.Height = Math.max( aDim.height, 0 ); + } + + return aSize; + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.XPlayerWindow createPlayerWindow( java.lang.Object[] aArgs ) + { + try + { + com.sun.star.media.XPlayerWindow xPlayerWindow = ( ( ( aArgs.length > 1 ) && ( AnyConverter.toInt( aArgs[ 0 ] ) > 0 ) ) ? + new PlayerWindow( maFactory, aArgs, maPlayer ) : + null ); + + // check if it is a real player window (video window) + if( xPlayerWindow != null && xPlayerWindow.getZoomLevel() == com.sun.star.media.ZoomLevel.NOT_AVAILABLE ) + xPlayerWindow = null; + + return xPlayerWindow; + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + return null; + } + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.XFrameGrabber createFrameGrabber() + { + return( (com.sun.star.media.XFrameGrabber) new FrameGrabber( maFactory, maURL ) ); + } + + // -------------- + // - XComponent - + // -------------- + + public synchronized void addEventListener( com.sun.star.lang.XEventListener xListener ) + { + } + + // ------------------------------------------------------------------------- + + public synchronized void removeEventListener( com.sun.star.lang.XEventListener xListener ) + { + } + + // ------------------------------------------------------------------------- + + public synchronized void dispose() + { + if( maPlayer != null ) + { + maPlayer.stop(); + maPlayer.close(); + maPlayer = null; + } + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.Player_Java"; + private static final String s_serviceName = "com.sun.star.media.Player_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/PlayerWindow.java b/avmedia/source/java/PlayerWindow.java new file mode 100644 index 000000000000..2229e4f1644b --- /dev/null +++ b/avmedia/source/java/PlayerWindow.java @@ -0,0 +1,600 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XEventListener; +import com.sun.star.awt.*; +import com.sun.star.media.*; + +// ----------------- +// - Player Window - +// ----------------- + +public class PlayerWindow implements java.awt.event.KeyListener, + java.awt.event.MouseListener, + java.awt.event.MouseMotionListener, + java.awt.event.FocusListener, + com.sun.star.lang.XServiceInfo, + com.sun.star.media.XPlayerWindow +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + private WindowAdapter maFrame; + private javax.media.Player maPlayer; + private com.sun.star.media.ZoomLevel meZoomLevel = com.sun.star.media.ZoomLevel.ORIGINAL; + private boolean mbShowControls = false; + + + // ------------------------------------------------------------------------- + + public PlayerWindow( com.sun.star.lang.XMultiServiceFactory aFactory, + java.lang.Object[] aArgs, javax.media.Player aPlayer ) + { + maFactory = aFactory; + + try + { + if( aArgs.length > 1 ) + { + com.sun.star.awt.Rectangle aBoundRect = (com.sun.star.awt.Rectangle) aArgs[ 1 ]; + + maFrame = new WindowAdapter( AnyConverter.toInt( aArgs[ 0 ] ) ); + maFrame.setPosSize( aBoundRect.X, aBoundRect.Y, aBoundRect.Width, aBoundRect.Height, (short) 0 ); + mbShowControls = false; + + java.awt.Panel aPanel = new java.awt.Panel( new java.awt.BorderLayout() ); + + aPanel.setLayout( null ); + aPanel.setBackground( java.awt.Color.black ); + aPanel.addKeyListener( this ); + aPanel.addMouseListener( this ); + aPanel.addMouseMotionListener( this ); + + if( mbShowControls ) + { + java.awt.Component aControlComponent = aPlayer.getControlPanelComponent(); + + if( aControlComponent != null ) + aPanel.add( aControlComponent ); + else + mbShowControls = false; + } + + java.awt.Component aVisualComponent = aPlayer.getVisualComponent(); + + if( aVisualComponent != null ) + { + aVisualComponent.addKeyListener( this ); + aVisualComponent.addMouseListener( this ); + aVisualComponent.addMouseMotionListener( this ); + aVisualComponent.addFocusListener( this ); + aPanel.add( aVisualComponent ); + } + else + meZoomLevel = com.sun.star.media.ZoomLevel.NOT_AVAILABLE; + + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().add( aPanel ); + + LayoutComponents(); + } + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + } + } + + // ------------------------------------------------------------------------- + + protected synchronized void LayoutComponents() + { + if( maFrame.getJavaFrame() != null ) + { + java.awt.Panel aPanel = (java.awt.Panel) maFrame.getJavaFrame().getComponent( 0 ); + int nW = maFrame.getJavaFrame().getWidth(); + int nH = maFrame.getJavaFrame().getHeight(); + int nControlH = 0; + + aPanel.setBounds( 0, 0, nW, nH ); + + if( mbShowControls ) + { + java.awt.Component aControlComponent = aPanel.getComponent( 0 ); + + if( aControlComponent != null ) + { + java.awt.Dimension aControlDimension = aControlComponent.getPreferredSize(); + + nControlH = Math.min( nH, aControlDimension.height ); + aControlComponent.setBounds( 0, nH - nControlH, nW, nControlH ); + } + } + + if( com.sun.star.media.ZoomLevel.NOT_AVAILABLE != meZoomLevel ) + { + java.awt.Component aVisualComponent = aPanel.getComponent( mbShowControls ? 1 : 0 ); + + if( aVisualComponent != null ) + { + java.awt.Dimension aPrefDim = aVisualComponent.getPreferredSize(); + int nVideoW = nW, nVideoH = ( nH - nControlH ); + int nX = 0, nY = 0, nWidth = 0, nHeight = 0; + boolean bDone = false, bZoom = false; + + if( com.sun.star.media.ZoomLevel.ORIGINAL == meZoomLevel ) + { + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_1_TO_4 == meZoomLevel ) + { + aPrefDim.width >>= 2; + aPrefDim.height >>= 2; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_1_TO_2 == meZoomLevel ) + { + aPrefDim.width >>= 1; + aPrefDim.height >>= 1; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_2_TO_1 == meZoomLevel ) + { + aPrefDim.width <<= 1; + aPrefDim.height <<= 1; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_4_TO_1 == meZoomLevel ) + { + aPrefDim.width <<= 2; + aPrefDim.height <<= 2; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.FIT_TO_WINDOW == meZoomLevel ) + { + nWidth = nVideoW; + nHeight = nVideoH; + bDone = true; + } + + if( bZoom ) + { + if( ( aPrefDim.width <= nVideoW ) && ( aPrefDim.height <= nVideoH ) ) + { + nX = ( nVideoW - aPrefDim.width ) >> 1; + nY = ( nVideoH - aPrefDim.height ) >> 1; + nWidth = aPrefDim.width; + nHeight = aPrefDim.height; + bDone = true; + } + } + + if( !bDone ) + { + if( aPrefDim.width > 0 && aPrefDim.height > 0 && nVideoW > 0 && nVideoH > 0 ) + { + double fPrefWH = (double) aPrefDim.width / aPrefDim.height; + + if( fPrefWH < ( (double) nVideoW / nVideoH ) ) + nVideoW = (int)( nVideoH * fPrefWH ); + else + nVideoH = (int)( nVideoW / fPrefWH ); + + nX = ( nW - nVideoW ) >> 1; + nY = ( nH - nControlH - nVideoH ) >> 1; + nWidth = nVideoW; + nHeight = nVideoH; + } + else + nX = nY = nWidth = nHeight = 0; + } + + aVisualComponent.setBounds( nX, nY, nWidth, nHeight ); + aVisualComponent.requestFocus(); + } + else + aPanel.requestFocus(); + } + else + aPanel.requestFocus(); + } + } + + // ------------------------------------------------------------------------- + + private void implFireMouseEvent( java.awt.event.MouseEvent aEvt ) + { + if( aEvt.getSource() != null && + aEvt.getSource() instanceof java.awt.Component ) + { + aEvt.translatePoint( ( (java.awt.Component) aEvt.getSource() ).getX(), + ( (java.awt.Component) aEvt.getSource() ).getY() ); + } + + maFrame.fireMouseEvent( aEvt ); + } + + // --------------- + // - KeyListener - + // --------------- + + public void keyPressed( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void keyReleased( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void keyTyped( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ----------------- + // - MouseListener - + // ----------------- + + public void mousePressed( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseClicked( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseEntered( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseExited( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseReleased( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ----------------------- + // - MouseMotionListener - + // ----------------------- + + public void mouseDragged( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseMoved( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ----------------------- + // - FocusListener - + // ----------------------- + + public void focusGained( java.awt.event.FocusEvent aEvt ) + { + if( maFrame.getJavaFrame() != null ) + maFrame.fireFocusEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void focusLost( java.awt.event.FocusEvent aEvt ) + { + if( maFrame.getJavaFrame() != null ) + maFrame.fireFocusEvent( aEvt ); + } + + // ----------------- + // - XPlayerWindow - + // ----------------- + + public synchronized void update() + { + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().repaint(); + } + + // ------------------------------------------------------------------------- + + public synchronized boolean setZoomLevel( com.sun.star.media.ZoomLevel eZoomLevel ) + { + boolean bRet = false; + + if( com.sun.star.media.ZoomLevel.NOT_AVAILABLE != meZoomLevel && + com.sun.star.media.ZoomLevel.NOT_AVAILABLE != eZoomLevel ) + { + if( eZoomLevel != meZoomLevel ) + { + meZoomLevel = eZoomLevel; + LayoutComponents(); + } + + bRet = true; + } + + return bRet; + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.ZoomLevel getZoomLevel() + { + return meZoomLevel; + } + + // ------------------------------------------------------------------------- + + public synchronized void setPointerType( int nPointerType ) + { + if( maFrame.getJavaFrame() != null ) + { + int nCursor; + + switch( nPointerType ) + { + case( com.sun.star.awt.SystemPointer.CROSS ): nCursor = java.awt.Cursor.CROSSHAIR_CURSOR; break; + case( com.sun.star.awt.SystemPointer.HAND ): nCursor = java.awt.Cursor.HAND_CURSOR; break; + case( com.sun.star.awt.SystemPointer.MOVE ): nCursor = java.awt.Cursor.MOVE_CURSOR; break; + case( com.sun.star.awt.SystemPointer.WAIT ): nCursor = java.awt.Cursor.WAIT_CURSOR; break; + + default: nCursor = java.awt.Cursor.DEFAULT_CURSOR; break; + } + + maFrame.getJavaFrame().setCursor( java.awt.Cursor.getPredefinedCursor( nCursor ) ); + } + } + + // -------------- + // - XComponent - + // -------------- + + public synchronized void dispose() + { + if( maFrame != null ) + { + java.awt.Panel aPanel = (java.awt.Panel) maFrame.getJavaFrame().getComponent( 0 ); + + if( aPanel != null && aPanel.getComponent( 0 ) != null ) + aPanel.getComponent( 0 ).removeFocusListener( this ); + + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().dispose(); + + maFrame.fireDisposingEvent(); + } + + maFrame = null; + } + + // ----------- + // - XWindow - + // ----------- + + public synchronized void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + if( maFrame != null ) + { + maFrame.setPosSize( X, Y, Width, Height, Flags ); + LayoutComponents(); + } + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.awt.Rectangle getPosSize() + { + return( ( maFrame != null ) ? maFrame.getPosSize() : new com.sun.star.awt.Rectangle() ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setVisible( boolean visible ) + { + if( maFrame != null ) + maFrame.setVisible( visible ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setEnable( boolean enable ) + { + if( maFrame != null ) + maFrame.setEnable( enable ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setFocus() + { + if( maFrame != null ) + maFrame.setFocus(); + } + + // ------------------------------------------------------------------------- + + public synchronized void addEventListener( com.sun.star.lang.XEventListener xListener ) + { + if( maFrame != null ) + maFrame.addEventListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeEventListener( com.sun.star.lang.XEventListener xListener ) + { + if( maFrame != null ) + maFrame.removeEventListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addWindowListener( XWindowListener xListener ) + { + if( maFrame != null ) + maFrame.addWindowListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeWindowListener( XWindowListener xListener ) + { + if( maFrame != null ) + maFrame.removeWindowListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addFocusListener( XFocusListener xListener ) + { + if( maFrame != null ) + maFrame.addFocusListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeFocusListener( XFocusListener xListener ) + { + if( maFrame != null ) + maFrame.removeFocusListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addKeyListener( XKeyListener xListener ) + { + if( maFrame != null ) + maFrame.addKeyListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeKeyListener( XKeyListener xListener ) + { + if( maFrame != null ) + maFrame.removeKeyListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addMouseListener( XMouseListener xListener ) + { + if( maFrame != null ) + maFrame.addMouseListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeMouseListener( XMouseListener xListener ) + { + if( maFrame != null ) + maFrame.removeMouseListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( maFrame != null ) + maFrame.addMouseMotionListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( maFrame != null ) + maFrame.removeMouseMotionListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addPaintListener( XPaintListener xListener ) + { + if( maFrame != null ) + maFrame.addPaintListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removePaintListener( XPaintListener xListener ) + { + if( maFrame != null ) + maFrame.removePaintListener( xListener ); + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.PlayerWindow_Java"; + private static final String s_serviceName = "com.sun.star.media.PlayerWindow_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/WindowAdapter.java b/avmedia/source/java/WindowAdapter.java new file mode 100644 index 000000000000..bd11aec5e738 --- /dev/null +++ b/avmedia/source/java/WindowAdapter.java @@ -0,0 +1,508 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; +import com.sun.star.lang.*; +import java.util.*; +import javax.swing.*; + +public class WindowAdapter +{ + private java.awt.Frame maFrame; + private LinkedList maEventListeners = new LinkedList(); + private LinkedList maWindowListeners = new LinkedList(); + private LinkedList maFocusListeners = new LinkedList(); + private LinkedList maKeyListeners = new LinkedList(); + private LinkedList maMouseListeners = new LinkedList(); + private LinkedList maMouseMotionListeners = new LinkedList(); + private LinkedList maPaintListeners = new LinkedList(); + private boolean mbShift = false, mbMod1 = false, mbMod2 = false; + + // ----------------- + // - WindowAdapter - + // ----------------- + + public WindowAdapter( int windowHandle ) + { + maFrame = SystemWindowAdapter.createFrame( windowHandle ); + } + + //---------------------------------------------------------------------------------- + + public java.awt.Frame getJavaFrame() + { + return maFrame; + } + + //---------------------------------------------------------------------------------- + + private short implGetUNOKeyCode( int nJavaKeyCode ) + { + short nRet = 0; + + switch( nJavaKeyCode ) + { + case( java.awt.event.KeyEvent.VK_NUMPAD0 ): + case( java.awt.event.KeyEvent.VK_0 ): nRet = com.sun.star.awt.Key.NUM0; break; + case( java.awt.event.KeyEvent.VK_NUMPAD1 ): + case( java.awt.event.KeyEvent.VK_1 ): nRet = com.sun.star.awt.Key.NUM1; break; + case( java.awt.event.KeyEvent.VK_NUMPAD2 ): + case( java.awt.event.KeyEvent.VK_2 ): nRet = com.sun.star.awt.Key.NUM2; break; + case( java.awt.event.KeyEvent.VK_NUMPAD3 ): + case( java.awt.event.KeyEvent.VK_3 ): nRet = com.sun.star.awt.Key.NUM3; break; + case( java.awt.event.KeyEvent.VK_NUMPAD4 ): + case( java.awt.event.KeyEvent.VK_4 ): nRet = com.sun.star.awt.Key.NUM4; break; + case( java.awt.event.KeyEvent.VK_NUMPAD5 ): + case( java.awt.event.KeyEvent.VK_5 ): nRet = com.sun.star.awt.Key.NUM5; break; + case( java.awt.event.KeyEvent.VK_NUMPAD6 ): + case( java.awt.event.KeyEvent.VK_6 ): nRet = com.sun.star.awt.Key.NUM6; break; + case( java.awt.event.KeyEvent.VK_NUMPAD7 ): + case( java.awt.event.KeyEvent.VK_7 ): nRet = com.sun.star.awt.Key.NUM7; break; + case( java.awt.event.KeyEvent.VK_NUMPAD8 ): + case( java.awt.event.KeyEvent.VK_8 ): nRet = com.sun.star.awt.Key.NUM8; break; + case( java.awt.event.KeyEvent.VK_NUMPAD9 ): + case( java.awt.event.KeyEvent.VK_9 ): nRet = com.sun.star.awt.Key.NUM9; break; + + case( java.awt.event.KeyEvent.VK_A ): nRet = com.sun.star.awt.Key.A; break; + case( java.awt.event.KeyEvent.VK_B ): nRet = com.sun.star.awt.Key.B; break; + case( java.awt.event.KeyEvent.VK_C ): nRet = com.sun.star.awt.Key.C; break; + case( java.awt.event.KeyEvent.VK_D ): nRet = com.sun.star.awt.Key.D; break; + case( java.awt.event.KeyEvent.VK_E ): nRet = com.sun.star.awt.Key.E; break; + case( java.awt.event.KeyEvent.VK_F ): nRet = com.sun.star.awt.Key.F; break; + case( java.awt.event.KeyEvent.VK_G ): nRet = com.sun.star.awt.Key.G; break; + case( java.awt.event.KeyEvent.VK_H ): nRet = com.sun.star.awt.Key.H; break; + case( java.awt.event.KeyEvent.VK_I ): nRet = com.sun.star.awt.Key.I; break; + case( java.awt.event.KeyEvent.VK_J ): nRet = com.sun.star.awt.Key.J; break; + case( java.awt.event.KeyEvent.VK_K ): nRet = com.sun.star.awt.Key.K; break; + case( java.awt.event.KeyEvent.VK_L ): nRet = com.sun.star.awt.Key.L; break; + case( java.awt.event.KeyEvent.VK_M ): nRet = com.sun.star.awt.Key.M; break; + case( java.awt.event.KeyEvent.VK_N ): nRet = com.sun.star.awt.Key.N; break; + case( java.awt.event.KeyEvent.VK_O ): nRet = com.sun.star.awt.Key.O; break; + case( java.awt.event.KeyEvent.VK_P ): nRet = com.sun.star.awt.Key.P; break; + case( java.awt.event.KeyEvent.VK_Q ): nRet = com.sun.star.awt.Key.Q; break; + case( java.awt.event.KeyEvent.VK_R ): nRet = com.sun.star.awt.Key.R; break; + case( java.awt.event.KeyEvent.VK_S ): nRet = com.sun.star.awt.Key.S; break; + case( java.awt.event.KeyEvent.VK_T ): nRet = com.sun.star.awt.Key.T; break; + case( java.awt.event.KeyEvent.VK_U ): nRet = com.sun.star.awt.Key.U; break; + case( java.awt.event.KeyEvent.VK_V ): nRet = com.sun.star.awt.Key.V; break; + case( java.awt.event.KeyEvent.VK_W ): nRet = com.sun.star.awt.Key.W; break; + case( java.awt.event.KeyEvent.VK_X ): nRet = com.sun.star.awt.Key.X; break; + case( java.awt.event.KeyEvent.VK_Y ): nRet = com.sun.star.awt.Key.Y; break; + case( java.awt.event.KeyEvent.VK_Z ): nRet = com.sun.star.awt.Key.Z; break; + + case( java.awt.event.KeyEvent.VK_F1 ): nRet = com.sun.star.awt.Key.F1; break; + case( java.awt.event.KeyEvent.VK_F2 ): nRet = com.sun.star.awt.Key.F2; break; + case( java.awt.event.KeyEvent.VK_F3 ): nRet = com.sun.star.awt.Key.F3; break; + case( java.awt.event.KeyEvent.VK_F4 ): nRet = com.sun.star.awt.Key.F4; break; + case( java.awt.event.KeyEvent.VK_F5 ): nRet = com.sun.star.awt.Key.F5; break; + case( java.awt.event.KeyEvent.VK_F6 ): nRet = com.sun.star.awt.Key.F6; break; + case( java.awt.event.KeyEvent.VK_F7 ): nRet = com.sun.star.awt.Key.F7; break; + case( java.awt.event.KeyEvent.VK_F8 ): nRet = com.sun.star.awt.Key.F8; break; + case( java.awt.event.KeyEvent.VK_F9 ): nRet = com.sun.star.awt.Key.F9; break; + case( java.awt.event.KeyEvent.VK_F10 ): nRet = com.sun.star.awt.Key.F10; break; + case( java.awt.event.KeyEvent.VK_F11 ): nRet = com.sun.star.awt.Key.F11; break; + case( java.awt.event.KeyEvent.VK_F12 ): nRet = com.sun.star.awt.Key.F12; break; + case( java.awt.event.KeyEvent.VK_F13 ): nRet = com.sun.star.awt.Key.F13; break; + case( java.awt.event.KeyEvent.VK_F14 ): nRet = com.sun.star.awt.Key.F14; break; + case( java.awt.event.KeyEvent.VK_F15 ): nRet = com.sun.star.awt.Key.F15; break; + case( java.awt.event.KeyEvent.VK_F16 ): nRet = com.sun.star.awt.Key.F16; break; + case( java.awt.event.KeyEvent.VK_F17 ): nRet = com.sun.star.awt.Key.F17; break; + case( java.awt.event.KeyEvent.VK_F18 ): nRet = com.sun.star.awt.Key.F18; break; + case( java.awt.event.KeyEvent.VK_F19 ): nRet = com.sun.star.awt.Key.F19; break; + case( java.awt.event.KeyEvent.VK_F20 ): nRet = com.sun.star.awt.Key.F20; break; + case( java.awt.event.KeyEvent.VK_F21 ): nRet = com.sun.star.awt.Key.F21; break; + case( java.awt.event.KeyEvent.VK_F22 ): nRet = com.sun.star.awt.Key.F22; break; + case( java.awt.event.KeyEvent.VK_F23 ): nRet = com.sun.star.awt.Key.F23; break; + case( java.awt.event.KeyEvent.VK_F24 ): nRet = com.sun.star.awt.Key.F24; break; + + case( java.awt.event.KeyEvent.VK_UP ): nRet = com.sun.star.awt.Key.UP; break; + case( java.awt.event.KeyEvent.VK_DOWN): nRet = com.sun.star.awt.Key.DOWN; break; + case( java.awt.event.KeyEvent.VK_LEFT ): nRet = com.sun.star.awt.Key.LEFT; break; + case( java.awt.event.KeyEvent.VK_RIGHT ): nRet = com.sun.star.awt.Key.RIGHT; break; + + case( java.awt.event.KeyEvent.VK_HOME ): nRet = com.sun.star.awt.Key.HOME; break; + case( java.awt.event.KeyEvent.VK_END ): nRet = com.sun.star.awt.Key.END; break; + + case( java.awt.event.KeyEvent.VK_PAGE_UP ): nRet = com.sun.star.awt.Key.PAGEUP; break; + case( java.awt.event.KeyEvent.VK_PAGE_DOWN ): nRet = com.sun.star.awt.Key.PAGEDOWN; break; + + case( java.awt.event.KeyEvent.VK_ENTER ): nRet = com.sun.star.awt.Key.RETURN; break; + case( java.awt.event.KeyEvent.VK_ESCAPE ): nRet = com.sun.star.awt.Key.ESCAPE; break; + + case( java.awt.event.KeyEvent.VK_TAB ): nRet = com.sun.star.awt.Key.TAB; break; + case( java.awt.event.KeyEvent.VK_BACK_SPACE ): nRet = com.sun.star.awt.Key.BACKSPACE; break; + case( java.awt.event.KeyEvent.VK_SPACE ): nRet = com.sun.star.awt.Key.SPACE; break; + case( java.awt.event.KeyEvent.VK_INSERT): nRet = com.sun.star.awt.Key.INSERT; break; + case( java.awt.event.KeyEvent.VK_DELETE): nRet = com.sun.star.awt.Key.DELETE; break; + case( java.awt.event.KeyEvent.VK_ADD ): nRet = com.sun.star.awt.Key.ADD; break; + case( java.awt.event.KeyEvent.VK_SUBTRACT ): nRet = com.sun.star.awt.Key.SUBTRACT; break; + case( java.awt.event.KeyEvent.VK_MULTIPLY ): nRet = com.sun.star.awt.Key.MULTIPLY; break; + case( java.awt.event.KeyEvent.VK_DIVIDE ): nRet = com.sun.star.awt.Key.DIVIDE; break; + case( java.awt.event.KeyEvent.VK_DECIMAL ): nRet = com.sun.star.awt.Key.POINT; break; + // case( java.awt.event.KeyEvent.VK_ COMMA; break; + case( java.awt.event.KeyEvent.VK_LESS ): nRet = com.sun.star.awt.Key.LESS; break; + case( java.awt.event.KeyEvent.VK_GREATER ): nRet = com.sun.star.awt.Key.GREATER; break; + case( java.awt.event.KeyEvent.VK_EQUALS ): nRet = com.sun.star.awt.Key.EQUAL; break; + // case( java.awt.event.KeyEvent.VK_ OPEN; break; + // case( java.awt.event.KeyEvent.VK_ CUT; break; + // case( java.awt.event.KeyEvent.VK_ COPY; break; + // case( java.awt.event.KeyEvent.VK_ PASTE; break; + // case( java.awt.event.KeyEvent.VK_ UNDO; break; + // case( java.awt.event.KeyEvent.VK_ REPEAT; break; + // case( java.awt.event.KeyEvent.VK_ FIND; break; + // case( java.awt.event.KeyEvent.VK_ PROPERTIES; break; + // case( java.awt.event.KeyEvent.VK_ FRONT; break; + // case( java.awt.event.KeyEvent.VK_ CONTEXTMENU; break; + // case( java.awt.event.KeyEvent.VK_ HELP; break; + + default: + break; + } + + return nRet; + } + + //---------------------------------------------------------------------------------- + + public void fireKeyEvent( java.awt.event.KeyEvent aEvt ) + { + if( maKeyListeners.size() > 0 ) + { + boolean bProcess = false, bPressed = false; + + if( java.awt.event.KeyEvent.KEY_PRESSED == aEvt.getID() ) + { + switch( aEvt.getKeyCode() ) + { + case( java.awt.event.KeyEvent.VK_SHIFT ): mbShift = true; break; + case( java.awt.event.KeyEvent.VK_CONTROL ): mbMod1 = true; break; + case( java.awt.event.KeyEvent.VK_ALT ): mbMod2 = true; break; + + default: + { + bProcess = bPressed = true; + } + break; + } + } + else if( java.awt.event.KeyEvent.KEY_RELEASED == aEvt.getID() ) + { + switch( aEvt.getKeyCode() ) + { + case( java.awt.event.KeyEvent.VK_SHIFT ): mbShift = false; break; + case( java.awt.event.KeyEvent.VK_CONTROL ): mbMod1 = false; break; + case( java.awt.event.KeyEvent.VK_ALT ): mbMod2 = false; break; + + default: + { + bProcess = true; + } + break; + } + } + + if( bProcess ) + { + KeyEvent aUNOEvt = new KeyEvent(); + + aUNOEvt.Modifiers = 0; + + if( mbShift ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.SHIFT; + + if( mbMod1 ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD1; + + if( mbMod2 ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD2; + + aUNOEvt.KeyCode = implGetUNOKeyCode( aEvt.getKeyCode() ); + aUNOEvt.KeyChar = aEvt.getKeyChar(); + aUNOEvt.KeyFunc = com.sun.star.awt.KeyFunction.DONTKNOW; + + ListIterator aIter = maKeyListeners.listIterator( 0 ); + + while( aIter.hasNext() ) + { + if( bPressed ) + ( (XKeyListener) aIter.next() ).keyPressed( aUNOEvt ); + else + ( (XKeyListener) aIter.next() ).keyReleased( aUNOEvt ); + } + } + } + } + + //---------------------------------------------------------------------------------- + + public void fireMouseEvent( java.awt.event.MouseEvent aEvt ) + { + MouseEvent aUNOEvt = new MouseEvent(); + + aUNOEvt.Modifiers = 0; + aUNOEvt.Buttons = 0; + aUNOEvt.X = aEvt.getX(); + aUNOEvt.Y = aEvt.getY(); + aUNOEvt.PopupTrigger = false; + + // Modifiers + if( aEvt.isShiftDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.SHIFT; + + if( aEvt.isControlDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD1; + + if( aEvt.isAltDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD2; + + // Buttons + if( SwingUtilities.isLeftMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.LEFT; + + if( SwingUtilities.isMiddleMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.MIDDLE; + + if( SwingUtilities.isRightMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.RIGHT; + + // event type + if( java.awt.event.MouseEvent.MOUSE_PRESSED == aEvt.getID() ) + { + ListIterator aIter = maMouseListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 1; + + while( aIter.hasNext() ) + ( (XMouseListener) aIter.next() ).mousePressed( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_RELEASED == aEvt.getID() ) + { + ListIterator aIter = maMouseListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 1; + + while( aIter.hasNext() ) + ( (XMouseListener) aIter.next() ).mouseReleased( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_DRAGGED == aEvt.getID() ) + { + ListIterator aIter = maMouseMotionListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 0; + + while( aIter.hasNext() ) + ( (XMouseMotionListener) aIter.next() ).mouseDragged( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_MOVED == aEvt.getID() ) + { + ListIterator aIter = maMouseMotionListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 0; + + while( aIter.hasNext() ) + ( (XMouseMotionListener) aIter.next() ).mouseMoved( aUNOEvt ); + } + } + + //---------------------------------------------------------------------------------- + + public void fireFocusEvent( java.awt.event.FocusEvent aEvt ) + { + if( java.awt.event.FocusEvent.FOCUS_GAINED == aEvt.getID() ) + { + ListIterator aIter = maFocusListeners.listIterator( 0 ); + FocusEvent aUNOEvt = new FocusEvent(); + + while( aIter.hasNext() ) + { + ( (XFocusListener) aIter.next() ).focusGained( aUNOEvt ); + } + } + } + + //---------------------------------------------------------------------------------- + + public void fireDisposingEvent() + { + ListIterator aIter = maEventListeners.listIterator( 0 ); + + while( aIter.hasNext() ) + { + ( (XEventListener) aIter.next() ).disposing( new com.sun.star.lang.EventObject() ); + } + } + + // -------------------- + // - XWindow methods - + // -------------------- + + public void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + maFrame.setBounds( X, Y, Width, Height ); + } + + //---------------------------------------------------------------------------------- + + public com.sun.star.awt.Rectangle getPosSize( ) + { + java.awt.Rectangle bounds = maFrame.getBounds(); + return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + //---------------------------------------------------------------------------------- + + public void setVisible( boolean visible ) + { + maFrame.setVisible( visible ); + } + + //---------------------------------------------------------------------------------- + + public void setEnable( boolean enable ) + { + maFrame.setEnabled( enable ); + } + + //---------------------------------------------------------------------------------- + + public void setFocus() + { + } + + //---------------------------------------------------------------------------------- + + public void addEventListener( XEventListener xListener ) + { + if( xListener != null ) + maEventListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeEventListener( XEventListener xListener ) + { + if( xListener != null ) + maEventListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addWindowListener( XWindowListener xListener ) + { + if( xListener != null ) + maWindowListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeWindowListener( XWindowListener xListener ) + { + if( xListener != null ) + maWindowListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addFocusListener( XFocusListener xListener ) + { + if( xListener != null ) + maFocusListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeFocusListener( XFocusListener xListener ) + { + if( xListener != null ) + maFocusListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addKeyListener( XKeyListener xListener ) + { + if( xListener != null ) + maKeyListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeKeyListener( XKeyListener xListener ) + { + if( xListener != null ) + maKeyListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addMouseListener( XMouseListener xListener ) + { + if( xListener != null ) + maMouseListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeMouseListener( XMouseListener xListener ) + { + if( xListener != null ) + maMouseListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( xListener != null ) + maMouseMotionListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( xListener != null ) + maMouseMotionListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addPaintListener( XPaintListener xListener ) + { + if( xListener != null ) + maPaintListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removePaintListener( XPaintListener xListener ) + { + if( xListener != null ) + maPaintListeners.remove( xListener ); + } +} diff --git a/avmedia/source/java/avmedia.jar b/avmedia/source/java/avmedia.jar Binary files differnew file mode 100644 index 000000000000..85a98bbcf33c --- /dev/null +++ b/avmedia/source/java/avmedia.jar diff --git a/avmedia/source/java/makefile.mk b/avmedia/source/java/makefile.mk new file mode 100644 index 000000000000..37c53a721164 --- /dev/null +++ b/avmedia/source/java/makefile.mk @@ -0,0 +1,61 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************** + +# Builds the Java Canvas implementation. + +PRJNAME = avmedia +PRJ = ..$/.. +TARGET = avmedia +PACKAGE = avmedia + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +.IF "$(GUIBASE)"=="javamedia" + +JAVAFILES = \ + Manager.java \ + Player.java \ + PlayerWindow.java \ + WindowAdapter.java \ + MediaUno.java \ + FrameGrabber.java \ + x11$/SystemWindowAdapter.java + +JARFILES = jurt.jar unoil.jar ridl.jar juh.jar java_uno.jar jmf.jar +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:s/.java//).class) + +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE +CUSTOMMANIFESTFILE = manifest + +.ENDIF # "$(GUIBASE)"=="javamedia" + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk diff --git a/avmedia/source/java/manifest b/avmedia/source/java/manifest new file mode 100644 index 000000000000..fa9c2500d385 --- /dev/null +++ b/avmedia/source/java/manifest @@ -0,0 +1,2 @@ +RegistrationClassName: MediaUno +UNO-Type-Path: diff --git a/avmedia/source/java/win/SystemWindowAdapter.java b/avmedia/source/java/win/SystemWindowAdapter.java new file mode 100644 index 000000000000..ebf3cac99307 --- /dev/null +++ b/avmedia/source/java/win/SystemWindowAdapter.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; + +public class SystemWindowAdapter +{ + static public java.awt.Frame createFrame( int windowHandle ) + { + java.awt.Frame aFrame; + + // we're initialized with the operating system window handle + // as the parameter. We then generate a dummy Java frame with + // that window as the parent, to fake a root window for the + // Java implementation. + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty( "os.name" ); + + // create the embedded frame + if( os.startsWith( "Windows" ) ) + aFrame = new sun.awt.windows.WEmbeddedFrame( windowHandle ); + else + throw new com.sun.star.uno.RuntimeException(); + + return aFrame; + } +} diff --git a/avmedia/source/java/x11/SystemWindowAdapter.java b/avmedia/source/java/x11/SystemWindowAdapter.java new file mode 100644 index 000000000000..4292dabe6775 --- /dev/null +++ b/avmedia/source/java/x11/SystemWindowAdapter.java @@ -0,0 +1,123 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import java.awt.*; +import java.lang.reflect.*; + +public class SystemWindowAdapter +{ + static public java.awt.Frame createFrame( int windowHandle ) + { + String aOS = (String) System.getProperty( "os.name" ); + java.awt.Frame aFrame = null; + + if( aOS.startsWith( "SunOS" ) ) + { + try + { + Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" ); + + if( aClass != null ) + { + try + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class, boolean.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ), + new Boolean( false ) } ); + } + } + catch( Exception e ) + { + } + + if( aFrame == null ) + { + try + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + catch( Exception e ) + { + } + } + } + } + catch( Exception e ) + { + } + } + else + { + try + { + Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" ); + + if( aClass != null ) + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + } + catch( Exception e ) + { + } + + if( aFrame == null ) + { + try + { + Class aClass = Class.forName( "sun.awt.X11.XEmbeddedFrame" ); + + if( aClass != null ) + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + catch( Exception e ) + { + } + } + } + + return aFrame; + } +} diff --git a/avmedia/source/quicktime/framegrabber.cxx b/avmedia/source/quicktime/framegrabber.cxx new file mode 100644 index 000000000000..186820beaec3 --- /dev/null +++ b/avmedia/source/quicktime/framegrabber.cxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "framegrabber.hxx" +#include "player.hxx" + +#include <tools/stream.hxx> +#include <vcl/graph.hxx> +#include <vcl/cvtgrf.hxx> +#include <unotools/localfilehelper.hxx> + +#define AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_Quicktime" +#define AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_Quicktime" + +using namespace ::com::sun::star; + +namespace avmedia { namespace quicktime { + +// ---------------- +// - FrameGrabber - +// ---------------- + +FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{ + OSErr result; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + // check the version of QuickTime installed + result = Gestalt(gestaltQuickTime,&mnVersion); + if ((result == noErr) && (mnVersion >= QT701)) + { + // we have version 7.01 or later, initialize + mpMovie = [QTMovie movie]; + [mpMovie retain]; + mbInitialized = true; + } + [pool release]; +} + +// ------------------------------------------------------------------------------ + +FrameGrabber::~FrameGrabber() +{ + if( mbInitialized ) + { + if( mpMovie ) + { + [mpMovie release]; + mpMovie = nil; + } + } +} + +// ------------------------------------------------------------------------------ + +bool FrameGrabber::create( const ::rtl::OUString& rURL ) +{ + bool bRet = false; + maURL = rURL; + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSString* aNSStr = [[[NSString alloc] initWithCharacters: rURL.getStr() length: rURL.getLength()]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ; + NSURL* aURL = [NSURL URLWithString:aNSStr ]; + + // create the Movie + + mpMovie = [mpMovie initWithURL:aURL error:nil]; + if(mpMovie) + { + [mpMovie retain]; + bRet = true; + } + + [pool release]; + + return( bRet ); +} + +// ------------------------------------------------------------------------------ + +uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime ) + throw (uno::RuntimeException) +{ + uno::Reference< graphic::XGraphic > xRet; + + NSImage* pImage = [mpMovie frameImageAtTime: QTMakeTimeWithTimeInterval(fMediaTime)]; + NSData *pBitmap = [pImage TIFFRepresentation]; + long nSize = [pBitmap length]; + const void* pBitmapData = [pBitmap bytes]; + SvMemoryStream aMemStm( (char *)pBitmapData, nSize, STREAM_READ | STREAM_WRITE ); + Graphic aGraphic; + if ( GraphicConverter::Import( aMemStm, aGraphic, CVT_TIF ) == ERRCODE_NONE ) + { + xRet = aGraphic.GetXGraphic(); + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_QUICKTIME_FRAMEGRABBER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_QUICKTIME_FRAMEGRABBER_SERVICENAME ) ); + + return aRet; +} + +} // namespace quicktime +} // namespace avmedia diff --git a/avmedia/source/quicktime/framegrabber.hxx b/avmedia/source/quicktime/framegrabber.hxx new file mode 100644 index 000000000000..a5b004e0383e --- /dev/null +++ b/avmedia/source/quicktime/framegrabber.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _FRAMEGRABBER_HXX +#define _FRAMEGRABBER_HXX + +#include "quicktimecommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XFRAMEGRABBER_HDL_ +#include "com/sun/star/media/XFrameGrabber.hdl" +#endif + +namespace avmedia { namespace quicktime { + +// ---------------- +// - FrameGrabber - +// ---------------- + +class FrameGrabber : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XFrameGrabber, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + FrameGrabber( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~FrameGrabber(); + + bool create( const ::rtl::OUString& rURL ); + + // XFrameGrabber + virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + ::rtl::OUString maURL; + QTMovie* mpMovie; + sal_Bool mbInitialized; + long mnVersion; +}; + +} // namespace quicktime +} // namespace avmedia + +#endif // _FRAMEGRABBER_HXX diff --git a/avmedia/source/quicktime/makefile.mk b/avmedia/source/quicktime/makefile.mk new file mode 100644 index 000000000000..f3c9f244f357 --- /dev/null +++ b/avmedia/source/quicktime/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmedia +TARGET=avmediaQuickTime + +.IF "$(GUIBASE)"=="aqua" + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +# --- Files ---------------------------------- + +CFLAGSCXX+=$(OBJCXXFLAGS) + +SLOFILES= \ + $(SLO)$/quicktimeuno.obj \ + $(SLO)$/manager.obj \ + $(SLO)$/window.obj \ + $(SLO)$/framegrabber.obj \ + $(SLO)$/player.obj + +EXCEPTIONSFILES= \ + $(SLO)$/quicktimeuno.obj + +SHL1TARGET= $(TARGET)$(DLLPOSTFIX) + +SHL1STDLIBS= \ + $(CPPULIB) \ + $(SALLIB) \ + $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(TOOLSLIB) \ + $(VCLLIB) + +SHL1STDLIBS+= \ + -framework Cocoa \ + -framework QTKit \ + -framework QuickTime + +# build DLL +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1IMPLIB=i$(TARGET) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +SHL1VERSIONMAP=$(SOLARENV)/src/component.map + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.ELSE +dummy: + @echo " Nothing to build for GUIBASE=$(GUIBASE)" +.ENDIF diff --git a/avmedia/source/quicktime/manager.cxx b/avmedia/source/quicktime/manager.cxx new file mode 100644 index 000000000000..4970864c7e76 --- /dev/null +++ b/avmedia/source/quicktime/manager.cxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "manager.hxx" +#include "player.hxx" +#include <tools/urlobj.hxx> + +using namespace ::com::sun::star; + +namespace avmedia { namespace quicktime { +// ---------------- +// - Manager - +// ---------------- + +Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{ + OSL_TRACE( "avmediaquicktime: Manager::Manager" ); +} + +// ------------------------------------------------------------------------------ + +Manager::~Manager() +{ +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const ::rtl::OUString& rURL ) + throw (uno::RuntimeException) +{ + Player* pPlayer( new Player( mxMgr ) ); + uno::Reference< media::XPlayer > xRet( pPlayer ); + INetURLObject aURL( rURL ); + + OSL_TRACE( "avmediaquicktime: Manager::createPlayer" ); + + if( !pPlayer->create( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) ) + xRet = uno::Reference< media::XPlayer >(); + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Manager::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_QUICKTIME_MANAGER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Manager::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_QUICKTIME_MANAGER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Manager::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_QUICKTIME_MANAGER_SERVICENAME ) ); + + return aRet; +} + +} // namespace quicktime +} // namespace avmedia diff --git a/avmedia/source/quicktime/manager.hxx b/avmedia/source/quicktime/manager.hxx new file mode 100644 index 000000000000..07740a1a9259 --- /dev/null +++ b/avmedia/source/quicktime/manager.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANAGER_HXX +#define _MANAGER_HXX + +#include "quicktimecommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XMANAGER_HDL_ +#include "com/sun/star/media/XManager.hdl" +#endif + +// ----------- +// - Manager - +// ----------- + +namespace avmedia { namespace quicktime { + +class Manager : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XManager, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Manager(); + + // XManager + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > SAL_CALL createPlayer( const ::rtl::OUString& aURL ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; +}; + +} // namespace quicktime +} // namespace avmedia + +#endif // _MANAGER_HXX diff --git a/avmedia/source/quicktime/player.cxx b/avmedia/source/quicktime/player.cxx new file mode 100644 index 000000000000..6c77f999e110 --- /dev/null +++ b/avmedia/source/quicktime/player.cxx @@ -0,0 +1,501 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <math.h> + +#include "player.hxx" +#include "framegrabber.hxx" +#include "window.hxx" + +// dbg_dump for development +#if OSL_DEBUG_LEVEL > 1 +#include <rtl/strbuf.hxx> +#include <rtl/ustring.hxx> + +const sal_Char *dbg_dump(const rtl::OString &rStr) +{ + static rtl::OStringBuffer aStr; + + aStr = rtl::OStringBuffer(rStr); + aStr.append(static_cast<char>(0)); + return aStr.getStr(); +} + +const sal_Char *dbg_dump(const rtl::OUString &rStr) +{ + return dbg_dump(rtl::OUStringToOString(rStr, RTL_TEXTENCODING_UTF8)); +} + +const sal_Char *dbg_dump(rtl_String *pStr) +{ + return dbg_dump(rtl::OString(pStr)); +} + +const sal_Char *dbg_dump(rtl_uString *pStr) +{ + return dbg_dump(rtl::OUString(pStr)); +} + +#endif + +using namespace ::com::sun::star; + +namespace avmedia { namespace quicktime { + +// ---------------- +// - Player - +// ---------------- + +Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ), + mpMovie( nil ), + /* GST + mbFakeVideo (sal_False ), + */ + mnUnmutedVolume( 0 ), + mnStopTime( DBL_MAX ), //max double + mbMuted( false ), + mbLooping( false ), + mbInitialized( false ), + mnWindowID( 0 ), + mnDuration( 0 ), + mnWidth( 0 ), + mnHeight( 0 ), + mnVersion( 0 ), + maSizeCondition( osl_createCondition() ) +{ + OSErr result; + + NSApplicationLoad(); + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + // check the version of QuickTime installed + result = Gestalt(gestaltQuickTime,&mnVersion); + if ((result == noErr) && (mnVersion >= QT701)) + { + // we have version 7.01 or later, initialize + mbInitialized = true; + } + [pool release]; +} + +// ------------------------------------------------------------------------------ + +Player::~Player() +{ + if( mpMovie ) + { + [mpMovie release]; + mpMovie = nil; + } +} +// ------------------------------------------------------------------------------ + +QTMovie* Player::getMovie() +{ + OSL_ASSERT( mpMovie ); + return mpMovie; +} + +// ------------------------------------------------------------------------------ + +bool Player::create( const ::rtl::OUString& rURL ) +{ + bool bRet = false; + // create the Movie + if( mbInitialized ) + { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + if( mpMovie ) + { + [mpMovie release]; + mpMovie = nil; + } + + NSString* aNSStr = [[[NSString alloc] initWithCharacters: rURL.getStr() length: rURL.getLength()]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ; + NSURL* aURL = [NSURL URLWithString:aNSStr ]; + + + NSError* pErr = nil; + mpMovie = [QTMovie movieWithURL:aURL error:&pErr]; + if(mpMovie) + { + [mpMovie retain]; + maURL = rURL; + bRet = true; + } + if( pErr ) + { + OSL_TRACE( "NSMovie create failed with error %ld (%s)", + (long)[pErr code], + [[pErr localizedDescription] cString] + ); + } + [pool release]; + } + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::start( ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::start"); + + if( mpMovie ) + { + [mpMovie play]; + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::stop( ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::stop"); + if( mpMovie ) + { + [mpMovie stop]; + } +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaying() + throw (uno::RuntimeException) +{ + bool bRet = false; + + if ( mpMovie ) + { + if ([mpMovie rate] != 0) + { + bRet = true; + } + } + + return bRet; +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getDuration( ) + throw (uno::RuntimeException) +{ + // slideshow checks for non-zero duration, so cheat here + double duration = 0.01; + + if ( mpMovie ) // && mnDuration > 0 ) { + { + QTTime structDuration = [mpMovie duration] ; + duration = (double)structDuration.timeValue / (double)structDuration.timeScale; + } + + return duration; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMediaTime( double fTime ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::setMediaTime"); + + if ( mpMovie ) + { + [mpMovie setCurrentTime: QTMakeTimeWithTimeInterval(fTime)]; + } +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getMediaTime( ) + throw (uno::RuntimeException) +{ + double position = 0.0; + + if ( mpMovie ) + { + QTTime structDuration = [mpMovie currentTime] ; + position = (double)structDuration.timeValue / (double)structDuration.timeScale; + } + + if(isPlaying() && position>mnStopTime) + { + stop(); + } + + return position; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setStopTime( double fTime ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::setStopTime %f", fTime); + + mnStopTime = fTime; +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getStopTime( ) + throw (uno::RuntimeException) +{ + double fRet = mnStopTime; + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setRate( double fRate ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::setRate"); + + // Quicktime: 0 = stop, 1 = normal speed, 2 = double speed, -1 = normal speed backwards + if ( mpMovie ) + { + [mpMovie setRate: fRate]; + } +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getRate( ) + throw (uno::RuntimeException) +{ + // Quicktime: 0 = stop, 1 = normal speed, 2 = double speed, -1 = normal speed backwards + double rate = 1.0; + + OSL_TRACE ("Player::getRate"); + + if ( mpMovie ) + { + rate = (double) [mpMovie rate]; + } + + return rate; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::setPlaybackLoop? %s", bSet?"True":"False" ); + + if(bSet) + { + [mpMovie setAttribute:[NSNumber numberWithBool:YES] forKey: QTMovieLoopsAttribute] ; + } + else + { + [mpMovie setAttribute:[NSNumber numberWithBool:NO] forKey: QTMovieLoopsAttribute] ; + } +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaybackLoop( ) + throw (uno::RuntimeException) +{ + bool bRet = [[mpMovie attributeForKey:QTMovieLoopsAttribute] boolValue]; + + OSL_TRACE ("Player::isPlaybackLoop ? %s", bRet?"True":"False" ); + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMute( sal_Bool bSet ) + throw (uno::RuntimeException) +{ + OSL_TRACE( "set mute: %d muted: %d unmuted volume: %lf", bSet, mbMuted, mnUnmutedVolume ); + + // change the volume to 0 or the unmuted volume + if( mpMovie && mbMuted != bSet ) + { + [mpMovie setMuted: bSet ]; + mbMuted = bSet; + } + +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isMute( ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Player::isMuted"); + + return mbMuted; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) + throw (uno::RuntimeException) +{ + // OOo db volume -40 = QTVolume 0 + // OOo db volume 0 = QTvolume 1 + if(nVolumeDB==-40) + { + mnUnmutedVolume = 0; + } + else + { + mnUnmutedVolume = pow( 10.0, nVolumeDB / 20.0 ); + } + + OSL_TRACE( "set volume: %d gst volume: %f", nVolumeDB, mnUnmutedVolume ); + + // change volume + if( !mbMuted && mpMovie ) + { + [mpMovie setVolume: mnUnmutedVolume ]; + } +} + +// ------------------------------------------------------------------------------ + +sal_Int16 SAL_CALL Player::getVolumeDB( ) + throw (uno::RuntimeException) +{ + sal_Int16 nVolumeDB = 0.0; + + if( mpMovie ) + { + float volume = 0.0; + + volume = [mpMovie volume]; + if(volume>0) //protect from log10(0) + { + nVolumeDB = (sal_Int16) ( 20.0*log10 ( volume ) ); + } + else + { + nVolumeDB = -40 ; // QT zero volume is no volume, -40db + } + } + + return nVolumeDB; +} + +// ------------------------------------------------------------------------------ + +awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( ) + throw (uno::RuntimeException) +{ + NSSize nsSize = [[mpMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; + awt::Size aSize( nsSize.width, nsSize.height ); + return aSize; +} + + +// ------------------------------------------------------------------------------ + +uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments ) + throw (uno::RuntimeException) +{ + uno::Reference< ::media::XPlayerWindow > xRet; + awt::Size aSize( getPreferredPlayerWindowSize() ); + NSSize nsSize( NSMakeSize(aSize.Width, aSize.Height) ); + + OSL_TRACE( "Player::createPlayerWindow %d %d length: %d", aSize.Width, aSize.Height, aArguments.getLength() ); + + if( aSize.Width > 0 && aSize.Height > 0 ) + { + sal_IntPtr nPtr = NULL; + aArguments[0] >>= nPtr; + NSView* pParentView = reinterpret_cast< NSView * >(nPtr); + + ::avmedia::quicktime::Window* pWindow = new ::avmedia::quicktime::Window( mxMgr, *this, pParentView ); + xRet = pWindow; + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber( ) + throw (::com::sun::star::uno::RuntimeException) +{ + uno::Reference< media::XFrameGrabber > xRet; + OSL_TRACE ("Player::createFrameGrabber"); + + if( maURL.getLength() > 0 ) + { + FrameGrabber* pGrabber = new FrameGrabber( mxMgr ); + + xRet = pGrabber; + + if( !pGrabber->create( maURL ) ) + { + xRet.clear(); + } + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Player::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_QUICKTIME_PLAYER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_QUICKTIME_PLAYER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Player::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_QUICKTIME_PLAYER_SERVICENAME ) ); + + return aRet; +} + +} // namespace quicktime +} // namespace avmedia diff --git a/avmedia/source/quicktime/player.hxx b/avmedia/source/quicktime/player.hxx new file mode 100644 index 000000000000..e85bbc5035db --- /dev/null +++ b/avmedia/source/quicktime/player.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _PLAYER_HXX +#define _PLAYER_HXX + +#include <osl/conditn.h> +#include "quicktimecommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYER_HDL_ +#include "com/sun/star/media/XPlayer.hdl" +#endif + +namespace avmedia { namespace quicktime { + +/* +// ---------- +// - Player - +// ---------- +*/ + +class Player : public ::cppu::WeakImplHelper2< ::com::sun::star::media::XPlayer, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Player( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Player(); + + bool create( const ::rtl::OUString& rURL ); + +// void processMessage( GstMessage *message ); + + // XPlayer + virtual void SAL_CALL start( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL stop( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaying( ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getDuration( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMediaTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getMediaTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setStopTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getStopTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRate( double fRate ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getRate( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaybackLoop( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMute( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isMute( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getVolumeDB( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber( ) throw (::com::sun::star::uno::RuntimeException); + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + + QTMovie* getMovie(); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + + ::rtl::OUString maURL; + + QTMovie *mpMovie; // the Movie object + /* GST + sal_Bool mbFakeVideo; + */ + float mnUnmutedVolume; + double mnStopTime; + + sal_Bool mbMuted; + sal_Bool mbLooping; + sal_Bool mbInitialized; + + long mnWindowID; + long mnDuration; + int mnWidth; + int mnHeight; + + long mnVersion; + oslCondition maSizeCondition; +}; + +} // namespace quicktime +} // namespace avmedia + +#endif // _PLAYER_HXX diff --git a/avmedia/source/quicktime/quicktimecommon.hxx b/avmedia/source/quicktime/quicktimecommon.hxx new file mode 100644 index 000000000000..82ade238396c --- /dev/null +++ b/avmedia/source/quicktime/quicktimecommon.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _QUICKTIMECOMMON_HXX +#define _QUICKTIMECOMMON_HXX + +#ifdef MACOSX +#include <premac.h> +#import <Cocoa/Cocoa.h> +#import <QTKit/QTKit.h> +#import <QuickTime/QuickTime.h> +#include <postmac.h> +#endif +#include <osl/mutex.hxx> +#ifndef __RTL_USTRING_ +#include <rtl/ustring.hxx> +#endif +#include <tools/debug.hxx> +#include <tools/stream.hxx> +#include <tools/string.hxx> +#include <tools/urlobj.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/media/XManager.hpp> + +#define AVMEDIA_QUICKTIME_MANAGER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Manager_QuickTime" +#define AVMEDIA_QUICKTIME_MANAGER_SERVICENAME "com.sun.star.media.Manager_QuickTime" + +#define AVMEDIA_QUICKTIME_PLAYER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Player_QuickTime" +#define AVMEDIA_QUICKTIME_PLAYER_SERVICENAME "com.sun.star.media.Player_QuickTime" + +#define AVMEDIA_QUICKTIME_WINDOW_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Window_QuickTime" +#define AVMEDIA_QUICKTIME_WINDOW_SERVICENAME "com.sun.star.media.Window_QuickTime" + +#define WM_GRAPHNOTIFY (WM_USER + 567) + +// Quicktime 7+ in Mac OS X 10.4 +#define QT701 0x07010000 + +// Quicktime 6.4+ in Mac OS X 10.3 +#define QT64 0x06400000 + + +#endif // _QUICKTIMECOMMOM_HXX diff --git a/avmedia/source/quicktime/quicktimeuno.cxx b/avmedia/source/quicktime/quicktimeuno.cxx new file mode 100644 index 000000000000..b2dee4d77838 --- /dev/null +++ b/avmedia/source/quicktime/quicktimeuno.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "quicktimecommon.hxx" +#include "manager.hxx" + +using namespace ::com::sun::star; + +// ------------------- +// - factory methods - +// ------------------- + +static uno::Reference< uno::XInterface > SAL_CALL create_MediaPlayer( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) +{ + return uno::Reference< uno::XInterface >( *new ::avmedia::quicktime::Manager( rxFact ) ); +} + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* /* pServiceManager */, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + uno::Reference< registry::XRegistryKey > xNewKey1( + static_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( + ::rtl::OUString::createFromAscii( + "/" AVMEDIA_QUICKTIME_MANAGER_IMPLEMENTATIONNAME "/UNO/SERVICES/" + AVMEDIA_QUICKTIME_MANAGER_SERVICENAME ) ) ); + + bRet = sal_True; + } + catch( registry::InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ ) +{ + uno::Reference< lang::XSingleServiceFactory > xFactory; + void* pRet = 0; + + if( rtl_str_compare( pImplName, AVMEDIA_QUICKTIME_MANAGER_IMPLEMENTATIONNAME ) == 0 ) + { + const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( AVMEDIA_QUICKTIME_MANAGER_SERVICENAME ) ); + + xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory( + reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), + ::rtl::OUString::createFromAscii( AVMEDIA_QUICKTIME_MANAGER_IMPLEMENTATIONNAME ), + create_MediaPlayer, uno::Sequence< ::rtl::OUString >( &aServiceName, 1 ) ) ); + } + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} diff --git a/avmedia/source/quicktime/window.cxx b/avmedia/source/quicktime/window.cxx new file mode 100644 index 000000000000..e44acf4fbb67 --- /dev/null +++ b/avmedia/source/quicktime/window.cxx @@ -0,0 +1,353 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/awt/SystemPointer.hpp> +#include <com/sun/star/awt/PosSize.hpp> + +#include "window.hxx" +#include "player.hxx" + +using namespace ::com::sun::star; + +namespace avmedia { namespace quicktime { + +// ----------- +// - statics - +// ----------- + +static ::osl::Mutex& ImplGetOwnStaticMutex() +{ + static ::osl::Mutex* pMutex = NULL; + + if( pMutex == NULL ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + + if( pMutex == NULL ) + { + static ::osl::Mutex aMutex; + pMutex = &aMutex; + } + } + + return *pMutex; +} + +// --------------- +// - Window - +// --------------- + +// ------------------------------------------------------------------------------ + +Window::Window( const uno::Reference< lang::XMultiServiceFactory >& i_rxMgr, Player& i_rPlayer, NSView* i_pParentView ) : + mxMgr( i_rxMgr ), + maListeners( maMutex ), + meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ), + mrPlayer( i_rPlayer ), + mnPointerType( awt::SystemPointer::ARROW ), + mpParentView( i_pParentView ), + mpMovieView( nil ) +{ + + ::osl::MutexGuard aGuard( ImplGetOwnStaticMutex() ); + + + if( mpParentView ) // sanity check + { + + NSRect aViewRect = [mpParentView frame]; + aViewRect.origin.x = aViewRect.origin.y = 0; + mpMovieView = [[QTMovieView alloc] initWithFrame: aViewRect]; + [mpMovieView setMovie: mrPlayer.getMovie() ]; + [mpMovieView setControllerVisible: NO]; + [mpMovieView setPreservesAspectRatio: YES]; + [mpMovieView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [mpParentView addSubview: mpMovieView]; + [mpParentView setAutoresizesSubviews: YES]; + } + + OSL_TRACE ("Window::Window"); +} + +// ------------------------------------------------------------------------------ + +Window::~Window() +{ + if( mpMovieView ) + { + [mpMovieView removeFromSuperview]; + [mpMovieView setMovie:nil]; + [mpMovieView release]; + mpMovieView = nil; + } +} + +bool Window::create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) +{ + return true; +} + +// XPlayerWindow +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::update( ) + throw (uno::RuntimeException) +{ + ; +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) + throw (uno::RuntimeException) +{ + return false; +} + +// ------------------------------------------------------------------------------ + +media::ZoomLevel SAL_CALL Window::getZoomLevel( ) + throw (uno::RuntimeException) +{ + return meZoomLevel; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) + throw (uno::RuntimeException) +{ + mnPointerType = nPointerType; +} + +// XWindow +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) + throw (uno::RuntimeException) +{ + if( mpParentView && mpMovieView ) + { + NSRect aRect = [mpMovieView frame]; + if( (Flags & awt::PosSize::WIDTH) ) + aRect.size.width = Width; + if( (Flags & awt::PosSize::HEIGHT) ) + aRect.size.height = Height; + } +} + +// ------------------------------------------------------------------------------ + +awt::Rectangle SAL_CALL Window::getPosSize() + throw (uno::RuntimeException) +{ + awt::Rectangle aRet; + + NSRect aRect = [mpMovieView frame]; + aRet.X = aRet.Y = 0; + aRet.Width = aRect.size.width; + aRet.Height = aRect.size.height; + + return aRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setVisible( sal_Bool bVisible ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Window::setVisible"); + +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setEnable( sal_Bool bEnable ) + throw (uno::RuntimeException) +{ + ; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setFocus( ) + throw (uno::RuntimeException) +{ + OSL_TRACE ("Window::setFocus"); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + + +// XComponent +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::dispose( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// XServiceInfo +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Window::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_QUICKTIME_WINDOW_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_QUICKTIME_WINDOW_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_QUICKTIME_WINDOW_SERVICENAME ) ); + + return aRet; +} + +} // namespace quicktime +} // namespace avmedia diff --git a/avmedia/source/quicktime/window.hxx b/avmedia/source/quicktime/window.hxx new file mode 100644 index 000000000000..4ca2e76ddc52 --- /dev/null +++ b/avmedia/source/quicktime/window.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WINDOW_HXX +#define _WINDOW_HXX + +#include "quicktimecommon.hxx" +#include <cppuhelper/interfacecontainer.h> + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYERWINDOW_HDL_ +#include "com/sun/star/media/XPlayerWindow.hdl" +#endif + +namespace avmedia { namespace quicktime { + +// --------------- +// - Window - +// --------------- + +class Player; + +class Window : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XPlayerWindow, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Window( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_rxMgr, + Player& i_rPlayer, + NSView* i_pParentView + ); + ~Window(); + + bool create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + void processGraphEvent(); + void updatePointer(); + + // XPlayerWindow + virtual void SAL_CALL update( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL setZoomLevel( ::com::sun::star::media::ZoomLevel ZoomLevel ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::media::ZoomLevel SAL_CALL getZoomLevel( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPointerType( sal_Int32 nPointerType ) throw (::com::sun::star::uno::RuntimeException); + + // XWindow + virtual void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool Visible ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setEnable( sal_Bool Enable ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setFocus( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + + ::osl::Mutex maMutex; + ::cppu::OMultiTypeInterfaceContainerHelper maListeners; + ::com::sun::star::media::ZoomLevel meZoomLevel; + Player& mrPlayer; + int mnPointerType; + + NSView* mpParentView; // parent view for our own private movie view + QTMovieView* mpMovieView; // the view containing the movie object, output target and controller + + void ImplLayoutVideoWindow(); +}; + +} // namespace quicktime +} // namespace avmedia + +#endif // _WINDOW_HXX diff --git a/avmedia/source/viewer/makefile.mk b/avmedia/source/viewer/makefile.mk new file mode 100644 index 000000000000..8d5d6a5df52d --- /dev/null +++ b/avmedia/source/viewer/makefile.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmedia +TARGET=viewer + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Resources --------------------------------- + +SRS1NAME=$(TARGET) +SRC1FILES =\ + mediawindow.src + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/mediaevent_impl.obj \ + $(SLO)$/mediawindowbase_impl.obj \ + $(SLO)$/mediawindow_impl.obj \ + $(SLO)$/mediawindow.obj + +EXCEPTIONSFILES= \ + $(SLO)$/mediawindow.obj \ + $(SLO)$/mediawindowbase_impl.obj \ + $(SLO)$/mediawindow_impl.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/avmedia/source/viewer/mediaevent_impl.cxx b/avmedia/source/viewer/mediaevent_impl.cxx new file mode 100644 index 000000000000..cf86f54df8f9 --- /dev/null +++ b/avmedia/source/viewer/mediaevent_impl.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediaevent_impl.hxx" +#include "mediawindow_impl.hxx" +#include <osl/mutex.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <vcl/event.hxx> + +using namespace ::com::sun::star; + +/* Definition of MediaWindowImpl class */ + +namespace avmedia { namespace priv { +// --------------------------- +// - MediaEventListenersImpl - +// --------------------------- + +MediaEventListenersImpl::MediaEventListenersImpl( Window& rEventWindow ) : + mpNotifyWindow( &rEventWindow ) +{ +} + +// --------------------------------------------------------------------- + +MediaEventListenersImpl::~MediaEventListenersImpl() +{ +} + +// --------------------------------------------------------------------- + +void MediaEventListenersImpl::cleanUp() +{ + Application::RemoveMouseAndKeyEvents( reinterpret_cast< ::Window* >( mpNotifyWindow ) ); + mpNotifyWindow = NULL; +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::disposing( const ::com::sun::star::lang::EventObject& /* Source */ ) + throw (::com::sun::star::uno::RuntimeException) +{ +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::keyPressed( const ::com::sun::star::awt::KeyEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + KeyCode aVCLKeyCode( e.KeyCode, + ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) | + ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) | + ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) ); + KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode ); + + Application::PostKeyEvent( VCLEVENT_WINDOW_KEYINPUT, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt ); + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::keyReleased( const ::com::sun::star::awt::KeyEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + KeyCode aVCLKeyCode( e.KeyCode, + ( ( e.Modifiers & 1 ) ? KEY_SHIFT : 0 ) | + ( ( e.Modifiers & 2 ) ? KEY_MOD1 : 0 ) | + ( ( e.Modifiers & 4 ) ? KEY_MOD2 : 0 ) ); + KeyEvent aVCLKeyEvt( e.KeyChar, aVCLKeyCode ); + Application::PostKeyEvent( VCLEVENT_WINDOW_KEYUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLKeyEvt ); + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::mousePressed( const ::com::sun::star::awt::MouseEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), + sal::static_int_cast< USHORT >(e.ClickCount), + 0, + ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) | + ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) | + ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ), + e.Modifiers ); + Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt ); + } +} + +// ----------------------------------------------gvd----------------------- + +void SAL_CALL MediaEventListenersImpl::mouseReleased( const ::com::sun::star::awt::MouseEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), + sal::static_int_cast< USHORT >(e.ClickCount), + 0, + ( ( e.Buttons & 1 ) ? MOUSE_LEFT : 0 ) | + ( ( e.Buttons & 2 ) ? MOUSE_RIGHT : 0 ) | + ( ( e.Buttons & 4 ) ? MOUSE_MIDDLE : 0 ), + e.Modifiers ); + Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONUP, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt ); + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::mouseEntered( const ::com::sun::star::awt::MouseEvent& /* e */ ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::mouseExited( const ::com::sun::star::awt::MouseEvent& /* e */ ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::mouseDragged( const ::com::sun::star::awt::MouseEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers ); + Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt ); + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::mouseMoved( const ::com::sun::star::awt::MouseEvent& e ) + throw (::com::sun::star::uno::RuntimeException) +{ + const ::osl::MutexGuard aGuard( maMutex ); + const ::vos::OGuard aAppGuard( Application::GetSolarMutex() ); + + if( mpNotifyWindow ) + { + MouseEvent aVCLMouseEvt( Point( e.X, e.Y ), 0, 0, e.Buttons, e.Modifiers ); + Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, reinterpret_cast< ::Window* >( mpNotifyWindow ), &aVCLMouseEvt ); + } +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::focusGained( const ::com::sun::star::awt::FocusEvent& /* e */ ) + throw (::com::sun::star::uno::RuntimeException) +{ +} + +// --------------------------------------------------------------------- + +void SAL_CALL MediaEventListenersImpl::focusLost( const ::com::sun::star::awt::FocusEvent& /* e */ ) + throw (::com::sun::star::uno::RuntimeException) +{ +} + +} // namespace priv +} // namespace avemdia + diff --git a/avmedia/source/viewer/mediaevent_impl.hxx b/avmedia/source/viewer/mediaevent_impl.hxx new file mode 100644 index 000000000000..b06ccd885fd6 --- /dev/null +++ b/avmedia/source/viewer/mediaevent_impl.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _AVMEDIA_MEDIAEVENT_IMPL_HXX +#define _AVMEDIA_MEDIAEVENT_IMPL_HXX + +#include <avmedia/mediawindow.hxx> +#include <cppuhelper/compbase4.hxx> +#include <com/sun/star/awt/XKeyListener.hpp> +#include <com/sun/star/awt/XMouseListener.hpp> +#include <com/sun/star/awt/XMouseMotionListener.hpp> +#include <com/sun/star/awt/XFocusListener.hpp> + +namespace avmedia +{ + namespace priv + { + // --------------------------- + // - MediaEventListenersImpl - + // --------------------------- + + class MediaWindowImpl; + + class MediaEventListenersImpl : public ::cppu::WeakImplHelper4< ::com::sun::star::awt::XKeyListener, + ::com::sun::star::awt::XMouseListener, + ::com::sun::star::awt::XMouseMotionListener, + ::com::sun::star::awt::XFocusListener > + { + public: + + MediaEventListenersImpl( Window& rNotifyWindow ); + ~MediaEventListenersImpl(); + + void cleanUp(); + + protected: + + // XKeyListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL keyPressed( const ::com::sun::star::awt::KeyEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL keyReleased( const ::com::sun::star::awt::KeyEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + // XMouseListener + virtual void SAL_CALL mousePressed( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL mouseReleased( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL mouseEntered( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL mouseExited( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + // XMouseMotionListener + virtual void SAL_CALL mouseDragged( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL mouseMoved( const ::com::sun::star::awt::MouseEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + // XFocusListener + virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + private: + + Window* mpNotifyWindow; + mutable ::osl::Mutex maMutex; + }; + } +} + +#endif diff --git a/avmedia/source/viewer/mediawindow.cxx b/avmedia/source/viewer/mediawindow.cxx new file mode 100644 index 000000000000..5005446633f4 --- /dev/null +++ b/avmedia/source/viewer/mediawindow.cxx @@ -0,0 +1,573 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <stdio.h> + +#include <avmedia/mediawindow.hxx> +#include "mediawindow_impl.hxx" +#include "mediamisc.hxx" +#include "mediawindow.hrc" +#include <tools/urlobj.hxx> +#include <vcl/msgbox.hxx> +#include <unotools/pathoptions.hxx> +#include <sfx2/filedlghelper.hxx> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/media/XManager.hpp> +#include "com/sun/star/ui/dialogs/TemplateDescription.hpp" + +#define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME 3.0 + +using namespace ::com::sun::star; + +namespace avmedia { + +// --------------- +// - MediaWindow - +// --------------- + +MediaWindow::MediaWindow( Window* parent, bool bInternalMediaControl ) : + mpImpl( new priv::MediaWindowImpl( parent, this, bInternalMediaControl ) ) +{ + mpImpl->Show(); +} + +// ------------------------------------------------------------------------- + +MediaWindow::~MediaWindow() +{ + mpImpl->cleanUp(); + delete mpImpl; + mpImpl = NULL; +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setURL( const ::rtl::OUString& rURL ) +{ + if( mpImpl ) + mpImpl->setURL( rURL ); +} + +// ------------------------------------------------------------------------- + +const ::rtl::OUString& MediaWindow::getURL() const +{ + return mpImpl->getURL(); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::isValid() const +{ + return( mpImpl != NULL && mpImpl->isValid() ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::MouseMove( const MouseEvent& /* rMEvt */ ) +{ +} + +// --------------------------------------------------------------------- + +void MediaWindow::MouseButtonDown( const MouseEvent& /* rMEvt */ ) +{ +} + +// --------------------------------------------------------------------- + +void MediaWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ ) +{ +} + +// ------------------------------------------------------------------------- + +void MediaWindow::KeyInput( const KeyEvent& /* rKEvt */ ) +{ +} + +// ------------------------------------------------------------------------- + +void MediaWindow::KeyUp( const KeyEvent& /* rKEvt */ ) +{ +} + +// ------------------------------------------------------------------------- + +void MediaWindow::Command( const CommandEvent& /* rCEvt */ ) +{ +} + +// ------------------------------------------------------------------------- + +sal_Int8 MediaWindow::AcceptDrop( const AcceptDropEvent& /* rEvt */ ) +{ + return 0; +} + +// ------------------------------------------------------------------------- + +sal_Int8 MediaWindow::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ ) +{ + return 0; +} + +// ------------------------------------------------------------------------- + +void MediaWindow::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ ) +{ +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::hasPreferredSize() const +{ + return( mpImpl != NULL && mpImpl->hasPreferredSize() ); +} + +// ------------------------------------------------------------------------- + +Size MediaWindow::getPreferredSize() const +{ + return mpImpl->getPreferredSize(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setPosSize( const Rectangle& rNewRect ) +{ + if( mpImpl ) + { + mpImpl->setPosSize( rNewRect ); + } +} + +// ------------------------------------------------------------------------- + +Rectangle MediaWindow::getPosSize() const +{ + return Rectangle( mpImpl->GetPosPixel(), mpImpl->GetSizePixel() ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setPointer( const Pointer& rPointer ) +{ + if( mpImpl ) + mpImpl->setPointer( rPointer ); +} + +// ------------------------------------------------------------------------- + +const Pointer& MediaWindow::getPointer() const +{ + return mpImpl->getPointer(); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::setZoom( ::com::sun::star::media::ZoomLevel eLevel ) +{ + return( mpImpl != NULL && mpImpl->setZoom( eLevel ) ); +} + +// ------------------------------------------------------------------------- + +::com::sun::star::media::ZoomLevel MediaWindow::getZoom() const +{ + return mpImpl->getZoom(); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::start() +{ + return( mpImpl != NULL && mpImpl->start() ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::stop() +{ + if( mpImpl ) + mpImpl->stop(); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::isPlaying() const +{ + return( mpImpl != NULL && mpImpl->isPlaying() ); +} + +// ------------------------------------------------------------------------- + +double MediaWindow::getDuration() const +{ + return mpImpl->getDuration(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setMediaTime( double fTime ) +{ + if( mpImpl ) + mpImpl->setMediaTime( fTime ); +} + +// ------------------------------------------------------------------------- + +double MediaWindow::getMediaTime() const +{ + return mpImpl->getMediaTime(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setStopTime( double fTime ) +{ + if( mpImpl ) + mpImpl->setStopTime( fTime ); +} + +// ------------------------------------------------------------------------- + +double MediaWindow::getStopTime() const +{ + return mpImpl->getStopTime(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setRate( double fRate ) +{ + if( mpImpl ) + mpImpl->setRate( fRate ); +} + +// ------------------------------------------------------------------------- + +double MediaWindow::getRate() const +{ + return mpImpl->getRate(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setPlaybackLoop( bool bSet ) +{ + if( mpImpl ) + mpImpl->setPlaybackLoop( bSet ); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::isPlaybackLoop() const +{ + return mpImpl->isPlaybackLoop(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::setMute( bool bSet ) +{ + if( mpImpl ) + mpImpl->setMute( bSet ); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::isMute() const +{ + return mpImpl->isMute(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::updateMediaItem( MediaItem& rItem ) const +{ + if( mpImpl ) + mpImpl->updateMediaItem( rItem ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::executeMediaItem( const MediaItem& rItem ) +{ + if( mpImpl ) + mpImpl->executeMediaItem( rItem ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::show() +{ + if( mpImpl ) + mpImpl->Show(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::hide() +{ + if( mpImpl ) + mpImpl->Hide(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::enable() +{ + if( mpImpl ) + mpImpl->Enable(); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::disable() +{ + if( mpImpl ) + mpImpl->Disable(); +} + +// ------------------------------------------------------------------------- + +Window* MediaWindow::getWindow() const +{ + return mpImpl; +} + +// ------------------------------------------------------------------------- + +void MediaWindow::getMediaFilters( FilterNameVector& rFilterNameVector ) +{ + static const char* pFilters[] = { "AIF Audio", "aif;aiff", + "AU Audio", "au", + "AVI", "avi", + "CD Audio", "cda", + "Matroska Media", "mkv", + "MIDI Audio", "mid;midi", + "MPEG Audio", "mp2;mp3;mpa", + "MPEG Video", "mpg;mpeg;mpv;mp4", + "Ogg bitstream", "ogg", + "Quicktime Video", "mov", + "Vivo Video", "viv", + "WAVE Audio", "wav" }; + + unsigned int i; + for( i = 0; i < ( sizeof( pFilters ) / sizeof( char* ) ); i += 2 ) + { + rFilterNameVector.push_back( ::std::make_pair< ::rtl::OUString, ::rtl::OUString >( + ::rtl::OUString::createFromAscii( pFilters[ i ] ), + ::rtl::OUString::createFromAscii( pFilters[ i + 1 ] ) ) ); + } +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::executeMediaURLDialog( Window* /* pParent */, ::rtl::OUString& rURL, bool bInsertDialog ) +{ + ::sfx2::FileDialogHelper aDlg( com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); + static const ::rtl::OUString aWildcard( RTL_CONSTASCII_USTRINGPARAM( "*." ) ); + FilterNameVector aFilters; + const ::rtl::OUString aSeparator( RTL_CONSTASCII_USTRINGPARAM( ";" ) ); + ::rtl::OUString aAllTypes; + + aDlg.SetTitle( AVMEDIA_RESID( bInsertDialog ? AVMEDIA_STR_INSERTMEDIA_DLG : AVMEDIA_STR_OPENMEDIA_DLG ) ); + + getMediaFilters( aFilters ); + + unsigned int i; + for( i = 0; i < aFilters.size(); ++i ) + { + for( sal_Int32 nIndex = 0; nIndex >= 0; ) + { + if( aAllTypes.getLength() ) + aAllTypes += aSeparator; + + ( aAllTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex ); + } + } + + // add filter for all media types + aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_MEDIAFILES ), aAllTypes ); + + for( i = 0; i < aFilters.size(); ++i ) + { + ::rtl::OUString aTypes; + + for( sal_Int32 nIndex = 0; nIndex >= 0; ) + { + if( aTypes.getLength() ) + aTypes += aSeparator; + + ( aTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex ); + } + + // add single filters + aDlg.AddFilter( aFilters[ i ].first, aTypes ); + } + + // add filter for all types + aDlg.AddFilter( AVMEDIA_RESID( AVMEDIA_STR_ALL_FILES ), String( RTL_CONSTASCII_USTRINGPARAM( "*.*" ) ) ); + + if( aDlg.Execute() == ERRCODE_NONE ) + { + const INetURLObject aURL( aDlg.GetPath() ); + rURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); + } + else if( rURL.getLength() ) + rURL = ::rtl::OUString(); + + return( rURL.getLength() > 0 ); +} + +// ------------------------------------------------------------------------- + +void MediaWindow::executeFormatErrorBox( Window* pParent ) +{ + ErrorBox aErrBox( pParent, AVMEDIA_RESID( AVMEDIA_ERR_URL ) ); + + aErrBox.Execute(); +} + +// ------------------------------------------------------------------------- + +bool MediaWindow::isMediaURL( const ::rtl::OUString& rURL, bool bDeep, Size* pPreferredSizePixel ) +{ + const INetURLObject aURL( rURL ); + bool bRet = false; + + if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) + { + if( bDeep || pPreferredSizePixel ) + { + try + { + sal_Bool bIsJavaBasedMediaWindow; + uno::Reference< media::XPlayer > xPlayer( priv::MediaWindowImpl::createPlayer( + aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ), + bIsJavaBasedMediaWindow ) ); + + if( xPlayer.is() ) + { + bRet = true; + + if( pPreferredSizePixel ) + { + const awt::Size aAwtSize( xPlayer->getPreferredPlayerWindowSize() ); + + pPreferredSizePixel->Width() = aAwtSize.Width; + pPreferredSizePixel->Height() = aAwtSize.Height; + } + } + } + catch( ... ) + { + } + } + else + { + FilterNameVector aFilters; + const ::rtl::OUString aExt( aURL.getExtension() ); + + getMediaFilters( aFilters ); + + unsigned int i; + for( i = 0; ( i < aFilters.size() ) && !bRet; ++i ) + { + for( sal_Int32 nIndex = 0; nIndex >= 0 && !bRet; ) + { + if( aExt.equalsIgnoreAsciiCase( aFilters[ i ].second.getToken( 0, ';', nIndex ) ) ) + bRet = true; + } + } + } + } + + return bRet; +} + +// ------------------------------------------------------------------------- + +uno::Reference< media::XPlayer > MediaWindow::createPlayer( const ::rtl::OUString& rURL ) +{ + sal_Bool bJavaBased = sal_False; + return priv::MediaWindowImpl::createPlayer( rURL, bJavaBased ); +} + +// ------------------------------------------------------------------------- + +uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const ::rtl::OUString& rURL, + bool bAllowToCreateReplacementGraphic, + double fMediaTime ) +{ + uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL ) ); + uno::Reference< graphic::XGraphic > xRet; + ::std::auto_ptr< Graphic > apGraphic; + + if( xPlayer.is() ) + { + uno::Reference< media::XFrameGrabber > xGrabber( xPlayer->createFrameGrabber() ); + + if( xGrabber.is() ) + { + if( AVMEDIA_FRAMEGRABBER_DEFAULTFRAME == fMediaTime ) + fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME; + + if( fMediaTime >= xPlayer->getDuration() ) + fMediaTime = ( xPlayer->getDuration() * 0.5 ); + + xRet = xGrabber->grabFrame( fMediaTime ); + } + + if( !xRet.is() && bAllowToCreateReplacementGraphic ) + { + awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() ); + + if( !aPrefSize.Width && !aPrefSize.Height ) + { + const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_AUDIOLOGO ) ); + apGraphic.reset( new Graphic( aBmpEx ) ); + } + } + } + + if( !xRet.is() && !apGraphic.get() && bAllowToCreateReplacementGraphic ) + { + const BitmapEx aBmpEx( AVMEDIA_RESID( AVMEDIA_BMP_EMPTYLOGO ) ); + apGraphic.reset( new Graphic( aBmpEx ) ); + } + + if( apGraphic.get() ) + xRet = apGraphic->GetXGraphic(); + + return xRet; +} + +} // namespace avemdia diff --git a/avmedia/source/viewer/mediawindow.hrc b/avmedia/source/viewer/mediawindow.hrc new file mode 100644 index 000000000000..67036e300c13 --- /dev/null +++ b/avmedia/source/viewer/mediawindow.hrc @@ -0,0 +1,9 @@ +#define AVMEDIA_STR_OPENMEDIA_DLG 16384 +#define AVMEDIA_STR_INSERTMEDIA_DLG 16385 +#define AVMEDIA_STR_ALL_MEDIAFILES 16386 +#define AVMEDIA_STR_ALL_FILES 16387 + +#define AVMEDIA_BMP_AUDIOLOGO 20000 +#define AVMEDIA_BMP_EMPTYLOGO 20001 + +#define AVMEDIA_ERR_URL 21000 diff --git a/avmedia/source/viewer/mediawindow.src b/avmedia/source/viewer/mediawindow.src new file mode 100644 index 000000000000..1c92b4d913af --- /dev/null +++ b/avmedia/source/viewer/mediawindow.src @@ -0,0 +1,77 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediawindow.hrc" + +String AVMEDIA_STR_INSERTMEDIA_DLG +{ + Text[en-US] = "Insert Movie and Sound"; +}; + +// ------------------------------------------------------------------------------ + +STRING AVMEDIA_STR_OPENMEDIA_DLG +{ + Text[en-US] = "Open Movie and Sound"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ALL_MEDIAFILES +{ + Text[en-US] = "All movie and sound files"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ALL_FILES +{ + Text[en-US] = "All files (*.*)"; +}; + +// ------------------------------------------------------------------------------ + +Bitmap AVMEDIA_BMP_AUDIOLOGO +{ + file = "avaudiologo.png"; +}; + +// ------------------------------------------------------------------------------ + +Bitmap AVMEDIA_BMP_EMPTYLOGO +{ + file = "avemptylogo.png"; +}; + +// ------------------------------------------------------------------------------ + +ErrorBox AVMEDIA_ERR_URL +{ + BUTTONS = WB_OK ; + DEFBUTTON = WB_DEF_OK ; + Message[en-US] = "The format of the selected file is not supported."; +}; diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx new file mode 100644 index 000000000000..15c830cb97a6 --- /dev/null +++ b/avmedia/source/viewer/mediawindow_impl.cxx @@ -0,0 +1,547 @@ +/************************************************************************ + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediawindow_impl.hxx" +#include "mediaevent_impl.hxx" +#include "mediamisc.hxx" +#include "mediawindow.hrc" +#include "helpids.hrc" + +#include <algorithm> +#include <cmath> +#include <osl/mutex.hxx> +#include <tools/time.hxx> +#include <vcl/svapp.hxx> + +#ifndef _COM_SUN_STAR_AWT_SYSTEMPOINTER_HDL_ +#include <com/sun/star/awt/SystemPointer.hdl> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HDL_ +#include <com/sun/star/lang/XComponent.hdl> +#endif + +#define AVMEDIA_TOOLBOXITEM_PREV 0x0001 +#define AVMEDIA_TOOLBOXITEM_PLAY 0x0002 +#define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004 +#define AVMEDIA_TOOLBOXITEM_STOP 0x0008 +#define AVMEDIA_TOOLBOXITEM_NEXT 0x0010 +#define AVMEDIA_TOOLBOXITEM_MUTE 0x0100 + +#define AVMEDIA_FFW_PLAYRATE 4 + +using namespace ::com::sun::star; + +namespace avmedia { namespace priv { + +// ---------------------- +// - MediaWindowControl - +// ---------------------- + +MediaWindowControl::MediaWindowControl( Window* pParent ) : + MediaControl( pParent, MEDIACONTROLSTYLE_MULTILINE ) +{ +} + +// --------------------------------------------------------------------- + +MediaWindowControl::~MediaWindowControl() +{ +} + +// --------------------------------------------------------------------- + +void MediaWindowControl::update() +{ + MediaItem aItem; + + static_cast< MediaWindowImpl* >( GetParent() )->updateMediaItem( aItem ); + setState( aItem ); +} + +// --------------------------------------------------------------------- + +void MediaWindowControl::execute( const MediaItem& rItem ) +{ + static_cast< MediaWindowImpl* >( GetParent() )->executeMediaItem( rItem ); +} + +// -------------------- +// - MediaChildWindow - +// -------------------- + +MediaChildWindow::MediaChildWindow( Window* pParent ) : + SystemChildWindow( pParent, WB_CLIPCHILDREN ) +{ +} + +// --------------------------------------------------------------------- + +MediaChildWindow::~MediaChildWindow() +{ +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::MouseMove( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseMove( rMEvt ); + GetParent()->MouseMove( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::MouseButtonDown( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseButtonDown( rMEvt ); + GetParent()->MouseButtonDown( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::MouseButtonUp( const MouseEvent& rMEvt ) +{ + const MouseEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) ), + rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), rMEvt.GetModifier() ); + + SystemChildWindow::MouseButtonUp( rMEvt ); + GetParent()->MouseButtonUp( aTransformedEvent ); +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::KeyInput( const KeyEvent& rKEvt ) +{ + SystemChildWindow::KeyInput( rKEvt ); + GetParent()->KeyInput( rKEvt ); +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::KeyUp( const KeyEvent& rKEvt ) +{ + SystemChildWindow::KeyUp( rKEvt ); + GetParent()->KeyUp( rKEvt ); +} + +// --------------------------------------------------------------------- + +void MediaChildWindow::Command( const CommandEvent& rCEvt ) +{ + const CommandEvent aTransformedEvent( GetParent()->ScreenToOutputPixel( OutputToScreenPixel( rCEvt.GetMousePosPixel() ) ), + rCEvt.GetCommand(), rCEvt.IsMouseEvent(), rCEvt.GetData() ); + + SystemChildWindow::Command( rCEvt ); + GetParent()->Command( aTransformedEvent ); +} + +// ---------------------- +// - MediaWindowImpl - +// ---------------------- + +MediaWindowImpl::MediaWindowImpl( Window* pParent, MediaWindow* pMediaWindow, bool bInternalMediaControl ) : + Control( pParent ), + MediaWindowBaseImpl( pMediaWindow ), + DropTargetHelper( this ), + DragSourceHelper( this ), + mxEventsIf( static_cast< ::cppu::OWeakObject* >( mpEvents = new MediaEventListenersImpl( maChildWindow ) ) ), + maChildWindow( this ), + mpMediaWindowControl( bInternalMediaControl ? new MediaWindowControl( this ) : NULL ), + mpEmptyBmpEx( NULL ), + mpAudioBmpEx( NULL ) +{ + maChildWindow.SetBackground( Color( COL_BLACK ) ); + maChildWindow.SetHelpId( HID_AVMEDIA_PLAYERWINDOW ); + maChildWindow.Hide(); + + if( mpMediaWindowControl ) + { + mpMediaWindowControl->SetSizePixel( mpMediaWindowControl->getMinSizePixel() ); + mpMediaWindowControl->Show(); + } +} + +// --------------------------------------------------------------------- + +MediaWindowImpl::~MediaWindowImpl() +{ + delete mpEmptyBmpEx; + delete mpAudioBmpEx; + delete mpMediaWindowControl; +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::cleanUp() +{ + uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() ); + + mpEvents->cleanUp(); + + if( xPlayerWindow.is() ) + { + xPlayerWindow->removeKeyListener( uno::Reference< awt::XKeyListener >( mxEventsIf, uno::UNO_QUERY ) ); + xPlayerWindow->removeMouseListener( uno::Reference< awt::XMouseListener >( mxEventsIf, uno::UNO_QUERY ) ); + xPlayerWindow->removeMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( mxEventsIf, uno::UNO_QUERY ) ); + + uno::Reference< lang::XComponent > xComponent( xPlayerWindow, uno::UNO_QUERY ); + + if( xComponent.is() ) + xComponent->dispose(); + + setPlayerWindow( NULL ); + } + + MediaWindowBaseImpl::cleanUp(); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::onURLChanged() +{ + if( getPlayer().is() ) + { + uno::Reference< media::XPlayerWindow > xPlayerWindow; + + const Point aPoint; + const Size aSize( maChildWindow.GetSizePixel() ); + const sal_IntPtr nWndHandle = (sal_IntPtr) maChildWindow.GetParentWindowHandle( isMediaWindowJavaBased() ); + + try + { + if( nWndHandle != 0 ) + { + uno::Sequence< uno::Any > aArgs( 3 ); + + aArgs[ 0 ] = uno::makeAny( nWndHandle ); + aArgs[ 1 ] = uno::makeAny( awt::Rectangle( aPoint.X(), aPoint.Y(), aSize.Width(), aSize.Height() ) ); + aArgs[ 2 ] = uno::makeAny( reinterpret_cast< sal_IntPtr >( &maChildWindow ) ); + + xPlayerWindow = getPlayer()->createPlayerWindow( aArgs ); + } + } + catch( uno::RuntimeException ) + { + // happens eg, on MacOSX where Java frames cannot be created from X11 window handles + } + + setPlayerWindow( xPlayerWindow ); + + if( xPlayerWindow.is() ) + { + xPlayerWindow->addKeyListener( uno::Reference< awt::XKeyListener >( mxEventsIf, uno::UNO_QUERY ) ); + xPlayerWindow->addMouseListener( uno::Reference< awt::XMouseListener >( mxEventsIf, uno::UNO_QUERY ) ); + xPlayerWindow->addMouseMotionListener( uno::Reference< awt::XMouseMotionListener >( mxEventsIf, uno::UNO_QUERY ) ); + xPlayerWindow->addFocusListener( uno::Reference< awt::XFocusListener >( mxEventsIf, uno::UNO_QUERY ) ); + } + } + else + setPlayerWindow( NULL ); + + if( getPlayerWindow().is() ) + maChildWindow.Show(); + else + maChildWindow.Hide(); + + if( mpMediaWindowControl ) + { + MediaItem aItem; + + updateMediaItem( aItem ); + mpMediaWindowControl->setState( aItem ); + } +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::update() +{ + uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() ); + + if( xPlayerWindow.is() ) + xPlayerWindow->update(); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::setPosSize( const Rectangle& rRect ) +{ + SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::setPointer( const Pointer& rPointer ) +{ + uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() ); + + SetPointer( rPointer ); + maChildWindow.SetPointer( rPointer ); + + if( xPlayerWindow.is() ) + { + long nPointer; + + switch( rPointer.GetStyle() ) + { + case( POINTER_CROSS ): nPointer = awt::SystemPointer::CROSS; break; + case( POINTER_HAND ): nPointer = awt::SystemPointer::HAND; break; + case( POINTER_MOVE ): nPointer = awt::SystemPointer::MOVE; break; + case( POINTER_WAIT ): nPointer = awt::SystemPointer::WAIT; break; + + default: nPointer = awt::SystemPointer::ARROW; break; + } + + xPlayerWindow->setPointerType( nPointer ); + } +} + +// --------------------------------------------------------------------- + +const Pointer& MediaWindowImpl::getPointer() const +{ + return GetPointer(); +} + +// --------------------------------------------------------------------- + +bool MediaWindowImpl::hasInternalMediaControl() const +{ + return( mpMediaWindowControl != NULL ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::Resize() +{ + uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() ); + const Size aCurSize( GetOutputSizePixel() ); + const sal_Int32 nOffset( mpMediaWindowControl ? AVMEDIA_CONTROLOFFSET : 0 ); + Size aPlayerWindowSize( aCurSize.Width() - ( nOffset << 1 ), + aCurSize.Height() - ( nOffset << 1 ) ); + + if( mpMediaWindowControl ) + { + const sal_Int32 nControlHeight = mpMediaWindowControl->GetSizePixel().Height(); + const sal_Int32 nControlY = ::std::max( aCurSize.Height() - nControlHeight - nOffset, 0L ); + + aPlayerWindowSize.Height() = ( nControlY - ( nOffset << 1 ) ); + mpMediaWindowControl->SetPosSizePixel( Point( nOffset, nControlY ), Size( aCurSize.Width() - ( nOffset << 1 ), nControlHeight ) ); + } + + if( xPlayerWindow.is() ) + xPlayerWindow->setPosSize( 0, 0, aPlayerWindowSize.Width(), aPlayerWindowSize.Height(), 0 ); + + maChildWindow.SetPosSizePixel( Point( nOffset, nOffset ), aPlayerWindowSize ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::StateChanged( StateChangedType eType ) +{ + uno::Reference< media::XPlayerWindow > xPlayerWindow( getPlayerWindow() ); + + if( xPlayerWindow.is() ) + { + // stop playing when going disabled or hidden + switch( eType ) + { + case STATE_CHANGE_VISIBLE: + { + stopPlayingInternal( !IsVisible() ); + xPlayerWindow->setVisible( IsVisible() ); + } + break; + + case STATE_CHANGE_ENABLE: + { + stopPlayingInternal( !IsEnabled() ); + xPlayerWindow->setEnable( IsEnabled() ); + } + break; + + default: + break; + } + } +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::Paint( const Rectangle& ) +{ + BitmapEx* pLogo = NULL; + + if( !getPlayer().is() ) + { + if( !mpEmptyBmpEx ) + mpEmptyBmpEx = new BitmapEx( AVMEDIA_RESID( AVMEDIA_BMP_EMPTYLOGO ) ); + + pLogo = mpEmptyBmpEx; + } + else if( !getPlayerWindow().is() ) + { + if( !mpAudioBmpEx ) + mpAudioBmpEx = new BitmapEx( AVMEDIA_RESID( AVMEDIA_BMP_AUDIOLOGO ) ); + + pLogo = mpAudioBmpEx; + } + + const Point aBasePos( maChildWindow.GetPosPixel() ); + const Rectangle aVideoRect( aBasePos, maChildWindow.GetSizePixel() ); + + if( pLogo && !pLogo->IsEmpty() && ( aVideoRect.GetWidth() > 0 ) && ( aVideoRect.GetHeight() > 0 ) ) + { + Size aLogoSize( pLogo->GetSizePixel() ); + const Color aBackgroundColor( 67, 67, 67 ); + + SetLineColor( aBackgroundColor ); + SetFillColor( aBackgroundColor ); + DrawRect( aVideoRect ); + + if( ( aLogoSize.Width() > aVideoRect.GetWidth() || aLogoSize.Height() > aVideoRect.GetHeight() ) && + ( aLogoSize.Height() > 0 ) ) + { + const double fLogoWH = (double) aLogoSize.Width() / aLogoSize.Height(); + + if( fLogoWH < ( (double) aVideoRect.GetWidth() / aVideoRect.GetHeight() ) ) + { + aLogoSize.Width() = (long) ( aVideoRect.GetHeight() * fLogoWH ); + aLogoSize.Height()= aVideoRect.GetHeight(); + } + else + { + aLogoSize.Width() = aVideoRect.GetWidth(); + aLogoSize.Height()= (long) ( aVideoRect.GetWidth() / fLogoWH ); + } + } + + DrawBitmapEx( Point( aBasePos.X() + ( ( aVideoRect.GetWidth() - aLogoSize.Width() ) >> 1 ), + aBasePos.Y() + ( ( aVideoRect.GetHeight() - aLogoSize.Height() ) >> 1 ) ), + aLogoSize, *pLogo ); + } +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::GetFocus() +{ +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->MouseMove( rMEvt ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->MouseButtonDown( rMEvt ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->MouseButtonUp( rMEvt ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->KeyInput( rKEvt ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->KeyUp( rKEvt ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::Command( const CommandEvent& rCEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->Command( rCEvt ); +} + +// --------------------------------------------------------------------- + +sal_Int8 MediaWindowImpl::AcceptDrop( const AcceptDropEvent& rEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + return( pMediaWindow ? pMediaWindow->AcceptDrop( rEvt ) : 0 ); +} + +// --------------------------------------------------------------------- + +sal_Int8 MediaWindowImpl::ExecuteDrop( const ExecuteDropEvent& rEvt ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + return( pMediaWindow ? pMediaWindow->ExecuteDrop( rEvt ) : 0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowImpl::StartDrag( sal_Int8 nAction, const Point& rPosPixel ) +{ + MediaWindow* pMediaWindow = getMediaWindow(); + + if( pMediaWindow ) + pMediaWindow->StartDrag( nAction, rPosPixel ); +} + +} // namespace priv +} // namespace avmedia diff --git a/avmedia/source/viewer/mediawindow_impl.hxx b/avmedia/source/viewer/mediawindow_impl.hxx new file mode 100644 index 000000000000..9008e499647d --- /dev/null +++ b/avmedia/source/viewer/mediawindow_impl.hxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: mediawindow_impl.hxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _AVMEDIA_MEDIAWINDOW_IMPL_HXX +#define _AVMEDIA_MEDIAWINDOW_IMPL_HXX + +#include <svtools/transfer.hxx> +#include <vcl/syschild.hxx> + +#include "mediawindowbase_impl.hxx" +#include "mediacontrol.hxx" + +class BitmapEx; + +namespace avmedia +{ + namespace priv + { + // ---------------------- + // - MediaWindowControl - + // ---------------------- + + class MediaWindowControl : public MediaControl + { + public: + + MediaWindowControl( Window* pParent ); + ~MediaWindowControl(); + + protected: + + void update(); + void execute( const MediaItem& rItem ); + }; + + // -------------------- + // - MediaChildWindow - + // -------------------- + + class MediaChildWindow : public SystemChildWindow + { + public: + + MediaChildWindow( Window* pParent ); + ~MediaChildWindow(); + + protected: + + virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void MouseButtonUp( const MouseEvent& rMEvt ); + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void KeyUp( const KeyEvent& rKEvt ); + virtual void Command( const CommandEvent& rCEvt ); + }; + + // ------------------. + // - MediaWindowImpl - + // ------------------- + + class MediaEventListenersImpl; + + class MediaWindowImpl : public Control, + public MediaWindowBaseImpl, + public DropTargetHelper, + public DragSourceHelper + + { + public: + + MediaWindowImpl( Window* parent, MediaWindow* pMediaWindow, bool bInternalMediaControl ); + virtual ~MediaWindowImpl(); + + virtual void cleanUp(); + virtual void onURLChanged(); + + public: + + void update(); + + void setPosSize( const Rectangle& rRect ); + + void setPointer( const Pointer& rPointer ); + const Pointer& getPointer() const; + + bool hasInternalMediaControl() const; + + protected: + + // Window + virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void MouseButtonUp( const MouseEvent& rMEvt ); + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void KeyUp( const KeyEvent& rKEvt ); + virtual void Command( const CommandEvent& rCEvt ); + virtual void Resize(); + virtual void StateChanged( StateChangedType ); + virtual void Paint( const Rectangle& ); // const + virtual void GetFocus(); + + // DropTargetHelper + virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ); + virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ); + + // DragSourceHelper + virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ); + + private: + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > mxEventsIf; + MediaEventListenersImpl* mpEvents; + MediaChildWindow maChildWindow; + MediaWindowControl* mpMediaWindowControl; + BitmapEx* mpEmptyBmpEx; + BitmapEx* mpAudioBmpEx; + }; + } +} + +#endif diff --git a/avmedia/source/viewer/mediawindowbase_impl.cxx b/avmedia/source/viewer/mediawindowbase_impl.cxx new file mode 100644 index 000000000000..94a6c36ed064 --- /dev/null +++ b/avmedia/source/viewer/mediawindowbase_impl.cxx @@ -0,0 +1,467 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediawindowbase_impl.hxx" +#include <avmedia/mediaitem.hxx> +#include "mediamisc.hxx" +#include "mediawindow.hrc" +#include <tools/urlobj.hxx> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/media/XManager.hpp> +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HDL_ +#include <com/sun/star/lang/XComponent.hdl> +#endif + +#define MEDIA_TIMER_TIMEOUT 100 + +using namespace ::com::sun::star; + +namespace avmedia { namespace priv { + +// ----------------------- +// - MediaWindowBaseImpl - +// ----------------------- + +struct ServiceManager +{ + const char* pServiceName; + sal_Bool bIsJavaBased; +}; + +// --------------------------------------------------------------------- + + +MediaWindowBaseImpl::MediaWindowBaseImpl( MediaWindow* pMediaWindow ) : + mpMediaWindow( pMediaWindow ), + mbIsMediaWindowJavaBased( sal_False ) +{ +} + +// --------------------------------------------------------------------- + +MediaWindowBaseImpl::~MediaWindowBaseImpl() +{ + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); +} + +// ------------------------------------------------------------------------- + +uno::Reference< media::XPlayer > MediaWindowBaseImpl::createPlayer( const ::rtl::OUString& rURL, sal_Bool& rbJavaBased ) +{ + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + uno::Reference< media::XPlayer > xPlayer; + + rbJavaBased = sal_False; + + if( xFactory.is() ) + { + static const ServiceManager aServiceManagers[] = + { + { AVMEDIA_MANAGER_SERVICE_NAME, AVMEDIA_MANAGER_SERVICE_IS_JAVABASED }, + { AVMEDIA_MANAGER_SERVICE_NAME_FALLBACK1, AVMEDIA_MANAGER_SERVICE_IS_JAVABASED_FALLBACK1 } + }; + + for( sal_uInt32 i = 0; !xPlayer.is() && ( i < ( sizeof( aServiceManagers ) / sizeof( ServiceManager ) ) ); ++i ) + { + const String aServiceName( aServiceManagers[ i ].pServiceName, RTL_TEXTENCODING_ASCII_US ); + + if( aServiceName.Len() ) + { + OSL_TRACE( "Trying to create media manager service %s", aServiceManagers[ i ].pServiceName ); + + try + { + uno::Reference< media::XManager > xManager( xFactory->createInstance( aServiceName ), uno::UNO_QUERY ); + + if( xManager.is() ) + { + xPlayer = uno::Reference< media::XPlayer >( xManager->createPlayer( rURL ), uno::UNO_QUERY ); + } + } + catch( ... ) + { + } + } + + if( xPlayer.is() ) + { + rbJavaBased = aServiceManagers[ i ].bIsJavaBased; + } + } + } + + return xPlayer; +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setURL( const ::rtl::OUString& rURL ) +{ + if( rURL != getURL() ) + { + INetURLObject aURL( maFileURL = rURL ); + + if( mxPlayer.is() ) + mxPlayer->stop(); + + if( mxPlayerWindow.is() ) + { + mxPlayerWindow->setVisible( false ); + mxPlayerWindow.clear(); + } + + mxPlayer.clear(); + + if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) + maFileURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); + + mxPlayer = createPlayer( maFileURL, mbIsMediaWindowJavaBased ); + onURLChanged(); + } +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::onURLChanged() +{ +} + +// --------------------------------------------------------------------- + +const ::rtl::OUString& MediaWindowBaseImpl::getURL() const +{ + return maFileURL; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isValid() const +{ + return( getPlayer().is() ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::stopPlayingInternal( bool bStop ) +{ + if( isPlaying() ) + { + bStop ? mxPlayer->stop() : mxPlayer->start(); + } +} + +// --------------------------------------------------------------------- + +MediaWindow* MediaWindowBaseImpl::getMediaWindow() const +{ + return mpMediaWindow; +} + +// --------------------------------------------------------------------- + +uno::Reference< media::XPlayer > MediaWindowBaseImpl::getPlayer() const +{ + return mxPlayer; +} + +// --------------------------------------------------------------------- + +uno::Reference< media::XPlayerWindow > MediaWindowBaseImpl::getPlayerWindow() const +{ + return mxPlayerWindow; +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setPlayerWindow( const uno::Reference< media::XPlayerWindow >& rxPlayerWindow ) +{ + mxPlayerWindow = rxPlayerWindow; +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::cleanUp() +{ + if( mxPlayer.is() ) + { + mxPlayer->stop(); + + uno::Reference< lang::XComponent > xComponent( mxPlayer, uno::UNO_QUERY ); + + if( xComponent.is() ) + xComponent->dispose(); + + mxPlayer.clear(); + } + + mpMediaWindow = NULL; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::hasPreferredSize() const +{ + return( mxPlayerWindow.is() ); +} + +// --------------------------------------------------------------------- + +Size MediaWindowBaseImpl::getPreferredSize() const +{ + Size aRet; + + if( mxPlayer.is() ) + { + awt::Size aPrefSize( mxPlayer->getPreferredPlayerWindowSize() ); + + aRet.Width() = aPrefSize.Width; + aRet.Height() = aPrefSize.Height; + } + + return aRet; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::setZoom( ::com::sun::star::media::ZoomLevel eLevel ) +{ + return( mxPlayerWindow.is() ? mxPlayerWindow->setZoomLevel( eLevel ) : false ); +} + +// ------------------------------------------------------------------------- + +::com::sun::star::media::ZoomLevel MediaWindowBaseImpl::getZoom() const +{ + return( mxPlayerWindow.is() ? mxPlayerWindow->getZoomLevel() : ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::start() +{ + return( mxPlayer.is() ? ( mxPlayer->start(), true ) : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::stop() +{ + if( mxPlayer.is() ) + mxPlayer->stop(); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isPlaying() const +{ + return( mxPlayer.is() && mxPlayer->isPlaying() ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getDuration() const +{ + return( mxPlayer.is() ? mxPlayer->getDuration() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setMediaTime( double fTime ) +{ + if( mxPlayer.is() ) + mxPlayer->setMediaTime( fTime ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getMediaTime() const +{ + return( mxPlayer.is() ? mxPlayer->getMediaTime() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setStopTime( double fTime ) +{ + if( mxPlayer.is() ) + mxPlayer->setStopTime( fTime ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getStopTime() const +{ + return( mxPlayer.is() ? mxPlayer->getStopTime() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setRate( double fRate ) +{ + if( mxPlayer.is() ) + mxPlayer->setRate( fRate ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getRate() const +{ + return( mxPlayer.is() ? mxPlayer->getRate() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setPlaybackLoop( bool bSet ) +{ + if( mxPlayer.is() ) + mxPlayer->setPlaybackLoop( bSet ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isPlaybackLoop() const +{ + return( mxPlayer.is() ? mxPlayer->isPlaybackLoop() : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setMute( bool bSet ) +{ + if( mxPlayer.is() ) + mxPlayer->setMute( bSet ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isMute() const +{ + return( mxPlayer.is() ? mxPlayer->isMute() : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setVolumeDB( sal_Int16 nVolumeDB ) +{ + if( mxPlayer.is() ) + mxPlayer->setVolumeDB( nVolumeDB ); +} + +// --------------------------------------------------------------------- + +sal_Int16 MediaWindowBaseImpl::getVolumeDB() const +{ + return( mxPlayer.is() ? mxPlayer->getVolumeDB() : 0 ); +} + +// ------------------------------------------------------------------------- + +void MediaWindowBaseImpl::updateMediaItem( MediaItem& rItem ) const +{ + if( isPlaying() ) + rItem.setState( ( getRate() > 1.0 ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY ); + else + rItem.setState( ( 0.0 == getMediaTime() ) ? MEDIASTATE_STOP : MEDIASTATE_PAUSE ); + + rItem.setDuration( getDuration() ); + rItem.setTime( getMediaTime() ); + rItem.setLoop( isPlaybackLoop() ); + rItem.setMute( isMute() ); + rItem.setVolumeDB( getVolumeDB() ); + rItem.setZoom( getZoom() ); + rItem.setURL( getURL() ); +} + +// ------------------------------------------------------------------------- + +void MediaWindowBaseImpl::executeMediaItem( const MediaItem& rItem ) +{ + const sal_uInt32 nMaskSet = rItem.getMaskSet(); + + // set URL first + if( nMaskSet & AVMEDIA_SETMASK_URL ) + setURL( rItem.getURL() ); + + // set different states next + if( nMaskSet & AVMEDIA_SETMASK_TIME ) + setMediaTime( ::std::min( rItem.getTime(), getDuration() ) ); + + if( nMaskSet & AVMEDIA_SETMASK_LOOP ) + setPlaybackLoop( rItem.isLoop() ); + + if( nMaskSet & AVMEDIA_SETMASK_MUTE ) + setMute( rItem.isMute() ); + + if( nMaskSet & AVMEDIA_SETMASK_VOLUMEDB ) + setVolumeDB( rItem.getVolumeDB() ); + + if( nMaskSet & AVMEDIA_SETMASK_ZOOM ) + setZoom( rItem.getZoom() ); + + // set play state at last + if( nMaskSet & AVMEDIA_SETMASK_STATE ) + { + switch( rItem.getState() ) + { + case( MEDIASTATE_PLAY ): + case( MEDIASTATE_PLAYFFW ): + { +/* + const double fNewRate = ( ( MEDIASTATE_PLAYFFW == rItem.getState() ) ? AVMEDIA_FFW_PLAYRATE : 1.0 ); + + if( getRate() != fNewRate ) + setRate( fNewRate ); +*/ + if( !isPlaying() ) + start(); + } + break; + + case( MEDIASTATE_PAUSE ): + { + if( isPlaying() ) + stop(); + } + break; + + case( MEDIASTATE_STOP ): + { + if( isPlaying() ) + { + setMediaTime( 0.0 ); + stop(); + setMediaTime( 0.0 ); + } + } + break; + } + } +} + +} // namespace priv +} // namespace avemdia diff --git a/avmedia/source/viewer/mediawindowbase_impl.hxx b/avmedia/source/viewer/mediawindowbase_impl.hxx new file mode 100644 index 000000000000..028b7c6ed079 --- /dev/null +++ b/avmedia/source/viewer/mediawindowbase_impl.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _AVMEDIA_MEDIAWINDOWBASE_IMPL_HXX +#define _AVMEDIA_MEDIAWINDOWBASE_IMPL_HXX + +#include <avmedia/mediawindow.hxx> +#include <com/sun/star/media/XPlayer.hpp> +#include <com/sun/star/media/XPlayerWindow.hpp> + +namespace avmedia +{ + namespace priv + { + // -------------- + // - UpdateMode - + // -------------- + + enum UpdateMode + { + UPDATEMODE_SYNC_STATUSBAR = 0, + UPDATEMODE_SYNC_PLAYER = 1, + UPDATEMODE_SYNC_NONE = 2 + }; + + // ----------------------- + // - MediaWindowBaseImpl - + // ----------------------- + + class MediaWindowBaseImpl + { + public: + + MediaWindowBaseImpl( MediaWindow* pMediaWindow ); + virtual ~MediaWindowBaseImpl(); + + virtual void cleanUp(); + virtual void onURLChanged(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > createPlayer( const ::rtl::OUString& rURL, + sal_Bool& rbJavaBased ); + + public: + + void setURL( const ::rtl::OUString& rURL ); + const ::rtl::OUString& getURL() const; + + bool isValid() const; + + bool hasPreferredSize() const; + Size getPreferredSize() const; + + bool setZoom( ::com::sun::star::media::ZoomLevel eLevel ); + ::com::sun::star::media::ZoomLevel getZoom() const; + + bool start(); + void stop(); + + bool isPlaying() const; + + double getDuration() const; + + void setMediaTime( double fTime ); + double getMediaTime() const; + + void setStopTime( double fTime ); + double getStopTime() const; + + void setRate( double fRate ); + double getRate() const; + + void setPlaybackLoop( bool bSet ); + bool isPlaybackLoop() const; + + void setFixedAspectRatio( bool bSet ); + bool isFixedAspectRatio() const; + + void setMute( bool bSet ); + bool isMute() const; + + void setVolumeDB( sal_Int16 nVolumeDB ); + sal_Int16 getVolumeDB() const; + + void updateMediaItem( MediaItem& rItem ) const; + void executeMediaItem( const MediaItem& rItem ); + + protected: + + void stopPlayingInternal( bool ); + + MediaWindow* getMediaWindow() const; + inline sal_Bool isMediaWindowJavaBased() const { return( mbIsMediaWindowJavaBased ); } + + ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > getPlayer() const; + + void setPlayerWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow >& rxPlayerWindow ); + ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > getPlayerWindow() const; + + private: + + ::rtl::OUString maFileURL; + ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mxPlayer; + ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > mxPlayerWindow; + MediaWindow* mpMediaWindow; + sal_Bool mbIsMediaWindowJavaBased; + }; + } +} + +#endif diff --git a/avmedia/source/win/exports.dxp b/avmedia/source/win/exports.dxp new file mode 100644 index 000000000000..db9c0a52f288 --- /dev/null +++ b/avmedia/source/win/exports.dxp @@ -0,0 +1,4 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory + diff --git a/avmedia/source/win/framegrabber.cxx b/avmedia/source/win/framegrabber.cxx new file mode 100644 index 000000000000..dc4a5dbeeb74 --- /dev/null +++ b/avmedia/source/win/framegrabber.cxx @@ -0,0 +1,247 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/prewin.h> +#if defined _MSC_VER +#pragma warning(push, 1) +#pragma warning(disable: 4917) +#endif +#include <windows.h> +#include <objbase.h> +#include <strmif.h> +#include <Amvideo.h> +#if defined(_MSC_VER) && (_MSC_VER < 1500) +#include <Qedit.h> +#else +#include "interface.hxx" +#endif +#include <uuids.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include <tools/postwin.h> + +#include "framegrabber.hxx" +#include "player.hxx" + +#include <tools/stream.hxx> +#include <vcl/graph.hxx> +#include <unotools/localfilehelper.hxx> + +#define AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.FrameGrabber_DirectX" +#define AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME "com.sun.star.media.FrameGrabber_DirectX" + +using namespace ::com::sun::star; + +namespace avmedia { namespace win { + +// ---------------- +// - FrameGrabber - +// ---------------- + +FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{ + ::CoInitialize( NULL ); +} + +// ------------------------------------------------------------------------------ + +FrameGrabber::~FrameGrabber() +{ + ::CoUninitialize(); +} + +// ------------------------------------------------------------------------------ + +IMediaDet* FrameGrabber::implCreateMediaDet( const ::rtl::OUString& rURL ) const +{ + IMediaDet* pDet = NULL; + + if( SUCCEEDED( CoCreateInstance( CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, IID_IMediaDet, (void**) &pDet ) ) ) + { + String aLocalStr; + + if( ::utl::LocalFileHelper::ConvertURLToPhysicalName( rURL, aLocalStr ) && aLocalStr.Len() ) + { + if( !SUCCEEDED( pDet->put_Filename( ::SysAllocString( reinterpret_cast<LPCOLESTR>(aLocalStr.GetBuffer()) ) ) ) ) + { + pDet->Release(); + pDet = NULL; + } + } + } + + return pDet; +} + +// ------------------------------------------------------------------------------ + +bool FrameGrabber::create( const ::rtl::OUString& rURL ) +{ + // just check if a MediaDet interface can be created with the given URL + IMediaDet* pDet = implCreateMediaDet( rURL ); + + if( pDet ) + { + maURL = rURL; + pDet->Release(); + pDet = NULL; + } + else + maURL = ::rtl::OUString(); + + return( maURL.getLength() > 0 ); +} + +// ------------------------------------------------------------------------------ + +uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime ) + throw (uno::RuntimeException) +{ + uno::Reference< graphic::XGraphic > xRet; + IMediaDet* pDet = implCreateMediaDet( maURL ); + + if( pDet ) + { + double fLength; + long nStreamCount; + bool bFound = false; + + if( SUCCEEDED( pDet->get_OutputStreams( &nStreamCount ) ) ) + { + for( long n = 0; ( n < nStreamCount ) && !bFound; ++n ) + { + GUID aMajorType; + + if( SUCCEEDED( pDet->put_CurrentStream( n ) ) && + SUCCEEDED( pDet->get_StreamType( &aMajorType ) ) && + ( aMajorType == MEDIATYPE_Video ) ) + { + bFound = true; + } + } + } + + if( bFound && + ( S_OK == pDet->get_StreamLength( &fLength ) ) && + ( fLength > 0.0 ) && ( fMediaTime >= 0.0 ) && ( fMediaTime <= fLength ) ) + { + AM_MEDIA_TYPE aMediaType; + long nWidth = 0, nHeight = 0, nSize = 0; + + if( SUCCEEDED( pDet->get_StreamMediaType( &aMediaType ) ) ) + { + if( ( aMediaType.formattype == FORMAT_VideoInfo ) && + ( aMediaType.cbFormat >= sizeof( VIDEOINFOHEADER ) ) ) + { + VIDEOINFOHEADER* pVih = reinterpret_cast< VIDEOINFOHEADER* >( aMediaType.pbFormat ); + + nWidth = pVih->bmiHeader.biWidth; + nHeight = pVih->bmiHeader.biHeight; + + if( nHeight < 0 ) + nHeight *= -1; + } + + if( aMediaType.cbFormat != 0 ) + { + ::CoTaskMemFree( (PVOID) aMediaType.pbFormat ); + aMediaType.cbFormat = 0; + aMediaType.pbFormat = NULL; + } + + if( aMediaType.pUnk != NULL ) + { + aMediaType.pUnk->Release(); + aMediaType.pUnk = NULL; + } + } + + if( ( nWidth > 0 ) && ( nHeight > 0 ) && + SUCCEEDED( pDet->GetBitmapBits( 0, &nSize, NULL, nWidth, nHeight ) ) && + ( nSize > 0 ) ) + { + char* pBuffer = new char[ nSize ]; + + try + { + if( SUCCEEDED( pDet->GetBitmapBits( fMediaTime, NULL, pBuffer, nWidth, nHeight ) ) ) + { + SvMemoryStream aMemStm( pBuffer, nSize, STREAM_READ | STREAM_WRITE ); + Bitmap aBmp; + + if( aBmp.Read( aMemStm, false ) && !aBmp.IsEmpty() ) + { + const Graphic aGraphic( aBmp ); + xRet = aGraphic.GetXGraphic(); + } + } + } + catch( ... ) + { + } + + delete [] pBuffer; + } + } + + pDet->Release(); + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_WIN_FRAMEGRABBER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_WIN_FRAMEGRABBER_SERVICENAME ) ); + + return aRet; +} + +} // namespace win +} // namespace avmedia diff --git a/avmedia/source/win/framegrabber.hxx b/avmedia/source/win/framegrabber.hxx new file mode 100644 index 000000000000..17085571feea --- /dev/null +++ b/avmedia/source/win/framegrabber.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _FRAMEGRABBER_HXX +#define _FRAMEGRABBER_HXX + +#include "wincommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XFRAMEGRABBER_HDL_ +#include "com/sun/star/media/XFrameGrabber.hdl" +#endif + +struct IMediaDet; + +namespace avmedia { namespace win { + +// ---------------- +// - FrameGrabber - +// ---------------- + +class FrameGrabber : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XFrameGrabber, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + FrameGrabber( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~FrameGrabber(); + + bool create( const ::rtl::OUString& rURL ); + + // XFrameGrabber + virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL grabFrame( double fMediaTime ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + ::rtl::OUString maURL; + + IMediaDet* implCreateMediaDet( const ::rtl::OUString& rURL ) const; +}; + +} // namespace win +} // namespace avmedia + +#endif // _FRAMEGRABBER_HXX diff --git a/avmedia/source/win/interface.hxx b/avmedia/source/win/interface.hxx new file mode 100644 index 000000000000..a5928139e7a7 --- /dev/null +++ b/avmedia/source/win/interface.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +extern "C" const CLSID CLSID_MediaDet; +extern "C" const IID IID_IMediaDet; +struct ISampleGrabber; + +struct +#ifndef __MINGW32__ +__declspec(uuid("65BD0710-24D2-4ff7-9324-ED2E5D3ABAFA")) __declspec(novtable) +#endif +IMediaDet : public IUnknown +{ +public: + virtual HRESULT __stdcall get_Filter( + IUnknown **pVal) = 0; + virtual HRESULT __stdcall put_Filter( + IUnknown *newVal) = 0; + virtual HRESULT __stdcall get_OutputStreams( + long *pVal) = 0; + virtual HRESULT __stdcall get_CurrentStream( + long *pVal) = 0; + virtual HRESULT __stdcall put_CurrentStream( + long newVal) = 0; + virtual HRESULT __stdcall get_StreamType( + GUID *pVal) = 0; + virtual HRESULT __stdcall get_StreamTypeB( + BSTR *pVal) = 0; + virtual HRESULT __stdcall get_StreamLength( + double *pVal) = 0; + virtual HRESULT __stdcall get_Filename( + BSTR *pVal) = 0; + virtual HRESULT __stdcall put_Filename( + BSTR newVal) = 0; + virtual HRESULT __stdcall GetBitmapBits( + double StreamTime, + long *pBufferSize, + char *pBuffer, + long Width, + long Height) = 0; + virtual HRESULT __stdcall WriteBitmapBits( + double StreamTime, + long Width, + long Height, + BSTR Filename) = 0; + virtual HRESULT __stdcall get_StreamMediaType( + AM_MEDIA_TYPE *pVal) = 0; + virtual HRESULT __stdcall GetSampleGrabber( + ISampleGrabber **ppVal) = 0; + virtual HRESULT __stdcall get_FrameRate( + double *pVal) = 0; + virtual HRESULT __stdcall EnterBitmapGrabMode( + double SeekTime) = 0; +}; + +extern "C" const IID IID_ISampleGrabberCB; +struct +#ifndef __MINGW32__ +__declspec(uuid("0579154A-2B53-4994-B0D0-E773148EFF85")) __declspec(novtable) +#endif +ISampleGrabberCB : public IUnknown +{ +public: + virtual HRESULT __stdcall SampleCB( + double SampleTime, + IMediaSample *pSample) = 0; + virtual HRESULT __stdcall BufferCB( + double SampleTime, + WIN_BYTE *pBuffer, + long BufferLen) = 0; +}; + +extern "C" const IID IID_ISampleGrabber; +struct +#ifndef __MINGW32__ +__declspec(uuid("6B652FFF-11FE-4fce-92AD-0266B5D7C78F")) __declspec(novtable) +#endif +ISampleGrabber : public IUnknown +{ +public: + virtual HRESULT __stdcall SetOneShot( + WIN_BOOL OneShot) = 0; + virtual HRESULT __stdcall SetMediaType( + const AM_MEDIA_TYPE *pType) = 0; + virtual HRESULT __stdcall GetConnectedMediaType( + AM_MEDIA_TYPE *pType) = 0; + virtual HRESULT __stdcall SetBufferSamples( + WIN_BOOL BufferThem) = 0; + virtual HRESULT __stdcall GetCurrentBuffer( + long *pBufferSize, + long *pBuffer) = 0; + virtual HRESULT __stdcall GetCurrentSample( + IMediaSample **ppSample) = 0; + virtual HRESULT __stdcall SetCallback( + ISampleGrabberCB *pCallback, + long WhichMethodToCallback) = 0; + +}; + diff --git a/avmedia/source/win/makefile.mk b/avmedia/source/win/makefile.mk new file mode 100644 index 000000000000..b70841e8bdf7 --- /dev/null +++ b/avmedia/source/win/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmedia +TARGET=avmediawin + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +.IF "$(ENABLE_DIRECTX)" != "" + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +# --- Files ---------------------------------- + +.IF "$(GUI)" == "WNT" + +SLOFILES= \ + $(SLO)$/winuno.obj \ + $(SLO)$/manager.obj \ + $(SLO)$/window.obj \ + $(SLO)$/player.obj \ + $(SLO)$/framegrabber.obj + + +EXCEPTIONSFILES= \ + $(SLO)$/winuno.obj \ + $(SLO)$/framegrabber.obj + +SHL1TARGET=$(TARGET) +SHL1STDLIBS= $(CPPULIB) $(SALLIB) $(COMPHELPERLIB) $(CPPUHELPERLIB) $(UNOTOOLSLIB) $(TOOLSLIB) $(VCLLIB) +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +SHL1STDLIBS += $(OLE32LIB) +SHL1STDLIBS += $(OLEAUT32LIB) +SHL1STDLIBS += $(GDI32LIB) +SHL1STDLIBS += $(DDRAWLIB) + +.IF "$(COM)"=="GCC" +SHL1STDLIBS += $(PSDK_HOME)$/lib$/strmiids.lib +.ELSE +SHL1STDLIBS += strmiids.lib +SHL1STDLIBS += dxguid.lib +.ENDIF + +.ENDIF +.ENDIF + +.INCLUDE : target.mk diff --git a/avmedia/source/win/manager.cxx b/avmedia/source/win/manager.cxx new file mode 100644 index 000000000000..13bc1e4fe593 --- /dev/null +++ b/avmedia/source/win/manager.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "manager.hxx" +#include "player.hxx" + +#include <tools/urlobj.hxx> + +#define AVMEDIA_WIN_MANAGER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Manager_DirectX" +#define AVMEDIA_WIN_MANAGER_SERVICENAME "com.sun.star.media.Manager" + +using namespace ::com::sun::star; + +namespace avmedia { namespace win { +// ---------------- +// - Manager - +// ---------------- + +Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{ +} + +// ------------------------------------------------------------------------------ + +Manager::~Manager() +{ +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const ::rtl::OUString& rURL ) + throw (uno::RuntimeException) +{ + Player* pPlayer( new Player( mxMgr ) ); + uno::Reference< media::XPlayer > xRet( pPlayer ); + const INetURLObject aURL( rURL ); + + if( !pPlayer->create( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) ) + xRet = uno::Reference< media::XPlayer >(); + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Manager::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_WIN_MANAGER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Manager::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_WIN_MANAGER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Manager::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_WIN_MANAGER_SERVICENAME ) ); + + return aRet; +} + +} // namespace win +} // namespace avmedia diff --git a/avmedia/source/win/manager.hxx b/avmedia/source/win/manager.hxx new file mode 100644 index 000000000000..1bb3e530c016 --- /dev/null +++ b/avmedia/source/win/manager.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANAGER_HXX +#define _MANAGER_HXX + +#include "wincommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XMANAGER_HDL_ +#include "com/sun/star/media/XManager.hdl" +#endif + +// ----------- +// - Manager - +// ----------- + +namespace avmedia { namespace win { + +class Manager : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XManager, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Manager(); + + // XManager + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > SAL_CALL createPlayer( const ::rtl::OUString& aURL ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; +}; + +} // namespace win +} // namespace avmedia + +#endif // _MANAGER_HXX diff --git a/avmedia/source/win/player.cxx b/avmedia/source/win/player.cxx new file mode 100644 index 000000000000..d27b2b55ff93 --- /dev/null +++ b/avmedia/source/win/player.cxx @@ -0,0 +1,494 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/prewin.h> +#if defined _MSC_VER +#pragma warning(push, 1) +#pragma warning(disable: 4917) +#endif +#include <windows.h> +#include <objbase.h> +#include <strmif.h> +#include <control.h> +#include <uuids.h> +#include <evcode.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include <tools/postwin.h> + +#include "player.hxx" +#include "framegrabber.hxx" +#include "window.hxx" + +#define AVMEDIA_WIN_PLAYER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Player_DirectX" +#define AVMEDIA_WIN_PLAYER_SERVICENAME "com.sun.star.media.Player_DirectX" + +using namespace ::com::sun::star; + +namespace avmedia { namespace win { + +bool isWindowsVistaOrHigher() +{ + // POST: return true if we are at least on Windows Vista + OSVERSIONINFO osvi; + ZeroMemory(&osvi, sizeof(osvi)); + osvi.dwOSVersionInfoSize = sizeof(osvi); + GetVersionEx(&osvi); + if ( osvi.dwMajorVersion >= 6 ) + return true; + + return false; +} + +// ---------------- +// - Player - +// ---------------- + +Player::Player( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ), + mpGB( NULL ), + mpOMF( NULL ), + mpMC( NULL ), + mpME( NULL ), + mpMS( NULL ), + mpMP( NULL ), + mpBA( NULL ), + mpBV( NULL ), + mpVW( NULL ), + mpEV( NULL ), + mnUnmutedVolume( 0 ), + mbMuted( false ), + mbLooping( false ) +{ + ::CoInitialize( NULL ); +} + +// ------------------------------------------------------------------------------ + +Player::~Player() +{ + if( mpBA ) + mpBA->Release(); + + if( mpBV ) + mpBV->Release(); + + if( mpVW ) + mpVW->Release(); + + if( mpMP ) + mpMP->Release(); + + if( mpMS ) + mpMS->Release(); + + if( mpME ) + mpME->Release(); + + if( mpMC ) + mpMC->Release(); + + if( mpEV ) + mpEV->Release(); + + if( mpOMF ) + mpOMF->Release(); + + if( mpGB ) + mpGB->Release(); + + ::CoUninitialize(); +} + +// ------------------------------------------------------------------------------ + +bool Player::create( const ::rtl::OUString& rURL ) +{ + HRESULT hR; + bool bRet = false; + + if( SUCCEEDED( hR = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**) &mpGB ) ) ) + { + // Don't use the overlay mixer on Windows Vista + // It disables the desktop composition as soon as RenderFile is called + // also causes some other problems: video rendering is not reliable + if( !isWindowsVistaOrHigher() ) + { + if( SUCCEEDED( CoCreateInstance( CLSID_OverlayMixer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &mpOMF ) ) ) + { + mpGB->AddFilter( mpOMF, L"com_sun_star_media_OverlayMixerFilter" ); + + if( !SUCCEEDED( mpOMF->QueryInterface( IID_IDDrawExclModeVideo, (void**) &mpEV ) ) ) + mpEV = NULL; + } + } + + if( SUCCEEDED( hR = mpGB->RenderFile( reinterpret_cast<LPCWSTR>(rURL.getStr()), NULL ) ) && + SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaControl, (void**) &mpMC ) ) && + SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaEventEx, (void**) &mpME ) ) && + SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaSeeking, (void**) &mpMS ) ) && + SUCCEEDED( hR = mpGB->QueryInterface( IID_IMediaPosition, (void**) &mpMP ) ) ) + { + // Video interfaces + mpGB->QueryInterface( IID_IVideoWindow, (void**) &mpVW ); + mpGB->QueryInterface( IID_IBasicVideo, (void**) &mpBV ); + + // Audio interface + mpGB->QueryInterface( IID_IBasicAudio, (void**) &mpBA ); + + if( mpBA ) + mpBA->put_Volume( mnUnmutedVolume ); + + bRet = true; + } + } + + if( bRet ) + maURL = rURL; + else + maURL = ::rtl::OUString(); + + return bRet; +} + +// ------------------------------------------------------------------------------ + +const IVideoWindow* Player::getVideoWindow() const +{ + return mpVW; +} + +// ------------------------------------------------------------------------------ + +void Player::setNotifyWnd( int nNotifyWnd ) +{ + if( mpME ) + mpME->SetNotifyWindow( (OAHWND) nNotifyWnd, WM_GRAPHNOTIFY, reinterpret_cast< LONG_PTR>( this ) ); +} + +// ------------------------------------------------------------------------------ + +void Player::setDDrawParams( IDirectDraw* pDDraw, IDirectDrawSurface* pDDrawSurface ) +{ + if( mpEV && pDDraw && pDDrawSurface ) + { + mpEV->SetDDrawObject( pDDraw ); + mpEV->SetDDrawSurface( pDDrawSurface ); + } +} + +// ------------------------------------------------------------------------------ + +long Player::processEvent() +{ + long nCode, nParam1, nParam2; + + if( mpME && SUCCEEDED( mpME->GetEvent( &nCode, &nParam1, &nParam2, 0 ) ) ) + { + if( EC_COMPLETE == nCode ) + { + if( mbLooping ) + { + setMediaTime( 0.0 ); + start(); + } + else + { + setMediaTime( getDuration() ); + stop(); + } + } + + mpME->FreeEventParams( nCode, nParam1, nParam2 ); + } + + return 0; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::start( ) + throw (uno::RuntimeException) +{ + if( mpMC ) + mpMC->Run(); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::stop( ) + throw (uno::RuntimeException) +{ + if( mpMC ) + mpMC->Stop(); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaying() + throw (uno::RuntimeException) +{ + OAFilterState eFilterState; + bool bRet = false; + + if( mpMC && SUCCEEDED( mpMC->GetState( 10, &eFilterState ) ) ) + bRet = ( State_Running == eFilterState ); + + return bRet; +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getDuration( ) + throw (uno::RuntimeException) +{ + REFTIME aRefTime( 0.0 ); + + if( mpMP ) + mpMP->get_Duration( &aRefTime ); + + return aRefTime; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMediaTime( double fTime ) + throw (uno::RuntimeException) +{ + if( mpMP ) + { + const bool bPlaying = isPlaying(); + + mpMP->put_CurrentPosition( fTime ); + + if( !bPlaying && mpMC ) + mpMC->StopWhenReady(); + } +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getMediaTime( ) + throw (uno::RuntimeException) +{ + REFTIME aRefTime( 0.0 ); + + if( mpMP ) + mpMP->get_CurrentPosition( &aRefTime ); + + return aRefTime; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setStopTime( double fTime ) + throw (uno::RuntimeException) +{ + if( mpMP ) + mpMP->put_StopTime( fTime ); +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getStopTime( ) + throw (uno::RuntimeException) +{ + REFTIME aRefTime( 0.0 ); + + if( mpMP ) + mpMP->get_StopTime( &aRefTime ); + + return aRefTime; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setRate( double fRate ) + throw (uno::RuntimeException) +{ + if( mpMP ) + mpMP->put_Rate( fRate ); +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getRate( ) + throw (uno::RuntimeException) +{ + double fRet( 0.0 ); + + if( mpMP ) + mpMP->get_Rate( &fRet ); + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setPlaybackLoop( sal_Bool bSet ) + throw (uno::RuntimeException) +{ + mbLooping = bSet; +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaybackLoop( ) + throw (uno::RuntimeException) +{ + return mbLooping; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMute( sal_Bool bSet ) + throw (uno::RuntimeException) +{ + if( mpBA && ( mbMuted != bSet ) ) + { + mbMuted = bSet; + mpBA->put_Volume( mbMuted ? -10000 : mnUnmutedVolume ); + } +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isMute( ) + throw (uno::RuntimeException) +{ + return mbMuted; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB ) + throw (uno::RuntimeException) +{ + mnUnmutedVolume = static_cast< long >( nVolumeDB ) * 100; + + if( !mbMuted && mpBA ) + mpBA->put_Volume( mnUnmutedVolume ); +} + +// ------------------------------------------------------------------------------ + +sal_Int16 SAL_CALL Player::getVolumeDB( ) + throw (uno::RuntimeException) +{ + return( static_cast< sal_Int16 >( mnUnmutedVolume / 100 ) ); +} + +// ------------------------------------------------------------------------------ + +awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( ) + throw (uno::RuntimeException) +{ + awt::Size aSize( 0, 0 ); + + if( mpBV ) + { + long nWidth = 0, nHeight = 0; + + mpBV->GetVideoSize( &nWidth, &nHeight ); + aSize.Width = nWidth; + aSize.Height = nHeight; + } + + return aSize; +} + +// ------------------------------------------------------------------------------ + +uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments ) + throw (uno::RuntimeException) +{ + uno::Reference< ::media::XPlayerWindow > xRet; + awt::Size aSize( getPreferredPlayerWindowSize() ); + + if( mpVW && aSize.Width > 0 && aSize.Height > 0 ) + { + ::avmedia::win::Window* pWindow = new ::avmedia::win::Window( mxMgr, *this ); + + xRet = pWindow; + + if( !pWindow->create( aArguments ) ) + xRet = uno::Reference< ::media::XPlayerWindow >(); + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber( ) + throw (uno::RuntimeException) +{ + uno::Reference< media::XFrameGrabber > xRet; + + if( maURL.getLength() > 0 ) + { + FrameGrabber* pGrabber = new FrameGrabber( mxMgr ); + + xRet = pGrabber; + + if( !pGrabber->create( maURL ) ) + xRet.clear(); + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Player::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_WIN_PLAYER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_WIN_PLAYER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Player::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_WIN_PLAYER_SERVICENAME ) ); + + return aRet; +} + +} // namespace win +} // namespace avmedia diff --git a/avmedia/source/win/player.hxx b/avmedia/source/win/player.hxx new file mode 100644 index 000000000000..34a567750b74 --- /dev/null +++ b/avmedia/source/win/player.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _PLAYER_HXX +#define _PLAYER_HXX + +#include "wincommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYER_HDL_ +#include "com/sun/star/media/XPlayer.hdl" +#endif + +struct IGraphBuilder; +struct IBaseFilter; +struct IMediaControl; +struct IMediaEventEx; +struct IMediaSeeking; +struct IMediaPosition; +struct IBasicAudio; +struct IBasicVideo; +struct IVideoWindow; +struct IDDrawExclModeVideo; +struct IDirectDraw; +struct IDirectDrawSurface; + +namespace avmedia { namespace win { + +// ---------- +// - Player - +// ---------- + +class Player : public ::cppu::WeakImplHelper2< ::com::sun::star::media::XPlayer, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Player( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Player(); + + bool create( const ::rtl::OUString& rURL ); + + void setNotifyWnd( int nNotifyWnd ); + void setDDrawParams( IDirectDraw* pDDraw, IDirectDrawSurface* pDDrawSurface ); + long processEvent(); + + const IVideoWindow* getVideoWindow() const; + + // XPlayer + virtual void SAL_CALL start( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL stop( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaying( ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getDuration( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMediaTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getMediaTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setStopTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getStopTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRate( double fRate ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getRate( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaybackLoop( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMute( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isMute( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getVolumeDB( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + + ::rtl::OUString maURL; + IGraphBuilder* mpGB; + IBaseFilter* mpOMF; + IMediaControl* mpMC; + IMediaEventEx* mpME; + IMediaSeeking* mpMS; + IMediaPosition* mpMP; + IBasicAudio* mpBA; + IBasicVideo* mpBV; + IVideoWindow* mpVW; + IDDrawExclModeVideo* mpEV; + long mnUnmutedVolume; + sal_Bool mbMuted; + sal_Bool mbLooping; + + void ImplLayoutVideoWindow(); +}; + +} // namespace win +} // namespace avmedia + +#endif // _PLAYER_HXX diff --git a/avmedia/source/win/wincommon.hxx b/avmedia/source/win/wincommon.hxx new file mode 100644 index 000000000000..502f4300273a --- /dev/null +++ b/avmedia/source/win/wincommon.hxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WINCOMMON_HXX +#define _WINCOMMON_HXX + +#include <osl/mutex.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <tools/stream.hxx> +#include <tools/string.hxx> +#include <tools/urlobj.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/media/XManager.hpp> + +#define WM_GRAPHNOTIFY (WM_USER + 567) + +#endif // _WINCOMMOM_HXX diff --git a/avmedia/source/win/window.cxx b/avmedia/source/win/window.cxx new file mode 100644 index 000000000000..1170505b440b --- /dev/null +++ b/avmedia/source/win/window.cxx @@ -0,0 +1,740 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/prewin.h> +#if defined _MSC_VER +#pragma warning(push, 1) +#pragma warning(disable: 4917) +#endif +#include <windows.h> +#include <objbase.h> +#include <strmif.h> +#include <control.h> +#include <dshow.h> +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include <tools/postwin.h> +#include <com/sun/star/awt/SystemPointer.hdl> + +#include "window.hxx" +#include "player.hxx" + +#define AVMEDIA_WIN_WINDOW_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Window_DirectX" +#define AVMEDIA_WIN_WINDOW_SERVICENAME "com.sun.star.media.Window_DirectX" + +using namespace ::com::sun::star; + +namespace avmedia { namespace win { + +// ----------- +// - statics - +// ----------- + +static ::osl::Mutex& ImplGetOwnStaticMutex() +{ + static ::osl::Mutex* pMutex = NULL; + + if( pMutex == NULL ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + + if( pMutex == NULL ) + { + static ::osl::Mutex aMutex; + pMutex = &aMutex; + } + } + + return *pMutex; +} + +// ----------- +// - WndProc - +// ----------- + +LRESULT CALLBACK MediaPlayerWndProc( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 ) +{ + Window* pWindow = (Window*) ::GetWindowLong( hWnd, 0 ); + bool bProcessed = true; + + if( pWindow ) + { + switch( nMsg ) + { + case( WM_SETCURSOR ): + pWindow->updatePointer(); + break; + + case( WM_GRAPHNOTIFY ): + pWindow->processGraphEvent(); + break; + + case( WM_MOUSEMOVE ): + case( WM_LBUTTONDOWN ): + case( WM_MBUTTONDOWN ): + case( WM_RBUTTONDOWN ): + case( WM_LBUTTONUP ): + case( WM_MBUTTONUP ): + case( WM_RBUTTONUP ): + { + awt::MouseEvent aUNOEvt; + POINT aWinPoint; + + if( !::GetCursorPos( &aWinPoint ) || !::ScreenToClient( hWnd, &aWinPoint ) ) + { + aWinPoint.x = GET_X_LPARAM( nPar2 ); + aWinPoint.y = GET_Y_LPARAM( nPar2 ); + } + aUNOEvt.Modifiers = 0; + aUNOEvt.Buttons = 0; + aUNOEvt.X = aWinPoint.x; + aUNOEvt.Y = aWinPoint.y; + aUNOEvt.PopupTrigger = false; + + // Modifiers + if( nPar1 & MK_SHIFT ) + aUNOEvt.Modifiers |= awt::KeyModifier::SHIFT; + + if( nPar1 & MK_CONTROL ) + aUNOEvt.Modifiers |= awt::KeyModifier::MOD1; + + // Buttons + if( WM_LBUTTONDOWN == nMsg || WM_LBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::LEFT; + + if( WM_MBUTTONDOWN == nMsg || WM_MBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::MIDDLE; + + if( WM_RBUTTONDOWN == nMsg || WM_RBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::RIGHT; + + // event type + if( WM_LBUTTONDOWN == nMsg || + WM_MBUTTONDOWN == nMsg || + WM_RBUTTONDOWN == nMsg ) + { + aUNOEvt.ClickCount = 1; + pWindow->fireMousePressedEvent( aUNOEvt ); + } + else if( WM_LBUTTONUP == nMsg || + WM_MBUTTONUP == nMsg || + WM_RBUTTONUP == nMsg ) + { + aUNOEvt.ClickCount = 1; + pWindow->fireMouseReleasedEvent( aUNOEvt ); + } + else if( WM_MOUSEMOVE == nMsg ) + { + aUNOEvt.ClickCount = 0; + pWindow->fireMouseMovedEvent( aUNOEvt ); + pWindow->updatePointer(); + } + } + break; + + case( WM_SETFOCUS ): + { + const awt::FocusEvent aUNOEvt; + pWindow->fireSetFocusEvent( aUNOEvt ); + } + break; + + default: + bProcessed = false; + break; + } + } + else + bProcessed = false; + + return( bProcessed ? 0 : DefWindowProc( hWnd, nMsg, nPar1, nPar2 ) ); +} + +// --------------- +// - Window - +// --------------- + +WNDCLASS* Window::mpWndClass = NULL; + +// ------------------------------------------------------------------------------ + +Window::Window( const uno::Reference< lang::XMultiServiceFactory >& rxMgr, Player& rPlayer ) : + mxMgr( rxMgr ), + mrPlayer( rPlayer ), + meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ), + mnParentWnd( 0 ), + mnFrameWnd( 0 ), + maListeners( maMutex ), + mnPointerType( awt::SystemPointer::ARROW ) +{ + ::osl::MutexGuard aGuard( ImplGetOwnStaticMutex() ); + + if( !mpWndClass ) + { + mpWndClass = new WNDCLASS; + + memset( mpWndClass, 0, sizeof( *mpWndClass ) ); + mpWndClass->hInstance = GetModuleHandle( NULL ); + mpWndClass->cbWndExtra = sizeof( DWORD ); + mpWndClass->lpfnWndProc = MediaPlayerWndProc; + mpWndClass->lpszClassName = "com_sun_star_media_PlayerWnd"; + mpWndClass->hbrBackground = (HBRUSH) ::GetStockObject( BLACK_BRUSH ); + mpWndClass->hCursor = ::LoadCursor( NULL, IDC_ARROW ); + + ::RegisterClass( mpWndClass ); + } +} + +// ------------------------------------------------------------------------------ + +Window::~Window() +{ + if( mnFrameWnd ) + ::DestroyWindow( (HWND) mnFrameWnd ); +} + +// ------------------------------------------------------------------------------ + +void Window::ImplLayoutVideoWindow() +{ + if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel ) + { + awt::Size aPrefSize( mrPlayer.getPreferredPlayerWindowSize() ); + awt::Rectangle aRect = getPosSize(); + int nW = aRect.Width, nH = aRect.Height; + int nVideoW = nW, nVideoH = nH; + int nX = 0, nY = 0, nWidth = 0, nHeight = 0; + bool bDone = false, bZoom = false; + + if( media::ZoomLevel_ORIGINAL == meZoomLevel ) + { + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_4 == meZoomLevel ) + { + aPrefSize.Width >>= 2; + aPrefSize.Height >>= 2; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_2 == meZoomLevel ) + { + aPrefSize.Width >>= 1; + aPrefSize.Height >>= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_2_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 1; + aPrefSize.Height <<= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_4_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 2; + aPrefSize.Height <<= 2; + bZoom = true; + } + else if( media::ZoomLevel_FIT_TO_WINDOW == meZoomLevel ) + { + nWidth = nVideoW; + nHeight = nVideoH; + bDone = true; + } + + if( bZoom ) + { + if( ( aPrefSize.Width <= nVideoW ) && ( aPrefSize.Height <= nVideoH ) ) + { + nX = ( nVideoW - aPrefSize.Width ) >> 1; + nY = ( nVideoH - aPrefSize.Height ) >> 1; + nWidth = aPrefSize.Width; + nHeight = aPrefSize.Height; + bDone = true; + } + } + + if( !bDone ) + { + if( aPrefSize.Width > 0 && aPrefSize.Height > 0 && nVideoW > 0 && nVideoH > 0 ) + { + double fPrefWH = (double) aPrefSize.Width / aPrefSize.Height; + + if( fPrefWH < ( (double) nVideoW / nVideoH ) ) + nVideoW = (int)( nVideoH * fPrefWH ); + else + nVideoH = (int)( nVideoW / fPrefWH ); + + nX = ( nW - nVideoW ) >> 1; + nY = ( nH - nVideoH ) >> 1; + nWidth = nVideoW; + nHeight = nVideoH; + } + else + nX = nY = nWidth = nHeight = 0; + } + + IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() ); + + if( pVideoWindow ) + pVideoWindow->SetWindowPosition( nX, nY, nWidth, nHeight ); + } +} + +// ------------------------------------------------------------------------------ + +bool Window::create( const uno::Sequence< uno::Any >& rArguments ) +{ + IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() ); + + if( !mnFrameWnd && pVideoWindow && mpWndClass ) + { + awt::Rectangle aRect; + sal_IntPtr nWnd; + + rArguments[ 0 ] >>= nWnd; + rArguments[ 1 ] >>= aRect; + + mnParentWnd = static_cast<int>(nWnd); + + mnFrameWnd = (int) ::CreateWindow( mpWndClass->lpszClassName, NULL, + WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + aRect.X, aRect.Y, aRect.Width, aRect.Height, + (HWND) mnParentWnd, NULL, mpWndClass->hInstance, 0 ); + + // if the last CreateWindow failed... + if( mnFrameWnd == 0 ) + { + // try again and this time assume that mnParent is indeed a dc + mnParentWnd = reinterpret_cast<int>(::WindowFromDC( (HDC)mnParentWnd )); + mnFrameWnd = (int) ::CreateWindow( mpWndClass->lpszClassName, NULL, + WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + aRect.X, aRect.Y, aRect.Width, aRect.Height, + (HWND)mnParentWnd , NULL, mpWndClass->hInstance, 0 ); + } + + if( mnFrameWnd ) + { + ::SetWindowLong( (HWND) mnFrameWnd, 0, (DWORD) this ); + +#ifdef DDRAW_TEST_OUTPUT + IDirectDraw7* pDDraw; + IDirectDrawSurface7* pDDSurface; + IDirectDrawClipper* pDDClipper; + + if( DD_OK == DirectDrawCreateEx( NULL, (void**) &pDDraw, IID_IDirectDraw7, NULL ) ) + { + if( DD_OK == pDDraw->SetCooperativeLevel( (HWND) mnParentWnd, DDSCL_NORMAL ) ) + { + DDSURFACEDESC2 aDDDesc; + + memset( &aDDDesc, 0, sizeof( aDDDesc ) ); + aDDDesc.dwSize = sizeof( aDDDesc ); + aDDDesc.dwFlags = DDSD_CAPS; + aDDDesc.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE; + + if( DD_OK == pDDraw->CreateSurface( &aDDDesc, &pDDSurface, NULL ) ) + { + if( DD_OK == pDDraw->CreateClipper( 0, &pDDClipper, NULL ) ) + { + pDDClipper->SetHWnd( 0, (HWND) mnFrameWnd ); + pDDSurface->SetClipper( pDDClipper ); + } + + mrPlayer.setDDrawParams( (IDirectDraw*) pDDraw, (IDirectDrawSurface*) pDDSurface ); +#endif + + pVideoWindow->put_Owner( (OAHWND) mnFrameWnd ); + pVideoWindow->put_MessageDrain( (OAHWND) mnFrameWnd ); + pVideoWindow->put_WindowStyle( WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN ); + + mrPlayer.setNotifyWnd( mnFrameWnd ); + + meZoomLevel = media::ZoomLevel_ORIGINAL; + ImplLayoutVideoWindow(); +#ifdef DDRAW_TEST_OUTPUT + } + } + } +#endif + } + } + + return( mnFrameWnd != 0 ); +} + +// ------------------------------------------------------------------------------ + +void Window::processGraphEvent() +{ + mrPlayer.processEvent(); +} + +// ------------------------------------------------------------------------------ + +void Window::updatePointer() +{ + char* pCursorName; + + switch( mnPointerType ) + { + case( awt::SystemPointer::CROSS ): pCursorName = IDC_CROSS; break; + //case( awt::SystemPointer::HAND ): pCursorName = IDC_HAND; break; + case( awt::SystemPointer::MOVE ): pCursorName = IDC_SIZEALL; break; + case( awt::SystemPointer::WAIT ): pCursorName = IDC_WAIT; break; + + default: + pCursorName = IDC_ARROW; + break; + } + + ::SetCursor( ::LoadCursor( NULL, pCursorName ) ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::update( ) + throw (uno::RuntimeException) +{ + ::RedrawWindow( (HWND) mnFrameWnd, NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) + throw (uno::RuntimeException) +{ + boolean bRet = false; + + if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel && + media::ZoomLevel_NOT_AVAILABLE != eZoomLevel ) + { + if( eZoomLevel != meZoomLevel ) + { + meZoomLevel = eZoomLevel; + ImplLayoutVideoWindow(); + } + + bRet = true; + } + + return bRet; +} + +// ------------------------------------------------------------------------------ + +media::ZoomLevel SAL_CALL Window::getZoomLevel( ) + throw (uno::RuntimeException) +{ + return meZoomLevel; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) + throw (uno::RuntimeException) +{ + mnPointerType = nPointerType; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 ) + throw (uno::RuntimeException) +{ + if( mnFrameWnd ) + { + ::SetWindowPos( (HWND) mnFrameWnd, HWND_TOP, X, Y, Width, Height, 0 ); + ImplLayoutVideoWindow(); + } +} + +// ------------------------------------------------------------------------------ + +awt::Rectangle SAL_CALL Window::getPosSize() + throw (uno::RuntimeException) +{ + awt::Rectangle aRet; + + if( mnFrameWnd ) + { + ::RECT aWndRect; + + if( ::GetClientRect( (HWND) mnFrameWnd, &aWndRect ) ) + { + aRet.X = aWndRect.left; + aRet.Y = aWndRect.top; + aRet.Width = aWndRect.right - aWndRect.left + 1; + aRet.Height = aWndRect.bottom - aWndRect.top + 1; + } + } + + return aRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setVisible( sal_Bool bVisible ) + throw (uno::RuntimeException) +{ + if( mnFrameWnd ) + { + IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() ); + + if( pVideoWindow ) + pVideoWindow->put_Visible( bVisible ? OATRUE : OAFALSE ); + + ::ShowWindow( (HWND) mnFrameWnd, bVisible ? SW_SHOW : SW_HIDE ); + } +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setEnable( sal_Bool bEnable ) + throw (uno::RuntimeException) +{ + if( mnFrameWnd ) + ::EnableWindow( (HWND) mnFrameWnd, bEnable ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setFocus( ) + throw (uno::RuntimeException) +{ + if( mnFrameWnd ) + ::SetFocus( (HWND) mnFrameWnd ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::dispose( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mousePressed( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mouseReleased( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseMotionListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseMotionListener >( aIter.next(), uno::UNO_QUERY )->mouseMoved( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XFocusListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XFocusListener >( aIter.next(), uno::UNO_QUERY )->focusGained( rEvt ); + } +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Window::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_WIN_WINDOW_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_WIN_WINDOW_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_WIN_WINDOW_SERVICENAME ) ); + + return aRet; +} + +} // namespace win +} // namespace avmedia diff --git a/avmedia/source/win/window.hxx b/avmedia/source/win/window.hxx new file mode 100644 index 000000000000..36cff49a742a --- /dev/null +++ b/avmedia/source/win/window.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WINDOW_HXX +#define _WINDOW_HXX + +#include "wincommon.hxx" +#include <cppuhelper/interfacecontainer.h> + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYERWINDOW_HDL_ +#include "com/sun/star/media/XPlayerWindow.hdl" +#endif + +struct IVideoWindow; + +namespace avmedia { namespace win { + +// --------------- +// - Window - +// --------------- + +class Player; + +class Window : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XPlayerWindow, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Window( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr, + Player& rPlayer ); + ~Window(); + + bool create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + void processGraphEvent(); + void updatePointer(); + + // XPlayerWindow + virtual void SAL_CALL update( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL setZoomLevel( ::com::sun::star::media::ZoomLevel ZoomLevel ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::media::ZoomLevel SAL_CALL getZoomLevel( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPointerType( sal_Int32 nPointerType ) throw (::com::sun::star::uno::RuntimeException); + + // XWindow + virtual void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool Visible ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setEnable( sal_Bool Enable ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setFocus( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +public: + + void fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireKeyPressedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + void fireKeyReleasedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + void fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; + + ::osl::Mutex maMutex; + ::cppu::OMultiTypeInterfaceContainerHelper maListeners; + ::com::sun::star::media::ZoomLevel meZoomLevel; + Player& mrPlayer; + int mnFrameWnd; + int mnParentWnd; + int mnPointerType; + + static WNDCLASS* mpWndClass; + + void ImplLayoutVideoWindow(); +}; + +} // namespace win +} // namespace avmedia + +#endif // _WINDOW_HXX diff --git a/avmedia/source/win/winuno.cxx b/avmedia/source/win/winuno.cxx new file mode 100644 index 000000000000..645871290413 --- /dev/null +++ b/avmedia/source/win/winuno.cxx @@ -0,0 +1,104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wincommon.hxx" +#include "manager.hxx" + +using namespace ::com::sun::star; + +// ------------------- +// - factory methods - +// ------------------- + +static uno::Reference< uno::XInterface > SAL_CALL create_MediaPlayer( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) +{ + return uno::Reference< uno::XInterface >( *new ::avmedia::win::Manager( rxFact ) ); +} + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void*, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + uno::Reference< registry::XRegistryKey > xNewKey1( + static_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( + ::rtl::OUString::createFromAscii( "/com.sun.star.comp.avmedia.Manager_DirectX/UNO/SERVICES/com.sun.star.media.Manager_DirectX" ) ) ); + + bRet = sal_True; + } + catch( registry::InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* ) +{ + uno::Reference< lang::XSingleServiceFactory > xFactory; + void* pRet = 0; + + if( rtl_str_compare( pImplName, "com.sun.star.comp.avmedia.Manager_DirectX" ) == 0 ) + { + const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( "com.sun.star.media.Manager_DirectX" ) ); + + xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory( + reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), + ::rtl::OUString::createFromAscii( "com.sun.star.comp.avmedia.Manager_DirectX" ), + create_MediaPlayer, uno::Sequence< ::rtl::OUString >( &aServiceName, 1 ) ) ); + } + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} diff --git a/avmedia/source/xine/exports.dxp b/avmedia/source/xine/exports.dxp new file mode 100644 index 000000000000..db9c0a52f288 --- /dev/null +++ b/avmedia/source/xine/exports.dxp @@ -0,0 +1,4 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory + diff --git a/avmedia/source/xine/makefile.mk b/avmedia/source/xine/makefile.mk new file mode 100644 index 000000000000..3ba341c0d32b --- /dev/null +++ b/avmedia/source/xine/makefile.mk @@ -0,0 +1,64 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmediaxine +TARGET=avmediaxine + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +.IF "$(verbose)"!="" || "$(VERBOSE)"!="" +CDEFS+= -DVERBOSE +.ENDIF + +# --- Files ---------------------------------- + +.IF "$(GUI)" == "UNX" && "$(GUIBASE)"!="aqua" + +SLOFILES= \ + $(SLO)$/xineuno.obj \ + $(SLO)$/manager.obj \ + $(SLO)$/window.obj \ + $(SLO)$/player.obj + +EXCEPTIONSFILES= \ + $(SLO)$/xineuno.obj + +SHL1TARGET=$(TARGET) +SHL1STDLIBS= $(CPPULIB) $(SALLIB) $(COMPHELPERLIB) $(CPPUHELPERLIB) +SHL1IMPLIB=i$(TARGET) +SHL1LIBS=$(SLB)$/$(TARGET).lib +SHL1DEF=$(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +.ENDIF + +.INCLUDE : target.mk diff --git a/avmedia/source/xine/manager.cxx b/avmedia/source/xine/manager.cxx new file mode 100644 index 000000000000..8fa1f27129b9 --- /dev/null +++ b/avmedia/source/xine/manager.cxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "manager.hxx" +#include "player.hxx" + +using namespace ::com::sun::star; + +namespace avmedia { namespace xine { +// ---------------- +// - Manager - +// ---------------- + +Manager::Manager( const uno::Reference< lang::XMultiServiceFactory >& rxMgr ) : + mxMgr( rxMgr ) +{ +} + +// ------------------------------------------------------------------------------ + +Manager::~Manager() +{ +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XPlayer > SAL_CALL Manager::createPlayer( const ::rtl::OUString& aURL ) + throw (uno::RuntimeException) +{ + Player* pPlayer( new Player ); + uno::Reference< media::XPlayer > xRet( pPlayer ); + + if( !pPlayer->create( aURL ) ) + xRet = uno::Reference< media::XPlayer >(); + + return xRet; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Manager::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_XINE_MANAGER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Manager::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_XINE_MANAGER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Manager::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_XINE_MANAGER_SERVICENAME ) ); + + return aRet; +} + +} // namespace xine +} // namespace avmedia diff --git a/avmedia/source/xine/manager.hxx b/avmedia/source/xine/manager.hxx new file mode 100644 index 000000000000..b8faf2774f73 --- /dev/null +++ b/avmedia/source/xine/manager.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _MANAGER_HXX +#define _MANAGER_HXX + +#include "xinecommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XMANAGER_HDL_ +#include "com/sun/star/media/XManager.hdl" +#endif + +// ----------- +// - Manager - +// ----------- + +namespace avmedia { namespace xine { + +class Manager : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XManager, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Manager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMgr ); + ~Manager(); + + // XManager + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > SAL_CALL createPlayer( const ::rtl::OUString& aURL ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMgr; +}; + +} // namespace xine +} // namespace avmedia + +#endif // _MANAGER_HXX diff --git a/avmedia/source/xine/player.cxx b/avmedia/source/xine/player.cxx new file mode 100644 index 000000000000..e343bf2c0dcf --- /dev/null +++ b/avmedia/source/xine/player.cxx @@ -0,0 +1,262 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "player.hxx" +#include "window.hxx" + +using namespace ::com::sun::star; + +namespace avmedia { namespace xine { + +// ---------------- +// - Player - +// ---------------- + +Player::Player() +{ +} + +// ------------------------------------------------------------------------------ + +Player::~Player() +{ +} + +// ------------------------------------------------------------------------------ + +bool Player::create( const ::rtl::OUString& /* rURL */ ) +{ + bool bRet = false; + + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::start( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::stop( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaying() + throw (uno::RuntimeException) +{ + bool bRet = false; + + return bRet; +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getDuration( ) + throw (uno::RuntimeException) +{ + double fRet = 0.0; + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMediaTime( double /* fTime */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getMediaTime( ) + throw (uno::RuntimeException) +{ + double fRet = 0.0; + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setStopTime( double /* fTime */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getStopTime( ) + throw (uno::RuntimeException) +{ + double fRet = 0.0; + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setRate( double /* fRate */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +double SAL_CALL Player::getRate( ) + throw (uno::RuntimeException) +{ + double fRet = 0.0; + + return fRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setPlaybackLoop( sal_Bool /* bSet */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isPlaybackLoop( ) + throw (uno::RuntimeException) +{ + bool bRet = false; + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setMute( sal_Bool /* bSet */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::isMute( ) + throw (uno::RuntimeException) +{ + bool bRet = false; + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Player::setVolumeDB( sal_Int16 /* nVolumeDB */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +sal_Int16 SAL_CALL Player::getVolumeDB( ) + throw (uno::RuntimeException) +{ + sal_Int16 nRet = 0; + + return nRet; +} + +// ------------------------------------------------------------------------------ + +awt::Size SAL_CALL Player::getPreferredPlayerWindowSize( ) + throw (uno::RuntimeException) +{ + awt::Size aSize( 0, 0 ); + + return aSize; +} + +// ------------------------------------------------------------------------------ + +uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( const uno::Sequence< uno::Any >& aArguments ) + throw (uno::RuntimeException) +{ + uno::Reference< ::media::XPlayerWindow > xRet; + awt::Size aSize( getPreferredPlayerWindowSize() ); + + if( aSize.Width > 0 && aSize.Height > 0 ) + { + ::avmedia::xine::Window* pWindow = new ::avmedia::xine::Window( *this ); + + xRet = pWindow; + + if( !pWindow->create( aArguments ) ) + xRet = uno::Reference< ::media::XPlayerWindow >(); + } + + return xRet; +} + +// ------------------------------------------------------------------------------ + +uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber( ) + throw (::com::sun::star::uno::RuntimeException) +{ + return NULL; +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Player::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_XINE_PLAYER_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_XINE_PLAYER_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Player::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_XINE_PLAYER_SERVICENAME ) ); + + return aRet; +} + +} // namespace xine +} // namespace avmedia diff --git a/avmedia/source/xine/player.hxx b/avmedia/source/xine/player.hxx new file mode 100644 index 000000000000..b1e18613fbeb --- /dev/null +++ b/avmedia/source/xine/player.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _PLAYER_HXX +#define _PLAYER_HXX + +#include "xinecommon.hxx" + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYER_HDL_ +#include "com/sun/star/media/XPlayer.hdl" +#endif + +namespace avmedia { namespace xine { + +// ---------- +// - Player - +// ---------- + +class Player : public ::cppu::WeakImplHelper2< ::com::sun::star::media::XPlayer, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Player(); + ~Player(); + + bool create( const ::rtl::OUString& rURL ); + + // XPlayer + virtual void SAL_CALL start( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL stop( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaying( ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getDuration( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMediaTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getMediaTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setStopTime( double fTime ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getStopTime( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRate( double fRate ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getRate( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPlaybackLoop( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isPlaybackLoop( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setMute( sal_Bool bSet ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isMute( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVolumeDB( sal_Int16 nVolumeDB ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getVolumeDB( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getPreferredPlayerWindowSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayerWindow > SAL_CALL createPlayerWindow( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::media::XFrameGrabber > SAL_CALL createFrameGrabber( ) throw (::com::sun::star::uno::RuntimeException); + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +private: +}; + +} // namespace xine +} // namespace avmedia + +#endif // _PLAYER_HXX diff --git a/avmedia/source/xine/window.cxx b/avmedia/source/xine/window.cxx new file mode 100644 index 000000000000..fb4f428c65fd --- /dev/null +++ b/avmedia/source/xine/window.cxx @@ -0,0 +1,571 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/awt/SystemPointer.hdl> + +#include "window.hxx" +#include "player.hxx" + +using namespace ::com::sun::star; + +namespace avmedia { namespace xine { + +// ----------- +// - statics - +// ----------- + +static ::osl::Mutex& ImplGetOwnStaticMutex() +{ + static ::osl::Mutex* pMutex = NULL; + + if( pMutex == NULL ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + + if( pMutex == NULL ) + { + static ::osl::Mutex aMutex; + pMutex = &aMutex; + } + } + + return *pMutex; +} + +// ----------- +// - WndProc - +// ----------- + +/* +LRESULT CALLBACK MediaPlayerWndProc( HWND hWnd,UINT nMsg, WPARAM nPar1, LPARAM nPar2 ) +{ + Window* pWindow = (Window*) ::GetWindowLong( hWnd, 0 ); + bool bProcessed = true; + + if( pWindow ) + { + switch( nMsg ) + { + case( WM_SETCURSOR ): + pWindow->updatePointer(); + break; + + case( WM_GRAPHNOTIFY ): + pWindow->processGraphEvent(); + break; + + case( WM_MOUSEMOVE ): + case( WM_LBUTTONDOWN ): + case( WM_MBUTTONDOWN ): + case( WM_RBUTTONDOWN ): + case( WM_LBUTTONUP ): + case( WM_MBUTTONUP ): + case( WM_RBUTTONUP ): + { + awt::MouseEvent aUNOEvt; + POINT aWinPoint; + + if( !::GetCursorPos( &aWinPoint ) || !::ScreenToClient( hWnd, &aWinPoint ) ) + { + aWinPoint.x = GET_X_LPARAM( nPar2 ); + aWinPoint.y = GET_Y_LPARAM( nPar2 ); + } + aUNOEvt.Modifiers = 0; + aUNOEvt.Buttons = 0; + aUNOEvt.X = aWinPoint.x; + aUNOEvt.Y = aWinPoint.y; + aUNOEvt.PopupTrigger = false; + + // Modifiers + if( nPar1 & MK_SHIFT ) + aUNOEvt.Modifiers |= awt::KeyModifier::SHIFT; + + if( nPar1 & MK_CONTROL ) + aUNOEvt.Modifiers |= awt::KeyModifier::MOD1; + + // Buttons + if( WM_LBUTTONDOWN == nMsg || WM_LBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::LEFT; + + if( WM_MBUTTONDOWN == nMsg || WM_MBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::MIDDLE; + + if( WM_RBUTTONDOWN == nMsg || WM_RBUTTONUP == nMsg ) + aUNOEvt.Buttons |= awt::MouseButton::RIGHT; + + // event type + if( WM_LBUTTONDOWN == nMsg || + WM_MBUTTONDOWN == nMsg || + WM_RBUTTONDOWN == nMsg ) + { + aUNOEvt.ClickCount = 1; + pWindow->fireMousePressedEvent( aUNOEvt ); + } + else if( WM_LBUTTONUP == nMsg || + WM_MBUTTONUP == nMsg || + WM_RBUTTONUP == nMsg ) + { + aUNOEvt.ClickCount = 1; + pWindow->fireMouseReleasedEvent( aUNOEvt ); + } + else if( WM_MOUSEMOVE == nMsg ) + { + aUNOEvt.ClickCount = 0; + pWindow->fireMouseMovedEvent( aUNOEvt ); + pWindow->updatePointer(); + } + } + break; + + case( WM_SETFOCUS ): + { + const awt::FocusEvent aUNOEvt; + pWindow->fireSetFocusEvent( aUNOEvt ); + } + break; + + default: + bProcessed = false; + break; + } + } + else + bProcessed = false; + + return( bProcessed ? 0 : DefWindowProc( hWnd, nMsg, nPar1, nPar2 ) ); +} +*/ + +// --------------- +// - Window - +// --------------- + +Window::Window( Player& rPlayer ) : + mrPlayer( rPlayer ), + maListeners( maMutex ), + meZoomLevel( media::ZoomLevel_NOT_AVAILABLE ), + mnPointerType( awt::SystemPointer::ARROW ) +{ + ::osl::MutexGuard aGuard( ImplGetOwnStaticMutex() ); +} + +// ------------------------------------------------------------------------------ + +Window::~Window() +{ +} + +// ------------------------------------------------------------------------------ + +void Window::implLayoutVideoWindow() +{ + if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel ) + { + awt::Size aPrefSize( mrPlayer.getPreferredPlayerWindowSize() ); + awt::Rectangle aRect = getPosSize(); + int nW = aRect.Width, nH = aRect.Height; + int nVideoW = nW, nVideoH = nH; + int nX = 0, nY = 0, nWidth = 0, nHeight = 0; + bool bDone = false, bZoom = false; + + if( media::ZoomLevel_ORIGINAL == meZoomLevel ) + { + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_4 == meZoomLevel ) + { + aPrefSize.Width >>= 2; + aPrefSize.Height >>= 2; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_1_TO_2 == meZoomLevel ) + { + aPrefSize.Width >>= 1; + aPrefSize.Height >>= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_2_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 1; + aPrefSize.Height <<= 1; + bZoom = true; + } + else if( media::ZoomLevel_ZOOM_4_TO_1 == meZoomLevel ) + { + aPrefSize.Width <<= 2; + aPrefSize.Height <<= 2; + bZoom = true; + } + else if( media::ZoomLevel_FIT_TO_WINDOW == meZoomLevel ) + { + nWidth = nVideoW; + nHeight = nVideoH; + bDone = true; + } + + if( bZoom ) + { + if( ( aPrefSize.Width <= nVideoW ) && ( aPrefSize.Height <= nVideoH ) ) + { + nX = ( nVideoW - aPrefSize.Width ) >> 1; + nY = ( nVideoH - aPrefSize.Height ) >> 1; + nWidth = aPrefSize.Width; + nHeight = aPrefSize.Height; + bDone = true; + } + } + + if( !bDone ) + { + if( aPrefSize.Width > 0 && aPrefSize.Height > 0 && nVideoW > 0 && nVideoH > 0 ) + { + double fPrefWH = (double) aPrefSize.Width / aPrefSize.Height; + + if( fPrefWH < ( (double) nVideoW / nVideoH ) ) + nVideoW = (int)( nVideoH * fPrefWH ); + else + nVideoH = (int)( nVideoW / fPrefWH ); + + nX = ( nW - nVideoW ) >> 1; + nY = ( nH - nVideoH ) >> 1; + nWidth = nVideoW; + nHeight = nVideoH; + } + else + nX = nY = nWidth = nHeight = 0; + } + + /* + IVideoWindow* pVideoWindow = const_cast< IVideoWindow* >( mrPlayer.getVideoWindow() ); + + if( pVideoWindow ) + pVideoWindow->SetWindowPosition( nX, nY, nWidth, nHeight ); + */ + } +} + +// ------------------------------------------------------------------------------ + +bool Window::create( const uno::Sequence< uno::Any >& /*rArguments*/ ) +{ + bool bRet = false; + + return bRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::update( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel eZoomLevel ) + throw (uno::RuntimeException) +{ + bool bRet = false; + + if( media::ZoomLevel_NOT_AVAILABLE != meZoomLevel && + media::ZoomLevel_NOT_AVAILABLE != eZoomLevel ) + { + if( eZoomLevel != meZoomLevel ) + { + meZoomLevel = eZoomLevel; + implLayoutVideoWindow(); + } + + bRet = true; + } + + return bRet; +} + +// ------------------------------------------------------------------------------ + +media::ZoomLevel SAL_CALL Window::getZoomLevel( ) + throw (uno::RuntimeException) +{ + return meZoomLevel; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPointerType( sal_Int32 nPointerType ) + throw (uno::RuntimeException) +{ + mnPointerType = nPointerType; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 /*Width*/, sal_Int32 /*Height*/, sal_Int16 /*Flags*/ ) + throw (uno::RuntimeException) +{ + implLayoutVideoWindow(); +} + +// ------------------------------------------------------------------------------ + +awt::Rectangle SAL_CALL Window::getPosSize() + throw (uno::RuntimeException) +{ + awt::Rectangle aRet; + + return aRet; +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setVisible( sal_Bool /* bVisible */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setEnable( sal_Bool /* bEnable */ ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::setFocus( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::dispose( ) + throw (uno::RuntimeException) +{ +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.addInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw (uno::RuntimeException) +{ + maListeners.removeInterface( getCppuType( &xListener ), xListener ); +} + +// ------------------------------------------------------------------------------ + +void Window::fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mousePressed( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseListener >( aIter.next(), uno::UNO_QUERY )->mouseReleased( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XMouseMotionListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XMouseMotionListener >( aIter.next(), uno::UNO_QUERY )->mouseMoved( rEvt ); + } +} + +// ----------------------------------------------------------------------------- + +void Window::fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ) +{ + ::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( getCppuType( (uno::Reference< awt::XFocusListener >*) 0 ) ); + + if( pContainer ) + { + ::cppu::OInterfaceIteratorHelper aIter( *pContainer ); + + while( aIter.hasMoreElements() ) + uno::Reference< awt::XFocusListener >( aIter.next(), uno::UNO_QUERY )->focusGained( rEvt ); + } +} + +// ------------------------------------------------------------------------------ + +::rtl::OUString SAL_CALL Window::getImplementationName( ) + throw (uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_XINE_WINDOW_IMPLEMENTATIONNAME ) ); +} + +// ------------------------------------------------------------------------------ + +sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName ) + throw (uno::RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) ); +} + +// ------------------------------------------------------------------------------ + +uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( ) + throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_XINE_WINDOW_SERVICENAME ) ); + + return aRet; +} + +} // namespace xine +} // namespace avmedia diff --git a/avmedia/source/xine/window.hxx b/avmedia/source/xine/window.hxx new file mode 100644 index 000000000000..014d349acfac --- /dev/null +++ b/avmedia/source/xine/window.hxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _WINDOW_HXX +#define _WINDOW_HXX + +#include "xinecommon.hxx" +#include <cppuhelper/interfacecontainer.h> + +#ifndef _COM_SUN_STAR_MEDIA_XPLAYERWINDOW_HDL_ +#include "com/sun/star/media/XPlayerWindow.hdl" +#endif + +namespace avmedia { namespace xine { + +// --------------- +// - Window - +// --------------- + +class Player; + +class Window : public ::cppu::WeakImplHelper2 < ::com::sun::star::media::XPlayerWindow, + ::com::sun::star::lang::XServiceInfo > +{ +public: + + Window( Player& rPlayer ); + ~Window(); + + bool create( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ); + + // XPlayerWindow + virtual void SAL_CALL update( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL setZoomLevel( ::com::sun::star::media::ZoomLevel ZoomLevel ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::media::ZoomLevel SAL_CALL getZoomLevel( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setPointerType( sal_Int32 nPointerType ) throw (::com::sun::star::uno::RuntimeException); + + // XWindow + virtual void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool Visible ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setEnable( sal_Bool Enable ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setFocus( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + +public: + + void fireMousePressedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireMouseReleasedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireMouseMovedEvent( const ::com::sun::star::awt::MouseEvent& rEvt ); + void fireKeyPressedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + void fireKeyReleasedEvent( const ::com::sun::star::awt::KeyEvent& rEvt ); + void fireSetFocusEvent( const ::com::sun::star::awt::FocusEvent& rEvt ); + +private: + + ::osl::Mutex maMutex; + Player& mrPlayer; + ::cppu::OMultiTypeInterfaceContainerHelper maListeners; + ::com::sun::star::media::ZoomLevel meZoomLevel; + sal_Int32 mnPointerType; + + void implLayoutVideoWindow(); +}; + +} // namespace xine +} // namespace avmedia + +#endif // _WINDOW_HXX diff --git a/avmedia/source/xine/xinecommon.hxx b/avmedia/source/xine/xinecommon.hxx new file mode 100644 index 000000000000..fe80a75370b6 --- /dev/null +++ b/avmedia/source/xine/xinecommon.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XINECOMMON_HXX +#define _XINECOMMON_HXX + +#include <osl/mutex.hxx> +#ifndef __RTL_USTRING_ +#include <rtl/ustring.hxx> +#endif +#include <tools/debug.hxx> +#include <tools/stream.hxx> +#include <tools/string.hxx> +#include <tools/urlobj.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/media/XManager.hpp> + +#define AVMEDIA_XINE_MANAGER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Manager_Xine" +#define AVMEDIA_XINE_MANAGER_SERVICENAME "com.sun.star.media.Manager_Xine" + +#define AVMEDIA_XINE_PLAYER_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Player_Xine" +#define AVMEDIA_XINE_PLAYER_SERVICENAME "com.sun.star.media.Player_Xine" + +#define AVMEDIA_XINE_WINDOW_IMPLEMENTATIONNAME "com.sun.star.comp.avmedia.Window_Xine" +#define AVMEDIA_XINE_WINDOW_SERVICENAME "com.sun.star.media.Window_Xine" + +#endif // _XINECOMMOM_HXX diff --git a/avmedia/source/xine/xineuno.cxx b/avmedia/source/xine/xineuno.cxx new file mode 100644 index 000000000000..4dc4f3f7e1dd --- /dev/null +++ b/avmedia/source/xine/xineuno.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "xinecommon.hxx" +#include "manager.hxx" + +using namespace ::com::sun::star; + +// ------------------- +// - factory methods - +// ------------------- + +static uno::Reference< uno::XInterface > SAL_CALL create_MediaPlayer( const uno::Reference< lang::XMultiServiceFactory >& rxFact ) +{ + return uno::Reference< uno::XInterface >( *new ::avmedia::xine::Manager( rxFact ) ); +} + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ----------------------- +// - component_writeInfo - +// ----------------------- + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* /* pServiceManager */, void* pRegistryKey ) +{ + sal_Bool bRet = sal_False; + + if( pRegistryKey ) + { + try + { + uno::Reference< registry::XRegistryKey > xNewKey1( + static_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( + ::rtl::OUString::createFromAscii( + "/" AVMEDIA_XINE_MANAGER_IMPLEMENTATIONNAME "/UNO/SERVICES/" + AVMEDIA_XINE_MANAGER_SERVICENAME ) ) ); + + bRet = sal_True; + } + catch( registry::InvalidRegistryException& ) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + + return bRet; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ ) +{ + uno::Reference< lang::XSingleServiceFactory > xFactory; + void* pRet = 0; + + if( rtl_str_compare( pImplName, AVMEDIA_XINE_MANAGER_IMPLEMENTATIONNAME ) == 0 ) + { + const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( AVMEDIA_XINE_MANAGER_SERVICENAME ) ); + + xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory( + reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), + ::rtl::OUString::createFromAscii( AVMEDIA_XINE_MANAGER_IMPLEMENTATIONNAME ), + create_MediaPlayer, uno::Sequence< ::rtl::OUString >( &aServiceName, 1 ) ) ); + } + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} |