video: Use cache dir for storing downloaded OpenH264 library
Using the executable's parent directory is a bad idea in most cases, as the place where Ruffle is installed should not be modified. This patch changes the directory where the OpenH264 library is saved to the cache directory, which should always be writable.
This commit is contained in:
parent
3da0246856
commit
e8f52fd8b5
|
@ -227,7 +227,9 @@ impl ActivePlayer {
|
|||
#[cfg(feature = "external_video")]
|
||||
{
|
||||
use ruffle_video_external::backend::ExternalVideoBackend;
|
||||
let openh264 = tokio::task::block_in_place(ExternalVideoBackend::load_openh264);
|
||||
let openh264 = tokio::task::block_in_place(|| {
|
||||
ExternalVideoBackend::load_openh264(&opt.cache_directory.join("video"))
|
||||
});
|
||||
let openh264 = match openh264 {
|
||||
Ok(codec) => Some(codec),
|
||||
Err(e) => {
|
||||
|
|
|
@ -177,8 +177,11 @@ impl PlayerOptions {
|
|||
if self.with_video {
|
||||
#[cfg(feature = "ruffle_video_external")]
|
||||
{
|
||||
let current_exe = std::env::current_exe()?;
|
||||
let directory = current_exe.parent().expect("Executable parent dir");
|
||||
|
||||
use ruffle_video_external::backend::ExternalVideoBackend;
|
||||
let openh264 = ExternalVideoBackend::load_openh264()
|
||||
let openh264 = ExternalVideoBackend::load_openh264(directory)
|
||||
.map_err(|e| anyhow!("Couldn't load OpenH264: {}", e))?;
|
||||
|
||||
player_builder =
|
||||
|
|
|
@ -12,7 +12,7 @@ use sha2::{Digest, Sha256};
|
|||
use slotmap::SlotMap;
|
||||
use std::fs::File;
|
||||
use std::io::copy;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use swf::{VideoCodec, VideoDeblocking};
|
||||
|
||||
enum ProxyOrStream {
|
||||
|
@ -102,6 +102,7 @@ impl ExternalVideoBackend {
|
|||
|
||||
fn download_openh264(
|
||||
openh264_data: &OpenH264Data,
|
||||
directory: &Path,
|
||||
) -> Result<PathBuf, Box<dyn std::error::Error>> {
|
||||
// See the license at: https://www.openh264.org/BINARY_LICENSE.txt
|
||||
const URL_BASE: &str = "http://ciscobinary.openh264.org/";
|
||||
|
@ -112,10 +113,7 @@ impl ExternalVideoBackend {
|
|||
openh264_data.download_sha256,
|
||||
);
|
||||
|
||||
let current_exe = std::env::current_exe()?;
|
||||
let directory = current_exe
|
||||
.parent()
|
||||
.ok_or("Could not determine Ruffle location.")?;
|
||||
std::fs::create_dir_all(directory)?;
|
||||
let filepath = directory.join(filename);
|
||||
|
||||
// If the binary doesn't exist in the expected location, download it.
|
||||
|
@ -149,7 +147,7 @@ impl ExternalVideoBackend {
|
|||
Ok(filepath)
|
||||
}
|
||||
|
||||
pub fn load_openh264() -> Result<OpenH264Codec, Box<dyn std::error::Error>> {
|
||||
pub fn load_openh264(directory: &Path) -> Result<OpenH264Codec, Box<dyn std::error::Error>> {
|
||||
let openh264_data = Self::get_openh264_data()?;
|
||||
|
||||
for filename in &openh264_data.local_filenames {
|
||||
|
@ -166,7 +164,7 @@ impl ExternalVideoBackend {
|
|||
}
|
||||
|
||||
tracing::info!("Downloading OpenH264 library");
|
||||
let filename = Self::download_openh264(&openh264_data)?;
|
||||
let filename = Self::download_openh264(&openh264_data, directory)?;
|
||||
tracing::info!("Using OpenH264 at {:?}", filename);
|
||||
Ok(OpenH264Codec::new(&filename)?)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue