blob: c55835222086d7a97a42cf052bc4080494c4afca [file] [log] [blame]
François Gaffieb4691282018-07-09 13:07:32 +02001/*
2 * Copyright (C) 2018 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#pragma once
18
19#include "jni.h"
20
21#include <memory.h>
22
23#include <system/audio.h>
24
25namespace android {
26
27class JNIAudioAttributeHelper
28{
29public:
30 using UniqueAaPtr = std::unique_ptr<audio_attributes_t, decltype(free)*>;
31
32 /**
33 * @brief makeUnique helper to prevent leak
34 * @return a unique ptr of 0-initialized native audio attributes structure
35 */
36 static UniqueAaPtr makeUnique();
37
38 /**
39 * @brief nativeFromJava Gets the underlying AudioAttributes from an AudioAttributes Java
40 * object.
41 * @param env
42 * @param jAudioAttributes JAVA AudioAttribute object
43 * @param paa native AudioAttribute pointer
44 * @return AUDIO_JAVA_SUCCESS on success, error code otherwise
45 */
46 static jint nativeFromJava(
47 JNIEnv* env, jobject jAudioAttributes, audio_attributes_t *attributes);
48
49 /**
50 * @brief nativeToJava AudioAttributes Java object from a native AudioAttributes.
51 * @param env
52 * @param jAudioAttributes JAVA AudioAttribute object
53 * @param attributes native AudioAttribute
54 * @return AUDIO_JAVA_SUCCESS on success, error code otherwise
55 */
56 static jint nativeToJava(
57 JNIEnv* env, jobject *jAudioAttributes, const audio_attributes_t &attributes);
58
59 /**
60 * @brief getJavaArray: creates an array of JAVA AudioAttributes objects
61 * @param env
62 * @param jAudioAttributeArray
63 * @param numAudioAttributes
64 * @return Array of AudioAttributes objects
65 */
66 static jint getJavaArray(
67 JNIEnv* env, jobjectArray *jAudioAttributeArray, jint numAudioAttributes);
68};
69
70}; // namespace android