r = MapExceptionToResult(ret);
SysLogException(NID_MEDIA, r, "[%s] Failed to perform audio_out_get_buffer_size operation with error code : %x", GetErrorMessage(r), ret);
}
-
+ // this is done to get better Stop time
__audioOutOptimalBufferSize = 1024;
+ __pFeedBuffer.reset(new (std::nothrow) ByteBuffer);
+ __pFeedBuffer->Construct(__audioOutOptimalBufferSize);
__presentSampleType = audioSampleType;
__presentSampleRate = audioSampleRate;
}
__audioOutOptimalBufferSize = 1024;
+ __pFeedBuffer.reset(new (std::nothrow) ByteBuffer);
+ __pFeedBuffer->Construct(__audioOutOptimalBufferSize);
__presentSampleType = audioSampleType;
__presentSampleRate = audioSampleRate;
result r = E_SUCCESS;
int ret = 0;
bool isSuccesful = true;
+ int feedSize = 0;
+ int index = 0;
while (!__stop)
{
if (isSuccesful)
SysTryCatch(NID_MEDIA, pBuffer, r = E_INVALID_ARG, E_INVALID_ARG,
"[E_INVALID_ARG] Invalid argument is used. The buffer to write is null.");
-
- if ((__volume >= 0) && (__volume < 100))
- {
- PreProcess(pBuffer);
- }
isSuccesful = false;
}
buffer_size = pBuffer->GetLimit();
pData = (unsigned char*) pBuffer->GetPointer();
SysTryCatch(NID_MEDIA, pData, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The data to write is null");
- if (!__stop)
+ index = 0;
+ while (!__stop && buffer_size)
{
- ret = audio_out_write(__audioOutHandle, (void*) pData, buffer_size);
- if (ret != buffer_size)
+ if (buffer_size > __audioOutOptimalBufferSize)
{
- SysLog(NID_MEDIA, "The size of actual written data is %d", ret);
+ feedSize = __audioOutOptimalBufferSize;
+ buffer_size = buffer_size - __audioOutOptimalBufferSize;
+ SysLog(NID_MEDIA, "index - %d buffer_size - %d", index, feedSize);
}
else
{
- isSuccesful = true;
- if (!__stop)
- {
- __pBufferSync->Enter();
- __bufferQueue.Dequeue(pBuffer);
- __pBufferSync->Exit();
- pBuffer = NULL;
- SendBufferEndReachedEvent();
-
- }
+ feedSize = buffer_size;
+ buffer_size = 0;
+ SysLog(NID_MEDIA, "index - %d buffer_size - %d", index, feedSize);
+ }
+ if ((__volume >= 0) && (__volume < 100))
+ {
+ PreProcess(pBuffer, index, feedSize);
+ ret = audio_out_write(__audioOutHandle, (void*) __pFeedBuffer->GetPointer(), feedSize);
+ }
+ else
+ {
+ pData = pData + index;
+ ret = audio_out_write(__audioOutHandle, (void*) pData, feedSize);
+ }
+ if (ret != feedSize)
+ {
+ SysLog(NID_MEDIA, "The size of actual written data is %d", ret);
+ }
+ index = index + feedSize;
+ }
+ if (buffer_size == 0)
+ {
+ isSuccesful = true;
+ if (!__stop)
+ {
+ __pBufferSync->Enter();
+ __bufferQueue.Dequeue(pBuffer);
+ __pBufferSync->Exit();
+ pBuffer = NULL;
+ SendBufferEndReachedEvent();
}
}
}
{
case AUDIO_TYPE_PCM_U8:
{
+ unsigned char* pOutput = __pFeedBuffer->GetPointer();
unsigned char* pData = pDataBuffer;
int noOfSamples = bytes;
for (int i = 0; i < noOfSamples; i++)
{
- int v = (((*pData - 128) * __volume256 + 128) >> 8) + 128;
- *pData++ = av_clip_uint8(v);
+ int v = (((*pData++ - 128) * __volume256 + 128) >> 8) + 128;
+ *pOutput++ = av_clip_uint8(v);
}
}
break;
case AUDIO_TYPE_PCM_S16_LE:
{
short* pData = (short*) pDataBuffer;
+ short* pOutput = (short*) __pFeedBuffer->GetPointer();
int noOfSamples = bytes >> 1;
for (int i = 0; i < noOfSamples; i++)
{
- int v = ((*pData) * __volume256 + 128) >> 8;
- *pData++ = av_clip_int16(v);
+ int v = ((*pData++) * __volume256 + 128) >> 8;
+ *pOutput++ = av_clip_int16(v);
}
}
break;
}
void
-_AudioOutImpl::PreProcess(ByteBuffer* pBuffer)
+_AudioOutImpl::PreProcess(ByteBuffer* pBuffer, int index, int size)
{
unsigned char* pDataBuffer = null;
- int bytes = 0;
if (pBuffer->GetLimit() > 0)
{
pDataBuffer = (unsigned char*) pBuffer->GetPointer();
{
return;
}
- bytes = pBuffer->GetLimit();
+ pDataBuffer = pDataBuffer + index;
}
else
{
}
if ((__volume256 < 256) && (__volume256 >= 0))
{
- ScaleDownVolume(pDataBuffer, bytes);
+ ScaleDownVolume(pDataBuffer, size);
}
}