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
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
pub mod definitions;
pub mod manager;
mod runner;
pub mod steps;
pub use runner::{start_workflow, WorkflowRequest, WorkflowRequestOperation, WorkflowStatus};
use crate::codecs::{AudioCodec, VideoCodec};
use crate::endpoints::rtmp_server::RtmpEndpointMediaData;
use crate::utils::hash_map_to_stream_metadata;
use crate::{StreamId, VideoTimestamp};
use bytes::Bytes;
use rml_rtmp::time::RtmpTimestamp;
use std::collections::HashMap;
use std::time::Duration;
pub use runner::{WorkflowState, WorkflowStepState};
#[derive(Clone, Debug, PartialEq)]
pub struct MediaNotification {
    
    pub stream_id: StreamId,
    
    pub content: MediaNotificationContent,
}
#[derive(Clone, Debug, PartialEq)]
pub enum MediaNotificationContent {
    
    
    NewIncomingStream {
        
        stream_name: String,
    },
    
    
    
    
    StreamDisconnected,
    
    Video {
        codec: VideoCodec,
        is_sequence_header: bool,
        is_keyframe: bool,
        data: Bytes,
        timestamp: VideoTimestamp,
    },
    
    Audio {
        codec: AudioCodec,
        is_sequence_header: bool,
        data: Bytes,
        timestamp: Duration,
    },
    
    Metadata { data: HashMap<String, String> },
}
impl MediaNotificationContent {
    
    pub fn to_rtmp_media_data(&self) -> Option<RtmpEndpointMediaData> {
        match self {
            MediaNotificationContent::StreamDisconnected => return None,
            MediaNotificationContent::NewIncomingStream { stream_name: _ } => return None,
            MediaNotificationContent::Metadata { data } => {
                Some(RtmpEndpointMediaData::NewStreamMetaData {
                    metadata: hash_map_to_stream_metadata(&data),
                })
            }
            MediaNotificationContent::Video {
                codec,
                is_keyframe,
                is_sequence_header,
                data,
                timestamp,
            } => Some(RtmpEndpointMediaData::NewVideoData {
                data: data.clone(),
                codec: codec.clone(),
                is_keyframe: *is_keyframe,
                is_sequence_header: *is_sequence_header,
                timestamp: RtmpTimestamp::new(timestamp.dts.as_millis() as u32),
                composition_time_offset: timestamp.pts_offset,
            }),
            MediaNotificationContent::Audio {
                codec,
                is_sequence_header,
                timestamp,
                data,
            } => Some(RtmpEndpointMediaData::NewAudioData {
                data: data.clone(),
                codec: codec.clone(),
                timestamp: RtmpTimestamp::new(timestamp.as_millis() as u32),
                is_sequence_header: *is_sequence_header,
            }),
        }
    }
}