• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 namespace android {
27 
28 struct LiveSession;
29 
30 struct 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(int64_t seekTimeUs);
51 
52 protected:
53     virtual ~HTTPLiveSource();
54 
55     virtual void onMessageReceived(const sp<AMessage> &msg);
56 
57 private:
58     enum Flags {
59         // Don't log any URLs.
60         kFlagIncognito = 1,
61     };
62 
63     enum {
64         kWhatSessionNotify,
65         kWhatFetchSubtitleData,
66         kWhatFetchMetaData,
67     };
68 
69     sp<IMediaHTTPService> mHTTPService;
70     AString mURL;
71     KeyedVector<String8, String8> mExtraHeaders;
72     uint32_t mFlags;
73     status_t mFinalResult;
74     off64_t mOffset;
75     sp<ALooper> mLiveLooper;
76     sp<LiveSession> mLiveSession;
77     int32_t mFetchSubtitleDataGeneration;
78     int32_t mFetchMetaDataGeneration;
79     bool mHasMetadata;
80     bool mMetadataSelected;
81 
82     void onSessionNotify(const sp<AMessage> &msg);
83     void pollForRawData(
84             const sp<AMessage> &msg, int32_t currentGeneration,
85             LiveSession::StreamType fetchType, int32_t pushWhat);
86 
87     DISALLOW_EVIL_CONSTRUCTORS(HTTPLiveSource);
88 };
89 
90 }  // namespace android
91 
92 #endif  // HTTP_LIVE_SOURCE_H_
93