android_LocAVPlayer.cpp revision 85edd878a30caa535b0267d8d6e61b4ccc0d5fd0
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define USE_LOG SLAndroidLogLevel_Verbose
18
19#include "sles_allinclusive.h"
20#include <media/IMediaPlayerService.h>
21#include "android_LocAVPlayer.h"
22
23
24namespace android {
25
26//--------------------------------------------------------------------------------------------------
27LocAVPlayer::LocAVPlayer(AudioPlayback_Parameters* params, bool hasVideo) :
28        GenericMediaPlayer(params, hasVideo)
29{
30    SL_LOGD("LocAVPlayer::LocAVPlayer()");
31
32}
33
34
35LocAVPlayer::~LocAVPlayer() {
36    SL_LOGD("LocAVPlayer::~LocAVPlayer()");
37
38}
39
40
41//--------------------------------------------------
42// Event handlers
43void LocAVPlayer::onPrepare() {
44    SL_LOGD("LocAVPlayer::onPrepare()");
45    sp<IMediaPlayerService> mediaPlayerService(getMediaPlayerService());
46    if (mediaPlayerService != NULL) {
47        switch (mDataLocatorType) {
48        case kDataLocatorUri:
49            mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/,
50                    mDataLocator.uriRef /*url*/, NULL /*headers*/, mPlaybackParams.sessionId);
51            if (mPlayer == NULL) {
52                SL_LOGE("media player service failed to create player by URI");
53            }
54            break;
55        case kDataLocatorFd:
56            mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/,
57                    mDataLocator.fdi.fd, mDataLocator.fdi.offset, mDataLocator.fdi.length,
58                    mPlaybackParams.sessionId);
59            if (mPlayer == NULL) {
60                SL_LOGE("media player service failed to create player by FD");
61            }
62            break;
63        case kDataLocatorNone:
64            SL_LOGE("no data locator for MediaPlayer object");
65            break;
66        default:
67            SL_LOGE("unsupported data locator %d for MediaPlayer object", mDataLocatorType);
68            break;
69        }
70    }
71    if (mPlayer == NULL) {
72        mStateFlags |= kFlagPreparedUnsuccessfully;
73    }
74    // blocks until mPlayer is prepared
75    GenericMediaPlayer::onPrepare();
76    SL_LOGD("LocAVPlayer::onPrepare() done");
77}
78
79} // namespace android
80