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 LIVE_SOURCE_H_ 18 19 #define LIVE_SOURCE_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/foundation/AString.h> 23 #include <media/stagefright/DataSource.h> 24 #include <utils/Vector.h> 25 26 namespace android { 27 28 struct ABuffer; 29 struct NuHTTPDataSource; 30 struct M3UParser; 31 32 struct LiveSource : public DataSource { 33 LiveSource(const char *url); 34 35 virtual status_t initCheck() const; 36 37 virtual ssize_t readAt(off_t offset, void *data, size_t size); 38 39 virtual uint32_t flags() { 40 return kWantsPrefetching; 41 } 42 43 bool getDuration(int64_t *durationUs) const; 44 45 bool isSeekable() const; 46 bool seekTo(int64_t seekTimeUs); 47 48 protected: 49 virtual ~LiveSource(); 50 51 private: 52 struct BandwidthItem { 53 AString mURI; 54 unsigned long mBandwidth; 55 }; 56 Vector<BandwidthItem> mBandwidthItems; 57 58 AString mMasterURL; 59 AString mURL; 60 status_t mInitCheck; 61 int64_t mDurationUs; 62 63 sp<M3UParser> mPlaylist; 64 int32_t mFirstItemSequenceNumber; 65 size_t mPlaylistIndex; 66 int64_t mLastFetchTimeUs; 67 68 sp<NuHTTPDataSource> mSource; 69 off_t mSourceSize; 70 off_t mOffsetBias; 71 72 bool mSignalDiscontinuity; 73 ssize_t mPrevBandwidthIndex; 74 75 status_t fetchM3U(const char *url, sp<ABuffer> *buffer); 76 77 static int SortByBandwidth(const BandwidthItem *a, const BandwidthItem *b); 78 79 bool switchToNext(); 80 bool loadPlaylist(bool fetchMaster); 81 void determineSeekability(); 82 83 DISALLOW_EVIL_CONSTRUCTORS(LiveSource); 84 }; 85 86 } // namespace android 87 88 #endif // LIVE_SOURCE_H_ 89