+void MediaPlayerBridgeCapiTV::ParseDashInfo() {
+ std::string dash_info = GetDashInfo();
+ Json::CharReaderBuilder builder;
+ Json::CharReader* reader(builder.newCharReader());
+ Json::Value value;
+
+ if (reader->parse(dash_info.c_str(), dash_info.c_str() + dash_info.length(),
+ &value, nullptr)) {
+ mrs_url_ = value["mrsUrl"].asString();
+ std::string periodId = value["periodId"].asString();
+ if (periodId != "")
+ content_id_ = clean_url_ + "#period=" + periodId;
+ }
+ LOG(INFO) << "mrsUrl: " << mrs_url_ << ",contentId: " << content_id_;
+}
+
+std::string MediaPlayerBridgeCapiTV::GetDashInfo() {
+ char* dash_info = nullptr;
+ // dash_info format:
+ // {"type":0,"minBufferTime":4000,"mrsUrl":"","periodId":"first"}
+ const int ret = player_get_dash_info(player_, &dash_info);
+ if (ret != PLAYER_ERROR_NONE) {
+ if (dash_info)
+ free(dash_info);
+ LOG(ERROR) << "Fail to call player_get_dash_info,ret:" << ret;
+ return "";
+ }
+
+ if (!dash_info) {
+ LOG(ERROR) << "empty dash_info.";
+ return "";
+ }
+
+ const std::string info(dash_info);
+ free(dash_info);
+ LOG(INFO) << "dash info str: " << info;
+
+ return info;
+}
+
+bool MediaPlayerBridgeCapiTV::GetDashLiveDuration(int64_t* duration) {
+ DCHECK(duration);
+ std::string dash_info = GetDashInfo();
+ Json::CharReaderBuilder builder;
+ Json::CharReader* reader(builder.newCharReader());
+ Json::Value value;
+ int64_t out_duration = 0;
+
+ if (reader->parse(dash_info.c_str(), dash_info.c_str() + dash_info.length(),
+ &value, nullptr)) {
+ out_duration = value["mediaPresentationDuration"].asInt();
+ }
+
+ // According to dash spec, if duration == -1, set max time as duration.
+ if (out_duration == -1)
+ out_duration = base::TimeDelta::Max().InMilliseconds();
+ *duration = out_duration;
+
+ return true;
+}
+