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 STREAMING_SOURCE_H_
18 
19 #define STREAMING_SOURCE_H_
20 
21 #include "NuPlayer.h"
22 #include "NuPlayerSource.h"
23 
24 namespace android {
25 
26 struct ABuffer;
27 struct ATSParser;
28 struct AnotherPacketSource;
29 
30 struct NuPlayer::StreamingSource : public NuPlayer::Source {
31     StreamingSource(
32             const sp<AMessage> &notify,
33             const sp<IStreamSource> &source);
34 
35     virtual status_t getBufferingSettings(
36             BufferingSettings* buffering /* nonnull */) override;
37     virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
38 
39     virtual void prepareAsync();
40     virtual void start();
41 
42     virtual status_t feedMoreTSData();
43 
44     virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
45 
46     virtual bool isRealTime() const;
47 
48 protected:
49     virtual ~StreamingSource();
50 
51     virtual void onMessageReceived(const sp<AMessage> &msg);
52 
53     virtual sp<AMessage> getFormat(bool audio);
54 
55 private:
56     enum {
57         kWhatReadBuffer,
58     };
59     sp<IStreamSource> mSource;
60     status_t mFinalResult;
61     sp<NuPlayerStreamListener> mStreamListener;
62     sp<ATSParser> mTSParser;
63 
64     bool mBuffering;
65     Mutex mBufferingLock;
66     sp<ALooper> mLooper;
67 
68     void setError(status_t err);
69     sp<AnotherPacketSource> getSource(bool audio);
70     bool haveSufficientDataOnAllTracks();
71     status_t postReadBuffer();
72     void onReadBuffer();
73 
74     DISALLOW_EVIL_CONSTRUCTORS(StreamingSource);
75 };
76 
77 }  // namespace android
78 
79 #endif  // STREAMING_SOURCE_H_
80