PageRenderTime 134ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/bwcheck/src/actionscript/org/flowplayer/bwcheck/net/ScreenSizeRule.as

https://github.com/longlho/flowplayer
ActionScript | 64 lines | 42 code | 13 blank | 9 comment | 2 complexity | e65fc315bf8b7fc3a628062a886464fb MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. /*
  2. * This file is part of Flowplayer, http://flowplayer.org
  3. *
  4. * By: Daniel Rossi <electroteque@gmail.com>, Anssi Piirainen <api@iki.fi> Flowplayer Oy
  5. * Copyright (c) 2009, 2010 Electroteque Multimedia, Flowplayer Oy
  6. *
  7. * Released under the MIT License:
  8. * http://www.opensource.org/licenses/mit-license.php
  9. */
  10. package org.flowplayer.bwcheck.net {
  11. import org.flowplayer.bwcheck.detect.*;
  12. import org.flowplayer.bwcheck.config.Config;
  13. import org.flowplayer.util.Log;
  14. import org.flowplayer.view.Flowplayer;
  15. import org.flowplayer.net.BitrateItem;
  16. import org.flowplayer.net.IStreamSelectionManager;
  17. import org.osmf.net.DynamicStreamingItem;
  18. import org.osmf.net.SwitchingRuleBase;
  19. import org.osmf.net.rtmpstreaming.RTMPNetStreamMetrics;
  20. import org.osmf.net.NetStreamMetricsBase;
  21. public class ScreenSizeRule extends SwitchingRuleBase {
  22. private var _player:Flowplayer;
  23. private var log:Log = new Log(this);
  24. private var _bitrates:Vector.<BitrateItem>;
  25. private var _config:Config;
  26. public function ScreenSizeRule(metrics:NetStreamMetricsBase, streamSelectionManager:IStreamSelectionManager, player:Flowplayer, config:Config) {
  27. super(metrics);
  28. _bitrates = streamSelectionManager.bitrates;
  29. _player = player;
  30. _config = config;
  31. }
  32. override public function getNewIndex():int {
  33. var screenWidth:Number = _player.screen.getDisplayObject().width;
  34. for (var i:Number = _bitrates.length - 1; i >= 0; i--) {
  35. var item:BitrateItem = _bitrates[i];
  36. log.debug("candidate '" + item.streamName + "' has width " + item.width);
  37. var fitsScreen:Boolean = BWStreamSelectionManager.fitsScreen(item, _player, _config);
  38. log.debug("fits screen? " + fitsScreen);
  39. if (fitsScreen) {
  40. log.debug("selecting bitrate with width " + item.width + ", index " + i);
  41. return i;
  42. break;
  43. }
  44. }
  45. return -1;
  46. }
  47. private function get rtmpMetrics():RTMPNetStreamMetrics {
  48. return metrics as RTMPNetStreamMetrics;
  49. }
  50. }
  51. }