summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/media/eme_player_js/eme_app.js
blob: 4c2ec0d86bb78dd9b33fcc9bb17e4b8962230145 (plain)
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// EMEApp is responsible for starting playback on the eme_player.html page.
// It selects the suitable player based on key system and other test options.
function EMEApp(testConfig) {
  this.video_ = null;
  this.testConfig_ = testConfig;
  this.updateDocument(testConfig);
}

EMEApp.prototype.createPlayer = function() {
  // Load document test configuration.
  this.updateTestConfig();
  if (this.video_) {
    Utils.timeLog('Delete old video tag.');
    this.video_.pause();
    this.video_.remove();
    delete(this.video_);
  }

  this.video_ = document.createElement('video');
  this.video_.controls = true;
  this.video_.preload = true;
  this.video_.width = 848;
  this.video_.height = 480;
  var videoSpan = document.getElementById(VIDEO_ELEMENT_ID);
  if (videoSpan)
    videoSpan.appendChild(this.video_);
  else
    document.body.appendChild(this.video_);

  var videoPlayer = PlayerUtils.createPlayer(this.video_, this.testConfig_);
  if (!videoPlayer) {
    Utils.timeLog('Cannot create a media player.');
    return;
  }
  Utils.timeLog('Using ' + videoPlayer.constructor.name);
  if (this.testConfig_.runFPS)
    FPSObserver.observe(this.video_);

  videoPlayer.init();
  return videoPlayer;
};

EMEApp.prototype.updateDocument = function(testConfig) {
  // Update document lists with test configuration values.
  Utils.addOptions(KEYSYSTEM_ELEMENT_ID, KEY_SYSTEMS);
  Utils.addOptions(MEDIA_TYPE_ELEMENT_ID, MEDIA_TYPES);
  Utils.addOptions(USE_PREFIXED_EME_ID, EME_VERSIONS_OPTIONS,
                   EME_DISABLED_OPTIONS);
  document.getElementById(MEDIA_FILE_ELEMENT_ID).value =
      testConfig.mediaFile || DEFAULT_MEDIA_FILE;
  document.getElementById(LICENSE_SERVER_ELEMENT_ID).value =
      testConfig.licenseServerURL || DEFAULT_LICENSE_SERVER;
  if (testConfig.keySystem)
    Utils.ensureOptionInList(KEYSYSTEM_ELEMENT_ID, testConfig.keySystem);
  if (testConfig.mediaType)
    Utils.ensureOptionInList(MEDIA_TYPE_ELEMENT_ID, testConfig.mediaType);
  document.getElementById(USE_MSE_ELEMENT_ID).value = testConfig.useMSE;
  if (testConfig.usePrefixedEME)
    document.getElementById(USE_PREFIXED_EME_ID).value = EME_PREFIXED_VERSION;
};

EMEApp.prototype.updateTestConfig = function() {
  // Reload test configuration from document.
  this.testConfig_.mediaFile =
      document.getElementById(MEDIA_FILE_ELEMENT_ID).value;
  this.testConfig_.keySystem =
      document.getElementById(KEYSYSTEM_ELEMENT_ID).value;
  this.testConfig_.mediaType =
      document.getElementById(MEDIA_TYPE_ELEMENT_ID).value;
  this.testConfig_.useMSE =
      document.getElementById(USE_MSE_ELEMENT_ID).value == 'true';
  this.testConfig_.usePrefixedEME = (
      document.getElementById(USE_PREFIXED_EME_ID).value ==
      EME_PREFIXED_VERSION);
  this.testConfig_.licenseServerURL =
      document.getElementById(LICENSE_SERVER_ELEMENT_ID).value;
};