Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: content/browser/resources/media/new/main.js

Issue 20804002: Added the next series of files that go into media-internals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * A global object that gets used by the C++ interface.
7 */
8 var media = (function() {
9 'use strict';
10
11 var manager = null;
12
13 /**
14 * Users of |media| must call initialize prior to calling other methods.
15 */
scherkus (not reviewing) 2013/07/29 23:55:18 jsdoc for man argument? also man isn't terribly g
Ty Overby 2013/07/30 00:13:34 Done.
16 function initialize(man) {
17 manager = man;
18 }
19
20 /**
21 * Call to modify or add a system property.
22 */
23 function onSystemProperty(timestamp, key, value) {
24 console.log('System properties not yet implemented');
25 }
26
27 /**
28 * Call to modify or add a property on a player.
29 */
30 function onPlayerProperty(id, timestamp, key, value) {
31 manager.updatePlayerInfo(id, timestamp, key, value);
32 }
33
34 function onPlayerPropertyNoRecord(id, timestamp, key, value) {
35 manager.updatePlayerInfoNoRecord(id, timestamp, key, value);
36 }
37
38 /**
39 * Call to add a player.
40 */
41 function onPlayerOpen(id, timestamp) {
42 manager.addPlayer(id, timestamp);
43 }
44
45 /**
46 * Call to remove a player.
47 */
48 function onPlayerClose(id) {
49 manager.removePlayer(id);
50 }
51
52 var media = {
53 onSystemProperty: onSystemProperty,
54 onPlayerProperty: onPlayerProperty,
55 onPlayerPropertyNoRecord: onPlayerPropertyNoRecord,
56 onPlayerOpen: onPlayerOpen,
57 onPlayerClose: onPlayerClose,
58
59 initialize: initialize,
60 };
61
62 // Everything beyond this point is for backwards compatibility reasons.
63 // It will go away when the backend is updated.
64
65 media.onNetUpdate = function(update) {
66 // TODO(tyoverby): Implement
67 };
68
69 media.onRendererTerminated = function(renderId) {
70 util.object.forEach(manager.players_, function(playerInfo, id) {
71 if (playerInfo.properties['render_id'] == renderId) {
72 media.onPlayerClose(id);
73 }
74 });
75 };
76
77 // For whatever reason, addAudioStream is also called on
78 // the removal of audio streams.
79 media.addAudioStream = function(event) {
80 switch (event.status) {
81 case 'created':
82 media.onPlayerOpen(event.id);
83 // We have to simulate the timestamp since it isn't provided to us.
84 media.onPlayerProperty(
85 event.id, (new Date()).getTime(), 'playing', event.playing);
86 break;
87 case 'closed':
88 media.onPlayerClose(event.id);
89 break;
90 }
91 };
92 media.onItemDeleted = function() {
93 // This only gets called when an audio stream is removed, which
94 // for whatever reason is also handled by addAudioStream...
95 // Because it is already handled, we can safely ignore it.
96 };
97
98 media.onMediaEvent = function(event) {
99 var source = event.renderer + ':' + event.player;
100
101 // Although this gets called on every event, there is nothing we can do
102 // about this because there is no onOpen event.
103 media.onPlayerOpen(source);
104 media.onPlayerPropertyNoRecord(
105 source, event.ticksMillis, 'render_id', event.renderer);
106 media.onPlayerPropertyNoRecord(
107 source, event.ticksMillis, 'player_id', event.player);
108
109 var propertyCount = 0;
110 util.object.forEach(event.params, function(value, key) {
111 key = key.trim();
112
113 // These keys get spammed *a lot*, so put them on the display
114 // but don't log list.
115 if (key === 'buffer_start' ||
116 key === 'buffer_end' ||
117 key === 'buffer_current' ||
118 key === 'is_downloading_data') {
119 media.onPlayerPropertyNoRecord(
120 source, event.ticksMillis, key, value);
121 } else {
122 media.onPlayerProperty(source, event.ticksMillis, key, value);
123 }
124 propertyCount += 1;
125 });
126
127 if (propertyCount === 0) {
128 media.onPlayerProperty(
129 source, event.ticksMillis, 'EVENT', event.type);
130 }
131 };
132
133 return media;
134 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698