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
24#include "LiveSession.h"
25
26namespace android {
27
28struct LiveSession;
29
30struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
31    HTTPLiveSource(
32            const sp<AMessage> &notify,
33            const sp<IMediaHTTPService> &httpService,
34            const char *url,
35            const KeyedVector<String8, String8> *headers);
36
37    virtual status_t getDefaultBufferingSettings(
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            MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) override;
57
58protected:
59    virtual ~HTTPLiveSource();
60
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<IMediaHTTPService> 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
94    DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource);
95};
96
97}  // namespace android
98
99#endif  // HTTP_LIVE_SOURCE_H_
100