| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/capture/video/chromeos/pixel_format_utils.h" | |
| 6 | |
| 7 #include <libdrm/drm_fourcc.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 namespace media { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 struct SupportedFormat { | |
| 16 VideoPixelFormat chromium_format; | |
| 17 arc::mojom::HalPixelFormat hal_format; | |
| 18 uint32_t drm_format; | |
| 19 } const kSupportedFormats[] = { | |
| 20 // The Android camera HAL v3 has three types of mandatory pixel formats: | |
| 21 // | |
| 22 // 1. HAL_PIXEL_FORMAT_YCbCr_420_888 (YUV flexible format). | |
| 23 // 2. HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED (platform-specific format). | |
| 24 // 3. HAL_PIXEL_FORMAT_BLOB (for JPEG). | |
| 25 // | |
| 26 // We can't use HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED as it is highly | |
| 27 // platform specific and there is no way for Chrome to query the exact | |
| 28 // pixel layout of the implementation-defined buffer. | |
| 29 // | |
| 30 // On Android the framework requests the preview stream with the | |
| 31 // implementation-defined format, and as a result some camera HALs support | |
| 32 // only implementation-defined preview buffers. We should use the video | |
| 33 // capture stream in Chrome VCD as it is mandatory for the camera HAL to | |
| 34 // support YUV flexbile format video streams. | |
| 35 | |
| 36 // TODO(jcliang): Change NV12 to I420 after the camera HAL supports handling | |
| 37 // I420 buffers. | |
| 38 {PIXEL_FORMAT_NV12, | |
| 39 arc::mojom::HalPixelFormat::HAL_PIXEL_FORMAT_YCbCr_420_888, | |
| 40 DRM_FORMAT_NV12}, | |
| 41 }; | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 VideoPixelFormat PixFormatHalToChromium(arc::mojom::HalPixelFormat from) { | |
| 46 auto* it = | |
| 47 std::find_if(std::begin(kSupportedFormats), std::end(kSupportedFormats), | |
| 48 [from](SupportedFormat f) { return f.hal_format == from; }); | |
| 49 if (it == std::end(kSupportedFormats)) { | |
| 50 return PIXEL_FORMAT_UNKNOWN; | |
| 51 } | |
| 52 return it->chromium_format; | |
| 53 } | |
| 54 | |
| 55 uint32_t PixFormatChromiumToDrm(VideoPixelFormat from) { | |
| 56 auto* it = std::find_if( | |
| 57 std::begin(kSupportedFormats), std::end(kSupportedFormats), | |
| 58 [from](SupportedFormat f) { return f.chromium_format == from; }); | |
| 59 if (it == std::end(kSupportedFormats)) { | |
| 60 return 0; | |
| 61 } | |
| 62 return it->drm_format; | |
| 63 } | |
| 64 | |
| 65 } // namespace media | |
| OLD | NEW |