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 <memory>
22 #include <vector>
23 
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 std::unique_ptr<TaskCase::Value> UniqueValue;
46     typedef std::unique_ptr<android::sp<Buffer> > UniqueBuffer;
47     /// construct Buffers and Values for calling builtin functions.
48     /// all constructed stuffs automatically deleted by the passed std::unique_ptrs.
49     bool prepareParams(std::vector<TaskProcess::Param>& list,
50             const bool* inputTypes,
51             std::unique_ptr<void_ptr[]>& ptrs,
52             std::unique_ptr<UniqueValue[]>& values,
53             std::unique_ptr<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         explicit Param(TaskCase::Value& val);
73         ParamType getType();
74         android::String8& getParamString();
75         TaskCase::Value& getValue();
76         TaskCase::Value* getValuePtr();
isIdType()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     std::unique_ptr<SignalProcessingInterface> mSp;
90 };
91 
92 
93 #endif // CTSAUDIO_TASKPROCESS_H
94