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