summaryrefslogtreecommitdiffstats
path: root/media/codecs/base/include
diff options
context:
space:
mode:
Diffstat (limited to 'media/codecs/base/include')
-rw-r--r--media/codecs/base/include/SimpleC2Component.h244
-rw-r--r--media/codecs/base/include/SimpleC2Interface.h236
2 files changed, 0 insertions, 480 deletions
diff --git a/media/codecs/base/include/SimpleC2Component.h b/media/codecs/base/include/SimpleC2Component.h
deleted file mode 100644
index b3a98f4..0000000
--- a/media/codecs/base/include/SimpleC2Component.h
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (C) 2017 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_C2_COMPONENT_H_
-#define SIMPLE_C2_COMPONENT_H_
-
-#include <list>
-#include <unordered_map>
-
-#include <C2Component.h>
-
-#include <media/stagefright/foundation/AHandler.h>
-#include <media/stagefright/foundation/ALooper.h>
-#include <media/stagefright/foundation/Mutexed.h>
-
-namespace android {
-
-class SimpleC2Component
- : public C2Component, public std::enable_shared_from_this<SimpleC2Component> {
-public:
- explicit SimpleC2Component(
- const std::shared_ptr<C2ComponentInterface> &intf);
- virtual ~SimpleC2Component();
-
- // C2Component
- // From C2Component
- virtual c2_status_t setListener_vb(
- const std::shared_ptr<Listener> &listener, c2_blocking_t mayBlock) override;
- virtual c2_status_t queue_nb(std::list<std::unique_ptr<C2Work>>* const items) override;
- virtual c2_status_t announce_nb(const std::vector<C2WorkOutline> &items) override;
- virtual c2_status_t flush_sm(
- flush_mode_t mode, std::list<std::unique_ptr<C2Work>>* const flushedWork) override;
- virtual c2_status_t drain_nb(drain_mode_t mode) override;
- virtual c2_status_t start() override;
- virtual c2_status_t stop() override;
- virtual c2_status_t reset() override;
- virtual c2_status_t release() override;
- virtual std::shared_ptr<C2ComponentInterface> intf() override;
-
- // for handler
- bool processQueue();
-
-protected:
- /**
- * Initialize internal states of the component according to the config set
- * in the interface.
- *
- * This method is called during start(), but only at the first invocation or
- * after reset().
- */
- virtual c2_status_t onInit() = 0;
-
- /**
- * Stop the component.
- */
- virtual c2_status_t onStop() = 0;
-
- /**
- * Reset the component.
- */
- virtual void onReset() = 0;
-
- /**
- * Release the component.
- */
- virtual void onRelease() = 0;
-
- /**
- * Flush the component.
- */
- virtual c2_status_t onFlush_sm() = 0;
-
- /**
- * Process the given work and finish pending work using finish().
- *
- * \param[in,out] work the work to process
- * \param[in] pool the pool to use for allocating output blocks.
- */
- virtual void process(
- const std::unique_ptr<C2Work> &work,
- const std::shared_ptr<C2BlockPool> &pool) = 0;
-
- /**
- * Drain the component and finish pending work using finish().
- *
- * \param[in] drainMode mode of drain.
- * \param[in] pool the pool to use for allocating output blocks.
- *
- * \retval C2_OK The component has drained all pending output
- * work.
- * \retval C2_OMITTED Unsupported mode (e.g. DRAIN_CHAIN)
- */
- virtual c2_status_t drain(
- uint32_t drainMode,
- const std::shared_ptr<C2BlockPool> &pool) = 0;
-
- // for derived classes
- /**
- * Finish pending work.
- *
- * This method will retrieve the pending work according to |frameIndex| and
- * feed the work into |fillWork| function. |fillWork| must be
- * "non-blocking". Once |fillWork| returns the filled work will be returned
- * to the client.
- *
- * \param[in] frameIndex the index of the pending work
- * \param[in] fillWork the function to fill the retrieved work.
- */
- void finish(uint64_t frameIndex, std::function<void(const std::unique_ptr<C2Work> &)> fillWork);
-
- /**
- * Clone pending or current work and send the work back to client.
- *
- * This method will retrieve and clone the pending or current work according
- * to |frameIndex| and feed the work into |fillWork| function. |fillWork|
- * must be "non-blocking". Once |fillWork| returns the filled work will be
- * returned to the client.
- *
- * \param[in] frameIndex the index of the work
- * \param[in] currentWork the current work under processing
- * \param[in] fillWork the function to fill the retrieved work.
- */
- void cloneAndSend(
- uint64_t frameIndex,
- const std::unique_ptr<C2Work> &currentWork,
- std::function<void(const std::unique_ptr<C2Work> &)> fillWork);
-
-
- std::shared_ptr<C2Buffer> createLinearBuffer(
- const std::shared_ptr<C2LinearBlock> &block);
-
- std::shared_ptr<C2Buffer> createLinearBuffer(
- const std::shared_ptr<C2LinearBlock> &block, size_t offset, size_t size);
-
- std::shared_ptr<C2Buffer> createGraphicBuffer(
- const std::shared_ptr<C2GraphicBlock> &block);
-
- std::shared_ptr<C2Buffer> createGraphicBuffer(
- const std::shared_ptr<C2GraphicBlock> &block,
- const C2Rect &crop);
-
- static constexpr uint32_t NO_DRAIN = ~0u;
-
- C2ReadView mDummyReadView;
-
-private:
- const std::shared_ptr<C2ComponentInterface> mIntf;
-
- class WorkHandler : public AHandler {
- public:
- enum {
- kWhatProcess,
- kWhatInit,
- kWhatStart,
- kWhatStop,
- kWhatReset,
- kWhatRelease,
- };
-
- WorkHandler();
- ~WorkHandler() override = default;
-
- void setComponent(const std::shared_ptr<SimpleC2Component> &thiz);
-
- protected:
- void onMessageReceived(const sp<AMessage> &msg) override;
-
- private:
- std::weak_ptr<SimpleC2Component> mThiz;
- bool mRunning;
- };
-
- enum {
- UNINITIALIZED,
- STOPPED,
- RUNNING,
- };
-
- struct ExecState {
- ExecState() : mState(UNINITIALIZED) {}
-
- int mState;
- std::shared_ptr<C2Component::Listener> mListener;
- };
- Mutexed<ExecState> mExecState;
-
- sp<ALooper> mLooper;
- sp<WorkHandler> mHandler;
-
- class WorkQueue {
- public:
- inline WorkQueue() : mFlush(false), mGeneration(0ul) {}
-
- inline uint64_t generation() const { return mGeneration; }
- inline void incGeneration() { ++mGeneration; mFlush = true; }
-
- std::unique_ptr<C2Work> pop_front();
- void push_back(std::unique_ptr<C2Work> work);
- bool empty() const;
- uint32_t drainMode() const;
- void markDrain(uint32_t drainMode);
- inline bool popPendingFlush() {
- bool flush = mFlush;
- mFlush = false;
- return flush;
- }
- void clear();
-
- private:
- struct Entry {
- std::unique_ptr<C2Work> work;
- uint32_t drainMode;
- };
-
- bool mFlush;
- uint64_t mGeneration;
- std::list<Entry> mQueue;
- };
- Mutexed<WorkQueue> mWorkQueue;
-
- typedef std::unordered_map<uint64_t, std::unique_ptr<C2Work>> PendingWork;
- Mutexed<PendingWork> mPendingWork;
-
- std::shared_ptr<C2BlockPool> mOutputBlockPool;
-
- SimpleC2Component() = delete;
-};
-
-} // namespace android
-
-#endif // SIMPLE_C2_COMPONENT_H_
diff --git a/media/codecs/base/include/SimpleC2Interface.h b/media/codecs/base/include/SimpleC2Interface.h
deleted file mode 100644
index 2051d3d..0000000
--- a/media/codecs/base/include/SimpleC2Interface.h
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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 ANDROID_SIMPLE_C2_INTERFACE_H_
-#define ANDROID_SIMPLE_C2_INTERFACE_H_
-
-#include <C2Component.h>
-#include <C2Config.h>
-#include <util/C2InterfaceHelper.h>
-
-namespace android {
-
-/**
- * Wrap a common interface object (such as Codec2Client::Interface, or C2InterfaceHelper into
- * a C2ComponentInterface.
- *
- * \param T common interface type
- */
-template <typename T>
-class SimpleC2Interface : public C2ComponentInterface {
-public:
- SimpleC2Interface(const char *name, c2_node_id_t id, const std::shared_ptr<T> &impl)
- : mName(name),
- mId(id),
- mImpl(impl) {
- }
-
- ~SimpleC2Interface() override = default;
-
- // From C2ComponentInterface
- C2String getName() const override { return mName; }
- c2_node_id_t getId() const override { return mId; }
- c2_status_t query_vb(
- const std::vector<C2Param*> &stackParams,
- const std::vector<C2Param::Index> &heapParamIndices,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2Param>>* const heapParams) const override {
- return mImpl->query(stackParams, heapParamIndices, mayBlock, heapParams);
- }
- c2_status_t config_vb(
- const std::vector<C2Param*> &params,
- c2_blocking_t mayBlock,
- std::vector<std::unique_ptr<C2SettingResult>>* const failures) override {
- return mImpl->config(params, mayBlock, failures);
- }
- c2_status_t createTunnel_sm(c2_node_id_t) override { return C2_OMITTED; }
- c2_status_t releaseTunnel_sm(c2_node_id_t) override { return C2_OMITTED; }
- c2_status_t querySupportedParams_nb(
- std::vector<std::shared_ptr<C2ParamDescriptor>> * const params) const override {
- return mImpl->querySupportedParams(params);
- }
- c2_status_t querySupportedValues_vb(
- std::vector<C2FieldSupportedValuesQuery> &fields,
- c2_blocking_t mayBlock) const override {
- return mImpl->querySupportedValues(fields, mayBlock);
- }
-
-private:
- C2String mName;
- const c2_node_id_t mId;
- const std::shared_ptr<T> mImpl;
-};
-
-/**
- * Utility classes for common interfaces.
- */
-template<>
-class SimpleC2Interface<void> {
-public:
- /**
- * Base Codec 2.0 parameters required for all components.
- */
- struct BaseParams : C2InterfaceHelper {
- explicit BaseParams(
- const std::shared_ptr<C2ReflectorHelper> &helper,
- C2String name,
- C2Component::kind_t kind,
- C2Component::domain_t domain,
- C2String mediaType,
- std::vector<C2String> aliases = std::vector<C2String>());
-
- /// Marks that this component has no input latency. Otherwise, component must
- /// add support for C2PortRequestedDelayTuning::input and C2PortActualDelayTuning::input.
- void noInputLatency();
-
- /// Marks that this component has no output latency. Otherwise, component must
- /// add support for C2PortRequestedDelayTuning::output and C2PortActualDelayTuning::output.
- void noOutputLatency();
-
- /// Marks that this component has no pipeline latency. Otherwise, component must
- /// add support for C2RequestedPipelineDelayTuning and C2ActualPipelineDelayTuning.
- void noPipelineLatency();
-
- /// Marks that this component has no need for private buffers. Otherwise, component must
- /// add support for C2MaxPrivateBufferCountTuning, C2PrivateAllocatorsTuning and
- /// C2PrivateBlockPoolsTuning.
- void noPrivateBuffers();
-
- /// Marks that this component holds no references to input buffers. Otherwise, component
- /// must add support for C2StreamMaxReferenceAgeTuning::input and
- /// C2StreamMaxReferenceCountTuning::input.
- void noInputReferences();
-
- /// Marks that this component holds no references to output buffers. Otherwise, component
- /// must add support for C2StreamMaxReferenceAgeTuning::output and
- /// C2StreamMaxReferenceCountTuning::output.
- void noOutputReferences();
-
- /// Marks that this component does not stretch time. Otherwise, component
- /// must add support for C2ComponentTimeStretchTuning.
- void noTimeStretch();
-
- std::shared_ptr<C2ApiLevelSetting> mApiLevel;
- std::shared_ptr<C2ApiFeaturesSetting> mApiFeatures;
-
- std::shared_ptr<C2PlatformLevelSetting> mPlatformLevel;
- std::shared_ptr<C2PlatformFeaturesSetting> mPlatformFeatures;
-
- std::shared_ptr<C2ComponentNameSetting> mName;
- std::shared_ptr<C2ComponentAliasesSetting> mAliases;
- std::shared_ptr<C2ComponentKindSetting> mKind;
- std::shared_ptr<C2ComponentDomainSetting> mDomain;
- std::shared_ptr<C2ComponentAttributesSetting> mAttrib;
- std::shared_ptr<C2ComponentTimeStretchTuning> mTimeStretch;
-
- std::shared_ptr<C2PortMediaTypeSetting::input> mInputMediaType;
- std::shared_ptr<C2PortMediaTypeSetting::output> mOutputMediaType;
- std::shared_ptr<C2StreamBufferTypeSetting::input> mInputFormat;
- std::shared_ptr<C2StreamBufferTypeSetting::output> mOutputFormat;
-
- std::shared_ptr<C2PortRequestedDelayTuning::input> mRequestedInputDelay;
- std::shared_ptr<C2PortRequestedDelayTuning::output> mRequestedOutputDelay;
- std::shared_ptr<C2RequestedPipelineDelayTuning> mRequestedPipelineDelay;
-
- std::shared_ptr<C2PortActualDelayTuning::input> mActualInputDelay;
- std::shared_ptr<C2PortActualDelayTuning::output> mActualOutputDelay;
- std::shared_ptr<C2ActualPipelineDelayTuning> mActualPipelineDelay;
-
- std::shared_ptr<C2StreamMaxReferenceAgeTuning::input> mMaxInputReferenceAge;
- std::shared_ptr<C2StreamMaxReferenceCountTuning::input> mMaxInputReferenceCount;
- std::shared_ptr<C2StreamMaxReferenceAgeTuning::output> mMaxOutputReferenceAge;
- std::shared_ptr<C2StreamMaxReferenceCountTuning::output> mMaxOutputReferenceCount;
- std::shared_ptr<C2MaxPrivateBufferCountTuning> mMaxPrivateBufferCount;
-
- std::shared_ptr<C2PortStreamCountTuning::input> mInputStreamCount;
- std::shared_ptr<C2PortStreamCountTuning::output> mOutputStreamCount;
-
- std::shared_ptr<C2SubscribedParamIndicesTuning> mSubscribedParamIndices;
- std::shared_ptr<C2PortSuggestedBufferCountTuning::input> mSuggestedInputBufferCount;
- std::shared_ptr<C2PortSuggestedBufferCountTuning::output> mSuggestedOutputBufferCount;
-
- std::shared_ptr<C2CurrentWorkTuning> mCurrentWorkOrdinal;
- std::shared_ptr<C2LastWorkQueuedTuning::input> mLastInputQueuedWorkOrdinal;
- std::shared_ptr<C2LastWorkQueuedTuning::output> mLastOutputQueuedWorkOrdinal;
-
- std::shared_ptr<C2PortAllocatorsTuning::input> mInputAllocators;
- std::shared_ptr<C2PortAllocatorsTuning::output> mOutputAllocators;
- std::shared_ptr<C2PrivateAllocatorsTuning> mPrivateAllocators;
- std::shared_ptr<C2PortBlockPoolsTuning::output> mOutputPoolIds;
- std::shared_ptr<C2PrivateBlockPoolsTuning> mPrivatePoolIds;
-
- std::shared_ptr<C2TrippedTuning> mTripped;
- std::shared_ptr<C2OutOfMemoryTuning> mOutOfMemory;
-
- std::shared_ptr<C2PortConfigCounterTuning::input> mInputConfigCounter;
- std::shared_ptr<C2PortConfigCounterTuning::output> mOutputConfigCounter;
- std::shared_ptr<C2ConfigCounterTuning> mDirectConfigCounter;
- };
-};
-
-template<typename T>
-using SimpleInterface = SimpleC2Interface<T>;
-
-template<typename T, typename ...Args>
-std::shared_ptr<T> AllocSharedString(const Args(&... args), const char *str) {
- size_t len = strlen(str) + 1;
- std::shared_ptr<T> ret = T::AllocShared(len, args...);
- strcpy(ret->m.value, str);
- return ret;
-}
-
-template<typename T, typename ...Args>
-std::shared_ptr<T> AllocSharedString(const Args(&... args), const std::string &str) {
- std::shared_ptr<T> ret = T::AllocShared(str.length() + 1, args...);
- strcpy(ret->m.value, str.c_str());
- return ret;
-}
-
-template <typename T>
-struct Setter {
- typedef typename std::remove_reference<T>::type type;
-
- static C2R NonStrictValueWithNoDeps(
- bool mayBlock, C2InterfaceHelper::C2P<type> &me) {
- (void)mayBlock;
- return me.F(me.v.value).validatePossible(me.v.value);
- }
-
- static C2R NonStrictValuesWithNoDeps(
- bool mayBlock, C2InterfaceHelper::C2P<type> &me) {
- (void)mayBlock;
- C2R res = C2R::Ok();
- for (size_t ix = 0; ix < me.v.flexCount(); ++ix) {
- res.plus(me.F(me.v.m.values[ix]).validatePossible(me.v.m.values[ix]));
- }
- return res;
- }
-
- static C2R StrictValueWithNoDeps(
- bool mayBlock,
- const C2InterfaceHelper::C2P<type> &old,
- C2InterfaceHelper::C2P<type> &me) {
- (void)mayBlock;
- if (!me.F(me.v.value).supportsNow(me.v.value)) {
- me.set().value = old.v.value;
- }
- return me.F(me.v.value).validatePossible(me.v.value);
- }
-};
-
-} // namespace android
-
-#endif // ANDROID_SIMPLE_C2_INTERFACE_H_