Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.

Commit 1e9ec06

Browse files
authored
implement can_play_type on ohos backend, fix player interface (#487)
Signed-off-by: rayguo17 <rayguo17@gmail.com>
1 parent f384dbc commit 1e9ec06

4 files changed

Lines changed: 85 additions & 2 deletions

File tree

backends/ohos/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ servo-media-player = { path = "../../player" }
1616
servo-media-streams = { path = "../../streams" }
1717
servo-media-traits = { path = "../../traits" }
1818
servo-media-webrtc = { path = "../../webrtc" }
19+
mime = "0.3.13"
20+
once_cell = "1.18.0"
1921
log = "0.4"
20-
ohos-media-sys = { version = "0.0.4" ,features = ["api-13"] }
22+
ohos-media-sys = { version = "0.0.5" ,features = ["api-21"] }

backends/ohos/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ impl Backend for OhosBackend {
167167
.collect(),
168168
None => vec![],
169169
};
170-
if OHOS_REGISTRY_SCANNER.contains(mime_type.as_str()) {
170+
171+
if OHOS_REGISTRY_SCANNER.are_mime_and_codecs_supported(&mime_type, &codecs) {
171172
if codecs.is_empty() {
172173
return SupportsMediaType::Maybe;
173174
}
175+
return SupportsMediaType::Probably;
174176
}
175177
}
176178
SupportsMediaType::No

backends/ohos/player.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ impl Player for OhosAVPlayer {
4040
todo!()
4141
}
4242

43+
fn can_resume(&self) -> bool {
44+
todo!()
45+
}
46+
4347
fn stop(&self) -> Result<(), servo_media_player::PlayerError> {
4448
todo!()
4549
}

backends/ohos/registry_scanner.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
5+
use std::collections::HashMap;
6+
7+
use once_cell::sync::Lazy;
8+
9+
pub static OHOS_REGISTRY_SCANNER: Lazy<OhosRegistryScanner> =
10+
Lazy::new(|| OhosRegistryScanner::new());
11+
12+
// Should be a combination of mime/codecs
13+
// If the type we are matching only contain mime, then we only match the container.
14+
//
15+
pub struct OhosRegistryScanner {
16+
av_player_supported_mime_codecs_type: HashMap<&'static str, &'static [&'static str]>,
17+
}
18+
19+
impl OhosRegistryScanner {
20+
fn new() -> OhosRegistryScanner {
21+
let mut registry_scanner = OhosRegistryScanner {
22+
av_player_supported_mime_codecs_type: HashMap::new(),
23+
};
24+
registry_scanner.initialize_av_player_container_and_codecs();
25+
registry_scanner
26+
}
27+
28+
pub fn are_mime_and_codecs_supported(&self, container_type: &str, codecs: &Vec<&str>) -> bool {
29+
let Some(supported_codecs) = self
30+
.av_player_supported_mime_codecs_type
31+
.get(container_type)
32+
else {
33+
return false;
34+
};
35+
codecs.iter().all(|codec| {
36+
supported_codecs.contains(codec) || {
37+
supported_codecs.iter().any(|supported_codec| {
38+
if let Some(stripped) = supported_codec.strip_suffix('*') {
39+
if codec.starts_with(stripped) {
40+
return true;
41+
}
42+
}
43+
false
44+
})
45+
}
46+
})
47+
}
48+
49+
fn initialize_av_player_container_and_codecs(&mut self) {
50+
// Video Container
51+
self.av_player_supported_mime_codecs_type
52+
.insert("video/mp4", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]);
53+
self.av_player_supported_mime_codecs_type
54+
.insert("video/mkv", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]);
55+
self.av_player_supported_mime_codecs_type
56+
.insert("video/ts", &["hev1*", "hvc1*", "aac", "mp3", "avc*"]);
57+
// Audio Container
58+
self.av_player_supported_mime_codecs_type
59+
.insert("audio/m4a", &["aac"]);
60+
self.av_player_supported_mime_codecs_type
61+
.insert("audio/aac", &["aac"]);
62+
self.av_player_supported_mime_codecs_type
63+
.insert("audio/mp3", &["mp3"]);
64+
self.av_player_supported_mime_codecs_type
65+
.insert("audio/ogg", &["vorbis"]);
66+
self.av_player_supported_mime_codecs_type
67+
.insert("audio/wav", &["1", "audio/pcm"]);
68+
self.av_player_supported_mime_codecs_type
69+
.insert("audio/flac", &["flac"]);
70+
self.av_player_supported_mime_codecs_type
71+
.insert("audio/amr", &["amr"]);
72+
self.av_player_supported_mime_codecs_type
73+
.insert("audio/ape", &["ape"]);
74+
}
75+
}

0 commit comments

Comments
 (0)