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