Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 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 HTTP_LIVE_SOURCE_H_ |
| 18 | |
| 19 | #define HTTP_LIVE_SOURCE_H_ |
| 20 | |
| 21 | #include "NuPlayer.h" |
| 22 | #include "NuPlayerSource.h" |
| 23 | |
Robert Shih | 0852843 | 2015-04-08 09:06:54 -0700 | [diff] [blame] | 24 | #include "LiveSession.h" |
| 25 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 28 | struct LiveSession; |
| 29 | |
| 30 | struct NuPlayer::HTTPLiveSource : public NuPlayer::Source { |
Andreas Huber | ad0d9c9 | 2011-04-19 11:50:27 -0700 | [diff] [blame] | 31 | HTTPLiveSource( |
Andreas Huber | b5f25f0 | 2013-02-05 10:14:26 -0800 | [diff] [blame] | 32 | const sp<AMessage> ¬ify, |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 33 | const sp<IMediaHTTPService> &httpService, |
Andreas Huber | ad0d9c9 | 2011-04-19 11:50:27 -0700 | [diff] [blame] | 34 | const char *url, |
Andreas Huber | 81e6844 | 2014-02-05 11:52:33 -0800 | [diff] [blame] | 35 | const KeyedVector<String8, String8> *headers); |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 36 | |
Wei Jia | 9bb3803 | 2017-03-23 18:00:38 -0700 | [diff] [blame] | 37 | virtual status_t getBufferingSettings( |
Wei Jia | 48fa06d | 2016-12-20 15:30:49 -0800 | [diff] [blame] | 38 | BufferingSettings* buffering /* nonnull */) override; |
| 39 | virtual status_t setBufferingSettings(const BufferingSettings& buffering) override; |
| 40 | |
Andreas Huber | 9575c96 | 2013-02-05 13:59:56 -0800 | [diff] [blame] | 41 | virtual void prepareAsync(); |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 42 | virtual void start(); |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 43 | |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 44 | virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit); |
Robert Shih | a83eebb | 2016-10-13 15:10:42 -0700 | [diff] [blame] | 45 | virtual sp<MetaData> getFormatMeta(bool audio); |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 46 | virtual sp<AMessage> getFormat(bool audio); |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 47 | |
Andreas Huber | 14f7672 | 2013-01-15 09:04:18 -0800 | [diff] [blame] | 48 | virtual status_t feedMoreTSData(); |
Andreas Huber | 43c3e6c | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 49 | virtual status_t getDuration(int64_t *durationUs); |
Chong Zhang | 404fced | 2014-06-11 14:45:31 -0700 | [diff] [blame] | 50 | virtual size_t getTrackCount() const; |
| 51 | virtual sp<AMessage> getTrackInfo(size_t trackIndex) const; |
Robert Shih | 89bf252 | 2014-07-29 19:25:10 -0700 | [diff] [blame] | 52 | virtual ssize_t getSelectedTrack(media_track_type /* type */) const; |
Robert Shih | 6ffb1fd | 2014-10-29 16:24:32 -0700 | [diff] [blame] | 53 | virtual status_t selectTrack(size_t trackIndex, bool select, int64_t timeUs); |
Wei Jia | c5de091 | 2016-11-18 10:22:14 -0800 | [diff] [blame] | 54 | virtual status_t seekTo( |
| 55 | int64_t seekTimeUs, |
| 56 | MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) override; |
Andreas Huber | b7c8e91 | 2012-11-27 15:02:53 -0800 | [diff] [blame] | 57 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 58 | protected: |
| 59 | virtual ~HTTPLiveSource(); |
| 60 | |
Andreas Huber | 0df36ec | 2013-02-06 10:44:39 -0800 | [diff] [blame] | 61 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 62 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 63 | private: |
Andreas Huber | ad0d9c9 | 2011-04-19 11:50:27 -0700 | [diff] [blame] | 64 | enum Flags { |
| 65 | // Don't log any URLs. |
| 66 | kFlagIncognito = 1, |
| 67 | }; |
| 68 | |
Andreas Huber | 0df36ec | 2013-02-06 10:44:39 -0800 | [diff] [blame] | 69 | enum { |
| 70 | kWhatSessionNotify, |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 71 | kWhatFetchSubtitleData, |
Robert Shih | 0852843 | 2015-04-08 09:06:54 -0700 | [diff] [blame] | 72 | kWhatFetchMetaData, |
Andreas Huber | 0df36ec | 2013-02-06 10:44:39 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 75 | sp<IMediaHTTPService> mHTTPService; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 76 | AString mURL; |
Andreas Huber | ad0d9c9 | 2011-04-19 11:50:27 -0700 | [diff] [blame] | 77 | KeyedVector<String8, String8> mExtraHeaders; |
Andreas Huber | 7314fa1 | 2011-02-24 14:42:48 -0800 | [diff] [blame] | 78 | uint32_t mFlags; |
Andreas Huber | eac68ba | 2011-09-27 12:12:25 -0700 | [diff] [blame] | 79 | status_t mFinalResult; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 80 | off64_t mOffset; |
| 81 | sp<ALooper> mLiveLooper; |
| 82 | sp<LiveSession> mLiveSession; |
Chong Zhang | dcb89b3 | 2013-08-06 09:44:47 -0700 | [diff] [blame] | 83 | int32_t mFetchSubtitleDataGeneration; |
Robert Shih | 0852843 | 2015-04-08 09:06:54 -0700 | [diff] [blame] | 84 | int32_t mFetchMetaDataGeneration; |
| 85 | bool mHasMetadata; |
| 86 | bool mMetadataSelected; |
Wei Jia | 48fa06d | 2016-12-20 15:30:49 -0800 | [diff] [blame] | 87 | BufferingSettings mBufferingSettings; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 88 | |
Andreas Huber | 0df36ec | 2013-02-06 10:44:39 -0800 | [diff] [blame] | 89 | void onSessionNotify(const sp<AMessage> &msg); |
Robert Shih | 0852843 | 2015-04-08 09:06:54 -0700 | [diff] [blame] | 90 | void pollForRawData( |
| 91 | const sp<AMessage> &msg, int32_t currentGeneration, |
| 92 | LiveSession::StreamType fetchType, int32_t pushWhat); |
Andreas Huber | 0df36ec | 2013-02-06 10:44:39 -0800 | [diff] [blame] | 93 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 94 | DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource); |
| 95 | }; |
| 96 | |
| 97 | } // namespace android |
| 98 | |
| 99 | #endif // HTTP_LIVE_SOURCE_H_ |