From b4bec47dfc3623935aca176af24e690b3aa88145 Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Wed, 21 Feb 2018 10:39:07 -0800 Subject: [PATCH] Codec2: separate platform dependency - Move C2* objects out of android namespace - keep some stubs in place to not break dependencies - Separate usage flags from gralloc usage flags - Remove some unused classes Bug: 64121714 Test: Build Change-Id: Ibd0a5c2b4c3835a46aaa9c75c467bc728c2d85eb --- .../codec2/1.0/InputSurfaceConnection.cpp | 1 - media/libstagefright/codec2/C2.cpp | 3 - media/libstagefright/codec2/include/C2.h | 113 ++++++------------ .../libstagefright/codec2/include/C2Buffer.h | 55 ++------- .../codec2/include/C2BufferBase.h | 94 +++++++++++++++ .../codec2/include/C2Component.h | 11 +- .../libstagefright/codec2/include/C2Config.h | 4 - media/libstagefright/codec2/include/C2Param.h | 21 +--- .../codec2/include/C2ParamDef.h | 4 - media/libstagefright/codec2/include/C2Work.h | 7 +- .../codec2/include/android-C2Buffer.h | 65 ++++++++++ .../codec2/1.0/InputSurfaceConnection.h | 3 - .../codec2/tests/C2Param_test.cpp | 7 -- .../codec2/vndk/C2AllocatorGralloc.cpp | 30 +++++ .../codec2/vndk/C2AllocatorIon.cpp | 5 +- media/libstagefright/codec2/vndk/C2Buffer.cpp | 30 +++-- media/libstagefright/codec2/vndk/C2Store.cpp | 8 +- .../codec2/vndk/include/C2BufferPriv.h | 4 - .../codec2/vndk/include/C2ComponentFactory.h | 15 +-- .../codec2/vndk/include/C2ErrnoUtils.h | 4 - .../codec2/vndk/include/C2PlatformSupport.h | 1 + .../codec2/vndk/include/util/C2ParamUtils.h | 7 +- .../codec2/vndk/internal/C2BlockInternal.h | 4 - .../codec2/vndk/internal/C2ParamInternal.h | 3 - media/libstagefright/codecs/cmds/codec2.cpp | 5 - 25 files changed, 276 insertions(+), 228 deletions(-) create mode 100644 media/libstagefright/codec2/include/C2BufferBase.h create mode 100644 media/libstagefright/codec2/include/android-C2Buffer.h diff --git a/media/libstagefright/codec2/1.0/InputSurfaceConnection.cpp b/media/libstagefright/codec2/1.0/InputSurfaceConnection.cpp index 32d640408b..08b5d656ff 100644 --- a/media/libstagefright/codec2/1.0/InputSurfaceConnection.cpp +++ b/media/libstagefright/codec2/1.0/InputSurfaceConnection.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include diff --git a/media/libstagefright/codec2/C2.cpp b/media/libstagefright/codec2/C2.cpp index a51b073762..359d4e53ca 100644 --- a/media/libstagefright/codec2/C2.cpp +++ b/media/libstagefright/codec2/C2.cpp @@ -22,8 +22,6 @@ #include #include -namespace android { - /** * There is nothing here yet. This library is built to see what symbols and methods get * defined as part of the API include files. @@ -32,5 +30,4 @@ namespace android { * Codec2 clients. */ -} // namespace android diff --git a/media/libstagefright/codec2/include/C2.h b/media/libstagefright/codec2/include/C2.h index 00e39248c7..508f9ae0cc 100644 --- a/media/libstagefright/codec2/include/C2.h +++ b/media/libstagefright/codec2/include/C2.h @@ -17,40 +17,18 @@ #ifndef C2_H_ #define C2_H_ -#include -#include -#include - -#ifdef __ANDROID__ - -#include // for status_t -#include // for nsecs_t - -namespace android { - -#else - #include -typedef int64_t nsecs_t; - -enum { - GRALLOC_USAGE_SW_READ_OFTEN, - GRALLOC_USAGE_RENDERSCRIPT, - GRALLOC_USAGE_HW_TEXTURE, - GRALLOC_USAGE_HW_COMPOSER, - GRALLOC_USAGE_HW_VIDEO_ENCODER, - GRALLOC_USAGE_PROTECTED, - GRALLOC_USAGE_SW_WRITE_OFTEN, - GRALLOC_USAGE_HW_RENDER, -}; -#endif +#include + +/** nanoseconds with arbitrary origin. */ +typedef int64_t c2_nsecs_t; /** \mainpage Codec2 * - * Codec2 is a frame-based data processing API used by android. + * Codec2 is a generic frame-based data processing API. * - * The framework accesses components via the \ref API. + * The media subsystem accesses components via the \ref API. */ /** \ingroup API @@ -109,53 +87,35 @@ typedef const char *C2StringLiteral; * c2_status_t: status codes used. */ enum c2_status_t : int32_t { - /* - * Use android status constants if available. Otherwise, define the android status constants as - * additional enum values using POSIX errno constants. + * Use POSIX errno constants. */ -#ifndef __ANDROID__ - ALREADY_EXISTS = -EEXIST, - BAD_VALUE = -EINVAL, - BAD_INDEX = -EOVERFLOW, - FAILED_TRANSACTION = -ENOTSUP, - INVALID_OPERATION = -ENOSYS, - NAME_NOT_FOUND = -ENOENT, - NO_MEMORY = -ENOMEM, - NO_INIT = -ENODEV, - OK = 0, - PERMISSION_DENIED = -EPERM, - TIMED_OUT = -ETIMEDOUT, - UNKNOWN_ERROR = -EFAULT, - UNKNOWN_TRANSACTION = -EBADMSG, - WOULD_BLOCK = -EWOULDBLOCK, -#endif - - C2_OK = OK, ///< operation completed successfully + C2_OK = 0, ///< operation completed successfully // bad input - C2_BAD_VALUE = BAD_VALUE, ///< argument has invalid value (user error) - C2_BAD_INDEX = BAD_INDEX, ///< argument uses invalid index (user error) - C2_CANNOT_DO = FAILED_TRANSACTION, ///< argument/index is valid but not possible + C2_BAD_VALUE = EINVAL, ///< argument has invalid value (user error) + C2_BAD_INDEX = ENXIO, ///< argument uses invalid index (user error) + C2_CANNOT_DO = ENOTSUP, ///< argument/index is valid but not possible // bad sequencing of events - C2_DUPLICATE = ALREADY_EXISTS, ///< object already exists - C2_NOT_FOUND = NAME_NOT_FOUND, ///< object not found - C2_BAD_STATE = INVALID_OPERATION, ///< operation is not permitted in the current state - C2_BLOCKING = WOULD_BLOCK, ///< operation would block but blocking is not permitted + C2_DUPLICATE = EEXIST, ///< object already exists + C2_NOT_FOUND = ENOENT, ///< object not found + C2_BAD_STATE = EPERM, ///< operation is not permitted in the current state + C2_BLOCKING = EWOULDBLOCK, ///< operation would block but blocking is not permitted + C2_CANCELED = EINTR, ///< operation interrupted/canceled // bad environment - C2_NO_MEMORY = NO_MEMORY, ///< not enough memory to complete operation - C2_REFUSED = PERMISSION_DENIED, ///< missing permission to complete operation + C2_NO_MEMORY = ENOMEM, ///< not enough memory to complete operation + C2_REFUSED = EACCES, ///< missing permission to complete operation - C2_TIMED_OUT = TIMED_OUT, ///< operation did not complete within timeout + C2_TIMED_OUT = ETIMEDOUT, ///< operation did not complete within timeout // bad versioning - C2_OMITTED = UNKNOWN_TRANSACTION, ///< operation is not implemented/supported (optional only) + C2_OMITTED = ENOSYS, ///< operation is not implemented/supported (optional only) // unknown fatal - C2_CORRUPTED = UNKNOWN_ERROR, ///< some unexpected error prevented the operation - C2_NO_INIT = NO_INIT, ///< status has not been initialized + C2_CORRUPTED = EFAULT, ///< some unexpected error prevented the operation + C2_NO_INIT = ENODEV, ///< status has not been initialized }; /** @@ -185,11 +145,12 @@ enum c2_blocking_t : int32_t { type args& operator=(const type args&) = delete; \ type(const type args&) = delete; \ -#define C2_PURE __attribute__((pure)) -#define C2_CONST __attribute__((const)) -#define C2_HIDE __attribute__((visibility("hidden"))) -#define C2_INTERNAL __attribute__((internal_linkage)) #define C2_ALLOW_OVERFLOW __attribute__((no_sanitize("integer"))) +#define C2_CONST __attribute__((const)) +#define C2_HIDE __attribute__((visibility("hidden"))) +#define C2_INTERNAL __attribute__((internal_linkage)) +#define C2_PACK __attribute__((packed)) +#define C2_PURE __attribute__((pure)) #define DEFINE_OTHER_COMPARISON_OPERATORS(type) \ inline bool operator!=(const type &other) const { return !(*this == other); } \ @@ -548,32 +509,28 @@ inline constexpr typename c2_types::wide_type c2_clamp(const T a, const U /// @} -#ifdef __ANDROID__ -} // namespace android -#endif - #include template -struct std::less<::android::c2_cntr_t> { - constexpr bool operator()(const ::android::c2_cntr_t &lh, const ::android::c2_cntr_t &rh) const { +struct std::less<::c2_cntr_t> { + constexpr bool operator()(const ::c2_cntr_t &lh, const ::c2_cntr_t &rh) const { return lh.peeku() < rh.peeku(); } }; template -struct std::less_equal<::android::c2_cntr_t> { - constexpr bool operator()(const ::android::c2_cntr_t &lh, const ::android::c2_cntr_t &rh) const { +struct std::less_equal<::c2_cntr_t> { + constexpr bool operator()(const ::c2_cntr_t &lh, const ::c2_cntr_t &rh) const { return lh.peeku() <= rh.peeku(); } }; template -struct std::greater<::android::c2_cntr_t> { - constexpr bool operator()(const ::android::c2_cntr_t &lh, const ::android::c2_cntr_t &rh) const { +struct std::greater<::c2_cntr_t> { + constexpr bool operator()(const ::c2_cntr_t &lh, const ::c2_cntr_t &rh) const { return lh.peeku() > rh.peeku(); } }; template -struct std::greater_equal<::android::c2_cntr_t> { - constexpr bool operator()(const ::android::c2_cntr_t &lh, const ::android::c2_cntr_t &rh) const { +struct std::greater_equal<::c2_cntr_t> { + constexpr bool operator()(const ::c2_cntr_t &lh, const ::c2_cntr_t &rh) const { return lh.peeku() >= rh.peeku(); } }; diff --git a/media/libstagefright/codec2/include/C2Buffer.h b/media/libstagefright/codec2/include/C2Buffer.h index 034075fce1..e49f82be3e 100644 --- a/media/libstagefright/codec2/include/C2Buffer.h +++ b/media/libstagefright/codec2/include/C2Buffer.h @@ -18,27 +18,20 @@ #define C2BUFFER_H_ #include +#include #include // for C2Info -#include #include +#include #ifdef __ANDROID__ - -// #include -#include -#include // TODO: remove - -typedef native_handle_t C2Handle; - +#include #else typedef void* C2Handle; #endif -namespace android { - /// \defgroup buffer Buffers /// @{ @@ -89,7 +82,7 @@ public: * \retval C2_REFUSED no permission to wait for the fence (unexpected - system) * \retval C2_CORRUPTED some unknown error prevented waiting for the fence (unexpected) */ - c2_status_t wait(nsecs_t timeoutNs); + c2_status_t wait(c2_nsecs_t timeoutNs); /** * Used to check if this fence is valid (if there is a chance for it to be signaled.) @@ -550,41 +543,9 @@ public: ALLOCATIONS **************************************************************************************************/ -/// \defgroup allocator Allocation and memory placement +/// \ingroup allocator Allocation and memory placement /// @{ -/** - * Buffer/memory usage bits. These are used by the allocators to select optimal memory type/pool and - * buffer layout. - * - * \note This struct has public fields without getters/setters. All methods are inline. - */ -struct C2MemoryUsage { -// public: - // TODO: match these to gralloc1.h - enum Consumer : uint64_t { - // \todo do we need to distinguish often from rarely? - CPU_READ = GRALLOC_USAGE_SW_READ_OFTEN, - RENDERSCRIPT_READ = GRALLOC_USAGE_RENDERSCRIPT, - HW_TEXTURE_READ = GRALLOC_USAGE_HW_TEXTURE, - HW_COMPOSER_READ = GRALLOC_USAGE_HW_COMPOSER, - HW_CODEC_READ = GRALLOC_USAGE_HW_VIDEO_ENCODER, - READ_PROTECTED = GRALLOC_USAGE_PROTECTED, - }; - - enum Producer : uint64_t { - CPU_WRITE = GRALLOC_USAGE_SW_WRITE_OFTEN, - RENDERSCRIPT_WRITE = GRALLOC_USAGE_RENDERSCRIPT, - HW_TEXTURE_WRITE = GRALLOC_USAGE_HW_RENDER, - HW_COMPOSER_WRITE = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER, - HW_CODEC_WRITE = GRALLOC_USAGE_HW_VIDEO_ENCODER, - WRITE_PROTECTED = GRALLOC_USAGE_PROTECTED, - }; - - uint64_t consumer; // e.g. input - uint64_t producer; // e.g. output -}; - class C2LinearAllocation; class C2GraphicAllocation; @@ -2301,6 +2262,10 @@ protected: /// @} -} // namespace android +// expose some objects in android namespace +namespace android { + /// \deprecated + typedef ::C2Fence C2Fence; +} #endif // C2BUFFER_H_ diff --git a/media/libstagefright/codec2/include/C2BufferBase.h b/media/libstagefright/codec2/include/C2BufferBase.h new file mode 100644 index 0000000000..68411f2466 --- /dev/null +++ b/media/libstagefright/codec2/include/C2BufferBase.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C2BUFFER_BASE_H_ +#define C2BUFFER_BASE_H_ + +/// \defgroup allocator Allocation and memory placement +/// @{ + +/** + * Buffer/memory usage bits. These shall be used by the allocators to select optimal memory type/ + * pool and buffer layout. Usage bits are conceptually separated into read and write usage, while + * the buffer use life-cycle is separated into producers (writers) and consumers (readers). + * These two concepts are related but not equivalent: consumers may only read buffers and only + * producers may write to buffers; note, however, that buffer producers may also want or need to + * read the buffers. + * + * Read and write buffer usage bits shall be or-ed to arrive at the full buffer usage. Admittedly, + * this does not account for the amount of reading and writing (e.g. a buffer may have one or more + * readers); however, the proper information necessary to properly weigh the various usages would be + * the amount of data read/written for each usage type. This would result in an integer array of + * size 64 (or the number of distinct usages) for memory usage, and likely such detailed information + * would not always be available. + * + * That platform-agnostic Codec 2.0 API only defines the bare minimum usages. Platforms shall define + * usage bits that are appropriate for the platform. + */ +struct C2MemoryUsage { +// public: + /** + * Buffer read usage. + */ + enum Read : uint64_t { + /** Buffer is read by the CPU. */ + CPU_READ = 1 << 0, + /** + * Buffer shall only be read by trusted hardware. The definition of trusted hardware is + * platform specific, but this flag is reserved to prevent mapping this block into CPU + * readable memory resulting in bus fault. This flag can be used when buffer access must be + * protected. + */ + READ_PROTECTED = 1 << 1, + }; + + /** + * Buffer write usage. + */ + enum Write : uint64_t { + /** Buffer is writted to by the CPU. */ + CPU_WRITE = 1 << 2, + /** + * Buffer shall only be written to by trusted hardware. The definition of trusted hardware + * is platform specific, but this flag is reserved to prevent mapping this block into CPU + * writable memory resulting in bus fault. This flag can be used when buffer integrity must + * be protected. + */ + WRITE_PROTECTED = 1 << 3, + }; + + enum : uint64_t { + /** + * Buffer usage bits reserved for the platform. We don't separately reserve read and + * write usages as platforms may have asymmetric distribution between them. + */ + PLATFORM_MASK = ~(CPU_READ | CPU_WRITE | READ_PROTECTED | WRITE_PROTECTED), + }; + + /** Create a usage from separate consumer and producer usage mask. \deprecated */ + inline C2MemoryUsage(uint64_t consumer, uint64_t producer) + : expected(consumer | producer) { } + + inline explicit C2MemoryUsage(uint64_t expected_) + : expected(expected_) { } + + uint64_t expected; // expected buffer usage +}; + +/// @} + +#endif // C2BUFFER_BASE_H_ + diff --git a/media/libstagefright/codec2/include/C2Component.h b/media/libstagefright/codec2/include/C2Component.h index 721966bf67..64bd1cb57b 100644 --- a/media/libstagefright/codec2/include/C2Component.h +++ b/media/libstagefright/codec2/include/C2Component.h @@ -29,13 +29,9 @@ #include #include -namespace android { - /// \defgroup components Components /// @{ -class C2Component; - struct C2FieldSupportedValuesQuery { enum type_t : uint32_t { POSSIBLE, ///< query all possible values regardless of other settings @@ -947,6 +943,11 @@ public: /// @} -} // namespace android +namespace android { + /// \deprecated + typedef ::C2Component C2Component; + /// \deprecated + typedef ::C2ComponentInterface C2ComponentInterface; +} #endif // C2COMPONENT_H_ diff --git a/media/libstagefright/codec2/include/C2Config.h b/media/libstagefright/codec2/include/C2Config.h index 2a2b9dec62..3f149bbff6 100644 --- a/media/libstagefright/codec2/include/C2Config.h +++ b/media/libstagefright/codec2/include/C2Config.h @@ -19,8 +19,6 @@ #include -namespace android { - /// \defgroup config Component configuration /// @{ @@ -262,6 +260,4 @@ typedef C2StreamParam C /// @} -} // namespace android - #endif diff --git a/media/libstagefright/codec2/include/C2Param.h b/media/libstagefright/codec2/include/C2Param.h index 4d9f707752..181697db64 100644 --- a/media/libstagefright/codec2/include/C2Param.h +++ b/media/libstagefright/codec2/include/C2Param.h @@ -23,13 +23,10 @@ #include #include -#include #include #include - -#define C2_PACK __attribute__((packed)) - -namespace android { +#include +#include /// \addtogroup Parameters /// @{ @@ -89,7 +86,6 @@ namespace android { */ /// \ingroup internal -struct _C2ParamManipulator; /** * Parameter base class. @@ -732,17 +728,6 @@ private: _C2FieldId _mFieldId; ///< field identifier }; -/** - * Structure uniquely specifying a field, an array element of a field, or a - * parameter in a configuration - */ -struct C2ParamOrField : public C2ParamField { -//public: - template - inline C2ParamOrField(S* param) - : C2ParamField(param->index(), 0u, param->size()) {} -}; - /** * A shared (union) representation of numeric values */ @@ -1376,6 +1361,4 @@ struct C2ParamFieldValues { /// @} -} // namespace android - #endif // C2PARAM_H_ diff --git a/media/libstagefright/codec2/include/C2ParamDef.h b/media/libstagefright/codec2/include/C2ParamDef.h index 3691e01bd3..f0b6223173 100644 --- a/media/libstagefright/codec2/include/C2ParamDef.h +++ b/media/libstagefright/codec2/include/C2ParamDef.h @@ -24,8 +24,6 @@ #include -namespace android { - /// \addtogroup Parameters /// @{ @@ -905,6 +903,4 @@ DESCRIBE_TEMPLATED_C2STRUCT(C2SimpleArrayStruct, { C2FIELD(values, "value /// @} -} // namespace android - #endif // C2PARAM_DEF_H_ diff --git a/media/libstagefright/codec2/include/C2Work.h b/media/libstagefright/codec2/include/C2Work.h index b6c58147dc..a2f02e59df 100644 --- a/media/libstagefright/codec2/include/C2Work.h +++ b/media/libstagefright/codec2/include/C2Work.h @@ -28,8 +28,6 @@ #include #include -namespace android { - /// \defgroup work Work and data processing /// @{ @@ -75,9 +73,8 @@ struct C2SettingResult { // WORK // ================================================================================================ -// c2_node_id_t-s +/** Unique ID for a processing node. */ typedef uint32_t c2_node_id_t; -typedef c2_node_id_t c2_node_id_t; enum { kParamIndexWorkOrdinal, @@ -211,6 +208,4 @@ struct C2WorkOutline { /// @} -} // namespace android - #endif // C2WORK_H_ diff --git a/media/libstagefright/codec2/include/android-C2Buffer.h b/media/libstagefright/codec2/include/android-C2Buffer.h new file mode 100644 index 0000000000..c71f2cf198 --- /dev/null +++ b/media/libstagefright/codec2/include/android-C2Buffer.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_C2BUFFER_H_ +#define ANDROID_C2BUFFER_H_ + +#include +#include + +/* Use android native handle for C2Handle */ +typedef ::native_handle_t C2Handle; + +namespace android { + +/** + * Android platform buffer/memory usage bits. + */ +struct C2AndroidMemoryUsage : public C2MemoryUsage { +// public: + /** + * Reuse gralloc flags where possible, as Codec 2.0 API only uses bits 0 and 1. + */ + enum Consumer : uint64_t { + RENDERSCRIPT_READ = GRALLOC_USAGE_RENDERSCRIPT, + HW_TEXTURE_READ = GRALLOC_USAGE_HW_TEXTURE, + HW_COMPOSER_READ = GRALLOC_USAGE_HW_COMPOSER, + HW_CODEC_READ = GRALLOC_USAGE_HW_VIDEO_ENCODER, + READ_PROTECTED = GRALLOC_USAGE_PROTECTED, + }; + + enum Producer : uint64_t { + RENDERSCRIPT_WRITE = GRALLOC_USAGE_RENDERSCRIPT, + HW_TEXTURE_WRITE = GRALLOC_USAGE_HW_RENDER, + HW_COMPOSER_WRITE = GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_RENDER, + HW_CODEC_WRITE = GRALLOC_USAGE_HW_VIDEO_ENCODER, + WRITE_PROTECTED = GRALLOC_USAGE_PROTECTED, + }; + + /** + * Convert from gralloc usage. + */ + static C2MemoryUsage FromGrallocUsage(uint64_t usage); + + /** + * Convert to gralloc usage. + */ + uint64_t asGrallocUsage() const; +}; + +} // namespace android + +#endif // ANDROID_C2BUFFER_H_ diff --git a/media/libstagefright/codec2/include/media/stagefright/codec2/1.0/InputSurfaceConnection.h b/media/libstagefright/codec2/include/media/stagefright/codec2/1.0/InputSurfaceConnection.h index fc19acdb2d..b24a41684f 100644 --- a/media/libstagefright/codec2/include/media/stagefright/codec2/1.0/InputSurfaceConnection.h +++ b/media/libstagefright/codec2/include/media/stagefright/codec2/1.0/InputSurfaceConnection.h @@ -25,9 +25,6 @@ #include namespace android { - -class C2Allocator; - namespace hardware { namespace media { namespace c2 { diff --git a/media/libstagefright/codec2/tests/C2Param_test.cpp b/media/libstagefright/codec2/tests/C2Param_test.cpp index 1a29add933..168b889ad9 100644 --- a/media/libstagefright/codec2/tests/C2Param_test.cpp +++ b/media/libstagefright/codec2/tests/C2Param_test.cpp @@ -23,8 +23,6 @@ #include #include -namespace android { - void PrintTo(const _C2FieldId &id, ::std::ostream* os) { *os << "@" << id._mOffset << "+" << id._mSize; } @@ -2397,15 +2395,11 @@ TEST_F(C2ParamTest, FlexParamOpsTest) { // *********************** -} - #include #include #include #include -namespace android { - C2ENUM( MetadataType, int32_t, kInvalid = -1, @@ -2935,4 +2929,3 @@ TEST_F(C2ParamTest, C2ValueTest) { EXPECT_EQ(15.25f, fp); } -} // namespace android diff --git a/media/libstagefright/codec2/vndk/C2AllocatorGralloc.cpp b/media/libstagefright/codec2/vndk/C2AllocatorGralloc.cpp index b287ca8b36..b255eec4d9 100644 --- a/media/libstagefright/codec2/vndk/C2AllocatorGralloc.cpp +++ b/media/libstagefright/codec2/vndk/C2AllocatorGralloc.cpp @@ -29,6 +29,36 @@ namespace android { +namespace { + enum : uint64_t { + /** + * Usage mask that is passed through from gralloc to Codec 2.0 usage. + */ + PASSTHROUGH_USAGE_MASK = + ~(GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_PROTECTED) + }; + + // verify that passthrough mask is within the platform mask + static_assert((~C2MemoryUsage::PLATFORM_MASK & PASSTHROUGH_USAGE_MASK) == 0, ""); +} + +C2MemoryUsage C2AndroidMemoryUsage::FromGrallocUsage(uint64_t usage) { + // gralloc does not support WRITE_PROTECTED + return C2MemoryUsage( + ((usage & GRALLOC_USAGE_SW_READ_MASK) ? C2MemoryUsage::CPU_READ : 0) | + ((usage & GRALLOC_USAGE_SW_WRITE_MASK) ? C2MemoryUsage::CPU_WRITE : 0) | + ((usage & GRALLOC_USAGE_PROTECTED) ? C2MemoryUsage::READ_PROTECTED : 0) | + (usage & PASSTHROUGH_USAGE_MASK)); +} + +uint64_t C2AndroidMemoryUsage::asGrallocUsage() const { + // gralloc does not support WRITE_PROTECTED + return (((expected & C2MemoryUsage::CPU_READ) ? GRALLOC_USAGE_SW_READ_MASK : 0) | + ((expected & C2MemoryUsage::CPU_WRITE) ? GRALLOC_USAGE_SW_WRITE_MASK : 0) | + ((expected & C2MemoryUsage::READ_PROTECTED) ? GRALLOC_USAGE_PROTECTED : 0) | + (expected & PASSTHROUGH_USAGE_MASK)); +} + using ::android::hardware::graphics::allocator::V2_0::IAllocator; using ::android::hardware::graphics::common::V1_0::BufferUsage; using ::android::hardware::graphics::common::V1_0::PixelFormat; diff --git a/media/libstagefright/codec2/vndk/C2AllocatorIon.cpp b/media/libstagefright/codec2/vndk/C2AllocatorIon.cpp index 4328a8d41e..a9613e4a17 100644 --- a/media/libstagefright/codec2/vndk/C2AllocatorIon.cpp +++ b/media/libstagefright/codec2/vndk/C2AllocatorIon.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -232,10 +233,10 @@ public: int prot = PROT_NONE; int flags = MAP_PRIVATE; - if (usage.consumer & C2MemoryUsage::CPU_READ) { + if (usage.expected & C2MemoryUsage::CPU_READ) { prot |= PROT_READ; } - if (usage.producer & C2MemoryUsage::CPU_WRITE) { + if (usage.expected & C2MemoryUsage::CPU_WRITE) { prot |= PROT_WRITE; flags = MAP_SHARED; } diff --git a/media/libstagefright/codec2/vndk/C2Buffer.cpp b/media/libstagefright/codec2/vndk/C2Buffer.cpp index 511ffe020f..47fdca1202 100644 --- a/media/libstagefright/codec2/vndk/C2Buffer.cpp +++ b/media/libstagefright/codec2/vndk/C2Buffer.cpp @@ -18,14 +18,13 @@ #define LOG_TAG "C2Buffer" #include +#include #include #include #include #include -namespace android { - namespace { // This anonymous namespace contains the helper classes that allow our implementation to create @@ -34,63 +33,63 @@ namespace { // Inherit from the parent, share with the friend. class ReadViewBuddy : public C2ReadView { using C2ReadView::C2ReadView; - friend class ::android::C2ConstLinearBlock; + friend class ::C2ConstLinearBlock; }; class WriteViewBuddy : public C2WriteView { using C2WriteView::C2WriteView; - friend class ::android::C2LinearBlock; + friend class ::C2LinearBlock; }; class ConstLinearBlockBuddy : public C2ConstLinearBlock { using C2ConstLinearBlock::C2ConstLinearBlock; - friend class ::android::C2LinearBlock; + friend class ::C2LinearBlock; }; class LinearBlockBuddy : public C2LinearBlock { using C2LinearBlock::C2LinearBlock; - friend class ::android::C2BasicLinearBlockPool; + friend class ::C2BasicLinearBlockPool; }; class AcquirableReadViewBuddy : public C2Acquirable { using C2Acquirable::C2Acquirable; - friend class ::android::C2ConstLinearBlock; + friend class ::C2ConstLinearBlock; }; class AcquirableWriteViewBuddy : public C2Acquirable { using C2Acquirable::C2Acquirable; - friend class ::android::C2LinearBlock; + friend class ::C2LinearBlock; }; class GraphicViewBuddy : public C2GraphicView { using C2GraphicView::C2GraphicView; - friend class ::android::C2ConstGraphicBlock; - friend class ::android::C2GraphicBlock; + friend class ::C2ConstGraphicBlock; + friend class ::C2GraphicBlock; }; class AcquirableConstGraphicViewBuddy : public C2Acquirable { using C2Acquirable::C2Acquirable; - friend class ::android::C2ConstGraphicBlock; + friend class ::C2ConstGraphicBlock; }; class AcquirableGraphicViewBuddy : public C2Acquirable { using C2Acquirable::C2Acquirable; - friend class ::android::C2GraphicBlock; + friend class ::C2GraphicBlock; }; class ConstGraphicBlockBuddy : public C2ConstGraphicBlock { using C2ConstGraphicBlock::C2ConstGraphicBlock; - friend class ::android::C2GraphicBlock; + friend class ::C2GraphicBlock; }; class GraphicBlockBuddy : public C2GraphicBlock { using C2GraphicBlock::C2GraphicBlock; - friend class ::android::C2BasicGraphicBlockPool; + friend class ::C2BasicGraphicBlockPool; }; class BufferDataBuddy : public C2BufferData { using C2BufferData::C2BufferData; - friend class ::android::C2Buffer; + friend class ::C2Buffer; }; } // namespace @@ -803,4 +802,3 @@ std::shared_ptr C2Buffer::CreateGraphicBuffer(const C2ConstGraphicBloc return std::shared_ptr(new C2Buffer({ block })); } -} // namespace android diff --git a/media/libstagefright/codec2/vndk/C2Store.cpp b/media/libstagefright/codec2/vndk/C2Store.cpp index 05b46c30b2..c4ed2f4682 100644 --- a/media/libstagefright/codec2/vndk/C2Store.cpp +++ b/media/libstagefright/codec2/vndk/C2Store.cpp @@ -136,13 +136,13 @@ c2_status_t GetCodec2BlockPool( switch (id) { case C2BlockPool::BASIC_LINEAR: res = allocatorStore->fetchAllocator(C2AllocatorStore::DEFAULT_LINEAR, &allocator); - if (res == OK) { + if (res == C2_OK) { *pool = std::make_shared(allocator); } break; case C2BlockPool::BASIC_GRAPHIC: res = allocatorStore->fetchAllocator(C2AllocatorStore::DEFAULT_GRAPHIC, &allocator); - if (res == OK) { + if (res == C2_OK) { *pool = std::make_shared(allocator); } break; @@ -345,7 +345,7 @@ C2PlatformComponentStore::ComponentModule::~ComponentModule() { c2_status_t C2PlatformComponentStore::ComponentModule::createInterface( c2_node_id_t id, std::shared_ptr *interface, - std::function deleter) { + std::function deleter) { interface->reset(); if (mInit != C2_OK) { return mInit; @@ -362,7 +362,7 @@ c2_status_t C2PlatformComponentStore::ComponentModule::createInterface( c2_status_t C2PlatformComponentStore::ComponentModule::createComponent( c2_node_id_t id, std::shared_ptr *component, - std::function deleter) { + std::function deleter) { component->reset(); if (mInit != C2_OK) { return mInit; diff --git a/media/libstagefright/codec2/vndk/include/C2BufferPriv.h b/media/libstagefright/codec2/vndk/include/C2BufferPriv.h index 875a8c23c0..977cf7bd23 100644 --- a/media/libstagefright/codec2/vndk/include/C2BufferPriv.h +++ b/media/libstagefright/codec2/vndk/include/C2BufferPriv.h @@ -21,8 +21,6 @@ #include -namespace android { - class C2BasicLinearBlockPool : public C2BlockPool { public: explicit C2BasicLinearBlockPool(const std::shared_ptr &allocator); @@ -73,6 +71,4 @@ private: const std::shared_ptr mAllocator; }; -} // namespace android - #endif // STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_ diff --git a/media/libstagefright/codec2/vndk/include/C2ComponentFactory.h b/media/libstagefright/codec2/vndk/include/C2ComponentFactory.h index cfea104152..7168498b77 100644 --- a/media/libstagefright/codec2/vndk/include/C2ComponentFactory.h +++ b/media/libstagefright/codec2/vndk/include/C2ComponentFactory.h @@ -22,8 +22,6 @@ #include #include -namespace android { - /** * Component factory object that enables to create a component and/or interface from a dynamically * linked library. This is needed because the component/interfaces are managed objects, but we @@ -36,8 +34,8 @@ namespace android { */ class C2ComponentFactory { public: - typedef std::function ComponentDeleter; - typedef std::function InterfaceDeleter; + typedef std::function ComponentDeleter; + typedef std::function InterfaceDeleter; /** * Creates a component. @@ -81,9 +79,12 @@ public: virtual ~C2ComponentFactory() = default; - typedef ::android::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); - typedef void (*DestroyCodec2FactoryFunc)(::android::C2ComponentFactory*); + typedef ::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); + typedef void (*DestroyCodec2FactoryFunc)(::C2ComponentFactory*); }; -} // namespace android + +namespace android { + typedef ::C2ComponentFactory C2ComponentFactory; +} #endif // STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ diff --git a/media/libstagefright/codec2/vndk/include/C2ErrnoUtils.h b/media/libstagefright/codec2/vndk/include/C2ErrnoUtils.h index 41132b983c..5b995f69e7 100644 --- a/media/libstagefright/codec2/vndk/include/C2ErrnoUtils.h +++ b/media/libstagefright/codec2/vndk/include/C2ErrnoUtils.h @@ -20,8 +20,6 @@ #include #include -namespace android { - // standard ERRNO mappings template constexpr c2_status_t _c2_errno2status_impl(); template<> constexpr c2_status_t _c2_errno2status_impl<0>() { return C2_OK; } @@ -52,7 +50,5 @@ c2_status_t c2_map_errno(int result) { return _c2_map_errno_impl::map(result); } -} // namespace android - #endif // STAGEFRIGHT_CODEC2_ERRNO_UTILS_H_ diff --git a/media/libstagefright/codec2/vndk/include/C2PlatformSupport.h b/media/libstagefright/codec2/vndk/include/C2PlatformSupport.h index 76b02ed091..afa51ee9b9 100644 --- a/media/libstagefright/codec2/vndk/include/C2PlatformSupport.h +++ b/media/libstagefright/codec2/vndk/include/C2PlatformSupport.h @@ -86,6 +86,7 @@ c2_status_t GetCodec2BlockPool( * \retval nullptr if the platform component store could not be obtained */ std::shared_ptr GetCodec2PlatformComponentStore(); + } // namespace android #endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_ diff --git a/media/libstagefright/codec2/vndk/include/util/C2ParamUtils.h b/media/libstagefright/codec2/vndk/include/util/C2ParamUtils.h index 3168248fac..1accc2c554 100644 --- a/media/libstagefright/codec2/vndk/include/util/C2ParamUtils.h +++ b/media/libstagefright/codec2/vndk/include/util/C2ParamUtils.h @@ -21,13 +21,14 @@ #include #include +#include +#include +#include /** \file * Utilities for parameter handling to be used by Codec2 implementations. */ -namespace android { - /// \cond INTERNAL /* ---------------------------- UTILITIES FOR ENUMERATION REFLECTION ---------------------------- */ @@ -313,7 +314,5 @@ std::list describeC2Params() { /* ---------------------------- UTILITIES FOR ENUMERATION REFLECTION ---------------------------- */ -} // namespace android - #endif // C2UTILS_PARAM_UTILS_H_ diff --git a/media/libstagefright/codec2/vndk/internal/C2BlockInternal.h b/media/libstagefright/codec2/vndk/internal/C2BlockInternal.h index 9c68369db7..25003cb85a 100644 --- a/media/libstagefright/codec2/vndk/internal/C2BlockInternal.h +++ b/media/libstagefright/codec2/vndk/internal/C2BlockInternal.h @@ -19,8 +19,6 @@ #include -namespace android { - struct _C2BlockPoolData; /** @@ -64,7 +62,5 @@ struct _C2BlockFactory { const C2Rect &allottedCrop = C2Rect(~0u, ~0u)); }; -} - #endif // ANDROID_STAGEFRIGHT_C2BLOCK_INTERNAL_H_ diff --git a/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h b/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h index 5bf3009e77..c805830f26 100644 --- a/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h +++ b/media/libstagefright/codec2/vndk/internal/C2ParamInternal.h @@ -19,8 +19,6 @@ #include -namespace android { - struct C2_HIDE _C2ParamInspector { inline static uint32_t getIndex(const C2ParamField &pf) { return pf._mIndex; @@ -44,7 +42,6 @@ struct C2_HIDE _C2ParamInspector { } }; -} #endif // ANDROID_STAGEFRIGHT_C2PARAM_INTERNAL_H_ diff --git a/media/libstagefright/codecs/cmds/codec2.cpp b/media/libstagefright/codecs/cmds/codec2.cpp index 8022b84ee1..95b0c61a02 100644 --- a/media/libstagefright/codecs/cmds/codec2.cpp +++ b/media/libstagefright/codecs/cmds/codec2.cpp @@ -59,11 +59,6 @@ #include #include -extern "C" ::android::C2ComponentFactory *CreateCodec2Factory(); -extern "C" void DestroyCodec2Factory(::android::C2ComponentFactory *); - -#include "../avcdec/C2SoftAvcDec.h" - using namespace android; using namespace std::chrono_literals;