blob: e81d6051808edf160d807e4f912d0ad2cef7cdb0 [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include <media/MediaPlayerInterface.h>
18
19#include <media/stagefright/foundation/ABase.h>
20
21namespace android {
22
23struct ALooper;
24struct NuPlayer;
25
26struct NuPlayerDriver : public MediaPlayerInterface {
27 NuPlayerDriver();
28
29 virtual status_t initCheck();
30
Andreas Huber9b80c2b2011-06-30 15:47:02 -070031 virtual status_t setUID(uid_t uid);
32
Andreas Huberf9334412010-12-15 15:17:42 -080033 virtual status_t setDataSource(
Andreas Huber1b86fe02014-01-29 11:13:26 -080034 const sp<IMediaHTTPService> &httpService,
35 const char *url,
36 const KeyedVector<String8, String8> *headers);
Andreas Huberf9334412010-12-15 15:17:42 -080037
38 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
39
40 virtual status_t setDataSource(const sp<IStreamSource> &source);
41
Glenn Kasten11731182011-02-08 17:26:17 -080042 virtual status_t setVideoSurfaceTexture(
Andy McFadden8ba01022012-12-18 09:46:54 -080043 const sp<IGraphicBufferProducer> &bufferProducer);
Andreas Huberf9334412010-12-15 15:17:42 -080044 virtual status_t prepare();
45 virtual status_t prepareAsync();
46 virtual status_t start();
47 virtual status_t stop();
48 virtual status_t pause();
49 virtual bool isPlaying();
50 virtual status_t seekTo(int msec);
51 virtual status_t getCurrentPosition(int *msec);
52 virtual status_t getDuration(int *msec);
53 virtual status_t reset();
54 virtual status_t setLooping(int loop);
55 virtual player_type playerType();
56 virtual status_t invoke(const Parcel &request, Parcel *reply);
57 virtual void setAudioSink(const sp<AudioSink> &audioSink);
Gloria Wang4f9e47f2011-04-25 17:28:22 -070058 virtual status_t setParameter(int key, const Parcel &request);
59 virtual status_t getParameter(int key, Parcel *reply);
Andreas Huberf9334412010-12-15 15:17:42 -080060
61 virtual status_t getMetadata(
62 const media::Metadata::Filter& ids, Parcel *records);
63
Andreas Huber3fe62152011-09-16 15:09:22 -070064 virtual status_t dump(int fd, const Vector<String16> &args) const;
65
Andreas Huber9575c962013-02-05 13:59:56 -080066 void notifySetDataSourceCompleted(status_t err);
67 void notifyPrepareCompleted(status_t err);
Andreas Huber43c3e6c2011-01-05 12:17:08 -080068 void notifyResetComplete();
Chong Zhang13d6faa2014-08-22 15:35:28 -070069 void notifySetSurfaceComplete();
Andreas Huber43c3e6c2011-01-05 12:17:08 -080070 void notifyDuration(int64_t durationUs);
71 void notifyPosition(int64_t positionUs);
72 void notifySeekComplete();
Marco Nelisseneb645a02014-08-20 09:44:44 -070073 void notifySeekComplete_l();
Andreas Huber3fe62152011-09-16 15:09:22 -070074 void notifyFrameStats(int64_t numFramesTotal, int64_t numFramesDropped);
Chong Zhangdcb89b32013-08-06 09:44:47 -070075 void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
Andreas Huber9575c962013-02-05 13:59:56 -080076 void notifyFlagsChanged(uint32_t flags);
Andreas Huber1aef2112011-01-04 14:01:29 -080077
Andreas Huberf9334412010-12-15 15:17:42 -080078protected:
79 virtual ~NuPlayerDriver();
80
81private:
Andreas Huber9575c962013-02-05 13:59:56 -080082 enum State {
83 STATE_IDLE,
84 STATE_SET_DATASOURCE_PENDING,
85 STATE_UNPREPARED,
86 STATE_PREPARING,
87 STATE_PREPARED,
88 STATE_RUNNING,
89 STATE_PAUSED,
90 STATE_RESET_IN_PROGRESS,
Lajos Molnar4b75b862013-08-15 15:59:19 -070091 STATE_STOPPED, // equivalent to PAUSED
92 STATE_STOPPED_AND_PREPARING, // equivalent to PAUSED, but seeking
93 STATE_STOPPED_AND_PREPARED, // equivalent to PAUSED, but seek complete
Andreas Huber9575c962013-02-05 13:59:56 -080094 };
95
Andreas Huber3fe62152011-09-16 15:09:22 -070096 mutable Mutex mLock;
Andreas Huber1aef2112011-01-04 14:01:29 -080097 Condition mCondition;
Andreas Huber43c3e6c2011-01-05 12:17:08 -080098
Andreas Huber9575c962013-02-05 13:59:56 -080099 State mState;
100
Andreas Huberec0c5972013-02-05 14:47:13 -0800101 bool mIsAsyncPrepare;
Andreas Huber9575c962013-02-05 13:59:56 -0800102 status_t mAsyncResult;
103
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800104 // The following are protected through "mLock"
105 // >>>
Chong Zhang13d6faa2014-08-22 15:35:28 -0700106 bool mSetSurfaceInProgress;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800107 int64_t mDurationUs;
108 int64_t mPositionUs;
Wei Jia15506a62014-08-20 15:14:44 -0700109 int64_t mNotifyTimeRealUs;
110 int64_t mPauseStartedTimeUs;
Andreas Huber3fe62152011-09-16 15:09:22 -0700111 int64_t mNumFramesTotal;
112 int64_t mNumFramesDropped;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800113 // <<<
Andreas Huber1aef2112011-01-04 14:01:29 -0800114
Andreas Huberf9334412010-12-15 15:17:42 -0800115 sp<ALooper> mLooper;
116 sp<NuPlayer> mPlayer;
Andreas Huber9575c962013-02-05 13:59:56 -0800117 uint32_t mPlayerFlags;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800118
Andreas Hubera4af2142011-10-26 15:23:31 -0700119 bool mAtEOS;
Lajos Molnara2e14302014-07-31 12:07:58 -0700120 bool mLooping;
Andreas Huber43c3e6c2011-01-05 12:17:08 -0800121
122 int64_t mStartupSeekTimeUs;
Andreas Huberf9334412010-12-15 15:17:42 -0800123
Andreas Huber9575c962013-02-05 13:59:56 -0800124 status_t prepare_l();
Wei Jia05601952014-08-20 18:21:11 -0700125 void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
126 void setPauseStartedTimeIfNeeded();
Andreas Huber9575c962013-02-05 13:59:56 -0800127
Andreas Huberf9334412010-12-15 15:17:42 -0800128 DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
129};
130
131} // namespace android
132
133