modules/media/src/main/java/com/sun/media/jfxmedia/locator/HLSConnectionHolder.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 576 
 577         private Playlist getPlaylist(int index) {
 578             if (playlists.size() > index) {
 579                 return playlists.get(index);
 580             } else {
 581                 return null;
 582             }
 583         }
 584 
 585         private boolean hasNext() {
 586             infoIndex++;
 587             if (playlistsLocations.size() > infoIndex && playlistsBitrates.size() > infoIndex) {
 588                 return true;
 589             } else {
 590                 return false;
 591             }
 592         }
 593 
 594         private URI getPlaylistURI() throws URISyntaxException, MalformedURLException {
 595             String location = playlistsLocations.get(infoIndex);
 596             if (location.startsWith("http://")) {
 597                 return new URI(location);
 598             } else {
 599                 return new URI(playlistURI.toURL().toString().substring(0, playlistURI.toURL().toString().lastIndexOf("/") + 1) + location);
 600             }
 601         }
 602 
 603         private Playlist getPlaylistBasedOnBitrate(int bitrate) {
 604             int playlistIndex = -1;
 605             int playlistBitrate = 0;
 606 
 607             // Get bitrate that less then requested bitrate, but most closed to it
 608             for (int i = 0; i < playlistsBitrates.size(); i++) {
 609                 int b = playlistsBitrates.get(i);
 610                 if (b < bitrate) {
 611                     if (playlistIndex != -1) {
 612                         if (b > playlistBitrate) {
 613                             playlistBitrate = b;
 614                             playlistIndex = i;
 615                         }
 616                     } else {


 882             if (sequenceNumberStart == -1) {
 883                 sequenceNumberStart = value;
 884             } else if (sequenceNumber != value) {
 885                 sequenceNumberUpdated = true;
 886                 sequenceNumber = value;
 887             } else {
 888                 return false;
 889             }
 890 
 891             return true;
 892         }
 893 
 894         private void close() {
 895             if (isLive) {
 896                 isPlaylistClosed = true;
 897                 liveSemaphore.release();
 898             }
 899         }
 900 
 901         private void setBaseURI(String playlistURI, String URI) {
 902             if (!URI.startsWith("http://")) {
 903                 baseURI = playlistURI.substring(0, playlistURI.lastIndexOf("/") + 1);
 904             }
 905             needBaseURI = false;
 906         }
 907     }
 908 }
   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 576 
 577         private Playlist getPlaylist(int index) {
 578             if (playlists.size() > index) {
 579                 return playlists.get(index);
 580             } else {
 581                 return null;
 582             }
 583         }
 584 
 585         private boolean hasNext() {
 586             infoIndex++;
 587             if (playlistsLocations.size() > infoIndex && playlistsBitrates.size() > infoIndex) {
 588                 return true;
 589             } else {
 590                 return false;
 591             }
 592         }
 593 
 594         private URI getPlaylistURI() throws URISyntaxException, MalformedURLException {
 595             String location = playlistsLocations.get(infoIndex);
 596             if (location.startsWith("http://") || location.startsWith("https://")) {
 597                 return new URI(location);
 598             } else {
 599                 return new URI(playlistURI.toURL().toString().substring(0, playlistURI.toURL().toString().lastIndexOf("/") + 1) + location);
 600             }
 601         }
 602 
 603         private Playlist getPlaylistBasedOnBitrate(int bitrate) {
 604             int playlistIndex = -1;
 605             int playlistBitrate = 0;
 606 
 607             // Get bitrate that less then requested bitrate, but most closed to it
 608             for (int i = 0; i < playlistsBitrates.size(); i++) {
 609                 int b = playlistsBitrates.get(i);
 610                 if (b < bitrate) {
 611                     if (playlistIndex != -1) {
 612                         if (b > playlistBitrate) {
 613                             playlistBitrate = b;
 614                             playlistIndex = i;
 615                         }
 616                     } else {


 882             if (sequenceNumberStart == -1) {
 883                 sequenceNumberStart = value;
 884             } else if (sequenceNumber != value) {
 885                 sequenceNumberUpdated = true;
 886                 sequenceNumber = value;
 887             } else {
 888                 return false;
 889             }
 890 
 891             return true;
 892         }
 893 
 894         private void close() {
 895             if (isLive) {
 896                 isPlaylistClosed = true;
 897                 liveSemaphore.release();
 898             }
 899         }
 900 
 901         private void setBaseURI(String playlistURI, String URI) {
 902             if (!URI.startsWith("http://") || !URI.startsWith("https://")) {
 903                 baseURI = playlistURI.substring(0, playlistURI.lastIndexOf("/") + 1);
 904             }
 905             needBaseURI = false;
 906         }
 907     }
 908 }