Loading media/libstagefright/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,8 @@ cc_library_shared { "libRScpp", "libhidlbase", "libhidlmemory", // TODO: Remove libv4l2_c2_componentstore. "libv4l2_c2componentstore", "libziparchive", "android.hidl.allocator@1.0", "android.hardware.cas.native@1.0", Loading media/libstagefright/CCodec.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,13 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "CCodec" #include <cutils/properties.h> #include <utils/Log.h> #include <thread> #include <C2PlatformSupport.h> #include <C2V4l2Support.h> #include <gui/Surface.h> #include <media/stagefright/BufferProducerWrapper.h> Loading Loading @@ -187,7 +189,14 @@ void CCodec::allocate(const AString &componentName) { std::shared_ptr<C2Component> comp; c2_status_t err = GetCodec2PlatformComponentStore()->createComponent( componentName.c_str(), &comp); static bool v4l2Enabled = property_get_bool("debug.stagefright.ccodec_v4l2", false); if (err != C2_OK && v4l2Enabled) { err = GetCodec2VDAComponentStore()->createComponent( componentName.c_str(), &comp); } if (err != C2_OK) { ALOGE("Failed Create component: %s", componentName.c_str()); Mutexed<State>::Locked state(mState); state->set(RELEASED); state.unlock(); Loading @@ -195,6 +204,7 @@ void CCodec::allocate(const AString &componentName) { state.lock(); return; } ALOGV("Success Create component: %s", componentName.c_str()); comp->setListener_vb(mListener, C2_MAY_BLOCK); { Mutexed<State>::Locked state(mState); Loading media/libstagefright/codec2/vndk/include/C2ComponentFactory.h 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 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 STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ #define STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ #include <C2Component.h> #include <functional> #include <memory> 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 * cannot safely create a managed object and pass it in C. * * Components/interfaces typically inherit from std::enable_shared_from_this, but C requires * passing simple pointer, and shared_ptr constructor needs to know the class to be constructed * derives from enable_shared_from_this. * */ class C2ComponentFactory { public: typedef std::function<void(::android::C2Component*)> ComponentDeleter; typedef std::function<void(::android::C2ComponentInterface*)> InterfaceDeleter; /** * Creates a component. * * This method SHALL return within 100ms. * * \param id component ID for the created component * \param component shared pointer where the created component is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component was created successfully * \retval C2_TIMED_OUT could not create the component within the time limit (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component */ virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, ComponentDeleter deleter = std::default_delete<C2Component>()) = 0; /** * Creates a component interface. * * This method SHALL return within 100ms. * * \param id component interface ID for the created interface * \param interface shared pointer where the created interface is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component interface was created successfully * \retval C2_TIMED_OUT could not create the component interface within the time limit * (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component interface * (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component interface */ virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, InterfaceDeleter deleter = std::default_delete<C2ComponentInterface>()) = 0; virtual ~C2ComponentFactory() = default; typedef ::android::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); typedef void (*DestroyCodec2FactoryFunc)(::android::C2ComponentFactory*); }; } // namespace android #endif // STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ media/libstagefright/codec2/vndk/include/C2PlatformSupport.h +1 −64 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ #define STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_ #include <C2Component.h> #include <C2ComponentFactory.h> #include <functional> #include <memory> namespace android { Loading Loading @@ -81,74 +81,11 @@ c2_status_t GetCodec2BlockPool( C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool); /** * 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 * cannot safely create a managed object and pass it in C. * * Components/interfaces typically inherit from std::enable_shared_from_this, but C requires * passing simple pointer, and shared_ptr constructor needs to know the class to be constructed * derives from enable_shared_from_this. * */ class C2ComponentFactory { public: typedef std::function<void(::android::C2Component*)> ComponentDeleter; typedef std::function<void(::android::C2ComponentInterface*)> InterfaceDeleter; /** * Creates a component. * * This method SHALL return within 100ms. * * \param id component ID for the created component * \param component shared pointer where the created component is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component was created successfully * \retval C2_TIMED_OUT could not create the component within the time limit (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component */ virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, ComponentDeleter deleter = std::default_delete<C2Component>()) = 0; /** * Creates a component interface. * * This method SHALL return within 100ms. * * \param id component interface ID for the created interface * \param interface shared pointer where the created interface is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component interface was created successfully * \retval C2_TIMED_OUT could not create the component interface within the time limit * (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component interface * (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component interface */ virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, InterfaceDeleter deleter = std::default_delete<C2ComponentInterface>()) = 0; virtual ~C2ComponentFactory() = default; typedef ::android::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); typedef void (*DestroyCodec2FactoryFunc)(::android::C2ComponentFactory*); }; /** * Returns the platform component store. * \retval nullptr if the platform component store could not be obtained */ std::shared_ptr<C2ComponentStore> GetCodec2PlatformComponentStore(); } // namespace android #endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_ Loading
media/libstagefright/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,8 @@ cc_library_shared { "libRScpp", "libhidlbase", "libhidlmemory", // TODO: Remove libv4l2_c2_componentstore. "libv4l2_c2componentstore", "libziparchive", "android.hidl.allocator@1.0", "android.hardware.cas.native@1.0", Loading
media/libstagefright/CCodec.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -16,11 +16,13 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "CCodec" #include <cutils/properties.h> #include <utils/Log.h> #include <thread> #include <C2PlatformSupport.h> #include <C2V4l2Support.h> #include <gui/Surface.h> #include <media/stagefright/BufferProducerWrapper.h> Loading Loading @@ -187,7 +189,14 @@ void CCodec::allocate(const AString &componentName) { std::shared_ptr<C2Component> comp; c2_status_t err = GetCodec2PlatformComponentStore()->createComponent( componentName.c_str(), &comp); static bool v4l2Enabled = property_get_bool("debug.stagefright.ccodec_v4l2", false); if (err != C2_OK && v4l2Enabled) { err = GetCodec2VDAComponentStore()->createComponent( componentName.c_str(), &comp); } if (err != C2_OK) { ALOGE("Failed Create component: %s", componentName.c_str()); Mutexed<State>::Locked state(mState); state->set(RELEASED); state.unlock(); Loading @@ -195,6 +204,7 @@ void CCodec::allocate(const AString &componentName) { state.lock(); return; } ALOGV("Success Create component: %s", componentName.c_str()); comp->setListener_vb(mListener, C2_MAY_BLOCK); { Mutexed<State>::Locked state(mState); Loading
media/libstagefright/codec2/vndk/include/C2ComponentFactory.h 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 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 STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ #define STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_ #include <C2Component.h> #include <functional> #include <memory> 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 * cannot safely create a managed object and pass it in C. * * Components/interfaces typically inherit from std::enable_shared_from_this, but C requires * passing simple pointer, and shared_ptr constructor needs to know the class to be constructed * derives from enable_shared_from_this. * */ class C2ComponentFactory { public: typedef std::function<void(::android::C2Component*)> ComponentDeleter; typedef std::function<void(::android::C2ComponentInterface*)> InterfaceDeleter; /** * Creates a component. * * This method SHALL return within 100ms. * * \param id component ID for the created component * \param component shared pointer where the created component is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component was created successfully * \retval C2_TIMED_OUT could not create the component within the time limit (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component */ virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, ComponentDeleter deleter = std::default_delete<C2Component>()) = 0; /** * Creates a component interface. * * This method SHALL return within 100ms. * * \param id component interface ID for the created interface * \param interface shared pointer where the created interface is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component interface was created successfully * \retval C2_TIMED_OUT could not create the component interface within the time limit * (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component interface * (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component interface */ virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, InterfaceDeleter deleter = std::default_delete<C2ComponentInterface>()) = 0; virtual ~C2ComponentFactory() = default; typedef ::android::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); typedef void (*DestroyCodec2FactoryFunc)(::android::C2ComponentFactory*); }; } // namespace android #endif // STAGEFRIGHT_CODEC2_COMPONENT_FACTORY_H_
media/libstagefright/codec2/vndk/include/C2PlatformSupport.h +1 −64 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ #define STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_ #include <C2Component.h> #include <C2ComponentFactory.h> #include <functional> #include <memory> namespace android { Loading Loading @@ -81,74 +81,11 @@ c2_status_t GetCodec2BlockPool( C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool); /** * 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 * cannot safely create a managed object and pass it in C. * * Components/interfaces typically inherit from std::enable_shared_from_this, but C requires * passing simple pointer, and shared_ptr constructor needs to know the class to be constructed * derives from enable_shared_from_this. * */ class C2ComponentFactory { public: typedef std::function<void(::android::C2Component*)> ComponentDeleter; typedef std::function<void(::android::C2ComponentInterface*)> InterfaceDeleter; /** * Creates a component. * * This method SHALL return within 100ms. * * \param id component ID for the created component * \param component shared pointer where the created component is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component was created successfully * \retval C2_TIMED_OUT could not create the component within the time limit (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component */ virtual c2_status_t createComponent( c2_node_id_t id, std::shared_ptr<C2Component>* const component, ComponentDeleter deleter = std::default_delete<C2Component>()) = 0; /** * Creates a component interface. * * This method SHALL return within 100ms. * * \param id component interface ID for the created interface * \param interface shared pointer where the created interface is stored. Cleared on * failure and updated on success. * * \retval C2_OK the component interface was created successfully * \retval C2_TIMED_OUT could not create the component interface within the time limit * (unexpected) * \retval C2_CORRUPTED some unknown error prevented the creation of the component interface * (unexpected) * * \retval C2_NO_MEMORY not enough memory to create the component interface */ virtual c2_status_t createInterface( c2_node_id_t id, std::shared_ptr<C2ComponentInterface>* const interface, InterfaceDeleter deleter = std::default_delete<C2ComponentInterface>()) = 0; virtual ~C2ComponentFactory() = default; typedef ::android::C2ComponentFactory* (*CreateCodec2FactoryFunc)(void); typedef void (*DestroyCodec2FactoryFunc)(::android::C2ComponentFactory*); }; /** * Returns the platform component store. * \retval nullptr if the platform component store could not be obtained */ std::shared_ptr<C2ComponentStore> GetCodec2PlatformComponentStore(); } // namespace android #endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_