android_GenericPlayer.h revision 13837cf3f7be0eb8b1a9552bd99a89f98c987720
113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi/*
213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project
313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi *
413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * you may not use this file except in compliance with the License.
613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * You may obtain a copy of the License at
713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi *
813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi *
1013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
1113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
1213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * See the License for the specific language governing permissions and
1413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * limitations under the License.
1513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi */
1613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
1713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
1813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//--------------------------------------------------------------------------------------------------
1913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivinamespace android {
2013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
2113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviclass GenericPlayer : public AHandler
2213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi{
2313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivipublic:
2413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
2513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    enum {
2613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kEventPrepared                = 'prep'
2713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    };
2813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
2913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    GenericPlayer(const AudioPlayback_Parameters* params);
3013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual ~GenericPlayer();
3113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
3213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void init(const notif_cbf_t cbf, void* notifUser);
3313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
3413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void setDataSource(const char *uri);
3513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void setDataSource(int fd, int64_t offset, int64_t length);
3613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
3713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void prepare();
3813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void play();
3913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void pause();
4013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void stop();
4113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void seek(int64_t timeMsec);
4213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void loop(bool loop);
4313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
4413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprotected:
4513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
4613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    void resetDataLocator();
4713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    DataLocator2 mDataLocator;
4813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    int          mDataLocatorType;
4913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
5013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    enum {
5113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPrepare    = 'prep',
5213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatNotif      = 'noti',
5313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPlay       = 'play',
5413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPause      = 'paus',
5513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatSeek       = 'seek',
5613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatLoop       = 'loop',
5713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    };
5813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
5913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Send a notification to one of the event listeners
6013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void notify(const char* event, int data, bool async);
6113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
6213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // AHandler implementation
6313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onMessageReceived(const sp<AMessage> &msg);
6413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
6513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Async event handlers (called from GenericPlayer's event loop)
6613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPrepare();
6713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onNotify(const sp<AMessage> &msg);
6813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPlay();
6913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPause();
7013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onSeek(const sp<AMessage> &msg);
7113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onLoop(const sp<AMessage> &msg);
7213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
7313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework
7413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    notif_cbf_t mNotifyClient;
7513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    void*       mNotifyUser;
7613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
7713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    enum {
7813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPrepared  = 1 <<0,
7913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPreparing = 1 <<1,
8013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPlaying   = 1 <<2,
8113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagBuffering = 1 <<3,
8213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagSeeking   = 1 <<4,
8313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagLooping   = 1 <<5,
8413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    };
8513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
8613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    uint32_t mStateFlags;
8713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
8813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    sp<ALooper> mLooper;
8913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    int32_t mLooperPriority;
9013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    AudioPlayback_Parameters mPlaybackParams;
9213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprivate:
9413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer);
9513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi};
9613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} // namespace android
98