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

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

Issue 293053005: Add support for complete buffer discards. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_discard_helper_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_discard_helper.h" 5 #include "media/base/audio_discard_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/audio_buffer.h" 10 #include "media/base/audio_buffer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 return false; 80 return false;
81 } 81 }
82 82
83 const size_t original_frame_count = decoded_buffer->frame_count(); 83 const size_t original_frame_count = decoded_buffer->frame_count();
84 84
85 // If there's a one buffer delay for decoding, pick up the last encoded 85 // If there's a one buffer delay for decoding, pick up the last encoded
86 // buffer's discard padding for processing with the current decoded buffer. 86 // buffer's discard padding for processing with the current decoded buffer.
87 DecoderBuffer::DiscardPadding current_discard_padding = 87 DecoderBuffer::DiscardPadding current_discard_padding =
88 encoded_buffer->discard_padding(); 88 encoded_buffer->discard_padding();
89 if (delayed_discard_) 89 if (delayed_discard_) {
90 // For simplicity disallow cases where decoder delay is present with delayed
91 // discard (no codecs at present). Doing so allows us to avoid complexity
92 // around endpoint tracking when handling complete buffer discards.
93 DCHECK_EQ(decoder_delay_, 0u);
90 std::swap(current_discard_padding, delayed_discard_padding_); 94 std::swap(current_discard_padding, delayed_discard_padding_);
95 }
91 96
92 if (discard_frames_ > 0) { 97 if (discard_frames_ > 0) {
93 const size_t decoded_frames = decoded_buffer->frame_count(); 98 const size_t decoded_frames = decoded_buffer->frame_count();
94 const size_t frames_to_discard = std::min(discard_frames_, decoded_frames); 99 const size_t frames_to_discard = std::min(discard_frames_, decoded_frames);
95 discard_frames_ -= frames_to_discard; 100 discard_frames_ -= frames_to_discard;
96 101
97 // If everything would be discarded, indicate a new buffer is required. 102 // If everything would be discarded, indicate a new buffer is required.
98 if (frames_to_discard == decoded_frames) { 103 if (frames_to_discard == decoded_frames) {
99 // For simplicity disallow cases where a buffer with discard padding is 104 // For simplicity disallow cases where a buffer with discard padding is
100 // present. Doing so allows us to avoid complexity around tracking 105 // present. Doing so allows us to avoid complexity around tracking
101 // discards across buffers. 106 // discards across buffers.
102 DCHECK(current_discard_padding.first == base::TimeDelta()); 107 DCHECK(current_discard_padding.first == base::TimeDelta());
103 DCHECK(current_discard_padding.second == base::TimeDelta()); 108 DCHECK(current_discard_padding.second == base::TimeDelta());
104 return false; 109 return false;
105 } 110 }
106 111
107 decoded_buffer->TrimStart(frames_to_discard); 112 decoded_buffer->TrimStart(frames_to_discard);
108 } 113 }
109 114
110 // Handle front discard padding. 115 // Handle front discard padding.
111 if (current_discard_padding.first > base::TimeDelta()) { 116 if (current_discard_padding.first > base::TimeDelta()) {
112 const size_t decoded_frames = decoded_buffer->frame_count(); 117 const size_t decoded_frames = decoded_buffer->frame_count();
118
119 // If a complete buffer discard is requested and there's no decoder delay,
120 // just discard all remaining frames from this buffer. With decoder delay
121 // we have to estimate the correct number of frames to discard based on the
122 // duration of the encoded buffer.
113 const size_t start_frames_to_discard = 123 const size_t start_frames_to_discard =
114 TimeDeltaToFrames(current_discard_padding.first); 124 current_discard_padding.first == kInfiniteDuration()
125 ? (decoder_delay_ > 0
126 ? TimeDeltaToFrames(encoded_buffer->duration())
127 : decoded_frames)
128 : TimeDeltaToFrames(current_discard_padding.first);
115 129
116 // Regardless of the timestamp on the encoded buffer, the corresponding 130 // Regardless of the timestamp on the encoded buffer, the corresponding
117 // decoded output will appear |decoder_delay_| frames later. 131 // decoded output will appear |decoder_delay_| frames later.
118 size_t discard_start = decoder_delay_; 132 size_t discard_start = decoder_delay_;
119 if (decoder_delay_ > 0) { 133 if (decoder_delay_ > 0) {
120 // If we have a |decoder_delay_| and have already discarded frames from 134 // If we have a |decoder_delay_| and have already discarded frames from
121 // this buffer, the |discard_start| must be adjusted by the number of 135 // this buffer, the |discard_start| must be adjusted by the number of
122 // frames already discarded. 136 // frames already discarded.
123 const size_t frames_discarded_so_far = 137 const size_t frames_discarded_so_far =
124 original_frame_count - decoded_buffer->frame_count(); 138 original_frame_count - decoded_buffer->frame_count();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DCHECK(current_discard_padding.second == base::TimeDelta()); 190 DCHECK(current_discard_padding.second == base::TimeDelta());
177 } 191 }
178 192
179 // Assign timestamp to the buffer. 193 // Assign timestamp to the buffer.
180 decoded_buffer->set_timestamp(timestamp_helper_.GetTimestamp()); 194 decoded_buffer->set_timestamp(timestamp_helper_.GetTimestamp());
181 timestamp_helper_.AddFrames(decoded_buffer->frame_count()); 195 timestamp_helper_.AddFrames(decoded_buffer->frame_count());
182 return true; 196 return true;
183 } 197 }
184 198
185 } // namespace media 199 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_discard_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698