blob: b0046720174bc0e572a2ae0c8a78dc53adc5dd2b [file] [log] [blame]
Wei Jia23dfee52017-01-16 10:18:15 -08001/*
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
22namespace android {
23
24// This entire class is inline
25struct BufferingParams {
26 BufferingSettings settings;
27
28 struct fields_t {
29 jclass clazz;
30 jmethodID constructID;
31
Wei Jia49ca7252017-03-10 09:52:26 -080032 jfieldID initial_mark_ms;
33 jfieldID resume_playback_mark_ms;
Wei Jia23dfee52017-01-16 10:18:15 -080034
35 void init(JNIEnv *env) {
36 jclass lclazz = env->FindClass("android/media/BufferingParams");
37 if (lclazz == NULL) {
38 return;
39 }
40
41 clazz = (jclass)env->NewGlobalRef(lclazz);
42 if (clazz == NULL) {
43 return;
44 }
45
46 constructID = env->GetMethodID(clazz, "<init>", "()V");
47
Wei Jia49ca7252017-03-10 09:52:26 -080048 initial_mark_ms = env->GetFieldID(clazz, "mInitialMarkMs", "I");
49 resume_playback_mark_ms = env->GetFieldID(clazz, "mResumePlaybackMarkMs", "I");
Wei Jia23dfee52017-01-16 10:18:15 -080050
51 env->DeleteLocalRef(lclazz);
52 }
53
54 void exit(JNIEnv *env) {
55 env->DeleteGlobalRef(clazz);
56 clazz = NULL;
57 }
58 };
59
60 void fillFromJobject(JNIEnv *env, const fields_t& fields, jobject params) {
Wei Jia49ca7252017-03-10 09:52:26 -080061 settings.mInitialMarkMs =
62 env->GetIntField(params, fields.initial_mark_ms);
63 settings.mResumePlaybackMarkMs =
64 env->GetIntField(params, fields.resume_playback_mark_ms);
Wei Jia23dfee52017-01-16 10:18:15 -080065 }
66
67 jobject asJobject(JNIEnv *env, const fields_t& fields) {
68 jobject params = env->NewObject(fields.clazz, fields.constructID);
69 if (params == NULL) {
70 return NULL;
71 }
Wei Jia49ca7252017-03-10 09:52:26 -080072 env->SetIntField(params, fields.initial_mark_ms, (jint)settings.mInitialMarkMs);
73 env->SetIntField(params, fields.resume_playback_mark_ms, (jint)settings.mResumePlaybackMarkMs);
Wei Jia23dfee52017-01-16 10:18:15 -080074
75 return params;
76 }
77};
78
79} // namespace android
80
81#endif // _ANDROID_MEDIA_BUFFERING_PARAMS_H_