Home | History | Annotate | Download | only in nuplayer
      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 
     27 namespace android {
     28 
     29 struct ALooper;
     30 struct AnotherPacketSource;
     31 struct MyHandler;
     32 
     33 struct 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     virtual bool isSeekable();
     50 
     51     void onMessageReceived(const sp<AMessage> &msg);
     52 
     53 protected:
     54     virtual ~RTSPSource();
     55 
     56     virtual sp<MetaData> getFormatMeta(bool audio);
     57 
     58 private:
     59     enum {
     60         kWhatNotify          = 'noti',
     61         kWhatDisconnect      = 'disc',
     62         kWhatPerformSeek     = 'seek',
     63     };
     64 
     65     enum State {
     66         DISCONNECTED,
     67         CONNECTING,
     68         CONNECTED,
     69         SEEKING,
     70     };
     71 
     72     enum Flags {
     73         // Don't log any URLs.
     74         kFlagIncognito = 1,
     75     };
     76 
     77     struct TrackInfo {
     78         sp<AnotherPacketSource> mSource;
     79 
     80         int32_t mTimeScale;
     81         uint32_t mRTPTime;
     82         int64_t mNormalPlaytimeUs;
     83         bool mNPTMappingValid;
     84     };
     85 
     86     AString mURL;
     87     KeyedVector<String8, String8> mExtraHeaders;
     88     bool mUIDValid;
     89     uid_t mUID;
     90     uint32_t mFlags;
     91     State mState;
     92     status_t mFinalResult;
     93     uint32_t mDisconnectReplyID;
     94     bool mStartingUp;
     95 
     96     sp<ALooper> mLooper;
     97     sp<AHandlerReflector<RTSPSource> > mReflector;
     98     sp<MyHandler> mHandler;
     99 
    100     Vector<TrackInfo> mTracks;
    101     sp<AnotherPacketSource> mAudioTrack;
    102     sp<AnotherPacketSource> mVideoTrack;
    103 
    104     sp<ATSParser> mTSParser;
    105 
    106     int32_t mSeekGeneration;
    107 
    108     sp<AnotherPacketSource> getSource(bool audio);
    109 
    110     void onConnected();
    111     void onDisconnected(const sp<AMessage> &msg);
    112     void finishDisconnectIfPossible();
    113 
    114     void performSeek(int64_t seekTimeUs);
    115 
    116     bool haveSufficientDataOnAllTracks();
    117 
    118     DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
    119 };
    120 
    121 }  // namespace android
    122 
    123 #endif  // RTSP_SOURCE_H_
    124