| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/session/audio_focus_delegate_android.h" | 5 #include "content/browser/media/session/audio_focus_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | |
| 8 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 9 #include "content/browser/media/session/media_session_impl.h" | 8 #include "content/browser/media/session/media_session_impl.h" |
| 10 #include "jni/AudioFocusDelegate_jni.h" | 9 #include "jni/AudioFocusDelegate_jni.h" |
| 11 | 10 |
| 12 using base::android::JavaParamRef; | 11 using base::android::JavaParamRef; |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 // static | 15 // static |
| 17 bool AudioFocusDelegateAndroid::Register(JNIEnv* env) { | 16 bool AudioFocusDelegateAndroid::Register(JNIEnv* env) { |
| 18 return RegisterNativesImpl(env); | 17 return RegisterNativesImpl(env); |
| 19 } | 18 } |
| 20 | 19 |
| 21 AudioFocusDelegateAndroid::AudioFocusDelegateAndroid( | 20 AudioFocusDelegateAndroid::AudioFocusDelegateAndroid( |
| 22 MediaSessionImpl* media_session) | 21 MediaSessionImpl* media_session) |
| 23 : media_session_(media_session) {} | 22 : media_session_(media_session) {} |
| 24 | 23 |
| 25 AudioFocusDelegateAndroid::~AudioFocusDelegateAndroid() { | 24 AudioFocusDelegateAndroid::~AudioFocusDelegateAndroid() { |
| 26 JNIEnv* env = base::android::AttachCurrentThread(); | 25 JNIEnv* env = base::android::AttachCurrentThread(); |
| 27 DCHECK(env); | 26 DCHECK(env); |
| 28 Java_AudioFocusDelegate_tearDown(env, j_media_session_delegate_); | 27 Java_AudioFocusDelegate_tearDown(env, j_media_session_delegate_); |
| 29 } | 28 } |
| 30 | 29 |
| 31 void AudioFocusDelegateAndroid::Initialize() { | 30 void AudioFocusDelegateAndroid::Initialize() { |
| 32 JNIEnv* env = base::android::AttachCurrentThread(); | 31 JNIEnv* env = base::android::AttachCurrentThread(); |
| 33 DCHECK(env); | 32 DCHECK(env); |
| 34 j_media_session_delegate_.Reset(Java_AudioFocusDelegate_create( | 33 j_media_session_delegate_.Reset( |
| 35 env, base::android::GetApplicationContext(), | 34 Java_AudioFocusDelegate_create(env, reinterpret_cast<intptr_t>(this))); |
| 36 reinterpret_cast<intptr_t>(this))); | |
| 37 } | 35 } |
| 38 | 36 |
| 39 bool AudioFocusDelegateAndroid::RequestAudioFocus( | 37 bool AudioFocusDelegateAndroid::RequestAudioFocus( |
| 40 AudioFocusManager::AudioFocusType audio_focus_type) { | 38 AudioFocusManager::AudioFocusType audio_focus_type) { |
| 41 JNIEnv* env = base::android::AttachCurrentThread(); | 39 JNIEnv* env = base::android::AttachCurrentThread(); |
| 42 DCHECK(env); | 40 DCHECK(env); |
| 43 return Java_AudioFocusDelegate_requestAudioFocus( | 41 return Java_AudioFocusDelegate_requestAudioFocus( |
| 44 env, j_media_session_delegate_, | 42 env, j_media_session_delegate_, |
| 45 audio_focus_type == | 43 audio_focus_type == |
| 46 AudioFocusManager::AudioFocusType::GainTransientMayDuck); | 44 AudioFocusManager::AudioFocusType::GainTransientMayDuck); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // static | 83 // static |
| 86 std::unique_ptr<AudioFocusDelegate> AudioFocusDelegate::Create( | 84 std::unique_ptr<AudioFocusDelegate> AudioFocusDelegate::Create( |
| 87 MediaSessionImpl* media_session) { | 85 MediaSessionImpl* media_session) { |
| 88 AudioFocusDelegateAndroid* delegate = | 86 AudioFocusDelegateAndroid* delegate = |
| 89 new AudioFocusDelegateAndroid(media_session); | 87 new AudioFocusDelegateAndroid(media_session); |
| 90 delegate->Initialize(); | 88 delegate->Initialize(); |
| 91 return std::unique_ptr<AudioFocusDelegate>(delegate); | 89 return std::unique_ptr<AudioFocusDelegate>(delegate); |
| 92 } | 90 } |
| 93 | 91 |
| 94 } // namespace content | 92 } // namespace content |
| OLD | NEW |