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 namespace android {
     26 
     27 struct ALooper;
     28 struct AnotherPacketSource;
     29 struct MyHandler;
     30 struct SDPLoader;
     31 
     32 struct NuPlayer::RTSPSource : public NuPlayer::Source {
     33     RTSPSource(
     34             const sp<AMessage> &notify,
     35             const sp<IMediaHTTPService> &httpService,
     36             const char *url,
     37             const KeyedVector<String8, String8> *headers,
     38             bool uidValid = false,
     39             uid_t uid = 0,
     40             bool isSDP = false);
     41 
     42     virtual void prepareAsync();
     43     virtual void start();
     44     virtual void stop();
     45     virtual void pause();
     46     virtual void resume();
     47 
     48     virtual status_t feedMoreTSData();
     49 
     50     virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
     51 
     52     virtual status_t getDuration(int64_t *durationUs);
     53     virtual status_t seekTo(int64_t seekTimeUs);
     54 
     55     void onMessageReceived(const sp<AMessage> &msg);
     56 
     57 protected:
     58     virtual ~RTSPSource();
     59 
     60     virtual sp<MetaData> getFormatMeta(bool audio);
     61 
     62 private:
     63     enum {
     64         kWhatNotify          = 'noti',
     65         kWhatDisconnect      = 'disc',
     66         kWhatPerformSeek     = 'seek',
     67     };
     68 
     69     enum State {
     70         DISCONNECTED,
     71         CONNECTING,
     72         CONNECTED,
     73         SEEKING,
     74     };
     75 
     76     enum Flags {
     77         // Don't log any URLs.
     78         kFlagIncognito = 1,
     79     };
     80 
     81     struct TrackInfo {
     82         sp<AnotherPacketSource> mSource;
     83 
     84         int32_t mTimeScale;
     85         uint32_t mRTPTime;
     86         int64_t mNormalPlaytimeUs;
     87         bool mNPTMappingValid;
     88     };
     89 
     90     sp<IMediaHTTPService> mHTTPService;
     91     AString mURL;
     92     KeyedVector<String8, String8> mExtraHeaders;
     93     bool mUIDValid;
     94     uid_t mUID;
     95     uint32_t mFlags;
     96     bool mIsSDP;
     97     State mState;
     98     status_t mFinalResult;
     99     uint32_t mDisconnectReplyID;
    100     Mutex mBufferingLock;
    101     bool mBuffering;
    102 
    103     sp<ALooper> mLooper;
    104     sp<MyHandler> mHandler;
    105     sp<SDPLoader> mSDPLoader;
    106 
    107     Vector<TrackInfo> mTracks;
    108     sp<AnotherPacketSource> mAudioTrack;
    109     sp<AnotherPacketSource> mVideoTrack;
    110 
    111     sp<ATSParser> mTSParser;
    112 
    113     int32_t mSeekGeneration;
    114 
    115     int64_t mEOSTimeoutAudio;
    116     int64_t mEOSTimeoutVideo;
    117 
    118     sp<AnotherPacketSource> getSource(bool audio);
    119 
    120     void onConnected();
    121     void onSDPLoaded(const sp<AMessage> &msg);
    122     void onDisconnected(const sp<AMessage> &msg);
    123     void finishDisconnectIfPossible();
    124 
    125     void performSeek(int64_t seekTimeUs);
    126 
    127     bool haveSufficientDataOnAllTracks();
    128 
    129     void setEOSTimeout(bool audio, int64_t timeout);
    130     void setError(status_t err);
    131     void startBufferingIfNecessary();
    132     bool stopBufferingIfNecessary();
    133 
    134     DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
    135 };
    136 
    137 }  // namespace android
    138 
    139 #endif  // RTSP_SOURCE_H_
    140