blob: 779d791ef48ade03624fa6351b5029c9ce6666e9 [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);
Andreas Huberb7c8e912012-11-27 15:02:53 -080049
50 virtual uint32_t flags() const;
Andreas Huber2bfdd422011-10-11 15:24:07 -070051
52 void onMessageReceived(const sp<AMessage> &msg);
53
54protected:
55 virtual ~RTSPSource();
56
Andreas Huber84066782011-08-16 09:34:26 -070057 virtual sp<MetaData> getFormatMeta(bool audio);
58
Andreas Huber2bfdd422011-10-11 15:24:07 -070059private:
60 enum {
61 kWhatNotify = 'noti',
62 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080063 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070064 };
65
66 enum State {
67 DISCONNECTED,
68 CONNECTING,
69 CONNECTED,
70 SEEKING,
71 };
72
73 enum Flags {
74 // Don't log any URLs.
75 kFlagIncognito = 1,
76 };
77
78 struct TrackInfo {
79 sp<AnotherPacketSource> mSource;
80
81 int32_t mTimeScale;
82 uint32_t mRTPTime;
83 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080084 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070085 };
86
87 AString mURL;
88 KeyedVector<String8, String8> mExtraHeaders;
89 bool mUIDValid;
90 uid_t mUID;
91 uint32_t mFlags;
92 State mState;
93 status_t mFinalResult;
94 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070095 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070096
97 sp<ALooper> mLooper;
98 sp<AHandlerReflector<RTSPSource> > mReflector;
99 sp<MyHandler> mHandler;
100
101 Vector<TrackInfo> mTracks;
102 sp<AnotherPacketSource> mAudioTrack;
103 sp<AnotherPacketSource> mVideoTrack;
104
Andreas Hubercfaeeec2012-08-31 10:27:46 -0700105 sp<ATSParser> mTSParser;
106
Andreas Huberee736e92011-12-08 13:04:50 -0800107 int32_t mSeekGeneration;
108
Andreas Huber2bfdd422011-10-11 15:24:07 -0700109 sp<AnotherPacketSource> getSource(bool audio);
110
111 void onConnected();
112 void onDisconnected(const sp<AMessage> &msg);
113 void finishDisconnectIfPossible();
114
Andreas Huberee736e92011-12-08 13:04:50 -0800115 void performSeek(int64_t seekTimeUs);
116
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700117 bool haveSufficientDataOnAllTracks();
118
Andreas Huber2bfdd422011-10-11 15:24:07 -0700119 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
120};
121
122} // namespace android
123
124#endif // RTSP_SOURCE_H_