blob: 97d3653974215c6283b06c11b9ec9e36229ba58c [file] [log] [blame]
Wei Jia53692fa2017-12-11 10:33:46 -08001/*
2 * Copyright 2017 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
Wei Jia2409c872018-02-02 10:34:33 -080017#ifndef HTTP_LIVE_SOURCE2_H_
Wei Jia53692fa2017-12-11 10:33:46 -080018
Wei Jia2409c872018-02-02 10:34:33 -080019#define HTTP_LIVE_SOURCE2_H_
Wei Jia53692fa2017-12-11 10:33:46 -080020
21#include "NuPlayer2.h"
22#include "NuPlayer2Source.h"
23
24#include "LiveSession.h"
25
26namespace android {
27
28struct LiveSession;
29
Wei Jia2409c872018-02-02 10:34:33 -080030struct NuPlayer2::HTTPLiveSource2 : public NuPlayer2::Source {
31 HTTPLiveSource2(
Wei Jia53692fa2017-12-11 10:33:46 -080032 const sp<AMessage> &notify,
33 const sp<MediaHTTPService> &httpService,
34 const char *url,
35 const KeyedVector<String8, String8> *headers);
36
37 virtual status_t getBufferingSettings(
38 BufferingSettings* buffering /* nonnull */) override;
39 virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
40
41 virtual void prepareAsync();
42 virtual void start();
43
44 virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
45 virtual sp<MetaData> getFormatMeta(bool audio);
46 virtual sp<AMessage> getFormat(bool audio);
47
48 virtual status_t feedMoreTSData();
49 virtual status_t getDuration(int64_t *durationUs);
50 virtual size_t getTrackCount() const;
51 virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
52 virtual ssize_t getSelectedTrack(media_track_type /* type */) const;
53 virtual status_t selectTrack(size_t trackIndex, bool select, int64_t timeUs);
54 virtual status_t seekTo(
55 int64_t seekTimeUs,
56 MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) override;
57
58protected:
Wei Jia2409c872018-02-02 10:34:33 -080059 virtual ~HTTPLiveSource2();
Wei Jia53692fa2017-12-11 10:33:46 -080060
61 virtual void onMessageReceived(const sp<AMessage> &msg);
62
63private:
64 enum Flags {
65 // Don't log any URLs.
66 kFlagIncognito = 1,
67 };
68
69 enum {
70 kWhatSessionNotify,
71 kWhatFetchSubtitleData,
72 kWhatFetchMetaData,
73 };
74
75 sp<MediaHTTPService> mHTTPService;
76 AString mURL;
77 KeyedVector<String8, String8> mExtraHeaders;
78 uint32_t mFlags;
79 status_t mFinalResult;
80 off64_t mOffset;
81 sp<ALooper> mLiveLooper;
82 sp<LiveSession> mLiveSession;
83 int32_t mFetchSubtitleDataGeneration;
84 int32_t mFetchMetaDataGeneration;
85 bool mHasMetadata;
86 bool mMetadataSelected;
87 BufferingSettings mBufferingSettings;
88
89 void onSessionNotify(const sp<AMessage> &msg);
90 void pollForRawData(
91 const sp<AMessage> &msg, int32_t currentGeneration,
92 LiveSession::StreamType fetchType, int32_t pushWhat);
93
Wei Jia2409c872018-02-02 10:34:33 -080094 DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource2);
Wei Jia53692fa2017-12-11 10:33:46 -080095};
96
97} // namespace android
98
Wei Jia2409c872018-02-02 10:34:33 -080099#endif // HTTP_LIVE_SOURCE2_H_