blob: c8409e5c289276ad1bcf40f06dae5c3281b4af73 [file] [log] [blame]
Andreas Huber2bfdd422011-10-11 15:24:07 -07001/*
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 <media/stagefright/foundation/AHandlerReflector.h>
24
25namespace android {
26
27struct ALooper;
28struct AnotherPacketSource;
29struct MyHandler;
30
31struct NuPlayer::RTSPSource : public NuPlayer::Source {
32 RTSPSource(
33 const char *url,
34 const KeyedVector<String8, String8> *headers,
35 bool uidValid = false,
36 uid_t uid = 0);
37
38 virtual void start();
39 virtual void stop();
40
41 virtual status_t feedMoreTSData();
42
Andreas Huber2bfdd422011-10-11 15:24:07 -070043 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
44
45 virtual status_t getDuration(int64_t *durationUs);
46 virtual status_t seekTo(int64_t seekTimeUs);
47 virtual bool isSeekable();
48
49 void onMessageReceived(const sp<AMessage> &msg);
50
51protected:
52 virtual ~RTSPSource();
53
Andreas Huber84066782011-08-16 09:34:26 -070054 virtual sp<MetaData> getFormatMeta(bool audio);
55
Andreas Huber2bfdd422011-10-11 15:24:07 -070056private:
57 enum {
58 kWhatNotify = 'noti',
59 kWhatDisconnect = 'disc',
Andreas Huberee736e92011-12-08 13:04:50 -080060 kWhatPerformSeek = 'seek',
Andreas Huber2bfdd422011-10-11 15:24:07 -070061 };
62
63 enum State {
64 DISCONNECTED,
65 CONNECTING,
66 CONNECTED,
67 SEEKING,
68 };
69
70 enum Flags {
71 // Don't log any URLs.
72 kFlagIncognito = 1,
73 };
74
75 struct TrackInfo {
76 sp<AnotherPacketSource> mSource;
77
78 int32_t mTimeScale;
79 uint32_t mRTPTime;
80 int64_t mNormalPlaytimeUs;
Andreas Huber1906e5c2011-12-08 12:27:47 -080081 bool mNPTMappingValid;
Andreas Huber2bfdd422011-10-11 15:24:07 -070082 };
83
84 AString mURL;
85 KeyedVector<String8, String8> mExtraHeaders;
86 bool mUIDValid;
87 uid_t mUID;
88 uint32_t mFlags;
89 State mState;
90 status_t mFinalResult;
91 uint32_t mDisconnectReplyID;
Andreas Huberbfd4d0d2012-05-17 14:18:50 -070092 bool mStartingUp;
Andreas Huber2bfdd422011-10-11 15:24:07 -070093
94 sp<ALooper> mLooper;
95 sp<AHandlerReflector<RTSPSource> > mReflector;
96 sp<MyHandler> mHandler;
97
98 Vector<TrackInfo> mTracks;
99 sp<AnotherPacketSource> mAudioTrack;
100 sp<AnotherPacketSource> mVideoTrack;
101
Andreas Huberee736e92011-12-08 13:04:50 -0800102 int32_t mSeekGeneration;
103
Andreas Huber2bfdd422011-10-11 15:24:07 -0700104 sp<AnotherPacketSource> getSource(bool audio);
105
106 void onConnected();
107 void onDisconnected(const sp<AMessage> &msg);
108 void finishDisconnectIfPossible();
109
Andreas Huberee736e92011-12-08 13:04:50 -0800110 void performSeek(int64_t seekTimeUs);
111
Andreas Huberbfd4d0d2012-05-17 14:18:50 -0700112 bool haveSufficientDataOnAllTracks();
113
Andreas Huber2bfdd422011-10-11 15:24:07 -0700114 DISALLOW_EVIL_CONSTRUCTORS(RTSPSource);
115};
116
117} // namespace android
118
119#endif // RTSP_SOURCE_H_