Skip to content

Commit

Permalink
sl: revert opensl change in e826c39
Browse files Browse the repository at this point in the history
queued data is just ptr, byte array is destroyed immediately
  • Loading branch information
wang-bin committed Sep 5, 2016
1 parent 88068c9 commit 8a3adac
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/output/audio/AudioOutputOpenSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class AudioOutputOpenSL Q_DECL_FINAL: public AudioOutputBackend
SLint32 m_streamType;
quint32 buffers_queued;
QSemaphore sem;

// Enqueue does not copy data. We MUST keep the data until it is played out
int queue_data_write;
QByteArray queue_data;
};

typedef AudioOutputOpenSL AudioOutputBackendOpenSL;
Expand Down Expand Up @@ -191,6 +195,7 @@ AudioOutputOpenSL::AudioOutputOpenSL(QObject *parent)
, m_sl_step(0)
, m_streamType(-1)
, buffers_queued(0)
, queue_data_write(0)
{
#ifdef Q_OS_ANDROID
char v[PROP_VALUE_MAX+1];
Expand Down Expand Up @@ -257,6 +262,7 @@ void AudioOutputOpenSL::acquireNextBuffer()

bool AudioOutputOpenSL::open()
{
queue_data.resize(buffer_size*buffer_count);
SLDataLocator_BufferQueue bufferQueueLocator = { SL_DATALOCATOR_BUFFERQUEUE, (SLuint32)buffer_count };
SLDataFormat_PCM_EX pcmFormat = audioFormatToSL(format);
SLDataSource audioSrc = { &bufferQueueLocator, &pcmFormat };
Expand Down Expand Up @@ -349,19 +355,30 @@ bool AudioOutputOpenSL::close()
m_playItf = NULL;
m_volumeItf = NULL;
m_bufferQueueItf = NULL;
queue_data.clear();
queue_data_write = 0;
return true;
}

bool AudioOutputOpenSL::write(const QByteArray& data)
{
// assume data.size() <= buffer_size. It's true in QtAV
const int s = qMin(queue_data.size() - queue_data_write, data.size());
// assume data.size() <= buffer_size. It's true in QtAV
if (s < data.size())
queue_data_write = 0;
memcpy((char*)queue_data.constData() + queue_data_write, data.constData(), data.size());
//qDebug("enqueue %p, queue_data_write: %d/%d available:%d", data.constData(), queue_data_write, queue_data.size(), sem.available());
#ifdef Q_OS_ANDROID
if (m_android)
SL_ENSURE((*m_bufferQueueItf_android)->Enqueue(m_bufferQueueItf_android, data.constData(), data.size()), false);
SL_ENSURE((*m_bufferQueueItf_android)->Enqueue(m_bufferQueueItf_android, queue_data.constData() + queue_data_write, data.size()), false);
else
#endif
SL_ENSURE((*m_bufferQueueItf)->Enqueue(m_bufferQueueItf, data.constData(), data.size()), false);
SL_ENSURE((*m_bufferQueueItf)->Enqueue(m_bufferQueueItf, queue_data.constData() + queue_data_write, data.size()), false);
buffers_queued++;
queue_data_write += data.size();
if (queue_data_write == queue_data.size())
queue_data_write = 0;
return true;
}

Expand Down

0 comments on commit 8a3adac

Please sign in to comment.