Skip to main content

browser_protocol/media/
mod.rs

1//! This domain allows detailed inspection of media elements.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5/// Players will get an ID that is unique within the agent context.
6
7pub type PlayerId = String;
8
9
10pub type Timestamp = f64;
11
12/// Have one type per entry in MediaLogRecord::Type
13/// Corresponds to kMessage
14
15#[derive(Debug, Clone, Serialize, Deserialize, Default)]
16#[serde(rename_all = "camelCase")]
17pub struct PlayerMessage {
18    /// Keep in sync with MediaLogMessageLevel
19    /// We are currently keeping the message level 'error' separate from the
20    /// PlayerError type because right now they represent different things,
21    /// this one being a DVLOG(ERROR) style log message that gets printed
22    /// based on what log level is selected in the UI, and the other is a
23    /// representation of a media::PipelineStatus object. Soon however we're
24    /// going to be moving away from using PipelineStatus for errors and
25    /// introducing a new error type which should hopefully let us integrate
26    /// the error log level into the PlayerError type.
27
28    pub level: String,
29
30    pub message: String,
31}
32
33/// Corresponds to kMediaPropertyChange
34
35#[derive(Debug, Clone, Serialize, Deserialize, Default)]
36#[serde(rename_all = "camelCase")]
37pub struct PlayerProperty {
38
39    pub name: String,
40
41    pub value: String,
42}
43
44/// Corresponds to kMediaEventTriggered
45
46#[derive(Debug, Clone, Serialize, Deserialize, Default)]
47#[serde(rename_all = "camelCase")]
48pub struct PlayerEvent {
49
50    pub timestamp: Timestamp,
51
52    pub value: String,
53}
54
55/// Represents logged source line numbers reported in an error.
56/// NOTE: file and line are from chromium c++ implementation code, not js.
57
58#[derive(Debug, Clone, Serialize, Deserialize, Default)]
59#[serde(rename_all = "camelCase")]
60pub struct PlayerErrorSourceLocation {
61
62    pub file: String,
63
64    pub line: i64,
65}
66
67/// Corresponds to kMediaError
68
69#[derive(Debug, Clone, Serialize, Deserialize, Default)]
70#[serde(rename_all = "camelCase")]
71pub struct PlayerError {
72
73    pub errorType: String,
74    /// Code is the numeric enum entry for a specific set of error codes, such
75    /// as PipelineStatusCodes in media/base/pipeline_status.h
76
77    pub code: i64,
78    /// A trace of where this error was caused / where it passed through.
79
80    pub stack: Vec<PlayerErrorSourceLocation>,
81    /// Errors potentially have a root cause error, ie, a DecoderError might be
82    /// caused by an WindowsError
83
84    pub cause: Vec<PlayerError>,
85    /// Extra data attached to an error, such as an HRESULT, Video Codec, etc.
86
87    pub data: serde_json::Map<String, JsonValue>,
88}
89
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default)]
92#[serde(rename_all = "camelCase")]
93pub struct Player {
94
95    pub playerId: PlayerId,
96
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub domNodeId: Option<crate::dom::BackendNodeId>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize, Default)]
102pub struct EnableParams {}
103
104impl EnableParams { pub const METHOD: &'static str = "Media.enable"; }
105
106impl crate::CdpCommand for EnableParams {
107    const METHOD: &'static str = "Media.enable";
108    type Response = crate::EmptyReturns;
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize, Default)]
112pub struct DisableParams {}
113
114impl DisableParams { pub const METHOD: &'static str = "Media.disable"; }
115
116impl crate::CdpCommand for DisableParams {
117    const METHOD: &'static str = "Media.disable";
118    type Response = crate::EmptyReturns;
119}