khronosfws/openmax_al/src/gst_adaptation/xaaudioencoderitfadaptation.c
changeset 32 94fc26b6e006
parent 31 8dfd592727cb
child 33 5e8b14bae8c3
equal deleted inserted replaced
31:8dfd592727cb 32:94fc26b6e006
    54                 sizeof(XAAudioEncoderSettings));
    54                 sizeof(XAAudioEncoderSettings));
    55         }DEBUG_API("<-XAAudioEncoderItfAdapt_SetEncoderSettings");
    55         }DEBUG_API("<-XAAudioEncoderItfAdapt_SetEncoderSettings");
    56     return ret;
    56     return ret;
    57     }
    57     }
    58 
    58 
       
    59 static gboolean
       
    60 populate_field_settings (GQuark field, const GValue * value, gpointer pfx)
       
    61 {
       
    62     gchar *field_name ;
       
    63    
       
    64     gpointer *pfxd = (gpointer*)pfx;
       
    65     XAMediaRecorderAdaptationCtx *ctxx = (XAMediaRecorderAdaptationCtx *) *pfxd;
       
    66 
       
    67     field_name = (gchar*)g_quark_to_string (field);
       
    68   
       
    69   if((strcasecmp((const char*)field_name,"channels") == 0))
       
    70       {
       
    71           if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
       
    72              {
       
    73                   (ctxx)->audioEncSettings.channelsIn = gst_value_get_int_range_max (value);
       
    74                   (ctxx)->audioEncSettings.channelsOut = gst_value_get_int_range_max (value);
       
    75              }else
       
    76                  {
       
    77                  (ctxx)->audioEncSettings.channelsIn = g_value_get_int(value);
       
    78                  (ctxx)->audioEncSettings.channelsOut = g_value_get_int(value);
       
    79                  }
       
    80 
       
    81       }                
       
    82   if((strcasecmp((const char*)field_name,"depth") == 0))
       
    83       {
       
    84           if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
       
    85             {
       
    86                 (ctxx)->audioEncSettings.bitsPerSample = gst_value_get_int_range_min (value);
       
    87             }else
       
    88             {
       
    89                 (ctxx)->audioEncSettings.bitsPerSample = g_value_get_int(value);
       
    90             }
       
    91       }
       
    92   if((strcasecmp((const char*)field_name,"endianness") == 0))
       
    93       {
       
    94           if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
       
    95         {
       
    96             (ctxx)->audioEncSettings.blockAlignment = gst_value_get_int_range_min (value);
       
    97         }else
       
    98         {
       
    99             (ctxx)->audioEncSettings.blockAlignment = g_value_get_int(value);
       
   100         }
       
   101       }
       
   102   if((strcasecmp((const char*)field_name,"bitrate") == 0))
       
   103       {
       
   104       if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
       
   105           {
       
   106               (ctxx)->audioEncSettings.bitRate = gst_value_get_int_range_min (value);
       
   107           }else
       
   108           {
       
   109               (ctxx)->audioEncSettings.bitRate = g_value_get_int(value);
       
   110           }
       
   111   
       
   112       }
       
   113   if((strcasecmp((const char*)field_name,"rate") == 0))
       
   114       {
       
   115         if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
       
   116             {
       
   117                 (ctxx)->audioEncSettings.sampleRate = gst_value_get_int_range_min (value)*1000;
       
   118             }else
       
   119                 {
       
   120                 (ctxx)->audioEncSettings.sampleRate = g_value_get_int(value) * 1000;
       
   121                 }
       
   122 
       
   123         }
       
   124 
       
   125 return TRUE;
       
   126 }
    59 XAresult XAAudioEncoderItfAdapt_GetEncoderSettings(XAAdaptationBaseCtx *bCtx,
   127 XAresult XAAudioEncoderItfAdapt_GetEncoderSettings(XAAdaptationBaseCtx *bCtx,
    60         XAAudioEncoderSettings *pSettings)
   128         XAAudioEncoderSettings *pSettings)
    61     {
   129     {
    62     XAMediaRecorderAdaptationCtx* mCtx = NULL;
   130     XAMediaRecorderAdaptationCtx* mCtx = NULL;
    63     XAresult ret = XA_RESULT_SUCCESS;
   131     XAresult ret = XA_RESULT_SUCCESS;
       
   132     
       
   133     GstElement *encoderelement=NULL,*actualencoder=NULL;
       
   134     GstPad * encoderpad = NULL;
       
   135     GstCaps *encodercaps =NULL;
       
   136     GstStructure *structure = NULL;
       
   137     XAAdaptationGstCtx *ctx = NULL;
       
   138     int value = -1 ;
    64 
   139 
    65     DEBUG_API("->XAAudioEncoderItfAdapt_GetEncoderSettings");
   140     DEBUG_API("->XAAudioEncoderItfAdapt_GetEncoderSettings");
    66     if (!bCtx || (bCtx->ctxId != XAMediaRecorderAdaptation) || !pSettings)
   141     if (!bCtx || (bCtx->ctxId != XAMediaRecorderAdaptation) || !pSettings)
    67         {
   142         {
    68         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
   143         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
    69         return XA_RESULT_PARAMETER_INVALID;
   144         return XA_RESULT_PARAMETER_INVALID;
    70         }
   145         }
    71     mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
   146     mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
    72     memcpy(pSettings, &(mCtx->audioEncSettings),
   147     ctx = (XAAdaptationGstCtx *)bCtx; 
    73             sizeof(XAAudioEncoderSettings));
   148     
       
   149     encoderelement = gst_bin_get_by_name((GstBin*)ctx->bin ,"mrcodecbin");
       
   150     if (encoderelement != NULL)
       
   151     {   
       
   152         encoderpad = gst_element_get_pad(encoderelement , "sink");
       
   153         if(encoderpad != NULL){
       
   154             encodercaps = gst_pad_get_negotiated_caps(encoderpad);
       
   155             if(encodercaps == NULL)
       
   156                 {
       
   157                 //pipeline is not in playing state , so getting allowed caps
       
   158                 encodercaps = gst_pad_get_allowed_caps(encoderpad);
       
   159                 }
       
   160         }
       
   161         else{
       
   162             DEBUG_ERR("No pad named sink in codecbin pad");
       
   163         }
       
   164         if(encodercaps != NULL && encodercaps->structs->len > 0)
       
   165         {    
       
   166         structure = gst_caps_get_structure (encodercaps, 0);
       
   167         } 
       
   168         else{
       
   169           DEBUG_ERR("no allowed caps for encoderelement");
       
   170         }
       
   171         
       
   172       //populate the values based on neotiated caps or allowed caps. 
       
   173       gst_structure_foreach (structure, populate_field_settings, (gpointer) &mCtx);
       
   174       
       
   175       //finding the actual encoder.
       
   176       if(mCtx->codecbin != NULL){
       
   177         actualencoder = gst_bin_get_by_name((GstBin*)mCtx->codecbin ,"audioenc");
       
   178       }
       
   179       //finding bitrate property
       
   180       if(value == -1 && actualencoder != NULL)
       
   181             {
       
   182             //search in encoder element , property is there or not?
       
   183                 g_object_get(G_OBJECT (actualencoder), "bitrate", &value,NULL);
       
   184              }
       
   185       if(mCtx->audioEncSettings.encoderId == XA_AUDIOCODEC_AMR)
       
   186           {
       
   187           g_object_get(G_OBJECT (mCtx->audiosource), "speechbitrate", &value,NULL);
       
   188           }
       
   189        if(value != -1)
       
   190             {
       
   191                mCtx->audioEncSettings.bitRate = value;
       
   192                value =-1;
       
   193             }
       
   194        
       
   195        //finding profile property        
       
   196         if(value == -1 && actualencoder != NULL)
       
   197             {
       
   198                 g_object_get(G_OBJECT (actualencoder), "profile", &value,NULL);
       
   199             }
       
   200         if(value != -1)
       
   201           {
       
   202                 mCtx->audioEncSettings.levelSetting = value;
       
   203                 value =-1;
       
   204           }
       
   205         
       
   206         //finding output-format property
       
   207         if(value == -1 && actualencoder != NULL)
       
   208           {
       
   209                 //try to see search in encoder element , property is there or not?
       
   210                g_object_get(G_OBJECT (actualencoder), "output-format", &value,NULL);
       
   211           }
       
   212         if(value != -1)
       
   213           {
       
   214                 mCtx->audioEncSettings.streamFormat = value;
       
   215                 value =-1;
       
   216           }
       
   217         
       
   218         
       
   219         //setting these settings to default.
       
   220         mCtx->audioEncSettings.channelMode=0;
       
   221         mCtx->audioEncSettings.rateControl = XA_RATECONTROLMODE_CONSTANTBITRATE;
       
   222         mCtx->audioEncSettings.encodeOptions = 0;
       
   223         
       
   224     //unref the caps, pads , elements      
       
   225     if(encodercaps != NULL)
       
   226     gst_caps_unref(encodercaps);
       
   227     if(encoderpad!= NULL)
       
   228     gst_object_unref(encoderpad);
       
   229     if(actualencoder!= NULL)
       
   230     gst_object_unref (actualencoder);
       
   231     if(encoderelement!= NULL)
       
   232     gst_object_unref (encoderelement);
       
   233     }else{
       
   234         DEBUG_ERR("Codecbin element Not found ");
       
   235     }
       
   236     memcpy(pSettings, &(mCtx->audioEncSettings), 
       
   237 							sizeof(XAAudioEncoderSettings));
    74     DEBUG_API("<-XAAudioEncoderItfAdapt_GetEncoderSettings");
   238     DEBUG_API("<-XAAudioEncoderItfAdapt_GetEncoderSettings");
    75     return ret;
   239     return ret;
    76     }
   240     }