1/*
2**
3** Copyright 2008, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ANDROID_VORBISPLAYER_H
19#define ANDROID_VORBISPLAYER_H
20
21#include <utils/threads.h>
22
23#include <media/MediaPlayerInterface.h>
24#include <media/AudioTrack.h>
25
26#include "ivorbiscodec.h"
27#include "ivorbisfile.h"
28
29#define ANDROID_LOOP_TAG "ANDROID_LOOP"
30
31namespace android {
32
33class VorbisPlayer : public MediaPlayerInterface {
34public:
35                        VorbisPlayer();
36                        ~VorbisPlayer();
37
38    virtual void        onFirstRef();
39    virtual status_t    initCheck();
40
41    virtual status_t    setDataSource(
42            const char *uri, const KeyedVector<String8, String8> *headers);
43
44    virtual status_t    setDataSource(int fd, int64_t offset, int64_t length);
45    virtual status_t    setVideoSurface(const sp<ISurface>& surface) { return UNKNOWN_ERROR; }
46    virtual status_t    prepare();
47    virtual status_t    prepareAsync();
48    virtual status_t    start();
49    virtual status_t    stop();
50    virtual status_t    seekTo(int msec);
51    virtual status_t    pause();
52    virtual bool        isPlaying();
53    virtual status_t    getCurrentPosition(int* msec);
54    virtual status_t    getDuration(int* msec);
55    virtual status_t    release();
56    virtual status_t    reset();
57    virtual status_t    setLooping(int loop);
58    virtual player_type playerType() { return VORBIS_PLAYER; }
59    virtual status_t    invoke(const Parcel& request, Parcel *reply) {return INVALID_OPERATION;}
60
61private:
62            status_t    setdatasource(const char *path, int fd, int64_t offset, int64_t length);
63            status_t    reset_nosync();
64            status_t    createOutputTrack();
65    static  int         renderThread(void*);
66            int         render();
67
68    static  size_t      vp_fread(void *, size_t, size_t, void *);
69    static  int         vp_fseek(void *, ogg_int64_t, int);
70    static  int         vp_fclose(void *);
71    static  long        vp_ftell(void *);
72
73    Mutex               mMutex;
74    Condition           mCondition;
75    FILE*               mFile;
76    int64_t             mOffset;
77    int64_t             mLength;
78    OggVorbis_File      mVorbisFile;
79    char*               mAudioBuffer;
80    int                 mPlayTime;
81    int                 mDuration;
82    status_t            mState;
83    int                 mStreamType;
84    bool                mLoop;
85    bool                mAndroidLoop;
86    volatile bool       mExit;
87    bool                mPaused;
88    volatile bool       mRender;
89    pid_t               mRenderTid;
90};
91
92}; // namespace android
93
94#endif // ANDROID_VORBISPLAYER_H
95