summary refs log tree commit diff
path: root/src/tracks.rs
blob: 4d69e122d2d26a0a86115a5bd15f26a886206821 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::collections::BTreeMap;

use relm4::SharedState;

pub type StreamIndex = usize;

#[derive(Debug, Clone)]
pub struct TrackMetadata {
    pub language: Option<isolang::Language>,
    pub title: Option<String>,
}

#[derive(Debug, Clone)]
pub struct SubtitleTrack {
    pub metadata: TrackMetadata,
    pub cues: Vec<SubtitleCue>,
}

#[derive(Debug, Clone)]
pub struct SubtitleCue {
    pub start: gst::ClockTime,
    pub end: gst::ClockTime,
    pub text: String,
}

pub static SUBTITLE_TRACKS: SharedState<BTreeMap<StreamIndex, SubtitleTrack>> = SharedState::new();

impl TrackMetadata {
    pub fn from_ffmpeg_stream(stream: &ffmpeg::Stream) -> Self {
        let language_code = stream.metadata().get("language").map(|s| s.to_string());
        let title = stream.metadata().get("title").map(|s| s.to_string());

        Self {
            language: language_code.and_then(|code| isolang::Language::from_639_2b(&code)),
            title,
        }
    }
}