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