blob: cbb6f90aa983d3d167cac9d49c9e545d9b24eb22 [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();
46
47 virtual status_t feedMoreTSData();
48
Andreas Huber2bfdd422011-10-11 15:24:07 -070049 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
50
51 virtual status_t getDuration(int64_t *durationUs);
52 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080053
Andreas Huber2bfdd422011-10-11 15:24:07 -070054 void onMessageReceived(const sp<AMessage> &msg);
55
56protected:
57 virtual ~RTSPSource();
58
Andreas Huber84066782011-08-16 09:34:26 -070059 virtual sp<MetaData> getFormatMeta(bool audio);
60
Andreas Huber2bfdd422011-10-11 15:24:07 -070061private:
62 enum {
63 kWhatNotify = 'noti',
64 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080065 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070066 };
67
68 enum State {
69 DISCONNECTED,
70 CONNECTING,
71 CONNECTED,
72 SEEKING,
73 };
74
75 enum Flags {
76 // Don't log any URLs.
77 kFlagIncognito = 1,
78 };
79
80 struct TrackInfo {
81 sp<AnotherPacketSource> mSource;
82
83 int32_t mTimeScale;
84 uint32_t mRTPTime;
85 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080086 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070087 };
88
89 AString mURL;
90 KeyedVector<String8, String8> mExtraHeaders;
91 bool mUIDValid;
92 uid_t mUID;
93 uint32_t mFlags;
Oscar Rydhé7a33b772012-02-20 10:15:48 +010094 bool mIsSDP;
Andreas Huber2bfdd422011-10-11 15:24:07 -070095 State mState;
96 status_t mFinalResult;
97 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070098 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070099
100 sp<ALooper> mLooper;
101 sp<AHandlerReflector<RTSPSource> > mReflector;
102 sp<MyHandler> mHandler;
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100103 sp<SDPLoader> mSDPLoader;
Andreas Huber2bfdd422011-10-11 15:24:07 -0700104
105 Vector<TrackInfo> mTracks;
106 sp<AnotherPacketSource> mAudioTrack;
107 sp<AnotherPacketSource> mVideoTrack;
108
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700109 sp<ATSParser> mTSParser;
110
Andreas Huberee736e92011-12-08 13:04:50 -0800111 int32_t mSeekGeneration;
112
Andreas Huber2bfdd422011-10-11 15:24:07 -0700113 sp<AnotherPacketSource> getSource(bool audio);
114
115 void onConnected();
Oscar Rydhé7a33b772012-02-20 10:15:48 +0100116 void onSDPLoaded(const sp<AMessage> &msg);
Andreas Huber2bfdd422011-10-11 15:24:07 -0700117 void onDisconnected(const sp<AMessage> &msg);
118 void finishDisconnectIfPossible();
119
Andreas Huberee736e92011-12-08 13:04:50 -0800120 void performSeek(int64_t seekTimeUs);
121
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700122 bool haveSufficientDataOnAllTracks();
123
Andreas Huber2bfdd422011-10-11 15:24:07 -0700124 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
125};
126
127} // namespace android
128
129#endif // RTSP_SOURCE_H_