zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Media (experimental)
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
 
class PlayerId(str):
    '''
    Players will get an ID that is unique within the agent context.
    '''
    def to_json(self) -> str:
        return self
 
    @classmethod
    def from_json(cls, json: str) -> PlayerId:
        return cls(json)
 
    def __repr__(self):
        return 'PlayerId({})'.format(super().__repr__())
 
 
class Timestamp(float):
    def to_json(self) -> float:
        return self
 
    @classmethod
    def from_json(cls, json: float) -> Timestamp:
        return cls(json)
 
    def __repr__(self):
        return 'Timestamp({})'.format(super().__repr__())
 
 
@dataclass
class PlayerMessage:
    '''
    Have one type per entry in MediaLogRecord::Type
    Corresponds to kMessage
    '''
    #: Keep in sync with MediaLogMessageLevel
    #: We are currently keeping the message level 'error' separate from the
    #: PlayerError type because right now they represent different things,
    #: this one being a DVLOG(ERROR) style log message that gets printed
    #: based on what log level is selected in the UI, and the other is a
    #: representation of a media::PipelineStatus object. Soon however we're
    #: going to be moving away from using PipelineStatus for errors and
    #: introducing a new error type which should hopefully let us integrate
    #: the error log level into the PlayerError type.
    level: str
 
    message: str
 
    def to_json(self):
        json = dict()
        json['level'] = self.level
        json['message'] = self.message
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            level=str(json['level']),
            message=str(json['message']),
        )
 
 
@dataclass
class PlayerProperty:
    '''
    Corresponds to kMediaPropertyChange
    '''
    name: str
 
    value: str
 
    def to_json(self):
        json = dict()
        json['name'] = self.name
        json['value'] = self.value
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            name=str(json['name']),
            value=str(json['value']),
        )
 
 
@dataclass
class PlayerEvent:
    '''
    Corresponds to kMediaEventTriggered
    '''
    timestamp: Timestamp
 
    value: str
 
    def to_json(self):
        json = dict()
        json['timestamp'] = self.timestamp.to_json()
        json['value'] = self.value
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            timestamp=Timestamp.from_json(json['timestamp']),
            value=str(json['value']),
        )
 
 
@dataclass
class PlayerErrorSourceLocation:
    '''
    Represents logged source line numbers reported in an error.
    NOTE: file and line are from chromium c++ implementation code, not js.
    '''
    file: str
 
    line: int
 
    def to_json(self):
        json = dict()
        json['file'] = self.file
        json['line'] = self.line
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            file=str(json['file']),
            line=int(json['line']),
        )
 
 
@dataclass
class PlayerError:
    '''
    Corresponds to kMediaError
    '''
    error_type: str
 
    #: Code is the numeric enum entry for a specific set of error codes, such
    #: as PipelineStatusCodes in media/base/pipeline_status.h
    code: int
 
    #: A trace of where this error was caused / where it passed through.
    stack: typing.List[PlayerErrorSourceLocation]
 
    #: Errors potentially have a root cause error, ie, a DecoderError might be
    #: caused by an WindowsError
    cause: typing.List[PlayerError]
 
    #: Extra data attached to an error, such as an HRESULT, Video Codec, etc.
    data: dict
 
    def to_json(self):
        json = dict()
        json['errorType'] = self.error_type
        json['code'] = self.code
        json['stack'] = [i.to_json() for i in self.stack]
        json['cause'] = [i.to_json() for i in self.cause]
        json['data'] = self.data
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            error_type=str(json['errorType']),
            code=int(json['code']),
            stack=[PlayerErrorSourceLocation.from_json(i) for i in json['stack']],
            cause=[PlayerError.from_json(i) for i in json['cause']],
            data=dict(json['data']),
        )
 
 
def enable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Enables the Media domain
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Media.enable',
    }
    json = yield cmd_dict
 
 
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Disables the Media domain.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Media.disable',
    }
    json = yield cmd_dict
 
 
@event_class('Media.playerPropertiesChanged')
@dataclass
class PlayerPropertiesChanged:
    '''
    This can be called multiple times, and can be used to set / override /
    remove player properties. A null propValue indicates removal.
    '''
    player_id: PlayerId
    properties: typing.List[PlayerProperty]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerPropertiesChanged:
        return cls(
            player_id=PlayerId.from_json(json['playerId']),
            properties=[PlayerProperty.from_json(i) for i in json['properties']]
        )
 
 
@event_class('Media.playerEventsAdded')
@dataclass
class PlayerEventsAdded:
    '''
    Send events as a list, allowing them to be batched on the browser for less
    congestion. If batched, events must ALWAYS be in chronological order.
    '''
    player_id: PlayerId
    events: typing.List[PlayerEvent]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerEventsAdded:
        return cls(
            player_id=PlayerId.from_json(json['playerId']),
            events=[PlayerEvent.from_json(i) for i in json['events']]
        )
 
 
@event_class('Media.playerMessagesLogged')
@dataclass
class PlayerMessagesLogged:
    '''
    Send a list of any messages that need to be delivered.
    '''
    player_id: PlayerId
    messages: typing.List[PlayerMessage]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerMessagesLogged:
        return cls(
            player_id=PlayerId.from_json(json['playerId']),
            messages=[PlayerMessage.from_json(i) for i in json['messages']]
        )
 
 
@event_class('Media.playerErrorsRaised')
@dataclass
class PlayerErrorsRaised:
    '''
    Send a list of any errors that need to be delivered.
    '''
    player_id: PlayerId
    errors: typing.List[PlayerError]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerErrorsRaised:
        return cls(
            player_id=PlayerId.from_json(json['playerId']),
            errors=[PlayerError.from_json(i) for i in json['errors']]
        )
 
 
@event_class('Media.playersCreated')
@dataclass
class PlayersCreated:
    '''
    Called whenever a player is created, or when a new agent joins and receives
    a list of active players. If an agent is restored, it will receive the full
    list of player ids and all events again.
    '''
    players: typing.List[PlayerId]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayersCreated:
        return cls(
            players=[PlayerId.from_json(i) for i in json['players']]
        )