2014-05-12 08:39:08 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "framegrabber.hxx"
|
|
|
|
#include "player.hxx"
|
|
|
|
|
|
|
|
#include <tools/stream.hxx>
|
|
|
|
#include <vcl/graph.hxx>
|
|
|
|
#include <vcl/cvtgrf.hxx>
|
|
|
|
#include <unotools/localfilehelper.hxx>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
namespace avmedia { namespace macavf {
|
|
|
|
|
|
|
|
FrameGrabber::FrameGrabber( const uno::Reference< lang::XMultiServiceFactory >& /*rxMgr*/ )
|
2015-11-10 09:18:42 -06:00
|
|
|
: mpImageGen( nullptr )
|
2014-05-12 08:39:08 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
FrameGrabber::~FrameGrabber()
|
|
|
|
{
|
|
|
|
if( mpImageGen )
|
|
|
|
CFRelease( mpImageGen );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FrameGrabber::create( const ::rtl::OUString& rURL )
|
|
|
|
{
|
2015-11-17 03:29:50 -06:00
|
|
|
NSString* pNSStr = [NSString stringWithCharacters:reinterpret_cast<unichar const *>(rURL.getStr()) length:rURL.getLength()];
|
2015-10-02 07:43:22 -05:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_PUSH
|
|
|
|
//TODO: 10.11 stringByAddingPercentEscapesUsingEncoding
|
2014-05-12 08:39:08 -05:00
|
|
|
NSURL* pNSURL = [NSURL URLWithString: [pNSStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
2015-10-02 07:43:22 -05:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_POP
|
2014-05-12 08:39:08 -05:00
|
|
|
AVAsset* pMovie = [AVURLAsset URLAssetWithURL:pNSURL options:nil];
|
|
|
|
if( !pMovie )
|
|
|
|
{
|
|
|
|
OSL_TRACE( "AVGrabber::create() cannot load url=\"%s\"", [pNSStr UTF8String] );
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-12 11:07:09 -05:00
|
|
|
|
|
|
|
return create( pMovie );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FrameGrabber::create( AVAsset* pMovie )
|
|
|
|
{
|
2014-05-12 08:39:08 -05:00
|
|
|
if( [[pMovie tracksWithMediaType:AVMediaTypeVideo] count] == 0)
|
|
|
|
{
|
2014-05-12 11:07:09 -05:00
|
|
|
OSL_TRACE( "AVGrabber::create() found no video content!" );
|
2014-05-12 08:39:08 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpImageGen = [AVAssetImageGenerator assetImageGeneratorWithAsset:pMovie];
|
|
|
|
CFRetain( mpImageGen );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
|
|
|
|
throw (uno::RuntimeException)
|
|
|
|
{
|
|
|
|
uno::Reference< graphic::XGraphic > xRet;
|
|
|
|
if( !mpImageGen )
|
|
|
|
return xRet;
|
|
|
|
OSL_TRACE( "AVPlayer::grabFrame( %.3fsec)", fMediaTime );
|
|
|
|
|
|
|
|
// get the requested image from the movie
|
2015-11-10 09:18:42 -06:00
|
|
|
CGImage* pCGImage = [mpImageGen copyCGImageAtTime:CMTimeMakeWithSeconds(fMediaTime,1000) actualTime:nullptr error:nullptr];
|
2014-05-12 08:39:08 -05:00
|
|
|
|
|
|
|
// convert the image to a TIFF-formatted byte-array
|
|
|
|
CFMutableDataRef pCFData = CFDataCreateMutable( kCFAllocatorDefault, 0 );
|
2015-11-10 09:18:42 -06:00
|
|
|
CGImageDestination* pCGImgDest = CGImageDestinationCreateWithData( pCFData, kUTTypeTIFF, 1, nullptr );
|
|
|
|
CGImageDestinationAddImage( pCGImgDest, pCGImage, nullptr );
|
2014-05-12 08:39:08 -05:00
|
|
|
CGImageDestinationFinalize( pCGImgDest );
|
|
|
|
CFRelease( pCGImgDest );
|
|
|
|
const long nBitmapLen = CFDataGetLength( pCFData );
|
2015-06-08 09:23:09 -05:00
|
|
|
UInt8 * pBitmapBytes = const_cast<UInt8 *>(CFDataGetBytePtr( pCFData ));
|
2014-05-12 08:39:08 -05:00
|
|
|
|
|
|
|
// convert the image into the return-value type which is a graphic::XGraphic
|
2015-01-07 01:28:42 -06:00
|
|
|
SvMemoryStream aMemStm( pBitmapBytes, nBitmapLen, StreamMode::READ | StreamMode::WRITE );
|
2014-05-12 08:39:08 -05:00
|
|
|
Graphic aGraphic;
|
2015-05-20 06:00:06 -05:00
|
|
|
if( GraphicConverter::Import( aMemStm, aGraphic, ConvertDataFormat::TIF ) == ERRCODE_NONE )
|
2014-05-12 08:39:08 -05:00
|
|
|
xRet = aGraphic.GetXGraphic();
|
|
|
|
|
|
|
|
// clean up resources
|
|
|
|
CFRelease( pCFData );
|
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::rtl::OUString SAL_CALL FrameGrabber::getImplementationName( )
|
|
|
|
throw (uno::RuntimeException)
|
|
|
|
{
|
2016-06-02 01:35:30 -05:00
|
|
|
return ::rtl::OUString( AVMEDIA_MACAVF_FRAMEGRABBER_IMPLEMENTATIONNAME );
|
2014-05-12 08:39:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL FrameGrabber::supportsService( const ::rtl::OUString& ServiceName )
|
|
|
|
throw (uno::RuntimeException)
|
|
|
|
{
|
2016-06-02 06:12:15 -05:00
|
|
|
return ServiceName == AVMEDIA_MACAVF_FRAMEGRABBER_SERVICENAME;
|
2014-05-12 08:39:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< ::rtl::OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( )
|
|
|
|
throw (uno::RuntimeException)
|
|
|
|
{
|
2016-08-01 06:05:42 -05:00
|
|
|
return { AVMEDIA_MACAVF_FRAMEGRABBER_SERVICENAME };
|
2014-05-12 08:39:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace macavf
|
|
|
|
} // namespace avmedia
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|