Add interface about drop 72/296572/2
authorEunhye Choi <eunhae1.choi@samsung.com>
Tue, 1 Aug 2023 08:26:26 +0000 (17:26 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Tue, 8 Aug 2023 09:20:56 +0000 (18:20 +0900)
- add interface about frame drop information
  the prototype is synchronized with VD one.

Change-Id: Ie13cfcba5cb97967989d2cd70040db34230abe35

include/trackrenderer_capi/trackrenderer_capi.h
src/include_internal/trackrenderer/trackrenderer.h
src/trackrenderer.cpp
src/trackrenderer_capi.cpp

index a775c85123303d45fef343b536565a544ac2c417..d806c3439ea68f9cbbb77e94cb1c7068a0117c8d 100644 (file)
@@ -569,6 +569,63 @@ int trackrenderer_set_playback_rate(TrackRendererHandle handle,
 int trackrenderer_get_playing_time(TrackRendererHandle handle,
                                    uint64_t* time_millisecond);
 
+/**
+ * @brief        Get dropped frame counts in videosink
+ * @description  In this function trackrenderer get currently dropped frames in
+ *               sink.
+ * @param        [in] handle : trackrenderer handle ptr.
+ * @param        [out] counts : dropped counts
+ * @return       Return 0 if trackrenderer successfully get frame counts.
+ *               Otherwise -1.
+ * @code
+ *               //prepare trackrenderer hanle
+ *               //your logic
+ *               uint64_t count = 0;
+ *               trackrenderer_get_dropped_frames(handle,static_cast<void*>(&count)));
+ *               //your logic
+ *               trackrenderer_stop(handle);
+ * @endcode
+ * @pre          The trackrenderer must be at least created and set up.
+ * @post         None
+ * @exception    None.
+ * @version      2.0
+ * @remark       None
+ * @see          trackrenderer_create() \n
+ *               trackrenderer_prepare()
+ */
+int trackrenderer_get_dropped_frames(TrackRendererHandle handle, void* counts);
+
+/**
+ * @brief        Get dropped frame counts for catchup in video/audio sink
+ * @description  In this function trackrenderer get dropped frames for catchup
+ *               in sink.
+ * @param        [in] handle : trackrenderer handle ptr.
+ * @param        [in] type : the type of the track
+ * @param        [out] counts : dropped counts
+ * @return       Return 0 if trackrenderer successfully get frame counts.
+ *               Otherwise -1.
+ * @code
+ *               //prepare trackrenderer hanle
+ *               //your logic
+ *               uint64_t dropped_video_frames = 0;
+ *               trackrenderer_get_dropped_frames_for_catchup(handle,
+ *                   TrackRendererTrackType::kTrackRendererTrackTypeVideo,
+ *                   static_cast<void*>(&dropped_video_frames)));
+ *               //your logic
+ *               trackrenderer_stop(handle);
+ * @endcode
+ * @pre          The trackrenderer must be at least created and set up.
+ * @post         None
+ * @exception    None.
+ * @version      3.0
+ * @remark       None
+ * @see          trackrenderer_create() \n
+ *               trackrenderer_prepare()
+ */
+int trackrenderer_get_dropped_frames_for_catchup(TrackRendererHandle handle,
+                                                 TrackRendererTrackType type,
+                                                 void* counts);
+
 /**
  * @brief        Flush buffers for a trackrenderer.
  * @description  In this function trackrenderer will flush data in
index e921da88df4f1f21269da6e9f78decb27427909d..a3643ec85d38a346f155b3d5e42a8dae350f79db 100644 (file)
@@ -98,6 +98,8 @@ class TrackRenderer : public ResourceConflictListener,
   bool Seek(uint64_t time_millisecond, double playback_rate, bool audio_mute);
   bool SetPlaybackRate(double playback_rate, bool audio_mute);
   bool GetPlayingTime(uint64_t* curtime_in_msec);
+  bool GetDroppedFrames(void* frame_counts);
+  bool GetDroppedFramesForCatchup(TrackType type, void* frame_counts);
   bool Deactivate(TrackType type);
   bool Activate(TrackType type, const Track& track);
   bool SubmitPacket(const DecoderInputBufferPtr& data,
index a558d71b237d63a7240d31ff0b314d269a6a2fab..dd98c14347c6f41d4d001455f66870c8d0431c24 100644 (file)
@@ -2292,6 +2292,60 @@ bool TrackRenderer::GetPlayingTime_(uint64_t* curtime_in_msec) {
   return true;
 }
 
+bool TrackRenderer::GetDroppedFrames(void* frame_counts) {
+  std::lock_guard<std::mutex> lk(resource_m_);
+  if (state_ == State::kStopped) return false;
+  if (!pipeline_) return false;
+  uint64_t drop_count = 0;
+  Elements element = Elements::kSinkVideo;
+  GstStructure *stats = nullptr;
+
+  pipeline_->GetProperty(element, "stats", &stats);
+  if(!stats) {
+    TRACKRENDERER_WARN("stats is null");
+    return false;
+  }
+
+  gst_structure_get_uint64(stats, "dropped", &drop_count);
+  gst_structure_free(stats);
+
+  TRACKRENDERER_INFO("dropped %" PRIu64, drop_count);
+
+  *(int64_t*)frame_counts = drop_count;
+
+  return true;
+}
+
+bool TrackRenderer::GetDroppedFramesForCatchup(TrackType type,
+                                               void* frame_counts) {
+  std::lock_guard<std::mutex> lk(resource_m_);
+  if (state_ == State::kStopped) return false;
+  if (!pipeline_) return false;
+  uint64_t drop_count = 0;
+  Elements video_element = Elements::kSinkVideo;
+  Elements audio_element = Elements::kSinkAudio;
+  GstStructure *stats = nullptr;
+
+  if (type == kTrackTypeAudio)
+    pipeline_->GetProperty(audio_element, "stats", &stats);
+  else if (type == kTrackTypeVideo)
+    pipeline_->GetProperty(video_element, "stats", &stats);
+
+  if(!stats) {
+    TRACKRENDERER_WARN("stats is null");
+    return false;
+  }
+
+  gst_structure_get_uint64(stats, "dropped", &drop_count);
+  gst_structure_free(stats);
+
+  TRACKRENDERER_INFO("dropped %" PRIu64, drop_count);
+
+  *(int64_t*)frame_counts = drop_count;
+
+  return true;
+}
+
 bool TrackRenderer::SetDisplayMode(const DisplayMode& mode) {
   std::lock_guard<std::mutex> lk(resource_m_);
   if (state_ == State::kStopped) return false;
index ff9cad24f507ea86ebe27d3762e432f5e4a1ccb8..f0e9d67779879a66c54dd7e7ddf58984cc03f3f3 100644 (file)
@@ -556,6 +556,28 @@ int trackrenderer_get_playing_time(TrackRendererHandle handle,
   return kSuccess;
 }
 
+int trackrenderer_get_dropped_frames(TrackRendererHandle handle, void* counts) {
+  auto priv = static_cast<TrackRendererPrivPtr>(handle);
+  if (!priv) return kFailed;
+  if (priv->renderer->GetDroppedFrames(counts) == false) {
+    return kFailed;
+  }
+  return kSuccess;
+}
+
+int trackrenderer_get_dropped_frames_for_catchup(TrackRendererHandle handle,
+                                                 TrackRendererTrackType type,
+                                                 void* counts) {
+  auto priv = static_cast<TrackRendererPrivPtr>(handle);
+  if (!priv) return kFailed;
+  if (priv->renderer->GetDroppedFramesForCatchup(
+          plusplayer::trackrenderer::capi_utils::ConvertToTrackType(type),
+          counts) == false) {
+    return kFailed;
+  }
+  return kSuccess;
+}
+
 using TrackType = plusplayer::trackrenderer::TrackType;
 
 int trackrenderer_deactivate(TrackRendererHandle handle,