MediaPlayerInterface.h revision 5daeb129a2c2ba3d14ccd94af283b5f561c783ea
189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project/*
289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * you may not use this file except in compliance with the License.
689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * You may obtain a copy of the License at
789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
1089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * See the License for the specific language governing permissions and
1489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * limitations under the License.
1589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project */
1689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#ifndef ANDROID_MEDIAPLAYERINTERFACE_H
1889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define ANDROID_MEDIAPLAYERINTERFACE_H
1989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#ifdef __cplusplus
2189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#include <sys/types.h>
2314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#include <utils/Errors.h>
242db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber#include <utils/KeyedVector.h>
252db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber#include <utils/String8.h>
262db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber#include <utils/RefBase.h>
2789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <media/mediaplayer.h>
2989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <media/AudioSystem.h>
30a64c8c79af1a15911c55306d83a797fa50969f77niko#include <media/Metadata.h>
3189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
3289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectnamespace android {
3389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
341d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Cataniaclass Parcel;
353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass ISurface;
365daeb129a2c2ba3d14ccd94af283b5f561c783eaAndreas Huberclass Surface;
373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
38d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cnikotemplate<typename T> class SortedVector;
391d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania
4089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectenum player_type {
4189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    PV_PLAYER = 1,
4289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    SONIVOX_PLAYER = 2,
4314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    STAGEFRIGHT_PLAYER = 4,
4414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // Test players are available only in the 'test' and 'eng' builds.
4514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // The shared library with the test player is passed passed as an
4614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // argument to the 'test:' url in the setDataSource call.
4714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    TEST_PLAYER = 5,
4889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
4989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
501d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania
5189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define DEFAULT_AUDIOSINK_BUFFERCOUNT 4
5289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define DEFAULT_AUDIOSINK_BUFFERSIZE 1200
5389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define DEFAULT_AUDIOSINK_SAMPLERATE 44100
5489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
5589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
5689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// callback mechanism for passing messages to MediaPlayer object
5789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projecttypedef void (*notify_callback_f)(void* cookie, int msg, int ext1, int ext2);
5889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
5989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// abstract base class - use MediaPlayerInterface
6089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass MediaPlayerBase : public RefBase
6189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
6289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic:
6389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // AudioSink: abstraction layer for audio output
6489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    class AudioSink : public RefBase {
6589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    public:
667d5b8a70c28c0d5746a600467b2887822dbff88eAndreas Huber        // Callback returns the number of bytes actually written to the buffer.
677d5b8a70c28c0d5746a600467b2887822dbff88eAndreas Huber        typedef size_t (*AudioCallback)(
6820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                AudioSink *audioSink, void *buffer, size_t size, void *cookie);
6920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
7089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual             ~AudioSink() {}
7189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual bool        ready() const = 0; // audio output is open and ready
7289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual bool        realtime() const = 0; // audio output is real-time output
7389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual ssize_t     bufferSize() const = 0;
7489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual ssize_t     frameCount() const = 0;
7589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual ssize_t     channelCount() const = 0;
7689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual ssize_t     frameSize() const = 0;
7789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual uint32_t    latency() const = 0;
7889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual float       msecsPerFrame() const = 0;
79342e9cf388cceb807def720e40e8b0a217f4bcaaEric Laurent        virtual status_t    getPosition(uint32_t *position) = 0;
8020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
8120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber        // If no callback is specified, use the "write" API below to submit
827d5b8a70c28c0d5746a600467b2887822dbff88eAndreas Huber        // audio data.
8320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber        virtual status_t    open(
8420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                uint32_t sampleRate, int channelCount,
8520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                int format=AudioSystem::PCM_16_BIT,
8620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT,
8720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                AudioCallback cb = NULL,
8820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber                void *cookie = NULL) = 0;
8920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
9089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void        start() = 0;
9189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual ssize_t     write(const void* buffer, size_t size) = 0;
9289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void        stop() = 0;
9389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void        flush() = 0;
9489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void        pause() = 0;
9589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void        close() = 0;
9689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
9789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
9889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project                        MediaPlayerBase() : mCookie(0), mNotify(0) {}
9989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual             ~MediaPlayerBase() {}
10089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    initCheck() = 0;
10189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual bool        hardwareOutput() = 0;
1022db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber
1032db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber    virtual status_t    setDataSource(
1042db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber            const char *url,
1052db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber            const KeyedVector<String8, String8> *headers = NULL) = 0;
1062db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber
10789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    setDataSource(int fd, int64_t offset, int64_t length) = 0;
1085daeb129a2c2ba3d14ccd94af283b5f561c783eaAndreas Huber    virtual status_t    setVideoISurface(const sp<ISurface>& surface) = 0;
1095daeb129a2c2ba3d14ccd94af283b5f561c783eaAndreas Huber    virtual status_t    setVideoSurface(const sp<Surface>& surface) = 0;
11089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    prepare() = 0;
11189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    prepareAsync() = 0;
11289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    start() = 0;
11389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    stop() = 0;
11489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    pause() = 0;
11589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual bool        isPlaying() = 0;
11689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    seekTo(int msec) = 0;
11789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    getCurrentPosition(int *msec) = 0;
11889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    getDuration(int *msec) = 0;
11989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    reset() = 0;
12089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    setLooping(int loop) = 0;
12189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual player_type playerType() = 0;
1224e92c7efc68b5d7635a32dbd283ab8558ad9bdd6Andreas Huber    virtual status_t    suspend() { return INVALID_OPERATION; }
1234e92c7efc68b5d7635a32dbd283ab8558ad9bdd6Andreas Huber    virtual status_t    resume() { return INVALID_OPERATION; }
1244e92c7efc68b5d7635a32dbd283ab8558ad9bdd6Andreas Huber
12589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual void        setNotifyCallback(void* cookie, notify_callback_f notifyFunc) {
12689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project                            mCookie = cookie; mNotify = notifyFunc; }
1271d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    // Invoke a generic method on the player by using opaque parcels
1281d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    // for the request and reply.
129d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    //
1301d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    // @param request Parcel that is positioned at the start of the
1311d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    //                data sent by the java layer.
1321d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    // @param[out] reply Parcel to hold the reply data. Cannot be null.
133d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // @return OK if the call was successful.
1341d187f1a86855f5f0694d7ec30efc9833bf7c589Nicolas Catania    virtual status_t    invoke(const Parcel& request, Parcel *reply) = 0;
135d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko
136d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // The Client in the MetadataPlayerService calls this method on
137d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // the native player to retrieve all or a subset of metadata.
138d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    //
139d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // @param ids SortedList of metadata ID to be fetch. If empty, all
140d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    //            the known metadata should be returned.
141d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // @param[inout] records Parcel where the player appends its metadata.
142d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko    // @return OK if the call was successful.
143a64c8c79af1a15911c55306d83a797fa50969f77niko    virtual status_t    getMetadata(const media::Metadata::Filter& ids,
144a64c8c79af1a15911c55306d83a797fa50969f77niko                                    Parcel *records) {
145a64c8c79af1a15911c55306d83a797fa50969f77niko        return INVALID_OPERATION;
146a64c8c79af1a15911c55306d83a797fa50969f77niko    };
147d608a813a9d2cbc6e2a5ea81d78d4a9044090c4cniko
14889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual void        sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); }
14989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
150bfa6b2d7a1be1832ac40ed90aece1834f720b5c6Andreas Huberprotected:
15189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    void*               mCookie;
15289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    notify_callback_f   mNotify;
15389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
15489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
15589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// Implement this class for media players that use the AudioFlinger software mixer
15689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass MediaPlayerInterface : public MediaPlayerBase
15789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
15889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic:
15989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual             ~MediaPlayerInterface() { }
16089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual bool        hardwareOutput() { return false; }
16189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual void        setAudioSink(const sp<AudioSink>& audioSink) { mAudioSink = audioSink; }
16289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectprotected:
16389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    sp<AudioSink>       mAudioSink;
16489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
16589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
16689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project// Implement this class for media players that output directo to hardware
16789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass MediaPlayerHWInterface : public MediaPlayerBase
16889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
16989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic:
17089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual             ~MediaPlayerHWInterface() {}
17189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual bool        hardwareOutput() { return true; }
17289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    setVolume(float leftVolume, float rightVolume) = 0;
17389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    virtual status_t    setAudioStreamType(int streamType) = 0;
17489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
17589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
17689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project}; // namespace android
17789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
17889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#endif // __cplusplus
17989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
18089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
18189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#endif // ANDROID_MEDIAPLAYERINTERFACE_H
182