From c9c5b5b3f98e339622a1706b3a026fde9d7e4bcf Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Wed, 12 Dec 2012 05:44:27 +0000 Subject: [PATCH] Mejoras en HLS --- src/com/upc/pbe/upcnews/Descarrega.java | 12 +++++------- src/com/upc/pbe/upcnews/HLS.java | 63 ++++++++++++++++++++++++++++++++++++--------------------------- src/com/upc/pbe/upcnews/MainActivity.java | 16 +--------------- 3 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/com/upc/pbe/upcnews/Descarrega.java b/src/com/upc/pbe/upcnews/Descarrega.java index 46bb321..0e59fb3 100644 --- a/src/com/upc/pbe/upcnews/Descarrega.java +++ b/src/com/upc/pbe/upcnews/Descarrega.java @@ -40,15 +40,13 @@ public class Descarrega extends AsyncTask // Llegeix cada byte i l'escriu en un arxiu fins que arriba a -1 InputStream in = conn.getInputStream(); OutputStream out = new FileOutputStream(file); - int b = 0; - while (b != -1) + byte data[] = new byte[102400]; //Mejor throughput!! + int count; + while((count = in.read(data)) != -1) { - b = in.read(); - if (b != -1) - { - out.write(b); - } + out.write(data,0,count); } + out.flush(); out.close(); in.close(); } diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 7d51592..e3b45c2 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -65,43 +65,52 @@ public class HLS loadVideo(); } Segment seg = segments.get(currentSegment++); - Log.d(TAG, seg.getName() + " " + seg.getURL()); - long startTime = System.currentTimeMillis(); - long segmentBytes = TrafficStats.getTotalRxBytes(); - d.descarregarguardar(seg.getURL(), localFolder); - double bps = bm.Measure(segmentBytes, startTime); - Log.d(TAG, "Velocitat actual (KB/s): " + (bps / 8e3)); - if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1)) + String path = localFolder+seg.getURL().substring(seg.getURL().lastIndexOf("/") + 1, seg.getURL().length()); + if(!new File(path).exists()) //Para qué bajarlo dos veces? { - int newQuality; - for(newQuality = 0; newQuality < qualities.size(); newQuality++) + Log.d(TAG, seg.getName() + " " + seg.getURL()); + long startTime = System.currentTimeMillis(); + long segmentBytes = TrafficStats.getTotalRxBytes(); + d.descarregarguardar(seg.getURL(), localFolder); + double bps = bm.Measure(segmentBytes, startTime); + Log.d(TAG, "Velocitat actual (KB/s): " + (bps / 8e3)); + if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1)) { - if(bps >= qualities.get(newQuality).getQuality()) + int newQuality; + for(newQuality = 0; newQuality < qualities.size(); newQuality++) { - break; + if(bps >= qualities.get(newQuality).getQuality()) + { + break; + } + } + if(currentQuality != newQuality) + { + currentQuality = newQuality; + currentVideo--; //Corregimos el del loadVideo() + loadVideo(); //Cargamos la nueva calidad } } - currentQuality = newQuality; - currentVideo--; //Corregimos el del loadVideo() - loadVideo(); - } - else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1)) - { - int newQuality; - for(newQuality = qualities.size(); newQuality <= 0; newQuality--) + else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1)) { - if(bps <= qualities.get(newQuality).getQuality()) + int newQuality; + for(newQuality = qualities.size()-1; newQuality > 0; newQuality--) + { + if(bps <= qualities.get(newQuality).getQuality()) + { + newQuality--; + break; + } + } + if(currentQuality != newQuality) { - newQuality--; - break; + currentQuality = newQuality; + currentVideo--; //Corregimos el del loadVideo() + loadVideo(); //Cargamos la nueva calidad } } - currentQuality = newQuality; - currentVideo--; //Corregimos el del loadVideo() - loadVideo(); } - return localFolder - + seg.getURL().substring(seg.getURL().lastIndexOf("/") + 1, seg.getURL().length()); + return path; } public String previous() throws IOException diff --git a/src/com/upc/pbe/upcnews/MainActivity.java b/src/com/upc/pbe/upcnews/MainActivity.java index 654654b..8071d01 100644 --- a/src/com/upc/pbe/upcnews/MainActivity.java +++ b/src/com/upc/pbe/upcnews/MainActivity.java @@ -63,19 +63,6 @@ public class MainActivity extends Activity implements OnClickListener { alertaText = (TextView) findViewById(R.id.textViewAlerta); alertaText.setVisibility(View.VISIBLE); } - /* - * TESTING ANDROID DOWNLOADMANAGER NATIU - * - * - * - String pfile = "sample_ep_128k-00001.ts"; - DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://revistes.upc.es/~imanol/PBE/"+pfile)); - request.setDescription("SetDescprition"); - request.setTitle("SetTitle"); - request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().toString(), "sample_ep_128k-00001.ts"); - DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - manager.enqueue(request); - */ } public void onClick(View v) { @@ -137,11 +124,10 @@ public class MainActivity extends Activity implements OnClickListener { } /* * COSAS POR HACER - * (RELEASE-CRITICAL) Lentitud descarga * (NORMAL) Quitar la elección de calidad al inicio? Discutir * (NORMAL) Poner la defaultURL al server de PBE * (WISHLIST) Descarga en segundo plano (Mejora dificil) - * (WISHLIST) Hacer streaming DE VERDAD (requiere descarga en segundo plano) + * (WISHLIST) Hacer streaming DE VERDAD (appendeando los videos, seria IMPRESIONANTE) * (WISHLIST) A�adir gif Imanol bailando (Easter eggs? vais en serio? XDDDDDDDDDDDD) * Borrar esta puta mierda */ -- libgit2 0.22.2