LibreOffice Module avmedia (master) 1
framegrabber.mm
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "framegrabber.hxx"
21#include "player.hxx"
22
23#include <sal/log.hxx>
24#include <tools/stream.hxx>
25#include <vcl/graph.hxx>
26#include <vcl/cvtgrf.hxx>
28
29using namespace ::com::sun::star;
30
31namespace avmedia::macavf {
32
34: mpImageGen( nullptr )
35{}
36
37
39{
40 if( mpImageGen )
41 CFRelease( mpImageGen );
42}
43
44
45bool FrameGrabber::create( AVAsset* pMovie )
46{
47 if( [[pMovie tracksWithMediaType:AVMediaTypeVideo] count] == 0)
48 {
49 SAL_WARN("avmedia", "AVGrabber::create() found no video content!" );
50 return false;
51 }
52
53 mpImageGen = [AVAssetImageGenerator assetImageGeneratorWithAsset:pMovie];
54 CFRetain( mpImageGen );
55 return true;
56}
57
58
59uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMediaTime )
60{
61 uno::Reference< graphic::XGraphic > xRet;
62 if( !mpImageGen )
63 return xRet;
64
65 // get the requested image from the movie
66 CGImage* pCGImage = [mpImageGen copyCGImageAtTime:CMTimeMakeWithSeconds(fMediaTime,1000) actualTime:nullptr error:nullptr];
67
68 // convert the image to a TIFF-formatted byte-array
69 CFMutableDataRef pCFData = CFDataCreateMutable( kCFAllocatorDefault, 0 );
70 SAL_WNODEPRECATED_DECLARATIONS_PUSH // kUTTypeTIFF (12.0)
71 CGImageDestination* pCGImgDest = CGImageDestinationCreateWithData( pCFData, kUTTypeTIFF, 1, nullptr );
73 CGImageDestinationAddImage( pCGImgDest, pCGImage, nullptr );
74 CGImageDestinationFinalize( pCGImgDest );
75 CFRelease( pCGImgDest );
76 const CFIndex nBitmapLen = CFDataGetLength( pCFData );
77 UInt8 * pBitmapBytes = const_cast<UInt8 *>(CFDataGetBytePtr( pCFData ));
78
79 // convert the image into the return-value type which is a graphic::XGraphic
80 SvMemoryStream aMemStm( pBitmapBytes, nBitmapLen, StreamMode::READ | StreamMode::WRITE );
81 Graphic aGraphic;
82 if( GraphicConverter::Import( aMemStm, aGraphic, ConvertDataFormat::TIF ) == ERRCODE_NONE )
83 xRet = aGraphic.GetXGraphic();
84
85 // clean up resources
86 CFRelease( pCFData );
87 return xRet;
88}
89
90
92{
94}
95
96sal_Bool SAL_CALL FrameGrabber::supportsService( const OUString& ServiceName )
97{
99}
100
101uno::Sequence< OUString > SAL_CALL FrameGrabber::getSupportedServiceNames( )
102{
104}
105
106} // namespace avmedia::macavf
107
108/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ErrCode Import(SvStream &rIStm, Graphic &rGraphic, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL grabFrame(double fMediaTime) override
Definition: framegrabber.mm:59
virtual ~FrameGrabber() override
Definition: framegrabber.mm:38
AVAssetImageGenerator * mpImageGen
virtual OUString SAL_CALL getImplementationName() override
Definition: framegrabber.mm:91
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: framegrabber.mm:96
bool create(AVAsset *pMovie)
Definition: framegrabber.mm:45
#define ERRCODE_NONE
#define SAL_WARN(area, stream)
#define AVMEDIA_MACAVF_FRAMEGRABBER_IMPLEMENTATIONNAME
#define AVMEDIA_MACAVF_FRAMEGRABBER_SERVICENAME
#define SAL_WNODEPRECATED_DECLARATIONS_POP
unsigned char sal_Bool
#define SAL_WNODEPRECATED_DECLARATIONS_PUSH