• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, 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 _ANDROID_MEDIA_BUFFERING_PARAMS_H_
18 #define _ANDROID_MEDIA_BUFFERING_PARAMS_H_
19 
20 #include <media/BufferingSettings.h>
21 
22 namespace android {
23 
24 // This entire class is inline
25 struct BufferingParams {
26     BufferingSettings settings;
27 
28     struct fields_t {
29         jclass      clazz;
30         jmethodID   constructID;
31 
32         jfieldID    initial_buffering_mode;
33         jfieldID    rebuffering_mode;
34         jfieldID    initial_watermark_ms;
35         jfieldID    initial_watermark_kb;
36         jfieldID    rebuffering_watermark_low_ms;
37         jfieldID    rebuffering_watermark_high_ms;
38         jfieldID    rebuffering_watermark_low_kb;
39         jfieldID    rebuffering_watermark_high_kb;
40 
initBufferingParams::fields_t41         void init(JNIEnv *env) {
42             jclass lclazz = env->FindClass("android/media/BufferingParams");
43             if (lclazz == NULL) {
44                 return;
45             }
46 
47             clazz = (jclass)env->NewGlobalRef(lclazz);
48             if (clazz == NULL) {
49                 return;
50             }
51 
52             constructID = env->GetMethodID(clazz, "<init>", "()V");
53 
54             initial_buffering_mode = env->GetFieldID(clazz, "mInitialBufferingMode", "I");
55             rebuffering_mode = env->GetFieldID(clazz, "mRebufferingMode", "I");
56             initial_watermark_ms = env->GetFieldID(clazz, "mInitialWatermarkMs", "I");
57             initial_watermark_kb = env->GetFieldID(clazz, "mInitialWatermarkKB", "I");
58             rebuffering_watermark_low_ms = env->GetFieldID(clazz, "mRebufferingWatermarkLowMs", "I");
59             rebuffering_watermark_high_ms = env->GetFieldID(clazz, "mRebufferingWatermarkHighMs", "I");
60             rebuffering_watermark_low_kb = env->GetFieldID(clazz, "mRebufferingWatermarkLowKB", "I");
61             rebuffering_watermark_high_kb = env->GetFieldID(clazz, "mRebufferingWatermarkHighKB", "I");
62 
63             env->DeleteLocalRef(lclazz);
64         }
65 
exitBufferingParams::fields_t66         void exit(JNIEnv *env) {
67             env->DeleteGlobalRef(clazz);
68             clazz = NULL;
69         }
70     };
71 
fillFromJobjectBufferingParams72     void fillFromJobject(JNIEnv *env, const fields_t& fields, jobject params) {
73         settings.mInitialBufferingMode =
74             (BufferingMode)env->GetIntField(params, fields.initial_buffering_mode);
75         settings.mRebufferingMode =
76             (BufferingMode)env->GetIntField(params, fields.rebuffering_mode);
77         settings.mInitialWatermarkMs =
78             env->GetIntField(params, fields.initial_watermark_ms);
79         settings.mInitialWatermarkKB =
80             env->GetIntField(params, fields.initial_watermark_kb);
81         settings.mRebufferingWatermarkLowMs =
82             env->GetIntField(params, fields.rebuffering_watermark_low_ms);
83         settings.mRebufferingWatermarkHighMs =
84             env->GetIntField(params, fields.rebuffering_watermark_high_ms);
85         settings.mRebufferingWatermarkLowKB =
86             env->GetIntField(params, fields.rebuffering_watermark_low_kb);
87         settings.mRebufferingWatermarkHighKB =
88             env->GetIntField(params, fields.rebuffering_watermark_high_kb);
89     }
90 
asJobjectBufferingParams91     jobject asJobject(JNIEnv *env, const fields_t& fields) {
92         jobject params = env->NewObject(fields.clazz, fields.constructID);
93         if (params == NULL) {
94             return NULL;
95         }
96         env->SetIntField(params, fields.initial_buffering_mode, (jint)settings.mInitialBufferingMode);
97         env->SetIntField(params, fields.rebuffering_mode, (jint)settings.mRebufferingMode);
98         env->SetIntField(params, fields.initial_watermark_ms, (jint)settings.mInitialWatermarkMs);
99         env->SetIntField(params, fields.initial_watermark_kb, (jint)settings.mInitialWatermarkKB);
100         env->SetIntField(params, fields.rebuffering_watermark_low_ms, (jint)settings.mRebufferingWatermarkLowMs);
101         env->SetIntField(params, fields.rebuffering_watermark_high_ms, (jint)settings.mRebufferingWatermarkHighMs);
102         env->SetIntField(params, fields.rebuffering_watermark_low_kb, (jint)settings.mRebufferingWatermarkLowKB);
103         env->SetIntField(params, fields.rebuffering_watermark_high_kb, (jint)settings.mRebufferingWatermarkHighKB);
104 
105         return params;
106     }
107 };
108 
109 }  // namespace android
110 
111 #endif  // _ANDROID_MEDIA_BUFFERING_PARAMS_H_
112