From ac5c5fd9e7513c046b792662606445ecdef2989c Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 16 Sep 2010 16:29:12 -0700 Subject: [PATCH] Add example for SLRecordItf callback registration and use. Change-Id: Ibcd27f5a49a42ddbcd313b30e7b07b1ce4f13705 --- opensles/tests/examples/slesTestRecBuffQueue.cpp | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/opensles/tests/examples/slesTestRecBuffQueue.cpp b/opensles/tests/examples/slesTestRecBuffQueue.cpp index 06e15df8..c6472696 100644 --- a/opensles/tests/examples/slesTestRecBuffQueue.cpp +++ b/opensles/tests/examples/slesTestRecBuffQueue.cpp @@ -63,6 +63,27 @@ typedef struct CallbackCntxt_ { SLint8* pData; // Current address of local audio data storage } CallbackCntxt; + +//----------------------------------------------------------------- +/* Callback for recording buffer queue events */ +void RecCallback( + SLRecordItf caller, + void *pContext, + SLuint32 event) +{ + if (SL_RECORDEVENT_HEADATNEWPOS & event) { + SLmillisecond pMsec = 0; + (*caller)->GetPosition(caller, &pMsec); + fprintf(stdout, "SL_RECORDEVENT_HEADATNEWPOS current position=%lums\n", pMsec); + } + + if (SL_RECORDEVENT_HEADATMARKER & event) { + SLmillisecond pMsec = 0; + (*caller)->GetPosition(caller, &pMsec); + fprintf(stdout, "SL_RECORDEVENT_HEADATMARKER current position=%lums\n", pMsec); + } +} + //----------------------------------------------------------------- /* Callback for recording buffer queue events */ void RecBufferQueueCallback( @@ -204,6 +225,18 @@ void TestRecToBuffQueue( SLObjectItf sl, const char* path, SLAint64 durationInSe result = (*recorder)->GetInterface(recorder, SL_IID_RECORD, (void*)&recordItf); ExitOnError(result); + /* Set up the recorder callback to get events during the recording */ + result = (*recordItf)->SetMarkerPosition(recordItf, 2000); + ExitOnError(result); + result = (*recordItf)->SetPositionUpdatePeriod(recordItf, 500); + ExitOnError(result); + result = (*recordItf)->SetCallbackEventsMask(recordItf, + SL_RECORDEVENT_HEADATMARKER | SL_RECORDEVENT_HEADATNEWPOS); + ExitOnError(result); + result = (*recordItf)->RegisterCallback(recordItf, RecCallback, NULL); + ExitOnError(result); + fprintf(stdout, "Recorder callback registered\n"); + /* Get the buffer queue interface which was explicitly requested */ result = (*recorder)->GetInterface(recorder, SL_IID_BUFFERQUEUE, (void*)&recBuffQueueItf); ExitOnError(result); -- 2.11.0