HTTPLiveSource.h revision c5de09127e9e0d5df7aa587be317e1487d793245
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 void prepareAsync();
38    virtual void start();
39
40    virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
41    virtual sp<MetaData> getFormatMeta(bool audio);
42    virtual sp<AMessage> getFormat(bool audio);
43
44    virtual status_t feedMoreTSData();
45    virtual status_t getDuration(int64_t *durationUs);
46    virtual size_t getTrackCount() const;
47    virtual sp<AMessage> getTrackInfo(size_t trackIndex) const;
48    virtual ssize_t getSelectedTrack(media_track_type /* type */) const;
49    virtual status_t selectTrack(size_t trackIndex, bool select, int64_t timeUs);
50    virtual status_t seekTo(
51            int64_t seekTimeUs,
52            MediaPlayerSeekMode mode = MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC) override;
53
54protected:
55    virtual ~HTTPLiveSource();
56
57    virtual void onMessageReceived(const sp<AMessage> &msg);
58
59private:
60    enum Flags {
61        // Don't log any URLs.
62        kFlagIncognito = 1,
63    };
64
65    enum {
66        kWhatSessionNotify,
67        kWhatFetchSubtitleData,
68        kWhatFetchMetaData,
69    };
70
71    sp<IMediaHTTPService> mHTTPService;
72    AString mURL;
73    KeyedVector<String8, String8> mExtraHeaders;
74    uint32_t mFlags;
75    status_t mFinalResult;
76    off64_t mOffset;
77    sp<ALooper> mLiveLooper;
78    sp<LiveSession> mLiveSession;
79    int32_t mFetchSubtitleDataGeneration;
80    int32_t mFetchMetaDataGeneration;
81    bool mHasMetadata;
82    bool mMetadataSelected;
83
84    void onSessionNotify(const sp<AMessage> &msg);
85    void pollForRawData(
86            const sp<AMessage> &msg, int32_t currentGeneration,
87            LiveSession::StreamType fetchType, int32_t pushWhat);
88
89    DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource);
90};
91
92}  // namespace android
93
94#endif  // HTTP_LIVE_SOURCE_H_
95