gstplayer.cxx (144e4e62) gstplayer.cxx (b6e71573)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 15 unchanged lines hidden (view full) ---

24#include "gstplayer.hxx"
25#include "gstwindow.hxx"
26#include "gstframegrabber.hxx"
27#include <stdio.h>
28#include <unistd.h>
29#include <math.h>
30#include <string>
31#include <gst/gstelement.h>
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 15 unchanged lines hidden (view full) ---

24#include "gstplayer.hxx"
25#include "gstwindow.hxx"
26#include "gstframegrabber.hxx"
27#include <stdio.h>
28#include <unistd.h>
29#include <math.h>
30#include <string>
31#include <gst/gstelement.h>
32#include <gst/interfaces/xoverlay.h>
32#include <gst/video/videooverlay.h>
33
34
35// maximum timeout time in nanoseconds
36#define GST_MAX_TIMEOUT (2500 * GST_MSECOND)
37
38using namespace ::com::sun::star;
39
40namespace avmedia

--- 266 unchanged lines hidden (view full) ---

307double SAL_CALL Player::getDuration()
308 throw( uno::RuntimeException )
309{
310 ::osl::MutexGuard aGuard(m_aMutex);
311 gint64 nDuration = 0;
312
313 if( implInitPlayer() )
314 {
33
34
35// maximum timeout time in nanoseconds
36#define GST_MAX_TIMEOUT (2500 * GST_MSECOND)
37
38using namespace ::com::sun::star;
39
40namespace avmedia

--- 266 unchanged lines hidden (view full) ---

307double SAL_CALL Player::getDuration()
308 throw( uno::RuntimeException )
309{
310 ::osl::MutexGuard aGuard(m_aMutex);
311 gint64 nDuration = 0;
312
313 if( implInitPlayer() )
314 {
315 GstFormat aFormat = GST_FORMAT_TIME;
316
317 if( !gst_element_query_duration( mpPlayer, &aFormat, &nDuration ) ||
318 ( GST_FORMAT_TIME != aFormat ) ||
315 if( !gst_element_query_duration( mpPlayer, GST_FORMAT_TIME, &nDuration ) ||
319 ( nDuration < 0 ) )
320 {
321 nDuration = 0;
322 }
323 }
324
325 return( static_cast< double >( nDuration ) / NANO_TIME_FACTOR );
326}

--- 16 unchanged lines hidden (view full) ---

343// ------------------------------------------------------------------------------
344double SAL_CALL Player::getMediaTime()
345 throw( uno::RuntimeException )
346{
347 double fRet = 0.0;
348 ::osl::MutexGuard aGuard(m_aMutex);
349 if( implInitPlayer() )
350 {
316 ( nDuration < 0 ) )
317 {
318 nDuration = 0;
319 }
320 }
321
322 return( static_cast< double >( nDuration ) / NANO_TIME_FACTOR );
323}

--- 16 unchanged lines hidden (view full) ---

340// ------------------------------------------------------------------------------
341double SAL_CALL Player::getMediaTime()
342 throw( uno::RuntimeException )
343{
344 double fRet = 0.0;
345 ::osl::MutexGuard aGuard(m_aMutex);
346 if( implInitPlayer() )
347 {
351 GstFormat aFormat = GST_FORMAT_TIME;
352 gint64 nCurTime = 0;
353
348 gint64 nCurTime = 0;
349
354 if( gst_element_query_position( mpPlayer, &aFormat, &nCurTime ) &&
355 ( GST_FORMAT_TIME == aFormat ) &&
350 if( gst_element_query_position( mpPlayer, GST_FORMAT_TIME, &nCurTime ) &&
356 ( nCurTime >= 0 ) )
357 {
358 fRet = static_cast< double >( nCurTime ) / NANO_TIME_FACTOR;
359 }
360 }
361
362 return( fRet );
363}

--- 170 unchanged lines hidden (view full) ---

534 if( ( aSize.Width > 0 ) && ( aSize.Height > 0 ) )
535 {
536 Window* pPlayerWindow = new Window( *this );
537
538 xRet = pPlayerWindow;
539
540 if( !pPlayerWindow->create( rArguments ) )
541 {
351 ( nCurTime >= 0 ) )
352 {
353 fRet = static_cast< double >( nCurTime ) / NANO_TIME_FACTOR;
354 }
355 }
356
357 return( fRet );
358}

--- 170 unchanged lines hidden (view full) ---

529 if( ( aSize.Width > 0 ) && ( aSize.Height > 0 ) )
530 {
531 Window* pPlayerWindow = new Window( *this );
532
533 xRet = pPlayerWindow;
534
535 if( !pPlayerWindow->create( rArguments ) )
536 {
537 OSL_ENSURE( false, "could not create player window\n" );
542 xRet.clear();
543 }
544 else
545 {
546 // try to use gconf user configurable video sink first
547 GstElement* pVideoSink = gst_element_factory_make( "gconfvideosink", NULL );
548
549 if( ( NULL != pVideoSink ) ||
550 ( NULL != ( pVideoSink = gst_element_factory_make( "autovideosink", NULL ) ) ) ||
551 ( NULL != ( pVideoSink = gst_element_factory_make( "xvimagesink", NULL ) ) ) ||
552 ( NULL != ( pVideoSink = gst_element_factory_make( "ximagesink", NULL ) ) ) )
553 {
554 GstState aOldState = GST_STATE_NULL;
555
556 mpPlayerWindow = pPlayerWindow;
557 gst_element_get_state( mpPlayer, &aOldState, NULL, GST_MAX_TIMEOUT );
558 gst_element_set_state( mpPlayer, GST_STATE_READY );
559 g_object_set( mpPlayer, "video-sink", pVideoSink, NULL );
538 xRet.clear();
539 }
540 else
541 {
542 // try to use gconf user configurable video sink first
543 GstElement* pVideoSink = gst_element_factory_make( "gconfvideosink", NULL );
544
545 if( ( NULL != pVideoSink ) ||
546 ( NULL != ( pVideoSink = gst_element_factory_make( "autovideosink", NULL ) ) ) ||
547 ( NULL != ( pVideoSink = gst_element_factory_make( "xvimagesink", NULL ) ) ) ||
548 ( NULL != ( pVideoSink = gst_element_factory_make( "ximagesink", NULL ) ) ) )
549 {
550 GstState aOldState = GST_STATE_NULL;
551
552 mpPlayerWindow = pPlayerWindow;
553 gst_element_get_state( mpPlayer, &aOldState, NULL, GST_MAX_TIMEOUT );
554 gst_element_set_state( mpPlayer, GST_STATE_READY );
555 g_object_set( mpPlayer, "video-sink", pVideoSink, NULL );
556 gst_video_overlay_set_window_handle( GST_VIDEO_OVERLAY( mpPlayer ),
557 pPlayerWindow->getXWindowHandle() );
560 gst_element_set_state( mpPlayer, aOldState );
561 }
558 gst_element_set_state( mpPlayer, aOldState );
559 }
560 else
561 OSL_ENSURE( false, "no video sink available\n" );
562 }
563 }
564
565 return( xRet );
566}
567
568// ------------------------------------------------------------------------------
569uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber()

--- 181 unchanged lines hidden (view full) ---

751 gchar* pPadName = gst_pad_get_name( pPad );
752
753 OSL_TRACE( ">>> Element %s has pad: %s", pElementName, pPadName );
754
755 g_free( pPadName );
756 g_free( pElementName );
757#endif
758
562 }
563 }
564
565 return( xRet );
566}
567
568// ------------------------------------------------------------------------------
569uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber()

--- 181 unchanged lines hidden (view full) ---

751 gchar* pPadName = gst_pad_get_name( pPad );
752
753 OSL_TRACE( ">>> Element %s has pad: %s", pElementName, pPadName );
754
755 g_free( pPadName );
756 g_free( pElementName );
757#endif
758
759 GstCaps* pCaps = gst_pad_get_caps( pPad );
759 GstCaps* pCaps = gst_pad_get_current_caps( pPad );
760
761 // we are interested only in getting video properties
762 // width and height or if we have a video source at all
763 if( pCaps )
764 {
765 for( gint i = 0, nSize = gst_caps_get_size( pCaps ); i < nSize; ++i )
766 {
767 const GstStructure* pStruct = gst_caps_get_structure( pCaps, i );

--- 90 unchanged lines hidden (view full) ---

858 // add bus callback
859 GSource* pBusSource = g_source_new( &aSourceFuncs, sizeof( GstBusSource ) );
860 static_cast< GstBusSource* >( pBusSource )->mpBus = gst_pipeline_get_bus( GST_PIPELINE( mpPlayer ) );
861 g_source_set_callback( pBusSource, NULL, this, NULL );
862 g_source_attach( pBusSource, mpContext );
863
864 // add bus sync handler to intercept video window creation for setting our own window
865 gst_bus_set_sync_handler( static_cast< GstBusSource* >( pBusSource )->mpBus,
760
761 // we are interested only in getting video properties
762 // width and height or if we have a video source at all
763 if( pCaps )
764 {
765 for( gint i = 0, nSize = gst_caps_get_size( pCaps ); i < nSize; ++i )
766 {
767 const GstStructure* pStruct = gst_caps_get_structure( pCaps, i );

--- 90 unchanged lines hidden (view full) ---

858 // add bus callback
859 GSource* pBusSource = g_source_new( &aSourceFuncs, sizeof( GstBusSource ) );
860 static_cast< GstBusSource* >( pBusSource )->mpBus = gst_pipeline_get_bus( GST_PIPELINE( mpPlayer ) );
861 g_source_set_callback( pBusSource, NULL, this, NULL );
862 g_source_attach( pBusSource, mpContext );
863
864 // add bus sync handler to intercept video window creation for setting our own window
865 gst_bus_set_sync_handler( static_cast< GstBusSource* >( pBusSource )->mpBus,
866 &lcl_implHandleCreateWindowFunc, this );
866 &lcl_implHandleCreateWindowFunc, this, NULL );
867
868 // watch for all elements (and pads) that will be added to the playbin,
869 // in order to retrieve properties like video width and height
870 g_signal_connect( GST_BIN( mpPlayer ), "element-added",
871 G_CALLBACK( Player::implHandleNewElementFunc ), this );
872
873 // set source URI for player
874 g_object_set( mpPlayer, "uri", mpURI->str, NULL );
875
876 // set video fake sink first, since we only create a player without window here
877 // and don't want to have the gstreamer default window appearing
878 g_object_set( mpPlayer, "video-sink", gst_element_factory_make( "fakesink", NULL ), NULL );
879
867
868 // watch for all elements (and pads) that will be added to the playbin,
869 // in order to retrieve properties like video width and height
870 g_signal_connect( GST_BIN( mpPlayer ), "element-added",
871 G_CALLBACK( Player::implHandleNewElementFunc ), this );
872
873 // set source URI for player
874 g_object_set( mpPlayer, "uri", mpURI->str, NULL );
875
876 // set video fake sink first, since we only create a player without window here
877 // and don't want to have the gstreamer default window appearing
878 g_object_set( mpPlayer, "video-sink", gst_element_factory_make( "fakesink", NULL ), NULL );
879
880 // This isn't ever going to happen, as createPlayerWindow() has to be called first
881 // to set the mpPlayerWindow, but let's keep it here in case it is called first some day:
882 if ( g_atomic_pointer_get( &mpPlayerWindow ) )
883 {
884 gst_video_overlay_set_window_handle( GST_VIDEO_OVERLAY( mpPlayer ), static_cast< Window* >( g_atomic_pointer_get(
885 &mpPlayerWindow ) )->getXWindowHandle() );
886 }
887
880 // set state of player to READY or destroy object in case of FAILURE
881 if( gst_element_set_state( mpPlayer, GST_STATE_READY ) == GST_STATE_CHANGE_FAILURE )
882 {
883 gst_object_unref( mpPlayer );
884 mpPlayer = NULL;
885 }
886
887 g_atomic_int_add( &mnInitialized, 1 );

--- 35 unchanged lines hidden (view full) ---

923
924// ------------------------------------------------------------------------------
925GstBusSyncReply Player::handleCreateWindow( GstBus* /* pBus */,
926 GstMessage* pMsg )
927{
928 GstBusSyncReply eRet = GST_BUS_PASS;
929
930 if( pMsg &&
888 // set state of player to READY or destroy object in case of FAILURE
889 if( gst_element_set_state( mpPlayer, GST_STATE_READY ) == GST_STATE_CHANGE_FAILURE )
890 {
891 gst_object_unref( mpPlayer );
892 mpPlayer = NULL;
893 }
894
895 g_atomic_int_add( &mnInitialized, 1 );

--- 35 unchanged lines hidden (view full) ---

931
932// ------------------------------------------------------------------------------
933GstBusSyncReply Player::handleCreateWindow( GstBus* /* pBus */,
934 GstMessage* pMsg )
935{
936 GstBusSyncReply eRet = GST_BUS_PASS;
937
938 if( pMsg &&
931 ( GST_MESSAGE_TYPE( pMsg ) == GST_MESSAGE_ELEMENT ) &&
932 gst_structure_has_name( pMsg->structure, "prepare-xwindow-id" ) &&
939 gst_is_video_overlay_prepare_window_handle_message( pMsg ) &&
933 g_atomic_pointer_get( &mpPlayerWindow ) )
934 {
935 OSL_TRACE( ">>> Got Request to create XOverlay" );
936
940 g_atomic_pointer_get( &mpPlayerWindow ) )
941 {
942 OSL_TRACE( ">>> Got Request to create XOverlay" );
943
937 gst_x_overlay_set_xwindow_id( GST_X_OVERLAY( GST_MESSAGE_SRC( pMsg ) ),
944 gst_video_overlay_set_window_handle( GST_VIDEO_OVERLAY( GST_MESSAGE_SRC( pMsg ) ),
938 static_cast< Window* >( g_atomic_pointer_get(
939 &mpPlayerWindow ) )->getXWindowHandle() );
940
941 gst_message_unref( pMsg );
942 eRet = GST_BUS_DROP;
943 }
944
945 return( eRet );
946}
947} // namespace gst
948} // namespace avmedia
945 static_cast< Window* >( g_atomic_pointer_get(
946 &mpPlayerWindow ) )->getXWindowHandle() );
947
948 gst_message_unref( pMsg );
949 eRet = GST_BUS_DROP;
950 }
951
952 return( eRet );
953}
954} // namespace gst
955} // namespace avmedia