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