Commit c9c5b5b3f98e339622a1706b3a026fde9d7e4bcf

Authored by Imanol-Mikel Barba Sabariego
1 parent 38bc30bc

Mejoras en HLS

src/com/upc/pbe/upcnews/Descarrega.java
... ... @@ -40,15 +40,13 @@ public class Descarrega extends AsyncTask<Object, Object, Object>
40 40 // Llegeix cada byte i l'escriu en un arxiu fins que arriba a -1
41 41 InputStream in = conn.getInputStream();
42 42 OutputStream out = new FileOutputStream(file);
43   - int b = 0;
44   - while (b != -1)
  43 + byte data[] = new byte[102400]; //Mejor throughput!!
  44 + int count;
  45 + while((count = in.read(data)) != -1)
45 46 {
46   - b = in.read();
47   - if (b != -1)
48   - {
49   - out.write(b);
50   - }
  47 + out.write(data,0,count);
51 48 }
  49 + out.flush();
52 50 out.close();
53 51 in.close();
54 52 }
... ...
src/com/upc/pbe/upcnews/HLS.java
... ... @@ -65,43 +65,52 @@ public class HLS
65 65 loadVideo();
66 66 }
67 67 Segment seg = segments.get(currentSegment++);
68   - Log.d(TAG, seg.getName() + " " + seg.getURL());
69   - long startTime = System.currentTimeMillis();
70   - long segmentBytes = TrafficStats.getTotalRxBytes();
71   - d.descarregarguardar(seg.getURL(), localFolder);
72   - double bps = bm.Measure(segmentBytes, startTime);
73   - Log.d(TAG, "Velocitat actual (KB/s): " + (bps / 8e3));
74   - if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1))
  68 + String path = localFolder+seg.getURL().substring(seg.getURL().lastIndexOf("/") + 1, seg.getURL().length());
  69 + if(!new File(path).exists()) //Para qué bajarlo dos veces?
75 70 {
76   - int newQuality;
77   - for(newQuality = 0; newQuality < qualities.size(); newQuality++)
  71 + Log.d(TAG, seg.getName() + " " + seg.getURL());
  72 + long startTime = System.currentTimeMillis();
  73 + long segmentBytes = TrafficStats.getTotalRxBytes();
  74 + d.descarregarguardar(seg.getURL(), localFolder);
  75 + double bps = bm.Measure(segmentBytes, startTime);
  76 + Log.d(TAG, "Velocitat actual (KB/s): " + (bps / 8e3));
  77 + if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1))
78 78 {
79   - if(bps >= qualities.get(newQuality).getQuality())
  79 + int newQuality;
  80 + for(newQuality = 0; newQuality < qualities.size(); newQuality++)
80 81 {
81   - break;
  82 + if(bps >= qualities.get(newQuality).getQuality())
  83 + {
  84 + break;
  85 + }
  86 + }
  87 + if(currentQuality != newQuality)
  88 + {
  89 + currentQuality = newQuality;
  90 + currentVideo--; //Corregimos el del loadVideo()
  91 + loadVideo(); //Cargamos la nueva calidad
82 92 }
83 93 }
84   - currentQuality = newQuality;
85   - currentVideo--; //Corregimos el del loadVideo()
86   - loadVideo();
87   - }
88   - else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1))
89   - {
90   - int newQuality;
91   - for(newQuality = qualities.size(); newQuality <= 0; newQuality--)
  94 + else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1))
92 95 {
93   - if(bps <= qualities.get(newQuality).getQuality())
  96 + int newQuality;
  97 + for(newQuality = qualities.size()-1; newQuality > 0; newQuality--)
  98 + {
  99 + if(bps <= qualities.get(newQuality).getQuality())
  100 + {
  101 + newQuality--;
  102 + break;
  103 + }
  104 + }
  105 + if(currentQuality != newQuality)
94 106 {
95   - newQuality--;
96   - break;
  107 + currentQuality = newQuality;
  108 + currentVideo--; //Corregimos el del loadVideo()
  109 + loadVideo(); //Cargamos la nueva calidad
97 110 }
98 111 }
99   - currentQuality = newQuality;
100   - currentVideo--; //Corregimos el del loadVideo()
101   - loadVideo();
102 112 }
103   - return localFolder
104   - + seg.getURL().substring(seg.getURL().lastIndexOf("/") + 1, seg.getURL().length());
  113 + return path;
105 114 }
106 115  
107 116 public String previous() throws IOException
... ...
src/com/upc/pbe/upcnews/MainActivity.java
... ... @@ -63,19 +63,6 @@ public class MainActivity extends Activity implements OnClickListener {
63 63 alertaText = (TextView) findViewById(R.id.textViewAlerta);
64 64 alertaText.setVisibility(View.VISIBLE);
65 65 }
66   - /*
67   - * TESTING ANDROID DOWNLOADMANAGER NATIU
68   - *
69   - *
70   - *
71   - String pfile = "sample_ep_128k-00001.ts";
72   - DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://revistes.upc.es/~imanol/PBE/"+pfile));
73   - request.setDescription("SetDescprition");
74   - request.setTitle("SetTitle");
75   - request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().toString(), "sample_ep_128k-00001.ts");
76   - DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
77   - manager.enqueue(request);
78   - */
79 66 }
80 67  
81 68 public void onClick(View v) {
... ... @@ -137,11 +124,10 @@ public class MainActivity extends Activity implements OnClickListener {
137 124 }
138 125 /*
139 126 * COSAS POR HACER
140   - * (RELEASE-CRITICAL) Lentitud descarga
141 127 * (NORMAL) Quitar la elección de calidad al inicio? Discutir
142 128 * (NORMAL) Poner la defaultURL al server de PBE
143 129 * (WISHLIST) Descarga en segundo plano (Mejora dificil)
144   - * (WISHLIST) Hacer streaming DE VERDAD (requiere descarga en segundo plano)
  130 + * (WISHLIST) Hacer streaming DE VERDAD (appendeando los videos, seria IMPRESIONANTE)
145 131 * (WISHLIST) A�adir gif Imanol bailando (Easter eggs? vais en serio? XDDDDDDDDDDDD)
146 132 * Borrar esta puta mierda
147 133 */
... ...