mediaplayer.cpp revision a514bdb58b5de4986679f72b7204b4764f7a2778
1/* mediaplayer.cpp 2** 3** Copyright 2006, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18//#define LOG_NDEBUG 0 19#define LOG_TAG "MediaPlayer" 20#include <utils/Log.h> 21 22#include <sys/types.h> 23#include <sys/stat.h> 24#include <unistd.h> 25#include <fcntl.h> 26 27#include <binder/IServiceManager.h> 28#include <binder/IPCThreadState.h> 29 30#include <media/mediaplayer.h> 31#include <media/AudioTrack.h> 32 33#include <surfaceflinger/Surface.h> 34 35#include <binder/MemoryBase.h> 36 37#include <utils/KeyedVector.h> 38#include <utils/String8.h> 39 40namespace android { 41 42MediaPlayer::MediaPlayer() 43{ 44 LOGV("constructor"); 45 mListener = NULL; 46 mCookie = NULL; 47 mDuration = -1; 48 mStreamType = AudioSystem::MUSIC; 49 mCurrentPosition = -1; 50 mSeekPosition = -1; 51 mCurrentState = MEDIA_PLAYER_IDLE; 52 mPrepareSync = false; 53 mPrepareStatus = NO_ERROR; 54 mLoop = false; 55 mLeftVolume = mRightVolume = 1.0; 56 mVideoWidth = mVideoHeight = 0; 57 mLockThreadId = 0; 58 mAudioSessionId = AudioSystem::newAudioSessionId(); 59} 60 61MediaPlayer::~MediaPlayer() 62{ 63 LOGV("destructor"); 64 disconnect(); 65 IPCThreadState::self()->flushCommands(); 66} 67 68void MediaPlayer::disconnect() 69{ 70 LOGV("disconnect"); 71 sp<IMediaPlayer> p; 72 { 73 Mutex::Autolock _l(mLock); 74 p = mPlayer; 75 mPlayer.clear(); 76 } 77 78 if (p != 0) { 79 p->disconnect(); 80 } 81} 82 83// always call with lock held 84void MediaPlayer::clear_l() 85{ 86 mDuration = -1; 87 mCurrentPosition = -1; 88 mSeekPosition = -1; 89 mVideoWidth = mVideoHeight = 0; 90} 91 92status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener) 93{ 94 LOGV("setListener"); 95 Mutex::Autolock _l(mLock); 96 mListener = listener; 97 return NO_ERROR; 98} 99 100 101status_t MediaPlayer::setDataSource(const sp<IMediaPlayer>& player) 102{ 103 status_t err = UNKNOWN_ERROR; 104 sp<IMediaPlayer> p; 105 { // scope for the lock 106 Mutex::Autolock _l(mLock); 107 108 if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) || 109 (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) { 110 LOGE("setDataSource called in state %d", mCurrentState); 111 return INVALID_OPERATION; 112 } 113 114 clear_l(); 115 p = mPlayer; 116 mPlayer = player; 117 if (player != 0) { 118 mCurrentState = MEDIA_PLAYER_INITIALIZED; 119 err = NO_ERROR; 120 } else { 121 LOGE("Unable to to create media player"); 122 } 123 } 124 125 if (p != 0) { 126 p->disconnect(); 127 } 128 129 return err; 130} 131 132status_t MediaPlayer::setDataSource( 133 const char *url, const KeyedVector<String8, String8> *headers) 134{ 135 LOGV("setDataSource(%s)", url); 136 status_t err = BAD_VALUE; 137 if (url != NULL) { 138 const sp<IMediaPlayerService>& service(getMediaPlayerService()); 139 if (service != 0) { 140 sp<IMediaPlayer> player( 141 service->create(getpid(), this, url, headers, mAudioSessionId)); 142 err = setDataSource(player); 143 } 144 } 145 return err; 146} 147 148status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length) 149{ 150 LOGV("setDataSource(%d, %lld, %lld)", fd, offset, length); 151 status_t err = UNKNOWN_ERROR; 152 const sp<IMediaPlayerService>& service(getMediaPlayerService()); 153 if (service != 0) { 154 sp<IMediaPlayer> player(service->create(getpid(), this, fd, offset, length, mAudioSessionId)); 155 err = setDataSource(player); 156 } 157 return err; 158} 159 160status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply) 161{ 162 Mutex::Autolock _l(mLock); 163 const bool hasBeenInitialized = 164 (mCurrentState != MEDIA_PLAYER_STATE_ERROR) && 165 ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE); 166 if ((mPlayer != NULL) && hasBeenInitialized) { 167 LOGV("invoke %d", request.dataSize()); 168 return mPlayer->invoke(request, reply); 169 } 170 LOGE("invoke failed: wrong state %X", mCurrentState); 171 return INVALID_OPERATION; 172} 173 174status_t MediaPlayer::suspend() { 175 Mutex::Autolock _l(mLock); 176 return mPlayer->suspend(); 177} 178 179status_t MediaPlayer::resume() { 180 Mutex::Autolock _l(mLock); 181 return mPlayer->resume(); 182} 183 184status_t MediaPlayer::setMetadataFilter(const Parcel& filter) 185{ 186 LOGD("setMetadataFilter"); 187 Mutex::Autolock lock(mLock); 188 if (mPlayer == NULL) { 189 return NO_INIT; 190 } 191 return mPlayer->setMetadataFilter(filter); 192} 193 194status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata) 195{ 196 LOGD("getMetadata"); 197 Mutex::Autolock lock(mLock); 198 if (mPlayer == NULL) { 199 return NO_INIT; 200 } 201 return mPlayer->getMetadata(update_only, apply_filter, metadata); 202} 203 204status_t MediaPlayer::setVideoSurface(const sp<Surface>& surface) 205{ 206 LOGV("setVideoSurface"); 207 Mutex::Autolock _l(mLock); 208 if (mPlayer == 0) return NO_INIT; 209 if (surface != NULL) 210 return mPlayer->setVideoSurface(surface->getISurface()); 211 else 212 return mPlayer->setVideoSurface(NULL); 213} 214 215// must call with lock held 216status_t MediaPlayer::prepareAsync_l() 217{ 218 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) { 219 mPlayer->setAudioStreamType(mStreamType); 220 mCurrentState = MEDIA_PLAYER_PREPARING; 221 return mPlayer->prepareAsync(); 222 } 223 LOGE("prepareAsync called in state %d", mCurrentState); 224 return INVALID_OPERATION; 225} 226 227// TODO: In case of error, prepareAsync provides the caller with 2 error codes, 228// one defined in the Android framework and one provided by the implementation 229// that generated the error. The sync version of prepare returns only 1 error 230// code. 231status_t MediaPlayer::prepare() 232{ 233 LOGV("prepare"); 234 Mutex::Autolock _l(mLock); 235 mLockThreadId = getThreadId(); 236 if (mPrepareSync) { 237 mLockThreadId = 0; 238 return -EALREADY; 239 } 240 mPrepareSync = true; 241 status_t ret = prepareAsync_l(); 242 if (ret != NO_ERROR) { 243 mLockThreadId = 0; 244 return ret; 245 } 246 247 if (mPrepareSync) { 248 mSignal.wait(mLock); // wait for prepare done 249 mPrepareSync = false; 250 } 251 LOGV("prepare complete - status=%d", mPrepareStatus); 252 mLockThreadId = 0; 253 return mPrepareStatus; 254} 255 256status_t MediaPlayer::prepareAsync() 257{ 258 LOGV("prepareAsync"); 259 Mutex::Autolock _l(mLock); 260 return prepareAsync_l(); 261} 262 263status_t MediaPlayer::start() 264{ 265 LOGV("start"); 266 Mutex::Autolock _l(mLock); 267 if (mCurrentState & MEDIA_PLAYER_STARTED) 268 return NO_ERROR; 269 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_PREPARED | 270 MEDIA_PLAYER_PLAYBACK_COMPLETE | MEDIA_PLAYER_PAUSED ) ) ) { 271 mPlayer->setLooping(mLoop); 272 mPlayer->setVolume(mLeftVolume, mRightVolume); 273 mCurrentState = MEDIA_PLAYER_STARTED; 274 status_t ret = mPlayer->start(); 275 if (ret != NO_ERROR) { 276 mCurrentState = MEDIA_PLAYER_STATE_ERROR; 277 } else { 278 if (mCurrentState == MEDIA_PLAYER_PLAYBACK_COMPLETE) { 279 LOGV("playback completed immediately following start()"); 280 } 281 } 282 return ret; 283 } 284 LOGE("start called in state %d", mCurrentState); 285 return INVALID_OPERATION; 286} 287 288status_t MediaPlayer::stop() 289{ 290 LOGV("stop"); 291 Mutex::Autolock _l(mLock); 292 if (mCurrentState & MEDIA_PLAYER_STOPPED) return NO_ERROR; 293 if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | 294 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) ) { 295 status_t ret = mPlayer->stop(); 296 if (ret != NO_ERROR) { 297 mCurrentState = MEDIA_PLAYER_STATE_ERROR; 298 } else { 299 mCurrentState = MEDIA_PLAYER_STOPPED; 300 } 301 return ret; 302 } 303 LOGE("stop called in state %d", mCurrentState); 304 return INVALID_OPERATION; 305} 306 307status_t MediaPlayer::pause() 308{ 309 LOGV("pause"); 310 Mutex::Autolock _l(mLock); 311 if (mCurrentState & (MEDIA_PLAYER_PAUSED|MEDIA_PLAYER_PLAYBACK_COMPLETE)) 312 return NO_ERROR; 313 if ((mPlayer != 0) && (mCurrentState & MEDIA_PLAYER_STARTED)) { 314 status_t ret = mPlayer->pause(); 315 if (ret != NO_ERROR) { 316 mCurrentState = MEDIA_PLAYER_STATE_ERROR; 317 } else { 318 mCurrentState = MEDIA_PLAYER_PAUSED; 319 } 320 return ret; 321 } 322 LOGE("pause called in state %d", mCurrentState); 323 return INVALID_OPERATION; 324} 325 326bool MediaPlayer::isPlaying() 327{ 328 Mutex::Autolock _l(mLock); 329 if (mPlayer != 0) { 330 bool temp = false; 331 mPlayer->isPlaying(&temp); 332 LOGV("isPlaying: %d", temp); 333 if ((mCurrentState & MEDIA_PLAYER_STARTED) && ! temp) { 334 LOGE("internal/external state mismatch corrected"); 335 mCurrentState = MEDIA_PLAYER_PAUSED; 336 } 337 return temp; 338 } 339 LOGV("isPlaying: no active player"); 340 return false; 341} 342 343status_t MediaPlayer::getVideoWidth(int *w) 344{ 345 LOGV("getVideoWidth"); 346 Mutex::Autolock _l(mLock); 347 if (mPlayer == 0) return INVALID_OPERATION; 348 *w = mVideoWidth; 349 return NO_ERROR; 350} 351 352status_t MediaPlayer::getVideoHeight(int *h) 353{ 354 LOGV("getVideoHeight"); 355 Mutex::Autolock _l(mLock); 356 if (mPlayer == 0) return INVALID_OPERATION; 357 *h = mVideoHeight; 358 return NO_ERROR; 359} 360 361status_t MediaPlayer::getCurrentPosition(int *msec) 362{ 363 LOGV("getCurrentPosition"); 364 Mutex::Autolock _l(mLock); 365 if (mPlayer != 0) { 366 if (mCurrentPosition >= 0) { 367 LOGV("Using cached seek position: %d", mCurrentPosition); 368 *msec = mCurrentPosition; 369 return NO_ERROR; 370 } 371 return mPlayer->getCurrentPosition(msec); 372 } 373 return INVALID_OPERATION; 374} 375 376status_t MediaPlayer::getDuration_l(int *msec) 377{ 378 LOGV("getDuration"); 379 bool isValidState = (mCurrentState & (MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_STOPPED | MEDIA_PLAYER_PLAYBACK_COMPLETE)); 380 if (mPlayer != 0 && isValidState) { 381 status_t ret = NO_ERROR; 382 if (mDuration <= 0) 383 ret = mPlayer->getDuration(&mDuration); 384 if (msec) 385 *msec = mDuration; 386 return ret; 387 } 388 LOGE("Attempt to call getDuration without a valid mediaplayer"); 389 return INVALID_OPERATION; 390} 391 392status_t MediaPlayer::getDuration(int *msec) 393{ 394 Mutex::Autolock _l(mLock); 395 return getDuration_l(msec); 396} 397 398status_t MediaPlayer::seekTo_l(int msec) 399{ 400 LOGV("seekTo %d", msec); 401 if ((mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_STARTED | MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE) ) ) { 402 if ( msec < 0 ) { 403 LOGW("Attempt to seek to invalid position: %d", msec); 404 msec = 0; 405 } else if ((mDuration > 0) && (msec > mDuration)) { 406 LOGW("Attempt to seek to past end of file: request = %d, EOF = %d", msec, mDuration); 407 msec = mDuration; 408 } 409 // cache duration 410 mCurrentPosition = msec; 411 if (mSeekPosition < 0) { 412 getDuration_l(NULL); 413 mSeekPosition = msec; 414 return mPlayer->seekTo(msec); 415 } 416 else { 417 LOGV("Seek in progress - queue up seekTo[%d]", msec); 418 return NO_ERROR; 419 } 420 } 421 LOGE("Attempt to perform seekTo in wrong state: mPlayer=%p, mCurrentState=%u", mPlayer.get(), mCurrentState); 422 return INVALID_OPERATION; 423} 424 425status_t MediaPlayer::seekTo(int msec) 426{ 427 mLockThreadId = getThreadId(); 428 Mutex::Autolock _l(mLock); 429 status_t result = seekTo_l(msec); 430 mLockThreadId = 0; 431 432 return result; 433} 434 435status_t MediaPlayer::reset() 436{ 437 LOGV("reset"); 438 Mutex::Autolock _l(mLock); 439 mLoop = false; 440 if (mCurrentState == MEDIA_PLAYER_IDLE) return NO_ERROR; 441 mPrepareSync = false; 442 if (mPlayer != 0) { 443 status_t ret = mPlayer->reset(); 444 if (ret != NO_ERROR) { 445 LOGE("reset() failed with return code (%d)", ret); 446 mCurrentState = MEDIA_PLAYER_STATE_ERROR; 447 } else { 448 mCurrentState = MEDIA_PLAYER_IDLE; 449 } 450 return ret; 451 } 452 clear_l(); 453 return NO_ERROR; 454} 455 456status_t MediaPlayer::setAudioStreamType(int type) 457{ 458 LOGV("MediaPlayer::setAudioStreamType"); 459 Mutex::Autolock _l(mLock); 460 if (mStreamType == type) return NO_ERROR; 461 if (mCurrentState & ( MEDIA_PLAYER_PREPARED | MEDIA_PLAYER_STARTED | 462 MEDIA_PLAYER_PAUSED | MEDIA_PLAYER_PLAYBACK_COMPLETE ) ) { 463 // Can't change the stream type after prepare 464 LOGE("setAudioStream called in state %d", mCurrentState); 465 return INVALID_OPERATION; 466 } 467 // cache 468 mStreamType = type; 469 return OK; 470} 471 472status_t MediaPlayer::setLooping(int loop) 473{ 474 LOGV("MediaPlayer::setLooping"); 475 Mutex::Autolock _l(mLock); 476 mLoop = (loop != 0); 477 if (mPlayer != 0) { 478 return mPlayer->setLooping(loop); 479 } 480 return OK; 481} 482 483bool MediaPlayer::isLooping() { 484 LOGV("isLooping"); 485 Mutex::Autolock _l(mLock); 486 if (mPlayer != 0) { 487 return mLoop; 488 } 489 LOGV("isLooping: no active player"); 490 return false; 491} 492 493status_t MediaPlayer::setVolume(float leftVolume, float rightVolume) 494{ 495 LOGV("MediaPlayer::setVolume(%f, %f)", leftVolume, rightVolume); 496 Mutex::Autolock _l(mLock); 497 mLeftVolume = leftVolume; 498 mRightVolume = rightVolume; 499 if (mPlayer != 0) { 500 return mPlayer->setVolume(leftVolume, rightVolume); 501 } 502 return OK; 503} 504 505status_t MediaPlayer::setAudioSessionId(int sessionId) 506{ 507 LOGV("MediaPlayer::setAudioSessionId(%d)", sessionId); 508 Mutex::Autolock _l(mLock); 509 if (!(mCurrentState & MEDIA_PLAYER_IDLE)) { 510 LOGE("setAudioSessionId called in state %d", mCurrentState); 511 return INVALID_OPERATION; 512 } 513 if (sessionId < 0) { 514 return BAD_VALUE; 515 } 516 mAudioSessionId = sessionId; 517 return NO_ERROR; 518} 519 520int MediaPlayer::getAudioSessionId() 521{ 522 Mutex::Autolock _l(mLock); 523 return mAudioSessionId; 524} 525 526void MediaPlayer::notify(int msg, int ext1, int ext2) 527{ 528 LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2); 529 bool send = true; 530 bool locked = false; 531 532 // TODO: In the future, we might be on the same thread if the app is 533 // running in the same process as the media server. In that case, 534 // this will deadlock. 535 // 536 // The threadId hack below works around this for the care of prepare 537 // and seekTo within the same process. 538 // FIXME: Remember, this is a hack, it's not even a hack that is applied 539 // consistently for all use-cases, this needs to be revisited. 540 if (mLockThreadId != getThreadId()) { 541 mLock.lock(); 542 locked = true; 543 } 544 545 if (mPlayer == 0) { 546 LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2); 547 if (locked) mLock.unlock(); // release the lock when done. 548 return; 549 } 550 551 switch (msg) { 552 case MEDIA_NOP: // interface test message 553 break; 554 case MEDIA_PREPARED: 555 LOGV("prepared"); 556 mCurrentState = MEDIA_PLAYER_PREPARED; 557 if (mPrepareSync) { 558 LOGV("signal application thread"); 559 mPrepareSync = false; 560 mPrepareStatus = NO_ERROR; 561 mSignal.signal(); 562 } 563 break; 564 case MEDIA_PLAYBACK_COMPLETE: 565 LOGV("playback complete"); 566 if (!mLoop) { 567 mCurrentState = MEDIA_PLAYER_PLAYBACK_COMPLETE; 568 } 569 break; 570 case MEDIA_ERROR: 571 // Always log errors. 572 // ext1: Media framework error code. 573 // ext2: Implementation dependant error code. 574 LOGE("error (%d, %d)", ext1, ext2); 575 mCurrentState = MEDIA_PLAYER_STATE_ERROR; 576 if (mPrepareSync) 577 { 578 LOGV("signal application thread"); 579 mPrepareSync = false; 580 mPrepareStatus = ext1; 581 mSignal.signal(); 582 send = false; 583 } 584 break; 585 case MEDIA_INFO: 586 // ext1: Media framework error code. 587 // ext2: Implementation dependant error code. 588 LOGW("info/warning (%d, %d)", ext1, ext2); 589 break; 590 case MEDIA_SEEK_COMPLETE: 591 LOGV("Received seek complete"); 592 if (mSeekPosition != mCurrentPosition) { 593 LOGV("Executing queued seekTo(%d)", mSeekPosition); 594 mSeekPosition = -1; 595 seekTo_l(mCurrentPosition); 596 } 597 else { 598 LOGV("All seeks complete - return to regularly scheduled program"); 599 mCurrentPosition = mSeekPosition = -1; 600 } 601 break; 602 case MEDIA_BUFFERING_UPDATE: 603 LOGV("buffering %d", ext1); 604 break; 605 case MEDIA_SET_VIDEO_SIZE: 606 LOGV("New video size %d x %d", ext1, ext2); 607 mVideoWidth = ext1; 608 mVideoHeight = ext2; 609 break; 610 default: 611 LOGV("unrecognized message: (%d, %d, %d)", msg, ext1, ext2); 612 break; 613 } 614 615 sp<MediaPlayerListener> listener = mListener; 616 if (locked) mLock.unlock(); 617 618 // this prevents re-entrant calls into client code 619 if ((listener != 0) && send) { 620 Mutex::Autolock _l(mNotifyLock); 621 LOGV("callback application"); 622 listener->notify(msg, ext1, ext2); 623 LOGV("back from callback"); 624 } 625} 626 627/*static*/ sp<IMemory> MediaPlayer::decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) 628{ 629 LOGV("decode(%s)", url); 630 sp<IMemory> p; 631 const sp<IMediaPlayerService>& service = getMediaPlayerService(); 632 if (service != 0) { 633 p = service->decode(url, pSampleRate, pNumChannels, pFormat); 634 } else { 635 LOGE("Unable to locate media service"); 636 } 637 return p; 638 639} 640 641void MediaPlayer::died() 642{ 643 LOGV("died"); 644 notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0); 645} 646 647/*static*/ sp<IMemory> MediaPlayer::decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) 648{ 649 LOGV("decode(%d, %lld, %lld)", fd, offset, length); 650 sp<IMemory> p; 651 const sp<IMediaPlayerService>& service = getMediaPlayerService(); 652 if (service != 0) { 653 p = service->decode(fd, offset, length, pSampleRate, pNumChannels, pFormat); 654 } else { 655 LOGE("Unable to locate media service"); 656 } 657 return p; 658 659} 660 661extern "C" { 662#define FLOATING_POINT 1 663#include "fftwrap.h" 664} 665 666static void *ffttable = NULL; 667 668// peeks at the audio data and fills 'data' with the requested kind 669// (currently kind=0 returns mono 16 bit PCM data, and kind=1 returns 670// 256 point FFT data). Return value is number of samples returned, 671// which may be 0. 672/*static*/ int MediaPlayer::snoop(short* data, int len, int kind) { 673 674 sp<IMemory> p; 675 const sp<IMediaPlayerService>& service = getMediaPlayerService(); 676 if (service != 0) { 677 // Take a peek at the waveform. The returned data consists of 16 bit mono PCM data. 678 p = service->snoop(); 679 680 if (p == NULL) { 681 return 0; 682 } 683 684 if (kind == 0) { // return waveform data 685 int plen = p->size(); 686 len *= 2; // number of shorts -> number of bytes 687 short *src = (short*) p->pointer(); 688 if (plen > len) { 689 plen = len; 690 } 691 memcpy(data, src, plen); 692 return plen / sizeof(short); // return number of samples 693 } else if (kind == 1) { 694 // TODO: use a more efficient FFT 695 // Right now this uses the speex library, which is compiled to do a float FFT 696 if (!ffttable) ffttable = spx_fft_init(512); 697 short *usrc = (short*) p->pointer(); 698 float fsrc[512]; 699 for (int i=0;i<512;i++) 700 fsrc[i] = usrc[i]; 701 float fdst[512]; 702 spx_fft_float(ffttable, fsrc, fdst); 703 if (len > 512) { 704 len = 512; 705 } 706 len /= 2; // only half the output data is valid 707 for (int i=0; i < len; i++) 708 data[i] = fdst[i]; 709 return len; 710 } 711 712 } else { 713 LOGE("Unable to locate media service"); 714 } 715 return 0; 716} 717 718}; // namespace android 719