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

Side by Side Diff: media/audio/mac/audio_auhal_mac.cc

Issue 1864483002: Forward output glitch information from stream WebRTC log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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/mac/audio_auhal_mac.h ('k') | media/audio/mac/audio_auhal_mac_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/mac/audio_auhal_mac.h" 5 #include "media/audio/mac/audio_auhal_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/mac_logging.h" 12 #include "base/mac/mac_logging.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/stringprintf.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
16 #include "media/audio/mac/audio_manager_mac.h" 17 #include "media/audio/mac/audio_manager_mac.h"
17 #include "media/base/audio_pull_fifo.h" 18 #include "media/base/audio_pull_fifo.h"
18 19
19 namespace media { 20 namespace media {
20 21
21 static void WrapBufferList(AudioBufferList* buffer_list, 22 static void WrapBufferList(AudioBufferList* buffer_list,
22 AudioBus* bus, 23 AudioBus* bus,
23 int frames) { 24 int frames) {
24 DCHECK(buffer_list); 25 DCHECK(buffer_list);
25 DCHECK(bus); 26 DCHECK(bus);
26 const int channels = bus->channels(); 27 const int channels = bus->channels();
27 const int buffer_list_channels = buffer_list->mNumberBuffers; 28 const int buffer_list_channels = buffer_list->mNumberBuffers;
28 CHECK_EQ(channels, buffer_list_channels); 29 CHECK_EQ(channels, buffer_list_channels);
29 30
30 // Copy pointers from AudioBufferList. 31 // Copy pointers from AudioBufferList.
31 for (int i = 0; i < channels; ++i) { 32 for (int i = 0; i < channels; ++i) {
32 bus->SetChannelData( 33 bus->SetChannelData(
33 i, static_cast<float*>(buffer_list->mBuffers[i].mData)); 34 i, static_cast<float*>(buffer_list->mBuffers[i].mData));
34 } 35 }
35 36
36 // Finally set the actual length. 37 // Finally set the actual length.
37 bus->set_frames(frames); 38 bus->set_frames(frames);
38 } 39 }
39 40
40 AUHALStream::AUHALStream(AudioManagerMac* manager, 41 AUHALStream::AUHALStream(AudioManagerMac* manager,
41 const AudioParameters& params, 42 const AudioParameters& params,
42 AudioDeviceID device) 43 AudioDeviceID device,
44 const AudioManager::LogCallback& log_callback)
43 : manager_(manager), 45 : manager_(manager),
44 params_(params), 46 params_(params),
45 output_channels_(params_.channels()), 47 output_channels_(params_.channels()),
46 number_of_frames_(params_.frames_per_buffer()), 48 number_of_frames_(params_.frames_per_buffer()),
47 number_of_frames_requested_(0), 49 number_of_frames_requested_(0),
48 source_(NULL), 50 source_(NULL),
49 device_(device), 51 device_(device),
50 audio_unit_(0), 52 audio_unit_(0),
51 volume_(1), 53 volume_(1),
52 hardware_latency_frames_(0), 54 hardware_latency_frames_(0),
53 stopped_(true), 55 stopped_(true),
54 current_hardware_pending_bytes_(0), 56 current_hardware_pending_bytes_(0),
55 current_lost_frames_(0), 57 current_lost_frames_(0),
56 last_sample_time_(0.0), 58 last_sample_time_(0.0),
57 last_number_of_frames_(0), 59 last_number_of_frames_(0),
58 total_lost_frames_(0), 60 total_lost_frames_(0),
59 largest_glitch_frames_(0), 61 largest_glitch_frames_(0),
60 glitches_detected_(0) { 62 glitches_detected_(0),
63 log_callback_(log_callback) {
61 // We must have a manager. 64 // We must have a manager.
62 DCHECK(manager_); 65 DCHECK(manager_);
63 66
64 DVLOG(1) << "ctor"; 67 DVLOG(1) << "ctor";
65 DVLOG(1) << "device ID: 0x" << std::hex << device; 68 DVLOG(1) << "device ID: 0x" << std::hex << device;
66 DVLOG(1) << "buffer size: " << number_of_frames_; 69 DVLOG(1) << "buffer size: " << number_of_frames_;
67 DVLOG(1) << "output channels: " << output_channels_; 70 DVLOG(1) << "output channels: " << output_channels_;
68 DVLOG(1) << "sample rate: " << params_.sample_rate(); 71 DVLOG(1) << "sample rate: " << params_.sample_rate();
69 } 72 }
70 73
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return; // No stats gathered to report. 386 return; // No stats gathered to report.
384 387
385 // A value of 0 indicates that we got the buffer size we asked for. 388 // A value of 0 indicates that we got the buffer size we asked for.
386 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.FramesRequested", 389 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.FramesRequested",
387 number_of_frames_requested_); 390 number_of_frames_requested_);
388 // Even if there aren't any glitches, we want to record it to get a feel for 391 // Even if there aren't any glitches, we want to record it to get a feel for
389 // how often we get no glitches vs the alternative. 392 // how often we get no glitches vs the alternative.
390 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.Audio.Render.Glitches", glitches_detected_, 393 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.Audio.Render.Glitches", glitches_detected_,
391 0, 999999, 100); 394 0, 999999, 100);
392 395
396 auto lost_frames_ms = (total_lost_frames_ * 1000) / params_.sample_rate();
397 std::string log_message = base::StringPrintf(
398 "AU out: Total glitches=%d. Total frames lost=%d (%d ms).",
399 glitches_detected_, total_lost_frames_, lost_frames_ms);
400 log_callback_.Run(log_message);
401
393 if (glitches_detected_ != 0) { 402 if (glitches_detected_ != 0) {
394 auto lost_frames_ms = (total_lost_frames_ * 1000) / params_.sample_rate();
395 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LostFramesInMs", lost_frames_ms); 403 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LostFramesInMs", lost_frames_ms);
396 auto largest_glitch_ms = 404 auto largest_glitch_ms =
397 (largest_glitch_frames_ * 1000) / params_.sample_rate(); 405 (largest_glitch_frames_ * 1000) / params_.sample_rate();
398 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LargestGlitchMs", 406 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LargestGlitchMs",
399 largest_glitch_ms); 407 largest_glitch_ms);
400 DLOG(WARNING) << "Total glitches=" << glitches_detected_ 408 DLOG(WARNING) << log_message;
401 << ". Total frames lost=" << total_lost_frames_ << " ("
402 << lost_frames_ms;
403 } 409 }
404 410
405 number_of_frames_requested_ = 0; 411 number_of_frames_requested_ = 0;
406 glitches_detected_ = 0; 412 glitches_detected_ = 0;
407 last_sample_time_ = 0; 413 last_sample_time_ = 0;
408 last_number_of_frames_ = 0; 414 last_number_of_frames_ = 0;
409 total_lost_frames_ = 0; 415 total_lost_frames_ = 0;
410 largest_glitch_frames_ = 0; 416 largest_glitch_frames_ = 0;
411 } 417 }
412 418
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 OSStatus result = AudioUnitUninitialize(audio_unit_); 554 OSStatus result = AudioUnitUninitialize(audio_unit_);
549 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 555 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
550 << "AudioUnitUninitialize() failed."; 556 << "AudioUnitUninitialize() failed.";
551 result = AudioComponentInstanceDispose(audio_unit_); 557 result = AudioComponentInstanceDispose(audio_unit_);
552 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 558 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
553 << "AudioComponentInstanceDispose() failed."; 559 << "AudioComponentInstanceDispose() failed.";
554 audio_unit_ = 0; 560 audio_unit_ = 0;
555 } 561 }
556 562
557 } // namespace media 563 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_auhal_mac.h ('k') | media/audio/mac/audio_auhal_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698