Skip to main content

cdp_driver/protocol/
media.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! This domain allows detailed inspection of media elements.
5//!
6//! Types, command parameters and event payloads for the `Media`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// Players will get an ID that is unique within the agent context.
15pub type PlayerId = String;
16
17pub type Timestamp = f64;
18
19/// Have one type per entry in MediaLogRecord::Type Corresponds to kMessage
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct PlayerMessage {
22    /// Keep in sync with MediaLogMessageLevel We are currently keeping the
23    /// message level 'error' separate from the PlayerError type because right now
24    /// they represent different things, this one being a DVLOG(ERROR) style log
25    /// message that gets printed based on what log level is selected in the UI,
26    /// and the other is a representation of a media::PipelineStatus object. Soon
27    /// however we're going to be moving away from using PipelineStatus for errors
28    /// and introducing a new error type which should hopefully let us integrate
29    /// the error log level into the PlayerError type.
30    pub level: PlayerMessageLevel,
31    pub message: String,
32}
33
34/// The values `level` accepts on `PlayerMessage`.
35#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
36pub enum PlayerMessageLevel {
37    /// `error`
38    #[serde(rename = "error")]
39    Error,
40    /// `warning`
41    #[serde(rename = "warning")]
42    Warning,
43    /// `info`
44    #[serde(rename = "info")]
45    Info,
46    /// `debug`
47    #[serde(rename = "debug")]
48    Debug,
49    /// A value this vendored schema does not list. Chrome adds values ahead of
50    /// the published protocol, so an unrecognised one is kept as it arrived
51    /// rather than failing the payload it came in.
52    #[serde(untagged)]
53    Unrecognized(String),
54}
55
56/// Corresponds to kMediaPropertyChange
57#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
58pub struct PlayerProperty {
59    pub name: String,
60    pub value: String,
61}
62
63/// Corresponds to kMediaEventTriggered
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct PlayerEvent {
66    pub timestamp: Timestamp,
67    pub value: String,
68}
69
70/// Represents logged source line numbers reported in an error. NOTE: file and
71/// line are from chromium c++ implementation code, not js.
72#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
73pub struct PlayerErrorSourceLocation {
74    pub file: String,
75    pub line: i64,
76}
77
78/// Corresponds to kMediaError
79#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
80pub struct PlayerError {
81    #[serde(rename = "errorType")]
82    pub error_type: String,
83    /// Code is the numeric enum entry for a specific set of error codes, such as
84    /// PipelineStatusCodes in media/base/pipeline_status.h
85    pub code: i64,
86    /// A trace of where this error was caused / where it passed through.
87    pub stack: Vec<PlayerErrorSourceLocation>,
88    /// Errors potentially have a root cause error, ie, a DecoderError might be
89    /// caused by an WindowsError
90    pub cause: Vec<PlayerError>,
91    /// Extra data attached to an error, such as an HRESULT, Video Codec, etc.
92    pub data: serde_json::Value,
93}
94
95#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
96pub struct Player {
97    #[serde(rename = "playerId")]
98    pub player_id: PlayerId,
99    #[serde(rename = "domNodeId", default, skip_serializing_if = "Option::is_none")]
100    pub dom_node_id: Option<crate::protocol::dom::BackendNodeId>,
101}
102
103/// Enables the Media domain
104///
105/// Parameters of `Media.enable`.
106#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
107pub struct EnableParams {}
108
109impl crate::typed::Command for EnableParams {
110    const METHOD: &'static str = "Media.enable";
111    type Returns = crate::typed::NoReturns;
112}
113
114/// Disables the Media domain.
115///
116/// Parameters of `Media.disable`.
117#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
118pub struct DisableParams {}
119
120impl crate::typed::Command for DisableParams {
121    const METHOD: &'static str = "Media.disable";
122    type Returns = crate::typed::NoReturns;
123}
124
125/// This can be called multiple times, and can be used to set / override /
126/// remove player properties. A null propValue indicates removal.
127///
128/// Payload of the `Media.playerPropertiesChanged` event.
129#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
130pub struct PlayerPropertiesChangedEvent {
131    #[serde(rename = "playerId")]
132    pub player_id: PlayerId,
133    pub properties: Vec<PlayerProperty>,
134}
135
136impl crate::typed::Event for PlayerPropertiesChangedEvent {
137    const METHOD: &'static str = "Media.playerPropertiesChanged";
138}
139
140/// Send events as a list, allowing them to be batched on the browser for less
141/// congestion. If batched, events must ALWAYS be in chronological order.
142///
143/// Payload of the `Media.playerEventsAdded` event.
144#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
145pub struct PlayerEventsAddedEvent {
146    #[serde(rename = "playerId")]
147    pub player_id: PlayerId,
148    pub events: Vec<PlayerEvent>,
149}
150
151impl crate::typed::Event for PlayerEventsAddedEvent {
152    const METHOD: &'static str = "Media.playerEventsAdded";
153}
154
155/// Send a list of any messages that need to be delivered.
156///
157/// Payload of the `Media.playerMessagesLogged` event.
158#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
159pub struct PlayerMessagesLoggedEvent {
160    #[serde(rename = "playerId")]
161    pub player_id: PlayerId,
162    pub messages: Vec<PlayerMessage>,
163}
164
165impl crate::typed::Event for PlayerMessagesLoggedEvent {
166    const METHOD: &'static str = "Media.playerMessagesLogged";
167}
168
169/// Send a list of any errors that need to be delivered.
170///
171/// Payload of the `Media.playerErrorsRaised` event.
172#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
173pub struct PlayerErrorsRaisedEvent {
174    #[serde(rename = "playerId")]
175    pub player_id: PlayerId,
176    pub errors: Vec<PlayerError>,
177}
178
179impl crate::typed::Event for PlayerErrorsRaisedEvent {
180    const METHOD: &'static str = "Media.playerErrorsRaised";
181}
182
183/// Called whenever a player is created, or when a new agent joins and
184/// receives a list of active players. If an agent is restored, it will
185/// receive one event for each active player.
186///
187/// Payload of the `Media.playerCreated` event.
188#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
189pub struct PlayerCreatedEvent {
190    pub player: Player,
191}
192
193impl crate::typed::Event for PlayerCreatedEvent {
194    const METHOD: &'static str = "Media.playerCreated";
195}