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