Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: media/capture/video/chromeos/pixel_format_utils.cc

Issue 2837273004: media: add video capture device for ARC++ camera HAL v3 (Closed)
Patch Set: RELAND: media: add video capture device for ARC++ camera HAL v3 Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/capture/video/chromeos/pixel_format_utils.cc
diff --git a/media/capture/video/chromeos/pixel_format_utils.cc b/media/capture/video/chromeos/pixel_format_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1396a87a19e793f356f5735f7c499a3c3a0f6b92
--- /dev/null
+++ b/media/capture/video/chromeos/pixel_format_utils.cc
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/capture/video/chromeos/pixel_format_utils.h"
+
+#include <libdrm/drm_fourcc.h>
+
+#include <algorithm>
+
+namespace media {
+
+namespace {
+
+struct SupportedFormat {
+ VideoPixelFormat chromium_format;
+ arc::mojom::HalPixelFormat hal_format;
+ uint32_t drm_format;
+} const kSupportedFormats[] = {
+ // The Android camera HAL v3 has three types of mandatory pixel formats:
+ //
+ // 1. HAL_PIXEL_FORMAT_YCbCr_420_888 (YUV flexible format).
+ // 2. HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED (platform-specific format).
+ // 3. HAL_PIXEL_FORMAT_BLOB (for JPEG).
+ //
+ // We can't use HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED as it is highly
+ // platform specific and there is no way for Chrome to query the exact
+ // pixel layout of the implementation-defined buffer.
+ //
+ // On Android the framework requests the preview stream with the
+ // implementation-defined format, and as a result some camera HALs support
+ // only implementation-defined preview buffers. We should use the video
+ // capture stream in Chrome VCD as it is mandatory for the camera HAL to
+ // support YUV flexbile format video streams.
+
+ // TODO(jcliang): Change NV12 to I420 after the camera HAL supports handling
+ // I420 buffers.
+ {PIXEL_FORMAT_NV12,
+ arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_YCbCr_420_888,
+ DRM_FORMAT_NV12},
+};
+
+} // namespace
+
+VideoPixelFormat PixFormatHalToChromium(arc::mojom::HalPixelFormat from) {
+ auto* it =
+ std::find_if(std::begin(kSupportedFormats), std::end(kSupportedFormats),
+ [from](SupportedFormat f) { return f.hal_format == from; });
+ if (it == std::end(kSupportedFormats)) {
+ return PIXEL_FORMAT_UNKNOWN;
+ }
+ return it->chromium_format;
+}
+
+uint32_t PixFormatChromiumToDrm(VideoPixelFormat from) {
+ auto* it = std::find_if(
+ std::begin(kSupportedFormats), std::end(kSupportedFormats),
+ [from](SupportedFormat f) { return f.chromium_format == from; });
+ if (it == std::end(kSupportedFormats)) {
+ return 0;
+ }
+ return it->drm_format;
+}
+
+} // namespace media
« no previous file with comments | « media/capture/video/chromeos/pixel_format_utils.h ('k') | media/capture/video/chromeos/stream_buffer_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698