|
| 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