Skip to content

Commit b36765f

Browse files
committed
chore: for android.
1 parent 77ed9d6 commit b36765f

File tree

9 files changed

+108
-58
lines changed

9 files changed

+108
-58
lines changed

sdk/android/api/org/webrtc/FrameCryptor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
public class FrameCryptor {
2222

23-
public enum FrameCryptorErrorState {
23+
public enum FrameCryptionState {
2424
NEW,
2525
OK,
2626
ENCRYPTIONFAILED,
2727
DECRYPTIONFAILED,
2828
MISSINGKEY,
29+
KEYRATCHETED,
2930
INTERNALERROR;
3031

31-
@CalledByNative("FrameCryptorErrorState")
32-
static FrameCryptorErrorState fromNativeIndex(int nativeIndex) {
32+
@CalledByNative("FrameCryptionState")
33+
static FrameCryptionState fromNativeIndex(int nativeIndex) {
3334
return values()[nativeIndex];
3435
}
3536
}
3637

3738
public static interface Observer {
3839
@CalledByNative("Observer")
39-
void onFrameCryptorErrorState(String participantId, FrameCryptorErrorState newState);
40+
void onFrameCryptionStateChanged(String participantId, FrameCryptionState newState);
4041
}
4142

4243
private long nativeFrameCryptor;

sdk/android/api/org/webrtc/FrameCryptorFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.webrtc;
1818

1919
public class FrameCryptorFactory {
20-
public static FrameCryptorKeyManager createFrameCryptorKeyManager() {
21-
return nativeCreateFrameCryptorKeyManager();
20+
public static FrameCryptorKeyManager createFrameCryptorKeyManager(boolean sharedKey, byte[] ratchetSalt, int ratchetWindowSize) {
21+
return nativeCreateFrameCryptorKeyManager(sharedKey, ratchetSalt, ratchetWindowSize);
2222
}
2323

2424
public static FrameCryptor createFrameCryptorForRtpSender(RtpSender rtpSender,
@@ -38,5 +38,5 @@ private static native FrameCryptor nativeCreateFrameCryptorForRtpSender(
3838
private static native FrameCryptor nativeCreateFrameCryptorForRtpReceiver(
3939
long rtpReceiver, String participantId, int algorithm, long nativeFrameCryptorKeyManager);
4040

41-
private static native FrameCryptorKeyManager nativeCreateFrameCryptorKeyManager();
41+
private static native FrameCryptorKeyManager nativeCreateFrameCryptorKeyManager(boolean sharedKey, byte[] ratchetSalt, int ratchetWindowSize);
4242
}

sdk/android/api/org/webrtc/FrameCryptorKeyManager.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ public boolean setKey(String participantId, int index, byte[] key) {
3434
return nativeSetKey(nativeKeyManager, participantId, index, key);
3535
}
3636

37-
public boolean setKeys(String participantId, ArrayList<byte[]> keys) {
38-
return nativeSetKeys(nativeKeyManager, participantId, keys);
39-
}
40-
41-
public ArrayList<byte[]> getKeys(String participantId) {
42-
return nativeGetKeys(nativeKeyManager, participantId);
37+
public byte[] ratchetKey(String participantId, int index) {
38+
return nativeRatchetKey(nativeKeyManager, participantId, index);
4339
}
4440

4541
public void dispose() {
@@ -53,12 +49,9 @@ private void checkKeyManagerExists() {
5349
throw new IllegalStateException("FrameCryptorKeyManager has been disposed.");
5450
}
5551
}
56-
57-
private static native long createNativeKeyManager();
52+
5853
private static native boolean nativeSetKey(
5954
long keyManagerPointer, String participantId, int index, byte[] key);
60-
private static native boolean nativeSetKeys(
61-
long keyManagerPointer, String participantId, ArrayList<byte[]> keys);
62-
private static native ArrayList<byte[]> nativeGetKeys(
63-
long keyManagerPointer, String participantId);
55+
private static native byte[] nativeRatchetKey(
56+
long keyManagerPointer, String participantId, int index);
6457
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
package org.webrtc;
12+
13+
public class OpenH264Decoder extends WrappedNativeVideoDecoder {
14+
@Override
15+
public long createNativeVideoDecoder() {
16+
return nativeCreateDecoder();
17+
}
18+
19+
static native long nativeCreateDecoder();
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
package org.webrtc;
12+
13+
public class OpenH264Encoder extends WrappedNativeVideoEncoder {
14+
@Override
15+
public long createNativeVideoEncoder() {
16+
return nativeCreateEncoder();
17+
}
18+
19+
static native long nativeCreateEncoder();
20+
21+
@Override
22+
public boolean isHardwareEncoder() {
23+
return false;
24+
}
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
#include <jni.h>
12+
13+
#include "modules/video_coding/codecs/h264/include/h264.h"
14+
#include "sdk/android/generated_open_h264_jni/OpenH264Decoder_jni.h"
15+
#include "sdk/android/generated_open_h264_jni/OpenH264Encoder_jni.h"
16+
#include "sdk/android/src/jni/jni_helpers.h"
17+
18+
namespace webrtc {
19+
namespace jni {
20+
21+
static jlong JNI_OpenH264Encoder_CreateEncoder(JNIEnv* jni) {
22+
return jlongFromPointer(H264Encoder::Create(cricket::VideoCodec("H264")).release());
23+
}
24+
25+
static jlong JNI_OpenH264Decoder_CreateDecoder(JNIEnv* jni) {
26+
return jlongFromPointer(H264Decoder::Create().release());
27+
}
28+
29+
} // namespace jni
30+
} // namespace webrtc

sdk/android/src/jni/pc/frame_cryptor.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ FrameCryptorObserverJni::FrameCryptorObserverJni(
3434

3535
FrameCryptorObserverJni::~FrameCryptorObserverJni() {}
3636

37-
void FrameCryptorObserverJni::OnFrameCryptionError(
37+
void FrameCryptorObserverJni::OnFrameCryptionStateChanged(
3838
const std::string participant_id,
39-
FrameCryptionError new_state) {
39+
FrameCryptionState new_state) {
4040
JNIEnv* env = AttachCurrentThreadIfNeeded();
41-
Java_Observer_onFrameCryptorErrorState(
41+
Java_Observer_onFrameCryptionStateChanged(
4242
env, j_observer_global_, NativeToJavaString(env, participant_id),
43-
Java_FrameCryptorErrorState_fromNativeIndex(env, new_state));
43+
Java_FrameCryptionState_fromNativeIndex(env, new_state));
4444
}
4545

4646
ScopedJavaLocalRef<jobject> NativeToJavaFrameCryptor(
@@ -163,9 +163,15 @@ JNI_FrameCryptorFactory_CreateFrameCryptorForRtpSender(
163163
}
164164

165165
static base::android::ScopedJavaLocalRef<jobject>
166-
JNI_FrameCryptorFactory_CreateFrameCryptorKeyManager(JNIEnv* env) {
166+
JNI_FrameCryptorFactory_CreateFrameCryptorKeyManager(JNIEnv* env, jboolean j_shared,
167+
const base::android::JavaParamRef<jbyteArray>& j_ratchetSalt, jint j_ratchetWindowSize) {
168+
auto ratchetSalt = JavaToNativeByteArray(env, j_ratchetSalt);
169+
KeyProviderOptions options;
170+
options.ratchet_salt = std::vector<uint8_t>(ratchetSalt.begin(), ratchetSalt.end());
171+
options.ratchet_window_size = j_ratchetWindowSize;
172+
options.shared_key = j_shared;
167173
return NativeToJavaFrameCryptorKeyManager(
168-
env, rtc::make_ref_counted<webrtc::DefaultKeyManagerImpl>());
174+
env, rtc::make_ref_counted<webrtc::DefaultKeyManagerImpl>(options));
169175
}
170176

171177
} // namespace jni

sdk/android/src/jni/pc/frame_cryptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class FrameCryptorObserverJni : public FrameCryptorTransformerObserver, public r
3535
~FrameCryptorObserverJni() override;
3636

3737
protected:
38-
void OnFrameCryptionError(const std::string participant_id,
39-
FrameCryptionError error) override;
38+
void OnFrameCryptionStateChanged(const std::string participant_id,
39+
FrameCryptionState state) override;
4040

4141
private:
4242
const ScopedJavaGlobalRef<jobject> j_observer_global_;

sdk/android/src/jni/pc/frame_cryptor_key_manager.cc

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,18 @@ static jboolean JNI_FrameCryptorKeyManager_SetKey(
4646
std::vector<uint8_t>(key.begin(), key.end()));
4747
}
4848

49-
static jboolean JNI_FrameCryptorKeyManager_SetKeys(
49+
static base::android::ScopedJavaLocalRef<jbyteArray> JNI_FrameCryptorKeyManager_RatchetKey(
5050
JNIEnv* env,
5151
jlong keyManagerPointer,
5252
const base::android::JavaParamRef<jstring>& participantId,
53-
const base::android::JavaParamRef<jobject>& keys) {
53+
jint j_index) {
5454
auto participant_id = JavaToStdString(env, participantId);
5555
auto key_manager =
5656
reinterpret_cast<webrtc::DefaultKeyManagerImpl*>(keyManagerPointer);
57-
auto keys_size = env->GetArrayLength((jobjectArray)keys.obj());
58-
std::vector<std::vector<uint8_t>> keys_vector;
59-
for (int i = 0; i < keys_size; i++) {
60-
auto key = JavaToNativeByteArray(
61-
env, base::android::JavaParamRef<jbyteArray>(
62-
env, (jbyteArray)env->GetObjectArrayElement(
63-
(jobjectArray)keys.obj(), i)));
64-
keys_vector.push_back(std::vector<uint8_t>(key.begin(), key.end()));
65-
}
66-
return key_manager->SetKeys(participant_id, keys_vector);
57+
auto newKey = key_manager->RatchetKey(participant_id, j_index);
58+
std::vector<int8_t> int8tKey =
59+
std::vector<int8_t>(newKey.begin(), newKey.end());
60+
return NativeToJavaByteArray(env, rtc::ArrayView<int8_t>(int8tKey));
6761
}
68-
69-
static ScopedJavaLocalRef<jobject> JNI_FrameCryptorKeyManager_GetKeys(
70-
JNIEnv* jni,
71-
jlong j_key_manager,
72-
const base::android::JavaParamRef<jstring>& participantId) {
73-
auto participant_id = JavaToStdString(jni, participantId);
74-
auto keys = reinterpret_cast<webrtc::DefaultKeyManagerImpl*>(j_key_manager)
75-
->keys(participant_id);
76-
JavaListBuilder j_keys(jni);
77-
for (size_t i = 0; i < keys.size(); i++) {
78-
auto uint8Key = keys[i];
79-
std::vector<int8_t> int8tKey =
80-
std::vector<int8_t>(uint8Key.begin(), uint8Key.end());
81-
auto j_key = NativeToJavaByteArray(jni, rtc::ArrayView<int8_t>(int8tKey));
82-
j_keys.add(j_key);
83-
}
84-
return j_keys.java_list();
85-
}
86-
8762
} // namespace jni
8863
} // namespace webrtc

0 commit comments

Comments
 (0)