lingxia_platform/traits/
media_runtime.rs1use 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 pub bitrate_kbps: Option<u32>,
36 pub fps: Option<u32>,
38 pub resolution_ratio: Option<f32>,
40 pub output_path: PathBuf,
41 pub progress_callback_id: u64,
45 pub callback_id: u64,
49}
50
51#[derive(Debug, Clone)]
52pub struct CompressedVideo {
53 pub path: PathBuf,
54 pub width: u32,
55 pub height: u32,
56 pub duration_ms: u64,
57 pub size: u64,
58 pub mime_type: Option<String>,
59}
60
61#[derive(Debug, Clone)]
62pub struct VideoInfo {
63 pub width: u32,
64 pub height: u32,
65 pub duration_ms: u64,
66 pub rotation: Option<u16>,
67 pub bitrate: Option<u64>,
68 pub fps: Option<f32>,
69 pub mime_type: Option<String>,
70}
71
72#[derive(Debug, Clone)]
73pub struct ExtractVideoThumbnailRequest {
74 pub source_uri: String,
75 pub output_path: PathBuf,
76 pub max_width: Option<u32>,
77 pub max_height: Option<u32>,
78 pub time_ms: Option<u64>,
79 pub quality: u8,
80}
81
82#[derive(Debug, Clone)]
83pub struct VideoThumbnail {
84 pub path: PathBuf,
85 pub width: u32,
86 pub height: u32,
87 pub mime_type: Option<String>,
88}
89
90pub trait MediaRuntime: Send + Sync + 'static {
91 fn copy_album_media_to_file(
104 &self,
105 uri: &str,
106 dest_path: &Path,
107 kind: MediaKind,
108 ) -> Result<(), PlatformError>;
109
110 fn get_image_info(&self, uri: &str) -> Result<ImageInfo, PlatformError>;
111
112 fn compress_image(&self, request: &CompressImageRequest) -> Result<PathBuf, PlatformError>;
113
114 fn compress_video(&self, request: &CompressVideoRequest) -> Result<(), PlatformError>;
117
118 fn cancel_compress_video(&self, callback_id: u64) -> Result<(), PlatformError>;
122
123 fn get_video_info(&self, uri: &str) -> Result<VideoInfo, PlatformError>;
124
125 fn extract_video_thumbnail(
126 &self,
127 request: &ExtractVideoThumbnailRequest,
128 ) -> Result<VideoThumbnail, PlatformError>;
129}