blob: f07c72449eaf1873007f8a5278703b19e0b49c1e [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(
35 const char *url,
36 const KeyedVector<String8, String8> *headers,
37 bool uidValid = false,
38 uid_t uid = 0);
39
40 virtual void start();
41 virtual void stop();
42
43 virtual status_t feedMoreTSData();
44
Andreas Huber2bfdd422011-10-11 15:24:07 -070045 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
46
47 virtual status_t getDuration(int64_t *durationUs);
48 virtual status_t seekTo(int64_t seekTimeUs);
49 virtual bool isSeekable();
50
51 void onMessageReceived(const sp<AMessage> &msg);
52
53protected:
54 virtual ~RTSPSource();
55
Andreas Huber84066782011-08-16 09:34:26 -070056 virtual sp<MetaData> getFormatMeta(bool audio);
57
Andreas Huber2bfdd422011-10-11 15:24:07 -070058private:
59 enum {
60 kWhatNotify = 'noti',
61 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080062 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070063 };
64
65 enum State {
66 DISCONNECTED,
67 CONNECTING,
68 CONNECTED,
69 SEEKING,
70 };
71
72 enum Flags {
73 // Don't log any URLs.
74 kFlagIncognito = 1,
75 };
76
77 struct TrackInfo {
78 sp<AnotherPacketSource> mSource;
79
80 int32_t mTimeScale;
81 uint32_t mRTPTime;
82 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080083 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070084 };
85
86 AString mURL;
87 KeyedVector<String8, String8> mExtraHeaders;
88 bool mUIDValid;
89 uid_t mUID;
90 uint32_t mFlags;
91 State mState;
92 status_t mFinalResult;
93 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070094 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070095
96 sp<ALooper> mLooper;
97 sp<AHandlerReflector<RTSPSource> > mReflector;
98 sp<MyHandler> mHandler;
99
100 Vector<TrackInfo> mTracks;
101 sp<AnotherPacketSource> mAudioTrack;
102 sp<AnotherPacketSource> mVideoTrack;
103
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700104 sp<ATSParser> mTSParser;
105
Andreas Huberee736e92011-12-08 13:04:50 -0800106 int32_t mSeekGeneration;
107
Andreas Huber2bfdd422011-10-11 15:24:07 -0700108 sp<AnotherPacketSource> getSource(bool audio);
109
110 void onConnected();
111 void onDisconnected(const sp<AMessage> &msg);
112 void finishDisconnectIfPossible();
113
Andreas Huberee736e92011-12-08 13:04:50 -0800114 void performSeek(int64_t seekTimeUs);
115
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700116 bool haveSufficientDataOnAllTracks();
117
Andreas Huber2bfdd422011-10-11 15:24:07 -0700118 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
119};
120
121} // namespace android
122
123#endif // RTSP_SOURCE_H_