1d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/* 2d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Copyright 2016, The Android Open Source Project 3d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 4d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Licensed under the Apache License, Version 2.0 (the "License"); 5d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * you may not use this file except in compliance with the License. 6d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * You may obtain a copy of the License at 7d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 8d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * http://www.apache.org/licenses/LICENSE-2.0 9d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 10d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Unless required by applicable law or agreed to in writing, software 11d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * distributed under the License is distributed on an "AS IS" BASIS, 12d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * See the License for the specific language governing permissions and 14d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * limitations under the License. 15d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 16d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 17d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0__CONVERSION_H 18d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#define ANDROID_HARDWARE_MEDIA_OMX_V1_0__CONVERSION_H 19d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 20d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <vector> 21d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <list> 22d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 234c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa#include <cinttypes> 24d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <unistd.h> 25d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 26d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <hidl/MQDescriptor.h> 27d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <hidl/Status.h> 28d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 29d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <binder/Binder.h> 30d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <binder/Status.h> 31d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <ui/FenceTime.h> 32d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <cutils/native_handle.h> 33d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 34d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <ui/GraphicBuffer.h> 35d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <media/OMXFenceParcelable.h> 36d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <media/OMXBuffer.h> 37d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <media/hardware/VideoAPI.h> 384c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa#include <media/stagefright/MediaErrors.h> 394c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa#include <gui/IGraphicBufferProducer.h> 40d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 41d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/types.h> 42d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/IOmx.h> 43d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/IOmxNode.h> 44d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/IOmxBufferSource.h> 45d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/IOmxObserver.h> 46d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/hardware/media/omx/1.0/IGraphicBufferSource.h> 47d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 48d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/IGraphicBufferSource.h> 49d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#include <android/IOMXBufferSource.h> 50d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 51d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace android { 52d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace hardware { 53d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace media { 54d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace omx { 55d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace V1_0 { 56d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasanamespace utils { 57d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 58d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::hidl_array; 59d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::hidl_string; 60d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::hidl_vec; 61d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::hidl_handle; 62d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::Return; 63d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::Void; 64d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::sp; 65d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 66d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::String8; 67d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::OMXFenceParcelable; 68d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 69d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::Message; 70d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::omx_message; 71d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 72d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::ColorAspects; 73d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::V1_0::Rect; 74d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::V1_0::Region; 75d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 76d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::graphics::common::V1_0::Dataspace; 77d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 78d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::graphics::common::V1_0::PixelFormat; 79d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 80d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::OMXBuffer; 81d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 82d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::V1_0::AnwBuffer; 83d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::GraphicBuffer; 84d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 85d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::IOmx; 86d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::IOMX; 87d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 88d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::IOmxNode; 89d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::IOMXNode; 90d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 91d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::IOmxObserver; 92d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::IOMXObserver; 93d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 94d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::hardware::media::omx::V1_0::IOmxBufferSource; 95d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasausing ::android::IOMXBufferSource; 96d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 97d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// native_handle_t helper functions. 98d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 99d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 100d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Take an fd and create a native handle containing only the given fd. 101d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * The created handle will need to be deleted manually with 102d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `native_handle_delete()`. 103d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 104d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] fd The source file descriptor (of type `int`). 105d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The create `native_handle_t*` that contains the given \p fd. If the 106d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * supplied \p fd is negative, the created native handle will contain no file 107d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * descriptors. 108d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 109d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * If the native handle cannot be created, the return value will be 110d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `nullptr`. 111d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 112d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * This function does not duplicate the file descriptor. 113d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 114d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline native_handle_t* native_handle_create_from_fd(int fd) { 115d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (fd < 0) { 116d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return native_handle_create(0, 0); 117d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 118d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa native_handle_t* nh = native_handle_create(1, 0); 119d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (nh == nullptr) { 120d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return nullptr; 121d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 122d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa nh->data[0] = fd; 123d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return nh; 124d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 125d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 126d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 127d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Extract a file descriptor from a native handle. 128d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 129d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] nh The source `native_handle_t*`. 130d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] index The index of the file descriptor in \p nh to read from. This 131d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * input has the default value of `0`. 132d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The `index`-th file descriptor in \p nh. If \p nh does not have 133d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * enough file descriptors, the returned value will be `-1`. 134d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 135d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * This function does not duplicate the file descriptor. 136d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 137d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline int native_handle_read_fd(native_handle_t const* nh, int index = 0) { 138d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return ((nh == nullptr) || (nh->numFds == 0) || 139d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa (nh->numFds <= index) || (index < 0)) ? 140d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa -1 : nh->data[index]; 141d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 142d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 143d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 144d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Conversion functions 145d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * ==================== 146d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 147d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * There are two main directions of conversion: 148d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * - `inTargetType(...)`: Create a wrapper whose lifetime depends on the 149d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * input. The wrapper has type `TargetType`. 150d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * - `toTargetType(...)`: Create a standalone object of type `TargetType` that 151d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * corresponds to the input. The lifetime of the output does not depend on the 152d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * lifetime of the input. 153d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * - `wrapIn(TargetType*, ...)`: Same as `inTargetType()`, but for `TargetType` 154d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * that cannot be copied and/or moved efficiently, or when there are multiple 155d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * output arguments. 156d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * - `convertTo(TargetType*, ...)`: Same as `toTargetType()`, but for 157d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `TargetType` that cannot be copied and/or moved efficiently, or when there 158d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * are multiple output arguments. 159d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 160d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `wrapIn()` and `convertTo()` functions will take output arguments before 161d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * input arguments. Some of these functions might return a value to indicate 162d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * success or error. 163d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 164d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * In converting or wrapping something as a Treble type that contains a 165d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `hidl_handle`, `native_handle_t*` will need to be created and returned as 166d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * an additional output argument, hence only `wrapIn()` or `convertTo()` would 167d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * be available. The caller must call `native_handle_delete()` to deallocate the 168d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * returned native handle when it is no longer needed. 169d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 170d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * For types that contain file descriptors, `inTargetType()` and `wrapAs()` do 171d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * not perform duplication of file descriptors, while `toTargetType()` and 172d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `convertTo()` do. 173d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 174d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 175d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 176d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `Return<void>` to `binder::Status`. 177d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 178d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Return<void>`. 179d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `binder::Status`. 180d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 181d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Return<void> -> ::android::binder::Status 182d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline ::android::binder::Status toBinderStatus( 183d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa Return<void> const& t) { 184d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return ::android::binder::Status::fromExceptionCode( 185d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.isOk() ? OK : UNKNOWN_ERROR, 186d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.description().c_str()); 187d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 188d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 189d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 190d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `Return<Status>` to `binder::Status`. 191d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 192d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Return<Status>`. 193d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `binder::Status`. 194d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 195d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Return<Status> -> ::android::binder::Status 196d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline ::android::binder::Status toBinderStatus( 197d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa Return<Status> const& t) { 198d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return ::android::binder::Status::fromStatusT( 199d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.isOk() ? static_cast<status_t>(static_cast<Status>(t)) : UNKNOWN_ERROR); 200d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 201d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 202d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 203d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `Return<void>` to `status_t`. This is for legacy binder calls. 204d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 205d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Return<void>`. 206d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `status_t`. 207d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 208d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Return<void> -> status_t 209d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline status_t toStatusT(Return<void> const& t) { 210d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return t.isOk() ? OK : UNKNOWN_ERROR; 211d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 212d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 213d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 214d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `Status` to `status_t`. This is for legacy binder calls. 215d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 216d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Status`. 217d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return the corresponding `status_t`. 218d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 219d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Status -> status_t 220d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline status_t toStatusT(Status const& t) { 2214c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa switch (t) { 2224c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::NO_ERROR: 2234c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::NAME_NOT_FOUND: 2244c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::WOULD_BLOCK: 2254c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::NO_MEMORY: 2264c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::ALREADY_EXISTS: 2274c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::NO_INIT: 2284c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::BAD_VALUE: 2294c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::DEAD_OBJECT: 2304c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::INVALID_OPERATION: 2314c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::TIMED_OUT: 2324c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::ERROR_UNSUPPORTED: 2334c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::UNKNOWN_ERROR: 2344c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::RELEASE_ALL_BUFFERS: 2354c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return static_cast<status_t>(t); 2364c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case Status::BUFFER_NEEDS_REALLOCATION: 2374c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return NOT_ENOUGH_DATA; 2384c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa default: 2394c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa ALOGW("Unrecognized status value: %" PRId32, static_cast<int32_t>(t)); 2404c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return static_cast<status_t>(t); 2414c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa } 2424c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa} 2434c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa 2444c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa/** 2454c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * \brief Convert `Return<Status>` to `status_t`. This is for legacy binder 2464c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * calls. 2474c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * 2484c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * \param[in] t The source `Return<Status>`. 2494c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * \return The corresponding `status_t`. 2504c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * 2514c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * This function first check if \p t has a transport error. If it does, then the 2524c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * return value is the transport error code. Otherwise, the return value is 2534c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * converted from `Status` contained inside \p t. 2544c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * 2554c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * Note: 2564c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * - This `Status` is omx-specific. It is defined in `types.hal`. 2574c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa * - The name of this function is not `convert`. 2584c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa */ 2594c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa// convert: Status -> status_t 2604c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasainline status_t toStatusT(Return<Status> const& t) { 2614c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return t.isOk() ? toStatusT(static_cast<Status>(t)) : UNKNOWN_ERROR; 262d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 263d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 264d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 265d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `status_t` to `Status`. 266d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 267d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `status_t`. 268d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `Status`. 269d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 270d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: status_t -> Status 271d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline Status toStatus(status_t l) { 2724c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa switch (l) { 2734c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case NO_ERROR: 2744c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case NAME_NOT_FOUND: 2754c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case WOULD_BLOCK: 2764c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case NO_MEMORY: 2774c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case ALREADY_EXISTS: 2784c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case NO_INIT: 2794c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case BAD_VALUE: 2804c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case DEAD_OBJECT: 2814c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case INVALID_OPERATION: 2824c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case TIMED_OUT: 2834c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case ERROR_UNSUPPORTED: 2844c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case UNKNOWN_ERROR: 2854c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case IGraphicBufferProducer::RELEASE_ALL_BUFFERS: 2864c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION: 2874c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return static_cast<Status>(l); 2884c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa case NOT_ENOUGH_DATA: 2894c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return Status::BUFFER_NEEDS_REALLOCATION; 2904c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa default: 2914c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa ALOGW("Unrecognized status value: %" PRId32, static_cast<int32_t>(l)); 2924c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa return static_cast<Status>(l); 2934c7a5b9d96c16e31a233549ff2d2ddb92d58540cPawin Vongmasa } 294d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 295d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 296d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 297d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap `native_handle_t*` in `hidl_handle`. 298d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 299d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] nh The source `native_handle_t*`. 300d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The `hidl_handle` that points to \p nh. 301d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 302d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: native_handle_t* -> hidl_handle 303d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline hidl_handle inHidlHandle(native_handle_t const* nh) { 304d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return hidl_handle(nh); 305d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 306d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 307d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 308d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap an `omx_message` and construct the corresponding `Message`. 309d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 310d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] t The wrapper of type `Message`. 311d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] nh The native_handle_t referred to by `t->fence`. 312d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `omx_message`. 313d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if the wrapping is successful; `false` otherwise. 314d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 315d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Upon success, \p nh will be created to hold the file descriptor stored in 316d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `l.fenceFd`, and `t->fence` will point to \p nh. \p nh will need to be 317d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * destroyed manually by `native_handle_delete()` when \p t is no longer needed. 318d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 319d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * Upon failure, \p nh will not be created and will not need to be deleted. \p t 320d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * will be invalid. 321d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 322d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap, omx_message -> Message, native_handle_t* 323d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool wrapAs(Message* t, native_handle_t** nh, omx_message const& l) { 324d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *nh = native_handle_create_from_fd(l.fenceFd); 325d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (!*nh) { 326d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 327d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 328d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->fence = *nh; 329d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa switch (l.type) { 330d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case omx_message::EVENT: 331d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = Message::Type::EVENT; 332d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.eventData.event = uint32_t(l.u.event_data.event); 333d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.eventData.data1 = l.u.event_data.data1; 334d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.eventData.data2 = l.u.event_data.data2; 335d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.eventData.data3 = l.u.event_data.data3; 336d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.eventData.data4 = l.u.event_data.data4; 337d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 338d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case omx_message::EMPTY_BUFFER_DONE: 339d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = Message::Type::EMPTY_BUFFER_DONE; 340d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.bufferData.buffer = l.u.buffer_data.buffer; 341d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 342d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case omx_message::FILL_BUFFER_DONE: 343d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = Message::Type::FILL_BUFFER_DONE; 344d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.extendedBufferData.buffer = l.u.extended_buffer_data.buffer; 345d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.extendedBufferData.rangeOffset = 346d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l.u.extended_buffer_data.range_offset; 347d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.extendedBufferData.rangeLength = 348d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l.u.extended_buffer_data.range_length; 349d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.extendedBufferData.flags = l.u.extended_buffer_data.flags; 350d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.extendedBufferData.timestampUs = 351d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l.u.extended_buffer_data.timestamp; 352d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 353d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case omx_message::FRAME_RENDERED: 354d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = Message::Type::FRAME_RENDERED; 355d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.renderData.timestampUs = l.u.render_data.timestamp; 356d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->data.renderData.systemTimeNs = l.u.render_data.nanoTime; 357d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 358d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa default: 359d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa native_handle_delete(*nh); 360d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 361d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 362d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 363d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 364d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 365d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 366d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap a `Message` inside an `omx_message`. 367d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 368d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The wrapper of type `omx_message`. 369d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Message`. 370d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if the wrapping is successful; `false` otherwise. 371d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 372d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: Message -> omx_message 373d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool wrapAs(omx_message* l, Message const& t) { 374d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->fenceFd = native_handle_read_fd(t.fence); 375d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa switch (t.type) { 376d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case Message::Type::EVENT: 377d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->type = omx_message::EVENT; 378d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.event_data.event = OMX_EVENTTYPE(t.data.eventData.event); 379d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.event_data.data1 = t.data.eventData.data1; 380d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.event_data.data2 = t.data.eventData.data2; 381d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.event_data.data3 = t.data.eventData.data3; 382d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.event_data.data4 = t.data.eventData.data4; 383d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 384d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case Message::Type::EMPTY_BUFFER_DONE: 385d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->type = omx_message::EMPTY_BUFFER_DONE; 386d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.buffer_data.buffer = t.data.bufferData.buffer; 387d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 388d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case Message::Type::FILL_BUFFER_DONE: 389d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->type = omx_message::FILL_BUFFER_DONE; 390d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.extended_buffer_data.buffer = t.data.extendedBufferData.buffer; 391d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.extended_buffer_data.range_offset = 392d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.data.extendedBufferData.rangeOffset; 393d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.extended_buffer_data.range_length = 394d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.data.extendedBufferData.rangeLength; 395d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.extended_buffer_data.flags = t.data.extendedBufferData.flags; 396d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.extended_buffer_data.timestamp = 397d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.data.extendedBufferData.timestampUs; 398d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 399d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case Message::Type::FRAME_RENDERED: 400d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->type = omx_message::FRAME_RENDERED; 401d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.render_data.timestamp = t.data.renderData.timestampUs; 402d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->u.render_data.nanoTime = t.data.renderData.systemTimeNs; 403d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa break; 404d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa default: 405d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 406d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 407d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 408d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 409d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 410d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 411d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Similar to `wrapTo(omx_message*, Message const&)`, but the output will 412d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * have an extended lifetime. 413d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 414d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The output `omx_message`. 415d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Message`. 416d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if the conversion is successful; `false` otherwise. 417d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 418d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * This function calls `wrapto()`, then attempts to duplicate the file 419d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * descriptor for the fence if it is not `-1`. If duplication fails, `false` 420d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * will be returned. 421d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 422d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Message -> omx_message 423d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(omx_message* l, Message const& t) { 424d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (!wrapAs(l, t)) { 425d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 426d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 427d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (l->fenceFd == -1) { 428d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 429d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 430d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->fenceFd = dup(l->fenceFd); 431d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return l->fenceFd != -1; 432d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 433d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 434d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 435d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap an `OMXFenceParcelable` inside a `hidl_handle`. 436d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 437d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] t The wrapper of type `hidl_handle`. 438d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] nh The native handle created to hold the file descriptor inside 439d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \p l. 440d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMXFenceParcelable`, which essentially contains one 441d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * file descriptor. 442d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if \p t and \p nh are successfully created to wrap around \p 443d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * l; `false` otherwise. 444d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 445d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * On success, \p nh needs to be deleted by the caller with 446d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `native_handle_delete()` after \p t and \p nh are no longer needed. 447d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 448d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * On failure, \p nh will not need to be deleted, and \p t will hold an invalid 449d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * value. 450d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 451d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: OMXFenceParcelable -> hidl_handle, native_handle_t* 452d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool wrapAs(hidl_handle* t, native_handle_t** nh, 453d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa OMXFenceParcelable const& l) { 454d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *nh = native_handle_create_from_fd(l.get()); 455d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (!*nh) { 456d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 457d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 458d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *t = *nh; 459d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 460d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 461d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 462d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 463d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap a `hidl_handle` inside an `OMXFenceParcelable`. 464d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 465d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The wrapper of type `OMXFenceParcelable`. 466d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `hidl_handle`. 467d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 468d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: hidl_handle -> OMXFenceParcelable 469d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline void wrapAs(OMXFenceParcelable* l, hidl_handle const& t) { 470d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->mFenceFd = native_handle_read_fd(t); 471d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 472d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 473d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 474d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert a `hidl_handle` to `OMXFenceParcelable`. If `hidl_handle` 475d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * contains file descriptors, the first file descriptor will be duplicated and 476d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * stored in the output `OMXFenceParcelable`. 477d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 478d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The output `OMXFenceParcelable`. 479d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The input `hidl_handle`. 480d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `false` if \p t contains a valid file descriptor but duplication 481d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * fails; `true` otherwise. 482d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 483d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: hidl_handle -> OMXFenceParcelable 484d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(OMXFenceParcelable* l, hidl_handle const& t) { 485d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa int fd = native_handle_read_fd(t); 486d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (fd != -1) { 487d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa fd = dup(fd); 488d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (fd == -1) { 489d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 490d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 491d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 492d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->mFenceFd = fd; 493d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 494d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 495d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 496d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 497d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `::android::ColorAspects` to `ColorAspects`. 498d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 499d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `::android::ColorAspects`. 500d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `ColorAspects`. 501d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 502d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: ::android::ColorAspects -> ColorAspects 503d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline ColorAspects toHardwareColorAspects(::android::ColorAspects const& l) { 504d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return ColorAspects{ 505d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Range>(l.mRange), 506d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Primaries>(l.mPrimaries), 507d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Transfer>(l.mTransfer), 508d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::MatrixCoeffs>(l.mMatrixCoeffs)}; 509d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 510d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 511d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 512d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `int32_t` to `ColorAspects`. 513d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 514d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `int32_t`. 515d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `ColorAspects`. 516d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 517d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: int32_t -> ColorAspects 518d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline ColorAspects toHardwareColorAspects(int32_t l) { 519d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return ColorAspects{ 520d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Range>((l >> 24) & 0xFF), 521d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Primaries>((l >> 16) & 0xFF), 522d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::Transfer>(l & 0xFF), 523d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<ColorAspects::MatrixCoeffs>((l >> 8) & 0xFF)}; 524d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 525d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 526d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 527d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `ColorAspects` to `::android::ColorAspects`. 528d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 529d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `ColorAspects`. 530d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding `::android::ColorAspects`. 531d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 532d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: ColorAspects -> ::android::ColorAspects 533d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline int32_t toCompactColorAspects(ColorAspects const& t) { 534d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<int32_t>( 535d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa (static_cast<uint32_t>(t.range) << 24) | 536d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa (static_cast<uint32_t>(t.primaries) << 16) | 537d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa (static_cast<uint32_t>(t.transfer)) | 538d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa (static_cast<uint32_t>(t.matrixCoeffs) << 8)); 539d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 540d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 541d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 542d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `int32_t` to `Dataspace`. 543d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 544d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `int32_t`. 545d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \result The corresponding `Dataspace`. 546d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 547d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: int32_t -> Dataspace 548d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline Dataspace toHardwareDataspace(int32_t l) { 549d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<Dataspace>(l); 550d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 551d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 552d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 553d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `Dataspace` to `int32_t`. 554d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 555d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `Dataspace`. 556d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \result The corresponding `int32_t`. 557d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 558d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: Dataspace -> int32_t 559d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline int32_t toRawDataspace(Dataspace const& t) { 560d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<int32_t>(t); 561d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 562d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 563d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 564d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap an opaque buffer inside a `hidl_vec<uint8_t>`. 565d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 566d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The pointer to the beginning of the opaque buffer. 567d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] size The size of the buffer. 568d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return A `hidl_vec<uint8_t>` that points to the buffer. 569d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 570d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: void*, size_t -> hidl_vec<uint8_t> 571d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline hidl_vec<uint8_t> inHidlBytes(void const* l, size_t size) { 572d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa hidl_vec<uint8_t> t; 573d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.setToExternal(static_cast<uint8_t*>(const_cast<void*>(l)), size, false); 574d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return t; 575d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 576d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 577d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 578d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Create a `hidl_vec<uint8_t>` that is a copy of an opaque buffer. 579d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 580d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The pointer to the beginning of the opaque buffer. 581d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] size The size of the buffer. 582d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return A `hidl_vec<uint8_t>` that is a copy of the input buffer. 583d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 584d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: void*, size_t -> hidl_vec<uint8_t> 585d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline hidl_vec<uint8_t> toHidlBytes(void const* l, size_t size) { 586d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa hidl_vec<uint8_t> t; 587d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.resize(size); 588d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa uint8_t const* src = static_cast<uint8_t const*>(l); 589d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa std::copy(src, src + size, t.data()); 590d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return t; 591d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 592d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 593d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 594d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap `GraphicBuffer` in `AnwBuffer`. 595d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 596d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] t The wrapper of type `AnwBuffer`. 597d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `GraphicBuffer`. 598d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 599d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: GraphicBuffer -> AnwBuffer 600d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline void wrapAs(AnwBuffer* t, GraphicBuffer const& l) { 601d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.width = l.getWidth(); 602d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.height = l.getHeight(); 603d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.stride = l.getStride(); 604d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.format = static_cast<PixelFormat>(l.getPixelFormat()); 605d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.layerCount = l.getLayerCount(); 606d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.usage = l.getUsage(); 607d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.id = l.getId(); 608d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.generationNumber = l.getGenerationNumber(); 609d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->nativeHandle = hidl_handle(l.handle); 610d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 611d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 612d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 613d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `AnwBuffer` to `GraphicBuffer`. 614d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 615d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The destination `GraphicBuffer`. 616d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `AnwBuffer`. 617d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 618d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * This function will duplicate all file descriptors in \p t. 619d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 620d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: AnwBuffer -> GraphicBuffer 621d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// Ref: frameworks/native/libs/ui/GraphicBuffer.cpp: GraphicBuffer::flatten 622d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(GraphicBuffer* l, AnwBuffer const& t) { 623d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa native_handle_t* handle = t.nativeHandle == nullptr ? 624d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa nullptr : native_handle_clone(t.nativeHandle); 625d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 626d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa size_t const numInts = 12 + (handle ? handle->numInts : 0); 627d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa int32_t* ints = new int32_t[numInts]; 628d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 629d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa size_t numFds = static_cast<size_t>(handle ? handle->numFds : 0); 630d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa int* fds = new int[numFds]; 631d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 632d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[0] = 'GBFR'; 633d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[1] = static_cast<int32_t>(t.attr.width); 634d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[2] = static_cast<int32_t>(t.attr.height); 635d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[3] = static_cast<int32_t>(t.attr.stride); 636d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[4] = static_cast<int32_t>(t.attr.format); 637d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[5] = static_cast<int32_t>(t.attr.layerCount); 638d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[6] = static_cast<int32_t>(t.attr.usage); 639d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[7] = static_cast<int32_t>(t.attr.id >> 32); 640d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[8] = static_cast<int32_t>(t.attr.id & 0xFFFFFFFF); 641d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[9] = static_cast<int32_t>(t.attr.generationNumber); 642d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[10] = 0; 643d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[11] = 0; 644d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (handle) { 645d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[10] = static_cast<int32_t>(handle->numFds); 646d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa ints[11] = static_cast<int32_t>(handle->numInts); 647d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa int* intsStart = handle->data + handle->numFds; 648d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa std::copy(handle->data, intsStart, fds); 649d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa std::copy(intsStart, intsStart + handle->numInts, &ints[12]); 650d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 651d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 652d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa void const* constBuffer = static_cast<void const*>(ints); 653d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa size_t size = numInts * sizeof(int32_t); 654d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa int const* constFds = static_cast<int const*>(fds); 655d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa status_t status = l->unflatten(constBuffer, size, constFds, numFds); 656d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 657d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa delete [] fds; 658d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa delete [] ints; 659d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa native_handle_delete(handle); 660d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return status == NO_ERROR; 661d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 662d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 663d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 664d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Wrap `OMXBuffer` in `CodecBuffer`. 665d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 666d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] t The wrapper of type `CodecBuffer`. 667d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMXBuffer`. 668d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if the wrapping is successful; `false` otherwise. 669d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 670d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// wrap: OMXBuffer -> CodecBuffer 671d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool wrapAs(CodecBuffer* t, OMXBuffer const& l) { 672d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->sharedMemory = hidl_memory(); 673d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->nativeHandle = hidl_handle(); 674d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa switch (l.mBufferType) { 675d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypeInvalid: { 676d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = CodecBuffer::Type::INVALID; 677d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 678d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 679d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypePreset: { 680d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = CodecBuffer::Type::PRESET; 681d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.preset.rangeLength = static_cast<uint32_t>(l.mRangeLength); 682d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.preset.rangeOffset = static_cast<uint32_t>(l.mRangeOffset); 683d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 684d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 685d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypeHidlMemory: { 686d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = CodecBuffer::Type::SHARED_MEM; 687d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->sharedMemory = l.mHidlMemory; 688d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 689d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 690d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypeSharedMem: { 691d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa // This is not supported. 692d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 693d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 694d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypeANWBuffer: { 695d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = CodecBuffer::Type::ANW_BUFFER; 696d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (l.mGraphicBuffer == nullptr) { 697d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.width = 0; 698d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.height = 0; 699d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.stride = 0; 700d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.format = static_cast<PixelFormat>(1); 701d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.layerCount = 0; 702d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.usage = 0; 703d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 704d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 705d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.width = l.mGraphicBuffer->getWidth(); 706d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.height = l.mGraphicBuffer->getHeight(); 707d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.stride = l.mGraphicBuffer->getStride(); 708d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.format = static_cast<PixelFormat>( 709d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l.mGraphicBuffer->getPixelFormat()); 710d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.layerCount = l.mGraphicBuffer->getLayerCount(); 711d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->attr.anwBuffer.usage = l.mGraphicBuffer->getUsage(); 712d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->nativeHandle = l.mGraphicBuffer->handle; 713d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 714d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 715d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case OMXBuffer::kBufferTypeNativeHandle: { 716d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->type = CodecBuffer::Type::NATIVE_HANDLE; 717d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->nativeHandle = l.mNativeHandle->handle(); 718d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 719d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 720d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 721d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 722d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 723d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 724d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 725d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `CodecBuffer` to `OMXBuffer`. 726d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 727d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The destination `OMXBuffer`. 728d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `CodecBuffer`. 729d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return `true` if successful; `false` otherwise. 730d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 731d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: CodecBuffer -> OMXBuffer 732d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(OMXBuffer* l, CodecBuffer const& t) { 733d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa switch (t.type) { 734d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case CodecBuffer::Type::INVALID: { 735d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer(); 736d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 737d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 738d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case CodecBuffer::Type::PRESET: { 739d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer( 740d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.attr.preset.rangeOffset, 741d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t.attr.preset.rangeLength); 742d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 743d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 744d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case CodecBuffer::Type::SHARED_MEM: { 745d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer(t.sharedMemory); 746d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 747d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 748d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case CodecBuffer::Type::ANW_BUFFER: { 749d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (t.nativeHandle.getNativeHandle() == nullptr) { 750d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer(sp<GraphicBuffer>(nullptr)); 751d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 752d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 753d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa AnwBuffer anwBuffer; 754d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa anwBuffer.nativeHandle = t.nativeHandle; 755d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa anwBuffer.attr = t.attr.anwBuffer; 756d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(); 757d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa if (!convertTo(graphicBuffer.get(), anwBuffer)) { 758d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 759d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 760d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer(graphicBuffer); 761d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 762d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 763d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa case CodecBuffer::Type::NATIVE_HANDLE: { 764d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa *l = OMXBuffer(NativeHandle::create( 765d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa native_handle_clone(t.nativeHandle), true)); 766d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 767d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 768d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 769d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return false; 770d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 771d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 772d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 773d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `IOMX::ComponentInfo` to `IOmx::ComponentInfo`. 774d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 775d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] t The destination `IOmx::ComponentInfo`. 776d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `IOMX::ComponentInfo`. 777d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 778d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: IOMX::ComponentInfo -> IOmx::ComponentInfo 779d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(IOmx::ComponentInfo* t, IOMX::ComponentInfo const& l) { 780d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->mName = l.mName.string(); 781d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->mRoles.resize(l.mRoles.size()); 782d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa size_t i = 0; 783d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa for (auto& role : l.mRoles) { 784d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa t->mRoles[i++] = role.string(); 785d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 786d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 787d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 788d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 789d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 790d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `IOmx::ComponentInfo` to `IOMX::ComponentInfo`. 791d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 792d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[out] l The destination `IOMX::ComponentInfo`. 793d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `IOmx::ComponentInfo`. 794d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 795d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: IOmx::ComponentInfo -> IOMX::ComponentInfo 796d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool convertTo(IOMX::ComponentInfo* l, IOmx::ComponentInfo const& t) { 797d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->mName = t.mName.c_str(); 798d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->mRoles.clear(); 799d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa for (size_t i = 0; i < t.mRoles.size(); ++i) { 800d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa l->mRoles.push_back(String8(t.mRoles[i].c_str())); 801d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa } 802d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return true; 803d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 804d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 805d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 806d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `OMX_BOOL` to `bool`. 807d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 808d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMX_BOOL`. 809d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `bool`. 810d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 811d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: OMX_BOOL -> bool 812d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline bool toRawBool(OMX_BOOL l) { 813d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return l == OMX_FALSE ? false : true; 814d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 815d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 816d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 817d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `bool` to `OMX_BOOL`. 818d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 819d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `bool`. 820d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `OMX_BOOL`. 821d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 822d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: bool -> OMX_BOOL 823d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline OMX_BOOL toEnumBool(bool t) { 824d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return t ? OMX_TRUE : OMX_FALSE; 825d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 826d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 827d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 828d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `OMX_COMMANDTYPE` to `uint32_t`. 829d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 830d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMX_COMMANDTYPE`. 831d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The underlying value of type `uint32_t`. 832d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 833d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `OMX_COMMANDTYPE` is an enum type whose underlying type is `uint32_t`. 834d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 835d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: OMX_COMMANDTYPE -> uint32_t 836d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline uint32_t toRawCommandType(OMX_COMMANDTYPE l) { 837d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<uint32_t>(l); 838d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 839d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 840d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 841d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `uint32_t` to `OMX_COMMANDTYPE`. 842d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 843d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `uint32_t`. 844d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding enum value of type `OMX_COMMANDTYPE`. 845d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 846d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `OMX_COMMANDTYPE` is an enum type whose underlying type is `uint32_t`. 847d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 848d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: uint32_t -> OMX_COMMANDTYPE 849d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline OMX_COMMANDTYPE toEnumCommandType(uint32_t t) { 850d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<OMX_COMMANDTYPE>(t); 851d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 852d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 853d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 854d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `OMX_INDEXTYPE` to `uint32_t`. 855d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 856d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMX_INDEXTYPE`. 857d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The underlying value of type `uint32_t`. 858d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 859d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `OMX_INDEXTYPE` is an enum type whose underlying type is `uint32_t`. 860d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 861d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: OMX_INDEXTYPE -> uint32_t 862d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline uint32_t toRawIndexType(OMX_INDEXTYPE l) { 863d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<uint32_t>(l); 864d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 865d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 866d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 867d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `uint32_t` to `OMX_INDEXTYPE`. 868d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 869d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `uint32_t`. 870d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The corresponding enum value of type `OMX_INDEXTYPE`. 871d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 872d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * `OMX_INDEXTYPE` is an enum type whose underlying type is `uint32_t`. 873d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 874d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: uint32_t -> OMX_INDEXTYPE 875d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline OMX_INDEXTYPE toEnumIndexType(uint32_t t) { 876d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<OMX_INDEXTYPE>(t); 877d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 878d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 879d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 880d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `IOMX::PortMode` to `PortMode`. 881d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 882d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `IOMX::PortMode`. 883d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `PortMode`. 884d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 885d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: IOMX::PortMode -> PortMode 886d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline PortMode toHardwarePortMode(IOMX::PortMode l) { 887d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<PortMode>(l); 888d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 889d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 890d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 891d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `PortMode` to `IOMX::PortMode`. 892d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 893d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] t The source `PortMode`. 894d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `IOMX::PortMode`. 895d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 896d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: PortMode -> IOMX::PortMode 897d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline IOMX::PortMode toIOMXPortMode(PortMode t) { 898d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<IOMX::PortMode>(t); 899d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 900d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 901d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 902d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `OMX_TICKS` to `uint64_t`. 903d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 904d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `OMX_TICKS`. 905d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `uint64_t`. 906d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 907d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: OMX_TICKS -> uint64_t 908d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline uint64_t toRawTicks(OMX_TICKS l) { 909d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#ifndef OMX_SKIP64BIT 910d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<uint64_t>(l); 911d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#else 912d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<uint64_t>(l.nLowPart) | 913d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<uint64_t>(l.nHighPart << 32); 914d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#endif 915d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 916d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 917d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa/** 918d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \brief Convert `uint64_t` to `OMX_TICKS`. 919d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * 920d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \param[in] l The source `uint64_t`. 921d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa * \return The destination `OMX_TICKS`. 922d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa */ 923d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa// convert: uint64_t -> OMX_TICKS 924d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasainline OMX_TICKS toOMXTicks(uint64_t t) { 925d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#ifndef OMX_SKIP64BIT 926d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return static_cast<OMX_TICKS>(t); 927d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#else 928d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa return OMX_TICKS{ 929d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<uint32_t>(t & 0xFFFFFFFF), 930d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa static_cast<uint32_t>(t >> 32)}; 931d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#endif 932d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} 933d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 934d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace utils 935d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace V1_0 936d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace omx 937d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace media 938d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace hardware 939d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa} // namespace android 940d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa 941d2075e8b86dbf6d7c6af7de6f2f698b1acf4c6dfPawin Vongmasa#endif // ANDROID_HARDWARE_MEDIA_OMX_V1_0__CONVERSION_H 942