The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 31 | namespace android { |
| 32 | |
| 33 | class VorbisPlayer : public MediaPlayerInterface { |
| 34 | public: |
| 35 | VorbisPlayer(); |
| 36 | ~VorbisPlayer(); |
| 37 | |
| 38 | virtual void onFirstRef(); |
| 39 | virtual status_t initCheck(); |
| 40 | virtual status_t setDataSource(const char* path); |
| 41 | virtual status_t setDataSource(int fd, int64_t offset, int64_t length); |
| 42 | virtual status_t setVideoSurface(const sp<ISurface>& surface) { return UNKNOWN_ERROR; } |
| 43 | virtual status_t prepare(); |
| 44 | virtual status_t prepareAsync(); |
| 45 | virtual status_t start(); |
| 46 | virtual status_t stop(); |
| 47 | virtual status_t seekTo(int msec); |
| 48 | virtual status_t pause(); |
| 49 | virtual bool isPlaying(); |
| 50 | virtual status_t getCurrentPosition(int* msec); |
| 51 | virtual status_t getDuration(int* msec); |
| 52 | virtual status_t release(); |
| 53 | virtual status_t reset(); |
| 54 | virtual status_t setLooping(int loop); |
| 55 | virtual player_type playerType() { return VORBIS_PLAYER; } |
Nicolas Catania | 20cb94e | 2009-05-12 23:25:55 -0700 | [diff] [blame] | 56 | virtual status_t invoke(const Parcel& request, Parcel *reply) {return INVALID_OPERATION;} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | status_t setdatasource(const char *path, int fd, int64_t offset, int64_t length); |
| 60 | status_t reset_nosync(); |
| 61 | status_t createOutputTrack(); |
| 62 | static int renderThread(void*); |
| 63 | int render(); |
| 64 | |
| 65 | static size_t vp_fread(void *, size_t, size_t, void *); |
| 66 | static int vp_fseek(void *, ogg_int64_t, int); |
| 67 | static int vp_fclose(void *); |
| 68 | static long vp_ftell(void *); |
| 69 | |
| 70 | Mutex mMutex; |
| 71 | Condition mCondition; |
| 72 | FILE* mFile; |
| 73 | int64_t mOffset; |
| 74 | int64_t mLength; |
| 75 | OggVorbis_File mVorbisFile; |
| 76 | char* mAudioBuffer; |
| 77 | int mPlayTime; |
| 78 | int mDuration; |
| 79 | status_t mState; |
| 80 | int mStreamType; |
| 81 | bool mLoop; |
| 82 | bool mAndroidLoop; |
| 83 | volatile bool mExit; |
| 84 | bool mPaused; |
| 85 | volatile bool mRender; |
| 86 | pid_t mRenderTid; |
| 87 | }; |
| 88 | |
| 89 | }; // namespace android |
| 90 | |
| 91 | #endif // ANDROID_VORBISPLAYER_H |