android_GenericPlayer.h revision 70c49ae2867094072a4365423417ea452bf82231
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
4470c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi    virtual void getDurationMsec(int* msec); // -1 if unknown
4570c49ae2867094072a4365423417ea452bf82231Jean-Michel Trivi
4613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprotected:
4713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
4813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    void resetDataLocator();
4913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    DataLocator2 mDataLocator;
5013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    int          mDataLocatorType;
5113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
5213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    enum {
5313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPrepare    = 'prep',
5413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatNotif      = 'noti',
5513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPlay       = 'play',
5613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatPause      = 'paus',
5713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatSeek       = 'seek',
5813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kWhatLoop       = 'loop',
5913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    };
6013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
6113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Send a notification to one of the event listeners
6213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void notify(const char* event, int data, bool async);
6313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
6413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // AHandler implementation
6513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onMessageReceived(const sp<AMessage> &msg);
6613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
6713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Async event handlers (called from GenericPlayer's event loop)
6813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPrepare();
6913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onNotify(const sp<AMessage> &msg);
7013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPlay();
7113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onPause();
7213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onSeek(const sp<AMessage> &msg);
7313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    virtual void onLoop(const sp<AMessage> &msg);
7413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
7513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework
7613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    notif_cbf_t mNotifyClient;
7713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    void*       mNotifyUser;
7813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
7913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    enum {
8013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPrepared  = 1 <<0,
8113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPreparing = 1 <<1,
8213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagPlaying   = 1 <<2,
8313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagBuffering = 1 <<3,
8413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagSeeking   = 1 <<4,
8513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi        kFlagLooping   = 1 <<5,
8613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    };
8713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
8813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    uint32_t mStateFlags;
8913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    sp<ALooper> mLooper;
9113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    int32_t mLooperPriority;
9213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    AudioPlayback_Parameters mPlaybackParams;
9413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprivate:
9613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi    DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer);
9713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi};
9813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi
9913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} // namespace android
100