| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2007 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 | #ifndef ANDROID_MEDIAPLAYERINTERFACE_H | 
 | 18 | #define ANDROID_MEDIAPLAYERINTERFACE_H | 
 | 19 |  | 
 | 20 | #ifdef __cplusplus | 
 | 21 |  | 
| Nicolas Catania | 14d2747 | 2009-07-13 14:37:49 -0700 | [diff] [blame] | 22 | #include <sys/types.h> | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <ui/ISurface.h> | 
 | 24 | #include <utils/RefBase.h> | 
| Nicolas Catania | 14d2747 | 2009-07-13 14:37:49 -0700 | [diff] [blame] | 25 | #include <utils/Errors.h> | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 |  | 
 | 27 | #include <media/mediaplayer.h> | 
 | 28 | #include <media/AudioSystem.h> | 
 | 29 |  | 
 | 30 | namespace android { | 
 | 31 |  | 
| niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame^] | 32 | typedef int32_t MetadataType; | 
 | 33 |  | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 34 | class Parcel; | 
| niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame^] | 35 | template<typename T> class SortedVector; | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 36 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | enum player_type { | 
 | 38 |     PV_PLAYER = 1, | 
 | 39 |     SONIVOX_PLAYER = 2, | 
| Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 40 |     VORBIS_PLAYER = 3, | 
| Nicolas Catania | 14d2747 | 2009-07-13 14:37:49 -0700 | [diff] [blame] | 41 |     STAGEFRIGHT_PLAYER = 4, | 
 | 42 |     // Test players are available only in the 'test' and 'eng' builds. | 
 | 43 |     // The shared library with the test player is passed passed as an | 
 | 44 |     // argument to the 'test:' url in the setDataSource call. | 
 | 45 |     TEST_PLAYER = 5, | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | }; | 
 | 47 |  | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 48 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | #define DEFAULT_AUDIOSINK_BUFFERCOUNT 4 | 
 | 50 | #define DEFAULT_AUDIOSINK_BUFFERSIZE 1200 | 
 | 51 | #define DEFAULT_AUDIOSINK_SAMPLERATE 44100 | 
 | 52 |  | 
 | 53 |  | 
 | 54 | // callback mechanism for passing messages to MediaPlayer object | 
 | 55 | typedef void (*notify_callback_f)(void* cookie, int msg, int ext1, int ext2); | 
 | 56 |  | 
 | 57 | // abstract base class - use MediaPlayerInterface | 
 | 58 | class MediaPlayerBase : public RefBase | 
 | 59 | { | 
 | 60 | public: | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 |     // AudioSink: abstraction layer for audio output | 
 | 62 |     class AudioSink : public RefBase { | 
 | 63 |     public: | 
| Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 64 |         typedef void (*AudioCallback)( | 
 | 65 |                 AudioSink *audioSink, void *buffer, size_t size, void *cookie); | 
 | 66 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 |         virtual             ~AudioSink() {} | 
 | 68 |         virtual bool        ready() const = 0; // audio output is open and ready | 
 | 69 |         virtual bool        realtime() const = 0; // audio output is real-time output | 
 | 70 |         virtual ssize_t     bufferSize() const = 0; | 
 | 71 |         virtual ssize_t     frameCount() const = 0; | 
 | 72 |         virtual ssize_t     channelCount() const = 0; | 
 | 73 |         virtual ssize_t     frameSize() const = 0; | 
 | 74 |         virtual uint32_t    latency() const = 0; | 
 | 75 |         virtual float       msecsPerFrame() const = 0; | 
| Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 76 |  | 
 | 77 |         // If no callback is specified, use the "write" API below to submit | 
 | 78 |         // audio data. Otherwise return a full buffer of audio data on each | 
 | 79 |         // callback. | 
 | 80 |         virtual status_t    open( | 
 | 81 |                 uint32_t sampleRate, int channelCount, | 
 | 82 |                 int format=AudioSystem::PCM_16_BIT, | 
 | 83 |                 int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT, | 
 | 84 |                 AudioCallback cb = NULL, | 
 | 85 |                 void *cookie = NULL) = 0; | 
 | 86 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 |         virtual void        start() = 0; | 
 | 88 |         virtual ssize_t     write(const void* buffer, size_t size) = 0; | 
 | 89 |         virtual void        stop() = 0; | 
 | 90 |         virtual void        flush() = 0; | 
 | 91 |         virtual void        pause() = 0; | 
 | 92 |         virtual void        close() = 0; | 
 | 93 |     }; | 
 | 94 |  | 
 | 95 |                         MediaPlayerBase() : mCookie(0), mNotify(0) {} | 
 | 96 |     virtual             ~MediaPlayerBase() {} | 
 | 97 |     virtual status_t    initCheck() = 0; | 
 | 98 |     virtual bool        hardwareOutput() = 0; | 
 | 99 |     virtual status_t    setDataSource(const char *url) = 0; | 
 | 100 |     virtual status_t    setDataSource(int fd, int64_t offset, int64_t length) = 0; | 
 | 101 |     virtual status_t    setVideoSurface(const sp<ISurface>& surface) = 0; | 
 | 102 |     virtual status_t    prepare() = 0; | 
 | 103 |     virtual status_t    prepareAsync() = 0; | 
 | 104 |     virtual status_t    start() = 0; | 
 | 105 |     virtual status_t    stop() = 0; | 
 | 106 |     virtual status_t    pause() = 0; | 
 | 107 |     virtual bool        isPlaying() = 0; | 
 | 108 |     virtual status_t    seekTo(int msec) = 0; | 
 | 109 |     virtual status_t    getCurrentPosition(int *msec) = 0; | 
 | 110 |     virtual status_t    getDuration(int *msec) = 0; | 
 | 111 |     virtual status_t    reset() = 0; | 
 | 112 |     virtual status_t    setLooping(int loop) = 0; | 
 | 113 |     virtual player_type playerType() = 0; | 
 | 114 |     virtual void        setNotifyCallback(void* cookie, notify_callback_f notifyFunc) { | 
 | 115 |                             mCookie = cookie; mNotify = notifyFunc; } | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 116 |     // Invoke a generic method on the player by using opaque parcels | 
 | 117 |     // for the request and reply. | 
| niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame^] | 118 |     // | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 119 |     // @param request Parcel that is positioned at the start of the | 
 | 120 |     //                data sent by the java layer. | 
 | 121 |     // @param[out] reply Parcel to hold the reply data. Cannot be null. | 
| niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame^] | 122 |     // @return OK if the call was successful. | 
| Nicolas Catania | 1d187f1 | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 123 |     virtual status_t    invoke(const Parcel& request, Parcel *reply) = 0; | 
| niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame^] | 124 |  | 
 | 125 |     // The Client in the MetadataPlayerService calls this method on | 
 | 126 |     // the native player to retrieve all or a subset of metadata. | 
 | 127 |     // | 
 | 128 |     // @param ids SortedList of metadata ID to be fetch. If empty, all | 
 | 129 |     //            the known metadata should be returned. | 
 | 130 |     // @param[inout] records Parcel where the player appends its metadata. | 
 | 131 |     // @return OK if the call was successful. | 
 | 132 |     virtual status_t    getMetadata(const SortedVector<MetadataType>& ids, | 
 | 133 |                                     Parcel *records) = 0; | 
 | 134 |  | 
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | protected: | 
 | 136 |     virtual void        sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); } | 
 | 137 |  | 
 | 138 |     void*               mCookie; | 
 | 139 |     notify_callback_f   mNotify; | 
 | 140 | }; | 
 | 141 |  | 
 | 142 | // Implement this class for media players that use the AudioFlinger software mixer | 
 | 143 | class MediaPlayerInterface : public MediaPlayerBase | 
 | 144 | { | 
 | 145 | public: | 
 | 146 |     virtual             ~MediaPlayerInterface() { } | 
 | 147 |     virtual bool        hardwareOutput() { return false; } | 
 | 148 |     virtual void        setAudioSink(const sp<AudioSink>& audioSink) { mAudioSink = audioSink; } | 
 | 149 | protected: | 
 | 150 |     sp<AudioSink>       mAudioSink; | 
 | 151 | }; | 
 | 152 |  | 
 | 153 | // Implement this class for media players that output directo to hardware | 
 | 154 | class MediaPlayerHWInterface : public MediaPlayerBase | 
 | 155 | { | 
 | 156 | public: | 
 | 157 |     virtual             ~MediaPlayerHWInterface() {} | 
 | 158 |     virtual bool        hardwareOutput() { return true; } | 
 | 159 |     virtual status_t    setVolume(float leftVolume, float rightVolume) = 0; | 
 | 160 |     virtual status_t    setAudioStreamType(int streamType) = 0; | 
 | 161 | }; | 
 | 162 |  | 
 | 163 | }; // namespace android | 
 | 164 |  | 
 | 165 | #endif // __cplusplus | 
 | 166 |  | 
 | 167 |  | 
 | 168 | #endif // ANDROID_MEDIAPLAYERINTERFACE_H |