1 /*
2 * Copyright 2015, 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 #include "android_media_SyncParams.h"
18
19 #include <nativehelper/JNIHelp.h>
20
21 namespace android {
22
init(JNIEnv * env)23 void SyncParams::fields_t::init(JNIEnv *env) {
24 jclass lclazz = env->FindClass("android/media/SyncParams");
25 if (lclazz == NULL) {
26 return;
27 }
28
29 clazz = (jclass)env->NewGlobalRef(lclazz);
30 if (clazz == NULL) {
31 return;
32 }
33
34 constructID = env->GetMethodID(clazz, "<init>", "()V");
35
36 sync_source = env->GetFieldID(clazz, "mSyncSource", "I");
37 audio_adjust_mode = env->GetFieldID(clazz, "mAudioAdjustMode", "I");
38 tolerance = env->GetFieldID(clazz, "mTolerance", "F");
39 frame_rate = env->GetFieldID(clazz, "mFrameRate", "F");
40 set = env->GetFieldID(clazz, "mSet", "I");
41
42 set_sync_source =
43 env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "SET_SYNC_SOURCE", "I"));
44 set_audio_adjust_mode = env->GetStaticIntField(
45 clazz, env->GetStaticFieldID(clazz, "SET_AUDIO_ADJUST_MODE", "I"));
46 set_tolerance =
47 env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "SET_TOLERANCE", "I"));
48 set_frame_rate =
49 env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "SET_FRAME_RATE", "I"));
50
51 env->DeleteLocalRef(lclazz);
52 }
53
exit(JNIEnv * env)54 void SyncParams::fields_t::exit(JNIEnv *env) {
55 env->DeleteGlobalRef(clazz);
56 clazz = NULL;
57 }
58
fillFromJobject(JNIEnv * env,const fields_t & fields,jobject params)59 void SyncParams::fillFromJobject(JNIEnv *env, const fields_t& fields, jobject params) {
60 sync.mSource = (AVSyncSource)env->GetIntField(params, fields.sync_source);
61 sync.mAudioAdjustMode = (AVSyncAudioAdjustMode)env->GetIntField(params, fields.audio_adjust_mode);
62 sync.mTolerance = env->GetFloatField(params, fields.tolerance);
63 frameRate = env->GetFloatField(params, fields.frame_rate);
64 int set = env->GetIntField(params, fields.set);
65
66 syncSourceSet = set & fields.set_sync_source;
67 audioAdjustModeSet = set & fields.set_audio_adjust_mode;
68 toleranceSet = set & fields.set_tolerance;
69 frameRateSet = set & fields.set_frame_rate;
70 }
71
asJobject(JNIEnv * env,const fields_t & fields)72 jobject SyncParams::asJobject(JNIEnv *env, const fields_t& fields) {
73 jobject params = env->NewObject(fields.clazz, fields.constructID);
74 if (params == NULL) {
75 return NULL;
76 }
77 env->SetIntField(params, fields.sync_source, (jint)sync.mSource);
78 env->SetIntField(params, fields.audio_adjust_mode, (jint)sync.mAudioAdjustMode);
79 env->SetFloatField(params, fields.tolerance, (jfloat)sync.mTolerance);
80 env->SetFloatField(params, fields.frame_rate, (jfloat)frameRate);
81 env->SetIntField(
82 params, fields.set,
83 (syncSourceSet ? fields.set_sync_source : 0)
84 | (audioAdjustModeSet ? fields.set_audio_adjust_mode : 0)
85 | (toleranceSet ? fields.set_tolerance : 0)
86 | (frameRateSet ? fields.set_frame_rate : 0));
87
88 return params;
89 }
90
91 } // namespace android
92