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

Side by Side Diff: media/base/audio_splicer.cc

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inlined getters and setters on DataBuffer Created 7 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_low_latency_input_mac.cc ('k') | media/base/audio_splicer_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/base/audio_splicer.h" 5 #include "media/base/audio_splicer.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/audio_decoder_config.h" 10 #include "media/base/audio_decoder_config.h"
(...skipping 18 matching lines...) Expand all
29 AudioSplicer::~AudioSplicer() { 29 AudioSplicer::~AudioSplicer() {
30 } 30 }
31 31
32 void AudioSplicer::Reset() { 32 void AudioSplicer::Reset() {
33 output_timestamp_helper_.SetBaseTimestamp(kNoTimestamp()); 33 output_timestamp_helper_.SetBaseTimestamp(kNoTimestamp());
34 output_buffers_.clear(); 34 output_buffers_.clear();
35 received_end_of_stream_ = false; 35 received_end_of_stream_ = false;
36 } 36 }
37 37
38 bool AudioSplicer::AddInput(const scoped_refptr<DataBuffer>& input){ 38 bool AudioSplicer::AddInput(const scoped_refptr<DataBuffer>& input){
39 DCHECK(!received_end_of_stream_ || input->IsEndOfStream()); 39 DCHECK(!received_end_of_stream_ || input->end_of_stream());
40 40
41 if (input->IsEndOfStream()) { 41 if (input->end_of_stream()) {
42 output_buffers_.push_back(input); 42 output_buffers_.push_back(input);
43 received_end_of_stream_ = true; 43 received_end_of_stream_ = true;
44 return true; 44 return true;
45 } 45 }
46 46
47 DCHECK(input->GetTimestamp() != kNoTimestamp()); 47 DCHECK(input->timestamp() != kNoTimestamp());
48 DCHECK(input->GetDuration() > base::TimeDelta()); 48 DCHECK(input->duration() > base::TimeDelta());
49 DCHECK_GT(input->GetDataSize(), 0); 49 DCHECK_GT(input->data_size(), 0);
50 50
51 if (output_timestamp_helper_.base_timestamp() == kNoTimestamp()) 51 if (output_timestamp_helper_.base_timestamp() == kNoTimestamp())
52 output_timestamp_helper_.SetBaseTimestamp(input->GetTimestamp()); 52 output_timestamp_helper_.SetBaseTimestamp(input->timestamp());
53 53
54 if (output_timestamp_helper_.base_timestamp() > input->GetTimestamp()) { 54 if (output_timestamp_helper_.base_timestamp() > input->timestamp()) {
55 DVLOG(1) << "Input timestamp is before the base timestamp."; 55 DVLOG(1) << "Input timestamp is before the base timestamp.";
56 return false; 56 return false;
57 } 57 }
58 58
59 base::TimeDelta timestamp = input->GetTimestamp(); 59 base::TimeDelta timestamp = input->timestamp();
60 base::TimeDelta expected_timestamp = output_timestamp_helper_.GetTimestamp(); 60 base::TimeDelta expected_timestamp = output_timestamp_helper_.GetTimestamp();
61 base::TimeDelta delta = timestamp - expected_timestamp; 61 base::TimeDelta delta = timestamp - expected_timestamp;
62 62
63 if (std::abs(delta.InMilliseconds()) > kMaxTimeDeltaInMilliseconds) { 63 if (std::abs(delta.InMilliseconds()) > kMaxTimeDeltaInMilliseconds) {
64 DVLOG(1) << "Timestamp delta too large: " << delta.InMicroseconds() << "us"; 64 DVLOG(1) << "Timestamp delta too large: " << delta.InMicroseconds() << "us";
65 return false; 65 return false;
66 } 66 }
67 67
68 int bytes_to_fill = 0; 68 int bytes_to_fill = 0;
69 if (delta != base::TimeDelta()) 69 if (delta != base::TimeDelta())
70 bytes_to_fill = output_timestamp_helper_.GetBytesToTarget(timestamp); 70 bytes_to_fill = output_timestamp_helper_.GetBytesToTarget(timestamp);
71 71
72 if (bytes_to_fill == 0 || std::abs(bytes_to_fill) < min_gap_size_) { 72 if (bytes_to_fill == 0 || std::abs(bytes_to_fill) < min_gap_size_) {
73 AddOutputBuffer(input); 73 AddOutputBuffer(input);
74 return true; 74 return true;
75 } 75 }
76 76
77 if (bytes_to_fill > 0) { 77 if (bytes_to_fill > 0) {
78 DVLOG(1) << "Gap detected @ " << expected_timestamp.InMicroseconds() 78 DVLOG(1) << "Gap detected @ " << expected_timestamp.InMicroseconds()
79 << " us: " << delta.InMicroseconds() << " us"; 79 << " us: " << delta.InMicroseconds() << " us";
80 80
81 // Create a buffer with enough silence samples to fill the gap and 81 // Create a buffer with enough silence samples to fill the gap and
82 // add it to the output buffer. 82 // add it to the output buffer.
83 scoped_refptr<DataBuffer> gap = new DataBuffer(bytes_to_fill); 83 scoped_refptr<DataBuffer> gap = new DataBuffer(bytes_to_fill);
84 gap->SetDataSize(bytes_to_fill); 84 gap->set_data_size(bytes_to_fill);
85 memset(gap->GetWritableData(), 0, bytes_to_fill); 85 memset(gap->writable_data(), 0, bytes_to_fill);
86 gap->SetTimestamp(expected_timestamp); 86 gap->set_timestamp(expected_timestamp);
87 gap->SetDuration(output_timestamp_helper_.GetDuration(bytes_to_fill)); 87 gap->set_duration(output_timestamp_helper_.GetDuration(bytes_to_fill));
88 AddOutputBuffer(gap); 88 AddOutputBuffer(gap);
89 89
90 // Add the input buffer now that the gap has been filled. 90 // Add the input buffer now that the gap has been filled.
91 AddOutputBuffer(input); 91 AddOutputBuffer(input);
92 return true; 92 return true;
93 } 93 }
94 94
95 int bytes_to_skip = -bytes_to_fill; 95 int bytes_to_skip = -bytes_to_fill;
96 96
97 DVLOG(1) << "Overlap detected @ " << expected_timestamp.InMicroseconds() 97 DVLOG(1) << "Overlap detected @ " << expected_timestamp.InMicroseconds()
98 << " us: " << -delta.InMicroseconds() << " us"; 98 << " us: " << -delta.InMicroseconds() << " us";
99 99
100 if (input->GetDataSize() <= bytes_to_skip) { 100 if (input->data_size() <= bytes_to_skip) {
101 DVLOG(1) << "Dropping whole buffer"; 101 DVLOG(1) << "Dropping whole buffer";
102 return true; 102 return true;
103 } 103 }
104 104
105 // Copy the trailing samples that do not overlap samples already output 105 // Copy the trailing samples that do not overlap samples already output
106 // into a new buffer. Add this new buffer to the output queue. 106 // into a new buffer. Add this new buffer to the output queue.
107 // 107 //
108 // TODO(acolwell): Implement a cross-fade here so the transition is less 108 // TODO(acolwell): Implement a cross-fade here so the transition is less
109 // jarring. 109 // jarring.
110 int new_buffer_size = input->GetDataSize() - bytes_to_skip; 110 int new_buffer_size = input->data_size() - bytes_to_skip;
111 111
112 scoped_refptr<DataBuffer> new_buffer = new DataBuffer(new_buffer_size); 112 scoped_refptr<DataBuffer> new_buffer = new DataBuffer(new_buffer_size);
113 new_buffer->SetDataSize(new_buffer_size); 113 new_buffer->set_data_size(new_buffer_size);
114 memcpy(new_buffer->GetWritableData(), 114 memcpy(new_buffer->writable_data(),
115 input->GetData() + bytes_to_skip, 115 input->data() + bytes_to_skip,
116 new_buffer_size); 116 new_buffer_size);
117 new_buffer->SetTimestamp(expected_timestamp); 117 new_buffer->set_timestamp(expected_timestamp);
118 new_buffer->SetDuration( 118 new_buffer->set_duration(
119 output_timestamp_helper_.GetDuration(new_buffer_size)); 119 output_timestamp_helper_.GetDuration(new_buffer_size));
120 AddOutputBuffer(new_buffer); 120 AddOutputBuffer(new_buffer);
121 return true; 121 return true;
122 } 122 }
123 123
124 bool AudioSplicer::HasNextBuffer() const { 124 bool AudioSplicer::HasNextBuffer() const {
125 return !output_buffers_.empty(); 125 return !output_buffers_.empty();
126 } 126 }
127 127
128 scoped_refptr<DataBuffer> AudioSplicer::GetNextBuffer() { 128 scoped_refptr<DataBuffer> AudioSplicer::GetNextBuffer() {
129 scoped_refptr<DataBuffer> ret = output_buffers_.front(); 129 scoped_refptr<DataBuffer> ret = output_buffers_.front();
130 output_buffers_.pop_front(); 130 output_buffers_.pop_front();
131 return ret; 131 return ret;
132 } 132 }
133 133
134 void AudioSplicer::AddOutputBuffer(const scoped_refptr<DataBuffer>& buffer) { 134 void AudioSplicer::AddOutputBuffer(const scoped_refptr<DataBuffer>& buffer) {
135 output_timestamp_helper_.AddBytes(buffer->GetDataSize()); 135 output_timestamp_helper_.AddBytes(buffer->data_size());
136 output_buffers_.push_back(buffer); 136 output_buffers_.push_back(buffer);
137 } 137 }
138 138
139 } // namespace media 139 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_low_latency_input_mac.cc ('k') | media/base/audio_splicer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698