11c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi/*
21c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * Copyright (C) 2010 The Android Open Source Project
31c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi *
41c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
51c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * you may not use this file except in compliance with the License.
61c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * You may obtain a copy of the License at
71c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi *
81c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
91c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi *
101c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
111c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
121c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * See the License for the specific language governing permissions and
141c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * limitations under the License.
151c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi */
161c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
171c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#include <stdlib.h>
181c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#include <stdio.h>
191c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#include <string.h>
201c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#include <unistd.h>
211c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#include <sys/time.h>
221c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
23c6853892c94800e72c0bd676d5d2136d48cea76eGlenn Kasten#include <SLES/OpenSLES.h>
241c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
251c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
268a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi#define MAX_NUMBER_INTERFACES 2
271c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
281c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#define TEST_MUTE 0
291c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#define TEST_SOLO 1
301c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
311c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivistatic int testMode;
321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi//-----------------------------------------------------------------
331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi/* Exits the application if an error is encountered */
341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__)
351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivivoid ExitOnErrorFunc( SLresult result , int line)
371c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{
381c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    if (SL_RESULT_SUCCESS != result) {
3958432eb9cea995c69b4f905e68b38c1b8216edebGlenn Kasten        fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line);
40c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten        exit(EXIT_FAILURE);
411c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    }
421c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi}
431c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
441c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
451c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi//-----------------------------------------------------------------
461c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
478a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi/* Play an audio URIs, play, pause, stop  */
481c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivivoid TestPlayUri( SLObjectItf sl, const char* path)
491c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{
501c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLresult  result;
511c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLEngineItf EngineItf;
521c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
531c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Objects this application uses: one player and an ouput mix */
541c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLObjectItf  player, outputMix;
551c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
561c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Source of audio data to play */
571c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLDataSource      audioSource;
581c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLDataLocator_URI uri;
591c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLDataFormat_MIME mime;
601c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
611c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Data sinks for the audio player */
621c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLDataSink               audioSink;
631c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLDataLocator_OutputMix  locator_outputmix;
641c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
651c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Play, Volume and PrefetchStatus interfaces for the audio player */
661c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLPlayItf           playItf;
671c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLMuteSoloItf       muteSoloItf;
681c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLPrefetchStatusItf prefetchItf;
691c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
701c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLboolean required[MAX_NUMBER_INTERFACES];
711c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLInterfaceID iidArray[MAX_NUMBER_INTERFACES];
721c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
731c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Get the SL Engine Interface which is implicit */
741c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf);
751c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
761c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
771c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Initialize arrays required[] and iidArray[] */
781c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) {
791c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        required[i] = SL_BOOLEAN_FALSE;
801c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        iidArray[i] = SL_IID_NULL;
811c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    }
821c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
831c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* ------------------------------------------------------ */
841c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Configuration of the output mix  */
851c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
861c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Create Output Mix object to be used by the player */
87c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten     result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required);
881c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi     ExitOnError(result);
891c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
901c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Realize the Output Mix object in synchronous mode */
911c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE);
921c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
931c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
941c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Setup the data sink structure */
951c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
961c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    locator_outputmix.outputMix   = outputMix;
971c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    audioSink.pLocator            = (void*)&locator_outputmix;
981c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    audioSink.pFormat             = NULL;
991c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1001c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* ------------------------------------------------------ */
1011c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Configuration of the player  */
1021c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1031c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Set arrays required[] and iidArray[] for SLMuteSoloItf and SLPrefetchStatusItf interfaces */
1041c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /*  (SLPlayItf is implicit) */
1051c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    required[0] = SL_BOOLEAN_TRUE;
1061c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    iidArray[0] = SL_IID_MUTESOLO;
1071c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    required[1] = SL_BOOLEAN_TRUE;
1081c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    iidArray[1] = SL_IID_PREFETCHSTATUS;
1091c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1101c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Setup the data source structure for the URI */
1111c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    uri.locatorType = SL_DATALOCATOR_URI;
1121c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    uri.URI         =  (SLchar*) path;
1131c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    mime.formatType = SL_DATAFORMAT_MIME;
1141c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /*     this is how ignored mime information is specified, according to OpenSL ES spec
1151c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi     *     in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */
1161c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    mime.mimeType      = (SLchar*)NULL;
1171c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED;
1181c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1191c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    audioSource.pFormat  = (void*)&mime;
1201c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    audioSource.pLocator = (void*)&uri;
1211c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1221c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Create the audio player */
1238a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi    result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink,
1248a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi            MAX_NUMBER_INTERFACES, iidArray, required);
1251c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1261c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1271c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Realize the player in synchronous mode. */
1281c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result);
1291c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "URI example: after Realize\n");
1301c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1311c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Get the SLPlayItf, SLPrefetchStatusItf and SLMuteSoloItf interfaces for the player */
1321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf);
1331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf);
1361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1371c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1381c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*player)->GetInterface(player, SL_IID_MUTESOLO, (void*)&muteSoloItf);
1391c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1401c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1411c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1421c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "Player configured\n");
1431c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1441c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* ------------------------------------------------------ */
1451c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Playback and test */
1461c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1471c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Start the data prefetching by setting the player to the paused state */
1481c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED );
1491c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1501c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1511c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Wait until there's data to play */
1521c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW;
1531c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) {
1541c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        usleep(100 * 1000);
1551c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus);
1561c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    }
1571c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1581c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1591c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Testing play states */
1601c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* let it play for 2s */
1611c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "----- Playing\n");
1621c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING );
1631c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1641c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    usleep(2 * 1000 * 1000);
1651c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
166b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    /* pause for 1s*/
167b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    fprintf(stdout, "----- Pausing (1s)\n");
1681c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED );
1691c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1701c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    usleep(2 * 1000 * 1000);
1711c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1721c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* resume */
173b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    fprintf(stdout, "----- Playing (2s, should have resumed where it paused)\n");
1741c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING );
1751c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1761c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    usleep(2 * 1000 * 1000);
1771c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
178b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    /* stop */
179b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    fprintf(stdout, "----- Stopping\n");
180b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED);
181b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    ExitOnError(result);
182b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi
183b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    /* play for 2s */
184b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    fprintf(stdout, "----- Playing (2s, should have started from the beginning\n");
185b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING );
186b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    ExitOnError(result);
187b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    usleep(2 * 1000 * 1000);
188b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi
189b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    /* stop */
190b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi    fprintf(stdout, "----- Stopping\n");
1911c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED);
1921c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
1931c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1941c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel TrividestroyKillKill:
1951c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1961c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Destroy the players */
1971c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    (*player)->Destroy(player);
1981c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
1991c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Destroy Output Mix object */
2001c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    (*outputMix)->Destroy(outputMix);
2011c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi}
2021c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2031c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi//-----------------------------------------------------------------
2041c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Triviint main(int argc, char* const argv[])
2051c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{
2061c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLresult    result;
2071c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLObjectItf sl;
2081c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2091c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf, SLMuteSoloItf\n",
2101c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi            argv[0]);
2111c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n");
2121c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "Plays a sound and alternates the muting of the channels (for 5s).\n");
2131c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, " and then alternates the solo\'ing of the channels (for 5s).\n");
2141c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    fprintf(stdout, "Stops after 10s\n");
2151c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2161c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    if (argc == 1) {
2171c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        fprintf(stdout, "Usage: \t%s url\n", argv[0]);
2181c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        fprintf(stdout, "Example: \"%s /sdcard/my.mp3\"\n", argv[0]);
219c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten        exit(EXIT_FAILURE);
2201c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    }
2211c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2221c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    SLEngineOption EngineOption[] = {
2231c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi            {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE}
2241c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    };
2251c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2261c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL);
2271c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
2281c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2291c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Realizing the SL Engine in synchronous mode. */
2301c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE);
2311c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    ExitOnError(result);
2321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    if (argc > 1) {
2341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi        TestPlayUri(sl, argv[1]);
2351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    }
2361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
2371c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    /* Shutdown OpenSL ES */
2381c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi    (*sl)->Destroy(sl);
2391c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi
240c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten    return EXIT_SUCCESS;
2411c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi}
242