blob: c30dc1b72dd256aad3890b58a0d2951c28dfd10a [file] [log] [blame]
The Android Open Source Project2729ea92008-10-21 07:00:00 -07001/*
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 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; }
56
57private:
58 status_t setdatasource(const char *path, int fd, int64_t offset, int64_t length);
59 status_t reset_nosync();
60 status_t createOutputTrack();
61 static int renderThread(void*);
62 int render();
63
64 static size_t vp_fread(void *, size_t, size_t, void *);
65 static int vp_fseek(void *, ogg_int64_t, int);
66 static int vp_fclose(void *);
67 static long vp_ftell(void *);
68
69 Mutex mMutex;
70 Condition mCondition;
71 FILE* mFile;
72 int64_t mOffset;
73 int64_t mLength;
74 OggVorbis_File mVorbisFile;
75 char* mAudioBuffer;
76 int mPlayTime;
77 int mDuration;
78 status_t mState;
79 int mStreamType;
80 bool mLoop;
81 bool mAndroidLoop;
82 volatile bool mExit;
83 bool mPaused;
84 volatile bool mRender;
85 pid_t mRenderTid;
86};
87
88}; // namespace android
89
90#endif // ANDROID_VORBISPLAYER_H
91