From de1b9441ef8af7ab893d8597dde677e6828543ff Mon Sep 17 00:00:00 2001
From: Thulinma <jaron@vietors.com>
Date: Tue, 5 Mar 2013 17:23:31 +0100
Subject: [PATCH] Working live HLS.

---
 src/conn_http_live.cpp | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/src/conn_http_live.cpp b/src/conn_http_live.cpp
index 55d49fed..ef0c3c4e 100644
--- a/src/conn_http_live.cpp
+++ b/src/conn_http_live.cpp
@@ -59,7 +59,7 @@ namespace Connector_HTTP {
         longestFragment = fragDuration;
       }
     }
-    if (metadata.isMember("length") && metadata["length"].asInt() > 0){
+    if (metadata.isMember("vod")){
       Result << "#EXTM3U\r\n"
       //"#EXT-X-VERSION:1\r\n"
       //"#EXT-X-ALLOW-CACHE:YES\r\n"
@@ -74,19 +74,17 @@ namespace Connector_HTTP {
       }
       Result << "#EXT-X-ENDLIST";
     }else{
+      std::cerr << metadata["frags"].toPrettyString() << std::endl;
       Result << "#EXTM3U\r\n"
-          "#EXT-X-MEDIA-SEQUENCE:0\r\n"
-          "#EXT-X-TARGETDURATION:" << (longestFragment / 1000) + 1 << "\r\n";
-      int lastDuration = 0;
-      for (int i = 0; i < fragIndices.size() - 1; i++){
-        Result << "#EXTINF:" << (metadata["keytime"][fragIndices[i + 1]].asInt() - lastDuration) / 1000 << ", no desc\r\n" << fragIndices[i] + 1
-            << "_" << fragIndices[i + 1] - fragIndices[i] << ".ts\r\n";
-        lastDuration = metadata["keytime"][fragIndices[i + 1]].asInt();
+          "#EXT-X-MEDIA-SEQUENCE:" << metadata["missed_frags"].asInt() <<"\r\n"
+          "#EXT-X-TARGETDURATION:10\r\n";
+      for (JSON::ArrIter ai = metadata["frags"].ArrBegin(); ai != metadata["frags"].ArrEnd(); ai++){
+        Result << "#EXTINF:" << (*ai)["dur"].asInt() / 1000 << ", no desc\r\n" << (*ai)["num"].asInt() << "_" << (*ai)["len"].asInt() << ".ts\r\n";
       }
     }
-#if DEBUG >= 8
+//#if DEBUG >= 8
     std::cerr << "Sending this index:" << std::endl << Result.str() << std::endl;
-#endif
+//#endif
     return Result.str();
   } //BuildIndex
 
@@ -241,16 +239,6 @@ namespace Connector_HTTP {
         }
         if (ss.spool()){
           while (Strm.parsePacket(ss.Received())){
-            if (Strm.getPacket(0).isMember("time")){
-              if ( !Strm.metadata.isMember("firsttime")){
-                Strm.metadata["firsttime"] = Strm.getPacket(0)["time"];
-              }else{
-                if ( !Strm.metadata.isMember("length") || Strm.metadata["length"].asInt() == 0){
-                  Strm.getPacket(0)["time"] = Strm.getPacket(0)["time"].asInt() - Strm.metadata["firsttime"].asInt();
-                }
-              }
-              Strm.metadata["lasttime"] = Strm.getPacket(0)["time"];
-            }
             if (pending_manifest){
               HTTP_S.Clean();
               HTTP_S.protocol = "HTTP/1.1";