blob: f1cae536f242bca497ca0b0064b602bab45c438b [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;
28struct AnotherPacketSource;
29struct MyHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010030struct SDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -070031
32struct NuPlayer::RTSPSource : public NuPlayer::Source {
33 RTSPSource(
Andreas Huberb5f25f02013-02-05 10:14:26 -080034 const sp<AMessage> &notify,
Andreas Huber1b86fe02014-01-29 11:13:26 -080035 const sp<IMediaHTTPService> &httpService,
Andreas Huber2bfdd422011-10-11 15:24:07 -070036 const char *url,
37 const KeyedVector<String8, String8> *headers,
38 bool uidValid = false,
Oscar Rydhé7a33b772012-02-20 10:15:48 +010039 uid_t uid = 0,
40 bool isSDP = false);
Andreas Huber2bfdd422011-10-11 15:24:07 -070041
Andreas Huber9575c962013-02-05 13:59:56 -080042 virtual void prepareAsync();
Andreas Huber2bfdd422011-10-11 15:24:07 -070043 virtual void start();
44 virtual void stop();
Roger Jönssonfba60da2013-01-21 17:15:45 +010045 virtual void pause();
46 virtual void resume();
Andreas Huber2bfdd422011-10-11 15:24:07 -070047
48 virtual status_t feedMoreTSData();
49
Andreas Huber2bfdd422011-10-11 15:24:07 -070050 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
51
52 virtual status_t getDuration(int64_t *durationUs);
53 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080054
Andreas Huber2bfdd422011-10-11 15:24:07 -070055 void onMessageReceived(const sp<AMessage> &msg);
56
57protected:
58 virtual ~RTSPSource();
59
Andreas Huber84066782011-08-16 09:34:26 -070060 virtual sp<MetaData> getFormatMeta(bool audio);
61
Andreas Huber2bfdd422011-10-11 15:24:07 -070062private:
63 enum {
64 kWhatNotify = 'noti',
65 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080066 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070067 };
68
69 enum State {
70 DISCONNECTED,
71 CONNECTING,
72 CONNECTED,
73 SEEKING,
74 };
75
76 enum Flags {
77 // Don't log any URLs.
78 kFlagIncognito = 1,
79 };
80
81 struct TrackInfo {
82 sp<AnotherPacketSource> mSource;
83
84 int32_t mTimeScale;
85 uint32_t mRTPTime;
86 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080087 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070088 };
89
Andreas Huber1b86fe02014-01-29 11:13:26 -080090 sp<IMediaHTTPService> mHTTPService;
Andreas Huber2bfdd422011-10-11 15:24:07 -070091 AString mURL;
92 KeyedVector<String8, String8> mExtraHeaders;
93 bool mUIDValid;
94 uid_t mUID;
95 uint32_t mFlags;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010096 bool mIsSDP;
Andreas Huber2bfdd422011-10-11 15:24:07 -070097 State mState;
98 status_t mFinalResult;
99 uint32_t mDisconnectReplyID;
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100100 bool mBuffering;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700101
102 sp<ALooper> mLooper;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700103 sp<MyHandler> mHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100104 sp<SDPLoader> mSDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700105
106 Vector<TrackInfo> mTracks;
107 sp<AnotherPacketSource> mAudioTrack;
108 sp<AnotherPacketSource> mVideoTrack;
109
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700110 sp<ATSParser> mTSParser;
111
Andreas Huberee736e92011-12-08 13:04:50 -0800112 int32_t mSeekGeneration;
113
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100114 int64_t mEOSTimeoutAudio;
115 int64_t mEOSTimeoutVideo;
116
Andreas Huber2bfdd422011-10-11 15:24:07 -0700117 sp<AnotherPacketSource> getSource(bool audio);
118
119 void onConnected();
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100120 void onSDPLoaded(const sp<AMessage> &msg);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700121 void onDisconnected(const sp<AMessage> &msg);
122 void finishDisconnectIfPossible();
123
Andreas Huberee736e92011-12-08 13:04:50 -0800124 void performSeek(int64_t seekTimeUs);
125
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700126 bool haveSufficientDataOnAllTracks();
127
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100128 void setEOSTimeout(bool audio, int64_t timeout);
129
Andreas Huber2bfdd422011-10-11 15:24:07 -0700130 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
131};
132
133} // namespace android
134
135#endif // RTSP_SOURCE_H_