1 /* 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 "ATSParser.h" 24 25 #include <media/stagefright/foundation/AHandlerReflector.h> 26 27 namespace android { 28 29 struct ALooper; 30 struct AnotherPacketSource; 31 struct MyHandler; 32 struct SDPLoader; 33 34 struct NuPlayer::RTSPSource : public NuPlayer::Source { 35 RTSPSource( 36 const sp<AMessage> ¬ify, 37 const char *url, 38 const KeyedVector<String8, String8> *headers, 39 bool uidValid = false, 40 uid_t uid = 0, 41 bool isSDP = false); 42 43 virtual void prepareAsync(); 44 virtual void start(); 45 virtual void stop(); 46 virtual void pause(); 47 virtual void resume(); 48 49 virtual status_t feedMoreTSData(); 50 51 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit); 52 53 virtual status_t getDuration(int64_t *durationUs); 54 virtual status_t seekTo(int64_t seekTimeUs); 55 56 void onMessageReceived(const sp<AMessage> &msg); 57 58 protected: 59 virtual ~RTSPSource(); 60 61 virtual sp<MetaData> getFormatMeta(bool audio); 62 63 private: 64 enum { 65 kWhatNotify = 'noti', 66 kWhatDisconnect = 'disc', 67 kWhatPerformSeek = 'seek', 68 }; 69 70 enum State { 71 DISCONNECTED, 72 CONNECTING, 73 CONNECTED, 74 SEEKING, 75 }; 76 77 enum Flags { 78 // Don't log any URLs. 79 kFlagIncognito = 1, 80 }; 81 82 struct TrackInfo { 83 sp<AnotherPacketSource> mSource; 84 85 int32_t mTimeScale; 86 uint32_t mRTPTime; 87 int64_t mNormalPlaytimeUs; 88 bool mNPTMappingValid; 89 }; 90 91 AString mURL; 92 KeyedVector<String8, String8> mExtraHeaders; 93 bool mUIDValid; 94 uid_t mUID; 95 uint32_t mFlags; 96 bool mIsSDP; 97 State mState; 98 status_t mFinalResult; 99 uint32_t mDisconnectReplyID; 100 bool mBuffering; 101 102 sp<ALooper> mLooper; 103 sp<AHandlerReflector<RTSPSource> > mReflector; 104 sp<MyHandler> mHandler; 105 sp<SDPLoader> mSDPLoader; 106 107 Vector<TrackInfo> mTracks; 108 sp<AnotherPacketSource> mAudioTrack; 109 sp<AnotherPacketSource> mVideoTrack; 110 111 sp<ATSParser> mTSParser; 112 113 int32_t mSeekGeneration; 114 115 int64_t mEOSTimeoutAudio; 116 int64_t mEOSTimeoutVideo; 117 118 sp<AnotherPacketSource> getSource(bool audio); 119 120 void onConnected(); 121 void onSDPLoaded(const sp<AMessage> &msg); 122 void onDisconnected(const sp<AMessage> &msg); 123 void finishDisconnectIfPossible(); 124 125 void performSeek(int64_t seekTimeUs); 126 127 bool haveSufficientDataOnAllTracks(); 128 129 void setEOSTimeout(bool audio, int64_t timeout); 130 131 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource); 132 }; 133 134 } // namespace android 135 136 #endif // RTSP_SOURCE_H_ 137