blob: 033b3e81b9fb65987d4ad166e923a402e68eec8d [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;
32
33struct NuPlayer::RTSPSource : public NuPlayer::Source {
34 RTSPSource(
Andreas Huberb5f25f02013-02-05 10:14:26 -080035 const sp<AMessage> &notify,
Andreas Huber2bfdd422011-10-11 15:24:07 -070036 const char *url,
37 const KeyedVector<String8, String8> *headers,
38 bool uidValid = false,
39 uid_t uid = 0);
40
41 virtual void start();
42 virtual void stop();
43
44 virtual status_t feedMoreTSData();
45
Andreas Huber2bfdd422011-10-11 15:24:07 -070046 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
47
48 virtual status_t getDuration(int64_t *durationUs);
49 virtual status_t seekTo(int64_t seekTimeUs);
Andreas Huberb7c8e912012-11-27 15:02:53 -080050
51 virtual uint32_t flags() const;
Andreas Huber2bfdd422011-10-11 15:24:07 -070052
53 void onMessageReceived(const sp<AMessage> &msg);
54
55protected:
56 virtual ~RTSPSource();
57
Andreas Huber84066782011-08-16 09:34:26 -070058 virtual sp<MetaData> getFormatMeta(bool audio);
59
Andreas Huber2bfdd422011-10-11 15:24:07 -070060private:
61 enum {
62 kWhatNotify = 'noti',
63 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080064 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070065 };
66
67 enum State {
68 DISCONNECTED,
69 CONNECTING,
70 CONNECTED,
71 SEEKING,
72 };
73
74 enum Flags {
75 // Don't log any URLs.
76 kFlagIncognito = 1,
77 };
78
79 struct TrackInfo {
80 sp<AnotherPacketSource> mSource;
81
82 int32_t mTimeScale;
83 uint32_t mRTPTime;
84 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080085 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070086 };
87
88 AString mURL;
89 KeyedVector<String8, String8> mExtraHeaders;
90 bool mUIDValid;
91 uid_t mUID;
92 uint32_t mFlags;
93 State mState;
94 status_t mFinalResult;
95 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070096 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070097
98 sp<ALooper> mLooper;
99 sp<AHandlerReflector<RTSPSource> > mReflector;
100 sp<MyHandler> mHandler;
101
102 Vector<TrackInfo> mTracks;
103 sp<AnotherPacketSource> mAudioTrack;
104 sp<AnotherPacketSource> mVideoTrack;
105
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700106 sp<ATSParser> mTSParser;
107
Andreas Huberee736e92011-12-08 13:04:50 -0800108 int32_t mSeekGeneration;
109
Andreas Huber2bfdd422011-10-11 15:24:07 -0700110 sp<AnotherPacketSource> getSource(bool audio);
111
112 void onConnected();
113 void onDisconnected(const sp<AMessage> &msg);
114 void finishDisconnectIfPossible();
115
Andreas Huberee736e92011-12-08 13:04:50 -0800116 void performSeek(int64_t seekTimeUs);
117
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700118 bool haveSufficientDataOnAllTracks();
119
Andreas Huber2bfdd422011-10-11 15:24:07 -0700120 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
121};
122
123} // namespace android
124
125#endif // RTSP_SOURCE_H_