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 A_RTSP_CONTROLLER_H_ 18 19 #define A_RTSP_CONTROLLER_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/foundation/AHandlerReflector.h> 23 #include <media/stagefright/MediaExtractor.h> 24 25 namespace android { 26 27 struct ALooper; 28 struct MyHandler; 29 30 struct ARTSPController : public MediaExtractor { 31 ARTSPController(const sp<ALooper> &looper); 32 33 void setUID(uid_t uid); 34 35 status_t connect(const char *url); 36 void disconnect(); 37 38 void seekAsync(int64_t timeUs, void (*seekDoneCb)(void *), void *cookie); 39 40 virtual size_t countTracks(); 41 virtual sp<MediaSource> getTrack(size_t index); 42 43 virtual sp<MetaData> getTrackMetaData( 44 size_t index, uint32_t flags); 45 46 int64_t getNormalPlayTimeUs(); 47 int64_t getQueueDurationUs(bool *eos); 48 49 void onMessageReceived(const sp<AMessage> &msg); 50 51 virtual uint32_t flags() const { 52 // Seeking 10secs forward or backward is a very expensive operation 53 // for rtsp, so let's not enable that. 54 // The user can always use the seek bar. 55 56 return CAN_PAUSE | CAN_SEEK; 57 } 58 59 protected: 60 virtual ~ARTSPController(); 61 62 private: 63 enum { 64 kWhatConnectDone = 'cdon', 65 kWhatDisconnectDone = 'ddon', 66 kWhatSeekDone = 'sdon', 67 }; 68 69 enum State { 70 DISCONNECTED, 71 CONNECTED, 72 CONNECTING, 73 }; 74 75 Mutex mLock; 76 Condition mCondition; 77 78 State mState; 79 status_t mConnectionResult; 80 81 sp<ALooper> mLooper; 82 sp<MyHandler> mHandler; 83 sp<AHandlerReflector<ARTSPController> > mReflector; 84 85 bool mUIDValid; 86 uid_t mUID; 87 88 void (*mSeekDoneCb)(void *); 89 void *mSeekDoneCookie; 90 int64_t mLastSeekCompletedTimeUs; 91 92 DISALLOW_EVIL_CONSTRUCTORS(ARTSPController); 93 }; 94 95 } // namespace android 96 97 #endif // A_RTSP_CONTROLLER_H_ 98