RTSPSource.h revision 8d237a5ce1e3c1dbc1d538f47e68cff2cc52d799
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 25namespace android { 26 27struct ALooper; 28struct AReplyToken; 29struct AnotherPacketSource; 30struct MyHandler; 31struct SDPLoader; 32 33struct NuPlayer::RTSPSource : public NuPlayer::Source { 34 RTSPSource( 35 const sp<AMessage> ¬ify, 36 const sp<IMediaHTTPService> &httpService, 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 58protected: 59 virtual ~RTSPSource(); 60 61 virtual sp<MetaData> getFormatMeta(bool audio); 62 63private: 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 sp<IMediaHTTPService> mHTTPService; 92 AString mURL; 93 KeyedVector<String8, String8> mExtraHeaders; 94 bool mUIDValid; 95 uid_t mUID; 96 uint32_t mFlags; 97 bool mIsSDP; 98 State mState; 99 status_t mFinalResult; 100 sp<AReplyToken> mDisconnectReplyID; 101 Mutex mBufferingLock; 102 bool mBuffering; 103 104 sp<ALooper> mLooper; 105 sp<MyHandler> mHandler; 106 sp<SDPLoader> mSDPLoader; 107 108 Vector<TrackInfo> mTracks; 109 sp<AnotherPacketSource> mAudioTrack; 110 sp<AnotherPacketSource> mVideoTrack; 111 112 sp<ATSParser> mTSParser; 113 114 int32_t mSeekGeneration; 115 116 int64_t mEOSTimeoutAudio; 117 int64_t mEOSTimeoutVideo; 118 119 sp<AReplyToken> mSeekReplyID; 120 121 sp<AnotherPacketSource> getSource(bool audio); 122 123 void onConnected(); 124 void onSDPLoaded(const sp<AMessage> &msg); 125 void onDisconnected(const sp<AMessage> &msg); 126 void finishDisconnectIfPossible(); 127 128 void performSeek(int64_t seekTimeUs); 129 130 bool haveSufficientDataOnAllTracks(); 131 132 void setEOSTimeout(bool audio, int64_t timeout); 133 void setError(status_t err); 134 void startBufferingIfNecessary(); 135 bool stopBufferingIfNecessary(); 136 void finishSeek(status_t err); 137 138 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource); 139}; 140 141} // namespace android 142 143#endif // RTSP_SOURCE_H_ 144