Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: runtime/embedders/openglui/android/android_sound_handler.cc

Issue 12340036: Android improvements: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "embedders/openglui/android/android_sound_handler.h" 5 #include "embedders/openglui/android/android_sound_handler.h"
6 6
7 #include "embedders/openglui/android/android_resource.h" 7 #include "embedders/openglui/android/android_resource.h"
8 #include "embedders/openglui/common/log.h" 8 #include "embedders/openglui/common/log.h"
9 9
10 AndroidSoundHandler::AndroidSoundHandler(android_app* application) 10 AndroidSoundHandler::AndroidSoundHandler(android_app* application)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 } 49 }
50 } 50 }
51 } 51 }
52 LOGI("Failed to start SoundService"); 52 LOGI("Failed to start SoundService");
53 Stop(); 53 Stop();
54 return -1; 54 return -1;
55 } 55 }
56 56
57 void AndroidSoundHandler::Stop() { 57 void AndroidSoundHandler::Stop() {
58 StopBackground(); 58 LOGI("Stopping SoundService");
59 if (output_mix_ != NULL) {
60 (*output_mix_)->Destroy(output_mix_);
61 output_mix_ = NULL;
62 }
63 if (engine_ != NULL) {
64 (*engine_)->Destroy(engine_);
65 engine_ = NULL;
66 engine_if_ = NULL;
67 }
68 if (sample_player_ != NULL) { 59 if (sample_player_ != NULL) {
60 LOGI("Destroying sample player");
69 (*sample_player_)->Destroy(sample_player_); 61 (*sample_player_)->Destroy(sample_player_);
70 sample_player_ = NULL; 62 sample_player_ = NULL;
71 sample_player_if_ = NULL; 63 sample_player_if_ = NULL;
72 sample_player_queue_ = NULL; 64 sample_player_queue_ = NULL;
73 } 65 }
74 samples_.clear(); 66 samples_.clear();
67 if (output_mix_ != NULL) {
68 LOGI("Destroying output mix");
69 (*output_mix_)->Destroy(output_mix_);
70 output_mix_ = NULL;
71 }
72 if (engine_ != NULL) {
73 LOGI("Destroying engine");
74 (*engine_)->Destroy(engine_);
75 engine_ = NULL;
76 engine_if_ = NULL;
77 }
78 }
79
80 int32_t AndroidSoundHandler::SetBackgroundPlayerState(int state) {
81 if (background_player_if_ != NULL) {
82 SLuint32 state;
83 (*background_player_)->GetState(background_player_, &state);
84 if (state == SL_OBJECT_STATE_REALIZED) {
85 (*background_player_if_)->SetPlayState(background_player_if_,
86 state);
87 return 0;
88 }
89 }
90 return -1;
91 }
92
93 int32_t AndroidSoundHandler::Pause() {
94 return SetBackgroundPlayerState(SL_PLAYSTATE_PAUSED);
95 }
96
97
98 int32_t AndroidSoundHandler::Resume() {
99 return SetBackgroundPlayerState(SL_PLAYSTATE_PLAYING);
75 } 100 }
76 101
77 int32_t AndroidSoundHandler::CreateAudioPlayer(SLEngineItf engine_if, 102 int32_t AndroidSoundHandler::CreateAudioPlayer(SLEngineItf engine_if,
78 const SLInterfaceID extra_if, 103 const SLInterfaceID extra_if,
79 SLDataSource data_source, 104 SLDataSource data_source,
80 SLDataSink data_sink, 105 SLDataSink data_sink,
81 SLObjectItf& player_out, 106 SLObjectItf& player_out,
82 SLPlayItf& player_if_out) { 107 SLPlayItf& player_if_out) {
83 const SLuint32 SoundPlayerIIDCount = 2; 108 const SLuint32 SoundPlayerIIDCount = 2;
84 const SLInterfaceID SoundPlayerIIDs[] = { SL_IID_PLAY, extra_if }; 109 const SLInterfaceID SoundPlayerIIDs[] = { SL_IID_PLAY, extra_if };
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 SetPlayState(background_player_if_, SL_PLAYSTATE_PLAYING) != 189 SetPlayState(background_player_if_, SL_PLAYSTATE_PLAYING) !=
165 SL_RESULT_SUCCESS) { 190 SL_RESULT_SUCCESS) {
166 LOGE("Couldn't start playing"); 191 LOGE("Couldn't start playing");
167 return -1; 192 return -1;
168 } 193 }
169 LOGI("Started playing"); 194 LOGI("Started playing");
170 return 0; 195 return 0;
171 } 196 }
172 197
173 void AndroidSoundHandler::StopBackground() { 198 void AndroidSoundHandler::StopBackground() {
174 if (background_player_if_ != NULL) { 199 if (Pause() == 0) {
175 SLuint32 state; 200 (*background_player_)->Destroy(background_player_);
176 (*background_player_)->GetState(background_player_, &state); 201 background_player_ = NULL;
177 if (state == SL_OBJECT_STATE_REALIZED) { 202 background_player_if_ = NULL;
178 (*background_player_if_)->SetPlayState(background_player_if_, 203 background_player_seek_if_ = NULL;
179 SL_PLAYSTATE_PAUSED);
180
181 (*background_player_)->Destroy(background_player_);
182 background_player_ = NULL;
183 background_player_if_ = NULL;
184 background_player_seek_if_ = NULL;
185 }
186 } 204 }
187 } 205 }
188 206
189 int32_t AndroidSoundHandler::StartSamplePlayer() { 207 int32_t AndroidSoundHandler::StartSamplePlayer() {
190 SLDataLocator_AndroidSimpleBufferQueue data_locator_in = { 208 SLDataLocator_AndroidSimpleBufferQueue data_locator_in = {
191 SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 209 SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
192 1 210 1
193 }; 211 };
194 212
195 SLDataFormat_PCM data_format= { 213 SLDataFormat_PCM data_format= {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return 0; 267 return 0;
250 } 268 }
251 LOGE("Enqueueing sample failed"); 269 LOGE("Enqueueing sample failed");
252 } 270 }
253 } 271 }
254 } 272 }
255 return -1; 273 return -1;
256 } 274 }
257 275
258 276
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/android/android_sound_handler.h ('k') | runtime/embedders/openglui/android/eventloop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698