blob: e11e3049a4033f87e58a358eae4615ff1a72e1eb [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
23#include <media/stagefright/foundation/AHandlerReflector.h>
24
25namespace android {
26
27struct ALooper;
28struct AnotherPacketSource;
29struct MyHandler;
30
31struct NuPlayer::RTSPSource : public NuPlayer::Source {
32 RTSPSource(
33 const char *url,
34 const KeyedVector<String8, String8> *headers,
35 bool uidValid = false,
36 uid_t uid = 0);
37
38 virtual void start();
39 virtual void stop();
40
41 virtual status_t feedMoreTSData();
42
43 virtual sp<MetaData> getFormat(bool audio);
44 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
45
46 virtual status_t getDuration(int64_t *durationUs);
47 virtual status_t seekTo(int64_t seekTimeUs);
48 virtual bool isSeekable();
49
50 void onMessageReceived(const sp<AMessage> &msg);
51
52protected:
53 virtual ~RTSPSource();
54
55private:
56 enum {
57 kWhatNotify = 'noti',
58 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080059 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070060 };
61
62 enum State {
63 DISCONNECTED,
64 CONNECTING,
65 CONNECTED,
66 SEEKING,
67 };
68
69 enum Flags {
70 // Don't log any URLs.
71 kFlagIncognito = 1,
72 };
73
74 struct TrackInfo {
75 sp<AnotherPacketSource> mSource;
76
77 int32_t mTimeScale;
78 uint32_t mRTPTime;
79 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080080 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070081 };
82
83 AString mURL;
84 KeyedVector<String8, String8> mExtraHeaders;
85 bool mUIDValid;
86 uid_t mUID;
87 uint32_t mFlags;
88 State mState;
89 status_t mFinalResult;
90 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070091 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070092
93 sp<ALooper> mLooper;
94 sp<AHandlerReflector<RTSPSource> > mReflector;
95 sp<MyHandler> mHandler;
96
97 Vector<TrackInfo> mTracks;
98 sp<AnotherPacketSource> mAudioTrack;
99 sp<AnotherPacketSource> mVideoTrack;
100
Andreas Huberee736e92011-12-08 13:04:50 -0800101 int32_t mSeekGeneration;
102
Andreas Huber2bfdd422011-10-11 15:24:07 -0700103 sp<AnotherPacketSource> getSource(bool audio);
104
105 void onConnected();
106 void onDisconnected(const sp<AMessage> &msg);
107 void finishDisconnectIfPossible();
108
Andreas Huberee736e92011-12-08 13:04:50 -0800109 void performSeek(int64_t seekTimeUs);
110
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700111 bool haveSufficientDataOnAllTracks();
112
Andreas Huber2bfdd422011-10-11 15:24:07 -0700113 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
114};
115
116} // namespace android
117
118#endif // RTSP_SOURCE_H_