blob: 6438a1ef489f4d482879c3299e2752a23cddd165 [file] [log] [blame]
Andreas Huber2bfdd422011-10-11 15:24:07 -07001/*
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#ifndef RTSP_SOURCE_H_
18
19#define RTSP_SOURCE_H_
20
21#include "NuPlayerSource.h"
22
Andreas Hubercfaeeec2012-08-31 10:27:46 -070023#include "ATSParser.h"
24
Andreas Huber2bfdd422011-10-11 15:24:07 -070025namespace android {
26
27struct ALooper;
Lajos Molnar3f274362015-03-05 14:35:41 -080028struct AReplyToken;
Andreas Huber2bfdd422011-10-11 15:24:07 -070029struct AnotherPacketSource;
30struct MyHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010031struct SDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -070032
33struct NuPlayer::RTSPSource : public NuPlayer::Source {
34 RTSPSource(
Andreas Huberb5f25f02013-02-05 10:14:26 -080035 const sp<AMessage> &notify,
Andreas Huber1b86fe02014-01-29 11:13:26 -080036 const sp<IMediaHTTPService> &httpService,
Andreas Huber2bfdd422011-10-11 15:24:07 -070037 const char *url,
38 const KeyedVector<String8, String8> *headers,
39 bool uidValid = false,
Oscar Rydhé7a33b772012-02-20 10:15:48 +010040 uid_t uid = 0,
41 bool isSDP = false);
Andreas Huber2bfdd422011-10-11 15:24:07 -070042
Andreas Huber9575c962013-02-05 13:59:56 -080043 virtual void prepareAsync();
Andreas Huber2bfdd422011-10-11 15:24:07 -070044 virtual void start();
45 virtual void stop();
Roger Jönssonfba60da2013-01-21 17:15:45 +010046 virtual void pause();
47 virtual void resume();
Andreas Huber2bfdd422011-10-11 15:24:07 -070048
49 virtual status_t feedMoreTSData();
50
Andreas Huber2bfdd422011-10-11 15:24:07 -070051 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
52
53 virtual status_t getDuration(int64_t *durationUs);
54 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080055
Andreas Huber2bfdd422011-10-11 15:24:07 -070056 void onMessageReceived(const sp<AMessage> &msg);
57
58protected:
59 virtual ~RTSPSource();
60
Andreas Huber84066782011-08-16 09:34:26 -070061 virtual sp<MetaData> getFormatMeta(bool audio);
62
Andreas Huber2bfdd422011-10-11 15:24:07 -070063private:
64 enum {
65 kWhatNotify = 'noti',
66 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080067 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070068 };
69
70 enum State {
71 DISCONNECTED,
72 CONNECTING,
73 CONNECTED,
74 SEEKING,
75 };
76
77 enum Flags {
78 // Don't log any URLs.
79 kFlagIncognito = 1,
80 };
81
82 struct TrackInfo {
83 sp<AnotherPacketSource> mSource;
84
85 int32_t mTimeScale;
86 uint32_t mRTPTime;
87 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080088 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070089 };
90
Andreas Huber1b86fe02014-01-29 11:13:26 -080091 sp<IMediaHTTPService> mHTTPService;
Andreas Huber2bfdd422011-10-11 15:24:07 -070092 AString mURL;
93 KeyedVector<String8, String8> mExtraHeaders;
94 bool mUIDValid;
95 uid_t mUID;
96 uint32_t mFlags;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010097 bool mIsSDP;
Andreas Huber2bfdd422011-10-11 15:24:07 -070098 State mState;
99 status_t mFinalResult;
Lajos Molnar3f274362015-03-05 14:35:41 -0800100 sp<AReplyToken> mDisconnectReplyID;
Chong Zhang180d1b92014-12-02 18:35:35 -0800101 Mutex mBufferingLock;
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100102 bool mBuffering;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700103
104 sp<ALooper> mLooper;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700105 sp<MyHandler> mHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100106 sp<SDPLoader> mSDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700107
108 Vector<TrackInfo> mTracks;
109 sp<AnotherPacketSource> mAudioTrack;
110 sp<AnotherPacketSource> mVideoTrack;
111
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700112 sp<ATSParser> mTSParser;
113
Andreas Huberee736e92011-12-08 13:04:50 -0800114 int32_t mSeekGeneration;
115
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100116 int64_t mEOSTimeoutAudio;
117 int64_t mEOSTimeoutVideo;
118
Robert Shih8d237a52015-07-13 17:59:36 -0700119 sp<AReplyToken> mSeekReplyID;
120
Andreas Huber2bfdd422011-10-11 15:24:07 -0700121 sp<AnotherPacketSource> getSource(bool audio);
122
123 void onConnected();
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100124 void onSDPLoaded(const sp<AMessage> &msg);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700125 void onDisconnected(const sp<AMessage> &msg);
126 void finishDisconnectIfPossible();
127
Andreas Huberee736e92011-12-08 13:04:50 -0800128 void performSeek(int64_t seekTimeUs);
129
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700130 bool haveSufficientDataOnAllTracks();
131
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100132 void setEOSTimeout(bool audio, int64_t timeout);
Chong Zhang180d1b92014-12-02 18:35:35 -0800133 void setError(status_t err);
134 void startBufferingIfNecessary();
135 bool stopBufferingIfNecessary();
Robert Shih8d237a52015-07-13 17:59:36 -0700136 void finishSeek(status_t err);
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100137
Andreas Huber2bfdd422011-10-11 15:24:07 -0700138 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
139};
140
141} // namespace android
142
143#endif // RTSP_SOURCE_H_