bool SetTrack(const std::vector<Track>& trackinfo);
void SetIniProperty(const std::map<std::string, bool>& Properties);
void SetIniElement(const std::map<std::string, std::string>& elements);
- bool Seek(uint64_t time_millisecond, double playback_rate);
- bool Seek(uint64_t time_millisecond, double playback_rate, bool audio_mute);
+ bool Seek(uint64_t time, double playback_rate);
+ bool Seek(uint64_t time, double playback_rate, bool audio_mute);
bool SetPlaybackRate(double playback_rate, bool audio_mute);
- bool GetPlayingTime(uint64_t* curtime_in_msec);
+ bool GetPlayingTime(uint64_t* curtime);
bool GetDroppedFrames(void* frame_counts);
bool GetDroppedFramesForCatchup(TrackType type, void* frame_counts);
bool Deactivate(TrackType type);
kPlaying,
};
+ enum class TimeUnit {
+ kMs,
+ kUs,
+ };
+
struct TrackContext {
int index = kInvalidTrackIndex;
bool is_enough_data = false;
bool SetUnlimitedMaxBufferMode_(const boost::any& value);
bool SetVideoPreDisplayMode_(const boost::any& value);
bool SetStartRenderingTime_(const boost::any& value);
+ bool SetPlayerTimeUnitType_(const boost::any& value);
void CompleteSeeking_(void);
bool HasSubtitleOnly_() const;
bool ActivateAudioPipeline(GstCaps* caps);
void EnableVideoHole_();
void ApplySoundStreamInfo_();
+ const char* ConvertTimeUnitToString_();
+ gint64 ConvertTimeUnitToNS_(uint64_t time);
+ uint64_t ConvertNsToTimeUnit_(gint64 time);
+
private:
EventListener* eventlistener_ = nullptr; // eventlistener is Defaultplayer
std::mutex resource_m_;
std::map<std::string, Config_Setter> config_setter_table_;
int64_t start_time = -1;
+ TimeUnit time_unit_type_ = TimeUnit::kMs;
+
private:
static const Attributes kAttributes_;
static const AttributesByElement kAttributesByElem_;
enum class TrackEncryptionUnit { kNone, kTs, kEs };
-void TvplusPerformanceLogs() {
- FILE* fp = NULL;
- const char* TVPLUS_POPUP_LOG_FILE_NAME = "/tmp/play_log.txt";
- TRACKRENDERER_DEBUG("~~~~~~~~~~~~~ [PROFILING LOG ON] ~~~~~~~~~~~~~~~~");
- if ((fp = fopen(TVPLUS_POPUP_LOG_FILE_NAME, "a+")) != NULL) {
- struct timespec tp;
- char unmute[30];
- clock_gettime(CLOCK_MONOTONIC, &tp);
- snprintf(unmute, 30, "[um:%d.%d]", (int)tp.tv_sec,
- (int)tp.tv_nsec / 10000000);
- fprintf(fp, "%s", unmute);
- chmod(TVPLUS_POPUP_LOG_FILE_NAME, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- fclose(fp);
- TRACKRENDERER_DEBUG("~~~~~~~~~~~~~ file write passed ~~~~~~~~~~~~~~~");
- } else {
- TRACKRENDERER_DEBUG("~~~~~~~~~~~~~ file write failed ~~~~~~~~~~~~~~~~");
- }
-}
-
inline bool IsPcmMimeType(const std::string& mimetype) {
return (mimetype.find("audio/x-raw") != std::string::npos);
}
if (state_ < State::kWorking) return false;
target_substate_ = SubState::kPlaying;
pipeline_->SetState(Elements::kPipeline, GST_STATE_PLAYING);
-#if 0
- internal::TvplusPerformanceLogs();
-#endif
+
if (internal::GetIniValue(properties_, "generate_dot"))
pipeline_->GenerateDot("plusplayer_trackrenderer_start");
}
}
-bool TrackRenderer::Seek(uint64_t time_millisecond,
+bool TrackRenderer::Seek(uint64_t time,
double playback_rate) {
TRACKRENDERER_ENTER;
std::lock_guard<std::mutex> lk(resource_m_);
"async", async);
}
- TRACKRENDERER_INFO("target %" PRIu64 " ms rate [%lf]", time_millisecond,
- playback_rate);
- gint64 start = time_millisecond * GST_MSECOND, stop = GST_CLOCK_TIME_NONE;
+ gint64 start = ConvertTimeUnitToNS_(time), stop = GST_CLOCK_TIME_NONE;
+ TRACKRENDERER_INFO("[%p] > target %" PRIu64 " %s rate [%lf]", this, time,
+ ConvertTimeUnitToString_(), playback_rate);
+
if (playback_rate < 0) {
stop = start;
start = 0;
if (!pipeline_->Seek(playback_rate, GST_FORMAT_TIME, (GstSeekFlags)flags,
GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_SET, stop)) {
- TRACKRENDERER_ERROR("Fail to seek to [%" PRIu64 "] ms", time_millisecond);
+ TRACKRENDERER_ERROR_P(this, "Fail to seek");
}
is_seeking_ = true;
return true;
}
-bool TrackRenderer::Seek(uint64_t time_millisecond,
+bool TrackRenderer::Seek(uint64_t time,
double playback_rate, bool audio_mute) {
TRACKRENDERER_ENTER;
std::lock_guard<std::mutex> lk(resource_m_);
else
flags |= GST_SEEK_FLAG_KEY_UNIT;
- TRACKRENDERER_INFO("target %" PRIu64 " ms rate [%lf] mute [%d]", time_millisecond,
- playback_rate, audio_mute);
- if (!pipeline_->Seek(playback_rate, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET,
- time_millisecond * GST_MSECOND, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
- TRACKRENDERER_ERROR("Fail to seek to [%" PRIu64 "] ms", time_millisecond);
+ auto convert_time = ConvertTimeUnitToNS_(time);
+
+ TRACKRENDERER_INFO("[%p] > target %" PRIu64 " %s rate [%lf] mute [%d]",
+ this, convert_time, ConvertTimeUnitToString_(),
+ playback_rate, audio_mute);
+ if (!pipeline_->Seek(playback_rate, GST_FORMAT_TIME,
+ (GstSeekFlags)(GST_SEEK_FLAG_FLUSH), GST_SEEK_TYPE_SET,
+ convert_time, GST_SEEK_TYPE_NONE,
+ GST_CLOCK_TIME_NONE)) {
+ TRACKRENDERER_ERROR("[%p] > Fail to seek to [%" PRIu64 "] %s",
+ this, convert_time, ConvertTimeUnitToString_());
}
+
is_seeking_ = true;
for (int i = 0; i < kTrackTypeMax; ++i) {
if (type == kTrackTypeSubtitle)
return true;
- trackrenderer->eventlistener_->OnSeekData(type, offset / GST_MSECOND);
+ trackrenderer->eventlistener_->OnSeekData(type,
+ trackrenderer->ConvertNsToTimeUnit_(static_cast<gint64>(offset)));
+
TRACKRENDERER_LEAVE;
return true;
}
return false;
}
-bool TrackRenderer::GetPlayingTime(uint64_t* curtime_in_msec) {
+bool TrackRenderer::GetPlayingTime(uint64_t* curtime) {
std::lock_guard<std::mutex> lk(resource_m_);
if (state_ == State::kStopped) return false;
if (state_ == State::kResourceConflicted) {
- *curtime_in_msec = last_position_;
+ *curtime = last_position_;
return true;
}
if (!pipeline_) return false;
- GetPlayingTime_(curtime_in_msec);
+ GetPlayingTime_(curtime);
return true;
}
-bool TrackRenderer::GetPlayingTime_(uint64_t* curtime_in_msec) {
+bool TrackRenderer::GetPlayingTime_(uint64_t* curtime) {
int64_t pos_video = 0, pos_audio = 0;
bool ret_video = pipeline_->QueryPosition(Elements::kSinkVideo,
GST_FORMAT_TIME, &pos_video);
bool ret_audio = pipeline_->QueryPosition(Elements::kSinkAudio,
GST_FORMAT_TIME, &pos_audio);
- if (ret_video || ret_audio)
- last_position_ = *curtime_in_msec = pos_audio > pos_video
- ? (pos_audio / GST_MSECOND)
- : (pos_video / GST_MSECOND);
- else
- *curtime_in_msec = last_position_;
- // TRACKRENDERER_INFO("playing time [%" PRIu64 " ms]", *curtime_in_msec);
+ if (ret_video || ret_audio) {
+ last_position_ = *curtime = pos_audio > pos_video
+ ? (ConvertNsToTimeUnit_(pos_audio))
+ : (ConvertNsToTimeUnit_(pos_video));
+ } else {
+ *curtime = last_position_;
+ }
+ // TRACKRENDERER_INFO("playing time [%" PRIu64 " %s]",
+ // *curtime, ConvertTimeUnitToString_());
return true;
}
&TrackRenderer::SetVideoPreDisplayMode_, this, std::placeholders::_1);
config_setter_table_[ConfigNameStartRenderingTime] = std::bind(
&TrackRenderer::SetStartRenderingTime_, this, std::placeholders::_1);
+ config_setter_table_[ConfigNamePlayerTimeUnitType] = std::bind(
+ &TrackRenderer::SetPlayerTimeUnitType_, this, std::placeholders::_1);
}
bool TrackRenderer::SetAccurateSeekMode_(const boost::any& value) {
return true;
}
+bool TrackRenderer::SetPlayerTimeUnitType_(const boost::any& value) {
+ std::uint32_t val = boost::any_cast<std::uint32_t>(value);
+ TRACKRENDERER_ERROR_P(this, " PlayerTimeUnitType [%s]",
+ (val == 0) ? "Ms" : "Us");
+ if (val == 0)
+ time_unit_type_ = TimeUnit::kMs;
+ else if (val == 1)
+ time_unit_type_ = TimeUnit::kUs;
+ return true;
+}
+
void TrackRenderer::GstElementLowLatency_(const TrackType& type) {
if (low_latency_mode_ ==
static_cast<std::uint32_t>(LowLatencyMode::kLowLatencyModeNone))
}
}
+const char* TrackRenderer::ConvertTimeUnitToString_() {
+ return time_unit_type_ == TimeUnit::kUs ? "us" : "ms";
+}
+
+gint64 TrackRenderer::ConvertTimeUnitToNS_(uint64_t time) {
+ return time_unit_type_ == TimeUnit::kUs ?
+ static_cast<gint64>(time * GST_USECOND) :
+ static_cast<gint64>(time * GST_MSECOND);
+}
+
+uint64_t TrackRenderer::ConvertNsToTimeUnit_(gint64 time) {
+ return time_unit_type_ == TimeUnit::kUs ?
+ static_cast<uint64_t>(time / GST_USECOND) :
+ static_cast<uint64_t>(time / GST_MSECOND);
+}
+
} // namespace trackrenderer
} // namespace plusplayer