From fd2e21c66a387fb8b9a8fe5a98161522eb173f29 Mon Sep 17 00:00:00 2001 From: Roman Kiryanov Date: Tue, 12 May 2020 11:26:22 -0700 Subject: (reland) Migrate codecs to .bp Bug: 338946090 Test: presubmit Change-Id: Iccc3a01b49dbfd23cfb7cba7e2dbd3e9c38558ef Signed-off-by: Roman Kiryanov --- Android.mk | 8 - system/codecs/Android.mk | 1 - system/codecs/omx/Android.mk | 16 -- system/codecs/omx/avcdec/Android.bp | 53 ++++++ system/codecs/omx/avcdec/Android.mk | 57 ------ system/codecs/omx/avcdec/GoldfishAVCDec.cpp | 3 +- system/codecs/omx/avcdec/GoldfishAVCDec.h | 184 ------------------- system/codecs/omx/avcdec/MediaH264Decoder.h | 97 ---------- system/codecs/omx/avcdec/include/GoldfishAVCDec.h | 184 +++++++++++++++++++ .../codecs/omx/avcdec/include/MediaH264Decoder.h | 97 ++++++++++ system/codecs/omx/common/Android.bp | 41 +++++ system/codecs/omx/common/Android.mk | 48 ----- system/codecs/omx/common/goldfish_media_utils.h | 100 ----------- .../omx/common/include/goldfish_media_utils.h | 100 +++++++++++ system/codecs/omx/plugin/Android.bp | 44 +++++ system/codecs/omx/plugin/Android.mk | 54 ------ system/codecs/omx/plugin/GoldfishOMXComponent.h | 189 -------------------- .../omx/plugin/GoldfishVideoDecoderOMXComponent.h | 197 --------------------- .../codecs/omx/plugin/SimpleGoldfishOMXComponent.h | 171 ------------------ .../omx/plugin/include/GoldfishOMXComponent.h | 189 ++++++++++++++++++++ .../include/GoldfishVideoDecoderOMXComponent.h | 197 +++++++++++++++++++++ .../plugin/include/SimpleGoldfishOMXComponent.h | 171 ++++++++++++++++++ system/codecs/omx/vpxdec/Android.bp | 52 ++++++ system/codecs/omx/vpxdec/Android.mk | 59 ------ system/codecs/omx/vpxdec/GoldfishVPX.cpp | 3 +- system/codecs/omx/vpxdec/GoldfishVPX.h | 111 ------------ system/codecs/omx/vpxdec/goldfish_vpx_defs.h | 65 ------- system/codecs/omx/vpxdec/include/GoldfishVPX.h | 111 ++++++++++++ .../codecs/omx/vpxdec/include/goldfish_vpx_defs.h | 65 +++++++ 29 files changed, 1306 insertions(+), 1361 deletions(-) delete mode 100644 system/codecs/Android.mk delete mode 100644 system/codecs/omx/Android.mk create mode 100644 system/codecs/omx/avcdec/Android.bp delete mode 100644 system/codecs/omx/avcdec/Android.mk delete mode 100644 system/codecs/omx/avcdec/GoldfishAVCDec.h delete mode 100644 system/codecs/omx/avcdec/MediaH264Decoder.h create mode 100644 system/codecs/omx/avcdec/include/GoldfishAVCDec.h create mode 100644 system/codecs/omx/avcdec/include/MediaH264Decoder.h create mode 100644 system/codecs/omx/common/Android.bp delete mode 100644 system/codecs/omx/common/Android.mk delete mode 100644 system/codecs/omx/common/goldfish_media_utils.h create mode 100644 system/codecs/omx/common/include/goldfish_media_utils.h create mode 100644 system/codecs/omx/plugin/Android.bp delete mode 100644 system/codecs/omx/plugin/Android.mk delete mode 100644 system/codecs/omx/plugin/GoldfishOMXComponent.h delete mode 100644 system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.h delete mode 100644 system/codecs/omx/plugin/SimpleGoldfishOMXComponent.h create mode 100644 system/codecs/omx/plugin/include/GoldfishOMXComponent.h create mode 100644 system/codecs/omx/plugin/include/GoldfishVideoDecoderOMXComponent.h create mode 100644 system/codecs/omx/plugin/include/SimpleGoldfishOMXComponent.h create mode 100644 system/codecs/omx/vpxdec/Android.bp delete mode 100644 system/codecs/omx/vpxdec/Android.mk delete mode 100644 system/codecs/omx/vpxdec/GoldfishVPX.h delete mode 100644 system/codecs/omx/vpxdec/goldfish_vpx_defs.h create mode 100644 system/codecs/omx/vpxdec/include/GoldfishVPX.h create mode 100644 system/codecs/omx/vpxdec/include/goldfish_vpx_defs.h diff --git a/Android.mk b/Android.mk index 6ab1d7d6..943da933 100644 --- a/Android.mk +++ b/Android.mk @@ -143,14 +143,6 @@ ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST)) include $(GOLDFISH_OPENGL_PATH)/system/hals/Android.mk endif -ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 28 -o $(IS_AT_LEAST_QPR1) = true && echo isApi29OrHigher),isApi29OrHigher) - # hardware codecs enabled after P - include $(GOLDFISH_OPENGL_PATH)/system/codecs/omx/common/Android.mk - include $(GOLDFISH_OPENGL_PATH)/system/codecs/omx/plugin/Android.mk - include $(GOLDFISH_OPENGL_PATH)/system/codecs/omx/avcdec/Android.mk - include $(GOLDFISH_OPENGL_PATH)/system/codecs/omx/vpxdec/Android.mk -endif - endif endif # ENABLE_GOLDFISH_OPENGL_FOLDER diff --git a/system/codecs/Android.mk b/system/codecs/Android.mk deleted file mode 100644 index 5053e7d6..00000000 --- a/system/codecs/Android.mk +++ /dev/null @@ -1 +0,0 @@ -include $(call all-subdir-makefiles) diff --git a/system/codecs/omx/Android.mk b/system/codecs/omx/Android.mk deleted file mode 100644 index c307f8eb..00000000 --- a/system/codecs/omx/Android.mk +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2018 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. -# -include $(call all-subdir-makefiles) diff --git a/system/codecs/omx/avcdec/Android.bp b/system/codecs/omx/avcdec/Android.bp new file mode 100644 index 00000000..2fc1c2f3 --- /dev/null +++ b/system/codecs/omx/avcdec/Android.bp @@ -0,0 +1,53 @@ +// +// Copyright 2019 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. +// + +cc_library_shared { + name: "libstagefright_goldfish_avcdec", + vendor: true, + srcs: [ + "GoldfishAVCDec.cpp", + "MediaH264Decoder.cpp", + ], + export_include_dirs: [ + "include", + ], + shared_libs: [ + "libstagefrighthw", + "android.hardware.media.omx@1.0", + "android.hardware.graphics.common@1.2", + "libstagefright_foundation", + "libbase", + "libbinder", + "libcutils", + "liblog", + "libui", + "libutils", + ], + static_libs: [ + "libgoldfish_codecs_common", + ], + header_libs: [ + "media_plugin_headers", + "libmedia_headers", + "libnativewindow_headers", + "libhardware_headers", + "libgralloc_cb.ranchu", + ], + cflags: [ + "-DLOG_TAG=\"goldfish_avcdec\"", + "-Wno-unused-private-field", + ], +} diff --git a/system/codecs/omx/avcdec/Android.mk b/system/codecs/omx/avcdec/Android.mk deleted file mode 100644 index 4ab6db3d..00000000 --- a/system/codecs/omx/avcdec/Android.mk +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright 2019 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. -# -LOCAL_PATH := $(call my-dir) - -commonSources := \ - GoldfishAVCDec.cpp \ - MediaH264Decoder.cpp - -$(call emugl-begin-shared-library,libstagefright_goldfish_avcdec$(GOLDFISH_OPENGL_LIB_SUFFIX)) - -LOCAL_SRC_FILES := $(commonSources) - -LOCAL_CFLAGS += -DLOG_TAG=\"goldfish_avcdec\" -LOCAL_CFLAGS += -Wno-unused-private-field - -$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog) - -LOCAL_HEADER_LIBRARIES := media_plugin_headers \ - libmedia_headers \ - libbinder_headers \ - libhidlbase_impl_internal \ - libbase -LOCAL_HEADER_LIBRARIES += libui_headers \ - libnativewindow_headers \ - libhardware_headers \ - libarect_headers \ - libarect_headers_for_ndk -LOCAL_SHARED_LIBRARIES := \ - libbinder \ - libutils \ - liblog \ - libcutils \ - libui \ - android.hardware.media.omx@1.0 \ - android.hardware.graphics.allocator@3.0 \ - android.hardware.graphics.mapper@3.0 \ - libstagefright_foundation - -LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu - -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) -$(call emugl-import,libgoldfish_codecs_common) -$(call emugl-import,libstagefrighthw) -$(call emugl-end-module) diff --git a/system/codecs/omx/avcdec/GoldfishAVCDec.cpp b/system/codecs/omx/avcdec/GoldfishAVCDec.cpp index 02c0dc16..a49d7e89 100644 --- a/system/codecs/omx/avcdec/GoldfishAVCDec.cpp +++ b/system/codecs/omx/avcdec/GoldfishAVCDec.cpp @@ -33,8 +33,7 @@ #include -#include -#include +#include #include using ::android::hardware::graphics::common::V1_2::PixelFormat; diff --git a/system/codecs/omx/avcdec/GoldfishAVCDec.h b/system/codecs/omx/avcdec/GoldfishAVCDec.h deleted file mode 100644 index 0fd52b0d..00000000 --- a/system/codecs/omx/avcdec/GoldfishAVCDec.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2015 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 GOLDFISH_H264_DEC_H_ - -#define GOLDFISH_H264_DEC_H_ - -#include "GoldfishVideoDecoderOMXComponent.h" -#include "MediaH264Decoder.h" -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -namespace android { - -/** Number of entries in the time-stamp array */ -#define MAX_TIME_STAMPS 64 - -/** Maximum number of cores supported by the codec */ -#define CODEC_MAX_NUM_CORES 4 - -#define CODEC_MAX_WIDTH 1920 - -#define CODEC_MAX_HEIGHT 1088 - -/** Input buffer size */ -#define INPUT_BUF_SIZE (1024 * 1024) - -#define MIN(a, b) ((a) < (b)) ? (a) : (b) - -/** Used to remove warnings about unused parameters */ -#define UNUSED(x) ((void)(x)) - -struct GoldfishAVCDec : public GoldfishVideoDecoderOMXComponent { - GoldfishAVCDec(const char *name, const OMX_CALLBACKTYPE *callbacks, - OMX_PTR appData, OMX_COMPONENTTYPE **component, RenderMode renderMode); - -protected: - virtual ~GoldfishAVCDec(); - - virtual void onQueueFilled(OMX_U32 portIndex); - virtual void onPortFlushCompleted(OMX_U32 portIndex); - virtual void onReset(); - virtual int getColorAspectPreference(); - - virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE getExtensionIndex(const char *name, OMX_INDEXTYPE *index); - -private: - // Number of input and output buffers - enum { - kNumBuffers = 8 - }; - - RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; - bool mEnableAndroidNativeBuffers = false; - std::map> mNWBuffers; - - int getHostColorBufferId(void* header); - - size_t mNumCores; // Number of cores to be uesd by the codec - - nsecs_t mTimeStart; // Time at the start of decode() - nsecs_t mTimeEnd; // Time at the end of decode() - -#ifdef FILE_DUMP_ENABLE - char mInFile[200]; -#endif /* FILE_DUMP_ENABLE */ - - OMX_COLOR_FORMATTYPE mOmxColorFormat; // OMX Color format - - bool mIsInFlush; // codec is flush mode - bool mReceivedEOS; // EOS is receieved on input port - - // The input stream has changed to a different resolution, which is still supported by the - // codec. So the codec is switching to decode the new resolution. - bool mChangingResolution; - bool mSignalledError; - size_t mInputOffset; - - status_t initDecoder(); - status_t deInitDecoder(); - status_t setFlushMode(); - status_t setParams(size_t stride); - void logVersion(); - status_t setNumCores(); - status_t resetDecoder(); - status_t resetPlugin(); - - - void readAndDiscardAllHostBuffers(); - - bool setDecodeArgs( - OMX_BUFFERHEADERTYPE *inHeader, - OMX_BUFFERHEADERTYPE *outHeader); - - bool getVUIParams(h264_image_t& img); - - void copyImageData( OMX_BUFFERHEADERTYPE *outHeader, h264_image_t & img); - - std::unique_ptr mContext; - std::vector mCsd0; - std::vector mCsd1; - uint64_t mConsumedBytes = 0; - uint8_t* mInPBuffer = nullptr; - uint8_t* mOutHeaderBuf = nullptr; - DISALLOW_EVIL_CONSTRUCTORS(GoldfishAVCDec); -}; -#ifdef FILE_DUMP_ENABLE - -#define INPUT_DUMP_PATH "/sdcard/media/avcd_input" -#define INPUT_DUMP_EXT "h264" - -#define GENERATE_FILE_NAMES() { \ - strcpy(mInFile, ""); \ - sprintf(mInFile, "%s_%lld.%s", INPUT_DUMP_PATH, \ - (long long) mTimeStart, \ - INPUT_DUMP_EXT); \ -} - -#define CREATE_DUMP_FILE(m_filename) { \ - FILE *fp = fopen(m_filename, "wb"); \ - if (fp != NULL) { \ - fclose(fp); \ - } else { \ - ALOGD("Could not open file %s", m_filename); \ - } \ -} -#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset)\ -{ \ - FILE *fp = fopen(m_filename, "ab"); \ - if (fp != NULL && m_buf != NULL && m_offset == 0) { \ - int i; \ - i = fwrite(m_buf, 1, m_size, fp); \ - ALOGD("fwrite ret %d to write %d", i, m_size); \ - if (i != (int) m_size) { \ - ALOGD("Error in fwrite, returned %d", i); \ - perror("Error in write to file"); \ - } \ - } else if (fp == NULL) { \ - ALOGD("Could not write to file %s", m_filename);\ - } \ - if (fp) { \ - fclose(fp); \ - } \ -} -#else /* FILE_DUMP_ENABLE */ -#define INPUT_DUMP_PATH -#define INPUT_DUMP_EXT -#define OUTPUT_DUMP_PATH -#define OUTPUT_DUMP_EXT -#define GENERATE_FILE_NAMES() -#define CREATE_DUMP_FILE(m_filename) -#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset) -#endif /* FILE_DUMP_ENABLE */ - -} // namespace android - -#endif // GOLDFISH_H264_DEC_H_ diff --git a/system/codecs/omx/avcdec/MediaH264Decoder.h b/system/codecs/omx/avcdec/MediaH264Decoder.h deleted file mode 100644 index a75758fa..00000000 --- a/system/codecs/omx/avcdec/MediaH264Decoder.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2015 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 GOLDFISH_MEDIA_H264_DEC_H_ -#define GOLDFISH_MEDIA_H264_DEC_H_ - -struct h264_init_result_t { - uint64_t host_handle; - int ret; -}; - -struct h264_result_t { - int ret; - uint64_t bytesProcessed; -}; - -struct h264_image_t { - const uint8_t* data; - uint32_t width; - uint32_t height; - uint64_t pts; // presentation time stamp - uint64_t color_primaries; - uint64_t color_range; - uint64_t color_trc; - uint64_t colorspace; - // on success, |ret| will indicate the size of |data|. - // If failed, |ret| will contain some negative error code. - int ret; -}; - -enum class RenderMode { - RENDER_BY_HOST_GPU = 1, - RENDER_BY_GUEST_CPU = 2, -}; - -class MediaH264Decoder { - uint64_t mHostHandle = 0; - uint32_t mVersion = 100; - RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; - - bool mHasAddressSpaceMemory = false; - uint64_t mAddressOffSet = 0; - int mSlot = -1; - -public: - MediaH264Decoder(RenderMode renderMode); - virtual ~MediaH264Decoder() = default; - - enum class PixelFormat : uint8_t { - YUV420P = 0, - UYVY422 = 1, - BGRA8888 = 2, - }; - - enum class Err : int { - NoErr = 0, - NoDecodedFrame = -1, - InitContextFailed = -2, - DecoderRestarted = -3, - NALUIgnored = -4, - }; - - bool getAddressSpaceMemory(); - void initH264Context(unsigned int width, - unsigned int height, - unsigned int outWidth, - unsigned int outHeight, - PixelFormat pixFmt); - void resetH264Context(unsigned int width, - unsigned int height, - unsigned int outWidth, - unsigned int outHeight, - PixelFormat pixFmt); - void destroyH264Context(); - h264_result_t decodeFrame(uint8_t* img, size_t szBytes, uint64_t pts); - void flush(); - // ask host to copy image data back to guest, with image metadata - // to guest as well - h264_image_t getImage(); - // ask host to render to hostColorBufferId, return only image metadata back to - // guest - h264_image_t renderOnHostAndReturnImageMetadata(int hostColorBufferId); -}; -#endif diff --git a/system/codecs/omx/avcdec/include/GoldfishAVCDec.h b/system/codecs/omx/avcdec/include/GoldfishAVCDec.h new file mode 100644 index 00000000..0fd52b0d --- /dev/null +++ b/system/codecs/omx/avcdec/include/GoldfishAVCDec.h @@ -0,0 +1,184 @@ +/* + * Copyright 2015 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 GOLDFISH_H264_DEC_H_ + +#define GOLDFISH_H264_DEC_H_ + +#include "GoldfishVideoDecoderOMXComponent.h" +#include "MediaH264Decoder.h" +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace android { + +/** Number of entries in the time-stamp array */ +#define MAX_TIME_STAMPS 64 + +/** Maximum number of cores supported by the codec */ +#define CODEC_MAX_NUM_CORES 4 + +#define CODEC_MAX_WIDTH 1920 + +#define CODEC_MAX_HEIGHT 1088 + +/** Input buffer size */ +#define INPUT_BUF_SIZE (1024 * 1024) + +#define MIN(a, b) ((a) < (b)) ? (a) : (b) + +/** Used to remove warnings about unused parameters */ +#define UNUSED(x) ((void)(x)) + +struct GoldfishAVCDec : public GoldfishVideoDecoderOMXComponent { + GoldfishAVCDec(const char *name, const OMX_CALLBACKTYPE *callbacks, + OMX_PTR appData, OMX_COMPONENTTYPE **component, RenderMode renderMode); + +protected: + virtual ~GoldfishAVCDec(); + + virtual void onQueueFilled(OMX_U32 portIndex); + virtual void onPortFlushCompleted(OMX_U32 portIndex); + virtual void onReset(); + virtual int getColorAspectPreference(); + + virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE getExtensionIndex(const char *name, OMX_INDEXTYPE *index); + +private: + // Number of input and output buffers + enum { + kNumBuffers = 8 + }; + + RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; + bool mEnableAndroidNativeBuffers = false; + std::map> mNWBuffers; + + int getHostColorBufferId(void* header); + + size_t mNumCores; // Number of cores to be uesd by the codec + + nsecs_t mTimeStart; // Time at the start of decode() + nsecs_t mTimeEnd; // Time at the end of decode() + +#ifdef FILE_DUMP_ENABLE + char mInFile[200]; +#endif /* FILE_DUMP_ENABLE */ + + OMX_COLOR_FORMATTYPE mOmxColorFormat; // OMX Color format + + bool mIsInFlush; // codec is flush mode + bool mReceivedEOS; // EOS is receieved on input port + + // The input stream has changed to a different resolution, which is still supported by the + // codec. So the codec is switching to decode the new resolution. + bool mChangingResolution; + bool mSignalledError; + size_t mInputOffset; + + status_t initDecoder(); + status_t deInitDecoder(); + status_t setFlushMode(); + status_t setParams(size_t stride); + void logVersion(); + status_t setNumCores(); + status_t resetDecoder(); + status_t resetPlugin(); + + + void readAndDiscardAllHostBuffers(); + + bool setDecodeArgs( + OMX_BUFFERHEADERTYPE *inHeader, + OMX_BUFFERHEADERTYPE *outHeader); + + bool getVUIParams(h264_image_t& img); + + void copyImageData( OMX_BUFFERHEADERTYPE *outHeader, h264_image_t & img); + + std::unique_ptr mContext; + std::vector mCsd0; + std::vector mCsd1; + uint64_t mConsumedBytes = 0; + uint8_t* mInPBuffer = nullptr; + uint8_t* mOutHeaderBuf = nullptr; + DISALLOW_EVIL_CONSTRUCTORS(GoldfishAVCDec); +}; +#ifdef FILE_DUMP_ENABLE + +#define INPUT_DUMP_PATH "/sdcard/media/avcd_input" +#define INPUT_DUMP_EXT "h264" + +#define GENERATE_FILE_NAMES() { \ + strcpy(mInFile, ""); \ + sprintf(mInFile, "%s_%lld.%s", INPUT_DUMP_PATH, \ + (long long) mTimeStart, \ + INPUT_DUMP_EXT); \ +} + +#define CREATE_DUMP_FILE(m_filename) { \ + FILE *fp = fopen(m_filename, "wb"); \ + if (fp != NULL) { \ + fclose(fp); \ + } else { \ + ALOGD("Could not open file %s", m_filename); \ + } \ +} +#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset)\ +{ \ + FILE *fp = fopen(m_filename, "ab"); \ + if (fp != NULL && m_buf != NULL && m_offset == 0) { \ + int i; \ + i = fwrite(m_buf, 1, m_size, fp); \ + ALOGD("fwrite ret %d to write %d", i, m_size); \ + if (i != (int) m_size) { \ + ALOGD("Error in fwrite, returned %d", i); \ + perror("Error in write to file"); \ + } \ + } else if (fp == NULL) { \ + ALOGD("Could not write to file %s", m_filename);\ + } \ + if (fp) { \ + fclose(fp); \ + } \ +} +#else /* FILE_DUMP_ENABLE */ +#define INPUT_DUMP_PATH +#define INPUT_DUMP_EXT +#define OUTPUT_DUMP_PATH +#define OUTPUT_DUMP_EXT +#define GENERATE_FILE_NAMES() +#define CREATE_DUMP_FILE(m_filename) +#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset) +#endif /* FILE_DUMP_ENABLE */ + +} // namespace android + +#endif // GOLDFISH_H264_DEC_H_ diff --git a/system/codecs/omx/avcdec/include/MediaH264Decoder.h b/system/codecs/omx/avcdec/include/MediaH264Decoder.h new file mode 100644 index 00000000..a75758fa --- /dev/null +++ b/system/codecs/omx/avcdec/include/MediaH264Decoder.h @@ -0,0 +1,97 @@ +/* + * Copyright 2015 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 GOLDFISH_MEDIA_H264_DEC_H_ +#define GOLDFISH_MEDIA_H264_DEC_H_ + +struct h264_init_result_t { + uint64_t host_handle; + int ret; +}; + +struct h264_result_t { + int ret; + uint64_t bytesProcessed; +}; + +struct h264_image_t { + const uint8_t* data; + uint32_t width; + uint32_t height; + uint64_t pts; // presentation time stamp + uint64_t color_primaries; + uint64_t color_range; + uint64_t color_trc; + uint64_t colorspace; + // on success, |ret| will indicate the size of |data|. + // If failed, |ret| will contain some negative error code. + int ret; +}; + +enum class RenderMode { + RENDER_BY_HOST_GPU = 1, + RENDER_BY_GUEST_CPU = 2, +}; + +class MediaH264Decoder { + uint64_t mHostHandle = 0; + uint32_t mVersion = 100; + RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; + + bool mHasAddressSpaceMemory = false; + uint64_t mAddressOffSet = 0; + int mSlot = -1; + +public: + MediaH264Decoder(RenderMode renderMode); + virtual ~MediaH264Decoder() = default; + + enum class PixelFormat : uint8_t { + YUV420P = 0, + UYVY422 = 1, + BGRA8888 = 2, + }; + + enum class Err : int { + NoErr = 0, + NoDecodedFrame = -1, + InitContextFailed = -2, + DecoderRestarted = -3, + NALUIgnored = -4, + }; + + bool getAddressSpaceMemory(); + void initH264Context(unsigned int width, + unsigned int height, + unsigned int outWidth, + unsigned int outHeight, + PixelFormat pixFmt); + void resetH264Context(unsigned int width, + unsigned int height, + unsigned int outWidth, + unsigned int outHeight, + PixelFormat pixFmt); + void destroyH264Context(); + h264_result_t decodeFrame(uint8_t* img, size_t szBytes, uint64_t pts); + void flush(); + // ask host to copy image data back to guest, with image metadata + // to guest as well + h264_image_t getImage(); + // ask host to render to hostColorBufferId, return only image metadata back to + // guest + h264_image_t renderOnHostAndReturnImageMetadata(int hostColorBufferId); +}; +#endif diff --git a/system/codecs/omx/common/Android.bp b/system/codecs/omx/common/Android.bp new file mode 100644 index 00000000..7a7f7270 --- /dev/null +++ b/system/codecs/omx/common/Android.bp @@ -0,0 +1,41 @@ +// +// Copyright 2020 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. +// + +cc_library_static { + name: "libgoldfish_codecs_common", + vendor: true, + srcs: [ + "goldfish_media_utils.cpp", + ], + shared_libs: [ + "libcutils", + "libutils", + "liblog", + ], + static_libs: [ + "libGoldfishAddressSpace", + ], + whole_static_libs: [ + "libGoldfishAddressSpace", + ], + export_include_dirs: [ + "include", + ], + cflags: [ + "-DLOG_TAG=\"goldfish_codecs_common\"", + "-Wno-unused-private-field", + ], +} diff --git a/system/codecs/omx/common/Android.mk b/system/codecs/omx/common/Android.mk deleted file mode 100644 index 6b1674c9..00000000 --- a/system/codecs/omx/common/Android.mk +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright 2019 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. -# -LOCAL_PATH := $(call my-dir) - -commonSources := \ - goldfish_media_utils.cpp - -$(call emugl-begin-shared-library,libgoldfish_codecs_common$(GOLDFISH_OPENGL_LIB_SUFFIX)) - -LOCAL_SRC_FILES := $(commonSources) - -LOCAL_CFLAGS += -DLOG_TAG=\"goldfish_codecs_common\" -LOCAL_CFLAGS += -Wno-unused-private-field - -$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog) - -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - -ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST)) -$(call emugl-import,libGoldfishAddressSpace$(GOLDFISH_OPENGL_LIB_SUFFIX)) -else -$(call emugl-export,STATIC_LIBRARIES,libplatform) -$(call emugl-export,STATIC_LIBRARIES,libGoldfishAddressSpace) - -ifeq (true,$(GFXSTREAM)) - -LOCAL_CFLAGS += -DVIRTIO_GPU -LOCAL_C_INCLUDES += external/libdrm external/minigbm/cros_gralloc -LOCAL_SHARED_LIBRARIES += libdrm - -endif - -endif - -$(call emugl-end-module) diff --git a/system/codecs/omx/common/goldfish_media_utils.h b/system/codecs/omx/common/goldfish_media_utils.h deleted file mode 100644 index d25ee301..00000000 --- a/system/codecs/omx/common/goldfish_media_utils.h +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2018 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. - -#include -#include - -#ifndef GOLDFISH_COMMON_GOLDFISH_DEFS_H -#define GOLDFISH_COMMON_GOLDFISH_DEFS_H - -enum class MediaCodecType : __u8 { - VP8Codec = 0, - VP9Codec = 1, - H264Codec = 2, - Max = 3, -}; - -enum class MediaOperation : __u8 { - InitContext = 0, - DestroyContext = 1, - DecodeImage = 2, - GetImage = 3, - Flush = 4, - Reset = 5, - Max = 6, -}; - -// This class will abstract away the knowledge required to send media codec data -// to the host. The implementation should only need the following information to -// properly send the data: -// 1) Which codec to use (MediaCodecType) -// 2) What operation to perform (MediaOperation) -// -// Example: -// auto transport = GoldfishMediaTransport::getInstance(); -// -class GoldfishMediaTransport { -protected: - GoldfishMediaTransport() {} - -public: - virtual ~GoldfishMediaTransport() {} - - // Writes a parameter to send to the host. Each parameter will take up - // 64-bits. |val| is the value of the parameter, and |num| is the parameter - // number, starting from 0. If |val| is an address, wrap it around - // offsetOf(), e.g., writeParam(offsetOf((uint64_t)ptr), 2); - virtual void writeParam(__u64 val, unsigned int num, unsigned int offSetToStartAddr = 0) = 0; - // Send the operation to perform to the host. At the time of this call, any - // parameters that the host needs should have already been passed using - // writeParam(). - virtual bool sendOperation(MediaCodecType codec, MediaOperation op, unsigned int offSetToStartAddr = 0) = 0; - // Get the address for input. This is usually given the the codec context to - // write data into for the host to process. - virtual uint8_t* getInputAddr(unsigned int offSet = 0) const = 0; - // Get the address for base pointer - virtual uint8_t* getBaseAddr() const = 0; - // Get the address for output. This is usually given to the codec context to - // read data written there by the host. - virtual uint8_t* getOutputAddr() const = 0; - // Get the address for return data from the host. The guest codec - // implementation will have knowledge of how the return data is laid out. - virtual uint8_t* getReturnAddr(unsigned int offSet = 0) const = 0; - // Get the offset of an address relative to the starting address of the - // allocated memory region. Use this for passing pointers from the guest to - // the host, as the guest address will be translated, thus the offset is the - // only value of significance. - virtual __u64 offsetOf(uint64_t addr) const = 0; - - // Get a slot of memory (8 M per slot) for use by a decoder instance. - // returns -1 for failure; or a slot >=0 on success. - // as of now, there are only 4 slots for use, each has 8 M, it is up - // to client on how to use it. - // 0th slot: [base, base+8M) - // ... - // ith slot: [base+8M*i, base+8M*(i+1)) - virtual int getMemorySlot() = 0; - - // Return a slot back to pool. the slot should be valid >=0 and less - // than the total size of slots. If nobody returns slot timely, the - // new client could get -1 from getMemorySlot() - virtual void returnMemorySlot(int slot) = 0; - - static GoldfishMediaTransport* getInstance(); -}; - -__u64 goldfish_create_media_metadata(MediaCodecType codecType, - __u64 metadata); - -#endif diff --git a/system/codecs/omx/common/include/goldfish_media_utils.h b/system/codecs/omx/common/include/goldfish_media_utils.h new file mode 100644 index 00000000..d25ee301 --- /dev/null +++ b/system/codecs/omx/common/include/goldfish_media_utils.h @@ -0,0 +1,100 @@ +// Copyright 2018 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. + +#include +#include + +#ifndef GOLDFISH_COMMON_GOLDFISH_DEFS_H +#define GOLDFISH_COMMON_GOLDFISH_DEFS_H + +enum class MediaCodecType : __u8 { + VP8Codec = 0, + VP9Codec = 1, + H264Codec = 2, + Max = 3, +}; + +enum class MediaOperation : __u8 { + InitContext = 0, + DestroyContext = 1, + DecodeImage = 2, + GetImage = 3, + Flush = 4, + Reset = 5, + Max = 6, +}; + +// This class will abstract away the knowledge required to send media codec data +// to the host. The implementation should only need the following information to +// properly send the data: +// 1) Which codec to use (MediaCodecType) +// 2) What operation to perform (MediaOperation) +// +// Example: +// auto transport = GoldfishMediaTransport::getInstance(); +// +class GoldfishMediaTransport { +protected: + GoldfishMediaTransport() {} + +public: + virtual ~GoldfishMediaTransport() {} + + // Writes a parameter to send to the host. Each parameter will take up + // 64-bits. |val| is the value of the parameter, and |num| is the parameter + // number, starting from 0. If |val| is an address, wrap it around + // offsetOf(), e.g., writeParam(offsetOf((uint64_t)ptr), 2); + virtual void writeParam(__u64 val, unsigned int num, unsigned int offSetToStartAddr = 0) = 0; + // Send the operation to perform to the host. At the time of this call, any + // parameters that the host needs should have already been passed using + // writeParam(). + virtual bool sendOperation(MediaCodecType codec, MediaOperation op, unsigned int offSetToStartAddr = 0) = 0; + // Get the address for input. This is usually given the the codec context to + // write data into for the host to process. + virtual uint8_t* getInputAddr(unsigned int offSet = 0) const = 0; + // Get the address for base pointer + virtual uint8_t* getBaseAddr() const = 0; + // Get the address for output. This is usually given to the codec context to + // read data written there by the host. + virtual uint8_t* getOutputAddr() const = 0; + // Get the address for return data from the host. The guest codec + // implementation will have knowledge of how the return data is laid out. + virtual uint8_t* getReturnAddr(unsigned int offSet = 0) const = 0; + // Get the offset of an address relative to the starting address of the + // allocated memory region. Use this for passing pointers from the guest to + // the host, as the guest address will be translated, thus the offset is the + // only value of significance. + virtual __u64 offsetOf(uint64_t addr) const = 0; + + // Get a slot of memory (8 M per slot) for use by a decoder instance. + // returns -1 for failure; or a slot >=0 on success. + // as of now, there are only 4 slots for use, each has 8 M, it is up + // to client on how to use it. + // 0th slot: [base, base+8M) + // ... + // ith slot: [base+8M*i, base+8M*(i+1)) + virtual int getMemorySlot() = 0; + + // Return a slot back to pool. the slot should be valid >=0 and less + // than the total size of slots. If nobody returns slot timely, the + // new client could get -1 from getMemorySlot() + virtual void returnMemorySlot(int slot) = 0; + + static GoldfishMediaTransport* getInstance(); +}; + +__u64 goldfish_create_media_metadata(MediaCodecType codecType, + __u64 metadata); + +#endif diff --git a/system/codecs/omx/plugin/Android.bp b/system/codecs/omx/plugin/Android.bp new file mode 100644 index 00000000..bd0bb18d --- /dev/null +++ b/system/codecs/omx/plugin/Android.bp @@ -0,0 +1,44 @@ +// +// Copyright 2018 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. +// + +cc_library_shared { + name: "libstagefrighthw", + vendor: true, + srcs: [ + "GoldfishOMXComponent.cpp", + "GoldfishOMXPlugin.cpp", + "GoldfishVideoDecoderOMXComponent.cpp", + "SimpleGoldfishOMXComponent.cpp", + ], + export_include_dirs: [ + "include", + ], + shared_libs: [ + "android.hardware.media.omx@1.0", + "libstagefright_foundation", + "libbase", + "libcutils", + "liblog", + "libutils", + ], + header_libs: [ + "libmedia_headers", + ], + cflags: [ + "-Wall", + "-Werror", + ], +} diff --git a/system/codecs/omx/plugin/Android.mk b/system/codecs/omx/plugin/Android.mk deleted file mode 100644 index 4adfd8a8..00000000 --- a/system/codecs/omx/plugin/Android.mk +++ /dev/null @@ -1,54 +0,0 @@ -# -# Copyright 2018 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. -# -LOCAL_PATH := $(call my-dir) - -commonSources := \ - GoldfishOMXComponent.cpp \ - GoldfishOMXPlugin.cpp \ - GoldfishVideoDecoderOMXComponent.cpp \ - SimpleGoldfishOMXComponent.cpp \ - -$(call emugl-begin-shared-library,libstagefrighthw$(GOLDFISH_OPENGL_LIB_SUFFIX)) - -LOCAL_SRC_FILES := $(commonSources) - -LOCAL_CFLAGS += $(PV_CFLAGS_MINUS_VISIBILITY) -Werror -LOCAL_CFLAGS += -Wno-unused-private-field - -LOCAL_C_INCLUDES += \ - $(call include-path-for, frameworks-native)/media/hardware \ - $(call include-path-for, frameworks-native)/media/openmax \ - -$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog) -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - -LOCAL_HEADER_LIBRARIES += media_plugin_headers \ - libmedia_headers \ - libbinder_headers \ - libhidlbase_impl_internal \ - libbase - -LOCAL_SHARED_LIBRARIES += \ - libbinder \ - libutils \ - liblog \ - libcutils \ - android.hardware.media.omx@1.0 \ - libstagefright_foundation - -LOCAL_VENDOR_MODULE := true - -$(call emugl-end-module) diff --git a/system/codecs/omx/plugin/GoldfishOMXComponent.h b/system/codecs/omx/plugin/GoldfishOMXComponent.h deleted file mode 100644 index 87a65ae3..00000000 --- a/system/codecs/omx/plugin/GoldfishOMXComponent.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2018 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 GOLDFISH_OMX_COMPONENT_H_ - -#define GOLDFISH_OMX_COMPONENT_H_ - -#include -#include -#include - -#include - -namespace android { - -struct GoldfishOMXComponent : public RefBase { - GoldfishOMXComponent( - const char *name, - const OMX_CALLBACKTYPE *callbacks, - OMX_PTR appData, - OMX_COMPONENTTYPE **component); - - virtual OMX_ERRORTYPE initCheck(); - - void setLibHandle(void *libHandle); - void *libHandle() const; - - virtual void prepareForDestruction(); - -protected: - virtual ~GoldfishOMXComponent(); - - const char *name() const; - - void notify( - OMX_EVENTTYPE event, - OMX_U32 data1, OMX_U32 data2, OMX_PTR data); - - void notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header); - void notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header); - - virtual OMX_ERRORTYPE sendCommand( - OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data); - - virtual OMX_ERRORTYPE getParameter( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE setParameter( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE getConfig( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE setConfig( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE getExtensionIndex( - const char *name, OMX_INDEXTYPE *index); - - virtual OMX_ERRORTYPE useBuffer( - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size, - OMX_U8 *ptr); - - virtual OMX_ERRORTYPE allocateBuffer( - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size); - - virtual OMX_ERRORTYPE freeBuffer( - OMX_U32 portIndex, - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE emptyThisBuffer( - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE fillThisBuffer( - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state); - -private: - AString mName; - const OMX_CALLBACKTYPE *mCallbacks; - OMX_COMPONENTTYPE *mComponent; - - void *mLibHandle; - - static OMX_ERRORTYPE SendCommandWrapper( - OMX_HANDLETYPE component, - OMX_COMMANDTYPE cmd, - OMX_U32 param, - OMX_PTR data); - - static OMX_ERRORTYPE GetParameterWrapper( - OMX_HANDLETYPE component, - OMX_INDEXTYPE index, - OMX_PTR params); - - static OMX_ERRORTYPE SetParameterWrapper( - OMX_HANDLETYPE component, - OMX_INDEXTYPE index, - OMX_PTR params); - - static OMX_ERRORTYPE GetConfigWrapper( - OMX_HANDLETYPE component, - OMX_INDEXTYPE index, - OMX_PTR params); - - static OMX_ERRORTYPE SetConfigWrapper( - OMX_HANDLETYPE component, - OMX_INDEXTYPE index, - OMX_PTR params); - - static OMX_ERRORTYPE GetExtensionIndexWrapper( - OMX_HANDLETYPE component, - OMX_STRING name, - OMX_INDEXTYPE *index); - - static OMX_ERRORTYPE UseBufferWrapper( - OMX_HANDLETYPE component, - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size, - OMX_U8 *ptr); - - static OMX_ERRORTYPE AllocateBufferWrapper( - OMX_HANDLETYPE component, - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size); - - static OMX_ERRORTYPE FreeBufferWrapper( - OMX_HANDLETYPE component, - OMX_U32 portIndex, - OMX_BUFFERHEADERTYPE *buffer); - - static OMX_ERRORTYPE EmptyThisBufferWrapper( - OMX_HANDLETYPE component, - OMX_BUFFERHEADERTYPE *buffer); - - static OMX_ERRORTYPE FillThisBufferWrapper( - OMX_HANDLETYPE component, - OMX_BUFFERHEADERTYPE *buffer); - - static OMX_ERRORTYPE GetStateWrapper( - OMX_HANDLETYPE component, - OMX_STATETYPE *state); - - DISALLOW_EVIL_CONSTRUCTORS(GoldfishOMXComponent); -}; - -template -bool isValidOMXParam(T *a) { - static_assert(offsetof(typeof(*a), nSize) == 0, "nSize not at offset 0"); - static_assert(std::is_same< decltype(a->nSize), OMX_U32>::value, "nSize has wrong type"); - static_assert(offsetof(typeof(*a), nVersion) == 4, "nVersion not at offset 4"); - static_assert(std::is_same< decltype(a->nVersion), OMX_VERSIONTYPE>::value, - "nVersion has wrong type"); - - if (a->nSize < sizeof(*a)) { - ALOGE("b/27207275: need %zu, got %u", sizeof(*a), a->nSize); - //android_errorWriteLog(0x534e4554, "27207275"); - return false; - } - return true; -} - -} // namespace android - -#endif // GOLDFISH_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.h b/system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.h deleted file mode 100644 index bf60f615..00000000 --- a/system/codecs/omx/plugin/GoldfishVideoDecoderOMXComponent.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2013 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 GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ - -#define GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ - -#include "SimpleGoldfishOMXComponent.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace android { - -struct GoldfishVideoDecoderOMXComponent : public SimpleGoldfishOMXComponent { - GoldfishVideoDecoderOMXComponent( - const char *name, - const char *componentRole, - OMX_VIDEO_CODINGTYPE codingType, - const CodecProfileLevel *profileLevels, - size_t numProfileLevels, - int32_t width, - int32_t height, - const OMX_CALLBACKTYPE *callbacks, - OMX_PTR appData, - OMX_COMPONENTTYPE **component); - -protected: - enum { - kDescribeColorAspectsIndex = kPrepareForAdaptivePlaybackIndex + 1, - kDescribeHdrStaticInfoIndex = kPrepareForAdaptivePlaybackIndex + 2, - kDescribeHdr10PlusInfoIndex = kPrepareForAdaptivePlaybackIndex + 3, - kEnableAndroidNativeBuffersIndex = kPrepareForAdaptivePlaybackIndex + 4, - kUseAndroidNativeBufferIndex = kPrepareForAdaptivePlaybackIndex + 5, - kGetAndroidNativeBufferUsageIndex = kPrepareForAdaptivePlaybackIndex + 6, - }; - - enum { - kNotSupported, - kPreferBitstream, - kPreferContainer, - }; - - virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled); - virtual void onReset(); - - virtual OMX_ERRORTYPE internalGetParameter( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetParameter( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE getConfig( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetConfig( - OMX_INDEXTYPE index, const OMX_PTR params, bool *frameConfig); - - virtual OMX_ERRORTYPE getExtensionIndex( - const char *name, OMX_INDEXTYPE *index); - - virtual bool supportsDescribeColorAspects(); - - virtual int getColorAspectPreference(); - - virtual bool supportDescribeHdrStaticInfo(); - - virtual bool supportDescribeHdr10PlusInfo(); - - // This function sets both minimum buffer count and actual buffer count of - // input port to be |numInputBuffers|. It will also set both minimum buffer - // count and actual buffer count of output port to be |numOutputBuffers|. - void initPorts(OMX_U32 numInputBuffers, - OMX_U32 inputBufferSize, - OMX_U32 numOutputBuffers, - const char *mimeType, - OMX_U32 minCompressionRatio = 1u); - - // This function sets input port's minimum buffer count to |numMinInputBuffers|, - // sets input port's actual buffer count to |numInputBuffers|, sets output port's - // minimum buffer count to |numMinOutputBuffers| and sets output port's actual buffer - // count to be |numOutputBuffers|. - void initPorts(OMX_U32 numMinInputBuffers, - OMX_U32 numInputBuffers, - OMX_U32 inputBufferSize, - OMX_U32 numMinOutputBuffers, - OMX_U32 numOutputBuffers, - const char *mimeType, - OMX_U32 minCompressionRatio = 1u); - - virtual void updatePortDefinitions(bool updateCrop = true, bool updateInputSize = false); - - uint32_t outputBufferWidth(); - uint32_t outputBufferHeight(); - - enum CropSettingsMode { - kCropUnSet = 0, - kCropSet, - kCropChanged, - }; - - // This function will handle several port change events which include - // size changed, crop changed, stride changed and coloraspects changed. - // It will trigger OMX_EventPortSettingsChanged event if necessary. - void handlePortSettingsChange( - bool *portWillReset, uint32_t width, uint32_t height, - OMX_COLOR_FORMATTYPE outputFormat = OMX_COLOR_FormatYUV420Planar, - CropSettingsMode cropSettingsMode = kCropUnSet, - bool fakeStride = false); - - void copyYV12FrameToOutputBuffer( - uint8_t *dst, const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV, - size_t srcYStride, size_t srcUStride, size_t srcVStride); - - enum { - kInputPortIndex = 0, - kOutputPortIndex = 1, - kMaxPortIndex = 1, - }; - - bool mIsAdaptive; - uint32_t mAdaptiveMaxWidth, mAdaptiveMaxHeight; - uint32_t mWidth, mHeight; - uint32_t mCropLeft, mCropTop, mCropWidth, mCropHeight; - OMX_COLOR_FORMATTYPE mOutputFormat; - HDRStaticInfo mHdrStaticInfo; - enum { - NONE, - AWAITING_DISABLED, - AWAITING_ENABLED - } mOutputPortSettingsChange; - - bool mUpdateColorAspects; - - Mutex mColorAspectsLock; - // color aspects passed from the framework. - ColorAspects mDefaultColorAspects; - // color aspects parsed from the bitstream. - ColorAspects mBitstreamColorAspects; - // final color aspects after combining the above two aspects. - ColorAspects mFinalColorAspects; - - bool colorAspectsDiffer(const ColorAspects &a, const ColorAspects &b); - - // This functions takes two color aspects and updates the mFinalColorAspects - // based on |preferredAspects|. - void updateFinalColorAspects( - const ColorAspects &otherAspects, const ColorAspects &preferredAspects); - - // This function will update the mFinalColorAspects based on codec preference. - status_t handleColorAspectsChange(); - - // Helper function to dump the ColorAspects. - void dumpColorAspects(const ColorAspects &colorAspects); - - sp dequeueInputFrameConfig(); - void queueOutputFrameConfig(const sp &info); - -private: - uint32_t mMinInputBufferSize; - uint32_t mMinCompressionRatio; - - const char *mComponentRole; - OMX_VIDEO_CODINGTYPE mCodingType; - const CodecProfileLevel *mProfileLevels; - size_t mNumProfileLevels; - typedef List > Hdr10PlusInfoList; - Hdr10PlusInfoList mHdr10PlusInputs; - Hdr10PlusInfoList mHdr10PlusOutputs; - - DISALLOW_EVIL_CONSTRUCTORS(GoldfishVideoDecoderOMXComponent); -}; - -} // namespace android - -#endif // GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/plugin/SimpleGoldfishOMXComponent.h b/system/codecs/omx/plugin/SimpleGoldfishOMXComponent.h deleted file mode 100644 index d2a3bf5d..00000000 --- a/system/codecs/omx/plugin/SimpleGoldfishOMXComponent.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2019 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 SIMPLE_GOLDFISH_OMX_COMPONENT_H_ - -#define SIMPLE_GOLDFISH_OMX_COMPONENT_H_ - -#include "GoldfishOMXComponent.h" - -#include -#include -#include -#include -#include - -namespace android { - -struct ALooper; -struct ABuffer; - -struct CodecProfileLevel { - OMX_U32 mProfile; - OMX_U32 mLevel; -}; - -struct SimpleGoldfishOMXComponent : public GoldfishOMXComponent { - SimpleGoldfishOMXComponent( - const char *name, - const OMX_CALLBACKTYPE *callbacks, - OMX_PTR appData, - OMX_COMPONENTTYPE **component); - - virtual void prepareForDestruction(); - - void onMessageReceived(const sp &msg); - -protected: - struct BufferInfo { - OMX_BUFFERHEADERTYPE *mHeader; - bool mOwnedByUs; - bool mFrameConfig; - }; - - struct PortInfo { - OMX_PARAM_PORTDEFINITIONTYPE mDef; - Vector mBuffers; - List mQueue; - - enum { - NONE, - DISABLING, - ENABLING, - } mTransition; - }; - - enum { - kStoreMetaDataExtensionIndex = OMX_IndexVendorStartUnused + 1, - kPrepareForAdaptivePlaybackIndex, - }; - - void addPort(const OMX_PARAM_PORTDEFINITIONTYPE &def); - - virtual OMX_ERRORTYPE internalGetParameter( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetParameter( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetConfig( - OMX_INDEXTYPE index, const OMX_PTR params, bool *frameConfig); - - virtual void onQueueFilled(OMX_U32 portIndex); - List &getPortQueue(OMX_U32 portIndex); - - virtual void onPortFlushCompleted(OMX_U32 portIndex); - virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled); - virtual void onReset(); - - PortInfo *editPortInfo(OMX_U32 portIndex); - -protected: - enum { - kWhatSendCommand, - kWhatEmptyThisBuffer, - kWhatFillThisBuffer, - }; - - Mutex mLock; - - sp mLooper; - sp > mHandler; - - OMX_STATETYPE mState; - OMX_STATETYPE mTargetState; - - Vector mPorts; - std::atomic_bool mFrameConfig; - - bool isSetParameterAllowed( - OMX_INDEXTYPE index, const OMX_PTR params) const; - - virtual OMX_ERRORTYPE sendCommand( - OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data); - - virtual OMX_ERRORTYPE getParameter( - OMX_INDEXTYPE index, OMX_PTR params); - - virtual OMX_ERRORTYPE setParameter( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE setConfig( - OMX_INDEXTYPE index, const OMX_PTR params); - - virtual OMX_ERRORTYPE useBuffer( - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size, - OMX_U8 *ptr); - - OMX_ERRORTYPE useBufferCallerLockedAlready( - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size, - OMX_U8 *ptr); - - virtual OMX_ERRORTYPE allocateBuffer( - OMX_BUFFERHEADERTYPE **buffer, - OMX_U32 portIndex, - OMX_PTR appPrivate, - OMX_U32 size); - - virtual OMX_ERRORTYPE freeBuffer( - OMX_U32 portIndex, - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE emptyThisBuffer( - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE fillThisBuffer( - OMX_BUFFERHEADERTYPE *buffer); - - virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state); - - void onSendCommand(OMX_COMMANDTYPE cmd, OMX_U32 param); - void onChangeState(OMX_STATETYPE state); - void onPortEnable(OMX_U32 portIndex, bool enable); - void onPortFlush(OMX_U32 portIndex, bool sendFlushComplete); - - void checkTransitions(); - - DISALLOW_EVIL_CONSTRUCTORS(SimpleGoldfishOMXComponent); -}; - -} // namespace android - -#endif // SIMPLE_GOLDFISH_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/plugin/include/GoldfishOMXComponent.h b/system/codecs/omx/plugin/include/GoldfishOMXComponent.h new file mode 100644 index 00000000..87a65ae3 --- /dev/null +++ b/system/codecs/omx/plugin/include/GoldfishOMXComponent.h @@ -0,0 +1,189 @@ +/* + * Copyright 2018 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 GOLDFISH_OMX_COMPONENT_H_ + +#define GOLDFISH_OMX_COMPONENT_H_ + +#include +#include +#include + +#include + +namespace android { + +struct GoldfishOMXComponent : public RefBase { + GoldfishOMXComponent( + const char *name, + const OMX_CALLBACKTYPE *callbacks, + OMX_PTR appData, + OMX_COMPONENTTYPE **component); + + virtual OMX_ERRORTYPE initCheck(); + + void setLibHandle(void *libHandle); + void *libHandle() const; + + virtual void prepareForDestruction(); + +protected: + virtual ~GoldfishOMXComponent(); + + const char *name() const; + + void notify( + OMX_EVENTTYPE event, + OMX_U32 data1, OMX_U32 data2, OMX_PTR data); + + void notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header); + void notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header); + + virtual OMX_ERRORTYPE sendCommand( + OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data); + + virtual OMX_ERRORTYPE getParameter( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE setParameter( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE getConfig( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE setConfig( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE getExtensionIndex( + const char *name, OMX_INDEXTYPE *index); + + virtual OMX_ERRORTYPE useBuffer( + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size, + OMX_U8 *ptr); + + virtual OMX_ERRORTYPE allocateBuffer( + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size); + + virtual OMX_ERRORTYPE freeBuffer( + OMX_U32 portIndex, + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE emptyThisBuffer( + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE fillThisBuffer( + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state); + +private: + AString mName; + const OMX_CALLBACKTYPE *mCallbacks; + OMX_COMPONENTTYPE *mComponent; + + void *mLibHandle; + + static OMX_ERRORTYPE SendCommandWrapper( + OMX_HANDLETYPE component, + OMX_COMMANDTYPE cmd, + OMX_U32 param, + OMX_PTR data); + + static OMX_ERRORTYPE GetParameterWrapper( + OMX_HANDLETYPE component, + OMX_INDEXTYPE index, + OMX_PTR params); + + static OMX_ERRORTYPE SetParameterWrapper( + OMX_HANDLETYPE component, + OMX_INDEXTYPE index, + OMX_PTR params); + + static OMX_ERRORTYPE GetConfigWrapper( + OMX_HANDLETYPE component, + OMX_INDEXTYPE index, + OMX_PTR params); + + static OMX_ERRORTYPE SetConfigWrapper( + OMX_HANDLETYPE component, + OMX_INDEXTYPE index, + OMX_PTR params); + + static OMX_ERRORTYPE GetExtensionIndexWrapper( + OMX_HANDLETYPE component, + OMX_STRING name, + OMX_INDEXTYPE *index); + + static OMX_ERRORTYPE UseBufferWrapper( + OMX_HANDLETYPE component, + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size, + OMX_U8 *ptr); + + static OMX_ERRORTYPE AllocateBufferWrapper( + OMX_HANDLETYPE component, + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size); + + static OMX_ERRORTYPE FreeBufferWrapper( + OMX_HANDLETYPE component, + OMX_U32 portIndex, + OMX_BUFFERHEADERTYPE *buffer); + + static OMX_ERRORTYPE EmptyThisBufferWrapper( + OMX_HANDLETYPE component, + OMX_BUFFERHEADERTYPE *buffer); + + static OMX_ERRORTYPE FillThisBufferWrapper( + OMX_HANDLETYPE component, + OMX_BUFFERHEADERTYPE *buffer); + + static OMX_ERRORTYPE GetStateWrapper( + OMX_HANDLETYPE component, + OMX_STATETYPE *state); + + DISALLOW_EVIL_CONSTRUCTORS(GoldfishOMXComponent); +}; + +template +bool isValidOMXParam(T *a) { + static_assert(offsetof(typeof(*a), nSize) == 0, "nSize not at offset 0"); + static_assert(std::is_same< decltype(a->nSize), OMX_U32>::value, "nSize has wrong type"); + static_assert(offsetof(typeof(*a), nVersion) == 4, "nVersion not at offset 4"); + static_assert(std::is_same< decltype(a->nVersion), OMX_VERSIONTYPE>::value, + "nVersion has wrong type"); + + if (a->nSize < sizeof(*a)) { + ALOGE("b/27207275: need %zu, got %u", sizeof(*a), a->nSize); + //android_errorWriteLog(0x534e4554, "27207275"); + return false; + } + return true; +} + +} // namespace android + +#endif // GOLDFISH_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/plugin/include/GoldfishVideoDecoderOMXComponent.h b/system/codecs/omx/plugin/include/GoldfishVideoDecoderOMXComponent.h new file mode 100644 index 00000000..bf60f615 --- /dev/null +++ b/system/codecs/omx/plugin/include/GoldfishVideoDecoderOMXComponent.h @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2013 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 GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ + +#define GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ + +#include "SimpleGoldfishOMXComponent.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace android { + +struct GoldfishVideoDecoderOMXComponent : public SimpleGoldfishOMXComponent { + GoldfishVideoDecoderOMXComponent( + const char *name, + const char *componentRole, + OMX_VIDEO_CODINGTYPE codingType, + const CodecProfileLevel *profileLevels, + size_t numProfileLevels, + int32_t width, + int32_t height, + const OMX_CALLBACKTYPE *callbacks, + OMX_PTR appData, + OMX_COMPONENTTYPE **component); + +protected: + enum { + kDescribeColorAspectsIndex = kPrepareForAdaptivePlaybackIndex + 1, + kDescribeHdrStaticInfoIndex = kPrepareForAdaptivePlaybackIndex + 2, + kDescribeHdr10PlusInfoIndex = kPrepareForAdaptivePlaybackIndex + 3, + kEnableAndroidNativeBuffersIndex = kPrepareForAdaptivePlaybackIndex + 4, + kUseAndroidNativeBufferIndex = kPrepareForAdaptivePlaybackIndex + 5, + kGetAndroidNativeBufferUsageIndex = kPrepareForAdaptivePlaybackIndex + 6, + }; + + enum { + kNotSupported, + kPreferBitstream, + kPreferContainer, + }; + + virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled); + virtual void onReset(); + + virtual OMX_ERRORTYPE internalGetParameter( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetParameter( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE getConfig( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetConfig( + OMX_INDEXTYPE index, const OMX_PTR params, bool *frameConfig); + + virtual OMX_ERRORTYPE getExtensionIndex( + const char *name, OMX_INDEXTYPE *index); + + virtual bool supportsDescribeColorAspects(); + + virtual int getColorAspectPreference(); + + virtual bool supportDescribeHdrStaticInfo(); + + virtual bool supportDescribeHdr10PlusInfo(); + + // This function sets both minimum buffer count and actual buffer count of + // input port to be |numInputBuffers|. It will also set both minimum buffer + // count and actual buffer count of output port to be |numOutputBuffers|. + void initPorts(OMX_U32 numInputBuffers, + OMX_U32 inputBufferSize, + OMX_U32 numOutputBuffers, + const char *mimeType, + OMX_U32 minCompressionRatio = 1u); + + // This function sets input port's minimum buffer count to |numMinInputBuffers|, + // sets input port's actual buffer count to |numInputBuffers|, sets output port's + // minimum buffer count to |numMinOutputBuffers| and sets output port's actual buffer + // count to be |numOutputBuffers|. + void initPorts(OMX_U32 numMinInputBuffers, + OMX_U32 numInputBuffers, + OMX_U32 inputBufferSize, + OMX_U32 numMinOutputBuffers, + OMX_U32 numOutputBuffers, + const char *mimeType, + OMX_U32 minCompressionRatio = 1u); + + virtual void updatePortDefinitions(bool updateCrop = true, bool updateInputSize = false); + + uint32_t outputBufferWidth(); + uint32_t outputBufferHeight(); + + enum CropSettingsMode { + kCropUnSet = 0, + kCropSet, + kCropChanged, + }; + + // This function will handle several port change events which include + // size changed, crop changed, stride changed and coloraspects changed. + // It will trigger OMX_EventPortSettingsChanged event if necessary. + void handlePortSettingsChange( + bool *portWillReset, uint32_t width, uint32_t height, + OMX_COLOR_FORMATTYPE outputFormat = OMX_COLOR_FormatYUV420Planar, + CropSettingsMode cropSettingsMode = kCropUnSet, + bool fakeStride = false); + + void copyYV12FrameToOutputBuffer( + uint8_t *dst, const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV, + size_t srcYStride, size_t srcUStride, size_t srcVStride); + + enum { + kInputPortIndex = 0, + kOutputPortIndex = 1, + kMaxPortIndex = 1, + }; + + bool mIsAdaptive; + uint32_t mAdaptiveMaxWidth, mAdaptiveMaxHeight; + uint32_t mWidth, mHeight; + uint32_t mCropLeft, mCropTop, mCropWidth, mCropHeight; + OMX_COLOR_FORMATTYPE mOutputFormat; + HDRStaticInfo mHdrStaticInfo; + enum { + NONE, + AWAITING_DISABLED, + AWAITING_ENABLED + } mOutputPortSettingsChange; + + bool mUpdateColorAspects; + + Mutex mColorAspectsLock; + // color aspects passed from the framework. + ColorAspects mDefaultColorAspects; + // color aspects parsed from the bitstream. + ColorAspects mBitstreamColorAspects; + // final color aspects after combining the above two aspects. + ColorAspects mFinalColorAspects; + + bool colorAspectsDiffer(const ColorAspects &a, const ColorAspects &b); + + // This functions takes two color aspects and updates the mFinalColorAspects + // based on |preferredAspects|. + void updateFinalColorAspects( + const ColorAspects &otherAspects, const ColorAspects &preferredAspects); + + // This function will update the mFinalColorAspects based on codec preference. + status_t handleColorAspectsChange(); + + // Helper function to dump the ColorAspects. + void dumpColorAspects(const ColorAspects &colorAspects); + + sp dequeueInputFrameConfig(); + void queueOutputFrameConfig(const sp &info); + +private: + uint32_t mMinInputBufferSize; + uint32_t mMinCompressionRatio; + + const char *mComponentRole; + OMX_VIDEO_CODINGTYPE mCodingType; + const CodecProfileLevel *mProfileLevels; + size_t mNumProfileLevels; + typedef List > Hdr10PlusInfoList; + Hdr10PlusInfoList mHdr10PlusInputs; + Hdr10PlusInfoList mHdr10PlusOutputs; + + DISALLOW_EVIL_CONSTRUCTORS(GoldfishVideoDecoderOMXComponent); +}; + +} // namespace android + +#endif // GOLDFISH_VIDEO_DECODER_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/plugin/include/SimpleGoldfishOMXComponent.h b/system/codecs/omx/plugin/include/SimpleGoldfishOMXComponent.h new file mode 100644 index 00000000..d2a3bf5d --- /dev/null +++ b/system/codecs/omx/plugin/include/SimpleGoldfishOMXComponent.h @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2019 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 SIMPLE_GOLDFISH_OMX_COMPONENT_H_ + +#define SIMPLE_GOLDFISH_OMX_COMPONENT_H_ + +#include "GoldfishOMXComponent.h" + +#include +#include +#include +#include +#include + +namespace android { + +struct ALooper; +struct ABuffer; + +struct CodecProfileLevel { + OMX_U32 mProfile; + OMX_U32 mLevel; +}; + +struct SimpleGoldfishOMXComponent : public GoldfishOMXComponent { + SimpleGoldfishOMXComponent( + const char *name, + const OMX_CALLBACKTYPE *callbacks, + OMX_PTR appData, + OMX_COMPONENTTYPE **component); + + virtual void prepareForDestruction(); + + void onMessageReceived(const sp &msg); + +protected: + struct BufferInfo { + OMX_BUFFERHEADERTYPE *mHeader; + bool mOwnedByUs; + bool mFrameConfig; + }; + + struct PortInfo { + OMX_PARAM_PORTDEFINITIONTYPE mDef; + Vector mBuffers; + List mQueue; + + enum { + NONE, + DISABLING, + ENABLING, + } mTransition; + }; + + enum { + kStoreMetaDataExtensionIndex = OMX_IndexVendorStartUnused + 1, + kPrepareForAdaptivePlaybackIndex, + }; + + void addPort(const OMX_PARAM_PORTDEFINITIONTYPE &def); + + virtual OMX_ERRORTYPE internalGetParameter( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetParameter( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetConfig( + OMX_INDEXTYPE index, const OMX_PTR params, bool *frameConfig); + + virtual void onQueueFilled(OMX_U32 portIndex); + List &getPortQueue(OMX_U32 portIndex); + + virtual void onPortFlushCompleted(OMX_U32 portIndex); + virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled); + virtual void onReset(); + + PortInfo *editPortInfo(OMX_U32 portIndex); + +protected: + enum { + kWhatSendCommand, + kWhatEmptyThisBuffer, + kWhatFillThisBuffer, + }; + + Mutex mLock; + + sp mLooper; + sp > mHandler; + + OMX_STATETYPE mState; + OMX_STATETYPE mTargetState; + + Vector mPorts; + std::atomic_bool mFrameConfig; + + bool isSetParameterAllowed( + OMX_INDEXTYPE index, const OMX_PTR params) const; + + virtual OMX_ERRORTYPE sendCommand( + OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data); + + virtual OMX_ERRORTYPE getParameter( + OMX_INDEXTYPE index, OMX_PTR params); + + virtual OMX_ERRORTYPE setParameter( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE setConfig( + OMX_INDEXTYPE index, const OMX_PTR params); + + virtual OMX_ERRORTYPE useBuffer( + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size, + OMX_U8 *ptr); + + OMX_ERRORTYPE useBufferCallerLockedAlready( + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size, + OMX_U8 *ptr); + + virtual OMX_ERRORTYPE allocateBuffer( + OMX_BUFFERHEADERTYPE **buffer, + OMX_U32 portIndex, + OMX_PTR appPrivate, + OMX_U32 size); + + virtual OMX_ERRORTYPE freeBuffer( + OMX_U32 portIndex, + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE emptyThisBuffer( + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE fillThisBuffer( + OMX_BUFFERHEADERTYPE *buffer); + + virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state); + + void onSendCommand(OMX_COMMANDTYPE cmd, OMX_U32 param); + void onChangeState(OMX_STATETYPE state); + void onPortEnable(OMX_U32 portIndex, bool enable); + void onPortFlush(OMX_U32 portIndex, bool sendFlushComplete); + + void checkTransitions(); + + DISALLOW_EVIL_CONSTRUCTORS(SimpleGoldfishOMXComponent); +}; + +} // namespace android + +#endif // SIMPLE_GOLDFISH_OMX_COMPONENT_H_ diff --git a/system/codecs/omx/vpxdec/Android.bp b/system/codecs/omx/vpxdec/Android.bp new file mode 100644 index 00000000..09a7f9cc --- /dev/null +++ b/system/codecs/omx/vpxdec/Android.bp @@ -0,0 +1,52 @@ +// +// Copyright 2018 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. +// + +cc_library_shared { + name: "libstagefright_goldfish_vpxdec", + vendor: true, + srcs: [ + "GoldfishVPX.cpp", + "goldfish_vpx_impl.cpp", + ], + export_include_dirs: [ + "include", + ], + shared_libs: [ + "libstagefrighthw", + "android.hardware.media.omx@1.0", + "android.hardware.graphics.common@1.2", + "libstagefright_foundation", + "libbinder", + "libcutils", + "libutils", + "liblog", + "libui", + ], + static_libs: [ + "libgoldfish_codecs_common", + ], + header_libs: [ + "media_plugin_headers", + "libmedia_headers", + "libbinder_headers", + "libhardware_headers", + "libnativewindow_headers", + "libgralloc_cb.ranchu", + ], + cflags: [ + "-DLOG_TAG=\"goldfish_vpxdec\"", + ], +} diff --git a/system/codecs/omx/vpxdec/Android.mk b/system/codecs/omx/vpxdec/Android.mk deleted file mode 100644 index e7ec2d4f..00000000 --- a/system/codecs/omx/vpxdec/Android.mk +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright 2019 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. -# -LOCAL_PATH := $(call my-dir) - -commonSources := \ - GoldfishVPX.cpp \ - goldfish_vpx_impl.cpp - -$(call emugl-begin-shared-library,libstagefright_goldfish_vpxdec$(GOLDFISH_OPENGL_LIB_SUFFIX)) - -LOCAL_SRC_FILES := $(commonSources) - -LOCAL_CFLAGS += -DLOG_TAG=\"goldfish_vpxdec\" -LOCAL_CFLAGS += -Wno-unused-private-field - -$(call emugl-export,SHARED_LIBRARIES,libcutils libutils liblog) - -LOCAL_HEADER_LIBRARIES := media_plugin_headers \ - libmedia_headers \ - libbinder_headers \ - libhidlbase_impl_internal \ - libbase - -LOCAL_HEADER_LIBRARIES += libui_headers \ - libnativewindow_headers \ - libhardware_headers \ - libarect_headers \ - libarect_headers_for_ndk - -LOCAL_HEADER_LIBRARIES += libgralloc_cb.ranchu - -LOCAL_SHARED_LIBRARIES += \ - libbinder \ - libutils \ - liblog \ - libcutils \ - libui \ - android.hardware.media.omx@1.0 \ - android.hardware.graphics.allocator@3.0 \ - android.hardware.graphics.mapper@3.0 \ - libstagefright_foundation - -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) -$(call emugl-import,libgoldfish_codecs_common) -$(call emugl-import,libstagefrighthw) -$(call emugl-end-module) diff --git a/system/codecs/omx/vpxdec/GoldfishVPX.cpp b/system/codecs/omx/vpxdec/GoldfishVPX.cpp index edf6aa3f..2a6e4bcf 100644 --- a/system/codecs/omx/vpxdec/GoldfishVPX.cpp +++ b/system/codecs/omx/vpxdec/GoldfishVPX.cpp @@ -36,8 +36,7 @@ #include -#include -#include +#include #include using ::android::hardware::graphics::common::V1_0::BufferUsage; diff --git a/system/codecs/omx/vpxdec/GoldfishVPX.h b/system/codecs/omx/vpxdec/GoldfishVPX.h deleted file mode 100644 index cb9321f5..00000000 --- a/system/codecs/omx/vpxdec/GoldfishVPX.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2011 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 GOLDFISH_VPX_H_ - -#define GOLDFISH_VPX_H_ - -#include "GoldfishVideoDecoderOMXComponent.h" -#include "goldfish_vpx_defs.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace android { - -struct ABuffer; - -struct GoldfishVPX : public GoldfishVideoDecoderOMXComponent { - GoldfishVPX(const char* name, - const char* componentRole, - OMX_VIDEO_CODINGTYPE codingType, - const OMX_CALLBACKTYPE* callbacks, - OMX_PTR appData, - OMX_COMPONENTTYPE** component, - RenderMode renderMode); - -protected: - virtual ~GoldfishVPX(); - - virtual void onQueueFilled(OMX_U32 portIndex); - virtual void onPortFlushCompleted(OMX_U32 portIndex); - virtual void onReset(); - virtual bool supportDescribeHdrStaticInfo(); - virtual bool supportDescribeHdr10PlusInfo(); - - virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, - OMX_PTR params); - - virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, - const OMX_PTR params); - - virtual OMX_ERRORTYPE getExtensionIndex(const char* name, - OMX_INDEXTYPE* index); - -private: - enum { - kNumBuffers = 10 - }; - - enum { - MODE_VP8, - MODE_VP9 - } mMode; - - RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; - bool mEnableAndroidNativeBuffers = false; - std::map> mNWBuffers; - - int getHostColorBufferId(void* header); - - enum { - INPUT_DATA_AVAILABLE, // VPX component is ready to decode data. - INPUT_EOS_SEEN, // VPX component saw EOS and is flushing On2 decoder. - OUTPUT_FRAMES_FLUSHED // VPX component finished flushing On2 decoder. - } mEOSStatus; - - vpx_codec_ctx_t *mCtx; - bool mFrameParallelMode; // Frame parallel is only supported by VP9 decoder. - struct PrivInfo { - OMX_TICKS mTimeStamp; - sp mHdr10PlusInfo; - }; - PrivInfo mPrivInfo[kNumBuffers]; - uint8_t mTimeStampIdx; - vpx_image_t *mImg; - - status_t initDecoder(); - status_t destroyDecoder(); - bool outputBuffers(bool flushDecoder, bool display, bool eos, bool *portWillReset); - bool outputBufferSafe(OMX_BUFFERHEADERTYPE *outHeader); - - void setup_ctx_parameters(vpx_codec_ctx_t*, int hostColorBufferId = -1); - - DISALLOW_EVIL_CONSTRUCTORS(GoldfishVPX); -}; - -} // namespace android - -#endif // GOLDFISH_VPX_H_ diff --git a/system/codecs/omx/vpxdec/goldfish_vpx_defs.h b/system/codecs/omx/vpxdec/goldfish_vpx_defs.h deleted file mode 100644 index 25fecde3..00000000 --- a/system/codecs/omx/vpxdec/goldfish_vpx_defs.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef MY_VPX_DEFS_H_ -#define MY_VPX_DEFS_H_ - - -#define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ -#define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */ -#define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */ -#define VPX_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */ - -typedef unsigned char uint8_t; - -enum class RenderMode { - RENDER_BY_HOST_GPU = 1, - RENDER_BY_GUEST_CPU = 2, -}; - -enum vpx_img_fmt_t { - VPX_IMG_FMT_NONE, - VPX_IMG_FMT_YV12 = - VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ - VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, - VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5, - VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6, - VPX_IMG_FMT_I440 = VPX_IMG_FMT_PLANAR | 7, - VPX_IMG_FMT_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH, - VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH, - VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH, - VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH -}; - -struct vpx_image_t { - vpx_img_fmt_t fmt; /**< Image Format */ - unsigned int d_w; /**< Displayed image width */ - unsigned int d_h; /**< Displayed image height */ - void *user_priv; -}; - -#define VPX_CODEC_OK 0 - -struct vpx_codec_ctx_t { - int vpversion; //8: vp8 or 9: vp9 - int version; // 100: return decoded frame to guest; 200: render on host - int hostColorBufferId; - uint64_t id; // >= 1, unique - int memory_slot; - uint64_t address_offset = 0; - size_t outputBufferWidth; - size_t outputBufferHeight; - size_t width; - size_t height; - size_t bpp; - uint8_t *data; - uint8_t *dst; - vpx_image_t myImg; -}; - -int vpx_codec_destroy(vpx_codec_ctx_t*); -int vpx_codec_dec_init(vpx_codec_ctx_t*); -vpx_image_t* vpx_codec_get_frame(vpx_codec_ctx_t*, int hostColorBufferId = -1); -int vpx_codec_flush(vpx_codec_ctx_t *ctx); -int vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, - unsigned int data_sz, void *user_priv, - long deadline); - -#endif // MY_VPX_DEFS_H_ diff --git a/system/codecs/omx/vpxdec/include/GoldfishVPX.h b/system/codecs/omx/vpxdec/include/GoldfishVPX.h new file mode 100644 index 00000000..cb9321f5 --- /dev/null +++ b/system/codecs/omx/vpxdec/include/GoldfishVPX.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2011 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 GOLDFISH_VPX_H_ + +#define GOLDFISH_VPX_H_ + +#include "GoldfishVideoDecoderOMXComponent.h" +#include "goldfish_vpx_defs.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace android { + +struct ABuffer; + +struct GoldfishVPX : public GoldfishVideoDecoderOMXComponent { + GoldfishVPX(const char* name, + const char* componentRole, + OMX_VIDEO_CODINGTYPE codingType, + const OMX_CALLBACKTYPE* callbacks, + OMX_PTR appData, + OMX_COMPONENTTYPE** component, + RenderMode renderMode); + +protected: + virtual ~GoldfishVPX(); + + virtual void onQueueFilled(OMX_U32 portIndex); + virtual void onPortFlushCompleted(OMX_U32 portIndex); + virtual void onReset(); + virtual bool supportDescribeHdrStaticInfo(); + virtual bool supportDescribeHdr10PlusInfo(); + + virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, + OMX_PTR params); + + virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, + const OMX_PTR params); + + virtual OMX_ERRORTYPE getExtensionIndex(const char* name, + OMX_INDEXTYPE* index); + +private: + enum { + kNumBuffers = 10 + }; + + enum { + MODE_VP8, + MODE_VP9 + } mMode; + + RenderMode mRenderMode = RenderMode::RENDER_BY_GUEST_CPU; + bool mEnableAndroidNativeBuffers = false; + std::map> mNWBuffers; + + int getHostColorBufferId(void* header); + + enum { + INPUT_DATA_AVAILABLE, // VPX component is ready to decode data. + INPUT_EOS_SEEN, // VPX component saw EOS and is flushing On2 decoder. + OUTPUT_FRAMES_FLUSHED // VPX component finished flushing On2 decoder. + } mEOSStatus; + + vpx_codec_ctx_t *mCtx; + bool mFrameParallelMode; // Frame parallel is only supported by VP9 decoder. + struct PrivInfo { + OMX_TICKS mTimeStamp; + sp mHdr10PlusInfo; + }; + PrivInfo mPrivInfo[kNumBuffers]; + uint8_t mTimeStampIdx; + vpx_image_t *mImg; + + status_t initDecoder(); + status_t destroyDecoder(); + bool outputBuffers(bool flushDecoder, bool display, bool eos, bool *portWillReset); + bool outputBufferSafe(OMX_BUFFERHEADERTYPE *outHeader); + + void setup_ctx_parameters(vpx_codec_ctx_t*, int hostColorBufferId = -1); + + DISALLOW_EVIL_CONSTRUCTORS(GoldfishVPX); +}; + +} // namespace android + +#endif // GOLDFISH_VPX_H_ diff --git a/system/codecs/omx/vpxdec/include/goldfish_vpx_defs.h b/system/codecs/omx/vpxdec/include/goldfish_vpx_defs.h new file mode 100644 index 00000000..25fecde3 --- /dev/null +++ b/system/codecs/omx/vpxdec/include/goldfish_vpx_defs.h @@ -0,0 +1,65 @@ +#ifndef MY_VPX_DEFS_H_ +#define MY_VPX_DEFS_H_ + + +#define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ +#define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */ +#define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */ +#define VPX_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */ + +typedef unsigned char uint8_t; + +enum class RenderMode { + RENDER_BY_HOST_GPU = 1, + RENDER_BY_GUEST_CPU = 2, +}; + +enum vpx_img_fmt_t { + VPX_IMG_FMT_NONE, + VPX_IMG_FMT_YV12 = + VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ + VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, + VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5, + VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6, + VPX_IMG_FMT_I440 = VPX_IMG_FMT_PLANAR | 7, + VPX_IMG_FMT_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH, + VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH, + VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH, + VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH +}; + +struct vpx_image_t { + vpx_img_fmt_t fmt; /**< Image Format */ + unsigned int d_w; /**< Displayed image width */ + unsigned int d_h; /**< Displayed image height */ + void *user_priv; +}; + +#define VPX_CODEC_OK 0 + +struct vpx_codec_ctx_t { + int vpversion; //8: vp8 or 9: vp9 + int version; // 100: return decoded frame to guest; 200: render on host + int hostColorBufferId; + uint64_t id; // >= 1, unique + int memory_slot; + uint64_t address_offset = 0; + size_t outputBufferWidth; + size_t outputBufferHeight; + size_t width; + size_t height; + size_t bpp; + uint8_t *data; + uint8_t *dst; + vpx_image_t myImg; +}; + +int vpx_codec_destroy(vpx_codec_ctx_t*); +int vpx_codec_dec_init(vpx_codec_ctx_t*); +vpx_image_t* vpx_codec_get_frame(vpx_codec_ctx_t*, int hostColorBufferId = -1); +int vpx_codec_flush(vpx_codec_ctx_t *ctx); +int vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, + unsigned int data_sz, void *user_priv, + long deadline); + +#endif // MY_VPX_DEFS_H_ -- cgit v1.2.3