diff options
author | Mark Hung <marklh9@gmail.com> | 2019-01-27 13:41:34 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2019-02-04 01:15:22 +0100 |
commit | 6b6c0b120f3275be6bd9dbb26480f8f1df355e00 (patch) | |
tree | d25c799cad8b21e4836e3b309425b2271b0615bc /svx | |
parent | 8a1321362a0229a25869e4e3d0422a5a51c5b5be (diff) |
tdf#44223 allow slideshow to play embedded media.
Implement MediaFileManager that create the temp media
file for package urls when making slideshow.
Change-Id: I10a5ddc405928b4322ad72eb603508faf25bf0db
Reviewed-on: https://gerrit.libreoffice.org/67209
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdomedia.cxx | 69 |
1 files changed, 8 insertions, 61 deletions
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx index 8ed836168792..7dd3f37d119b 100644 --- a/svx/source/svdraw/svdomedia.cxx +++ b/svx/source/svdraw/svdomedia.cxx @@ -44,25 +44,13 @@ using namespace ::com::sun::star; -// Note: the temp file is read only, until it is deleted! -// It may be shared between multiple documents in case of copy/paste, -// hence the shared_ptr. -struct MediaTempFile -{ - OUString const m_TempFileURL; - MediaTempFile(OUString const& rURL) - : m_TempFileURL(rURL) - {} - ~MediaTempFile() - { - ::osl::File::remove(m_TempFileURL); - } -}; - struct SdrMediaObj::Impl { ::avmedia::MediaItem m_MediaProperties; - std::shared_ptr< MediaTempFile > m_pTempFile; + // Note: the temp file is read only, until it is deleted! + // It may be shared between multiple documents in case of copy/paste, + // hence the shared_ptr. + std::shared_ptr< ::avmedia::MediaTempFile > m_pTempFile; uno::Reference< graphic::XGraphic > m_xCachedSnapshot; OUString m_LastFailedPkgURL; }; @@ -270,47 +258,6 @@ uno::Reference<io::XInputStream> SdrMediaObj::GetInputStream() return tempFile.openStream(); } -static bool lcl_CopyToTempFile( - uno::Reference<io::XInputStream> const& xInStream, - OUString & o_rTempFileURL, - const OUString& rDesiredExtension) -{ - OUString tempFileURL; - ::osl::FileBase::RC const err = - ::osl::FileBase::createTempFile(nullptr, nullptr, & tempFileURL); - if (::osl::FileBase::E_None != err) - { - SAL_INFO("svx", "cannot create temp file"); - return false; - } - - if (!rDesiredExtension.isEmpty()) - { - OUString newTempFileURL = tempFileURL + rDesiredExtension; - if (osl::File::move(tempFileURL, newTempFileURL) != osl::FileBase::E_None) - { - SAL_WARN("svx", "Could not rename file '" << tempFileURL << "' to '" << newTempFileURL << "'"); - return false; - } - tempFileURL = newTempFileURL; - } - - try - { - ::ucbhelper::Content tempContent(tempFileURL, - uno::Reference<ucb::XCommandEnvironment>(), - comphelper::getProcessComponentContext()); - tempContent.writeStream(xInStream, true); // copy stream to file - } - catch (uno::Exception const& e) - { - SAL_WARN("svx", "exception: '" << e << "'"); - return false; - } - o_rTempFileURL = tempFileURL; - return true; -} - void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream) { if (m_xImpl->m_pTempFile || m_xImpl->m_LastFailedPkgURL.isEmpty()) @@ -321,14 +268,14 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream OUString tempFileURL; const bool bSuccess( - lcl_CopyToTempFile( + ::avmedia::CreateMediaTempFile( xStream, tempFileURL, "")); if (bSuccess) { - m_xImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL)); + m_xImpl->m_pTempFile.reset(new ::avmedia::MediaTempFile(tempFileURL)); #if HAVE_FEATURE_AVMEDIA m_xImpl->m_MediaProperties.setURL( m_xImpl->m_LastFailedPkgURL, tempFileURL, ""); @@ -372,7 +319,7 @@ static bool lcl_HandlePackageURL( OUString sDesiredExtension; if (nLastDot > nLastSlash && nLastDot+1 < rURL.getLength()) sDesiredExtension = rURL.copy(nLastDot); - return lcl_CopyToTempFile(xInStream, o_rTempFileURL, sDesiredExtension); + return ::avmedia::CreateMediaTempFile(xInStream, o_rTempFileURL, sDesiredExtension); } #endif @@ -407,7 +354,7 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper if (bSuccess) { m_xImpl->m_pTempFile.reset( - new MediaTempFile(tempFileURL)); + new ::avmedia::MediaTempFile(tempFileURL)); #if HAVE_FEATURE_AVMEDIA m_xImpl->m_MediaProperties.setURL(url, tempFileURL, ""); #endif |