CMediaPlayer.c revision bcc5c7225e3b7a1dbf2e9e830987f69167acf06f
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                result = android_Player_setVideoSurface(thiz->mAVPlayer.get(), nativeSurface);
61            }
62        }
63    }
64#endif
65
66    return result;
67}
68
69
70XAresult CMediaPlayer_Resume(void *self, XAboolean async)
71{
72    return XA_RESULT_SUCCESS;
73}
74
75
76/** \brief Hook called by Object::Destroy when a media player is destroyed */
77
78void CMediaPlayer_Destroy(void *self)
79{
80    CMediaPlayer *thiz = (CMediaPlayer *) self;
81    freeDataLocatorFormat(&thiz->mDataSource);
82    freeDataLocatorFormat(&thiz->mBankSource);
83    freeDataLocatorFormat(&thiz->mAudioSink);
84    freeDataLocatorFormat(&thiz->mImageVideoSink);
85    freeDataLocatorFormat(&thiz->mVibraSink);
86    freeDataLocatorFormat(&thiz->mLEDArraySink);
87#ifdef ANDROID
88    android_Player_destroy(thiz);
89#endif
90}
91
92
93predestroy_t CMediaPlayer_PreDestroy(void *self)
94{
95    return predestroy_ok;
96}
97