Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of 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,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef C2WORK_H_
     18 
     19 #define C2WORK_H_
     20 
     21 #include <stdint.h>
     22 #include <stdbool.h>
     23 #include <C2Param.h>
     24 #include <C2Buffer.h>
     25 #include <C2Config.h>
     26 
     27 #include <memory>
     28 #include <list>
     29 #include <vector>
     30 
     31 typedef int status_t;
     32 
     33 namespace android {
     34 
     35 /// \defgroup work Work and data processing
     36 /// @{
     37 
     38 struct C2SettingResult {
     39     enum Failure {
     40         READ_ONLY,  ///< parameter is read-only and cannot be set
     41         MISMATCH,   ///< parameter mismatches input data
     42         BAD_VALUE,  ///< parameter does not accept value
     43         BAD_TYPE,   ///< parameter is not supported
     44         BAD_PORT,   ///< parameter is not supported on the specific port
     45         BAD_INDEX,  ///< parameter is not supported on the specific stream
     46         CONFLICT,   ///< parameter is in conflict with another setting
     47     };
     48 
     49     C2ParamField field;
     50     Failure failure;
     51     std::unique_ptr<C2FieldSupportedValues> supportedValues; //< if different from normal (e.g. in conflict w/another param or input data)
     52     std::list<C2ParamField> conflictingFields;
     53 };
     54 
     55 // ================================================================================================
     56 //  WORK
     57 // ================================================================================================
     58 
     59 // node_id-s
     60 typedef uint32_t node_id;
     61 
     62 enum flags_t : uint32_t {
     63     BUFFERFLAG_CODEC_CONFIG,
     64     BUFFERFLAG_DROP_FRAME,
     65     BUFFERFLAG_END_OF_STREAM,
     66 };
     67 
     68 enum {
     69     kParamIndexWorkOrdinal,
     70 };
     71 
     72 struct C2WorkOrdinalStruct {
     73     uint64_t timestamp;
     74     uint64_t frame_index;    // submission ordinal on the initial component
     75     uint64_t custom_ordinal; // can be given by the component, e.g. decode order
     76 
     77     DEFINE_AND_DESCRIBE_C2STRUCT(WorkOrdinal)
     78     C2FIELD(timestamp, "timestamp")
     79     C2FIELD(frame_index, "frame-index")
     80     C2FIELD(custom_ordinal, "custom-ordinal")
     81 };
     82 
     83 struct C2BufferPack {
     84 //public:
     85     flags_t  flags;
     86     C2WorkOrdinalStruct ordinal;
     87     std::vector<std::shared_ptr<C2Buffer>> buffers;
     88     //< for initial work item, these may also come from the parser - if provided
     89     //< for output buffers, these are the responses to requestedInfos
     90     std::list<std::unique_ptr<C2Info>>       infos;
     91     std::list<std::shared_ptr<C2InfoBuffer>> infoBuffers;
     92 };
     93 
     94 struct C2Worklet {
     95 //public:
     96     // IN
     97     node_id component;
     98 
     99     std::list<std::unique_ptr<C2Param>> tunings; //< tunings to be applied before processing this
    100                                                  // worklet
    101     std::list<C2Param::Type> requestedInfos;
    102     std::vector<std::shared_ptr<C2BlockAllocator>> allocators; //< This vector shall be the same size as
    103                                                           //< output.buffers.
    104 
    105     // OUT
    106     C2BufferPack output;
    107     std::list<std::unique_ptr<C2SettingResult>> failures;
    108 };
    109 
    110 /**
    111  * This structure holds information about all a single work item.
    112  *
    113  * This structure shall be passed by the client to the component for the first worklet. As such,
    114  * worklets must not be empty. The ownership of this object is passed.
    115  *
    116  * input:
    117  *      The input data to be processed. This is provided by the client with ownership. When the work
    118  *      is returned, the input buffer-pack's buffer vector shall contain nullptrs.
    119  *
    120  * worklets:
    121  *      The chain of components and associated allocators, tunings and info requests that the data
    122  *      must pass through. If this has more than a single element, the tunnels between successive
    123  *      components of the worklet chain must have been (successfully) pre-registered at the time
    124  *      the work is submitted. Allocating the output buffers in the worklets is the responsibility
    125  *      of each component. Upon work submission, each output buffer-pack shall be an appropriately
    126  *      sized vector containing nullptrs. When the work is completed/returned to the client,
    127  *
    128  * worklets_processed:
    129  *      It shall be initialized to 0 by the client when the work is submitted.
    130  *      It shall contain the number of worklets that were successfully processed when the work is
    131  *      returned. If this is less then the number of worklets, result must not be success.
    132  *      It must be in the range of [0, worklets.size()].
    133  *
    134  * result:
    135  *      The final outcome of the work. If 0 when work is returned, it is assumed that all worklets
    136  *      have been processed.
    137  */
    138 struct C2Work {
    139 //public:
    140     // pre-chain infos (for portions of a tunneling chain that happend before this work-chain for
    141     // this work item - due to framework facilitated (non-tunneled) work-chaining)
    142     std::list<std::pair<std::unique_ptr<C2PortMimeConfig>, std::unique_ptr<C2Info>>> preChainInfos;
    143     std::list<std::pair<std::unique_ptr<C2PortMimeConfig>, std::unique_ptr<C2Buffer>>> preChainInfoBlobs;
    144 
    145     C2BufferPack input;
    146     std::list<std::unique_ptr<C2Worklet>> worklets;
    147 
    148     uint32_t worklets_processed;
    149     status_t result;
    150 };
    151 
    152 struct C2WorkOutline {
    153 //public:
    154     C2WorkOrdinalStruct ordinal;
    155     std::list<node_id> chain;
    156 };
    157 
    158 /// @}
    159 
    160 }  // namespace android
    161 
    162 #endif  // C2WORK_H_
    163