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