CMediaPlayer.c revision 68d56b8ebaf60184a3aef988e3d2b09ed8b88c05
1/*
2 * Copyright (C) 2010 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/** \file CMediaPlayer.c MediaPlayer class */
18
19#ifdef ANDROID
20
21#include <binder/ProcessState.h>
22
23#include <media/IStreamSource.h>
24#include <media/mediaplayer.h>
25#include <media/stagefright/foundation/ADebug.h>
26
27#include <binder/IServiceManager.h>
28#include <media/IMediaPlayerService.h>
29#include <surfaceflinger/ISurfaceComposer.h>
30#include <surfaceflinger/SurfaceComposerClient.h>
31
32#include <fcntl.h>
33#endif
34
35#include "sles_allinclusive.h"
36
37#ifdef ANDROID
38using namespace android;
39
40#endif
41
42
43XAresult CMediaPlayer_Realize(void *self, XAboolean async)
44{
45    CMediaPlayer *thiz = (CMediaPlayer *) self;
46
47    XAresult result = XA_RESULT_SUCCESS;
48
49#ifdef ANDROID
50    // realize player
51    result = android_Player_realize(thiz, async);
52    if (XA_RESULT_SUCCESS == result) {
53
54        // if there is a video sink
55        if (XA_DATALOCATOR_NATIVEDISPLAY == thiz->mImageVideoSink.mLocator.mLocatorType) {
56            XANativeHandle nativeSurface = thiz->mImageVideoSink.mLocator.mNativeDisplay.hWindow;
57
58            if ((thiz->mAVPlayer != 0) && (NULL != nativeSurface)) {
59                // initialize display surface
60                android::GenericMediaPlayer* avp =
61                        (android::GenericMediaPlayer*)(thiz->mAVPlayer.get());
62                result = android_Player_setVideoSurface(avp, nativeSurface);
63            }
64        }
65    }
66#endif
67
68    return result;
69}
70
71
72XAresult CMediaPlayer_Resume(void *self, XAboolean async)
73{
74    return XA_RESULT_SUCCESS;
75}
76
77
78/** \brief Hook called by Object::Destroy when a media player is destroyed */
79
80void CMediaPlayer_Destroy(void *self)
81{
82    CMediaPlayer *thiz = (CMediaPlayer *) self;
83    freeDataLocatorFormat(&thiz->mDataSource);
84    freeDataLocatorFormat(&thiz->mBankSource);
85    freeDataLocatorFormat(&thiz->mAudioSink);
86    freeDataLocatorFormat(&thiz->mImageVideoSink);
87    freeDataLocatorFormat(&thiz->mVibraSink);
88    freeDataLocatorFormat(&thiz->mLEDArraySink);
89#ifdef ANDROID
90    android_Player_destroy(thiz);
91#endif
92}
93
94
95predestroy_t CMediaPlayer_PreDestroy(void *self)
96{
97    return predestroy_ok;
98}
99