From c12833f5e31c3f4a3c7302534960f27961e02486 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Sat, 8 Dec 2012 18:17:49 +0000 Subject: [PATCH] HLS casi terminado, añadido BandwidthMeasurer --- src/com/upc/pbe/upcnews/BandwidthMeasurer.java | 27 +++++++++++++++++++++++++++ src/com/upc/pbe/upcnews/Directoris.java | 5 ++--- src/com/upc/pbe/upcnews/HLS.java | 57 +++++++++++++++++++++++++++++++++++++++++++-------------- src/com/upc/pbe/upcnews/MainActivity.java | 45 +++++---------------------------------------- src/com/upc/pbe/upcnews/Parser.java | 4 ++-- src/com/upc/pbe/upcnews/UpcApp.java | 15 +++++++++++---- src/com/upc/pbe/upcnews/Video.java | 8 ++++---- 7 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 src/com/upc/pbe/upcnews/BandwidthMeasurer.java diff --git a/src/com/upc/pbe/upcnews/BandwidthMeasurer.java b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java new file mode 100644 index 0000000..12a879f --- /dev/null +++ b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java @@ -0,0 +1,27 @@ +package com.upc.pbe.upcnews; + +import android.net.TrafficStats; + +public class BandwidthMeasurer +{ + public double Measure(long rxBytes, long Time) + { + double bps; + long TotalRxAfterTest = TrafficStats.getTotalRxBytes(); + long AfterTime = System.currentTimeMillis(); + + double TimeDifference = AfterTime - Time; + + double rxDiff = TotalRxAfterTest - rxBytes; + + if(rxDiff != 0) + { + bps = (rxDiff / (TimeDifference/1000)); // total rx bytes per second. + } + else + { + bps = -1; //No transmitted data + } + return bps; + } +} diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index 8a37f91..fe5bc93 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -112,9 +112,8 @@ public class Directoris extends Activity implements OnItemClickListener { ArrayList m3u8parsed = p.parseFile(playlist); Log.d(TAG, "parsing completed"); - HLS h = new HLS(m3u8parsed); - // h.start(); - + HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); + h.start(); } catch (ErrorException e) { diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 9c3c74f..a66c859 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -2,31 +2,60 @@ package com.upc.pbe.upcnews; import java.util.ArrayList; +import android.util.Log; + public class HLS { - static final String TAG = "HLS"; - - ArrayList videos; - int video; - int quality; //0 es la más alta + private static final String TAG = "HLS"; + private ArrayList videos; + private int currentVideo ; + private int currentQuality; //0 es la más alta + private int currentSegment; + private boolean endReached; + private String localFolder; + //private fileDownloader fd; + private BandwidthMeasurer bm; - public HLS(ArrayList parsed) + public HLS(ArrayList parsed, String localFolder) { + currentVideo = currentQuality = currentSegment = 0; this.videos = parsed; - video = 0; - quality = 0; + endReached = false; + this.localFolder = localFolder; + bm = new BandwidthMeasurer(); } public void start() { - int currentVideo = 0; - for(video = 0; video < videos.size(); video++) + for(currentVideo = 0; currentVideo < videos.size(); currentVideo++) { - ArrayList