jfxrt

)mediaFilesDiscontinuities.get(HLSConnectionHolder.access$500(this$0))).booleanValue();
  }
  
  public double seek(long paramLong)
  {
    synchronized (lock)
    {
      if (isLive)
      {
        if (paramLong == 0L)
        {
          HLSConnectionHolder.access$502(this$0, -1);
          HLSConnectionHolder.access$600(this$0).drainPermits();
          HLSConnectionHolder.access$600(this$0).release(mediaFiles.size());
        }
      }
      else
      {
        paramLong += targetDuration / 2000L;
        int i = mediaFilesStartTimes.size();
        for (int j = 0; j < i; j++) {
          if (paramLong >= ((Double)mediaFilesStartTimes.get(j)).doubleValue()) {
            if (j + 1 < i)
            {
              if (paramLong < ((Double)mediaFilesStartTimes.get(j + 1)).doubleValue())
              {
                HLSConnectionHolder.access$502(this$0, j - 1);
                return ((Double)mediaFilesStartTimes.get(j)).doubleValue();
              }
            }
            else
            {
              if (paramLong - targetDuration / 2000L < duration)
              {
                HLSConnectionHolder.access$502(this$0, j - 1);
                return ((Double)mediaFilesStartTimes.get(j)).doubleValue();
              }
              if (paramLong - targetDuration / 2000L == duration) {
                return duration;
              }
            }
          }
        }
      }
    }
    return -1.0D;
  }
  
  public int getMimeType()
  {
    synchronized (lock)
    {
      if (mediaFiles.size() > 0)
      {
        if (((String)mediaFiles.get(0)).endsWith(".ts")) {
          return 1;
        }
        if (((String)mediaFiles.get(0)).endsWith(".mp3")) {
          return 2;
        }
      }
    }
    return -1;
  }
  
  public String getMediaFileExtension()
  {
    synchronized (lock)
    {
      if (mediaFiles.size() > 0)
      {
        int i = ((String)mediaFiles.get(0)).lastIndexOf(".");
        if (i != -1) {
          return ((String)mediaFiles.get(0)).substring(i);
        }
      }
    }
    return null;
  }
  
  public boolean setSequenceNumber(int paramInt)
  {
    if (sequenceNumberStart == -1)
    {
      sequenceNumberStart = paramInt;
    }
    else if (sequenceNumber != paramInt)
    {
      sequenceNumberUpdated = true;
      sequenceNumber = paramInt;
    }
    else
    {
      return false;
    }
    return true;
  }
  
  public void close()
  {
    if (isLive)
    {
      HLSConnectionHolder.access$702(this$0, true);
      HLSConnectionHolder.access$600(this$0).release();
    }
  }
  
  private void setBaseURI(String paramString1, String paramString2)
  {
    if (!paramString2.startsWith("http://")) {
      baseURI = paramString1.substring(0, paramString1.lastIndexOf("/") + 1);
    }
    needBaseURI = false;
  }
}

/* Location:
 * Qualified Name:     com.sun.media.jfxmedia.locator.HLSConnectionHolder.Playlist
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.media.jfxmedia.locator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

class HLSConnectionHolder$PlaylistParser
{
  private boolean isFirstLine = true;
  private boolean isLineMediaFileURI = false;
  private boolean isEndList = false;
  private boolean isLinePlaylistURI = false;
  private boolean isVariantPlaylist = false;
  private boolean isDiscontinuity = false;
  private int targetDuration = 0;
  private int sequenceNumber = 0;
  private int dataListIndex = -1;
  private List<String> dataListString = new ArrayList();
  private List<Integer> dataListInteger = new ArrayList();
  private List<Double> dataListDouble = new ArrayList();
  private List<Boolean> dataListBoolean = new ArrayList();
  
  private HLSConnectionHolder$PlaylistParser(HLSConnectionHolder paramHLSConnectionHolder) {}
  
  public void load(URI paramURI)
  {
    URLConnection localURLConnection = null;
    BufferedReader localBufferedReader = null;
    try
    {
      localURLConnection = paramURI.toURL().openConnection();
      localBufferedReader = new BufferedReader(new InputStreamReader(localURLConnection.getInputStream()));
      boolean bool;
      do
      {
        bool = parseLine(localBufferedReader.readLine());
      } while (bool);
    }
    catch (MalformedURLException localMalformedURLException) {}catch (IOException localIOException3) {}finally
    {
      if (localBufferedReader != null)
      {
        try
        {
          localBufferedReader.close();
        }
        catch (IOException localIOException5) {}
        if ((localURLConnection != null) && ((localURLConnection instanceof HttpURLConnection))) {
          ((HttpURLConnection)localURLConnection).disconnect();
        }
      }
    }
  }
  
  public boolean isVariantPlaylist()
  {
    return isVariantPlaylist;
  }
  
  public boolean isLivePlaylist()
  {
    return !isEndList;
  }
  
  public int getTargetDuration()
  {
    return targetDuration;
  }
  
  public int getSequenceNumber()
  {
    return sequenceNumber;
  }
  
  public boolean hasNext()
  {
    dataListIndex += 1;
    return (dataListString.size() > dataListIndex) || (dataListInteger.size() > dataListIndex) || (dataListDouble.size() > dataListIndex) || (dataListBoolean.size() > dataListIndex);
  }
  
  public String getString()
  {
    return (String)dataListString.get(dataListIndex);
  }
  
  public Integer getInteger()
  {
    return (Integer)dataListInteger.get(dataListIndex);
  }
  
  public Double getDouble()
  {
    return (Double)dataListDouble.get(dataListIndex);
  }
  
  public Boolean getBoolean()
  {
    return (Boolean)dataListBoolean.get(dataListIndex);
  }
  
  public void reset()
  {
    isFirstLine = true;
    isLineMediaFileURI = false;
    isEndList = false;
    isLinePlaylistURI = false;
    isVariantPlaylist = false;
    isDiscontinuity = false;
    targetDuration = 0;
    sequenceNumber = 0;
    dataListIndex = -1;
    dataListString.clear();
    dataListInteger.clear();
    dataListDouble.clear();
    dataListBoolean.clear();
  }
  
  public boolean parseLine(String paramString)
  {
    if (paramString == null) {
      return false;
    }
    if (isFirstLine)
    {
      if (paramString.compareTo("#EXTM3U") != 0) {
        return false;
      }
      isFirstLine = false;
      return true;
    }
    if ((paramString.isEmpty()) || ((paramString.startsWith("#")) && (!paramString.startsWith("#EXT")))) {
      return true;
    }
    String[] arrayOfString1;
    String[] arrayOfString2;
    if (paramString.startsWith("#EXTINF"))
    {
      arrayOfString1 = paramString.split(":");
      if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0))
      {
        arrayOfString2 = arrayOfString1[1].split(",");
        if (arrayOfString2.length >= 1) {
          dataListDouble.add(Double.valueOf(Double.parseDouble(arrayOfString2[0])));
        }
      }
      isLineMediaFileURI = true;
    }
    else if (paramString.startsWith("#EXT-X-TARGETDURATION"))
    {
      arrayOfString1 = paramString.split(":");
      if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0)) {
        targetDuration = Integer.parseInt(arrayOfString1[1]);
      }
    }
    else if (paramString.startsWith("#EXT-X-MEDIA-SEQUENCE"))
    {
      arrayOfString1 = paramString.split(":");
      if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0)) {
        sequenceNumber = Integer.parseInt(arrayOfString1[1]);
      }
    }
    else if (paramString.startsWith("#EXT-X-STREAM-INF"))
    {
      isVariantPlaylist = true;
      int i = 0;
      arrayOfString2 = paramString.split(":");
      if ((arrayOfString2.length == 2) && (arrayOfString2[1].length() > 0))
      {
        String[] arrayOfString3 = arrayOfString2[1].split(",");
        if (arrayOfString3.length > 0) {
          for (int j = 0; j < arrayOfString3.length; j++)
          {
            arrayOfString3[j] = arrayOfString3[j].trim();
            if (arrayOfString3[j].startsWith("BANDWIDTH"))
            {
              String[] arrayOfString4 = arrayOfString3[j].split("=");
              if ((arrayOfString4.length == 2) && (arrayOfString4[1].length() > 0)) {
                i = Integer.parseInt(arrayOfString4[1]);
              }
            }
          }
        }
      }
      if (i < 1) {
        return false;
      }
      dataListInteger.add(Integer.valueOf(i));
      isLinePlaylistURI = true;
    }
    else if (paramString.startsWith("#EXT-X-ENDLIST"))
    {
      isEndList = true;
    }
    else if (paramString.startsWith("#EXT-X-DISCONTINUITY"))
    {
      isDiscontinuity = true;
    }
    else if (isLinePlaylistURI)
    {
      isLinePlaylistURI = false;
      dataListString.add(paramString);
    }
    else if (isLineMediaFileURI)
    {
      isLineMediaFileURI = false;
      dataListString.add(paramString);
      dataListBoolean.add(Boolean.valueOf(isDiscontinuity));
      isDiscontinuity = false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     com.sun.media.jfxmedia.locator.HLSConnectionHolder.PlaylistParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.media.jfxmedia.locator;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;

class HLSConnectionHolder$PlaylistThread
  extends Thread
{
  public static final int STATE_INIT = 0;
  public static final int STATE_EXIT = 1;
  public static final int STATE_RELOAD_PLAYLIST = 2;
  private BlockingQueue<Integer> stateQueue = new LinkedBlockingQueue();
  private URI playlistURI = null;
  private HLSConnectionHolder.Playlist reloadPlaylist = null;
  private final Object reloadLock = new Object();
  private volatile boolean stopped = false;
  
  HLSConnectionHolder$PlaylistThread(HLSConnectionHolder paramHLSConnectionHolder)
  {
    setName("JFXMedia HLS Playlist Thread");
    setDaemon(true);
  }
  
  public void setPlaylistURI(URI paramURI)
  {
    playlistURI = paramURI;
  }
  
  public void setReloadPlaylist(HLSConnectionHolder.Playlist paramPlaylist)
  {
    synchronized (reloadLock)
    {
      reloadPlaylist = paramPlaylist;
    }
  }
  
  public void run()
  {
    while (!stopped) {
      try
      {
        int i = ((Integer)stateQueue.take()).intValue();
        switch (i)
        {
        case 0: 
          stateInit();
          break;
        case 1: 
          stopped = true;
          break;
        case 2: 
          stateReloadPlaylist();
        }
      }
      catch (Exception localException) {}
    }
  }
  
  public void putState(int paramInt)
  {
    if (stateQueue != null) {
      stateQueue.offer(Integer.valueOf(paramInt));
    }
  }
  
  private void stateInit()
  {
    if (playlistURI == null) {
      return;
    }
    HLSConnectionHolder.PlaylistParser localPlaylistParser = new HLSConnectionHolder.PlaylistParser(this$0, null);
    localPlaylistParser.load(playlistURI);
    if (localPlaylistParser.isVariantPlaylist())
    {
      HLSConnectionHolder.access$102(this$0, new HLSConnectionHolder.VariantPlaylist(this$0, playlistURI));
      while (localPlaylistParser.hasNext()) {
        HLSConnectionHolder.access$100(this$0).addPlaylistInfo(localPlaylistParser.getString(), localPlaylistParser.getInteger().intValue());
      }
    }
    if (HLSConnectionHolder.access$200(this$0) == null)
    {
      HLSConnectionHolder.access$202(this$0, new HLSConnectionHolder.Playlist(this$0, localPlaylistParser.isLivePlaylist(), localPlaylistParser.getTargetDuration()));
      HLSConnectionHolder.access$200(this$0).setPlaylistURI(playlistURI);
    }
    if (HLSConnectionHolder.access$200(this$0).setSequenceNumber(localPlaylistParser.getSequenceNumber())) {
      while (localPlaylistParser.hasNext()) {
        HLSConnectionHolder.access$200(this$0).addMediaFile(localPlaylistParser.getString(), localPlaylistParser.getDouble().doubleValue(), localPlaylistParser.getBoolean().booleanValue());
      }
    }
    if (HLSConnectionHolder.access$100(this$0) != null) {
      HLSConnectionHolder.access$100(this$0).addPlaylist(HLSConnectionHolder.access$200(this$0));
    }
    if (HLSConnectionHolder.access$100(this$0) != null) {
      while (HLSConnectionHolder.access$100(this$0).hasNext()) {
        try
        {
          HLSConnectionHolder.access$202(this$0, new HLSConnectionHolder.Playlist(this$0, HLSConnectionHolder.access$100(this$0).getPlaylistURI()));
          HLSConnectionHolder.access$200(this$0).update(null);
          HLSConnectionHolder.access$100(this$0).addPlaylist(HLSConnectionHolder.access$200(this$0));
        }
        catch (URISyntaxException localURISyntaxException) {}catch (MalformedURLException localMalformedURLException) {}
      }
    }
    if (HLSConnectionHolder.access$100(this$0) != null)
    {
      HLSConnectionHolder.access$202(this$0, HLSConnectionHolder.access$100(this$0).getPlaylist(0));
      HLSConnectionHolder.access$302(this$0, true);
    }
    if (HLSConnectionHolder.access$200(this$0).isLive())
    {
      setReloadPlaylist(HLSConnectionHolder.access$200(this$0));
      putState(2);
    }
    HLSConnectionHolder.access$400(this$0).countDown();
  }
  
  private void stateReloadPlaylist()
  {
    try
    {
      long l;
      synchronized (reloadLock)
      {
        l = reloadPlaylist.getTargetDuration() / 2L;
      }
      Thread.sleep(l);
    }
    catch (Exception localException)
    {
      return;
    }
    synchronized (reloadLock)
    {
      reloadPlaylist.update(null);
    }
    putState(2);
  }
}

/* Location:
 * Qualified Name:     com.sun.media.jfxmedia.locator.HLSConnectionHolder.PlaylistThread
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.media.jfxmedia.locator;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

class HLSConnectionHolder$VariantPlaylist
{
  public volatile int playlistsSize = 0;
  private URI playlistURI = null;
  private int infoIndex = -1;
  private List<String> playlistsLocations = new ArrayList();
  private List<Integer> playlistsBitrates = new ArrayList();
  private List<HLSConnectionHolder.Playlist> playlists = new ArrayList();
  private String mediaFileExtension = null;
  
  HLSConnectionHolder$VariantPlaylist(HLSConnectionHolder paramHLSConnectionHolder, URI paramURI)
  {
    playlistURI = paramURI;
  }
  
  public void addPlaylistInfo(String paramString, int paramInt)
  {
    playlistsLocations.add(paramString);
    playlistsBitrates.add(Integer.valueOf(paramInt));
  }
  
  public void addPlaylist(HLSConnectionHolder.Playlist paramPlaylist)
  {
    if (mediaFileExtension == null)
    {
      mediaFileExtension = paramPlaylist.getMediaFileExtension();
    }
    else if (!mediaFileExtension.equals(paramPlaylist.getMediaFileExtension()))
    {
      playlistsLocations.remove(infoIndex);
      playlistsBitrates.remove(infoIndex);
      infoIndex -= 1;
      return;
    }
    playlists.add(paramPlaylist);
    playlistsSize = playlists.size();
  }
  
  public HLSConnectionHolder.Playlist getPlaylist(int paramInt)
  {
    if (playlists.size() > paramInt) {
      return (HLSConnectionHolder.Playlist)playlists.get(paramInt);
    }
    return null;
  }
  
  public boolean hasNext()
  {
    infoIndex += 1;
    return (playlistsLocations.size() > infoIndex) && (playlistsBitrates.size() > infoIndex);
  }
  
  public URI getPlaylistURI()
    throws URISyntaxException, MalformedURLException
  {
    String str = (String)playlistsLocations.get(infoIndex);
    if (str.startsWith("http://")) {
      return new URI(str);
    }
    return new URI(playlistURI.toURL().toString().substring(0, playlistURI.toURL().toString().lastIndexOf("/") + 1) + str);
  }
  
  public HLSConnectionHolder.Playlist getPlaylistBasedOnBitrate(int paramInt)
  {
    int i = -1;
    int j = 0;
    int m;
    for (int k = 0; k < playlistsBitrates.size(); k++)
    {
      m = ((Integer)playlistsBitrates.get(k)).intValue();
      if (m < paramInt) {
        if (i != -1)
        {
          if (m > j)
          {
            j = m;
            i = k;
          }
        }
        else {
          i = k;
        }
      }
    }
    if (i == -1) {
      for (k = 0; k < playlistsBitrates.size(); k++)
      {
        m = ((Integer)playlistsBitrates.get(k)).intValue();
        if ((m < j) || (i == -1))
        {
          j = m;
          i = k;
        }
      }
    }
    if ((i < 0) || (i >= playlists.size())) {
      return null;
    }
    return (HLSConnectionHolder.Playlist)playlists.get(i);
  }
}

/* Location:
 * Qualified Name:     com.sun.media.jfxmedia.locator.HLSConnectionHolder.VariantPlaylist
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.media.jfxmedia.locator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;

final class HLSConnectionHolder
  extends ConnectionHolder
{
  private URLConnection urlConnection = null;
  private PlaylistThread playlistThread = new PlaylistThread();
  private VariantPlaylist variantPlaylist = null;
  private Playlist currentPlaylist = null;
  private int mediaFileIndex = -1;
  private CountDownLatch readySignal = new CountDownLatch(1);
  private Semaphore liveSemaphore = new Semaphore(0);
  private boolean isPlaylistClosed = false;
  private boolean isBitrateAdjustable = false;
  private long startTime = -1L;
  private static final long HLS_VALUE_FLOAT_MULTIPLIER = 1000L;
  private static final int HLS_PROP_GET_DURATION = 1;
  private static final int HLS_PROP_GET_HLS_MODE = 2;
  private static final int HLS_PROP_GET_MIMETYPE = 3;
  private static final int HLS_VALUE_MIMETYPE_MP2T = 1;
  private static final int HLS_VALUE_MIMETYPE_MP3 = 2;
  
  HLSConnectionHolder(URI paramURI)
    throws IOException
  {
    playlistThread.setPlaylistURI(paramURI);
    init();
  }
  
  private void init()
  {
    playlistThread.putState(0);
    playlistThread.start();
  }
  
  public int readNextBlock()
    throws IOException
  {
    if ((isBitrateAdjustable) && (startTime == -1L)) {
      startTime = System.currentTimeMillis();
    }
    int i = super.readNextBlock();
    if ((isBitrateAdjustable) && (i == -1))
    {
      long l = System.currentTimeMillis() - startTime;
      startTime = -1L;
      adjustBitrate(l);
    }
    return i;
  }
  
  int readBlock(long paramLong, int paramInt)
    throws IOException
  {
    throw new IOException();
  }
  
  boolean needBuffer()
  {
    return true;
  }
  
  boolean isSeekable()
  {
    return true;
  }
  
  boolean isRandomAccess()
  {
    return false;
  }
  
  public long seek(long paramLong)
  {
    try
    {
      readySignal.await();
    }
    catch (Exception localException)
    {
      return -1L;
    }
    return (currentPlaylist.seek(paramLong) * 1000.0D);
  }
  
  public void closeConnection()
  {
    currentPlaylist.close();
    super.closeConnection();
    resetConnection();
    playlistThread.putState(1);
  }
  
  public int property(int paramInt1, int paramInt2)
  {
    try
    {
      readySignal.await();
    }
    catch (Exception localException)
    {
      return -1;
    }
    if (paramInt1 == 1) {
      return (int)(currentPlaylist.getDuration() * 1000.0D);
    }
    if (paramInt1 == 2) {
      return 1;
    }
    if (paramInt1 == 3) {
      return currentPlaylist.getMimeType();
    }
    return -1;
  }
  
  public int getStreamSize()
  {
    try
    {
      readySignal.await();
    }
    catch (Exception localException)
    {
      return -1;
    }
    return loadNextSegment();
  }
  
  private void resetConnection()
  {
    super.closeConnection();
    if ((urlConnection != null) && ((urlConnection instanceof HttpURLConnection)))
    {
      ((HttpURLConnection)urlConnection).disconnect();
      urlConnection = null;
    }
  }
  
  private int loadNextSegment()
  {
    resetConnection();
    String str = currentPlaylist.getNextMediaFile();
    if (str == null) {
      return -1;
    }
    try
    {
      URI localURI = new URI(str);
      urlConnection = localURI.toURL().openConnection();
      channel = openChannel();
    }
    catch (Exception localException)
    {
      return -1;
    }
    if (currentPlaylist.isCurrentMediaFileDiscontinuity()) {
      return -1 * urlConnection.getContentLength();
    }
    return urlConnection.getContentLength();
  }
  
  private ReadableByteChannel openChannel()
    throws IOException
  {
    return Channels.newChannel(urlConnection.getInputStream());
  }
  
  private void adjustBitrate(long paramLong)
  {
    int i = (int)(urlConnection.getContentLength() * 8L * 1000L / paramLong);
    Playlist localPlaylist = variantPlaylist.getPlaylistBasedOnBitrate(i);
    if ((localPlaylist != null) && (localPlaylist != currentPlaylist))
    {
      if (currentPlaylist.isLive())
      {
        localPlaylist.update(currentPlaylist.getNextMediaFile());
        playlistThread.setReloadPlaylist(localPlaylist);
      }
      localPlaylist.setForceDiscontinuity(true);
      currentPlaylist = localPlaylist;
    }
  }
  
  private class Playlist
  {
    private boolean isLive = false;
    private long targetDuration = 0L;
    private URI playlistURI = null;
    private final Object lock = new Object();
    private List<String> mediaFiles = new ArrayList();
    private List<Double> mediaFilesStartTimes = new ArrayList();
    private List<Boolean> mediaFilesDiscontinuities = new ArrayList();
    private boolean needBaseURI = true;
    private String baseURI = null;
    private double duration = 0.0D;
    private int sequenceNumber = -1;
    private int sequenceNumberStart = -1;
    private boolean sequenceNumberUpdated = false;
    private boolean forceDiscontinuity = false;
    
    Playlist(boolean paramBoolean, int paramInt)
    {
      isLive = paramBoolean;
      targetDuration = (paramInt * 1000);
      if (paramBoolean) {
        duration = -1.0D;
      }
    }
    
    Playlist(URI paramURI)
    {
      playlistURI = paramURI;
    }
    
    public void update(String paramString)
    {
      HLSConnectionHolder.PlaylistParser localPlaylistParser = new HLSConnectionHolder.PlaylistParser(HLSConnectionHolder.this, null);
      localPlaylistParser.load(playlistURI);
      isLive = localPlaylistParser.isLivePlaylist();
      targetDuration = (localPlaylistParser.getTargetDuration() * 1000);
      if (isLive) {
        duration = -1.0D;
      }
      if (setSequenceNumber(localPlaylistParser.getSequenceNumber())) {
        while (localPlaylistParser.hasNext()) {
          addMediaFile(localPlaylistParser.getString(), localPlaylistParser.getDouble().doubleValue(), localPlaylistParser.getBoolean().booleanValue());
        }
      }
      if (paramString != null) {
        synchronized (lock)
        {
          for (int i = 0; i < mediaFiles.size(); i++)
          {
            String str = (String)mediaFiles.get(i);
            if (paramString.endsWith(str))
            {
              mediaFileIndex = (i - 1);
              break;
            }
          }
        }
      }
    }
    
    public boolean isLive()
    {
      return isLive;
    }
    
    public long getTargetDuration()
    {
      return targetDuration;
    }
    
    public void setPlaylistURI(URI paramURI)
    {
      playlistURI = paramURI;
    }
    
    public URI getPlaylistURI()
    {
      return playlistURI;
    }
    
    public void addMediaFile(String paramString, double paramDouble, boolean paramBoolean)
    {
      synchronized (lock)
      {
        if (needBaseURI) {
          setBaseURI(playlistURI.toString(), paramString);
        }
        int i;
        if (isLive)
        {
          if (sequenceNumberUpdated)
          {
            i = mediaFiles.indexOf(paramString);
            if (i != -1) {
              for (int j = 0; j < i; j++)
              {
                mediaFiles.remove(0);
                mediaFilesDiscontinuities.remove(0);
                if (mediaFileIndex == -1) {
                  forceDiscontinuity = true;
                }
                if (mediaFileIndex >= 0) {
                  HLSConnectionHolder.access$510(HLSConnectionHolder.this);
                }
              }
            }
            sequenceNumberUpdated = false;
          }
          if (mediaFiles.contains(paramString)) {
            return;
          }
        }
        mediaFiles.add(paramString);
        mediaFilesDiscontinuities.add(Boolean.valueOf(paramBoolean));
        if (isLive)
        {
          i = mediaFiles.size() - (mediaFileIndex + 1);
          liveSemaphore.drainPermits();
          liveSemaphore.release(i);
        }
        else
        {
          mediaFilesStartTimes.add(Double.valueOf(duration));
          duration += paramDouble;
        }
      }
    }
    
    public String getNextMediaFile()
    {
      if (isLive) {
        try
        {
          liveSemaphore.acquire();
        }
        catch (InterruptedException localInterruptedException)
        {
          return null;
        }
      }
      if (isPlaylistClosed) {
        return null;
      }
      synchronized (lock)
      {
        HLSConnectionHolder.access$508(HLSConnectionHolder.this);
        if (mediaFileIndex < mediaFiles.size())
        {
          if (baseURI != null) {
            return baseURI + (String)mediaFiles.get(mediaFileIndex);
          }
          return (String)mediaFiles.get(mediaFileIndex);
        }
        return null;
      }
    }
    
    public double getDuration()
    {
      return duration;
    }
    
    public void setForceDiscontinuity(boolean paramBoolean)
    {
      forceDiscontinuity = paramBoolean;
    }
    
    public boolean isCurrentMediaFileDiscontinuity()
    {
      if (forceDiscontinuity)
      {
        forceDiscontinuity = false;
        return true;
      }
      return ((Boolean)mediaFilesDiscontinuities.get(mediaFileIndex)).booleanValue();
    }
    
    public double seek(long paramLong)
    {
      synchronized (lock)
      {
        if (isLive)
        {
          if (paramLong == 0L)
          {
            mediaFileIndex = -1;
            liveSemaphore.drainPermits();
            liveSemaphore.release(mediaFiles.size());
          }
        }
        else
        {
          paramLong += targetDuration / 2000L;
          int i = mediaFilesStartTimes.size();
          for (int j = 0; j < i; j++) {
            if (paramLong >= ((Double)mediaFilesStartTimes.get(j)).doubleValue()) {
              if (j + 1 < i)
              {
                if (paramLong < ((Double)mediaFilesStartTimes.get(j + 1)).doubleValue())
                {
                  mediaFileIndex = (j - 1);
                  return ((Double)mediaFilesStartTimes.get(j)).doubleValue();
                }
              }
              else
              {
                if (paramLong - targetDuration / 2000L < duration)
                {
                  mediaFileIndex = (j - 1);
                  return ((Double)mediaFilesStartTimes.get(j)).doubleValue();
                }
                if (paramLong - targetDuration / 2000L == duration) {
                  return duration;
                }
              }
            }
          }
        }
      }
      return -1.0D;
    }
    
    public int getMimeType()
    {
      synchronized (lock)
      {
        if (mediaFiles.size() > 0)
        {
          if (((String)mediaFiles.get(0)).endsWith(".ts")) {
            return 1;
          }
          if (((String)mediaFiles.get(0)).endsWith(".mp3")) {
            return 2;
          }
        }
      }
      return -1;
    }
    
    public String getMediaFileExtension()
    {
      synchronized (lock)
      {
        if (mediaFiles.size() > 0)
        {
          int i = ((String)mediaFiles.get(0)).lastIndexOf(".");
          if (i != -1) {
            return ((String)mediaFiles.get(0)).substring(i);
          }
        }
      }
      return null;
    }
    
    public boolean setSequenceNumber(int paramInt)
    {
      if (sequenceNumberStart == -1)
      {
        sequenceNumberStart = paramInt;
      }
      else if (sequenceNumber != paramInt)
      {
        sequenceNumberUpdated = true;
        sequenceNumber = paramInt;
      }
      else
      {
        return false;
      }
      return true;
    }
    
    public void close()
    {
      if (isLive)
      {
        isPlaylistClosed = true;
        liveSemaphore.release();
      }
    }
    
    private void setBaseURI(String paramString1, String paramString2)
    {
      if (!paramString2.startsWith("http://")) {
        baseURI = paramString1.substring(0, paramString1.lastIndexOf("/") + 1);
      }
      needBaseURI = false;
    }
  }
  
  private class PlaylistParser
  {
    private boolean isFirstLine = true;
    private boolean isLineMediaFileURI = false;
    private boolean isEndList = false;
    private boolean isLinePlaylistURI = false;
    private boolean isVariantPlaylist = false;
    private boolean isDiscontinuity = false;
    private int targetDuration = 0;
    private int sequenceNumber = 0;
    private int dataListIndex = -1;
    private List<String> dataListString = new ArrayList();
    private List<Integer> dataListInteger = new ArrayList();
    private List<Double> dataListDouble = new ArrayList();
    private List<Boolean> dataListBoolean = new ArrayList();
    
    private PlaylistParser() {}
    
    public void load(URI paramURI)
    {
      URLConnection localURLConnection = null;
      BufferedReader localBufferedReader = null;
      try
      {
        localURLConnection = paramURI.toURL().openConnection();
        localBufferedReader = new BufferedReader(new InputStreamReader(localURLConnection.getInputStream()));
        boolean bool;
        do
        {
          bool = parseLine(localBufferedReader.readLine());
        } while (bool);
      }
      catch (MalformedURLException localMalformedURLException) {}catch (IOException localIOException3) {}finally
      {
        if (localBufferedReader != null)
        {
          try
          {
            localBufferedReader.close();
          }
          catch (IOException localIOException5) {}
          if ((localURLConnection != null) && ((localURLConnection instanceof HttpURLConnection))) {
            ((HttpURLConnection)localURLConnection).disconnect();
          }
        }
      }
    }
    
    public boolean isVariantPlaylist()
    {
      return isVariantPlaylist;
    }
    
    public boolean isLivePlaylist()
    {
      return !isEndList;
    }
    
    public int getTargetDuration()
    {
      return targetDuration;
    }
    
    public int getSequenceNumber()
    {
      return sequenceNumber;
    }
    
    public boolean hasNext()
    {
      dataListIndex += 1;
      return (dataListString.size() > dataListIndex) || (dataListInteger.size() > dataListIndex) || (dataListDouble.size() > dataListIndex) || (dataListBoolean.size() > dataListIndex);
    }
    
    public String getString()
    {
      return (String)dataListString.get(dataListIndex);
    }
    
    public Integer getInteger()
    {
      return (Integer)dataListInteger.get(dataListIndex);
    }
    
    public Double getDouble()
    {
      return (Double)dataListDouble.get(dataListIndex);
    }
    
    public Boolean getBoolean()
    {
      return (Boolean)dataListBoolean.get(dataListIndex);
    }
    
    public void reset()
    {
      isFirstLine = true;
      isLineMediaFileURI = false;
      isEndList = false;
      isLinePlaylistURI = false;
      isVariantPlaylist = false;
      isDiscontinuity = false;
      targetDuration = 0;
      sequenceNumber = 0;
      dataListIndex = -1;
      dataListString.clear();
      dataListInteger.clear();
      dataListDouble.clear();
      dataListBoolean.clear();
    }
    
    public boolean parseLine(String paramString)
    {
      if (paramString == null) {
        return false;
      }
      if (isFirstLine)
      {
        if (paramString.compareTo("#EXTM3U") != 0) {
          return false;
        }
        isFirstLine = false;
        return true;
      }
      if ((paramString.isEmpty()) || ((paramString.startsWith("#")) && (!paramString.startsWith("#EXT")))) {
        return true;
      }
      String[] arrayOfString1;
      String[] arrayOfString2;
      if (paramString.startsWith("#EXTINF"))
      {
        arrayOfString1 = paramString.split(":");
        if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0))
        {
          arrayOfString2 = arrayOfString1[1].split(",");
          if (arrayOfString2.length >= 1) {
            dataListDouble.add(Double.valueOf(Double.parseDouble(arrayOfString2[0])));
          }
        }
        isLineMediaFileURI = true;
      }
      else if (paramString.startsWith("#EXT-X-TARGETDURATION"))
      {
        arrayOfString1 = paramString.split(":");
        if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0)) {
          targetDuration = Integer.parseInt(arrayOfString1[1]);
        }
      }
      else if (paramString.startsWith("#EXT-X-MEDIA-SEQUENCE"))
      {
        arrayOfString1 = paramString.split(":");
        if ((arrayOfString1.length == 2) && (arrayOfString1[1].length() > 0)) {
          sequenceNumber = Integer.parseInt(arrayOfString1[1]);
        }
      }
      else if (paramString.startsWith("#EXT-X-STREAM-INF"))
      {
        isVariantPlaylist = true;
        int i = 0;
        arrayOfString2 = paramString.split(":");
        if ((arrayOfString2.length == 2) && (arrayOfString2[1].length() > 0))
        {
          String[] arrayOfString3 = arrayOfString2[1].split(",");
          if (arrayOfString3.length > 0) {
            for (int j = 0; j < arrayOfString3.length; j++)
            {
              arrayOfString3[j] = arrayOfString3[j].trim();
              if (arrayOfString3[j].startsWith("BANDWIDTH"))
              {
                String[] arrayOfString4 = arrayOfString3[j].split("=");
                if ((arrayOfString4.length == 2) && (arrayOfString4[1].length() > 0)) {
                  i = Integer.parseInt(arrayOfString4[1]);
                }
              }
            }
          }
        }
        if (i < 1) {
          return false;
        }
        dataListInteger.add(Integer.valueOf(i));
        isLinePlaylistURI = true;
      }
      else if (paramString.startsWith("#EXT-X-ENDLIST"))
      {
        isEndList = true;
      }
      else if (paramString.startsWith("#EXT-X-DISCONTINUITY"))
      {
        isDiscontinuity = true;
      }
      else if (isLinePlaylistURI)
      {
        isLinePlaylistURI = false;
        dataListString.add(paramString);
      }
      else if (isLineMediaFileURI)
      {
        isLineMediaFileURI = false;
        dataListString.add(paramString);
        dataListBoolean.add(Boolean.valueOf(isDiscontinuity));
        isDiscontinuity = false;
      }
      return true;
    }
  }
  
  private class PlaylistThread
    extends Thread
  {
    public static final int STATE_INIT = 0;
    public static final int STATE_EXIT = 1;
    public static final int STATE_RELOAD_PLAYLIST = 2;
    private BlockingQueue<Integer> stateQueue = new LinkedBlockingQueue();
    private URI playlistURI = null;
    private HLSConnectionHolder.Playlist reloadPlaylist = null;
    private final Object reloadLock = new Object();
    private volatile boolean stopped = false;
    
    PlaylistThread()
    {
      setName("JFXMedia HLS Playlist Thread");
      setDaemon(true);
    }
    
    public void setPlaylistURI(URI paramURI)
    {
      playlistURI = paramURI;
    }
    
    public void setReloadPlaylist(HLSConnectionHolder.Playlist paramPlaylist)
    {
      synchronized (reloadLock)
      {
        reloadPlaylist = paramPlaylist;
      }
    }
    
    public void run()
    {
      while (!stopped) {
        try
        {
          int i = ((Integer)stateQueue.take()).intValue();
          switch (i)
          {
          case 0: 
            stateInit();
            break;
          case 1: 
            stopped = true;
            break;
          case 2: 
            stateReloadPlaylist();
          }
        }
        catch (Exception localException) {}
      }
    }
    
    public void putState(int paramInt)
    {
      if (stateQueue != null) {
        stateQueue.offer(Integer.valueOf(paramInt));
      }
    }
    
    private void stateInit()
    {
      if (playlistURI == null) {
        return;
      }
      HLSConnectionHolder.PlaylistParser localPlaylistParser = new HLSConnectionHolder.PlaylistParser(HLSConnectionHolder.this, null);
      localPlaylistParser.load(playlistURI);
      if (localPlaylistParser.isVariantPlaylist())
      {
        variantPlaylist = new HLSConnectionHolder.VariantPlaylist(HLSConnectionHolder.this, playlistURI);
        while (localPlaylistParser.hasNext()) {
          variantPlaylist.addPlaylistInfo(localPlaylistParser.getString(), localPlaylistParser.getInteger().intValue());
        }
      }
      if (currentPlaylist == null)
      {
        currentPlaylist = new HLSConnectionHolder.Playlist(HLSConnectionHolder.this, localPlaylistParser.isLivePlaylist(), localPlaylistParser.getTargetDuration());
        currentPlaylist.setPlaylistURI(playlistURI);
      }
      if (currentPlaylist.setSequenceNumber(localPlaylistParser.getSequenceNumber())) {
        while (localPlaylistParser.hasNext()) {
          currentPlaylist.addMediaFile(localPlaylistParser.getString(), localPlaylistParser.getDouble().doubleValue(), localPlaylistParser.getBoolean().booleanValue());
        }
      }
      if (variantPlaylist != null) {
        variantPlaylist.addPlaylist(currentPlaylist);
      }
      if (variantPlaylist != null) {
        while (variantPlaylist.hasNext()) {
          try
          {
            currentPlaylist = new HLSConnectionHolder.Playlist(HLSConnectionHolder.this, variantPlaylist.getPlaylistURI());
            currentPlaylist.update(null);
            variantPlaylist.addPlaylist(currentPlaylist);
          }
          catch (URISyntaxException localURISyntaxException) {}catch (MalformedURLException localMalformedURLException) {}
        }
      }
      if (variantPlaylist != null)
      {
        currentPlaylist = variantPlaylist.getPlaylist(0);
        isBitrateAdjustable = true;
      }
      if (currentPlaylist.isLive())
      {
        setReloadPlaylist(currentPlaylist);
        putState(2);
      }
      readySignal.countDown();
    }
    
    private void stateReloadPlaylist()
    {
      try
      {
        long l;
        synchronized (reloadLock)
        {
          l = reloadPlaylist.getTargetDuration() / 2L;
        }
        Thread.sleep(l);
      }
      catch (Exception localException)
      {
        return;
      }
      synchronized (reloadLock)
      {
        reloadPlaylist.update(null);
      }
      putState(2);
    }
  }
  
  private class VariantPlaylist
  {
    public volatile int playlistsSize = 0;
    private URI playlistURI = null;
    private int infoIndex = -1;
    private List<String> playlistsLocations = new ArrayList();
    private List<Integer> playlistsBitrates = new ArrayList();
    private List<HLSConnectionHolder.Playlist>
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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd