• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/MediaAnalyticsItem.h>
20 #include <media/stagefright/foundation/ABase.h>
21 
22 namespace android {
23 
24 struct ALooper;
25 struct NuPlayer;
26 
27 struct NuPlayerDriver : public MediaPlayerInterface {
28     explicit NuPlayerDriver(pid_t pid);
29 
30     virtual status_t initCheck();
31 
32     virtual status_t setUID(uid_t uid);
33 
34     virtual status_t setDataSource(
35             const sp<IMediaHTTPService> &httpService,
36             const char *url,
37             const KeyedVector<String8, String8> *headers);
38 
39     virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
40 
41     virtual status_t setDataSource(const sp<IStreamSource> &source);
42 
43     virtual status_t setDataSource(const sp<DataSource>& dataSource);
44 
45     virtual status_t setVideoSurfaceTexture(
46             const sp<IGraphicBufferProducer> &bufferProducer);
47 
48     virtual status_t getDefaultBufferingSettings(
49             BufferingSettings* buffering /* nonnull */) override;
50     virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
51 
52     virtual status_t prepare();
53     virtual status_t prepareAsync();
54     virtual status_t start();
55     virtual status_t stop();
56     virtual status_t pause();
57     virtual bool isPlaying();
58     virtual status_t setPlaybackSettings(const AudioPlaybackRate &rate);
59     virtual status_t getPlaybackSettings(AudioPlaybackRate *rate);
60     virtual status_t setSyncSettings(const AVSyncSettings &sync, float videoFpsHint);
61     virtual status_t getSyncSettings(AVSyncSettings *sync, float *videoFps);
62     virtual status_t seekTo(
63             int msec, MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC);
64     virtual status_t getCurrentPosition(int *msec);
65     virtual status_t getDuration(int *msec);
66     virtual status_t reset();
67     virtual status_t setLooping(int loop);
68     virtual player_type playerType();
69     virtual status_t invoke(const Parcel &request, Parcel *reply);
70     virtual void setAudioSink(const sp<AudioSink> &audioSink);
71     virtual status_t setParameter(int key, const Parcel &request);
72     virtual status_t getParameter(int key, Parcel *reply);
73 
74     virtual status_t getMetadata(
75             const media::Metadata::Filter& ids, Parcel *records);
76 
77     virtual status_t dump(int fd, const Vector<String16> &args) const;
78 
79     void notifySetDataSourceCompleted(status_t err);
80     void notifyPrepareCompleted(status_t err);
81     void notifyResetComplete();
82     void notifySetSurfaceComplete();
83     void notifyDuration(int64_t durationUs);
84     void notifyMorePlayingTimeUs(int64_t timeUs);
85     void notifySeekComplete();
86     void notifySeekComplete_l();
87     void notifyListener(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
88     void notifyFlagsChanged(uint32_t flags);
89 
90     // Modular DRM
91     virtual status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId);
92     virtual status_t releaseDrm();
93 
94 protected:
95     virtual ~NuPlayerDriver();
96 
97 private:
98     enum State {
99         STATE_IDLE,
100         STATE_SET_DATASOURCE_PENDING,
101         STATE_UNPREPARED,
102         STATE_PREPARING,
103         STATE_PREPARED,
104         STATE_RUNNING,
105         STATE_PAUSED,
106         STATE_RESET_IN_PROGRESS,
107         STATE_STOPPED,                  // equivalent to PAUSED
108         STATE_STOPPED_AND_PREPARING,    // equivalent to PAUSED, but seeking
109         STATE_STOPPED_AND_PREPARED,     // equivalent to PAUSED, but seek complete
110     };
111 
112     mutable Mutex mLock;
113     Condition mCondition;
114 
115     State mState;
116 
117     bool mIsAsyncPrepare;
118     status_t mAsyncResult;
119 
120     // The following are protected through "mLock"
121     // >>>
122     bool mSetSurfaceInProgress;
123     int64_t mDurationUs;
124     int64_t mPositionUs;
125     bool mSeekInProgress;
126     int64_t mPlayingTimeUs;
127     // <<<
128 
129     sp<ALooper> mLooper;
130     const sp<NuPlayer> mPlayer;
131     sp<AudioSink> mAudioSink;
132     uint32_t mPlayerFlags;
133 
134     MediaAnalyticsItem *mAnalyticsItem;
135     uid_t mClientUid;
136     mutable Mutex mMetricsLock;
137 
138     bool mAtEOS;
139     bool mLooping;
140     bool mAutoLoop;
141 
142 
143     void updateMetrics(const char *where);
144     void logMetrics(const char *where);
145 
146     status_t prepare_l();
147     status_t start_l();
148     void notifyListener_l(int msg, int ext1 = 0, int ext2 = 0, const Parcel *in = NULL);
149 
150     DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
151 };
152 
153 }  // namespace android
154 
155 
156