blob: 3718bf9fab36fc71c6850e323db42e488914f181 [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 -070025#include <media/stagefright/foundation/AHandlerReflector.h>
26
27namespace android {
28
29struct ALooper;
30struct AnotherPacketSource;
31struct MyHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010032struct SDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -070033
34struct NuPlayer::RTSPSource : public NuPlayer::Source {
35 RTSPSource(
Andreas Huberb5f25f02013-02-05 10:14:26 -080036 const sp<AMessage> &notify,
Andreas Huber1b86fe02014-01-29 11:13:26 -080037 const sp<IMediaHTTPService> &httpService,
Andreas Huber2bfdd422011-10-11 15:24:07 -070038 const char *url,
39 const KeyedVector<String8, String8> *headers,
40 bool uidValid = false,
Oscar Rydhé7a33b772012-02-20 10:15:48 +010041 uid_t uid = 0,
42 bool isSDP = false);
Andreas Huber2bfdd422011-10-11 15:24:07 -070043
Andreas Huber9575c962013-02-05 13:59:56 -080044 virtual void prepareAsync();
Andreas Huber2bfdd422011-10-11 15:24:07 -070045 virtual void start();
46 virtual void stop();
Roger Jönssonfba60da2013-01-21 17:15:45 +010047 virtual void pause();
48 virtual void resume();
Andreas Huber2bfdd422011-10-11 15:24:07 -070049
50 virtual status_t feedMoreTSData();
51
Andreas Huber2bfdd422011-10-11 15:24:07 -070052 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
53
54 virtual status_t getDuration(int64_t *durationUs);
55 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080056
Andreas Huber2bfdd422011-10-11 15:24:07 -070057 void onMessageReceived(const sp<AMessage> &msg);
58
59protected:
60 virtual ~RTSPSource();
61
Andreas Huber84066782011-08-16 09:34:26 -070062 virtual sp<MetaData> getFormatMeta(bool audio);
63
Andreas Huber2bfdd422011-10-11 15:24:07 -070064private:
65 enum {
66 kWhatNotify = 'noti',
67 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080068 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070069 };
70
71 enum State {
72 DISCONNECTED,
73 CONNECTING,
74 CONNECTED,
75 SEEKING,
76 };
77
78 enum Flags {
79 // Don't log any URLs.
80 kFlagIncognito = 1,
81 };
82
83 struct TrackInfo {
84 sp<AnotherPacketSource> mSource;
85
86 int32_t mTimeScale;
87 uint32_t mRTPTime;
88 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080089 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070090 };
91
Andreas Huber1b86fe02014-01-29 11:13:26 -080092 sp<IMediaHTTPService> mHTTPService;
Andreas Huber2bfdd422011-10-11 15:24:07 -070093 AString mURL;
94 KeyedVector<String8, String8> mExtraHeaders;
95 bool mUIDValid;
96 uid_t mUID;
97 uint32_t mFlags;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010098 bool mIsSDP;
Andreas Huber2bfdd422011-10-11 15:24:07 -070099 State mState;
100 status_t mFinalResult;
101 uint32_t mDisconnectReplyID;
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100102 bool mBuffering;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700103
104 sp<ALooper> mLooper;
105 sp<AHandlerReflector<RTSPSource> > mReflector;
106 sp<MyHandler> mHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100107 sp<SDPLoader> mSDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700108
109 Vector<TrackInfo> mTracks;
110 sp<AnotherPacketSource> mAudioTrack;
111 sp<AnotherPacketSource> mVideoTrack;
112
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700113 sp<ATSParser> mTSParser;
114
Andreas Huberee736e92011-12-08 13:04:50 -0800115 int32_t mSeekGeneration;
116
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100117 int64_t mEOSTimeoutAudio;
118 int64_t mEOSTimeoutVideo;
119
Andreas Huber2bfdd422011-10-11 15:24:07 -0700120 sp<AnotherPacketSource> getSource(bool audio);
121
122 void onConnected();
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100123 void onSDPLoaded(const sp<AMessage> &msg);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700124 void onDisconnected(const sp<AMessage> &msg);
125 void finishDisconnectIfPossible();
126
Andreas Huberee736e92011-12-08 13:04:50 -0800127 void performSeek(int64_t seekTimeUs);
128
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700129 bool haveSufficientDataOnAllTracks();
130
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100131 void setEOSTimeout(bool audio, int64_t timeout);
132
Andreas Huber2bfdd422011-10-11 15:24:07 -0700133 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
134};
135
136} // namespace android
137
138#endif // RTSP_SOURCE_H_