dash_writer: Update MPD output to allow live streaming

- Change type from static to dynamic.
- Add availabilityStartTime prop to MPD element.

The two together allow DASH players to pick up playback from
the latest chunk automatically.

Change-Id: I4debe5d7235e4161d34e13755e76b96532366dcb
diff --git a/encoder/dash_writer.cc b/encoder/dash_writer.cc
index 7926ecf..b0387cc 100644
--- a/encoder/dash_writer.cc
+++ b/encoder/dash_writer.cc
@@ -7,11 +7,14 @@
 // be found in the AUTHORS file in the root of the source tree.
 #include "encoder/dash_writer.h"
 
+#include <ctime>
 #include <ios>
 #include <sstream>
 
 #include "glog/logging.h"
 
+#include "encoder/time_util.h"
+
 namespace webmlive {
 const char kIndentStep[] = "  ";
 
@@ -21,7 +24,7 @@
 const char kDefaultSchema[] = "urn:mpeg:dash:schema:mpd:2011";
 const int kDefaultMinBufferTime = 1;
 const int kDefaultMediaPresentationDuration = 36000;  // 10 hours.
-const char kDefaultType[] = "static";
+const char kDefaultType[] = "dynamic";
 const char kDefaultProfiles[] = "urn:mpeg:dash:profile:isoff-live:2011";
 const int kDefaultStartTime = 0;
 const int kDefaultMaxWidth = 1920;
@@ -54,6 +57,14 @@
 const char kAudioSchemeUri[] =
   "urn:mpeg:dash:23003:3:audio_channel_configuration:2011";
 
+// %Y - year
+// %m - month, zero padded (01-12)
+// %d - day of month, zero padded (01-31).
+// %H - hour, zero padded, 24 hour clock (00-23)
+// %M - minute, zero padded (00-59)
+// %S - second, zero padded (00-61)
+const char kAvailabilityStartTimeFormat[] = "%Y-%m-%dT%H:%M:%SZ";
+
 //
 // AdaptationSet
 //
@@ -175,10 +186,15 @@
 
   manifest << "<?xml version=\"1.0\"?>\n";
 
+  time_t raw_time = time(NULL);
+
   // Open the MPD element.
   manifest << "<MPD "
            << "xmlns=\"" << kDefaultSchema << "\" "
            << "type=\"" << config_.type << "\" "
+           << "availabilityStartTime=\""
+           << StrFTime(gmtime(&raw_time), kAvailabilityStartTimeFormat)
+           << "\" "
            << "minBufferTime=\"PT" << config_.min_buffer_time << "S\" "
            << "mediaPresentationDuration=\"PT"
            << config_.media_presentation_duration << "S\" "