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