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

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

Issue 1838203003: [TO M50] Enable implicit signalling for HE AAC v1 & v2 in ADTS. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2661
Patch Set: Created 4 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
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/time/default_tick_clock.h" 19 #include "base/time/default_tick_clock.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "media/base/audio_buffer.h" 21 #include "media/base/audio_buffer.h"
21 #include "media/base/audio_buffer_converter.h" 22 #include "media/base/audio_buffer_converter.h"
22 #include "media/base/audio_hardware_config.h" 23 #include "media/base/audio_hardware_config.h"
23 #include "media/base/audio_splicer.h" 24 #include "media/base/audio_splicer.h"
24 #include "media/base/bind_to_current_loop.h" 25 #include "media/base/bind_to_current_loop.h"
25 #include "media/base/demuxer_stream.h" 26 #include "media/base/demuxer_stream.h"
26 #include "media/base/media_log.h" 27 #include "media/base/media_log.h"
28 #include "media/base/media_switches.h"
27 #include "media/base/timestamp_constants.h" 29 #include "media/base/timestamp_constants.h"
28 #include "media/filters/audio_clock.h" 30 #include "media/filters/audio_clock.h"
29 #include "media/filters/decrypting_demuxer_stream.h" 31 #include "media/filters/decrypting_demuxer_stream.h"
30 32
31 namespace media { 33 namespace media {
32 34
33 namespace { 35 namespace {
34 36
35 enum AudioRendererEvent { 37 enum AudioRendererEvent {
36 INITIALIZED, 38 INITIALIZED,
(...skipping 16 matching lines...) Expand all
53 const scoped_refptr<MediaLog>& media_log) 55 const scoped_refptr<MediaLog>& media_log)
54 : task_runner_(task_runner), 56 : task_runner_(task_runner),
55 expecting_config_changes_(false), 57 expecting_config_changes_(false),
56 sink_(sink), 58 sink_(sink),
57 audio_buffer_stream_( 59 audio_buffer_stream_(
58 new AudioBufferStream(task_runner, std::move(decoders), media_log)), 60 new AudioBufferStream(task_runner, std::move(decoders), media_log)),
59 hardware_config_(hardware_config), 61 hardware_config_(hardware_config),
60 media_log_(media_log), 62 media_log_(media_log),
61 tick_clock_(new base::DefaultTickClock()), 63 tick_clock_(new base::DefaultTickClock()),
62 last_audio_memory_usage_(0), 64 last_audio_memory_usage_(0),
65 last_decoded_sample_rate_(0),
63 playback_rate_(0.0), 66 playback_rate_(0.0),
64 state_(kUninitialized), 67 state_(kUninitialized),
65 buffering_state_(BUFFERING_HAVE_NOTHING), 68 buffering_state_(BUFFERING_HAVE_NOTHING),
66 rendering_(false), 69 rendering_(false),
67 sink_playing_(false), 70 sink_playing_(false),
68 pending_read_(false), 71 pending_read_(false),
69 received_end_of_stream_(false), 72 received_end_of_stream_(false),
70 rendered_end_of_stream_(false), 73 rendered_end_of_stream_(false),
71 weak_factory_(this) { 74 weak_factory_(this) {
72 audio_buffer_stream_->set_splice_observer(base::Bind( 75 audio_buffer_stream_->set_splice_observer(base::Bind(
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 #if defined(OS_CHROMEOS) 365 #if defined(OS_CHROMEOS)
363 // On ChromeOS let the OS level resampler handle resampling unless the 366 // On ChromeOS let the OS level resampler handle resampling unless the
364 // initial sample rate is too low; this allows support for sample rate 367 // initial sample rate is too low; this allows support for sample rate
365 // adaptations where necessary. 368 // adaptations where necessary.
366 if (stream->audio_decoder_config().samples_per_second() >= 44100) { 369 if (stream->audio_decoder_config().samples_per_second() >= 44100) {
367 sample_rate = stream->audio_decoder_config().samples_per_second(); 370 sample_rate = stream->audio_decoder_config().samples_per_second();
368 preferred_buffer_size = 0; // No preference. 371 preferred_buffer_size = 0; // No preference.
369 } 372 }
370 #endif 373 #endif
371 374
372 audio_parameters_.Reset( 375 int stream_channel_count = ChannelLayoutToChannelCount(
373 hw_params.format(), 376 stream->audio_decoder_config().channel_layout());
374 // Always use the source's channel layout to avoid premature downmixing 377
375 // (http://crbug.com/379288), platform specific issues around channel 378 bool try_supported_channel_layouts = false;
376 // layouts (http://crbug.com/266674), and unnecessary upmixing overhead. 379 #if defined(OS_WIN)
377 stream->audio_decoder_config().channel_layout(), sample_rate, 380 try_supported_channel_layouts =
378 hw_params.bits_per_sample(), 381 base::CommandLine::ForCurrentProcess()->HasSwitch(
379 AudioHardwareConfig::GetHighLatencyBufferSize(sample_rate, 382 switches::kTrySupportedChannelLayouts);
380 preferred_buffer_size)); 383 #endif
384
385 // We don't know how to up-mix for DISCRETE layouts (fancy multichannel
386 // hardware with non-standard speaker arrangement). Instead, pretend the
387 // hardware layout is stereo and let the OS take care of further up-mixing
388 // to the discrete layout (http://crbug.com/266674). Additionally, pretend
389 // hardware is stereo whenever kTrySupportedChannelLayouts is set. This flag
390 // is for savvy users who want stereo content to output in all surround
391 // speakers. Using the actual layout (likely 5.1 or higher) will mean our
392 // mixer will attempt to up-mix stereo source streams to just the left/right
393 // speaker of the 5.1 setup, nulling out the other channels
394 // (http://crbug.com/177872).
395 ChannelLayout hw_channel_layout =
396 hw_params.channel_layout() == CHANNEL_LAYOUT_DISCRETE ||
397 try_supported_channel_layouts
398 ? CHANNEL_LAYOUT_STEREO
399 : hw_params.channel_layout();
400 int hw_channel_count = ChannelLayoutToChannelCount(hw_channel_layout);
401
402 // The layout we pass to |audio_parameters_| will be used for the lifetime
403 // of this audio renderer, regardless of changes to hardware and/or stream
404 // properties. Below we choose the max of stream layout vs. hardware layout
405 // to leave room for changes to the hardware and/or stream (i.e. avoid
406 // premature down-mixing - http://crbug.com/379288).
407 // If stream_channels < hw_channels:
408 // Taking max means we up-mix to hardware layout. If stream later changes
409 // to have more channels, we aren't locked into down-mixing to the
410 // initial stream layout.
411 // If stream_channels > hw_channels:
412 // We choose to output stream's layout, meaning mixing is a no-op for the
413 // renderer. Browser-side will down-mix to the hardware config. If the
414 // hardware later changes to equal stream channels, browser-side will stop
415 // down-mixing and use the data from all stream channels.
416 ChannelLayout renderer_channel_layout =
417 hw_channel_count > stream_channel_count
418 ? hw_channel_layout
419 : stream->audio_decoder_config().channel_layout();
420
421 audio_parameters_.Reset(hw_params.format(), renderer_channel_layout,
422 sample_rate, hw_params.bits_per_sample(),
423 AudioHardwareConfig::GetHighLatencyBufferSize(
424 sample_rate, preferred_buffer_size));
381 } 425 }
382 426
383 audio_clock_.reset( 427 audio_clock_.reset(
384 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate())); 428 new AudioClock(base::TimeDelta(), audio_parameters_.sample_rate()));
385 429
386 audio_buffer_stream_->Initialize( 430 audio_buffer_stream_->Initialize(
387 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized, 431 stream, base::Bind(&AudioRendererImpl::OnAudioBufferStreamInitialized,
388 weak_factory_.GetWeakPtr()), 432 weak_factory_.GetWeakPtr()),
389 cdm_context, statistics_cb, waiting_for_decryption_key_cb); 433 cdm_context, statistics_cb, waiting_for_decryption_key_cb);
390 } 434 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 DCHECK_EQ(status, AudioBufferStream::OK); 511 DCHECK_EQ(status, AudioBufferStream::OK);
468 DCHECK(buffer.get()); 512 DCHECK(buffer.get());
469 513
470 if (state_ == kFlushing) { 514 if (state_ == kFlushing) {
471 ChangeState_Locked(kFlushed); 515 ChangeState_Locked(kFlushed);
472 DoFlush_Locked(); 516 DoFlush_Locked();
473 return; 517 return;
474 } 518 }
475 519
476 if (expecting_config_changes_) { 520 if (expecting_config_changes_) {
521 if (last_decoded_sample_rate_ &&
522 buffer->sample_rate() != last_decoded_sample_rate_) {
523 DVLOG(1) << __FUNCTION__ << " Updating audio sample_rate."
524 << " ts:" << buffer->timestamp().InMicroseconds()
525 << " old:" << last_decoded_sample_rate_
526 << " new:" << buffer->sample_rate();
527 OnConfigChange();
528 }
529 last_decoded_sample_rate_ = buffer->sample_rate();
530
477 DCHECK(buffer_converter_); 531 DCHECK(buffer_converter_);
478 buffer_converter_->AddInput(buffer); 532 buffer_converter_->AddInput(buffer);
479 while (buffer_converter_->HasNextBuffer()) { 533 while (buffer_converter_->HasNextBuffer()) {
480 if (!splicer_->AddInput(buffer_converter_->GetNextBuffer())) { 534 if (!splicer_->AddInput(buffer_converter_->GetNextBuffer())) {
481 HandleAbortedReadOrDecodeError(true); 535 HandleAbortedReadOrDecodeError(true);
482 return; 536 return;
483 } 537 }
484 } 538 }
485 } else { 539 } else {
486 if (!splicer_->AddInput(buffer)) { 540 if (!splicer_->AddInput(buffer)) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 << buffering_state; 887 << buffering_state;
834 DCHECK_NE(buffering_state_, buffering_state); 888 DCHECK_NE(buffering_state_, buffering_state);
835 lock_.AssertAcquired(); 889 lock_.AssertAcquired();
836 buffering_state_ = buffering_state; 890 buffering_state_ = buffering_state;
837 891
838 task_runner_->PostTask(FROM_HERE, 892 task_runner_->PostTask(FROM_HERE,
839 base::Bind(buffering_state_cb_, buffering_state_)); 893 base::Bind(buffering_state_cb_, buffering_state_));
840 } 894 }
841 895
842 } // namespace media 896 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/audio_renderer_impl.h ('k') | media/test/data/bear-audio-implicit-he-aac-v1.aac » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698