midi_input_port_android.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_MIDI_MIDI_INPUT_PORT_ANDROID_H_
  5. #define MEDIA_MIDI_MIDI_INPUT_PORT_ANDROID_H_
  6. #include <jni.h>
  7. #include <stddef.h>
  8. #include <stdint.h>
  9. #include "base/android/scoped_java_ref.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/time/time.h"
  12. namespace midi {
  13. class MidiInputPortAndroid final {
  14. public:
  15. class Delegate {
  16. public:
  17. virtual ~Delegate() {}
  18. virtual void OnReceivedData(MidiInputPortAndroid* port,
  19. const uint8_t* data,
  20. size_t size,
  21. base::TimeTicks time) = 0;
  22. };
  23. MidiInputPortAndroid(JNIEnv* env, jobject raw, Delegate* delegate);
  24. ~MidiInputPortAndroid();
  25. // Returns true when the operation succeeds.
  26. bool Open();
  27. void Close();
  28. // Called by the Java world.
  29. void OnData(JNIEnv* env,
  30. const base::android::JavaParamRef<jbyteArray>& data,
  31. jint offset,
  32. jint size,
  33. jlong timestamp);
  34. private:
  35. base::android::ScopedJavaGlobalRef<jobject> raw_port_;
  36. const raw_ptr<Delegate> delegate_;
  37. };
  38. } // namespace midi
  39. #endif // MEDIA_MIDI_MIDI_INPUT_PORT_ANDROID_H_