summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-02-26 21:24:49 +0200
committerMichael Stahl <mstahl@redhat.com>2018-02-28 14:00:00 +0100
commitbf6ff1ac366ceff7bf46ff3cf40e39e236c2c1cb (patch)
tree4a3f1e2133567041fd8100567d1f577bd4d86cff /svx/source
parent7963353a816f22a66330923f90f500820784313a (diff)
tdf#79546: Make sure temp copy of inserted media file keeps the same extension
Inserting videos into Impress presentations with 'Insert>Audio or Video' did not work at all for me. This helps. It seems that the AVFoundation APIs are sadly rather picky about file name extensions. Why we need to make a temporary copy of the media file (which after all can be rather large) at all, when inserting it in a slide, I don't understand. But I am not going to dig into that now. Change-Id: I43fcfb5bb3ef0a2c0f8979ac3e7c458a84f180a1 Reviewed-on: https://gerrit.libreoffice.org/50390 Reviewed-by: Tor Lillqvist <tml@collabora.com> Tested-by: Tor Lillqvist <tml@collabora.com> (cherry picked from commit 1aa5a3874bf716acfbded2a09319dce5d4ce8c0d) Reviewed-on: https://gerrit.libreoffice.org/50440 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/svdraw/svdomedia.cxx28
1 files changed, 24 insertions, 4 deletions
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 785a3a0f73fb..9fb5645738d5 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -269,7 +269,8 @@ uno::Reference<io::XInputStream> SdrMediaObj::GetInputStream()
static bool lcl_CopyToTempFile(
uno::Reference<io::XInputStream> const& xInStream,
- OUString & o_rTempFileURL)
+ OUString & o_rTempFileURL,
+ const OUString& rDesiredExtension)
{
OUString tempFileURL;
::osl::FileBase::RC const err =
@@ -280,6 +281,17 @@ static bool lcl_CopyToTempFile(
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,
@@ -304,7 +316,7 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream
return;
}
OUString tempFileURL;
- bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL);
+ bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL, "");
if (bSuccess)
{
m_xImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL));
@@ -346,7 +358,15 @@ static bool lcl_HandlePackageURL(
SAL_WARN("svx", "no stream?");
return false;
}
- return lcl_CopyToTempFile(xInStream, o_rTempFileURL);
+ // Make sure the temporary copy has the same file name extension as the original media file
+ // (like .mp4). That seems to be important for some AVFoundation APIs. For random extension-less
+ // file names, they don't seem to even bother looking inside the file.
+ sal_Int32 nLastDot = rURL.lastIndexOf('.');
+ sal_Int32 nLastSlash = rURL.lastIndexOf('/');
+ OUString sDesiredExtension;
+ if (nLastDot > nLastSlash && nLastDot+1 < rURL.getLength())
+ sDesiredExtension = rURL.copy(nLastDot);
+ return lcl_CopyToTempFile(xInStream, o_rTempFileURL, sDesiredExtension);
}
#endif