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

Side by Side Diff: media/audio/android/opensles_output.h

Issue 1166483002: Stop enqueueing data to output audio device if consecutive empty buffers are received (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « media/audio/android/audio_android_unittest.cc ('k') | media/audio/android/opensles_output.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 5 #ifndef MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
6 #define MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 6 #define MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
7 7
8 #include <SLES/OpenSLES.h> 8 #include <SLES/OpenSLES.h>
9 #include <SLES/OpenSLES_Android.h> 9 #include <SLES/OpenSLES_Android.h>
10 10
11 #include "base/cancelable_callback.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
12 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h"
14 #include "media/audio/android/opensles_util.h" 17 #include "media/audio/android/opensles_util.h"
15 #include "media/audio/audio_io.h" 18 #include "media/audio/audio_io.h"
16 #include "media/audio/audio_parameters.h" 19 #include "media/audio/audio_parameters.h"
20 #include "media/base/audio_timestamp_helper.h"
21
22 namespace base {
23 class SingleThreadTaskRunner;
24 }
17 25
18 namespace media { 26 namespace media {
19 27
20 class AudioManagerAndroid; 28 class AudioManagerAndroid;
21 29
22 // Implements PCM audio output support for Android using the OpenSLES API. 30 // Implements PCM audio output support for Android using the OpenSLES API.
23 // This class is created and lives on the Audio Manager thread but recorded 31 // This class is created and lives on the Audio Manager thread but recorded
24 // audio buffers are given to us from an internal OpenSLES audio thread. 32 // audio buffers are given to us from an internal OpenSLES audio thread.
25 // All public methods should be called on the Audio Manager thread. 33 // All public methods should be called on the Audio Manager thread.
26 class OpenSLESOutputStream : public AudioOutputStream { 34 class OpenSLESOutputStream : public AudioOutputStream {
(...skipping 23 matching lines...) Expand all
50 58
51 // Called from OpenSLES specific audio worker thread. 59 // Called from OpenSLES specific audio worker thread.
52 static void SimpleBufferQueueCallback( 60 static void SimpleBufferQueueCallback(
53 SLAndroidSimpleBufferQueueItf buffer_queue, 61 SLAndroidSimpleBufferQueueItf buffer_queue,
54 void* instance); 62 void* instance);
55 63
56 // Fills up one buffer by asking the registered source for data. 64 // Fills up one buffer by asking the registered source for data.
57 // Called from OpenSLES specific audio worker thread. 65 // Called from OpenSLES specific audio worker thread.
58 void FillBufferQueue(); 66 void FillBufferQueue();
59 67
60 // Called from the audio manager thread. 68 // Called from either the audio manager thread or the OpenSLES audio worker
61 void FillBufferQueueNoLock(); 69 // thread. |lock_| must be held when this method is called.
70 // |in_idle_mode| is true if the player is in idle mode, or false otherwise.
71 void FillBufferQueueNoLock(bool in_idle_mode);
62 72
63 // Called in Open(); 73 // Called in Open();
64 void SetupAudioBuffer(); 74 void SetupAudioBuffer();
65 75
66 // Called in Close(); 76 // Called in Close();
67 void ReleaseAudioBuffer(); 77 void ReleaseAudioBuffer();
68 78
69 // If OpenSLES reports an error this function handles it and passes it to 79 // If OpenSLES reports an error this function handles it and passes it to
70 // the attached AudioOutputCallback::OnError(). 80 // the attached AudioOutputCallback::OnError().
71 void HandleError(SLresult error); 81 void HandleError(SLresult error);
72 82
83 // Called to check whether there are any audio data available to render.
84 void CheckForIdle();
85
86 // Called to cancel the check for empty audio data.
87 void CancelIdleCheck();
88
89 // Starts entering idle mode. The player will stop writing data to buffer
90 // queue until non empty data arrives. |in_idle_mode| indicates whether
91 // the player is in the idle mode. |frames_filled| and |idle_start_time|
92 // are used by |audio_timestamp_helper_| and |idle_start_time_| to avoid
93 // time drifting.
94 void WaitingForAudio(bool in_idle_mode,
95 int frames_filled, base::TimeTicks idle_start_time);
96
73 base::ThreadChecker thread_checker_; 97 base::ThreadChecker thread_checker_;
74 98
75 // Protects |callback_|, |active_buffer_index_|, |audio_data_|, 99 // Protects |callback_|, |active_buffer_index_|, |audio_data_|,
76 // |buffer_size_bytes_| and |simple_buffer_queue_|. 100 // |buffer_size_bytes_| and |simple_buffer_queue_|.
77 base::Lock lock_; 101 base::Lock lock_;
78 102
79 AudioManagerAndroid* audio_manager_; 103 AudioManagerAndroid* audio_manager_;
80 104
81 // Audio playback stream type. 105 // Audio playback stream type.
82 // See SLES/OpenSLES_Android.h for details. 106 // See SLES/OpenSLES_Android.h for details.
(...skipping 27 matching lines...) Expand all
110 // This is needed because platform voice volume never goes to zero in 134 // This is needed because platform voice volume never goes to zero in
111 // COMMUNICATION mode on Android. 135 // COMMUNICATION mode on Android.
112 bool muted_; 136 bool muted_;
113 137
114 // Volume level from 0 to 1. 138 // Volume level from 0 to 1.
115 float volume_; 139 float volume_;
116 140
117 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 141 // Container for retrieving data from AudioSourceCallback::OnMoreData().
118 scoped_ptr<AudioBus> audio_bus_; 142 scoped_ptr<AudioBus> audio_bus_;
119 143
144 // Object to calculate the current audio timestamp in idle mode.
145 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
146
147 // The start TimeTicks when the player enters idle mode.
148 base::TimeTicks idle_start_time_;
149
150 // The number of consecutive empty audio buffers encountered.
151 uint32 consecutive_empty_buffer_count_;
152
153 // A cancelable task that is posted when the player enters idle mode. The task
154 // is posted regularly to check whether there are any audio data available to
155 // render.
156 base::CancelableClosure idle_check_callback_;
157
158 // TaskRunner to post |idle_check_callback_|.
159 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
160
161 // Weak pointer for callbacks.
162 base::WeakPtr<OpenSLESOutputStream> weak_this_;
163 // NOTE: Weak pointers must be invalidated before all other member variables.
164 base::WeakPtrFactory<OpenSLESOutputStream> weak_factory_;
165
120 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream); 166 DISALLOW_COPY_AND_ASSIGN(OpenSLESOutputStream);
121 }; 167 };
122 168
123 } // namespace media 169 } // namespace media
124 170
125 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_ 171 #endif // MEDIA_AUDIO_ANDROID_OPENSLES_OUTPUT_H_
OLDNEW
« no previous file with comments | « media/audio/android/audio_android_unittest.cc ('k') | media/audio/android/opensles_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698