gst_plugins_symbian/gst/devsound/devsoundsrcwrapper.cpp
branchRCL_3
changeset 29 567bb019e3e3
parent 2 5505e8908944
child 30 7e817e7e631c
equal deleted inserted replaced
6:9b2c3c7a1a9c 29:567bb019e3e3
    25 #include <mmcccodecinformation.h>
    25 #include <mmcccodecinformation.h>
    26 #include "debugtracemacros.h"
    26 #include "debugtracemacros.h"
    27 
    27 
    28 DevSoundWrapperSrc::DevSoundWrapperSrc()
    28 DevSoundWrapperSrc::DevSoundWrapperSrc()
    29     {
    29     {
    30     init_complete = 0;
    30     //init_complete = 0;
    31     dev_sound = NULL;
    31     dev_sound = NULL;
    32     buffersize = 0;
    32     buffersize = 0;
    33     dev_count = 0;
    33     dev_count = 0;
       
    34     speechbitrate = 0;
    34     caps.iRate = EMMFSampleRate8000Hz;
    35     caps.iRate = EMMFSampleRate8000Hz;
    35     caps.iEncoding = EMMFSoundEncoding16BitPCM;
    36     caps.iEncoding = EMMFSoundEncoding16BitPCM;
    36     caps.iChannels = EMMFMono;
    37     caps.iChannels = EMMFMono;
    37     fourcc = KMMFFourCCCodePCM16;
    38     fourcc = KMMFFourCCCodePCM16;
    38     iCallbackError = KErrNone;
    39     iCallbackError = KErrNone;
    46 void DevSoundWrapperSrc::InitializeComplete(TInt aError)
    47 void DevSoundWrapperSrc::InitializeComplete(TInt aError)
    47     {
    48     {
    48     TRACE_PRN_FN_ENT;
    49     TRACE_PRN_FN_ENT;
    49     TRequestStatus* stat = &(AL->iStatus);
    50     TRequestStatus* stat = &(AL->iStatus);
    50 
    51 
    51     if (aError == KErrNone)
    52     iCallbackError = aError;
    52         {
       
    53         init_complete = 1;
       
    54         }
       
    55     else
       
    56         {
       
    57         init_complete = 0;
       
    58         }
       
    59 
       
    60     User::RequestComplete(stat, aError);
    53     User::RequestComplete(stat, aError);
    61     TRACE_PRN_FN_EXT;
    54     TRACE_PRN_FN_EXT;
    62     }
    55     }
    63 /************************************************************/
    56 /************************************************************/
    64 
    57 
    72     }
    65     }
    73 /*******************************************************/
    66 /*******************************************************/
    74 
    67 
    75 void DevSoundWrapperSrc::BufferToBeEmptied(CMMFBuffer* aBuffer)
    68 void DevSoundWrapperSrc::BufferToBeEmptied(CMMFBuffer* aBuffer)
    76     {
    69     {
    77 //    TRACE_PRN_FN_ENT;
    70     TRACE_PRN_FN_ENT;
    78 
    71 
    79     buffer = aBuffer;
    72     buffer = aBuffer;
    80     bufferreadpos = 0;
    73     bufferreadpos = 0;
    81     CMMFDataBuffer* buf = STATIC_CAST (CMMFDataBuffer*, buffer);
    74     CMMFDataBuffer* buf = STATIC_CAST (CMMFDataBuffer*, buffer);
    82     buffersize = buf->Data().Length();
    75     buffersize = buf->Data().Length();
    91     else
    84     else
    92         {
    85         {
    93         User::RequestComplete(stat, KErrNotFound);
    86         User::RequestComplete(stat, KErrNotFound);
    94         iCallbackError = KErrNotFound;
    87         iCallbackError = KErrNotFound;
    95         }
    88         }
    96 //    TRACE_PRN_FN_EXT;
    89     TRACE_PRN_FN_EXT;
    97     }
    90     }
    98 /********************************************************/
    91 /********************************************************/
    99 
    92 
   100 void DevSoundWrapperSrc::RecordError(TInt aError)
    93 void DevSoundWrapperSrc::RecordError(TInt aError)
   101     {
    94     {
   102     TRACE_PRN_FN_ENT;
    95     TRACE_PRN_FN_ENT;
   103     TRACE_PRN_N1(_L("DevSoundWrapperSrc::RecordError %d"),aError);
    96     TRACE_PRN_N1(_L("DevSoundWrapperSrc::RecordError %d"),aError);
   104     iCallbackError = aError;
    97     iCallbackError = aError;
       
    98     TRequestStatus* stat = &(AL->iStatus);
       
    99     /// need to check this, error can occure before and after calling 
       
   100     /// the StartActiveScheduler and might and might not be waiting for 
       
   101     /// completing the request
       
   102     if( AL->IsActive() )
       
   103         {
       
   104     /// need to complete the request for coming out from blocking call.
       
   105         User::RequestComplete(stat, aError);
       
   106         iCallbackError = aError;    
       
   107         }
   105     TRACE_PRN_FN_EXT;
   108     TRACE_PRN_FN_EXT;
   106     }
   109     }
   107 /**********************************************************/
   110 /**********************************************************/
   108 
   111 
   109 void DevSoundWrapperSrc::ConvertError(TInt /*aError*/)
   112 void DevSoundWrapperSrc::ConvertError(TInt /*aError*/)
   174 
   177 
   175 /*******************************************************/
   178 /*******************************************************/
   176 int initialize_devsound(GstDevsoundSrc* ds)
   179 int initialize_devsound(GstDevsoundSrc* ds)
   177     {
   180     {
   178     TRACE_PRN_FN_ENT;
   181     TRACE_PRN_FN_ENT;
   179     int ret = 0;
       
   180     DevSoundWrapperSrc* handle = (DevSoundWrapperSrc*) ds->handle;
   182     DevSoundWrapperSrc* handle = (DevSoundWrapperSrc*) ds->handle;
   181 
   183 
   182     handle->AL->InitialiseActiveListener();
   184     handle->AL->InitialiseActiveListener();
   183 
   185 
   184         TRAP(ret, handle->dev_sound->InitializeL(*handle, handle->fourcc, EMMFStateRecording));
   186         TRAP(handle->iCallbackError, handle->dev_sound->InitializeL(*handle, handle->fourcc, EMMFStateRecording));
   185 
   187 
   186     if (ret)
   188     if ( handle->iCallbackError )
   187         {
   189         {
   188         TRACE_PRN_FN_EXT;
   190         TRACE_PRN_FN_EXT;
   189         return ret;
   191         return handle->iCallbackError;
   190         }
   192         }
   191 
   193 
   192     handle->AL->StartActiveScheduler();
   194     handle->AL->StartActiveScheduler();
   193 
   195 
   194     if (handle->init_complete == 1)
   196     if (KErrNone == handle->iCallbackError )
   195         {
   197         {
   196         TMMFPrioritySettings temp;
   198         TMMFPrioritySettings temp;
   197         temp.iPref = (TMdaPriorityPreference) ds->preference;
   199         temp.iPref = (TMdaPriorityPreference) ds->preference;
   198         temp.iPriority = ds->priority;
   200         temp.iPriority = ds->priority;
   199         handle->dev_sound->SetPrioritySettings(temp);
   201         handle->dev_sound->SetPrioritySettings(temp);
   200 
   202 
   201         SetConfigurations(handle);
   203         handle->iCallbackError = SetConfigurations(handle);
   202         ret = KErrNone;
   204         }
       
   205 
       
   206     TRACE_PRN_IF_ERR(handle->iCallbackError);
       
   207     TRACE_PRN_FN_EXT;
       
   208     return handle->iCallbackError;
       
   209     }
       
   210 /*********************************************************/
       
   211 
       
   212 int stop_devsound(GstDevsoundSrc *ds)
       
   213     {
       
   214     TRACE_PRN_FN_ENT;
       
   215     DevSoundWrapperSrc* handle = (DevSoundWrapperSrc*) ds->handle;
       
   216     handle->dev_sound->Stop();
       
   217     TRACE_PRN_FN_EXT;
       
   218     return 0;
       
   219     }
       
   220 
       
   221 int pause_devsound(GstDevsoundSrc *ds)
       
   222     {
       
   223     TRACE_PRN_FN_ENT;
       
   224     DevSoundWrapperSrc* handle = (DevSoundWrapperSrc*) ds->handle;
       
   225     handle->dev_sound->Pause();
       
   226     TRACE_PRN_FN_EXT;
       
   227     return 0;
       
   228     }
       
   229 
       
   230 int resume_devsound(GstDevsoundSrc *ds)
       
   231     {
       
   232     TRACE_PRN_FN_ENT;
       
   233     DevSoundWrapperSrc* handle = (DevSoundWrapperSrc*) ds->handle;
       
   234     if(handle->dev_sound->IsResumeSupported())
       
   235         {
       
   236         handle->iCallbackError = handle->dev_sound->Resume();
   203         }
   237         }
   204     else
   238     else
   205         {
   239         {
   206         ret = KErrNotFound;
   240         if( KErrNone == recordinit(handle) )
   207         }
   241             initproperties(ds);
   208 
   242         }
   209     TRACE_PRN_IF_ERR(ret);
   243     TRACE_PRN_FN_EXT;
   210     TRACE_PRN_FN_EXT;
   244     return 0;
   211     return ret;
   245     }
   212     }
       
   213 /*********************************************************/
       
   214 
   246 
   215 int open_device(DevSoundWrapperSrc **handle)
   247 int open_device(DevSoundWrapperSrc **handle)
   216     {
   248     {
   217     int retcode = KErrNone;
   249     (*handle)->iCallbackError = KErrNone;
   218     TRACE_PRN_FN_ENT;
   250     TRACE_PRN_FN_ENT;
   219 
   251 
   220     (*handle)->dev_count++;
   252     (*handle)->dev_count++;
   221 
   253 
   222     (*handle)->as = CActiveScheduler::Current();
   254     (*handle)->as = CActiveScheduler::Current();
   231         }
   263         }
   232 
   264 
   233     (*handle)->AL = new CActiveListener;
   265     (*handle)->AL = new CActiveListener;
   234     ((*handle)->AL)->asw = new CActiveSchedulerWait();
   266     ((*handle)->AL)->asw = new CActiveSchedulerWait();
   235 
   267 
   236         TRAP( retcode,(*handle)->dev_sound = CMMFDevSound::NewL() );
   268         TRAP( (*handle)->iCallbackError,(*handle)->dev_sound = CMMFDevSound::NewL() );
   237 
   269 
   238     if (!(*handle)->AL || !((*handle)->AL)->asw || !(*handle)->dev_sound
   270     if (!(*handle)->AL || !((*handle)->AL)->asw || !(*handle)->dev_sound
   239             || !(*handle)->as)
   271             || !(*handle)->as)
   240         {
   272         {
   241         retcode = KErrNoMemory;
   273         return KErrNoMemory;
   242         }
   274         }
   243 
   275     
   244     TRACE_PRN_FN_EXT;
   276     TRAP((*handle)->iCallbackError ,(*handle)->iAudoInputRecord = CAudioInput::NewL(*(*handle)->dev_sound));
   245 
   277     if ( KErrNone == (*handle)->iCallbackError )
   246     return retcode;
   278 	{
       
   279 	RArray<CAudioInput::TAudioInputPreference> inputArray;
       
   280     inputArray.Append( CAudioInput::EDefaultMic );
       
   281     // Set Audio Input
       
   282     (*handle)->iAudoInputRecord->SetAudioInputL( inputArray.Array( ) );
       
   283     inputArray.Close();
       
   284 	}
       
   285     TRACE_PRN_FN_EXT;
       
   286 
       
   287     return (*handle)->iCallbackError;
   247     }
   288     }
   248 
   289 
   249 /*********************************************************/
   290 /*********************************************************/
   250 
   291 
   251 int close_devsound(GstDevsoundSrc *ds)
   292 int close_devsound(GstDevsoundSrc *ds)
   252     {
   293     {
   253     TRACE_PRN_FN_ENT;
   294     TRACE_PRN_FN_ENT;
   254     (STATIC_CAST(DevSoundWrapperSrc*, ds->handle))->dev_sound->Stop();
   295     CMMFDevSound    *dev_sound= 0;
       
   296     dev_sound = (STATIC_CAST(DevSoundWrapperSrc*, ds->handle))->dev_sound;
       
   297     dev_sound->Stop();
   255     g_list_foreach(ds->supportedbitrates, (GFunc) g_free, NULL);
   298     g_list_foreach(ds->supportedbitrates, (GFunc) g_free, NULL);
   256     g_list_free(ds->supportedbitrates);
   299     g_list_free(ds->supportedbitrates);
   257 
   300 
   258     g_list_foreach(ds->fmt, (GFunc) g_free, NULL);
   301     g_list_foreach(ds->fmt, (GFunc) g_free, NULL);
   259     g_list_free(ds->fmt);
   302     g_list_free(ds->fmt);
   260 
   303     ds->fmt = NULL;
       
   304     delete (STATIC_CAST(DevSoundWrapperSrc*, ds->handle))->iAudoInputRecord;
       
   305     delete dev_sound;
   261     delete ds->handle;
   306     delete ds->handle;
   262     TRACE_PRN_FN_EXT;
   307     TRACE_PRN_FN_EXT;
   263     return 0;
   308     return 0;
       
   309     }
       
   310 /************************************************************/
       
   311 void update_devsound_speech_bitrate(DevSoundWrapperSrc *handle, TUint bitrate)
       
   312     {
       
   313     handle->speechbitrate = bitrate;
   264     }
   314     }
   265 /************************************************************/
   315 /************************************************************/
   266 
   316 
   267 int SetConfigurations(DevSoundWrapperSrc *handle)
   317 int SetConfigurations(DevSoundWrapperSrc *handle)
   268     {
   318     {
   273     temp_caps = (handle->dev_sound)->Capabilities();
   323     temp_caps = (handle->dev_sound)->Capabilities();
   274 
   324 
   275     handle->gain = (handle->dev_sound)->MaxGain();
   325     handle->gain = (handle->dev_sound)->MaxGain();
   276     (handle->dev_sound)->SetGain(handle->gain);
   326     (handle->dev_sound)->SetGain(handle->gain);
   277     handle->caps.iBufferSize = temp_caps.iBufferSize;
   327     handle->caps.iBufferSize = temp_caps.iBufferSize;
   278 
   328     
   279         TRAP(ret, (handle->dev_sound)->SetConfigL(handle->caps) );
       
   280     if (ret)
       
   281         {
       
   282         return ret;
       
   283         }
       
   284 
       
   285     (handle->caps) = (handle->dev_sound)->Config();
       
   286 
       
   287     switch (handle->fourcc)
   329     switch (handle->fourcc)
   288         {
   330         {
   289         case KMccFourCCIdG711:
   331         case KMccFourCCIdG711:
   290             {
   332             {
   291             if (!handle->iG711EncoderIntfc)
   333             if (!handle->iG711EncoderIntfc)
   320             {
   362             {
   321             break;
   363             break;
   322             }
   364             }
   323         }
   365         }
   324 
   366 
       
   367     if (ret)
       
   368         return ret;
       
   369     
   325     if (!handle->iSpeechEncoderConfig && handle->fourcc
   370     if (!handle->iSpeechEncoderConfig && handle->fourcc
   326             != KMMFFourCCCodePCM16)
   371             != KMMFFourCCCodePCM16)
   327         {
   372         {
   328 
   373 
   329             TRAP(ret, handle->iSpeechEncoderConfig
   374             TRAP(ret, handle->iSpeechEncoderConfig
   330                     = CSpeechEncoderConfig::NewL(*handle->dev_sound));
   375                     = CSpeechEncoderConfig::NewL(*handle->dev_sound));
   331         }
   376         if (ret)
       
   377             return ret;
       
   378         
       
   379         if(handle->speechbitrate > 0)
       
   380             {
       
   381             ret = set_speech_encoder_bit_rate(handle,handle->speechbitrate);
       
   382             if(ret)
       
   383                 return ret;
       
   384             }
       
   385         }
       
   386     
       
   387      TRAP(ret, (handle->dev_sound)->SetConfigL(handle->caps) );
       
   388      if (ret)
       
   389          {
       
   390          return ret;
       
   391          }
       
   392 
       
   393      (handle->caps) = (handle->dev_sound)->Config();
   332 
   394 
   333     TRACE_PRN_FN_EXT;
   395     TRACE_PRN_FN_EXT;
   334     return ret;
   396     return ret;
   335     }
   397     }
   336 
   398 
   536 /******************************************************************/
   598 /******************************************************************/
   537 
   599 
   538 void set_rate(DevSoundWrapperSrc *handle, int rate)
   600 void set_rate(DevSoundWrapperSrc *handle, int rate)
   539     {
   601     {
   540     handle->caps.iRate = rate;
   602     handle->caps.iRate = rate;
       
   603     TRACE_PRN_N1(_L("set_rate %d"),rate);
   541     }
   604     }
   542 /******************************************************************/
   605 /******************************************************************/
   543 void set_channels(DevSoundWrapperSrc *handle, int channels)
   606 void set_channels(DevSoundWrapperSrc *handle, int channels)
   544     {
   607     {
   545     handle->caps.iChannels = channels;
   608     handle->caps.iChannels = channels;
       
   609     TRACE_PRN_N1(_L("set_channels %d"),channels);
   546     }
   610     }
   547 /****************************************************************/
   611 /****************************************************************/
   548 void set_encoding(DevSoundWrapperSrc *handle, int encoding)
   612 void set_encoding(DevSoundWrapperSrc *handle, int encoding)
   549     {
   613     {
   550     handle->caps.iEncoding = encoding;
   614     handle->caps.iEncoding = encoding;
   555     handle->caps.iBufferSize = size;
   619     handle->caps.iBufferSize = size;
   556     }
   620     }
   557 /*****************************************************************/
   621 /*****************************************************************/
   558 void set_fourcc(DevSoundWrapperSrc *handle, int fourcc)
   622 void set_fourcc(DevSoundWrapperSrc *handle, int fourcc)
   559     {
   623     {
       
   624     TRACE_PRN_FN_ENT;
   560     handle->fourcc = fourcc;
   625     handle->fourcc = fourcc;
       
   626     TRACE_PRN_N1(_L("set_fourcc %d"),fourcc);
       
   627     TRACE_PRN_FN_EXT;
   561     }
   628     }
   562 
   629 
   563 /*******************************************************************/
   630 /*******************************************************************/
   564 
   631 
   565 int recordinit(DevSoundWrapperSrc *handle)
   632 int recordinit(DevSoundWrapperSrc *handle)
   566     {
   633     {
   567     TRACE_PRN_FN_ENT;
   634     TRACE_PRN_FN_ENT;
   568     int ret = 0;
       
   569     ((handle)->AL)->InitialiseActiveListener();
   635     ((handle)->AL)->InitialiseActiveListener();
   570     handle->iCallbackError = KErrNone;
   636     handle->iCallbackError = KErrNone;
   571 
   637 
   572         TRAP(ret, (handle->dev_sound)->RecordInitL() );
   638         TRAP(handle->iCallbackError, (handle->dev_sound)->RecordInitL() );
   573 
   639 
   574     if (ret)
   640     if (!handle->iCallbackError)
   575         {
   641         {
   576         TRACE_PRN_FN_EXT;
   642         ((handle)->AL)->StartActiveScheduler();
   577         return ret;
   643         }
   578         }
   644 
   579     ((handle)->AL)->StartActiveScheduler();
   645     TRACE_PRN_FN_EXT;
   580 
   646     return handle->iCallbackError;
   581     if ((handle->iCallbackError) != KErrNone)
       
   582         {
       
   583         TRACE_PRN_FN_EXT;
       
   584         return (handle->iCallbackError);
       
   585         }
       
   586     TRACE_PRN_FN_EXT;
       
   587     return KErrNone;
       
   588 
       
   589     }
   647     }
   590 
   648 
   591 /*******************************************************************/
   649 /*******************************************************************/
   592 int record_data(DevSoundWrapperSrc *handle)
   650 int record_data(DevSoundWrapperSrc *handle)
   593     {
   651     {
   604 /*********************************************************************/
   662 /*********************************************************************/
   605 
   663 
   606 int pre_init_setconf(GstDevsoundSrc *ds)
   664 int pre_init_setconf(GstDevsoundSrc *ds)
   607     {
   665     {
   608     TRACE_PRN_FN_ENT;
   666     TRACE_PRN_FN_ENT;
   609     int ret = 0;
   667     
   610     DevSoundWrapperSrc* dsPtr = STATIC_CAST(DevSoundWrapperSrc*, ds->handle);
   668     DevSoundWrapperSrc* dsPtr = STATIC_CAST(DevSoundWrapperSrc*, ds->handle);
   611 
   669     dsPtr->iCallbackError = KErrNone;
   612     // NOTE: it is too late for setting prio/pref here
   670     // NOTE: it is too late for setting prio/pref here
   613     if (ds->pending.preferenceupdate == 1 || ds->pending.priorityupdate == 1)
   671     if (ds->pending.preferenceupdate == 1 || ds->pending.priorityupdate == 1)
   614         {
   672         {
   615         ds->pending.preferenceupdate = FALSE;
   673         ds->pending.preferenceupdate = FALSE;
   616         ds->pending.priorityupdate = FALSE;
   674         ds->pending.priorityupdate = FALSE;
   623 
   681 
   624     if (ds->pending.leftbalanceupdate == 1 || ds->pending.rightbalanceupdate
   682     if (ds->pending.leftbalanceupdate == 1 || ds->pending.rightbalanceupdate
   625             == 1)
   683             == 1)
   626         {
   684         {
   627 
   685 
   628             TRAP( ret, (dsPtr->dev_sound)->SetRecordBalanceL(ds->leftbalance,
   686             TRAP( dsPtr->iCallbackError, (dsPtr->dev_sound)->SetRecordBalanceL(ds->leftbalance,
   629                             ds->rightbalance) );
   687                             ds->rightbalance) );
   630         ds->pending.leftbalanceupdate = FALSE;
   688         ds->pending.leftbalanceupdate = FALSE;
   631         ds->pending.rightbalanceupdate = FALSE;
   689         ds->pending.rightbalanceupdate = FALSE;
   632         }
   690         }
   633     TRACE_PRN_FN_EXT;
   691     TRACE_PRN_FN_EXT;
   634     return ret;
   692     return dsPtr->iCallbackError;
   635     }
   693     }
   636 /*********************************************************/
   694 /*********************************************************/
   637 void getsupporteddatatypes(GstDevsoundSrc *ds)
   695 void getsupporteddatatypes(GstDevsoundSrc *ds)
   638     {
   696     {
   639     TRACE_PRN_FN_ENT;
   697     TRACE_PRN_FN_ENT;
   687     get_g729_vad_mode(dsPtr, &ds->g729vadmode);
   745     get_g729_vad_mode(dsPtr, &ds->g729vadmode);
   688     get_ilbc_vad_mode(dsPtr, &ds->ilbcvadmode);
   746     get_ilbc_vad_mode(dsPtr, &ds->ilbcvadmode);
   689     TRACE_PRN_FN_EXT;
   747     TRACE_PRN_FN_EXT;
   690     }
   748     }
   691 
   749 
       
   750 int call_back_error(DevSoundWrapperSrc* dsPtr)
       
   751     {
       
   752     TRACE_PRN_FN_ENT;
       
   753     return dsPtr->iCallbackError;
       
   754     TRACE_PRN_FN_EXT;
       
   755     }
       
   756