blob: 8db5b9b8eb77746d31c2ba48c3a893da856f9a51 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* MidiFile.cpp
2**
3** Copyright 2007, 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 "MidiFile"
20#include "utils/Log.h"
21
22#include <stdio.h>
23#include <assert.h>
24#include <limits.h>
25#include <unistd.h>
26#include <fcntl.h>
27#include <sched.h>
28#include <utils/threads.h>
29#include <libsonivox/eas_reverb.h>
30#include <sys/types.h>
31#include <sys/stat.h>
Glenn Kasten6af763b2011-05-04 17:58:57 -070032#include <unistd.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Dima Zavin34bb4192011-05-11 14:15:23 -070034#include <system/audio.h>
Dima Zavin24fc2fb2011-04-19 22:30:36 -070035
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "MidiFile.h"
37
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038// ----------------------------------------------------------------------------
39
40namespace android {
41
42// ----------------------------------------------------------------------------
43
44// The midi engine buffers are a bit small (128 frames), so we batch them up
45static const int NUM_BUFFERS = 4;
46
47// TODO: Determine appropriate return codes
48static status_t ERROR_NOT_OPEN = -1;
49static status_t ERROR_OPEN_FAILED = -2;
50static status_t ERROR_EAS_FAILURE = -3;
51static status_t ERROR_ALLOCATE_FAILED = -4;
52
53static const S_EAS_LIB_CONFIG* pLibConfig = NULL;
54
55MidiFile::MidiFile() :
56 mEasData(NULL), mEasHandle(NULL), mAudioBuffer(NULL),
57 mPlayTime(-1), mDuration(-1), mState(EAS_STATE_ERROR),
Dima Zavin24fc2fb2011-04-19 22:30:36 -070058 mStreamType(AUDIO_STREAM_MUSIC), mLoop(false), mExit(false),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 mPaused(false), mRender(false), mTid(-1)
60{
Steve Block71f2cf12011-10-20 11:56:00 +010061 ALOGV("constructor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
63 mFileLocator.path = NULL;
64 mFileLocator.fd = -1;
65 mFileLocator.offset = 0;
66 mFileLocator.length = 0;
67
68 // get the library configuration and do sanity check
69 if (pLibConfig == NULL)
70 pLibConfig = EAS_Config();
71 if ((pLibConfig == NULL) || (LIB_VERSION != pLibConfig->libVersion)) {
Steve Block3762c312012-01-06 19:20:56 +000072 ALOGE("EAS library/header mismatch");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 goto Failed;
74 }
75
76 // initialize EAS library
77 if (EAS_Init(&mEasData) != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +000078 ALOGE("EAS_Init failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 goto Failed;
80 }
81
82 // select reverb preset and enable
83 EAS_SetParameter(mEasData, EAS_MODULE_REVERB, EAS_PARAM_REVERB_PRESET, EAS_PARAM_REVERB_CHAMBER);
84 EAS_SetParameter(mEasData, EAS_MODULE_REVERB, EAS_PARAM_REVERB_BYPASS, EAS_FALSE);
85
86 // create playback thread
87 {
88 Mutex::Autolock l(mMutex);
Glenn Kasten376c3932011-06-23 17:11:35 -070089 mThread = new MidiFileThread(this);
90 mThread->run("midithread", ANDROID_PRIORITY_AUDIO);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 mCondition.wait(mMutex);
Steve Block71f2cf12011-10-20 11:56:00 +010092 ALOGV("thread started");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94
95 // indicate success
96 if (mTid > 0) {
Steve Block71f2cf12011-10-20 11:56:00 +010097 ALOGV(" render thread(%d) started", mTid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 mState = EAS_STATE_READY;
99 }
100
101Failed:
102 return;
103}
104
105status_t MidiFile::initCheck()
106{
107 if (mState == EAS_STATE_ERROR) return ERROR_EAS_FAILURE;
108 return NO_ERROR;
109}
110
111MidiFile::~MidiFile() {
Steve Block71f2cf12011-10-20 11:56:00 +0100112 ALOGV("MidiFile destructor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 release();
114}
115
Andreas Huber25643002010-01-28 11:19:57 -0800116status_t MidiFile::setDataSource(
117 const char* path, const KeyedVector<String8, String8> *) {
Steve Block71f2cf12011-10-20 11:56:00 +0100118 ALOGV("MidiFile::setDataSource url=%s", path);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 Mutex::Autolock lock(mMutex);
120
121 // file still open?
122 if (mEasHandle) {
123 reset_nosync();
124 }
125
126 // open file and set paused state
127 mFileLocator.path = strdup(path);
128 mFileLocator.fd = -1;
129 mFileLocator.offset = 0;
130 mFileLocator.length = 0;
131 EAS_RESULT result = EAS_OpenFile(mEasData, &mFileLocator, &mEasHandle);
132 if (result == EAS_SUCCESS) {
133 updateState();
134 }
135
136 if (result != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +0000137 ALOGE("EAS_OpenFile failed: [%d]", (int)result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 mState = EAS_STATE_ERROR;
139 return ERROR_OPEN_FAILED;
140 }
141
142 mState = EAS_STATE_OPEN;
143 mPlayTime = 0;
144 return NO_ERROR;
145}
146
147status_t MidiFile::setDataSource(int fd, int64_t offset, int64_t length)
148{
Steve Block71f2cf12011-10-20 11:56:00 +0100149 ALOGV("MidiFile::setDataSource fd=%d", fd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 Mutex::Autolock lock(mMutex);
151
152 // file still open?
153 if (mEasHandle) {
154 reset_nosync();
155 }
156
157 // open file and set paused state
158 mFileLocator.fd = dup(fd);
159 mFileLocator.offset = offset;
160 mFileLocator.length = length;
161 EAS_RESULT result = EAS_OpenFile(mEasData, &mFileLocator, &mEasHandle);
162 updateState();
163
164 if (result != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +0000165 ALOGE("EAS_OpenFile failed: [%d]", (int)result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 mState = EAS_STATE_ERROR;
167 return ERROR_OPEN_FAILED;
168 }
169
170 mState = EAS_STATE_OPEN;
171 mPlayTime = 0;
172 return NO_ERROR;
173}
174
175status_t MidiFile::prepare()
176{
Steve Block71f2cf12011-10-20 11:56:00 +0100177 ALOGV("MidiFile::prepare");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 Mutex::Autolock lock(mMutex);
179 if (!mEasHandle) {
180 return ERROR_NOT_OPEN;
181 }
182 EAS_RESULT result;
183 if ((result = EAS_Prepare(mEasData, mEasHandle)) != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +0000184 ALOGE("EAS_Prepare failed: [%ld]", result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 return ERROR_EAS_FAILURE;
186 }
187 updateState();
188 return NO_ERROR;
189}
190
191status_t MidiFile::prepareAsync()
192{
Steve Block71f2cf12011-10-20 11:56:00 +0100193 ALOGV("MidiFile::prepareAsync");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 status_t ret = prepare();
195
196 // don't hold lock during callback
197 if (ret == NO_ERROR) {
198 sendEvent(MEDIA_PREPARED);
199 } else {
200 sendEvent(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ret);
201 }
202 return ret;
203}
204
205status_t MidiFile::start()
206{
Steve Block71f2cf12011-10-20 11:56:00 +0100207 ALOGV("MidiFile::start");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 Mutex::Autolock lock(mMutex);
209 if (!mEasHandle) {
210 return ERROR_NOT_OPEN;
211 }
212
213 // resuming after pause?
214 if (mPaused) {
215 if (EAS_Resume(mEasData, mEasHandle) != EAS_SUCCESS) {
216 return ERROR_EAS_FAILURE;
217 }
218 mPaused = false;
219 updateState();
220 }
221
222 mRender = true;
223
224 // wake up render thread
Steve Block71f2cf12011-10-20 11:56:00 +0100225 ALOGV(" wakeup render thread");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 mCondition.signal();
227 return NO_ERROR;
228}
229
230status_t MidiFile::stop()
231{
Steve Block71f2cf12011-10-20 11:56:00 +0100232 ALOGV("MidiFile::stop");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 Mutex::Autolock lock(mMutex);
234 if (!mEasHandle) {
235 return ERROR_NOT_OPEN;
236 }
237 if (!mPaused && (mState != EAS_STATE_STOPPED)) {
238 EAS_RESULT result = EAS_Pause(mEasData, mEasHandle);
239 if (result != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +0000240 ALOGE("EAS_Pause returned error %ld", result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 return ERROR_EAS_FAILURE;
242 }
243 }
244 mPaused = false;
245 return NO_ERROR;
246}
247
248status_t MidiFile::seekTo(int position)
249{
Steve Block71f2cf12011-10-20 11:56:00 +0100250 ALOGV("MidiFile::seekTo %d", position);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 // hold lock during EAS calls
252 {
253 Mutex::Autolock lock(mMutex);
254 if (!mEasHandle) {
255 return ERROR_NOT_OPEN;
256 }
257 EAS_RESULT result;
258 if ((result = EAS_Locate(mEasData, mEasHandle, position, false))
259 != EAS_SUCCESS)
260 {
Steve Block3762c312012-01-06 19:20:56 +0000261 ALOGE("EAS_Locate returned %ld", result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 return ERROR_EAS_FAILURE;
263 }
264 EAS_GetLocation(mEasData, mEasHandle, &mPlayTime);
265 }
266 sendEvent(MEDIA_SEEK_COMPLETE);
267 return NO_ERROR;
268}
269
270status_t MidiFile::pause()
271{
Steve Block71f2cf12011-10-20 11:56:00 +0100272 ALOGV("MidiFile::pause");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 Mutex::Autolock lock(mMutex);
274 if (!mEasHandle) {
275 return ERROR_NOT_OPEN;
276 }
277 if ((mState == EAS_STATE_PAUSING) || (mState == EAS_STATE_PAUSED)) return NO_ERROR;
278 if (EAS_Pause(mEasData, mEasHandle) != EAS_SUCCESS) {
279 return ERROR_EAS_FAILURE;
280 }
281 mPaused = true;
282 return NO_ERROR;
283}
284
285bool MidiFile::isPlaying()
286{
Steve Block71f2cf12011-10-20 11:56:00 +0100287 ALOGV("MidiFile::isPlaying, mState=%d", int(mState));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 if (!mEasHandle || mPaused) return false;
289 return (mState == EAS_STATE_PLAY);
290}
291
292status_t MidiFile::getCurrentPosition(int* position)
293{
Steve Block71f2cf12011-10-20 11:56:00 +0100294 ALOGV("MidiFile::getCurrentPosition");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 if (!mEasHandle) {
Steve Block3762c312012-01-06 19:20:56 +0000296 ALOGE("getCurrentPosition(): file not open");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 return ERROR_NOT_OPEN;
298 }
299 if (mPlayTime < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000300 ALOGE("getCurrentPosition(): mPlayTime = %ld", mPlayTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 return ERROR_EAS_FAILURE;
302 }
303 *position = mPlayTime;
304 return NO_ERROR;
305}
306
307status_t MidiFile::getDuration(int* duration)
308{
309
Steve Block71f2cf12011-10-20 11:56:00 +0100310 ALOGV("MidiFile::getDuration");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 {
312 Mutex::Autolock lock(mMutex);
313 if (!mEasHandle) return ERROR_NOT_OPEN;
314 *duration = mDuration;
315 }
316
317 // if no duration cached, get the duration
318 // don't need a lock here because we spin up a new engine
319 if (*duration < 0) {
320 EAS_I32 temp;
321 EAS_DATA_HANDLE easData = NULL;
322 EAS_HANDLE easHandle = NULL;
323 EAS_RESULT result = EAS_Init(&easData);
324 if (result == EAS_SUCCESS) {
325 result = EAS_OpenFile(easData, &mFileLocator, &easHandle);
326 }
327 if (result == EAS_SUCCESS) {
328 result = EAS_Prepare(easData, easHandle);
329 }
330 if (result == EAS_SUCCESS) {
331 result = EAS_ParseMetaData(easData, easHandle, &temp);
332 }
333 if (easHandle) {
334 EAS_CloseFile(easData, easHandle);
335 }
336 if (easData) {
337 EAS_Shutdown(easData);
338 }
339
340 if (result != EAS_SUCCESS) {
341 return ERROR_EAS_FAILURE;
342 }
343
344 // cache successful result
345 mDuration = *duration = int(temp);
346 }
347
348 return NO_ERROR;
349}
350
351status_t MidiFile::release()
352{
Steve Block71f2cf12011-10-20 11:56:00 +0100353 ALOGV("MidiFile::release");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 Mutex::Autolock l(mMutex);
355 reset_nosync();
356
357 // wait for render thread to exit
358 mExit = true;
359 mCondition.signal();
360
361 // wait for thread to exit
362 if (mAudioBuffer) {
363 mCondition.wait(mMutex);
364 }
365
366 // release resources
367 if (mEasData) {
368 EAS_Shutdown(mEasData);
369 mEasData = NULL;
370 }
371 return NO_ERROR;
372}
373
374status_t MidiFile::reset()
375{
Steve Block71f2cf12011-10-20 11:56:00 +0100376 ALOGV("MidiFile::reset");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 Mutex::Autolock lock(mMutex);
378 return reset_nosync();
379}
380
381// call only with mutex held
382status_t MidiFile::reset_nosync()
383{
Steve Block71f2cf12011-10-20 11:56:00 +0100384 ALOGV("MidiFile::reset_nosync");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 // close file
386 if (mEasHandle) {
387 EAS_CloseFile(mEasData, mEasHandle);
388 mEasHandle = NULL;
389 }
390 if (mFileLocator.path) {
391 free((void*)mFileLocator.path);
392 mFileLocator.path = NULL;
393 }
394 if (mFileLocator.fd >= 0) {
395 close(mFileLocator.fd);
396 }
397 mFileLocator.fd = -1;
398 mFileLocator.offset = 0;
399 mFileLocator.length = 0;
400
401 mPlayTime = -1;
402 mDuration = -1;
403 mLoop = false;
404 mPaused = false;
405 mRender = false;
406 return NO_ERROR;
407}
408
409status_t MidiFile::setLooping(int loop)
410{
Steve Block71f2cf12011-10-20 11:56:00 +0100411 ALOGV("MidiFile::setLooping");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 Mutex::Autolock lock(mMutex);
413 if (!mEasHandle) {
414 return ERROR_NOT_OPEN;
415 }
416 loop = loop ? -1 : 0;
417 if (EAS_SetRepeat(mEasData, mEasHandle, loop) != EAS_SUCCESS) {
418 return ERROR_EAS_FAILURE;
419 }
420 return NO_ERROR;
421}
422
423status_t MidiFile::createOutputTrack() {
Jean-Michel Trivi4ed260f2012-03-02 14:54:07 -0800424 if (mAudioSink->open(pLibConfig->sampleRate, pLibConfig->numChannels,
425 CHANNEL_MASK_USE_CHANNEL_ORDER, AUDIO_FORMAT_PCM_16_BIT, 2) != NO_ERROR) {
Steve Block3762c312012-01-06 19:20:56 +0000426 ALOGE("mAudioSink open failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 return ERROR_OPEN_FAILED;
428 }
429 return NO_ERROR;
430}
431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432int MidiFile::render() {
433 EAS_RESULT result = EAS_FAILURE;
434 EAS_I32 count;
435 int temp;
436 bool audioStarted = false;
437
Steve Block71f2cf12011-10-20 11:56:00 +0100438 ALOGV("MidiFile::render");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439
440 // allocate render buffer
441 mAudioBuffer = new EAS_PCM[pLibConfig->mixBufferSize * pLibConfig->numChannels * NUM_BUFFERS];
442 if (!mAudioBuffer) {
Steve Block3762c312012-01-06 19:20:56 +0000443 ALOGE("mAudioBuffer allocate failed");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 goto threadExit;
445 }
446
447 // signal main thread that we started
448 {
449 Mutex::Autolock l(mMutex);
Glenn Kasten6af763b2011-05-04 17:58:57 -0700450 mTid = gettid();
Steve Block71f2cf12011-10-20 11:56:00 +0100451 ALOGV("render thread(%d) signal", mTid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 mCondition.signal();
453 }
454
455 while (1) {
456 mMutex.lock();
457
458 // nothing to render, wait for client thread to wake us up
459 while (!mRender && !mExit)
460 {
Steve Block71f2cf12011-10-20 11:56:00 +0100461 ALOGV("MidiFile::render - signal wait");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 mCondition.wait(mMutex);
Steve Block71f2cf12011-10-20 11:56:00 +0100463 ALOGV("MidiFile::render - signal rx'd");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 }
465 if (mExit) {
466 mMutex.unlock();
467 break;
468 }
469
470 // render midi data into the input buffer
Steve Block71f2cf12011-10-20 11:56:00 +0100471 //ALOGV("MidiFile::render - rendering audio");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 int num_output = 0;
473 EAS_PCM* p = mAudioBuffer;
474 for (int i = 0; i < NUM_BUFFERS; i++) {
475 result = EAS_Render(mEasData, p, pLibConfig->mixBufferSize, &count);
476 if (result != EAS_SUCCESS) {
Steve Block3762c312012-01-06 19:20:56 +0000477 ALOGE("EAS_Render returned %ld", result);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
479 p += count * pLibConfig->numChannels;
480 num_output += count * pLibConfig->numChannels * sizeof(EAS_PCM);
481 }
482
483 // update playback state and position
Steve Block71f2cf12011-10-20 11:56:00 +0100484 // ALOGV("MidiFile::render - updating state");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 EAS_GetLocation(mEasData, mEasHandle, &mPlayTime);
486 EAS_State(mEasData, mEasHandle, &mState);
487 mMutex.unlock();
488
489 // create audio output track if necessary
490 if (!mAudioSink->ready()) {
Steve Block71f2cf12011-10-20 11:56:00 +0100491 ALOGV("MidiFile::render - create output track");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 if (createOutputTrack() != NO_ERROR)
493 goto threadExit;
494 }
495
496 // Write data to the audio hardware
Steve Block71f2cf12011-10-20 11:56:00 +0100497 // ALOGV("MidiFile::render - writing to audio output");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 if ((temp = mAudioSink->write(mAudioBuffer, num_output)) < 0) {
Steve Block3762c312012-01-06 19:20:56 +0000499 ALOGE("Error in writing:%d",temp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 return temp;
501 }
502
503 // start audio output if necessary
504 if (!audioStarted) {
Steve Block71f2cf12011-10-20 11:56:00 +0100505 //ALOGV("MidiFile::render - starting audio");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 mAudioSink->start();
507 audioStarted = true;
508 }
509
510 // still playing?
511 if ((mState == EAS_STATE_STOPPED) || (mState == EAS_STATE_ERROR) ||
512 (mState == EAS_STATE_PAUSED))
513 {
514 switch(mState) {
515 case EAS_STATE_STOPPED:
516 {
Steve Block71f2cf12011-10-20 11:56:00 +0100517 ALOGV("MidiFile::render - stopped");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 sendEvent(MEDIA_PLAYBACK_COMPLETE);
519 break;
520 }
521 case EAS_STATE_ERROR:
522 {
Steve Block3762c312012-01-06 19:20:56 +0000523 ALOGE("MidiFile::render - error");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 sendEvent(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN);
525 break;
526 }
527 case EAS_STATE_PAUSED:
Steve Block71f2cf12011-10-20 11:56:00 +0100528 ALOGV("MidiFile::render - paused");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 break;
530 default:
531 break;
532 }
533 mAudioSink->stop();
534 audioStarted = false;
535 mRender = false;
536 }
537 }
538
539threadExit:
540 mAudioSink.clear();
541 if (mAudioBuffer) {
542 delete [] mAudioBuffer;
543 mAudioBuffer = NULL;
544 }
545 mMutex.lock();
546 mTid = -1;
547 mCondition.signal();
548 mMutex.unlock();
549 return result;
550}
551
552} // end namespace android