khronosfws/openmax_al/src/adaptation/xastaticcapsadaptation.c
changeset 16 43d09473c595
parent 14 80975da52420
child 22 128eb6a32b84
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
     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 <gst.h>
       
    19 #include <string.h>
       
    20 #include <gstparamspecs.h>
       
    21 #include "XAStaticCapsAdaptation.h"
       
    22 
       
    23 #define AUD_D (XACAP_DECODER|XACAP_AUDIO)
       
    24 #define AUD_E (XACAP_ENCODER|XACAP_AUDIO)
       
    25 #define VID_D (XACAP_DECODER|XACAP_VIDEO)
       
    26 #define VID_E (XACAP_ENCODER|XACAP_VIDEO)
       
    27 #define IMG_D (XACAP_DECODER|XACAP_IMAGE)
       
    28 #define IMG_E (XACAP_ENCODER|XACAP_IMAGE)
       
    29 #define AUD_O (XACAP_DEVSNK|XACAP_AUDIO)
       
    30 #define AUD_I (XACAP_DEVSRC|XACAP_AUDIO)
       
    31 #define VID_O (XACAP_DEVSNK|XACAP_VIDEO)
       
    32 #define VID_I (XACAP_DEVSRC|XACAP_VIDEO)
       
    33 #define ANY 0x7FFFFFFF
       
    34 
       
    35 
       
    36 /* initially contains default "any"values, later filled in by querying GStreamer plugins */
       
    37 static XAStaticCapsData allCaps[] =
       
    38     {/* { type,  id,                        adaptId,            maxCh, minBPS, maxBPS, minSR, maxSR, minBR, maxBR, maxFR, maxW, maxH, extra }, */
       
    39      //   { AUD_D, XA_AUDIOCODEC_PCM,         (XAchar *)"audioparse",       0,0,0,0,0,0,0,0,0,0,0,0 },
       
    40         { AUD_E, XA_AUDIOCODEC_PCM,         NULL,                         0,0,0,0,0,0,0,0,0,0,0,0 },
       
    41      //   { AUD_D, XA_ADAPTID_VORBIS,         (XAchar *)"vorbisdec",        0,0,0,0,0,0,0,0,0,0,0,0 },
       
    42      //   { AUD_E, XA_ADAPTID_VORBIS,         (XAchar *)"vorbisenc",        0,0,0,0,0,0,0,0,0,0,0,0 },
       
    43      //   { VID_D, XA_ADAPTID_MOTIONJPEG,     (XAchar *)"jpegdec",          0,0,0,0,0,0,0,0,0,0,0,0 },
       
    44      //   { VID_E, XA_ADAPTID_MOTIONJPEG,     (XAchar *)"jpegenc",          0,0,0,0,0,0,0,0,0,0,0,0 },
       
    45      //   { VID_D, XA_ADAPTID_THEORA,         (XAchar *)"theoradec",        0,0,0,0,0,0,0,0,0,0,0,0 },
       
    46      //  { VID_E, XA_ADAPTID_THEORA,         (XAchar *)"theoraenc",        0,0,0,0,0,0,0,0,0,0,0,0 },
       
    47      //   { VID_D, XA_ADAPTID_RAWVIDEO,       (XAchar *)"videoparse",       0,0,0,0,0,0,0,0,0,0,0,0 },
       
    48         { VID_E, XA_ADAPTID_RAWVIDEO,       NULL,                         0,0,0,0,0,0,0,0,0,0,0,0 },
       
    49      //   { IMG_D, XA_IMAGECODEC_JPEG,        (XAchar *)"jpegdec",          0,0,0,0,0,0,0,0,0,0,0,0 },
       
    50      //   { IMG_E, XA_IMAGECODEC_JPEG,        (XAchar *)"jpegenc",          0,0,0,0,0,0,0,0,0,0,0,0 },
       
    51      //   { IMG_D, XA_IMAGECODEC_RAW,         (XAchar *)"videoparse",       0,0,0,0,0,0,0,0,0,0,0,0 },
       
    52         { IMG_E, XA_IMAGECODEC_RAW,         NULL,                         0,0,0,0,0,0,0,0,0,0,0,0 },
       
    53         { AUD_O, XA_ADAPTID_DEVSOUNDSINK,       (XAchar *)"devsoundsink",     0,0,0,0,0,0,0,0,0,0,0,0 },
       
    54         { AUD_I, XA_ADAPTID_DEVSOUNDSRC,        (XAchar *)"devsoundsrc",          0,0,0,0,0,0,0,0,0,0,0,0 },
       
    55       //  { AUD_O, XA_ADAPTID_ALSASINK,       (XAchar *)"alsasink",         0,0,0,0,0,0,0,0,0,0,0,0 },
       
    56       //  { AUD_I, XA_ADAPTID_ALSASRC,        (XAchar *)"alsasrc",          0,0,0,0,0,0,0,0,0,0,0,0 }
       
    57 //#ifdef XA_USE_TEST_PLUGINS
       
    58 //        ,{ AUD_I, XA_ADAPTID_AUDIOTESTSRC,   (XAchar *)"audiotestsrc",     0,0,0,0,0,0,0,0,0,0,0,0 }
       
    59 //#endif
       
    60     };
       
    61 
       
    62 /*
       
    63  * XAresult XAStaticCapsAdapt_ReadImageCaps(GstCaps* caps, XAStaticCapsData* data)
       
    64  */
       
    65 XAresult XAStaticCapsAdapt_ReadImageCaps(GstCaps* caps, XAStaticCapsData* data)
       
    66 {
       
    67     XAresult res = XA_RESULT_SUCCESS;
       
    68 
       
    69     XAuint32 widthMax = 0;
       
    70     XAuint32 heightMax = 0;
       
    71     gint capsCount = 0;
       
    72     gint iterator = 0;
       
    73     GstStructure *capsStruct = NULL;
       
    74     G_CONST_RETURN GValue* value = NULL;
       
    75 
       
    76     DEBUG_API("->XAStaticCapsAdapt_ReadImageCaps");
       
    77     capsCount = gst_caps_get_size( caps );
       
    78     for( iterator = 0; iterator < capsCount; iterator++ )
       
    79     {
       
    80         capsStruct = gst_caps_get_structure( caps, iterator );
       
    81 
       
    82         DEBUG_INFO_A1("Caps from gst: %s", gst_structure_to_string(capsStruct));
       
    83 
       
    84         if (gst_structure_n_fields( capsStruct ) > 0) /* Any check*/
       
    85         {
       
    86             value = gst_structure_get_value( capsStruct, "width" );
       
    87             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
    88             {
       
    89                 widthMax = gst_value_get_int_range_max( value );
       
    90                 DEBUG_INFO_A1("widthMax:%d",(int)widthMax);
       
    91             }
       
    92             else
       
    93             {
       
    94                 DEBUG_ERR("Cannot get width from capabilities struct");
       
    95                 DEBUG_API("<-XAStaticCapsAdapt_ReadImageCaps - XA_RESULT_INTERNAL_ERROR");
       
    96                 return XA_RESULT_INTERNAL_ERROR;
       
    97             }
       
    98 
       
    99             value = gst_structure_get_value( capsStruct, "height" );
       
   100             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   101             {
       
   102                 heightMax = gst_value_get_int_range_max( value );
       
   103                 DEBUG_INFO_A1("heightMax:%d",(int)heightMax);
       
   104             }
       
   105             else
       
   106             {
       
   107                 DEBUG_ERR("Cannot get height from capabilities struct");
       
   108                 DEBUG_API("<-XAStaticCapsAdapt_ReadImageCaps - XA_RESULT_INTERNAL_ERROR");
       
   109                 return XA_RESULT_INTERNAL_ERROR;
       
   110             }
       
   111 
       
   112             if (heightMax < data->maxH)
       
   113             {
       
   114                 data->maxH = heightMax;
       
   115             }
       
   116             if (widthMax < data->maxW)
       
   117             {
       
   118                 data->maxW = widthMax;
       
   119             }
       
   120         }
       
   121     }
       
   122     DEBUG_API("<-XAStaticCapsAdapt_ReadImageCaps");
       
   123     return res;
       
   124 }
       
   125 
       
   126 /*
       
   127  * XAresult XAStaticCapsAdapt_ReadAudioCaps(GstCaps* caps, XAStaticCapsData* data, GstElement* element)
       
   128  */
       
   129 XAresult XAStaticCapsAdapt_ReadAudioCaps(GstCaps* caps, XAStaticCapsData* data, GstElement* element)
       
   130 {
       
   131     XAresult res = XA_RESULT_SUCCESS;
       
   132 
       
   133     XAuint32 channelsMax = ANY;
       
   134     XAuint32 minRate = 0;
       
   135     XAuint32 maxRate = ANY;
       
   136     XAuint32 minBPS = 0;
       
   137     XAuint32 maxBPS = ANY;
       
   138     XAuint32 minBR = 0;
       
   139     XAuint32 maxBR = ANY;
       
   140     XAboolean intCapsUsed = XA_BOOLEAN_FALSE;
       
   141 
       
   142     gint capsCount = 0;
       
   143     gint iterator = 0;
       
   144     GstStructure *capsStruct = NULL;
       
   145     G_CONST_RETURN GValue* value = NULL;
       
   146     const char* capsName = NULL;
       
   147 
       
   148     DEBUG_API("->XAStaticCapsAdapt_ReadAudioCaps");
       
   149     capsCount = gst_caps_get_size( caps );
       
   150     for( iterator = 0; iterator < capsCount; iterator++ )
       
   151     {
       
   152         capsStruct = gst_caps_get_structure( caps, iterator );
       
   153 
       
   154         DEBUG_INFO_A1("Caps from gst: %s", gst_structure_to_string(capsStruct));
       
   155         capsName = gst_structure_get_name(capsStruct);
       
   156 
       
   157         if (intCapsUsed == XA_BOOLEAN_TRUE)
       
   158         {
       
   159             break; // preferred caps used 
       
   160         }
       
   161         else if (!strcmp( capsName,"audio/x-raw-int"))
       
   162         {
       
   163             intCapsUsed = XA_BOOLEAN_TRUE;
       
   164         }
       
   165 
       
   166         if (gst_structure_n_fields( capsStruct ) > 0) // Any check
       
   167         {
       
   168             value = gst_structure_get_value( capsStruct, "channels" );
       
   169             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   170             {
       
   171                 channelsMax = gst_value_get_int_range_max( value );
       
   172                 DEBUG_INFO_A1("channelsMax:%d",(int)channelsMax);
       
   173             }
       
   174             else if (G_VALUE_HOLDS_INT(value))
       
   175             {
       
   176                 channelsMax = g_value_get_int( value );
       
   177                 DEBUG_INFO_A1("channelsMax:%d",(int)channelsMax);
       
   178             }
       
   179             else
       
   180             {
       
   181                 DEBUG_ERR("Cannot get channels from capabilities struct");
       
   182                 DEBUG_API("<-XAStaticCapsAdapt_ReadAudioCaps - XA_RESULT_INTERNAL_ERROR");
       
   183                 return XA_RESULT_INTERNAL_ERROR;
       
   184             }
       
   185 
       
   186             value = gst_structure_get_value( capsStruct, "rate" );
       
   187             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   188             {
       
   189                 minRate = gst_value_get_int_range_min( value );
       
   190                 maxRate = gst_value_get_int_range_max( value );
       
   191                 DEBUG_INFO_A2("minRate:%d maxRate:%d",(int)minRate,(int)maxRate);
       
   192             }
       
   193             else
       
   194             {
       
   195                 DEBUG_ERR("Cannot get rates from capabilities struct");
       
   196                 DEBUG_API("<-XAStaticCapsAdapt_ReadAudioCaps - XA_RESULT_INTERNAL_ERROR");
       
   197                 return XA_RESULT_INTERNAL_ERROR;
       
   198             }
       
   199 
       
   200             value = gst_structure_get_value( capsStruct, "width" );
       
   201             if (GST_VALUE_HOLDS_LIST(value))
       
   202             {
       
   203                 XAuint32 count = 0;
       
   204                 XAuint32 i = 0;
       
   205                 XAuint32 bps = 0;
       
   206                 count = gst_value_list_get_size(value);
       
   207                 for (i = 0; i < count; i++  )
       
   208                 {
       
   209                     G_CONST_RETURN GValue* v = gst_value_list_get_value(value, i);
       
   210                     bps =  g_value_get_int(v);
       
   211                     if (bps < minBPS || i == 0)
       
   212                     {
       
   213                         minBPS = bps;
       
   214                     }
       
   215                     if (bps > maxBPS || i == 0)
       
   216                     {
       
   217                         maxBPS = bps;
       
   218                     }
       
   219                     DEBUG_INFO_A2("minBPS:%d maxBPS:%d",(int)minBPS,(int)maxBPS);
       
   220                 }
       
   221             }
       
   222             else if (G_VALUE_HOLDS_INT(value))
       
   223             {
       
   224                 minBPS = g_value_get_int(value);
       
   225                 maxBPS = g_value_get_int(value);
       
   226                 DEBUG_INFO_A2("minBPS:%d maxBPS:%d",(int)minBPS,(int)maxBPS);
       
   227             }
       
   228             else
       
   229             {
       
   230                 // if not there read from depth 
       
   231                 value = gst_structure_get_value( capsStruct, "depth" );
       
   232                 if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   233                 {
       
   234                     minBPS = gst_value_get_int_range_min( value );
       
   235                     maxBPS = gst_value_get_int_range_max( value );
       
   236                     DEBUG_INFO_A2("minBPS:%d maxBPS:%d",(int)minBPS,(int)maxBPS);
       
   237                 }
       
   238                 else
       
   239                 {
       
   240                     DEBUG_ERR("Cannot get width from capabilities struct");
       
   241                     DEBUG_API("<-XAStaticCapsAdapt_ReadAudioCaps - XA_RESULT_INTERNAL_ERROR");
       
   242                     return XA_RESULT_INTERNAL_ERROR;
       
   243                 }
       
   244             }
       
   245 
       
   246             value = gst_structure_get_value( capsStruct, "bitrate" );
       
   247             if( value && GST_VALUE_HOLDS_INT_RANGE(value) )
       
   248             {
       
   249                 minBR = gst_value_get_int_range_min( value );
       
   250                 maxBR = gst_value_get_int_range_max( value );
       
   251                 DEBUG_INFO_A2("minBR:%d maxBR:%d",(int)minBR,(int)maxBR);
       
   252             }
       
   253             else
       
   254             {
       
   255             	// TL: Replaced this code...
       
   256               /*  GParamSpec* param = g_object_class_find_property(G_OBJECT_GET_CLASS(element), "bitrate");
       
   257                 if(param && G_IS_PARAM_SPEC_INT(param))
       
   258                 {
       
   259                     GParamSpecInt *pint = G_PARAM_SPEC_INT (param);
       
   260                     if(pint->minimum>0) minBR = pint->minimum;
       
   261                     else minBR = 1;
       
   262                     maxBR = pint->maximum;
       
   263                 }
       
   264                 */
       
   265                 
       
   266                 // ...with this:
       
   267                 // GstBitRate *bitRate; // This object doesn't exist yet
       
   268                 // GObject *minBitRate = G_OBJECT(bitRate->minBitRate);
       
   269                 // GObject *maxBitRate = G_OBJECT(bitRate->maxBitRate);
       
   270                 //if (g_object_class_find_property(G_OBJECT_GET_CLASS(minBitRate), "bitrate"))
       
   271                 //{
       
   272                 //	if (minBitRate > 0)
       
   273                 //		minBR = minBitRate;
       
   274                 //	else
       
   275                 //		minBR = 1;
       
   276               	//}
       
   277               	//else
       
   278               	//	minBR = 0;
       
   279                 //if (g_object_class_find_property(G_OBJECT_GET_CLASS(maxBitRate), "bitrate"))             		
       
   280                 //	maxBR = maxBitRate;
       
   281                 // else
       
   282                 // maxBR = 0;
       
   283             }
       
   284 
       
   285             if (channelsMax < data->maxCh)
       
   286             {
       
   287                 data->maxCh = channelsMax;
       
   288             }
       
   289             if (minRate > data->minSR)
       
   290             {
       
   291                 data->minSR = minRate;
       
   292             }
       
   293             if (maxRate < data->maxSR)
       
   294             {
       
   295                 data->maxSR = maxRate;
       
   296             }
       
   297             if (minBPS > data->minBPS)
       
   298             {
       
   299                 data->minBPS = minBPS;
       
   300             }
       
   301             if (maxBPS < data->maxBPS)
       
   302             {
       
   303                 data->maxBPS = maxBPS;
       
   304             }
       
   305             if (minBR > data->minBR)
       
   306             {
       
   307                 data->minBR = minBR;
       
   308             }
       
   309             if (maxBR < data->maxBR)
       
   310             {
       
   311                 data->maxBR = maxBR;
       
   312             }
       
   313         }
       
   314     }
       
   315     
       
   316     DEBUG_API("<-XAStaticCapsAdapt_ReadAudioCaps");
       
   317     return res;
       
   318 }
       
   319 
       
   320 /*
       
   321  * XAresult XAStaticCapsAdapt_ReadVideoCaps(GstCaps* caps, XAStaticCapsData* data)
       
   322  */
       
   323 XAresult XAStaticCapsAdapt_ReadVideoCaps(GstCaps* caps, XAStaticCapsData* data)
       
   324 {
       
   325     XAresult res = XA_RESULT_SUCCESS;
       
   326 
       
   327     XAuint32 widthMax = ANY;
       
   328     XAuint32 heightMax = ANY;
       
   329     XAuint32 frMax = ANY;
       
   330     const GValue* framerate = NULL;
       
   331 
       
   332     gint capsCount = 0;
       
   333     gint iterator = 0;
       
   334     GstStructure *capsStruct = NULL;
       
   335     G_CONST_RETURN GValue* value = NULL;
       
   336 
       
   337     DEBUG_API("->XAStaticCapsAdapt_ReadVideoCaps");
       
   338     capsCount = gst_caps_get_size( caps );
       
   339     for( iterator = 0; iterator < capsCount; iterator++ )
       
   340     {
       
   341         capsStruct = gst_caps_get_structure( caps, iterator );
       
   342 
       
   343         DEBUG_INFO_A1("Caps from gst: %s", gst_structure_to_string(capsStruct));
       
   344 
       
   345         if (gst_structure_n_fields( capsStruct ) > 0) /* Any check*/
       
   346         {
       
   347             value = gst_structure_get_value( capsStruct, "width" );
       
   348             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   349             {
       
   350               widthMax = gst_value_get_int_range_max( value );
       
   351               DEBUG_INFO_A1("widthMax:%d",(int)widthMax);
       
   352             }
       
   353             else
       
   354             {
       
   355               DEBUG_ERR("Cannot get width from capabilities struct");
       
   356               DEBUG_API("<-XAStaticCapsAdapt_ReadVideoCaps - XA_RESULT_INTERNAL_ERROR");
       
   357               return XA_RESULT_INTERNAL_ERROR;
       
   358             }
       
   359 
       
   360             value = gst_structure_get_value( capsStruct, "height" );
       
   361             if (GST_VALUE_HOLDS_INT_RANGE(value))
       
   362             {
       
   363               heightMax = gst_value_get_int_range_max( value );
       
   364               DEBUG_INFO_A1("heightMax:%d",(int)heightMax);
       
   365             }
       
   366             else
       
   367             {
       
   368               DEBUG_ERR("Cannot get height from capabilities struct");
       
   369               DEBUG_API("<-XAStaticCapsAdapt_ReadVideoCaps - XA_RESULT_INTERNAL_ERROR");
       
   370               return XA_RESULT_INTERNAL_ERROR;
       
   371             }
       
   372 
       
   373             value = gst_structure_get_value( capsStruct, "framerate" );
       
   374             if (GST_VALUE_HOLDS_FRACTION_RANGE(value))
       
   375             {
       
   376               framerate = gst_value_get_fraction_range_max( value );
       
   377               frMax = gst_value_get_fraction_numerator( framerate );
       
   378               DEBUG_INFO_A1("frMax:%d",(int)frMax);
       
   379             }
       
   380             else
       
   381             {
       
   382               DEBUG_ERR("Cannot get height from capabilities struct");
       
   383               DEBUG_API("<-XAStaticCapsAdapt_ReadVideoCaps - XA_RESULT_INTERNAL_ERROR");
       
   384               return XA_RESULT_INTERNAL_ERROR;
       
   385             }
       
   386 
       
   387             if (heightMax < data->maxH)
       
   388             {
       
   389               data->maxH = heightMax;
       
   390             }
       
   391             if (widthMax < data->maxW)
       
   392             {
       
   393               data->maxW = widthMax;
       
   394             }
       
   395             if (frMax < data->maxFR)
       
   396             {
       
   397               data->maxFR = frMax;
       
   398             }
       
   399         }
       
   400     }
       
   401 
       
   402     DEBUG_API("<-XAStaticCapsAdapt_ReadVideoCaps");
       
   403     return res;
       
   404 }
       
   405 
       
   406 /*
       
   407  * XAresult XAStaticCapsAdapt_ReadAudioIOCaps(GstCaps* caps, XAStaticCapsData* data)
       
   408  */
       
   409 XAresult XAStaticCapsAdapt_ReadAudioIOCaps(GstCaps* caps, XAStaticCapsData* data)
       
   410 {
       
   411     XAresult res = XA_RESULT_SUCCESS;
       
   412 
       
   413     XAuint32 minSR = 0;
       
   414     XAuint32 maxSR = ANY;
       
   415     gint capsCount = 0;
       
   416     gint iterator = 0;
       
   417     GstStructure *capsStruct = NULL;
       
   418 
       
   419     const char* capsName = NULL;
       
   420     XAuint32 depth = 0;
       
   421 
       
   422     DEBUG_API("->XAStaticCapsAdapt_ReadAudioIOCaps");
       
   423     capsCount = gst_caps_get_size( caps );
       
   424     for( iterator = 0; iterator < capsCount; iterator++ )
       
   425     {
       
   426         capsStruct = gst_caps_get_structure( caps, iterator );
       
   427 
       
   428         DEBUG_INFO_A1("Caps from gst: %s", gst_structure_to_string(capsStruct));
       
   429 
       
   430         capsName = gst_structure_get_name(capsStruct);
       
   431         if (!strcmp(capsName, "audio/x-raw-int"))
       
   432         {
       
   433             if (gst_structure_get_int( capsStruct, "depth", (gint*)&depth))
       
   434             {
       
   435                 DEBUG_INFO_A1("depth:%d",(int)depth);
       
   436             }
       
   437             else
       
   438             {
       
   439                 DEBUG_ERR("Cannot get depth from capabilities struct");
       
   440                 DEBUG_API("<-XAStaticCapsAdapt_ReadAudioIOCaps - XA_RESULT_INTERNAL_ERROR");
       
   441                 return XA_RESULT_INTERNAL_ERROR;
       
   442             }
       
   443             if (minSR == 0 && maxSR == 0)
       
   444             {
       
   445                 minSR = depth;
       
   446                 maxSR = depth;
       
   447             }
       
   448             else
       
   449             {
       
   450                 if (depth < minSR)
       
   451                 {
       
   452                     minSR = depth;
       
   453                 }
       
   454                 if (depth > maxSR)
       
   455                 {
       
   456                     maxSR = depth;
       
   457                 }
       
   458             }
       
   459             switch (depth)
       
   460             {
       
   461             case XA_PCMSAMPLEFORMAT_FIXED_8:
       
   462                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_8;
       
   463                 break;
       
   464             case XA_PCMSAMPLEFORMAT_FIXED_16:
       
   465                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_16;
       
   466                 break;
       
   467             case XA_PCMSAMPLEFORMAT_FIXED_20:
       
   468                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_20;
       
   469                 break;
       
   470             case XA_PCMSAMPLEFORMAT_FIXED_24:
       
   471                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_24;
       
   472                 break;
       
   473             case XA_PCMSAMPLEFORMAT_FIXED_28:
       
   474                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_28;
       
   475                 break;
       
   476             case XA_PCMSAMPLEFORMAT_FIXED_32:
       
   477                 data->pcmProfilesSupported |= XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_32;
       
   478                 break;
       
   479             default:
       
   480                 DEBUG_ERR("Invalid depth");
       
   481                 DEBUG_API("<-XAStaticCapsAdapt_ReadAudioIOCaps - XA_RESULT_INTERNAL_ERROR");
       
   482                 return XA_RESULT_INTERNAL_ERROR;
       
   483             }
       
   484         }
       
   485     }
       
   486     data->minSR = minSR;
       
   487     data->maxSR = maxSR;
       
   488 
       
   489 
       
   490     DEBUG_API("<-XAStaticCapsAdapt_ReadAudioIOCaps");
       
   491     return res;
       
   492 }
       
   493 
       
   494 /*
       
   495  * XAresult XAStaticCapsAdapt_GetCapsFromGst(XAStaticCapsData* data)
       
   496  */
       
   497 XAresult XAStaticCapsAdapt_GetCapsFromGst(XAStaticCapsData* data)
       
   498 {
       
   499     XAresult res = XA_RESULT_SUCCESS;
       
   500     GstCaps* caps = NULL;
       
   501     GstPad* pad = NULL;
       
   502     GstPad* pads[2] = {NULL, NULL};
       
   503     GstElement* element = NULL;
       
   504     XAuint32 padCount = 2; /* default src/sink */
       
   505     XAuint32 padLoop = 0;
       
   506 
       
   507     DEBUG_API("->XAStaticCapsAdapt_GetCapsFromGst");
       
   508 
       
   509     /* by default no constraints */
       
   510     data->maxCh = ANY;
       
   511     data->minBPS = 0;
       
   512     data->maxBPS = ANY;
       
   513     data->minSR = 0;
       
   514     data->maxSR = ANY;
       
   515     data->minBR = 0;
       
   516     data->maxBR = ANY;
       
   517     data->maxFR = ANY;
       
   518     data->maxW = ANY;
       
   519     data->maxH = ANY;
       
   520     data->extra = 0;
       
   521     data->pcmProfilesSupported = 0;
       
   522     data->numBitrates = 0;
       
   523 
       
   524     if (data->xaid == XA_AUDIOCODEC_PCM)
       
   525     {
       
   526         data->extra = XA_AUDIOPROFILE_PCM;
       
   527     }
       
   528 
       
   529     if (data->adaptId != NULL)
       
   530     {
       
   531         element =  gst_element_factory_make( (char *)data->adaptId, (char *)data->adaptId);
       
   532         if (!element)
       
   533         {
       
   534             DEBUG_ERR("Cannot make gst element!");
       
   535             DEBUG_API("<-XAStaticCapsAdapt_GetelementCaps - XA_RESULT_INTERNAL_ERROR");
       
   536             return XA_RESULT_INTERNAL_ERROR;
       
   537         }
       
   538 
       
   539         if (data->captype == AUD_I || data->captype == AUD_O)
       
   540         {
       
   541             padCount = 1;
       
   542             if (data->captype == AUD_I)
       
   543             {
       
   544                 pads[0] = gst_element_get_static_pad( element, "src");
       
   545             }
       
   546             else
       
   547             {
       
   548                 pads[0] = gst_element_get_static_pad( element, "sink");
       
   549             }
       
   550         }
       
   551         else
       
   552         {
       
   553             padCount = 2;
       
   554             pads[0] = gst_element_get_static_pad( element, "sink");
       
   555             pads[1] = gst_element_get_static_pad( element, "src");
       
   556         }
       
   557 
       
   558         if (!pads[0] || (!pads[1] && padCount == 2))
       
   559         {
       
   560             DEBUG_ERR("Cannot get pad!");
       
   561             DEBUG_API("<-XAStaticCapsAdapt_GetCapsFromGst - XA_RESULT_INTERNAL_ERROR");
       
   562             return XA_RESULT_INTERNAL_ERROR;
       
   563         }
       
   564 
       
   565         for (padLoop = 0; padLoop < padCount; padLoop++)
       
   566         {
       
   567             pad = pads[padLoop];
       
   568 
       
   569             caps = gst_pad_get_caps( pad );
       
   570             if( !caps )
       
   571             {
       
   572                 DEBUG_ERR("Cannot receive caps from pad!");
       
   573                 DEBUG_API("<-XAStaticCapsAdapt_GetCapsFromGst - XA_RESULT_INTERNAL_ERROR");
       
   574                 return XA_RESULT_INTERNAL_ERROR;
       
   575             }
       
   576 
       
   577             if (data->captype & XACAP_IMAGE)
       
   578             {
       
   579                 res = XAStaticCapsAdapt_ReadImageCaps(caps, data);
       
   580             }
       
   581             else if(data->captype & XACAP_AUDIO)
       
   582             {
       
   583                 res = XAStaticCapsAdapt_ReadAudioCaps(caps, data, element);
       
   584             }
       
   585             else if(data->captype & XACAP_VIDEO)
       
   586             {
       
   587                 res = XAStaticCapsAdapt_ReadVideoCaps(caps, data);
       
   588             }
       
   589             if (data->captype == AUD_I || data->captype == AUD_O)
       
   590             {
       
   591                 res = XAStaticCapsAdapt_ReadAudioIOCaps(caps, data);
       
   592             }
       
   593         }
       
   594     }
       
   595 
       
   596     DEBUG_API("<-XAStaticCapsAdapt_GetCapsFromGst");
       
   597     return res;
       
   598 }
       
   599 
       
   600 /*
       
   601  * XAresult XAStaticCapsAdapt_InitCaps()
       
   602  */
       
   603 XAresult XAStaticCapsAdapt_InitCaps()
       
   604 {
       
   605     XAresult res = XA_RESULT_SUCCESS;
       
   606     XAuint32 i = 0;
       
   607     XAuint32 capCount = (sizeof(allCaps)/sizeof(XAStaticCapsData));
       
   608     DEBUG_API("->XAStaticCapsAdapt_InitCaps");
       
   609 
       
   610     for( i = 0; i < capCount; i++)
       
   611     {
       
   612         res = XAStaticCapsAdapt_GetCapsFromGst(&allCaps[i]);
       
   613         if (res != XA_RESULT_SUCCESS)
       
   614         {
       
   615             DEBUG_API("<-XAStaticCapsAdapt_InitCaps");
       
   616             return res;
       
   617         }
       
   618     }
       
   619 
       
   620     DEBUG_API("<-XAStaticCapsAdapt_InitCaps");
       
   621     return res;
       
   622 }
       
   623 
       
   624 /* XAresult XAStaticCapsAdapt_GetCapsCount
       
   625  * Description: Count capabilities of certain type. Filter is specified by
       
   626  *              bitmasking XACapsType values.
       
   627  */
       
   628 XAresult XAStaticCapsAdapt_GetCapsCount(XACapsType filter, XAuint32 *count)
       
   629 {
       
   630     XAresult res = XA_RESULT_SUCCESS;
       
   631     XAuint32 capCount = (sizeof(allCaps)/sizeof(XAStaticCapsData));
       
   632     DEBUG_API("->XAStaticCapsAdapt_GetCapsCount");
       
   633     if(!count)
       
   634     {
       
   635         res = XA_RESULT_PARAMETER_INVALID;
       
   636     }
       
   637     else
       
   638     {
       
   639         XAuint32 i = 0;
       
   640         (*count)=0;
       
   641         for( i=0; i<capCount; i++ )
       
   642         {
       
   643             if ( (allCaps[i].captype & filter) == filter )
       
   644             {
       
   645                 (*count)++;
       
   646             }
       
   647         }
       
   648     }
       
   649     DEBUG_API("<-XAStaticCapsAdapt_GetCapsCount");
       
   650     return res;
       
   651 }
       
   652 
       
   653 /* XAresult XAStaticCapsAdapt_GetCapsById
       
   654  * Description: Get capabilities of type XACapsType and matching id
       
   655  */
       
   656 XAresult XAStaticCapsAdapt_GetCapsById(XACapsType filter, XAuint32 maxId, XAStaticCapsData* data)
       
   657 {
       
   658     XAresult res = XA_RESULT_SUCCESS;
       
   659     XAuint32 capCount = (sizeof(allCaps)/sizeof(XAStaticCapsData));
       
   660     DEBUG_API("->XAStaticCapsAdapt_GetCapsById");
       
   661     if(!data)
       
   662     {
       
   663         res = XA_RESULT_PARAMETER_INVALID;
       
   664     }
       
   665     else
       
   666     {
       
   667         XAuint32 i = 0;
       
   668         XAboolean found = XA_BOOLEAN_FALSE;
       
   669         for( i=0; i<capCount; i++ )
       
   670         {
       
   671             if ( ((allCaps[i].captype & filter) == filter) && (maxId==allCaps[i].xaid) )
       
   672             {
       
   673                 memcpy(data, &allCaps[i], sizeof(XAStaticCapsData));
       
   674                 found = XA_BOOLEAN_TRUE;
       
   675                 break;
       
   676             }
       
   677         }
       
   678         if(!found)
       
   679         {
       
   680            res = XA_RESULT_FEATURE_UNSUPPORTED;
       
   681         }
       
   682     }
       
   683     DEBUG_API("<-XAStaticCapsAdapt_GetCapsById");
       
   684     return res;
       
   685 }
       
   686 
       
   687 /* XAresult XAStaticCapsAdapt_GetCapsByIdx
       
   688  * Description: Get n'th capabilities of type XACapsType
       
   689  */
       
   690 XAresult XAStaticCapsAdapt_GetCapsByIdx(XACapsType filter, XAuint32 idx, XAStaticCapsData* data)
       
   691 {
       
   692     XAresult res = XA_RESULT_SUCCESS;
       
   693     XAuint32 capCount = (sizeof(allCaps)/sizeof(XAStaticCapsData));
       
   694     DEBUG_API("->XAStaticCapsAdapt_GetCapsByIdx");
       
   695     if(!data)
       
   696     {
       
   697         res = XA_RESULT_PARAMETER_INVALID;
       
   698     }
       
   699     else
       
   700     {
       
   701         XAuint32 i = 0,j=0;
       
   702         XAboolean found = XA_BOOLEAN_FALSE;
       
   703         for( i=0; i<capCount; i++ )
       
   704         {
       
   705             if ( (allCaps[i].captype & filter) == filter )
       
   706             {
       
   707                 if( idx == j++ )
       
   708                 {
       
   709                     memcpy(data, &allCaps[i], sizeof(XAStaticCapsData));
       
   710                     found = XA_BOOLEAN_TRUE;
       
   711                     break;
       
   712                 }
       
   713             }
       
   714         }
       
   715         if(!found)
       
   716         {
       
   717            res = XA_RESULT_PARAMETER_INVALID;
       
   718         }
       
   719     }
       
   720     DEBUG_API("<-XAStaticCapsAdapt_GetCapsByIdx");
       
   721     return res;
       
   722 }
       
   723 
       
   724 /* XAresult XAStaticCapsAdapt_QueryColorFormats
       
   725  * Description: Get color formats associated with the XA_IMAGECODEC_RAW codec.
       
   726  */
       
   727 XAresult XAStaticCapsAdapt_QueryColorFormats(XAuint32* pIndex, XAuint32* pColorFormats)
       
   728 {
       
   729     XAresult res = XA_RESULT_SUCCESS;
       
   730     DEBUG_API("->XAStaticCapsAdapt_QueryColorFormats");
       
   731 
       
   732     if( !pIndex )
       
   733     {
       
   734         DEBUG_ERR("illegal NULL parameter");
       
   735         res = XA_RESULT_PARAMETER_INVALID;
       
   736     }
       
   737     else
       
   738     {
       
   739         XAStaticCapsData temp;
       
   740         res = XAStaticCapsAdapt_GetCapsById(XACAP_ENCODER|XACAP_IMAGE, XA_IMAGECODEC_RAW, &temp);
       
   741         if( res == XA_RESULT_SUCCESS )
       
   742         {
       
   743             if( !pColorFormats )
       
   744             {   /* query number of color formats */
       
   745                 *pIndex = 1; /* one used by camera context */
       
   746             }
       
   747             else
       
   748             {   /* query color format */
       
   749                 if( *pIndex >= 1 ) /* one used by camera context */
       
   750                 {
       
   751                     DEBUG_ERR("index parameter invalid");
       
   752                     res = XA_RESULT_PARAMETER_INVALID;
       
   753                 }
       
   754                 else
       
   755                 {   /* internal format used by pipeline, look camera context for details  */
       
   756                     *pColorFormats = XA_COLORFORMAT_YUV420PLANAR;
       
   757                 }
       
   758             }
       
   759         }
       
   760         else
       
   761         {
       
   762             *pIndex = 0;
       
   763         }
       
   764     }
       
   765 
       
   766     DEBUG_API("<-XAStaticCapsAdapt_QueryColorFormats");
       
   767     return res;
       
   768 }
       
   769