[WebRTC][TTVD] Return all supported camera framerates 54/313754/3
authorJakub Gajownik <j.gajownik2@samsung.com>
Fri, 28 Jun 2024 15:46:00 +0000 (17:46 +0200)
committerBot Blink <blinkbot@samsung.com>
Tue, 2 Jul 2024 17:56:01 +0000 (17:56 +0000)
We should return all the supported framerates when handling
|GetSupportedFormats|. When user agent ask for lower than
max framerate, we're now potenially waste resources on
gathering more frame than needed.
After this CL, if lower framerate is requested through
|getUserMedia|, it might be selected on camera device
as well. This should save more resources in scenarios with
e.g 15fps camera requestes for other tasks.

Bug: https://jira-eu.sec.samsung.net/browse/VDGAME-528
Change-Id: I13e2cf8e03222b5c73f642bd08a16b96d004200b
Signed-off-by: Jakub Gajownik <j.gajownik2@samsung.com>
media/capture/video/tizen/camera.cc
media/capture/video/tizen/camera_utils.cc
media/capture/video/tizen/camera_utils.h

index 67b8c871f54e9fa53e99a56ddf9bf6727b48da03..238f53f962fa8e60ae3d3362c1acb78d51495ece 100644 (file)
@@ -81,17 +81,14 @@ CameraSupportedFormats Camera::GetSupportedFormats() {
   result.reserve(supported_resolutions.size() * supported_formats.size());
   for (auto format : supported_formats) {
     for (const auto resolution : supported_resolutions) {
-      float max_framerate =
-          GetMaxSupportedFramerate(handle_.get(), format, resolution);
-      if (max_framerate == 0.0f) {
-        continue;
+      for (const auto framerate :
+           GetSupportedFramerates(handle_.get(), format, resolution)) {
+        TIZEN_MEDIA_LOG(INFO)
+            << "Supported format: " << resolution.ToString()
+            << ", framerate: " << framerate << ", pixel format: " << format;
+        result.emplace_back(
+            CameraSupportedFormat{format, framerate, resolution});
       }
-
-      TIZEN_MEDIA_LOG(INFO)
-          << "Supported format: " << resolution.ToString()
-          << ", framerate: " << max_framerate << ", pixel format: " << format;
-      result.emplace_back(
-          CameraSupportedFormat{format, max_framerate, resolution});
     }
   }
   supported_formats_ = result;
index f071704176f5bc9b36c2f60a60018cfc6b6b68ff..4194e59b0f69275cf81e3e65f6fcebcd6ad1fd02 100644 (file)
@@ -27,11 +27,8 @@ bool SupportedFormatCb(camera_pixel_format_e format, void* user_data) {
 }
 
 bool SupportedFpsCb(camera_attr_fps_e fps, void* user_data) {
-  float* current_max = reinterpret_cast<float*>(user_data);
-  float framerate = static_cast<float>(static_cast<int>(fps));
-  if (framerate > *current_max) {
-    *current_max = framerate;
-  }
+  std::vector<float>* result = reinterpret_cast<std::vector<float>*>(user_data);
+  result->push_back(static_cast<float>(static_cast<int>(fps)));
   return true;
 }
 
@@ -171,26 +168,24 @@ SupportedFormats GetSupportedPreviewFormats(camera_h handle) {
   return result;
 }
 
-float GetMaxSupportedFramerate(camera_h handle,
-                               camera_pixel_format_e format,
-                               gfx::Size resolution) {
+std::vector<float> GetSupportedFramerates(camera_h handle,
+                                          camera_pixel_format_e format,
+                                          gfx::Size resolution) {
   if (!handle) {
     TIZEN_MEDIA_LOG_NO_INSTANCE(ERROR) << "Invalid camera handle!";
-    return 0.0f;
+    return {};
   }
 
-  // TODO(j.gajownik2) Add workaround for MJPEG
-
-  float max_framerate = 0.0f;
-  // TODO(j.gajownik2) What we should do with CAMERA_ATTR_FPS_AUTO?
-  int err = camera_attr_foreach_supported_fps(handle, &SupportedFpsCb,
-                                              &max_framerate);
+  std::vector<float> framerate;
+  int err = camera_attr_foreach_supported_fps_by_resolution(
+      handle, resolution.width(), resolution.height(), &SupportedFpsCb,
+      &framerate);
   if (err != CAMERA_ERROR_NONE) {
     TIZEN_MEDIA_LOG_NO_INSTANCE(ERROR)
         << "Error getting supported framerate: " << err;
-    return 0.0f;
+    return {};
   }
-  return max_framerate;
+  return framerate;
 }
 
 }  // namespace media
index 40d756161b51337c27f12cfb12877893dfa3f96f..ae4aa29897ba8b4fc4ff9d8ef56ec1972e61ab37 100644 (file)
@@ -25,9 +25,9 @@ SupportedResolutions GetSupportedPreviewResolutions(camera_h handle);
 using SupportedFormats = std::vector<camera_pixel_format_e>;
 SupportedFormats GetSupportedPreviewFormats(camera_h handle);
 
-float GetMaxSupportedFramerate(camera_h handle,
-                               camera_pixel_format_e format,
-                               gfx::Size resolution);
+std::vector<float> GetSupportedFramerates(camera_h handle,
+                                          camera_pixel_format_e format,
+                                          gfx::Size resolution);
 
 }  // namespace media