cleanup code about audio mute 42/298242/3
authorEunhye Choi <eunhae1.choi@samsung.com>
Mon, 4 Sep 2023 06:39:45 +0000 (15:39 +0900)
committerEunhye Choi <eunhae1.choi@samsung.com>
Mon, 4 Sep 2023 08:26:04 +0000 (17:26 +0900)
- cleanup code about audio mute
- remove unnecessary function

[Version] 0.0.33

Change-Id: I24b0b757df42edd39d10251e1bbe57f2950f1e52

packaging/libtrackrenderer.spec
src/trackrenderer.cpp

index 63a9126092b7db3dd4b6c30252dcd66af5d9a4de..3a5c46d5ead3d79fb4337984d217326218065fb6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libtrackrenderer
 Summary:    new multimedia streaming player trackrenderer
-Version:    0.0.32
+Version:    0.0.33
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index c7f7f90ef576b4393f233e43e72fd7ee0e8d24fd..9974a201eb9003c40aa8b0413dab546944155693 100644 (file)
@@ -40,6 +40,9 @@ const char kPadProbeSubtitleBlock[] = "SUBTITLE_BLOCK_DOWNSTREAM";
 const char kPadProbeCapsEvent[] = "CAPS_EVENT_DOWNSTREAM";
 const char kPadProbeAppsrcEvent[] = "APPSRC_EVENT_DOWNSTREAM";
 
+const char kVideoSinkName[] = "tizenwlsink";
+const char kAudioSinkName[] = "pulsesink";
+
 // Hw clock
 #ifndef PR_TASK_PERF_USER_TRACE
 #define PR_TASK_PERF_USER_TRACE 666
@@ -90,22 +93,10 @@ void TvplusPerformanceLogs() {
   }
 }
 
-bool IsSdkEnabledFeature() {
-#ifdef SDK_ENABLED_FEATURE
-  return true;
-#endif
-  return false;
-}
-
 inline bool IsPcmMimeType(const std::string& mimetype) {
   return (mimetype.find("audio/x-raw") != std::string::npos);
 }
 
-const char* GetAudioSinkPluginName(bool swdecoder,
-                                   const std::string& mimetype) {
-  return "pulsesink";
-}
-
 const char* GetIniElement(const std::map<std::string, std::string>& elements,
                             const std::string& key) {
   auto look = elements.find(key);
@@ -119,15 +110,6 @@ const char* GetIniElement(const std::map<std::string, std::string>& elements,
   return look->second.c_str();
 }
 
-const char* GetVideoSinkPluginName(const std::map<std::string, std::string>& ini_elements,
-                                   bool swdecoder) {
-  const char* videosink = GetIniElement(ini_elements, "videosink_element_overlay");
-  if (!videosink)
-    return "tizenwlsink";
-
-  return videosink;
-}
-
 bool GetIniValue(const std::map<std::string, bool>& properties,
                  const std::string& key) {
   auto look = properties.find(key);
@@ -792,26 +774,15 @@ bool TrackRenderer::Seek(uint64_t time_millisecond,
   TRACKRENDERER_ENTER;
   std::lock_guard<std::mutex> lk(resource_m_);
   if (state_ == State::kStopped) return false;
-  if (!pipeline_) {
+  if (!pipeline_)
     return false;
-  }
-  // mute off/on values are defined in mmaudiosink element
-  static const int mute_off = 2;
-  static const int mute_on = 3;
-
-  int mute_flag = audio_mute ? mute_on : mute_off;
 
   auto is_audio_track = [](const Track& item) noexcept -> bool {
     return item.mimetype.find("audio") != std::string::npos;
   };
   auto target = find_if(trackinfo_.begin(), trackinfo_.end(), is_audio_track);
-  if (target != trackinfo_.end()) {
-    if (target->use_swdecoder || internal::IsSdkEnabledFeature()) {
-      pipeline_->SetProperty(Elements::kSinkAudio, "mute", mute_flag % 2);
-    } else {
-      pipeline_->SetProperty(Elements::kSinkAudio, "mute-mask", mute_flag);
-    }
-  }
+  if (target != trackinfo_.end())
+    pipeline_->SetProperty(Elements::kSinkAudio, "mute", audio_mute);
 
   int flags = GST_SEEK_FLAG_FLUSH;
   if (is_accurate_seek_)
@@ -846,33 +817,20 @@ bool TrackRenderer::SetPlaybackRate(double playback_rate, bool audio_mute) {
   TRACKRENDERER_ENTER;
   std::lock_guard<std::mutex> lk(resource_m_);
   if (state_ == State::kStopped) return false;
-  if (!pipeline_) {
-    return false;
-  }
-  // mute off/on values are defined in mmaudiosink element
-  static const int mute_off = 2;
-  static const int mute_on = 3;
+  if (!pipeline_) return false;
+
   uint64_t last_video_pts = 0, curtime_in_msec = 0;
-  int mute_flag = audio_mute ? mute_on : mute_off;
+
   GetPlayingTime_(&curtime_in_msec);
 
-  TRACKRENDERER_INFO("Set mute-mask property as [%d] ,rate [%lf]", mute_flag,
+  TRACKRENDERER_INFO("Set audio mute property as [%d], rate [%lf]", audio_mute,
                      playback_rate);
   auto is_audio_track = [](const Track& item) noexcept -> bool {
     return item.mimetype.find("audio") != std::string::npos;
   };
   auto target = find_if(trackinfo_.begin(), trackinfo_.end(), is_audio_track);
-  if (target != trackinfo_.end()) {
-    if (target->use_swdecoder || internal::IsSdkEnabledFeature()) {
-      pipeline_->SetProperty(Elements::kSinkAudio, "mute", mute_flag % 2);
-    } else {
-      pipeline_->SetProperty(Elements::kSinkAudio, "mute-mask", mute_flag);
-      pipeline_->SetProperty(Elements::kDecAudio, "audio-playback-rate",
-                             gint(playback_rate * 100));
-      pipeline_->SetProperty(Elements::kSinkAudio, "playback-rate",
-                             gint(playback_rate * 100));
-    }
-  }
+  if (target != trackinfo_.end())
+    pipeline_->SetProperty(Elements::kSinkAudio, "mute", audio_mute);
 
   Elements audio_probe_element = Elements::kDecAudio;
   Elements video_probe_element = Elements::kDecVideo;
@@ -1138,7 +1096,7 @@ bool TrackRenderer::CreateVideoPipeline_(const Track* track) {
   display_->GetDisplay(&display_type);
   const char* videosink_name = "fakesink";
   if (internal::IsDisplayNeeded(display_type))
-    videosink_name = internal::GetVideoSinkPluginName(ini_elements_, track->use_swdecoder);
+    videosink_name = kVideoSinkName;
 
   if (!pipeline_->FactoryMake(Elements::kSinkVideo, videosink_name, NULL)) {
     TRACKRENDERER_ERROR("fail to make video sink(%s)", videosink_name);
@@ -1146,7 +1104,7 @@ bool TrackRenderer::CreateVideoPipeline_(const Track* track) {
   }
 
   if (videosink_name &&
-      (strstr(videosink_name, "fakesink") || strstr(videosink_name, "tizenwlsink"))) {
+      (strstr(videosink_name, "fakesink") || strstr(videosink_name, kVideoSinkName))) {
     pipeline_->SignalConnect(Elements::kSinkVideo, "preroll-handoff",
                               G_CALLBACK(GstPrerollDecodedVideoBufferCb_), this);
     pipeline_->SignalConnect(Elements::kSinkVideo, "handoff",
@@ -1200,7 +1158,7 @@ bool TrackRenderer::CreateVideoPipeline_(const Track* track) {
   bool sw_codec =  internal::GetIniValue(properties_, "use_default_video_codec_sw");
   if (!sw_codec && pipeline_->IsFactoryListType(Elements::kDecVideo, GST_ELEMENT_FACTORY_TYPE_HARDWARE)) {
     TRACKRENDERER_INFO("HW codec");
-    if (videosink_name && strstr(videosink_name, "tizenwlsink"))
+    if (videosink_name && strstr(videosink_name, kVideoSinkName))
       pipeline_->SetProperty(Elements::kSinkVideo, "use-tbm", true);
   } else { /* sw */
     TRACKRENDERER_INFO("SW codec");
@@ -1210,7 +1168,7 @@ bool TrackRenderer::CreateVideoPipeline_(const Track* track) {
     pipeline_->FactoryMake(Elements::kVideoConvert, "videoconvert", NULL);
     pipeline_->SetProperty(Elements::kVideoConvert, "n-threads", 2);
 
-    if (videosink_name && strstr(videosink_name, "tizenwlsink"))
+    if (videosink_name && strstr(videosink_name, kVideoSinkName))
       pipeline_->SetProperty(Elements::kSinkVideo, "use-tbm", false);
   }
 
@@ -1269,11 +1227,7 @@ bool TrackRenderer::CreateAudioPipeline_(const Track* track) {
     return false;
   }
 
-  pipeline_->FactoryMake(
-      Elements::kSinkAudio,
-      internal::GetAudioSinkPluginName(track->use_swdecoder, track->mimetype),
-      NULL);
-
+  pipeline_->FactoryMake(Elements::kSinkAudio, kAudioSinkName, NULL);
   pipeline_->SetProperty(Elements::kSinkAudio, "provide-clock", FALSE);
 
   pipeline_->CreateBin(Elements::kBinAudio, "audiobin");
@@ -1312,10 +1266,7 @@ bool TrackRenderer::CreateRawAudioPipeline_(const Track* track) {
        TRACKRENDERER_ENTER;
   CreateAppSrc_(kTrackTypeAudio, track->mimetype);
 
-  pipeline_->FactoryMake(
-      Elements::kSinkAudio,
-      internal::GetAudioSinkPluginName(track->use_swdecoder, track->mimetype),
-      NULL);
+  pipeline_->FactoryMake(Elements::kSinkAudio, kAudioSinkName, NULL);
   pipeline_->SetProperty(Elements::kSinkAudio, "drift-tolerance",
                          ((200 * GST_MSECOND) / GST_USECOND));
   pipeline_->SetProperty(Elements::kSinkAudio, "provide-clock", FALSE);
@@ -1440,7 +1391,7 @@ bool TrackRenderer::GetResource_() {
   for (const Track& track : trackinfo_) {
     if (track.active == false) continue;
     if (track.type != kTrackTypeVideo) continue;
-    if (internal::IsSdkEnabledFeature() || track.use_swdecoder) continue;
+    if (track.use_swdecoder) continue; // FIXME: need to acquire the renderer res
 
     ResourceProperty videodecproperty;
     videodecproperty.category = ResourceCategory::kVideoDecoder;
@@ -2153,10 +2104,7 @@ bool TrackRenderer::ActivateAudioPipeline(GstCaps * caps) {
   }
   pipeline_->FactoryMake(Elements::kAudioConvert, "audioconvert", nullptr);
   pipeline_->FactoryMake(Elements::kAudioResample, "audioresample", nullptr);
-  pipeline_->FactoryMake(
-       Elements::kSinkAudio,
-       "pulsesink",
-       nullptr);
+  pipeline_->FactoryMake(Elements::kSinkAudio, kAudioSinkName, nullptr);
 
   pipeline_->SetProperty(Elements::kSinkAudio, "sync", TRUE, "async", TRUE, "provide-clock", FALSE);
   pipeline_->SetProperty(Elements::kAppSrcAudio, "stream-type",
@@ -2226,7 +2174,7 @@ bool TrackRenderer::Activate(TrackType type, const Track& track) {
   trackinfo_.push_back(track);
 
   if (type == kTrackTypeVideo) {
-    if (!internal::IsSdkEnabledFeature() && !track.use_swdecoder) { /* except sw */
+    if (!track.use_swdecoder) {
       std::list<ResourceProperty> propertylist;
       ResourceProperty videodecproperty;
       videodecproperty.category = ResourceCategory::kVideoDecoder;
@@ -2241,7 +2189,7 @@ bool TrackRenderer::Activate(TrackType type, const Track& track) {
         TRACKRENDERER_ERROR("Video resource acquire fail! ChangeTrack fail.");
         return false;
       }
-    }
+    } // FIXME: need to acquire the renderer res
 
     auto caps = caps_builder_.Build(track, internal::IsDrmEmeElementNecessary(
                                                drm_property_, track.mimetype));
@@ -2266,9 +2214,8 @@ bool TrackRenderer::Activate(TrackType type, const Track& track) {
       return false;
     }
 
-    pipeline_->FactoryMake(Elements::kSinkVideo,
-                           internal::GetVideoSinkPluginName(ini_elements_,
-                                                            track.use_swdecoder), NULL);
+    // FIXME: need to check display type
+    pipeline_->FactoryMake(Elements::kSinkVideo, kVideoSinkName, NULL);
     pipeline_->SetProperty(Elements::kSinkVideo, "async", FALSE);
     if (internal::IsDecryptorElementNecessary(drm_property_)) {
       pipeline_->FactoryMake(Elements::kDrmVideo, "cencdecrypt", NULL);
@@ -2563,7 +2510,7 @@ void TrackRenderer::SetVolume_() {
     TRACKRENDERER_WARN("no audio sink");
     return;
   }
-  if (strstr(sink_name, "pulsesink")) {
+  if (strstr(sink_name, kAudioSinkName)) {
     pipeline_->SetProperty(Elements::kSinkAudio, "volume", (volume_/100.0));
   } else {
     TRACKRENDERER_WARN("unknown audio sink name: %s", sink_name);
@@ -2841,10 +2788,7 @@ bool TrackRenderer::ActivateAudio_() {
                                               drm_property_, track.mimetype));
   pipeline_->FactoryMake(Elements::kDecAudio, (GstCaps*)caps.GetCaps_(),
                           GST_ELEMENT_FACTORY_TYPE_DECODER, NULL);
-  pipeline_->FactoryMake(
-      Elements::kSinkAudio,
-      internal::GetAudioSinkPluginName(track.use_swdecoder, track.mimetype),
-      nullptr);
+  pipeline_->FactoryMake(Elements::kSinkAudio, kAudioSinkName, NULL);
   if (volume_ != kVolumeNone) {
     SetVolume_();
   }
@@ -3015,7 +2959,7 @@ void TrackRenderer::EnableVideoHole_() {
     TRACKRENDERER_WARN("no video sink");
     return;
   }
-  if (strstr(sink_name, "fakesink") || strstr(sink_name, "tizenwlsink")) {
+  if (strstr(sink_name, "fakesink") || strstr(sink_name, kVideoSinkName)) {
     pipeline_->SetProperty(Elements::kSinkVideo, "signal-handoffs", is_video_hole_enabled_ ? false : true);
     TRACKRENDERER_DEBUG("value: %d", is_video_hole_enabled_);
   } else {