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

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

Issue 2142403002: Pick up starting position from OpenSLES getPosition(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | no next file » | 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 #include "media/audio/android/opensles_output.h" 5 #include "media/audio/android/opensles_output.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "media/audio/android/audio_manager_android.h" 10 #include "media/audio/android/audio_manager_android.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 DCHECK(thread_checker_.CalledOnValidThread()); 80 DCHECK(thread_checker_.CalledOnValidThread());
81 DCHECK(callback); 81 DCHECK(callback);
82 DCHECK(player_); 82 DCHECK(player_);
83 DCHECK(simple_buffer_queue_); 83 DCHECK(simple_buffer_queue_);
84 if (started_) 84 if (started_)
85 return; 85 return;
86 86
87 base::AutoLock lock(lock_); 87 base::AutoLock lock(lock_);
88 DCHECK(!callback_); 88 DCHECK(!callback_);
89 callback_ = callback; 89 callback_ = callback;
90 delay_calculator_.SetBaseTimestamp(base::TimeDelta());
91 90
92 // Fill audio data with silence to avoid start-up glitches. Don't use 91 // Fill audio data with silence to avoid start-up glitches. Don't use
93 // FillBufferQueueNoLock() since it can trigger recursive entry if an error 92 // FillBufferQueueNoLock() since it can trigger recursive entry if an error
94 // occurs while writing into the stream. See http://crbug.com/624877. 93 // occurs while writing into the stream. See http://crbug.com/624877.
95 memset(audio_data_[active_buffer_index_], 0, buffer_size_bytes_); 94 memset(audio_data_[active_buffer_index_], 0, buffer_size_bytes_);
96 delay_calculator_.AddFrames(audio_bus_->frames());
97 LOG_ON_FAILURE_AND_RETURN((*simple_buffer_queue_) 95 LOG_ON_FAILURE_AND_RETURN((*simple_buffer_queue_)
98 ->Enqueue(simple_buffer_queue_, 96 ->Enqueue(simple_buffer_queue_,
99 audio_data_[active_buffer_index_], 97 audio_data_[active_buffer_index_],
100 buffer_size_bytes_)); 98 buffer_size_bytes_));
101 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; 99 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue;
102 100
103 // Start streaming data by setting the play state to SL_PLAYSTATE_PLAYING. 101 // Start streaming data by setting the play state to SL_PLAYSTATE_PLAYING.
104 // For a player object, when the object is in the SL_PLAYSTATE_PLAYING 102 // For a player object, when the object is in the SL_PLAYSTATE_PLAYING
105 // state, adding buffers will implicitly start playback. 103 // state, adding buffers will implicitly start playback.
106 LOG_ON_FAILURE_AND_RETURN( 104 LOG_ON_FAILURE_AND_RETURN(
107 (*player_)->SetPlayState(player_, SL_PLAYSTATE_PLAYING)); 105 (*player_)->SetPlayState(player_, SL_PLAYSTATE_PLAYING));
108 106
107 // On older version of Android, the position may not be reset even though we
108 // call Clear() during Stop(), in this case the best we can do is assume that
109 // we're continuing on from this previous position.
110 uint32_t position_in_ms = 0;
111 LOG_ON_FAILURE_AND_RETURN((*player_)->GetPosition(player_, &position_in_ms));
112 delay_calculator_.SetBaseTimestamp(
113 base::TimeDelta::FromMilliseconds(position_in_ms));
114 delay_calculator_.AddFrames(audio_bus_->frames());
115
109 started_ = true; 116 started_ = true;
110 } 117 }
111 118
112 void OpenSLESOutputStream::Stop() { 119 void OpenSLESOutputStream::Stop() {
113 DVLOG(2) << "OpenSLESOutputStream::Stop()"; 120 DVLOG(2) << "OpenSLESOutputStream::Stop()";
114 DCHECK(thread_checker_.CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
115 if (!started_) 122 if (!started_)
116 return; 123 return;
117 124
118 base::AutoLock lock(lock_); 125 base::AutoLock lock(lock_);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 394 }
388 } 395 }
389 396
390 void OpenSLESOutputStream::HandleError(SLresult error) { 397 void OpenSLESOutputStream::HandleError(SLresult error) {
391 DLOG(ERROR) << "OpenSLES Output error " << error; 398 DLOG(ERROR) << "OpenSLES Output error " << error;
392 if (callback_) 399 if (callback_)
393 callback_->OnError(this); 400 callback_->OnError(this);
394 } 401 }
395 402
396 } // namespace media 403 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698