Skip to main content

lingxia_platform/traits/
media_runtime.rs

1use std::path::{Path, PathBuf};
2
3use crate::error::PlatformError;
4
5use super::media_interaction::MediaKind;
6
7#[derive(Debug, Clone)]
8pub struct ImageInfo {
9    pub width: u32,
10    pub height: u32,
11    pub mime_type: Option<String>,
12}
13
14#[derive(Debug, Clone)]
15pub struct CompressImageRequest {
16    pub source_uri: String,
17    pub quality: u8,
18    pub max_width: Option<u32>,
19    pub max_height: Option<u32>,
20    pub output_path: PathBuf,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum VideoCompressQuality {
25    Low,
26    Medium,
27    High,
28}
29
30#[derive(Debug, Clone)]
31pub struct CompressVideoRequest {
32    pub source_uri: String,
33    pub quality: Option<VideoCompressQuality>,
34    /// Target average bitrate in kbps.
35    pub bitrate_kbps: Option<u32>,
36    /// Target frame rate in fps.
37    pub fps: Option<u32>,
38    /// Scale ratio relative to source resolution in (0, 1].
39    pub resolution_ratio: Option<f32>,
40    pub output_path: PathBuf,
41}
42
43#[derive(Debug, Clone)]
44pub struct CompressedVideo {
45    pub path: PathBuf,
46    pub width: u32,
47    pub height: u32,
48    pub duration_ms: u64,
49    pub size: u64,
50    pub mime_type: Option<String>,
51}
52
53#[derive(Debug, Clone)]
54pub struct VideoInfo {
55    pub width: u32,
56    pub height: u32,
57    pub duration_ms: u64,
58    pub rotation: Option<u16>,
59    pub bitrate: Option<u64>,
60    pub fps: Option<f32>,
61    pub mime_type: Option<String>,
62}
63
64#[derive(Debug, Clone)]
65pub struct ExtractVideoThumbnailRequest {
66    pub source_uri: String,
67    pub output_path: PathBuf,
68    pub max_width: Option<u32>,
69    pub max_height: Option<u32>,
70    pub time_ms: Option<u64>,
71    pub quality: u8,
72}
73
74#[derive(Debug, Clone)]
75pub struct VideoThumbnail {
76    pub path: PathBuf,
77    pub width: u32,
78    pub height: u32,
79    pub mime_type: Option<String>,
80}
81
82pub trait MediaRuntime: Send + Sync + 'static {
83    /// Copy a picked/album media asset identified by `uri` into a local file at `dest_path`.
84    ///
85    /// Notes:
86    /// - `uri` is an opaque platform media reference coming from platform pickers and may not be a
87    ///   directly readable filesystem path.
88    /// - Implementations should support platform-specific schemes as applicable, for example:
89    ///   - Android: `content://...`
90    ///   - iOS: `ph://...` (or other Photos identifiers)
91    ///   - Harmony: picker URIs such as `file://media/...`
92    ///   - Some platforms may also provide `file:///absolute/path` (or an absolute path string).
93    /// - Implementations should create parent directories for `dest_path` if needed and write the
94    ///   file content so that `dest_path` exists on success.
95    fn copy_album_media_to_file(
96        &self,
97        uri: &str,
98        dest_path: &Path,
99        kind: MediaKind,
100    ) -> Result<(), PlatformError>;
101
102    fn get_image_info(&self, uri: &str) -> Result<ImageInfo, PlatformError>;
103
104    fn compress_image(&self, request: &CompressImageRequest) -> Result<PathBuf, PlatformError>;
105
106    fn compress_video(
107        &self,
108        request: &CompressVideoRequest,
109    ) -> Result<CompressedVideo, PlatformError>;
110
111    fn get_video_info(&self, uri: &str) -> Result<VideoInfo, PlatformError>;
112
113    fn extract_video_thumbnail(
114        &self,
115        request: &ExtractVideoThumbnailRequest,
116    ) -> Result<VideoThumbnail, PlatformError>;
117}