MediaPlayerInterface.h revision 1d187f1a86855f5f0694d7ec30efc9833bf7c589
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 22#include <ui/ISurface.h> 23#include <utils/RefBase.h> 24 25#include <media/mediaplayer.h> 26#include <media/AudioSystem.h> 27 28namespace android { 29 30class Parcel; 31 32enum player_type { 33 PV_PLAYER = 1, 34 SONIVOX_PLAYER = 2, 35 VORBIS_PLAYER = 3 36}; 37 38 39#define DEFAULT_AUDIOSINK_BUFFERCOUNT 4 40#define DEFAULT_AUDIOSINK_BUFFERSIZE 1200 41#define DEFAULT_AUDIOSINK_SAMPLERATE 44100 42 43 44// callback mechanism for passing messages to MediaPlayer object 45typedef void (*notify_callback_f)(void* cookie, int msg, int ext1, int ext2); 46 47// abstract base class - use MediaPlayerInterface 48class MediaPlayerBase : public RefBase 49{ 50public: 51 // AudioSink: abstraction layer for audio output 52 class AudioSink : public RefBase { 53 public: 54 virtual ~AudioSink() {} 55 virtual bool ready() const = 0; // audio output is open and ready 56 virtual bool realtime() const = 0; // audio output is real-time output 57 virtual ssize_t bufferSize() const = 0; 58 virtual ssize_t frameCount() const = 0; 59 virtual ssize_t channelCount() const = 0; 60 virtual ssize_t frameSize() const = 0; 61 virtual uint32_t latency() const = 0; 62 virtual float msecsPerFrame() const = 0; 63 virtual status_t open(uint32_t sampleRate, int channelCount, int format=AudioSystem::PCM_16_BIT, int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT) = 0; 64 virtual void start() = 0; 65 virtual ssize_t write(const void* buffer, size_t size) = 0; 66 virtual void stop() = 0; 67 virtual void flush() = 0; 68 virtual void pause() = 0; 69 virtual void close() = 0; 70 }; 71 72 MediaPlayerBase() : mCookie(0), mNotify(0) {} 73 virtual ~MediaPlayerBase() {} 74 virtual status_t initCheck() = 0; 75 virtual bool hardwareOutput() = 0; 76 virtual status_t setDataSource(const char *url) = 0; 77 virtual status_t setDataSource(int fd, int64_t offset, int64_t length) = 0; 78 virtual status_t setVideoSurface(const sp<ISurface>& surface) = 0; 79 virtual status_t prepare() = 0; 80 virtual status_t prepareAsync() = 0; 81 virtual status_t start() = 0; 82 virtual status_t stop() = 0; 83 virtual status_t pause() = 0; 84 virtual bool isPlaying() = 0; 85 virtual status_t seekTo(int msec) = 0; 86 virtual status_t getCurrentPosition(int *msec) = 0; 87 virtual status_t getDuration(int *msec) = 0; 88 virtual status_t reset() = 0; 89 virtual status_t setLooping(int loop) = 0; 90 virtual player_type playerType() = 0; 91 virtual void setNotifyCallback(void* cookie, notify_callback_f notifyFunc) { 92 mCookie = cookie; mNotify = notifyFunc; } 93 // Invoke a generic method on the player by using opaque parcels 94 // for the request and reply. 95 // @param request Parcel that is positioned at the start of the 96 // data sent by the java layer. 97 // @param[out] reply Parcel to hold the reply data. Cannot be null. 98 // @return OK if the invocation was made successfully. A player 99 // not supporting the direct API should return INVALID_OPERATION. 100 virtual status_t invoke(const Parcel& request, Parcel *reply) = 0; 101protected: 102 virtual void sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); } 103 104 void* mCookie; 105 notify_callback_f mNotify; 106}; 107 108// Implement this class for media players that use the AudioFlinger software mixer 109class MediaPlayerInterface : public MediaPlayerBase 110{ 111public: 112 virtual ~MediaPlayerInterface() { } 113 virtual bool hardwareOutput() { return false; } 114 virtual void setAudioSink(const sp<AudioSink>& audioSink) { mAudioSink = audioSink; } 115protected: 116 sp<AudioSink> mAudioSink; 117}; 118 119// Implement this class for media players that output directo to hardware 120class MediaPlayerHWInterface : public MediaPlayerBase 121{ 122public: 123 virtual ~MediaPlayerHWInterface() {} 124 virtual bool hardwareOutput() { return true; } 125 virtual status_t setVolume(float leftVolume, float rightVolume) = 0; 126 virtual status_t setAudioStreamType(int streamType) = 0; 127}; 128 129}; // namespace android 130 131#endif // __cplusplus 132 133 134#endif // ANDROID_MEDIAPLAYERINTERFACE_H 135