khronosfws/openmax_al/src/engine/xavideodecodercapabilitiesitf.c
changeset 33 5e8b14bae8c3
parent 28 ebf79c79991a
child 36 73253677b50a
equal deleted inserted replaced
28:ebf79c79991a 33:5e8b14bae8c3
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <assert.h>
       
    21 #include <string.h>
       
    22 
       
    23 
       
    24 #include "xaglobals.h"
       
    25 #include "xavideodecodercapabilitiesitf.h"
       
    26 #include "xacapabilitiesmgr.h"   
       
    27 
       
    28 
       
    29 /* XAVideoDecoderCapabilitiesItfImpl* GetImpl
       
    30  * Description: Validate interface pointer and cast it to implementation pointer.
       
    31  */
       
    32 static XAVideoDecoderCapabilitiesItfImpl* GetImpl(XAVideoDecoderCapabilitiesItf self)
       
    33 {
       
    34     if( self )
       
    35     {
       
    36         XAVideoDecoderCapabilitiesItfImpl* impl = (XAVideoDecoderCapabilitiesItfImpl*)(*self);
       
    37         if( impl && (impl == impl->self) )
       
    38         {
       
    39             return impl;
       
    40         }
       
    41     }
       
    42     return NULL;
       
    43 }
       
    44 
       
    45 /**
       
    46  * Base interface XAVideoDecoderCapabilitiesItf implementation
       
    47  **/
       
    48 
       
    49 /* XAresult XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoders
       
    50  * Description: Retrieves available video decoders.
       
    51  */
       
    52 XAresult XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoders(
       
    53                             XAVideoDecoderCapabilitiesItf self,
       
    54                             XAuint32* pNumDecoders,
       
    55                             XAuint32* pDecoderIds)
       
    56 {
       
    57     XAVideoDecoderCapabilitiesItfImpl* impl = NULL;
       
    58     XAresult res = XA_RESULT_SUCCESS;
       
    59 
       
    60     DEBUG_API("->XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoders");
       
    61 
       
    62     impl = GetImpl(self);
       
    63     if( !impl || !pNumDecoders )
       
    64     {
       
    65         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    66         res = XA_RESULT_PARAMETER_INVALID;
       
    67     }
       
    68     else
       
    69     {
       
    70         if( pDecoderIds )
       
    71         {   /* query array of decoders */
       
    72             if( *pNumDecoders < impl->numCodecs )
       
    73             {
       
    74                 DEBUG_ERR("XA_RESULT_BUFFER_INSUFFICIENT");
       
    75                 res = XA_RESULT_BUFFER_INSUFFICIENT;
       
    76             }
       
    77             else
       
    78             {
       
    79                 
       
    80   
       
    81                 XAuint32 i = 0;
       
    82                 XACapabilities temp;
       
    83                 for( i=0; i<impl->numCodecs; i++ )
       
    84                 {
       
    85                     /* query decoder id from adaptation using index value */
       
    86                     XACapabilitiesMgr_GetCapsByIdx(NULL, (XACapsType)(XACAP_DECODER|XACAP_VIDEO), i, &temp);
       
    87                     pDecoderIds[i] = temp.xaid;
       
    88                 }
       
    89 
       
    90             }
       
    91         }
       
    92         /* return number of decoders */
       
    93         *pNumDecoders = impl->numCodecs;
       
    94     }
       
    95 
       
    96     DEBUG_API("<-XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoders");
       
    97     return res;
       
    98 }
       
    99 
       
   100 /* XAresult XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoderCapabilities
       
   101  * Description: Retrieves video decoder capabilities.
       
   102  */
       
   103 XAresult XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoderCapabilities(
       
   104                             XAVideoDecoderCapabilitiesItf self,
       
   105                             XAuint32 decoderId,
       
   106                             XAuint32* pIndex,
       
   107                             XAVideoCodecDescriptor* pDescriptor)
       
   108 {
       
   109     XAVideoDecoderCapabilitiesItfImpl* impl = NULL;
       
   110     XAresult res = XA_RESULT_SUCCESS;
       
   111     DEBUG_API("->XAVideoDecoderCapabilitiesItfImpl_GetDecoderCapabilities");
       
   112     impl = GetImpl(self);
       
   113 
       
   114     if( !impl || !pIndex )
       
   115     {
       
   116         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   117         res = XA_RESULT_PARAMETER_INVALID;
       
   118     }
       
   119     else
       
   120     {
       
   121         if( !pDescriptor )
       
   122         {   /* query number of capa structures */
       
   123             *pIndex = 1;
       
   124         }
       
   125         else
       
   126         {   /* query capabilities */
       
   127             if( *pIndex >= 1 )
       
   128             {
       
   129                 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   130                 res = XA_RESULT_PARAMETER_INVALID;
       
   131             }
       
   132             else
       
   133             {
       
   134                 /* query capabilities from adaptation using codec id */
       
   135   
       
   136                 XACapabilities temp;
       
   137                 memset(pDescriptor,0,sizeof(XAVideoCodecDescriptor));
       
   138                 res = XACapabilitiesMgr_GetCapsById(NULL, (XACapsType)(XACAP_DECODER|XACAP_VIDEO), decoderId, &temp);
       
   139                 if( res == XA_RESULT_SUCCESS )
       
   140                 {
       
   141                     XAVideoCodecDescriptor* desc = (XAVideoCodecDescriptor*)(&temp.pEntry);
       
   142                     /* map applicable values to XAVideoCodecCapabilities */
       
   143                     pDescriptor->codecId = temp.xaid;
       
   144                     pDescriptor->maxWidth = desc->maxWidth;
       
   145                     pDescriptor->maxHeight = desc->maxHeight;
       
   146                     pDescriptor->maxFrameRate = (desc->maxFrameRate & 0xffff)<<16;
       
   147                     pDescriptor->maxBitRate = desc->maxBitRate;
       
   148                     /*other caps undefined*/
       
   149                     pDescriptor->rateControlSupported = 0; /* reserved in decoders */
       
   150                     pDescriptor->profileSetting = 0; /* unknown for theora or motionjpeg */
       
   151                     pDescriptor->levelSetting = 0; /* unknown for theora or motionjpeg */
       
   152                 }
       
   153 
       
   154             }
       
   155         }
       
   156     }
       
   157 
       
   158     DEBUG_API("<-XAVideoDecoderCapabilitiesItfImpl_GetDecoderCapabilities");
       
   159     return res;
       
   160 }
       
   161 
       
   162 /**
       
   163  * XAVideoDecoderCapabilitiesItfImpl -specific methods
       
   164  **/
       
   165 
       
   166 /* XAVideoDecoderCapabilitiesItfImpl_Create
       
   167  * Description: Allocate and initialize XAVideoDecoderCapabilitiesItfImpl
       
   168  */
       
   169 XAVideoDecoderCapabilitiesItfImpl* XAVideoDecoderCapabilitiesItfImpl_Create()
       
   170 {
       
   171     XAVideoDecoderCapabilitiesItfImpl* self = (XAVideoDecoderCapabilitiesItfImpl*)
       
   172         calloc(1,sizeof(XAVideoDecoderCapabilitiesItfImpl));
       
   173     DEBUG_API("->XAVideoDecoderCapabilitiesItfImpl_Create");
       
   174 
       
   175     if( self )
       
   176     {
       
   177         /* init itf default implementation */
       
   178         self->itf.GetVideoDecoders =
       
   179             XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoders;
       
   180         self->itf.GetVideoDecoderCapabilities =
       
   181             XAVideoDecoderCapabilitiesItfImpl_GetVideoDecoderCapabilities;
       
   182 
       
   183   
       
   184         /* init variables */
       
   185         assert( XACapabilitiesMgr_GetCapsCount( NULL, (XACapsType)(XACAP_DECODER|XACAP_VIDEO),
       
   186                                   &(self->numCodecs) ) == XA_RESULT_SUCCESS );
       
   187 
       
   188         self->self = self;
       
   189     }
       
   190     DEBUG_API("<-XAVideoDecoderCapabilitiesItfImpl_Create");
       
   191     return self;
       
   192 }
       
   193 
       
   194 /* void XAVideoDecoderCapabilitiesItfImpl_Free
       
   195  * Description: Free all resources reserved at XAVideoDecoderCapabilitiesItfImpl_Create
       
   196  */
       
   197 void XAVideoDecoderCapabilitiesItfImpl_Free(XAVideoDecoderCapabilitiesItfImpl* self)
       
   198 {
       
   199     DEBUG_API("->XAVideoDecoderCapabilitiesItfImpl_Free");
       
   200     assert(self==self->self);
       
   201     free(self);
       
   202     DEBUG_API("<-XAVideoDecoderCapabilitiesItfImpl_Free");
       
   203 }