Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright (C) 2018 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 ANDROID_STAGEFRIGHT_C2PARAM_INTERNAL_H_
     18 #define ANDROID_STAGEFRIGHT_C2PARAM_INTERNAL_H_
     19 
     20 #include <C2Param.h>
     21 
     22 struct C2_HIDE _C2ParamInspector {
     23     inline static uint32_t GetOffset(const C2FieldDescriptor &fd) {
     24         return fd._mFieldId._mOffset;
     25     }
     26 
     27     inline static void SetOffset(C2FieldDescriptor &fd, uint32_t offset) {
     28         fd._mFieldId._mOffset = offset;
     29     }
     30 
     31     inline static uint32_t GetEndOffset(const C2FieldDescriptor &fd, uint32_t paramSize = 0) {
     32         uint32_t endOffset = fd._mFieldId._mOffset + fd._mExtent * fd._mFieldId._mSize;
     33         /// for flex parameters return paramSize if given
     34         return fd._mExtent ? endOffset : std::max(endOffset, paramSize);
     35     }
     36 
     37     inline static uint32_t GetSize(const C2FieldDescriptor &fd) {
     38         return fd._mFieldId._mSize;
     39     }
     40 
     41     inline static uint32_t GetIndex(const C2ParamField &pf) {
     42         return pf._mIndex;
     43     }
     44 
     45     inline static uint32_t GetOffset(const C2ParamField &pf) {
     46         return pf._mFieldId._mOffset;
     47     }
     48 
     49     inline static uint32_t GetSize(const C2ParamField &pf) {
     50         return pf._mFieldId._mSize;
     51     }
     52 
     53     inline static uint32_t GetOffset(const _C2FieldId &f) {
     54         return f._mOffset;
     55     }
     56 
     57     inline static uint32_t GetSize(const _C2FieldId &f) {
     58         return f._mSize;
     59     }
     60 
     61     inline static _C2FieldId GetField(const C2FieldDescriptor &fd) {
     62         return fd._mFieldId;
     63     }
     64 
     65     inline static uint32_t GetAttrib(const C2ParamDescriptor &pd) {
     66         return pd._mAttrib;
     67     }
     68 
     69     inline static _C2FieldId GetField(const C2ParamField &pf) {
     70         return pf._mFieldId;
     71     }
     72 
     73     inline static
     74     C2ParamField CreateParamField(C2Param::Index index, uint32_t offset, uint32_t size) {
     75         return C2ParamField(index, offset, size);
     76     }
     77 
     78     inline static
     79     C2ParamField CreateParamField(C2Param::Index index, _C2FieldId field) {
     80         return C2ParamField(index, field._mOffset, field._mSize);
     81     }
     82 
     83     inline static
     84     void TrimParam(C2Param *param, uint32_t newSize) {
     85         if (param && *param && param->size() > newSize && newSize >= sizeof(C2Param)) {
     86             param->_mSize = newSize;
     87         }
     88     }
     89 
     90     inline static void AddNamedValues(
     91             C2FieldDescriptor &fd, C2FieldDescriptor::NamedValuesType &&namedValues) {
     92         fd._mNamedValues = std::move(namedValues);
     93     }
     94 
     95     inline static
     96     C2StructDescriptor CreateStructDescriptor(C2Param::CoreIndex index,
     97                                         std::vector<C2FieldDescriptor> &&fields) {
     98         return C2StructDescriptor(index, std::move(fields));
     99     }
    100 
    101     inline static
    102     C2FieldDescriptor OffsetFieldDescriptor(const C2FieldDescriptor &fd, size_t offset) {
    103         return C2FieldDescriptor(fd, offset);
    104     }
    105 
    106     // expose attributes
    107     typedef C2ParamDescriptor::attrib_t attrib_t;
    108 };
    109 
    110 #endif // ANDROID_STAGEFRIGHT_C2PARAM_INTERNAL_H_
    111 
    112