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

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 2684103005: Allow media track switching. (Closed)
Patch Set: Fixed comments Created 3 years, 8 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/renderers/audio_renderer_impl.h ('k') | media/renderers/audio_renderer_impl_unittest.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 #include "media/renderers/audio_renderer_impl.h" 5 #include "media/renderers/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 18 matching lines...) Expand all
29 #include "media/base/renderer_client.h" 29 #include "media/base/renderer_client.h"
30 #include "media/base/timestamp_constants.h" 30 #include "media/base/timestamp_constants.h"
31 #include "media/filters/audio_clock.h" 31 #include "media/filters/audio_clock.h"
32 #include "media/filters/decrypting_demuxer_stream.h" 32 #include "media/filters/decrypting_demuxer_stream.h"
33 33
34 namespace media { 34 namespace media {
35 35
36 AudioRendererImpl::AudioRendererImpl( 36 AudioRendererImpl::AudioRendererImpl(
37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
38 media::AudioRendererSink* sink, 38 media::AudioRendererSink* sink,
39 ScopedVector<AudioDecoder> decoders, 39 const CreateAudioDecodersCB& create_audio_decoders_cb,
40 const scoped_refptr<MediaLog>& media_log) 40 const scoped_refptr<MediaLog>& media_log)
41 : task_runner_(task_runner), 41 : task_runner_(task_runner),
42 expecting_config_changes_(false), 42 expecting_config_changes_(false),
43 sink_(sink), 43 sink_(sink),
44 audio_buffer_stream_(
45 new AudioBufferStream(task_runner, std::move(decoders), media_log)),
46 media_log_(media_log), 44 media_log_(media_log),
47 client_(nullptr), 45 client_(nullptr),
48 tick_clock_(new base::DefaultTickClock()), 46 tick_clock_(new base::DefaultTickClock()),
49 last_audio_memory_usage_(0), 47 last_audio_memory_usage_(0),
50 last_decoded_sample_rate_(0), 48 last_decoded_sample_rate_(0),
51 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE), 49 last_decoded_channel_layout_(CHANNEL_LAYOUT_NONE),
52 playback_rate_(0.0), 50 playback_rate_(0.0),
53 state_(kUninitialized), 51 state_(kUninitialized),
52 create_audio_decoders_cb_(create_audio_decoders_cb),
54 buffering_state_(BUFFERING_HAVE_NOTHING), 53 buffering_state_(BUFFERING_HAVE_NOTHING),
55 rendering_(false), 54 rendering_(false),
56 sink_playing_(false), 55 sink_playing_(false),
57 pending_read_(false), 56 pending_read_(false),
58 received_end_of_stream_(false), 57 received_end_of_stream_(false),
59 rendered_end_of_stream_(false), 58 rendered_end_of_stream_(false),
60 is_suspending_(false), 59 is_suspending_(false),
61 weak_factory_(this) { 60 weak_factory_(this) {
62 audio_buffer_stream_->set_config_change_observer(base::Bind( 61 DCHECK(create_audio_decoders_cb_);
63 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr()));
64
65 // Tests may not have a power monitor. 62 // Tests may not have a power monitor.
66 base::PowerMonitor* monitor = base::PowerMonitor::Get(); 63 base::PowerMonitor* monitor = base::PowerMonitor::Get();
67 if (!monitor) 64 if (!monitor)
68 return; 65 return;
69 66
70 // PowerObserver's must be added and removed from the same thread, but we 67 // PowerObserver's must be added and removed from the same thread, but we
71 // won't remove the observer until we're destructed on |task_runner_| so we 68 // won't remove the observer until we're destructed on |task_runner_| so we
72 // must post it here if we're on the wrong thread. 69 // must post it here if we're on the wrong thread.
73 if (task_runner_->BelongsToCurrentThread()) { 70 if (task_runner_->BelongsToCurrentThread()) {
74 monitor->AddObserver(this); 71 monitor->AddObserver(this);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void AudioRendererImpl::Initialize(DemuxerStream* stream, 330 void AudioRendererImpl::Initialize(DemuxerStream* stream,
334 CdmContext* cdm_context, 331 CdmContext* cdm_context,
335 RendererClient* client, 332 RendererClient* client,
336 const PipelineStatusCB& init_cb) { 333 const PipelineStatusCB& init_cb) {
337 DVLOG(1) << __func__; 334 DVLOG(1) << __func__;
338 DCHECK(task_runner_->BelongsToCurrentThread()); 335 DCHECK(task_runner_->BelongsToCurrentThread());
339 DCHECK(client); 336 DCHECK(client);
340 DCHECK(stream); 337 DCHECK(stream);
341 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); 338 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO);
342 DCHECK(!init_cb.is_null()); 339 DCHECK(!init_cb.is_null());
343 DCHECK_EQ(kUninitialized, state_); 340 DCHECK(state_ == kUninitialized || state_ == kFlushed);
344 DCHECK(sink_.get()); 341 DCHECK(sink_.get());
345 342
343 // If we are re-initializing playback (e.g. switching media tracks), stop the
344 // sink first.
345 if (state_ == kFlushed) {
346 sink_->Stop();
347 audio_clock_.reset();
348 }
349
346 // Trying to track down AudioClock crash, http://crbug.com/674856. 350 // Trying to track down AudioClock crash, http://crbug.com/674856.
347 // AudioRenderImpl should only be initialized once to avoid destroying 351 // AudioRenderImpl should only be initialized once to avoid destroying
348 // AudioClock while the audio thread is still using it. 352 // AudioClock while the audio thread is still using it.
349 CHECK_EQ(audio_clock_.get(), nullptr); 353 CHECK_EQ(audio_clock_.get(), nullptr);
350 354
351 state_ = kInitializing; 355 state_ = kInitializing;
352 client_ = client; 356 client_ = client;
353 357
358 audio_buffer_stream_ = base::MakeUnique<AudioBufferStream>(
359 task_runner_, create_audio_decoders_cb_.Run(), media_log_);
360
361 audio_buffer_stream_->set_config_change_observer(base::Bind(
362 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr()));
363
354 // Always post |init_cb_| because |this| could be destroyed if initialization 364 // Always post |init_cb_| because |this| could be destroyed if initialization
355 // failed. 365 // failed.
356 init_cb_ = BindToCurrentLoop(init_cb); 366 init_cb_ = BindToCurrentLoop(init_cb);
357 367
358 auto output_device_info = sink_->GetOutputDeviceInfo(); 368 auto output_device_info = sink_->GetOutputDeviceInfo();
359 const AudioParameters& hw_params = output_device_info.output_params(); 369 const AudioParameters& hw_params = output_device_info.output_params();
360 expecting_config_changes_ = stream->SupportsConfigChanges(); 370 expecting_config_changes_ = stream->SupportsConfigChanges();
361 if (!expecting_config_changes_ || !hw_params.IsValid() || 371 if (!expecting_config_changes_ || !hw_params.IsValid() ||
362 hw_params.format() == AudioParameters::AUDIO_FAKE) { 372 hw_params.format() == AudioParameters::AUDIO_FAKE) {
363 // The actual buffer size is controlled via the size of the AudioBus 373 // The actual buffer size is controlled via the size of the AudioBus
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 // All channels with a zero mix are muted and can be ignored. 1009 // All channels with a zero mix are muted and can be ignored.
1000 std::vector<bool> channel_mask(audio_parameters_.channels(), false); 1010 std::vector<bool> channel_mask(audio_parameters_.channels(), false);
1001 for (size_t ch = 0; ch < matrix.size(); ++ch) { 1011 for (size_t ch = 0; ch < matrix.size(); ++ch) {
1002 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), 1012 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(),
1003 [](float mix) { return !!mix; }); 1013 [](float mix) { return !!mix; });
1004 } 1014 }
1005 algorithm_->SetChannelMask(std::move(channel_mask)); 1015 algorithm_->SetChannelMask(std::move(channel_mask));
1006 } 1016 }
1007 1017
1008 } // namespace media 1018 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/renderers/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698