blob: 00699560be2e5d462ad65fd8beb99f75050cd036 [file] [log] [blame]
Hugo Hudsonb83ad732011-07-14 23:31:17 +01001/*
2 * Copyright (C) 2011 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 <stdlib.h>
18#include <assert.h>
19
20#include <jni.h>
21#include <variablespeed.h>
22
23// Quick #define to make sure I get all the JNI method calls right.
24#define JNI_METHOD(x, y) \
25JNIEXPORT y JNICALL \
26Java_com_android_ex_variablespeed_VariableSpeedNative_##x
27
28class MethodLog {
29 public:
30 explicit MethodLog(const char* name) : name_(name) {
Hugo Hudson0bd6ec52011-07-26 20:05:25 +010031 LOGV("+ %s", name);
Hugo Hudsonb83ad732011-07-14 23:31:17 +010032 }
33 virtual ~MethodLog() {
Hugo Hudson0bd6ec52011-07-26 20:05:25 +010034 LOGV("- %s", name_);
Hugo Hudsonb83ad732011-07-14 23:31:17 +010035 }
36
37 private:
38 const char* name_;
39};
40
41extern "C" {
42JNI_METHOD(playFileDescriptor, void) (JNIEnv*, jclass, int fd, jlong offset,
43 jlong length) {
44 MethodLog _("playFileDescriptor");
45 AudioEngine::GetEngine()->PlayFileDescriptor(fd, offset, length);
46}
47
48JNI_METHOD(playUri, void) (JNIEnv* env, jclass, jstring uri) {
49 MethodLog _("playUri");
50 const char* utf8 = env->GetStringUTFChars(uri, NULL);
51 CHECK(NULL != utf8);
52 AudioEngine::GetEngine()->PlayUri(utf8);
53}
54
55JNI_METHOD(setVariableSpeed, void) (JNIEnv*, jclass, float speed) {
56 MethodLog _("setVariableSpeed");
57 AudioEngine::GetEngine()->SetVariableSpeed(speed);
58}
59
60JNI_METHOD(startPlayback, void) (JNIEnv*, jclass) {
61 MethodLog _("startPlayback");
62 AudioEngine::GetEngine()->RequestStart();
63}
64
65JNI_METHOD(stopPlayback, void) (JNIEnv*, jclass) {
66 MethodLog _("stopPlayback");
67 AudioEngine::GetEngine()->RequestStop();
68}
69
70JNI_METHOD(getCurrentPosition, int) (JNIEnv*, jclass) {
Hugo Hudsonb83ad732011-07-14 23:31:17 +010071 return AudioEngine::GetEngine()->GetCurrentPosition();
72}
73
74JNI_METHOD(getTotalDuration, int) (JNIEnv*, jclass) {
Hugo Hudsonb83ad732011-07-14 23:31:17 +010075 return AudioEngine::GetEngine()->GetTotalDuration();
76}
77
Hugo Hudson0bd6ec52011-07-26 20:05:25 +010078JNI_METHOD(initializeEngine, void) (JNIEnv*, jclass,
79 int targetFrames, float windowDuration,
Hugo Hudsonb83ad732011-07-14 23:31:17 +010080 float windowOverlapDuration, size_t maxPlayBufferCount,
81 float initialRate, size_t decodeInitialSize, size_t decodeMaxSize,
82 size_t startPositionMillis) {
83 MethodLog _("initializeEngine");
Hugo Hudson0bd6ec52011-07-26 20:05:25 +010084 AudioEngine::SetEngine(new AudioEngine(targetFrames,
Hugo Hudsonb83ad732011-07-14 23:31:17 +010085 windowDuration, windowOverlapDuration, maxPlayBufferCount, initialRate,
86 decodeInitialSize, decodeMaxSize, startPositionMillis));
87}
88
89JNI_METHOD(shutdownEngine, void) (JNIEnv*, jclass) {
90 MethodLog _("shutdownEngine");
91 AudioEngine::DeleteEngine();
92}
93} // extern "C"