Home | History | Annotate | Download | only in omx
      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 //#define LOG_NDEBUG 0
     18 #define LOG_TAG "OMXUtils"
     19 
     20 #include <string.h>
     21 
     22 #include <media/hardware/HardwareAPI.h>
     23 #include <media/stagefright/MediaErrors.h>
     24 #include "OMXUtils.h"
     25 
     26 namespace android {
     27 
     28 status_t StatusFromOMXError(OMX_ERRORTYPE err) {
     29     switch (err) {
     30         case OMX_ErrorNone:
     31             return OK;
     32         case OMX_ErrorUnsupportedSetting:
     33         case OMX_ErrorUnsupportedIndex:
     34             return ERROR_UNSUPPORTED; // this is a media specific error
     35         case OMX_ErrorInsufficientResources:
     36             return NO_MEMORY;
     37         case OMX_ErrorInvalidComponentName:
     38         case OMX_ErrorComponentNotFound:
     39             return NAME_NOT_FOUND;
     40         default:
     41             return UNKNOWN_ERROR;
     42     }
     43 }
     44 
     45 /**************************************************************************************************/
     46 
     47 DescribeColorFormatParams::DescribeColorFormatParams(const DescribeColorFormat2Params &params) {
     48     InitOMXParams(this);
     49 
     50     eColorFormat = params.eColorFormat;
     51     nFrameWidth = params.nFrameWidth;
     52     nFrameHeight = params.nFrameHeight;
     53     nStride = params.nStride;
     54     nSliceHeight = params.nSliceHeight;
     55     bUsingNativeBuffers = params.bUsingNativeBuffers;
     56     // we don't copy media images as this conversion is only used pre-query
     57 };
     58 
     59 void DescribeColorFormat2Params::initFromV1(const DescribeColorFormatParams &params) {
     60     InitOMXParams(this);
     61 
     62     eColorFormat = params.eColorFormat;
     63     nFrameWidth = params.nFrameWidth;
     64     nFrameHeight = params.nFrameHeight;
     65     nStride = params.nStride;
     66     nSliceHeight = params.nSliceHeight;
     67     bUsingNativeBuffers = params.bUsingNativeBuffers;
     68     sMediaImage.initFromV1(params.sMediaImage);
     69 };
     70 
     71 void MediaImage2::initFromV1(const MediaImage &image) {
     72     memset(this, 0, sizeof(*this));
     73 
     74     if (image.mType != MediaImage::MEDIA_IMAGE_TYPE_YUV) {
     75         mType = MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN;
     76         return;
     77     }
     78 
     79     for (size_t ix = 0; ix < image.mNumPlanes; ++ix) {
     80         if (image.mPlane[ix].mHorizSubsampling > INT32_MAX
     81                 || image.mPlane[ix].mVertSubsampling > INT32_MAX) {
     82             mType = MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN;
     83             return;
     84         }
     85     }
     86 
     87     mType = (MediaImage2::Type)image.mType;
     88     mNumPlanes = image.mNumPlanes;
     89     mWidth = image.mWidth;
     90     mHeight = image.mHeight;
     91     mBitDepth = image.mBitDepth;
     92     mBitDepthAllocated = 8;
     93     for (size_t ix = 0; ix < image.mNumPlanes; ++ix) {
     94         mPlane[ix].mOffset = image.mPlane[ix].mOffset;
     95         mPlane[ix].mColInc = image.mPlane[ix].mColInc;
     96         mPlane[ix].mRowInc = image.mPlane[ix].mRowInc;
     97         mPlane[ix].mHorizSubsampling = (int32_t)image.mPlane[ix].mHorizSubsampling;
     98         mPlane[ix].mVertSubsampling = (int32_t)image.mPlane[ix].mVertSubsampling;
     99     }
    100 }
    101 
    102 /**************************************************************************************************/
    103 
    104 }  // namespace android
    105 
    106