Allow dynamically enable/disable face detection 41/315641/8
authorJakub Gajownik <j.gajownik2@samsung.com>
Wed, 17 Jul 2024 16:07:19 +0000 (18:07 +0200)
committerBot Blink <blinkbot@samsung.com>
Mon, 5 Aug 2024 18:44:15 +0000 (18:44 +0000)
As AI zoom was implemented in one of previous changes,
this patch extends it with support for enabling/disabling
it when modifing MediaStream constraints.

When "target" is changed in AI zoom settings, it triggers
camera device restart and once it's launched again, it'll
have new settings applied. So now, it's possible to control
it dynamically using Tizen-specific WebAPI.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-505
Change-Id: I2171614c21b52e479c179a5ce57fe34f5f3f1a63
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
third_party/blink/public/web/modules/mediastream/media_stream_video_source.h
third_party/blink/renderer/modules/mediastream/apply_constraints_processor.cc
third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.cc
third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h
third_party/blink/renderer/modules/mediastream/media_stream_video_source.cc
third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.cc
third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h

index 9a351c1349fb9109bb9c625efe5f386c0d843f37..bf134567759cce591cae831d3b69fc1b561b47f0 100644 (file)
@@ -131,7 +131,8 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource
   // IS_STOPPED). Any attempt to invoke Restart() when the source is not in this
   // state results in no action and |callback| invoked with INVALID_STATE.
   void Restart(const media::VideoCaptureFormat& new_format,
-               RestartCallback callback);
+               RestartCallback callback,
+               bool enable_face_detection = false);
 
   // Called by |track| to notify the source whether it has any paths to a
   // consuming endpoint.
@@ -163,6 +164,8 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource
   // must return a value.
   virtual absl::optional<media::VideoCaptureFormat> GetCurrentFormat() const;
 
+  virtual absl::optional<media::VideoCaptureParams> GetCurrentParams() const;
+
   // Returns true if encoded output can be enabled in the source.
   virtual bool SupportsEncodedOutput() const;
 
@@ -299,7 +302,8 @@ class BLINK_MODULES_EXPORT MediaStreamVideoSource
   // Note that if this method is overridden, StopSourceForRestartImpl() must
   // also be overridden following the respective contract. Otherwise, behavior
   // is undefined.
-  virtual void RestartSourceImpl(const media::VideoCaptureFormat& new_format);
+  virtual void RestartSourceImpl(const media::VideoCaptureFormat& new_format,
+                                 bool enable_face_detection);
 
   // This method should be called by implementations once an attempt to restart
   // the source completes. |did_restart| must be true if the source is running
index 12e7d29d5a765a58977007dfd4707c29d4159ed1..3cabefba405cb50ac775a992431368bcb9e57db3 100644 (file)
@@ -213,7 +213,17 @@ void ApplyConstraintsProcessor::MaybeStopSourceForRestart(
     return;
   }
 
-  if (video_source_->GetCurrentFormat() == settings.Format()) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  const auto current_params = video_source_->GetCurrentParams();
+  const bool restart_for_face_detection =
+      current_params && current_params->enable_face_detection !=
+                            settings.capture_params().enable_face_detection;
+#else
+  const bool restart_for_face_detection = false;
+#endif  // BUILDFLAG(IS_TIZEN_TV)
+
+  if (video_source_->GetCurrentFormat() == settings.Format() &&
+      !restart_for_face_detection) {
     video_source_->ReconfigureTrack(GetCurrentVideoTrack(),
                                     settings.track_adapter_settings(),
                                     settings.capture_params().ai_zoom_settings);
@@ -270,7 +280,9 @@ void ApplyConstraintsProcessor::FindNewFormatAndRestart(
       settings.HasValue() ? settings.Format()
                           : *video_source_->GetCurrentFormat(),
       WTF::BindOnce(&ApplyConstraintsProcessor::MaybeSourceRestarted,
-                    WrapWeakPersistent(this)));
+                    WrapWeakPersistent(this)),
+      settings.HasValue() ? settings.capture_params().enable_face_detection
+                          : false);
 }
 
 void ApplyConstraintsProcessor::MaybeSourceRestarted(
index 216c0de1ba03f25a95ade27de6b349bbd4d86543..111b81352e78d9e14dc3a5a8729ce21231090e01 100644 (file)
@@ -152,10 +152,12 @@ void MediaStreamVideoCapturerSource::StopSourceForRestartImpl() {
 }
 
 void MediaStreamVideoCapturerSource::RestartSourceImpl(
-    const media::VideoCaptureFormat& new_format) {
+    const media::VideoCaptureFormat& new_format,
+    bool enable_face_detection) {
   DCHECK(new_format.IsValid());
   media::VideoCaptureParams new_capture_params = capture_params_;
   new_capture_params.requested_format = new_format;
+  new_capture_params.enable_face_detection = enable_face_detection;
 #if defined(TIZEN_MULTIMEDIA)
   new_capture_params.lazy_start = false;
 #endif
@@ -172,6 +174,12 @@ MediaStreamVideoCapturerSource::GetCurrentFormat() const {
   return capture_params_.requested_format;
 }
 
+absl::optional<media::VideoCaptureParams>
+MediaStreamVideoCapturerSource::GetCurrentParams() const {
+  DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+  return capture_params_;
+}
+
 void MediaStreamVideoCapturerSource::ChangeSourceImpl(
     const MediaStreamDevice& new_device) {
   DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
index eca3eebb3a6e5709d85d3c9d14d786f6ed297da0..edce557eb3d90f633f492b759c2701bc7212ccfe 100644 (file)
@@ -96,8 +96,10 @@ class MODULES_EXPORT MediaStreamVideoCapturerSource
   media::VideoCaptureFeedbackCB GetFeedbackCallback() const override;
   void StopSourceImpl() override;
   void StopSourceForRestartImpl() override;
-  void RestartSourceImpl(const media::VideoCaptureFormat& new_format) override;
+  void RestartSourceImpl(const media::VideoCaptureFormat& new_format,
+                         bool enable_face_detection) override;
   absl::optional<media::VideoCaptureFormat> GetCurrentFormat() const override;
+  absl::optional<media::VideoCaptureParams> GetCurrentParams() const override;
   void ChangeSourceImpl(const MediaStreamDevice& new_device) override;
 #if !BUILDFLAG(IS_ANDROID)
   void Crop(const base::Token& crop_id,
index f8714632a7b150f5d1c96adcb73112023676334b..513c7bbee36eec54d1531122cc9039ebdbc81203 100644 (file)
@@ -270,7 +270,8 @@ void MediaStreamVideoSource::OnStopForRestartDone(bool did_stop_for_restart) {
 
 void MediaStreamVideoSource::Restart(
     const media::VideoCaptureFormat& new_format,
-    RestartCallback callback) {
+    RestartCallback callback,
+    bool enable_face_detection) {
   DCHECK(GetTaskRunner()->BelongsToCurrentThread());
   if (state_ != STOPPED_FOR_RESTART) {
     GetTaskRunner()->PostTask(
@@ -281,11 +282,12 @@ void MediaStreamVideoSource::Restart(
   DCHECK(!restart_callback_);
   state_ = RESTARTING;
   restart_callback_ = std::move(callback);
-  RestartSourceImpl(new_format);
+  RestartSourceImpl(new_format, enable_face_detection);
 }
 
 void MediaStreamVideoSource::RestartSourceImpl(
-    const media::VideoCaptureFormat& new_format) {
+    const media::VideoCaptureFormat& new_format,
+    bool /* enable_face_detection */) {
   NOTREACHED();
 }
 
@@ -369,6 +371,12 @@ MediaStreamVideoSource::GetCurrentFormat() const {
   return absl::optional<media::VideoCaptureFormat>();
 }
 
+absl::optional<media::VideoCaptureParams>
+MediaStreamVideoSource::GetCurrentParams() const {
+  DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+  return absl::nullopt;
+}
+
 size_t MediaStreamVideoSource::CountEncodedSinks() const {
   return std::accumulate(tracks_.begin(), tracks_.end(), size_t(0),
                          [](size_t accum, MediaStreamVideoTrack* track) {
index 390ed4bab50f93e14771d61c9595f29837d4109d..4f1584b36106510a803f04803c10b52cc2f86c6b 100644 (file)
@@ -136,7 +136,8 @@ void MockMediaStreamVideoSource::StopSourceForRestartImpl() {
 }
 
 void MockMediaStreamVideoSource::RestartSourceImpl(
-    const media::VideoCaptureFormat& new_format) {
+    const media::VideoCaptureFormat& new_format,
+    bool /* enable_face_detection */) {
   DCHECK(is_stopped_for_restart_);
   if (!can_restart_) {
     OnRestartDone(false);
index f7aa0aab3da35b9d60cdf66b092eaf9f8df355b6..43077dc9ef301fa1f603360484ee302f4805e4ee 100644 (file)
@@ -100,7 +100,8 @@ class MockMediaStreamVideoSource : public blink::MediaStreamVideoSource {
   void StopSourceImpl() override;
   absl::optional<media::VideoCaptureFormat> GetCurrentFormat() const override;
   void StopSourceForRestartImpl() override;
-  void RestartSourceImpl(const media::VideoCaptureFormat& new_format) override;
+  void RestartSourceImpl(const media::VideoCaptureFormat& new_format,
+                         bool enable_face_detection) override;
 
  private:
   media::VideoCaptureFormat format_;