Skip to content

Commit 68f592a

Browse files
theandi666Android (Google) Code Review
authored andcommitted
Merge "Don't perform RTSP seeks right away but queue them for 200ms" into ics-mr1
2 parents 0ba9380 + 21902a8 commit 68f592a

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

media/libmediaplayerservice/nuplayer/RTSPSource.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ NuPlayer::RTSPSource::RTSPSource(
3838
mFlags(0),
3939
mState(DISCONNECTED),
4040
mFinalResult(OK),
41-
mDisconnectReplyID(0) {
41+
mDisconnectReplyID(0),
42+
mSeekGeneration(0) {
4243
if (headers) {
4344
mExtraHeaders = *headers;
4445

@@ -146,14 +147,21 @@ status_t NuPlayer::RTSPSource::getDuration(int64_t *durationUs) {
146147
}
147148

148149
status_t NuPlayer::RTSPSource::seekTo(int64_t seekTimeUs) {
150+
sp<AMessage> msg = new AMessage(kWhatPerformSeek, mReflector->id());
151+
msg->setInt32("generation", ++mSeekGeneration);
152+
msg->setInt64("timeUs", seekTimeUs);
153+
msg->post(200000ll);
154+
155+
return OK;
156+
}
157+
158+
void NuPlayer::RTSPSource::performSeek(int64_t seekTimeUs) {
149159
if (mState != CONNECTED) {
150-
return UNKNOWN_ERROR;
160+
return;
151161
}
152162

153163
mState = SEEKING;
154164
mHandler->seek(seekTimeUs);
155-
156-
return OK;
157165
}
158166

159167
bool NuPlayer::RTSPSource::isSeekable() {
@@ -168,6 +176,20 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
168176
mDisconnectReplyID = replyID;
169177
finishDisconnectIfPossible();
170178
return;
179+
} else if (msg->what() == kWhatPerformSeek) {
180+
int32_t generation;
181+
CHECK(msg->findInt32("generation", &generation));
182+
183+
if (generation != mSeekGeneration) {
184+
// obsolete.
185+
return;
186+
}
187+
188+
int64_t seekTimeUs;
189+
CHECK(msg->findInt64("timeUs", &seekTimeUs));
190+
191+
performSeek(seekTimeUs);
192+
return;
171193
}
172194

173195
CHECK_EQ(msg->what(), (int)kWhatNotify);

media/libmediaplayerservice/nuplayer/RTSPSource.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct NuPlayer::RTSPSource : public NuPlayer::Source {
5656
enum {
5757
kWhatNotify = 'noti',
5858
kWhatDisconnect = 'disc',
59+
kWhatPerformSeek = 'seek',
5960
};
6061

6162
enum State {
@@ -96,12 +97,16 @@ struct NuPlayer::RTSPSource : public NuPlayer::Source {
9697
sp<AnotherPacketSource> mAudioTrack;
9798
sp<AnotherPacketSource> mVideoTrack;
9899

100+
int32_t mSeekGeneration;
101+
99102
sp<AnotherPacketSource> getSource(bool audio);
100103

101104
void onConnected();
102105
void onDisconnected(const sp<AMessage> &msg);
103106
void finishDisconnectIfPossible();
104107

108+
void performSeek(int64_t seekTimeUs);
109+
105110
DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
106111
};
107112

0 commit comments

Comments
 (0)