Home | History | Annotate | Download | only in task
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 
     18 #ifndef CTSAUDIO_TASKPROCESS_H
     19 #define CTSAUDIO_TASKPROCESS_H
     20 
     21 #include <vector>
     22 
     23 #include <UniquePtr.h>
     24 #include <utils/StrongPointer.h>
     25 
     26 #include "audio/Buffer.h"
     27 #include "TaskGeneric.h"
     28 #include "TaskCase.h"
     29 #include "BuiltinProcessing.h"
     30 #include "SignalProcessingInterface.h"
     31 
     32 class TaskProcess: public TaskGeneric {
     33 public:
     34     TaskProcess();
     35     virtual ~TaskProcess();
     36     virtual TaskGeneric::ExecutionResult run();
     37     virtual bool parseAttribute(const android::String8& name, const android::String8& value);
     38 private:
     39     TaskGeneric::ExecutionResult doRun(bool builtin);
     40 
     41     class Param;
     42     bool parseParams(std::vector<Param>& list, const char* str, bool isInput);
     43     //typedef necessary to prevent compiler's confusion
     44     typedef void* void_ptr;
     45     typedef UniquePtr<TaskCase::Value> UniqueValue;
     46     typedef UniquePtr<android::sp<Buffer> > UniqueBuffer;
     47     /// construct Buffers and Values for calling builtin functions.
     48     /// all constructed stuffs automatically deleted by the passed UniquePtrs
     49     bool prepareParams(std::vector<TaskProcess::Param>& list,
     50             const bool* inputTypes,
     51             UniquePtr<void_ptr, DefaultDelete<void_ptr[]> > & ptrs,
     52             UniquePtr<UniqueValue, DefaultDelete<UniqueValue[]> > & values,
     53             UniquePtr<UniqueBuffer, DefaultDelete<UniqueBuffer[]> > & buffers,
     54             bool isInput);
     55 
     56 private:
     57     enum ProcessType {
     58         EBuiltin,
     59         EScript
     60     };
     61     ProcessType mType;
     62     android::String8 mName; // buit-in function or script name
     63 
     64     enum ParamType {
     65         EId,
     66         EVal,
     67         EConst
     68     };
     69     class Param {
     70     public:
     71         Param(ParamType type, android::String8& string);
     72         Param(TaskCase::Value& val);
     73         ParamType getType();
     74         android::String8& getParamString();
     75         TaskCase::Value& getValue();
     76         TaskCase::Value* getValuePtr();
     77         inline bool isIdType() {
     78             return (mType == EId);
     79         }
     80     private:
     81         ParamType mType;
     82         android::String8 mString;
     83         TaskCase::Value mValue;
     84     };
     85 
     86     std::vector<Param> mInput;
     87     std::vector<Param> mOutput;
     88     BuiltinProcessing mBuiltin;
     89     UniquePtr<SignalProcessingInterface> mSp;
     90 };
     91 
     92 
     93 #endif // CTSAUDIO_TASKPROCESS_H
     94