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