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