static void Flush(audio_output_t *p_aout, bool drain) { aout_sys_t *p_sys = p_aout->sys; if (drain) { mtime_t delay; vlc_mutex_lock( &p_sys->lock ); delay = p_sys->length; vlc_mutex_unlock( &p_sys->lock ); msleep(delay); } else { vlc_mutex_lock( &p_sys->lock ); SetPlayState( p_sys->playerPlay, SL_PLAYSTATE_STOPPED ); Clear( p_sys->playerBufferQueue ); SetPlayState( p_sys->playerPlay, SL_PLAYSTATE_PLAYING ); p_sys->length = 0; /* release audio data not yet written to opensles */ block_ChainRelease( p_sys->p_buffer_chain ); p_sys->p_buffer_chain = NULL; p_sys->pp_buffer_last = &p_sys->p_buffer_chain; /* release audio data written to opensles, but not yet * played on hardware */ block_ChainRelease( p_sys->p_chain ); p_sys->p_chain = NULL; p_sys->pp_last = &p_sys->p_chain; vlc_mutex_unlock( &p_sys->lock ); } }
static void Flush(dtaudio_output_t *aout, bool drain) { aout_sys_t *sys = (aout_sys_t *) aout->ao_priv; if (drain) { int64_t delay; if (!TimeGet(aout, &delay)) usleep(delay * 1000); } else { SetPlayState(sys->playerPlay, SL_PLAYSTATE_STOPPED); Clear(sys->playerBufferQueue); SetPlayState(sys->playerPlay, SL_PLAYSTATE_PLAYING); sys->samples = 0; sys->started = 0; } }
static void Pause(audio_output_t *p_aout, bool pause, mtime_t date) { (void)date; aout_sys_t *p_sys = p_aout->sys; SetPlayState( p_sys->playerPlay, pause ? SL_PLAYSTATE_PAUSED : SL_PLAYSTATE_PLAYING ); }
static void Stop(dtaudio_output_t *aout) { aout_sys_t *sys = (aout_sys_t *) aout->ao_priv; SetPlayState(sys->playerPlay, SL_PLAYSTATE_STOPPED); //Flush remaining buffers if any. Clear(sys->playerBufferQueue); free(sys->buf); Destroy(sys->playerObject); sys->playerObject = NULL; free(sys); sys = NULL; }
static void Stop(ao_wrapper_t *aout) { aout_sys_t *sys = (aout_sys_t *) aout->ao_priv; SetPlayState(sys->playerPlay, SL_PLAYSTATE_STOPPED); //Flush remaining buffers if any. Clear(sys->playerBufferQueue); Destroy(sys->playerObject); Destroy(sys->outputMixObject); Destroy(sys->engineObject); dlclose(sys->p_so_handle); free(sys->buf); free(sys); sys = NULL; }
/* attach to an available lcd */ CMPC_Lcd::CMPC_Lcd(void) { InitializeCriticalSection(&cs); hLCD_UpdateThread = NULL; // lcd init ZeroMemory(&m_ConnCtx, sizeof(m_ConnCtx)); m_ConnCtx.appFriendlyName = _T(LCD_APP_NAME); m_ConnCtx.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW | LGLCD_APPLET_CAP_QVGA; m_ConnCtx.isAutostartable = FALSE; m_ConnCtx.isPersistent = FALSE; m_ConnCtx.onConfigure.configCallback = NULL; // we don't have a configuration screen m_ConnCtx.onConfigure.configContext = NULL; m_ConnCtx.onNotify.notificationCallback = NULL; m_ConnCtx.onNotify.notifyContext = NULL; m_ConnCtx.connection = LGLCD_INVALID_CONNECTION; // the "connection" member will be returned upon return CAppSettings& s = AfxGetAppSettings(); if (!s.fLCDSupport) { return; } if (FALSE == m_Connection.Initialize(m_ConnCtx)) { //_tperror(_T("Initialize")); return; } m_MonoOutput = m_Connection.MonoOutput(); m_MonoOutput->ShowPage(&m_MonoPage); m_ColorOutput = m_Connection.ColorOutput(); m_ColorOutput->ShowPage(&m_ColorPage); SetAsForeground(TRUE); m_Connection.Update(); if (m_Connection.IsConnected()) { Thread_Loop = true; SetPlayState(PS_STOP); hLCD_UpdateThread = (HANDLE) _beginthread(LCD_UpdateThread, 512 /* stack */, (void*) this /* arg */); } }
static int Start(dtaudio_output_t *aout) { SLresult result; aout_sys_t *sys = (aout_sys_t *) aout->ao_priv; dtaudio_para_t *para = &aout->para; // configure audio source - this defines the number of samples you can enqueue. SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS }; int mask; if (para->dst_channels > 1) mask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; else mask = SL_SPEAKER_FRONT_CENTER; SLDataFormat_PCM format_pcm; format_pcm.formatType = SL_DATAFORMAT_PCM; format_pcm.numChannels = para->dst_channels; //format_pcm.samplesPerSec = ((SLuint32) para->dst_samplerate * 1000) ; format_pcm.samplesPerSec = ((SLuint32) convertSampleRate(para->dst_samplerate)); format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; format_pcm.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; format_pcm.channelMask = mask; format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; SLDataSource audioSrc = {&loc_bufq, &format_pcm}; // configure audio sink SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, sys->outputMixObject }; SLDataSink audioSnk = {&loc_outmix, NULL}; //create audio player const SLInterfaceID ids2[] = {sys->SL_IID_ANDROIDSIMPLEBUFFERQUEUE, sys->SL_IID_VOLUME}; static const SLboolean req2[] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE}; result = CreateAudioPlayer(sys->engineEngine, &sys->playerObject, &audioSrc, &audioSnk, sizeof(ids2) / sizeof(*ids2), ids2, req2); if (unlikely(result != SL_RESULT_SUCCESS)) { // error return -1; /* Try again with a more sensible samplerate */ #if 0 fmt->i_rate = 44100; format_pcm.samplesPerSec = ((SLuint32) 44100 * 1000) ; result = CreateAudioPlayer(sys->engineEngine, &sys->playerObject, &audioSrc, &audioSnk, sizeof(ids2) / sizeof(*ids2), ids2, req2); #endif } CHECK_OPENSL_ERROR("Failed to create audio player"); result = Realize(sys->playerObject, SL_BOOLEAN_FALSE); CHECK_OPENSL_ERROR("Failed to realize player object."); result = GetInterface(sys->playerObject, sys->SL_IID_PLAY, &sys->playerPlay); CHECK_OPENSL_ERROR("Failed to get player interface."); result = GetInterface(sys->playerObject, sys->SL_IID_VOLUME, &sys->volumeItf); CHECK_OPENSL_ERROR("failed to get volume interface."); result = GetInterface(sys->playerObject, sys->SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &sys->playerBufferQueue); CHECK_OPENSL_ERROR("Failed to get buff queue interface"); result = RegisterCallback(sys->playerBufferQueue, PlayedCallback, (void *) aout); CHECK_OPENSL_ERROR("Failed to register buff queue callback."); // set the player's state to playing result = SetPlayState(sys->playerPlay, SL_PLAYSTATE_PLAYING); CHECK_OPENSL_ERROR("Failed to switch to playing state"); /* XXX: rounding shouldn't affect us at normal sampling rate */ sys->rate = para->dst_samplerate; sys->samples_per_buf = OPENSLES_BUFLEN * para->dst_samplerate / 1000; sys->buf = malloc(OPENSLES_BUFFERS * sys->samples_per_buf * bytesPerSample(aout)); if (!sys->buf) goto error; sys->started = 0; sys->next_buf = 0; sys->samples = 0; SetPositionUpdatePeriod(sys->playerPlay, AOUT_MIN_PREPARE_TIME * 1000 / CLOCK_FREQ); return 0; error: if (sys->playerObject) { Destroy(sys->playerObject); sys->playerObject = NULL; } return -1; }
static void Pause(dtaudio_output_t *aout, bool pause) { aout_sys_t *sys = (aout_sys_t *) aout->ao_priv; SetPlayState(sys->playerPlay, pause ? SL_PLAYSTATE_PAUSED : SL_PLAYSTATE_PLAYING); }
/* attach to an available lcd */ CMPC_Lcd::CMPC_Lcd(void) { BYTE bPause[] = {0x93, 0xFF, 0x93, 0xFF, 0x93, 0xFF, 0x93, 0xFF, 0x93, 0xFF, 0x93, 0xFF, 0x93, 0xFF }; BYTE bStop[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; BYTE bPlay[] = {0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F }; hBmp[PS_PLAY] = CreateBitmap(56, 7, 1, 1, bPlay); hBmp[PS_PAUSE] = CreateBitmap(14, 7, 1, 1, bPause); hBmp[PS_STOP] = CreateBitmap( 8, 7, 1, 1, bStop); InitializeCriticalSection(&cs); hLCD_UpdateThread = NULL; // lcd init ZeroMemory(&m_ConnCtx, sizeof(m_ConnCtx)); m_ConnCtx.appFriendlyName = _T(LCD_APP_NAME); m_ConnCtx.isPersistent = FALSE; m_ConnCtx.isAutostartable = FALSE; m_ConnCtx.onConfigure.configCallback = NULL; // we don't have a configuration screen m_ConnCtx.onConfigure.configContext = NULL; m_ConnCtx.connection = LGLCD_INVALID_CONNECTION; // the "connection" member will be returned upon return if (m_Output.Initialize(&m_ConnCtx) != ERROR_SUCCESS || // Initialize the output object m_Manager.Initialize() != ERROR_SUCCESS) { //_tperror(_T("Initialize")); return; } m_Manager.SetExpiration(INFINITE); // Set the expiration on the sample screen // Add and lock the screen onto our output manager m_Output.AddScreen(&m_Manager); m_Output.LockScreen(&m_Manager); m_Output.Update(GetTickCount()); // This invokes OnUpdate for the active screen m_Output.Draw(); // This invokes OnDraw for the active screen if (m_Output.IsOpened()) { Thread_Loop = true; SetPlayState(PS_STOP); hLCD_UpdateThread = (HANDLE) _beginthread(LCD_UpdateThread, 512 /* stack */, (void*) this /* arg */); } }