blob: 8cf34a093b7d78d1473fd09176fb47452a3373a0 [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 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
91 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;
103 sp<AHandlerReflector<RTSPSource> > mReflector;
104 sp<MyHandler> mHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100105 sp<SDPLoader> mSDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700106
107 Vector<TrackInfo> mTracks;
108 sp<AnotherPacketSource> mAudioTrack;
109 sp<AnotherPacketSource> mVideoTrack;
110
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700111 sp<ATSParser> mTSParser;
112
Andreas Huberee736e92011-12-08 13:04:50 -0800113 int32_t mSeekGeneration;
114
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100115 int64_t mEOSTimeoutAudio;
116 int64_t mEOSTimeoutVideo;
117
Andreas Huber2bfdd422011-10-11 15:24:07 -0700118 sp<AnotherPacketSource> getSource(bool audio);
119
120 void onConnected();
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100121 void onSDPLoaded(const sp<AMessage> &msg);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700122 void onDisconnected(const sp<AMessage> &msg);
123 void finishDisconnectIfPossible();
124
Andreas Huberee736e92011-12-08 13:04:50 -0800125 void performSeek(int64_t seekTimeUs);
126
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700127 bool haveSufficientDataOnAllTracks();
128
Roger Jönssonb50e83e2013-01-21 16:26:41 +0100129 void setEOSTimeout(bool audio, int64_t timeout);
130
Andreas Huber2bfdd422011-10-11 15:24:07 -0700131 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
132};
133
134} // namespace android
135
136#endif // RTSP_SOURCE_H_