[Libreoffice-commits] core.git: svx/source

Tor Lillqvist tml at collabora.com
Tue Feb 27 13:45:26 UTC 2018


 svx/source/svdraw/svdomedia.cxx |   28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

New commits:
commit 1aa5a3874bf716acfbded2a09319dce5d4ce8c0d
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Feb 26 21:24:49 2018 +0200

    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 at collabora.com>
    Tested-by: Tor Lillqvist <tml at collabora.com>

diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 8303e2b71fa9..4c41e76e6dc3 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));
@@ -348,7 +360,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
 


More information about the Libreoffice-commits mailing list