From 7bd065a59305d85fc09b0590c4760e2eb11678b4 Mon Sep 17 00:00:00 2001 From: rayguo17 Date: Tue, 27 Jan 2026 01:01:43 +0800 Subject: [PATCH] implement can_play_type on ohos backend, fix player interface Signed-off-by: rayguo17 --- backends/ohos/Cargo.toml | 4 +- backends/ohos/lib.rs | 4 +- backends/ohos/player.rs | 4 ++ backends/ohos/registry_scanner.rs | 75 +++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 backends/ohos/registry_scanner.rs diff --git a/backends/ohos/Cargo.toml b/backends/ohos/Cargo.toml index 109ece4b..0165e126 100644 --- a/backends/ohos/Cargo.toml +++ b/backends/ohos/Cargo.toml @@ -16,5 +16,7 @@ servo-media-player = { path = "../../player" } servo-media-streams = { path = "../../streams" } servo-media-traits = { path = "../../traits" } servo-media-webrtc = { path = "../../webrtc" } +mime = "0.3.13" +once_cell = "1.18.0" log = "0.4" -ohos-media-sys = { version = "0.0.4" ,features = ["api-13"] } \ No newline at end of file +ohos-media-sys = { version = "0.0.5" ,features = ["api-21"] } \ No newline at end of file diff --git a/backends/ohos/lib.rs b/backends/ohos/lib.rs index b38a1d9b..b97997a7 100644 --- a/backends/ohos/lib.rs +++ b/backends/ohos/lib.rs @@ -167,10 +167,12 @@ impl Backend for OhosBackend { .collect(), None => vec![], }; - if OHOS_REGISTRY_SCANNER.contains(mime_type.as_str()) { + + if OHOS_REGISTRY_SCANNER.are_mime_and_codecs_supported(&mime_type, &codecs) { if codecs.is_empty() { return SupportsMediaType::Maybe; } + return SupportsMediaType::Probably; } } SupportsMediaType::No diff --git a/backends/ohos/player.rs b/backends/ohos/player.rs index dabf4a4d..32bb280b 100644 --- a/backends/ohos/player.rs +++ b/backends/ohos/player.rs @@ -40,6 +40,10 @@ impl Player for OhosAVPlayer { todo!() } + fn can_resume(&self) -> bool { + todo!() + } + fn stop(&self) -> Result<(), servo_media_player::PlayerError> { todo!() } diff --git a/backends/ohos/registry_scanner.rs b/backends/ohos/registry_scanner.rs new file mode 100644 index 00000000..7b1d6457 --- /dev/null +++ b/backends/ohos/registry_scanner.rs @@ -0,0 +1,75 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use std::collections::HashMap; + +use once_cell::sync::Lazy; + +pub static OHOS_REGISTRY_SCANNER: Lazy = + Lazy::new(|| OhosRegistryScanner::new()); + +// Should be a combination of mime/codecs +// If the type we are matching only contain mime, then we only match the container. +// +pub struct OhosRegistryScanner { + av_player_supported_mime_codecs_type: HashMap<&'static str, &'static [&'static str]>, +} + +impl OhosRegistryScanner { + fn new() -> OhosRegistryScanner { + let mut registry_scanner = OhosRegistryScanner { + av_player_supported_mime_codecs_type: HashMap::new(), + }; + registry_scanner.initialize_av_player_container_and_codecs(); + registry_scanner + } + + pub fn are_mime_and_codecs_supported(&self, container_type: &str, codecs: &Vec<&str>) -> bool { + let Some(supported_codecs) = self + .av_player_supported_mime_codecs_type + .get(container_type) + else { + return false; + }; + codecs.iter().all(|codec| { + supported_codecs.contains(codec) || { + supported_codecs.iter().any(|supported_codec| { + if let Some(stripped) = supported_codec.strip_suffix('*') { + if codec.starts_with(stripped) { + return true; + } + } + false + }) + } + }) + } + + fn initialize_av_player_container_and_codecs(&mut self) { + // Video Container + self.av_player_supported_mime_codecs_type + .insert("video/mp4", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]); + self.av_player_supported_mime_codecs_type + .insert("video/mkv", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]); + self.av_player_supported_mime_codecs_type + .insert("video/ts", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]); + // Audio Container + self.av_player_supported_mime_codecs_type + .insert("audio/m4a", &["aac"]); + self.av_player_supported_mime_codecs_type + .insert("audio/aac", &["aac"]); + self.av_player_supported_mime_codecs_type + .insert("audio/mp3", &["mp3"]); + self.av_player_supported_mime_codecs_type + .insert("audio/ogg", &["vorbis"]); + self.av_player_supported_mime_codecs_type + .insert("audio/wav", &["1", "audio/pcm"]); + self.av_player_supported_mime_codecs_type + .insert("audio/flac", &["flac"]); + self.av_player_supported_mime_codecs_type + .insert("audio/amr", &["amr"]); + self.av_player_supported_mime_codecs_type + .insert("audio/ape", &["ape"]); + } +}