167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi/* 267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * Copyright (C) 2010 The Android Open Source Project 367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * 467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * you may not use this file except in compliance with the License. 667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * You may obtain a copy of the License at 767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * 867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * 1067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 1167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 1267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * See the License for the specific language governing permissions and 1467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * limitations under the License. 1567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi */ 1667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 175120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#include <assert.h> 185120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#include <pthread.h> 1967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#include <stdlib.h> 2067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#include <stdio.h> 2167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#include <string.h> 2267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#include <unistd.h> 2367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#include <sys/time.h> 2467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 25a6c5e52ded343b557152156c33d33a10d29bf6f1Glenn Kasten#include <SLES/OpenSLES.h> 2667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 2767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 2867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#define MAX_NUMBER_INTERFACES 3 2967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 3067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#define REPETITIONS 4 // 4 repetitions, but will stop the looping before the end 3167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 3267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#define INITIAL_RATE 2000 // 2x normal playback speed 3367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 345120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten// These are extensions to OpenSL ES 1.0.1 values 355120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 365120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#define SL_PREFETCHSTATUS_UNKNOWN 0 375120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#define SL_PREFETCHSTATUS_ERROR (-1) 385120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 395120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten// Mutex and condition shared with main program to protect prefetch_status 405120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 415120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kastenstatic pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 425120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kastenstatic pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 435120f09a47360dda4913139836c10cc5d57b0b8bGlenn KastenSLuint32 prefetch_status = SL_PREFETCHSTATUS_UNKNOWN; 445120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 455120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten/* used to detect errors likely to have occured when the OpenSL ES framework fails to open 465120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. 475120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten */ 485120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#define PREFETCHEVENT_ERROR_CANDIDATE \ 495120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) 505120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 5167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//----------------------------------------------------------------- 5267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//* Exits the application if an error is encountered */ 5367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) 5467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 5567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivivoid ExitOnErrorFunc( SLresult result , int line) 5667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi{ 5767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (SL_RESULT_SUCCESS != result) { 58d968dacf7a35d52b6907283f3d95295a238340ccGlenn Kasten fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); 594d7c8c742d5b09895e7ce3d07d314b6ada56123dGlenn Kasten exit(EXIT_FAILURE); 6067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 6167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi} 6267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 6367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//----------------------------------------------------------------- 6467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi/* PlayItf callback for an audio player */ 6567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivivoid PlayEventCallback( SLPlayItf caller, void *pContext, SLuint32 event) 6667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi{ 6767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "PlayEventCallback event = "); 6867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PLAYEVENT_HEADATEND) { 6967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "SL_PLAYEVENT_HEADATEND \n"); 7067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* slow playback down by 2x for next loop, if possible */ 7167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLpermille minRate, maxRate, stepSize, rate = 1000; 7267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLuint32 capa; 735120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(NULL != pContext); 745120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLPlaybackRateItf pRateItf = (SLPlaybackRateItf)pContext; 755120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLresult res = (*pRateItf)->GetRate(pRateItf, &rate); CheckErr(res); 765120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*pRateItf)->GetRateRange(pRateItf, 0, &minRate, &maxRate, &stepSize, &capa); 7767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi CheckErr(res); 7867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "old rate = %d, minRate=%d, maxRate=%d\n", rate, minRate, maxRate); 7967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi rate /= 2; 8067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (rate < minRate) { 8167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi rate = minRate; 8267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 8367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "new rate = %d\n", rate); 845120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*pRateItf)->SetRate(pRateItf, rate); CheckErr(res); 855120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (res == SL_RESULT_FEATURE_UNSUPPORTED) { 865120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stderr, "new playback rate %d per mille is unsupported\n", rate); 875120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } else { 885120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten CheckErr(res); 895120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 9067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 9167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PLAYEVENT_HEADATMARKER) { 9267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER "); 9367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 9467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PLAYEVENT_HEADATNEWPOS) { 9567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS "); 9667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 9767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PLAYEVENT_HEADMOVING) { 9867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "SL_PLAYEVENT_HEADMOVING "); 9967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 10067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PLAYEVENT_HEADSTALLED) { 10167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "SL_PLAYEVENT_HEADSTALLED"); 10267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 10367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "\n"); 10467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi} 10567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 10667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//----------------------------------------------------------------- 10767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi/* PrefetchStatusItf callback for an audio player */ 10867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivivoid PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) 10967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi{ 1105120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten //fprintf(stdout, "\t\tPrefetchEventCallback: received event %u\n", event); 1115120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLresult result; 1125120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(pContext == NULL); 11367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLpermille level = 0; 1145120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten result = (*caller)->GetFillLevel(caller, &level); 1155120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten CheckErr(result); 11667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLuint32 status; 1175120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten result = (*caller)->GetPrefetchStatus(caller, &status); 1185120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten CheckErr(result); 11967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { 12067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "\t\tPrefetchEventCallback: Buffer fill level is = %d\n", level); 12167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 12267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (event & SL_PREFETCHEVENT_STATUSCHANGE) { 123d968dacf7a35d52b6907283f3d95295a238340ccGlenn Kasten fprintf(stdout, "\t\tPrefetchEventCallback: Prefetch Status is = %u\n", status); 12467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 1255120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLuint32 new_prefetch_status; 1265120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if ((event & PREFETCHEVENT_ERROR_CANDIDATE) == PREFETCHEVENT_ERROR_CANDIDATE 1275120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten && level == 0 && status == SL_PREFETCHSTATUS_UNDERFLOW) { 1285120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stdout, "\t\tPrefetchEventCallback: Error while prefetching data, exiting\n"); 1295120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten new_prefetch_status = SL_PREFETCHSTATUS_ERROR; 1305120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } else if (event == SL_PREFETCHEVENT_STATUSCHANGE && 1315120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten status == SL_PREFETCHSTATUS_SUFFICIENTDATA) { 1325120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten new_prefetch_status = status; 1335120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } else { 1345120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten return; 1355120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 1365120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten int ok; 1375120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten ok = pthread_mutex_lock(&mutex); 1385120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(ok == 0); 1395120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten prefetch_status = new_prefetch_status; 1405120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten ok = pthread_cond_signal(&cond); 1415120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(ok == 0); 1425120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten ok = pthread_mutex_unlock(&mutex); 1435120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(ok == 0); 14467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi} 14567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 1465120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten// Display rate capabilities in a nicely formatted way 1475120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 1485120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kastenvoid printCapabilities(SLuint32 capabilities) 1495120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten{ 1505120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten bool needBar = false; 1515120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("0x%x (", capabilities); 1525120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#define _(x) \ 1535120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (capabilities & SL_RATEPROP_##x) { \ 1545120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (needBar) \ 1555120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("|"); \ 1565120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("SL_RATEPROP_" #x); \ 1575120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten needBar = true; \ 1585120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten capabilities &= ~SL_RATEPROP_##x; \ 1595120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 1605120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten _(SILENTAUDIO) 1615120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten _(STAGGEREDAUDIO) 1625120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten _(NOPITCHCORAUDIO) 1635120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten _(PITCHCORAUDIO) 1645120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (capabilities != 0) { 1655120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (needBar) 1665120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("|"); 1675120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("0x%x", capabilities); 1685120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten needBar = true; 1695120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 1705120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (!needBar) 1715120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("N/A"); 1725120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf(")"); 1735120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten} 17467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 17567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//----------------------------------------------------------------- 17667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 17767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi/* Play some music from a URI */ 17867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivivoid TestSlowDownUri( SLObjectItf sl, const char* path) 17967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi{ 18067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLEngineItf EngineItf; 18167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 18267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLint32 numOutputs = 0; 18367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLuint32 deviceID = 0; 18467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 18567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLresult res; 18667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 18767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLDataSource audioSource; 18867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLDataLocator_URI uri; 18967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLDataFormat_MIME mime; 19067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 19167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLDataSink audioSink; 19267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLDataLocator_OutputMix locator_outputmix; 19367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 19467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLObjectItf player; 19567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLPlayItf playItf; 19667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLSeekItf seekItf; 19767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLPrefetchStatusItf prefetchItf; 19867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLPlaybackRateItf rateItf; 19967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 20067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLObjectItf OutputMix; 20167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 20267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLboolean required[MAX_NUMBER_INTERFACES]; 20367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; 20467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 20567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Get the SL Engine Interface which is implicit */ 20667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); CheckErr(res); 20767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 20867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Initialize arrays required[] and iidArray[] */ 20967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { 21067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi required[i] = SL_BOOLEAN_FALSE; 21167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray[i] = SL_IID_NULL; 21267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 21367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 21467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi required[0] = SL_BOOLEAN_TRUE; 21567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray[0] = SL_IID_VOLUME; 21667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi // Create Output Mix object to be used by player 2174d7c8c742d5b09895e7ce3d07d314b6ada56123dGlenn Kasten res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, 21867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray, required); CheckErr(res); 21967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 22067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi // Realizing the Output Mix object in synchronous mode. 22167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); CheckErr(res); 22267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 22367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Setup the data source structure for the URI */ 22467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi uri.locatorType = SL_DATALOCATOR_URI; 22567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi uri.URI = (SLchar*) path; 22667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi mime.formatType = SL_DATAFORMAT_MIME; 22767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi mime.mimeType = (SLchar*)NULL; 22867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; 22967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 23067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi audioSource.pFormat = (void *)&mime; 23167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi audioSource.pLocator = (void *)&uri; 23267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 23367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Setup the data sink structure */ 23467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; 23567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi locator_outputmix.outputMix = OutputMix; 23667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi audioSink.pLocator = (void *)&locator_outputmix; 23767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi audioSink.pFormat = NULL; 23867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 23967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /******************************************************/ 24067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Create the audio player */ 24167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi required[0] = SL_BOOLEAN_TRUE; 24267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray[0] = SL_IID_SEEK; 24367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi required[1] = SL_BOOLEAN_TRUE; 24467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray[1] = SL_IID_PREFETCHSTATUS; 24567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi required[2] = SL_BOOLEAN_TRUE; 24667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi iidArray[2] = SL_IID_PLAYBACKRATE; 24767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 24867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi MAX_NUMBER_INTERFACES, iidArray, required); CheckErr(res); 24967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 25067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Realizing the player in synchronous mode. */ 25167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); 25267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "URI example: after Realize\n"); 25367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 25467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Get interfaces */ 25567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); CheckErr(res); 25667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 25767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*player)->GetInterface(player, SL_IID_SEEK, (void*)&seekItf); CheckErr(res); 25867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 25967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*player)->GetInterface(player, SL_IID_PLAYBACKRATE, (void*)&rateItf); CheckErr(res); 26067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 26167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); 26267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi CheckErr(res); 2635120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, NULL); 26467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi CheckErr(res); 26567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, 26667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); CheckErr(res); 26767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 26867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Configure fill level updates every 5 percent */ 26967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi (*prefetchItf)->SetFillUpdatePeriod(prefetchItf, 50); CheckErr(res); 27067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 27167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Display duration */ 27267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLmillisecond durationInMsec = SL_TIME_UNKNOWN; 27367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->GetDuration(playItf, &durationInMsec); CheckErr(res); 27467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (durationInMsec == SL_TIME_UNKNOWN) { 27567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "Content duration is unknown (before starting to prefetch)\n"); 27667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } else { 277d968dacf7a35d52b6907283f3d95295a238340ccGlenn Kasten fprintf(stdout, "Content duration is %u ms (before starting to prefetch)\n", 27867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi durationInMsec); 27967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 28067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 28167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Loop on the whole of the content */ 28267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN); CheckErr(res); 28367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 28467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Set up marker and position callbacks */ 2855120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*playItf)->RegisterCallback(playItf, PlayEventCallback, (void *) rateItf); CheckErr(res); 28667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetCallbackEventsMask(playItf, 28767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SL_PLAYEVENT_HEADATEND | SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS); 28867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetMarkerPosition(playItf, 1500); CheckErr(res); 28967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetPositionUpdatePeriod(playItf, 500); CheckErr(res); 29067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 2915120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten /* Get the default rate */ 2925120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLpermille rate = 1234; 2935120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*rateItf)->GetRate(rateItf, &rate); CheckErr(res); 2945120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("default rate = %d per mille\n", rate); 2955120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(1000 == rate); 2965120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 2975120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten /* Get the default rate properties */ 2985120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLuint32 properties = 0; 2995120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*rateItf)->GetProperties(rateItf, &properties); CheckErr(res); 3005120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("default rate properties: "); 3015120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printCapabilities(properties); 3025120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("\n"); 3035120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten assert(SL_RATEPROP_NOPITCHCORAUDIO == properties); 3045120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 3055120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten /* Get all supported playback rate ranges */ 3065120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLuint8 index; 3075120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten for (index = 0; ; ++index) { 3085120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLpermille minRate, maxRate, stepSize; 3095120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten SLuint32 capabilities; 3105120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*rateItf)->GetRateRange(rateItf, index, &minRate, &maxRate, &stepSize, &capabilities); 3115120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (res == SL_RESULT_PARAMETER_INVALID) { 3125120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (index == 0) { 3135120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stderr, "implementation supports no rate ranges\n"); 3145120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 3155120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten break; 3165120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 3175120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten CheckErr(res); 3185120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (index == 255) { 3195120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stderr, "implementation supports way too many rate ranges, I'm giving up\n"); 3205120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten break; 3215120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 3225120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("range[%u]: min=%d, max=%d, capabilities=", index, minRate, maxRate); 3235120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printCapabilities(capabilities); 3245120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten printf("\n"); 3255120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 3265120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 32767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Change the playback rate before playback */ 3285120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten res = (*rateItf)->SetRate(rateItf, INITIAL_RATE); 3295120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (res == SL_RESULT_FEATURE_UNSUPPORTED || res == SL_RESULT_PARAMETER_INVALID) { 3305120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stderr, "initial playback rate %d per mille is unsupported\n", INITIAL_RATE); 3315120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } else { 3325120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten CheckErr(res); 3335120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 33467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 33567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /******************************************************/ 33667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Play the URI */ 33767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* first cause the player to prefetch the data */ 33867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); CheckErr(res); 33967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 3405120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten // wait for prefetch status callback to indicate either sufficient data or error 3415120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten pthread_mutex_lock(&mutex); 3425120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten while (prefetch_status == SL_PREFETCHSTATUS_UNKNOWN) { 3435120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten pthread_cond_wait(&cond, &mutex); 34467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 3455120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten pthread_mutex_unlock(&mutex); 3465120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten if (prefetch_status == SL_PREFETCHSTATUS_ERROR) { 3475120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten fprintf(stderr, "Error during prefetch, exiting\n"); 34867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi goto destroyRes; 34967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 35067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 35167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Display duration again, */ 35267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->GetDuration(playItf, &durationInMsec); CheckErr(res); 35367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (durationInMsec == SL_TIME_UNKNOWN) { 35467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "Content duration is unknown (after prefetch completed)\n"); 35567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } else { 356d968dacf7a35d52b6907283f3d95295a238340ccGlenn Kasten fprintf(stdout, "Content duration is %u ms (after prefetch completed)\n", durationInMsec); 35767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 35867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 3595120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten /* Start playing */ 36067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "starting to play\n"); 36167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); CheckErr(res); 36267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 36367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Wait as long as the duration of the content, times the repetitions, 36467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi * before stopping the loop */ 3655120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#if 1 36667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi usleep( (REPETITIONS-1) * durationInMsec * 1100); 3675120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#else 3685120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten int ii; 3695120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten for (ii = 0; ii < REPETITIONS; ++ii) { 3705120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten usleep(durationInMsec * 1100); 3715120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten PlayEventCallback(playItf, (void *) rateItf, SL_PLAYEVENT_HEADATEND); 3725120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten } 3735120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten#endif 3745120f09a47360dda4913139836c10cc5d57b0b8bGlenn Kasten 37567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN); CheckErr(res); 37667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "As of now, stopped looping (sound shouldn't repeat from now on)\n"); 37767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* wait some more to make sure it doesn't repeat */ 37867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi usleep(durationInMsec * 1000); 37967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 38067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Stop playback */ 38167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "stopping playback\n"); 38267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); CheckErr(res); 38367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 38467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel TrividestroyRes: 38567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 38667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Destroy the player */ 38767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi (*player)->Destroy(player); 38867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 38967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Destroy Output Mix object */ 39067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi (*OutputMix)->Destroy(OutputMix); 39167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi} 39267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 39367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi//----------------------------------------------------------------- 39467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Triviint main(int argc, char* const argv[]) 39567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi{ 39667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLresult res; 39767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLObjectItf sl; 39867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 39967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLSeekItf, SLPlaybackRateItf\n", 40067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi argv[0]); 40167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); 40267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "Plays a sound and loops it %d times while changing the \n", REPETITIONS); 40367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "playback rate each time.\n\n"); 40467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 40567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi if (argc == 1) { 40667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "Usage: \n\t%s path \n\t%s url\n", argv[0], argv[0]); 40767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", 40867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi argv[0], argv[0]); 4094d7c8c742d5b09895e7ce3d07d314b6ada56123dGlenn Kasten return EXIT_FAILURE; 41067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi } 41167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 41267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi SLEngineOption EngineOption[] = { 41367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi {(SLuint32) SL_ENGINEOPTION_THREADSAFE, 41467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi (SLuint32) SL_BOOLEAN_TRUE}}; 41567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 41667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); 41767537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi CheckErr(res); 41867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Realizing the SL Engine in synchronous mode. */ 41967537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); 42067537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi CheckErr(res); 42167537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 42267537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi TestSlowDownUri(sl, argv[1]); 42367537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 42467537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi /* Shutdown OpenSL ES */ 42567537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi (*sl)->Destroy(sl); 42667537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi 4274d7c8c742d5b09895e7ce3d07d314b6ada56123dGlenn Kasten return EXIT_SUCCESS; 42867537364adc48cd6fa56e36d4201428b5d9dedafJean-Michel Trivi} 429