• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #define LOG_TAG "BufferingSettings"
18 //#define LOG_NDEBUG 0
19 
20 #include <binder/Parcel.h>
21 
22 #include <media/BufferingSettings.h>
23 
24 namespace android {
25 
26 // static
IsValidBufferingMode(int mode)27 bool BufferingSettings::IsValidBufferingMode(int mode) {
28     return (mode >= BUFFERING_MODE_NONE && mode < BUFFERING_MODE_COUNT);
29 }
30 
31 // static
IsTimeBasedBufferingMode(int mode)32 bool BufferingSettings::IsTimeBasedBufferingMode(int mode) {
33     return (mode == BUFFERING_MODE_TIME_ONLY || mode == BUFFERING_MODE_TIME_THEN_SIZE);
34 }
35 
36 // static
IsSizeBasedBufferingMode(int mode)37 bool BufferingSettings::IsSizeBasedBufferingMode(int mode) {
38     return (mode == BUFFERING_MODE_SIZE_ONLY || mode == BUFFERING_MODE_TIME_THEN_SIZE);
39 }
40 
BufferingSettings()41 BufferingSettings::BufferingSettings()
42         : mInitialBufferingMode(BUFFERING_MODE_NONE),
43           mRebufferingMode(BUFFERING_MODE_NONE),
44           mInitialWatermarkMs(kNoWatermark),
45           mInitialWatermarkKB(kNoWatermark),
46           mRebufferingWatermarkLowMs(kNoWatermark),
47           mRebufferingWatermarkHighMs(kNoWatermark),
48           mRebufferingWatermarkLowKB(kNoWatermark),
49           mRebufferingWatermarkHighKB(kNoWatermark) { }
50 
readFromParcel(const Parcel * parcel)51 status_t BufferingSettings::readFromParcel(const Parcel* parcel) {
52     if (parcel == nullptr) {
53         return BAD_VALUE;
54     }
55     mInitialBufferingMode = (BufferingMode)parcel->readInt32();
56     mRebufferingMode = (BufferingMode)parcel->readInt32();
57     mInitialWatermarkMs = parcel->readInt32();
58     mInitialWatermarkKB = parcel->readInt32();
59     mRebufferingWatermarkLowMs = parcel->readInt32();
60     mRebufferingWatermarkHighMs = parcel->readInt32();
61     mRebufferingWatermarkLowKB = parcel->readInt32();
62     mRebufferingWatermarkHighKB = parcel->readInt32();
63 
64     return OK;
65 }
66 
writeToParcel(Parcel * parcel) const67 status_t BufferingSettings::writeToParcel(Parcel* parcel) const {
68     if (parcel == nullptr) {
69         return BAD_VALUE;
70     }
71     parcel->writeInt32(mInitialBufferingMode);
72     parcel->writeInt32(mRebufferingMode);
73     parcel->writeInt32(mInitialWatermarkMs);
74     parcel->writeInt32(mInitialWatermarkKB);
75     parcel->writeInt32(mRebufferingWatermarkLowMs);
76     parcel->writeInt32(mRebufferingWatermarkHighMs);
77     parcel->writeInt32(mRebufferingWatermarkLowKB);
78     parcel->writeInt32(mRebufferingWatermarkHighKB);
79 
80     return OK;
81 }
82 
toString() const83 String8 BufferingSettings::toString() const {
84     String8 s;
85     s.appendFormat("initialMode(%d), rebufferingMode(%d), "
86             "initialMarks(%d ms, %d KB), rebufferingMarks(%d, %d)ms, (%d, %d)KB",
87             mInitialBufferingMode, mRebufferingMode,
88             mInitialWatermarkMs, mInitialWatermarkKB,
89             mRebufferingWatermarkLowMs, mRebufferingWatermarkHighMs,
90             mRebufferingWatermarkLowKB, mRebufferingWatermarkHighKB);
91     return s;
92 }
93 
94 } // namespace android
95