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 Trivi//----------------------------------------------------------------- 321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi/* Exits the application if an error is encountered */ 331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) 341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivivoid ExitOnErrorFunc( SLresult result , int line) 361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{ 371c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi if (SL_RESULT_SUCCESS != result) { 3858432eb9cea995c69b4f905e68b38c1b8216edebGlenn Kasten fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); 39c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten exit(EXIT_FAILURE); 401c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi } 411c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi} 421c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 431c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 441c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi//----------------------------------------------------------------- 451c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 468a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi/* Play an audio URIs, play, pause, stop */ 471c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivivoid TestPlayUri( SLObjectItf sl, const char* path) 481c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{ 491c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLresult result; 501c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLEngineItf EngineItf; 511c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 521c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Objects this application uses: one player and an ouput mix */ 531c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLObjectItf player, outputMix; 541c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 551c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Source of audio data to play */ 561c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLDataSource audioSource; 571c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLDataLocator_URI uri; 581c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLDataFormat_MIME mime; 591c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 601c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Data sinks for the audio player */ 611c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLDataSink audioSink; 621c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLDataLocator_OutputMix locator_outputmix; 631c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 641c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Play, Volume and PrefetchStatus interfaces for the audio player */ 651c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLPlayItf playItf; 661c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLMuteSoloItf muteSoloItf; 671c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLPrefetchStatusItf prefetchItf; 681c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 691c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLboolean required[MAX_NUMBER_INTERFACES]; 701c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; 711c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 721c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Get the SL Engine Interface which is implicit */ 731c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); 741c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 751c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 761c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Initialize arrays required[] and iidArray[] */ 771c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { 781c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi required[i] = SL_BOOLEAN_FALSE; 791c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi iidArray[i] = SL_IID_NULL; 801c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi } 811c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 821c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* ------------------------------------------------------ */ 831c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Configuration of the output mix */ 841c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 851c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Create Output Mix object to be used by the player */ 86c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); 871c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 881c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 891c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Realize the Output Mix object in synchronous mode */ 901c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); 911c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 921c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 931c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Setup the data sink structure */ 941c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; 951c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi locator_outputmix.outputMix = outputMix; 961c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi audioSink.pLocator = (void*)&locator_outputmix; 971c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi audioSink.pFormat = NULL; 981c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 991c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* ------------------------------------------------------ */ 1001c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Configuration of the player */ 1011c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1021c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Set arrays required[] and iidArray[] for SLMuteSoloItf and SLPrefetchStatusItf interfaces */ 1031c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* (SLPlayItf is implicit) */ 1041c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi required[0] = SL_BOOLEAN_TRUE; 1051c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi iidArray[0] = SL_IID_MUTESOLO; 1061c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi required[1] = SL_BOOLEAN_TRUE; 1071c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi iidArray[1] = SL_IID_PREFETCHSTATUS; 1081c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1091c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Setup the data source structure for the URI */ 1101c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi uri.locatorType = SL_DATALOCATOR_URI; 1111c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi uri.URI = (SLchar*) path; 1121c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi mime.formatType = SL_DATAFORMAT_MIME; 1131c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* this is how ignored mime information is specified, according to OpenSL ES spec 1141c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ 1151c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi mime.mimeType = (SLchar*)NULL; 1161c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; 1171c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1181c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi audioSource.pFormat = (void*)&mime; 1191c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi audioSource.pLocator = (void*)&uri; 1201c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1211c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Create the audio player */ 1228a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 1238a1b7f28c1c3de212a302182022310ab7b227788Jean-Michel Trivi MAX_NUMBER_INTERFACES, iidArray, required); 1241c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1251c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1261c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Realize the player in synchronous mode. */ 1271c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); 1281c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "URI example: after Realize\n"); 1291c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1301c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Get the SLPlayItf, SLPrefetchStatusItf and SLMuteSoloItf interfaces for the player */ 1311c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); 1321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); 1351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1371c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*player)->GetInterface(player, SL_IID_MUTESOLO, (void*)&muteSoloItf); 1381c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1391c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1401c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1411c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "Player configured\n"); 1421c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1431c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* ------------------------------------------------------ */ 1441c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Playback and test */ 1451c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1461c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Start the data prefetching by setting the player to the paused state */ 1471c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); 1481c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1491c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1501c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Wait until there's data to play */ 1511c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; 1521c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { 1531c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi usleep(100 * 1000); 1541c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); 1551c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi } 1561c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1571c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1581c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Testing play states */ 1591c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* let it play for 2s */ 1601c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "----- Playing\n"); 1611c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); 1621c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1631c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi usleep(2 * 1000 * 1000); 1641c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 165b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi /* pause for 1s*/ 166b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi fprintf(stdout, "----- Pausing (1s)\n"); 1671c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); 1681c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1691c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi usleep(2 * 1000 * 1000); 1701c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1711c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* resume */ 172b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi fprintf(stdout, "----- Playing (2s, should have resumed where it paused)\n"); 1731c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); 1741c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1751c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi usleep(2 * 1000 * 1000); 1761c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 177b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi /* stop */ 178b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi fprintf(stdout, "----- Stopping\n"); 179b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); 180b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi ExitOnError(result); 181b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi 182b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi /* play for 2s */ 183b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi fprintf(stdout, "----- Playing (2s, should have started from the beginning\n"); 184b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); 185b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi ExitOnError(result); 186b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi usleep(2 * 1000 * 1000); 187b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi 188b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi /* stop */ 189b78fe5f783209fbe1fed42634ca9889052ffcd0bJean-Michel Trivi fprintf(stdout, "----- Stopping\n"); 1901c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); 1911c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 1921c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1931c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Destroy the players */ 1941c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi (*player)->Destroy(player); 1951c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 1961c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Destroy Output Mix object */ 1971c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi (*outputMix)->Destroy(outputMix); 1981c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi} 1991c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2001c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi//----------------------------------------------------------------- 2011c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Triviint main(int argc, char* const argv[]) 2021c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi{ 2031c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLresult result; 2041c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLObjectItf sl; 2051c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2061c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf, SLMuteSoloItf\n", 2071c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi argv[0]); 2081c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); 2091c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "Plays a sound and alternates the muting of the channels (for 5s).\n"); 2101c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, " and then alternates the solo\'ing of the channels (for 5s).\n"); 2111c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "Stops after 10s\n"); 2121c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2131c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi if (argc == 1) { 2141c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "Usage: \t%s url\n", argv[0]); 2151c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi fprintf(stdout, "Example: \"%s /sdcard/my.mp3\"\n", argv[0]); 216c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten exit(EXIT_FAILURE); 2171c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi } 2181c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2191c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi SLEngineOption EngineOption[] = { 2201c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} 2211c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi }; 2221c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2231c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); 2241c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 2251c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2261c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Realizing the SL Engine in synchronous mode. */ 2271c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); 2281c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi ExitOnError(result); 2291c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2301c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi if (argc > 1) { 2311c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi TestPlayUri(sl, argv[1]); 2321c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi } 2331c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 2341c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi /* Shutdown OpenSL ES */ 2351c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi (*sl)->Destroy(sl); 2361c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi 237c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten return EXIT_SUCCESS; 2381c1c2d6d225e8180ba85f41170f7921d471308daJean-Michel Trivi} 239