2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __ANDROID_GENERICPLAYER_H__
18 #define __ANDROID_GENERICPLAYER_H__
20 #include <media/stagefright/foundation/AHandler.h>
21 #include <media/stagefright/foundation/ALooper.h>
22 #include <media/stagefright/foundation/AMessage.h>
24 //--------------------------------------------------------------------------------------------------
26 * Message parameters for AHandler messages, see list in GenericPlayer::kWhatxxx
28 #define WHATPARAM_SEEK_SEEKTIME_MS "seekTimeMs"
29 #define WHATPARAM_LOOP_LOOPING "looping"
30 #define WHATPARAM_BUFFERING_UPDATE "bufferingUpdate"
31 #define WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT "buffUpdateThreshold"
35 class GenericPlayer : public AHandler
40 kEventPrepared = 'prep',
41 kEventHasVideoSize = 'vsiz',
42 kEventPrefetchStatusChange = 'pfsc',
43 kEventPrefetchFillLevelUpdate = 'pflu',
44 kEventEndOfStream = 'eos'
48 GenericPlayer(const AudioPlayback_Parameters* params);
49 virtual ~GenericPlayer();
51 virtual void init(const notif_cbf_t cbf, void* notifUser);
52 virtual void preDestroy();
54 virtual void setDataSource(const char *uri);
55 virtual void setDataSource(int fd, int64_t offset, int64_t length);
57 virtual void prepare();
61 virtual void seek(int64_t timeMsec);
62 virtual void loop(bool loop);
63 virtual void setBufferingUpdateThreshold(int16_t thresholdPercent);
65 virtual void getDurationMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown
66 virtual void getPositionMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown
67 virtual void getSampleRate(uint32_t* hz);// ANDROID_UNKNOWN_SAMPLERATE if unknown
69 void setVolume(bool mute, bool useStereoPos, XApermille stereoPos, XAmillibel volume);
74 void resetDataLocator();
75 DataLocator2 mDataLocator;
78 // Constants used to identify the messages in this player's AHandler message loop
79 // in onMessageReceived()
81 kWhatPrepare = 'prep',
86 kWhatSeekComplete = 'skcp',
88 kWhatVolumeUpdate = 'volu',
89 kWhatBufferingUpdate = 'bufu',
90 kWhatBuffUpdateThres = 'buut',
93 // Send a notification to one of the event listeners
94 virtual void notify(const char* event, int data1, bool async);
95 virtual void notify(const char* event, int data1, int data2, bool async);
97 // AHandler implementation
98 virtual void onMessageReceived(const sp<AMessage> &msg);
100 // Async event handlers (called from GenericPlayer's event loop)
101 virtual void onPrepare();
102 virtual void onNotify(const sp<AMessage> &msg);
103 virtual void onPlay();
104 virtual void onPause();
105 virtual void onSeek(const sp<AMessage> &msg);
106 virtual void onLoop(const sp<AMessage> &msg);
107 virtual void onVolumeUpdate();
108 virtual void onSeekComplete();
109 virtual void onBufferingUpdate(const sp<AMessage> &msg);
110 virtual void onSetBufferingUpdateThreshold(const sp<AMessage> &msg);
112 // Convenience methods
113 // for async notifications of prefetch status and cache fill level, needs to be called
114 // with mSettingsLock locked
116 void notifyCacheFill();
117 // for internal async notification to update state that the player is no longer seeking
119 void bufferingUpdate(int16_t fillLevelPerMille);
121 // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework
122 notif_cbf_t mNotifyClient;
124 // lock to protect mNotifyClient and mNotifyUser updates
125 Mutex mNotifyClientLock;
128 kFlagPrepared = 1 <<0,
129 kFlagPreparing = 1 <<1,
130 kFlagPlaying = 1 <<2,
131 kFlagBuffering = 1 <<3,
132 kFlagSeeking = 1 <<4,
133 kFlagLooping = 1 <<5,
136 uint32_t mStateFlags;
139 int32_t mLooperPriority;
141 AudioPlayback_Parameters mPlaybackParams;
143 AndroidAudioLevels mAndroidAudioLevels;
144 int mChannelCount; // this is used for the panning law, and is not exposed outside of the object
145 int32_t mDurationMsec;
146 int32_t mPositionMsec;
147 uint32_t mSampleRateHz;
149 CacheStatus_t mCacheStatus;
150 int16_t mCacheFill; // cache fill level + played back level in permille
151 int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener
152 int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported
155 DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer);
158 } // namespace android
160 #endif /* __ANDROID_GENERICPLAYER_H__ */