Home | History | Annotate | Download | only in 1.0
      1 /*
      2  * Copyright 2017, 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 #include <ios>
     18 #include <list>
     19 
     20 #include <android-base/logging.h>
     21 
     22 #include <media/stagefright/omx/1.0/Conversion.h>
     23 #include <media/stagefright/omx/1.0/OmxStore.h>
     24 #include <media/stagefright/xmlparser/MediaCodecsXmlParser.h>
     25 
     26 namespace android {
     27 namespace hardware {
     28 namespace media {
     29 namespace omx {
     30 namespace V1_0 {
     31 namespace implementation {
     32 
     33 OmxStore::OmxStore(
     34         const char* owner,
     35         const char* const* searchDirs,
     36         const char* mainXmlName,
     37         const char* performanceXmlName,
     38         const char* profilingResultsXmlPath) {
     39     MediaCodecsXmlParser parser(searchDirs,
     40             mainXmlName,
     41             performanceXmlName,
     42             profilingResultsXmlPath);
     43     mParsingStatus = toStatus(parser.getParsingStatus());
     44 
     45     const auto& serviceAttributeMap = parser.getServiceAttributeMap();
     46     mServiceAttributeList.resize(serviceAttributeMap.size());
     47     size_t i = 0;
     48     for (const auto& attributePair : serviceAttributeMap) {
     49         ServiceAttribute attribute;
     50         attribute.key = attributePair.first;
     51         attribute.value = attributePair.second;
     52         mServiceAttributeList[i] = std::move(attribute);
     53         ++i;
     54     }
     55 
     56     const auto& roleMap = parser.getRoleMap();
     57     mRoleList.resize(roleMap.size());
     58     i = 0;
     59     for (const auto& rolePair : roleMap) {
     60         RoleInfo role;
     61         role.role = rolePair.first;
     62         role.type = rolePair.second.type;
     63         role.isEncoder = rolePair.second.isEncoder;
     64         // TODO: Currently, preferPlatformNodes information is not available in
     65         // the xml file. Once we have a way to provide this information, it
     66         // should be parsed properly.
     67         role.preferPlatformNodes = rolePair.first.compare(0, 5, "audio") == 0;
     68         hidl_vec<NodeInfo>& nodeList = role.nodes;
     69         nodeList.resize(rolePair.second.nodeList.size());
     70         size_t j = 0;
     71         for (const auto& nodePair : rolePair.second.nodeList) {
     72             NodeInfo node;
     73             node.name = nodePair.second.name;
     74             node.owner = owner;
     75             hidl_vec<NodeAttribute>& attributeList = node.attributes;
     76             attributeList.resize(nodePair.second.attributeList.size());
     77             size_t k = 0;
     78             for (const auto& attributePair : nodePair.second.attributeList) {
     79                 NodeAttribute attribute;
     80                 attribute.key = attributePair.first;
     81                 attribute.value = attributePair.second;
     82                 attributeList[k] = std::move(attribute);
     83                 ++k;
     84             }
     85             nodeList[j] = std::move(node);
     86             ++j;
     87         }
     88         mRoleList[i] = std::move(role);
     89         ++i;
     90     }
     91 
     92     mPrefix = parser.getCommonPrefix();
     93 }
     94 
     95 OmxStore::~OmxStore() {
     96 }
     97 
     98 Return<void> OmxStore::listServiceAttributes(listServiceAttributes_cb _hidl_cb) {
     99     if (mParsingStatus == Status::NO_ERROR) {
    100         _hidl_cb(Status::NO_ERROR, mServiceAttributeList);
    101     } else {
    102         _hidl_cb(mParsingStatus, hidl_vec<ServiceAttribute>());
    103     }
    104     return Void();
    105 }
    106 
    107 Return<void> OmxStore::getNodePrefix(getNodePrefix_cb _hidl_cb) {
    108     _hidl_cb(mPrefix);
    109     return Void();
    110 }
    111 
    112 Return<void> OmxStore::listRoles(listRoles_cb _hidl_cb) {
    113     _hidl_cb(mRoleList);
    114     return Void();
    115 }
    116 
    117 Return<sp<IOmx>> OmxStore::getOmx(hidl_string const& omxName) {
    118     return IOmx::tryGetService(omxName);
    119 }
    120 
    121 }  // namespace implementation
    122 }  // namespace V1_0
    123 }  // namespace omx
    124 }  // namespace media
    125 }  // namespace hardware
    126 }  // namespace android
    127