Index: media/filters/frame_processor.cc |
diff --git a/media/filters/frame_processor.cc b/media/filters/frame_processor.cc |
index a10ed5017ed50814a2269dd0fde06d8fa3189618..b50c34f634742f55ffcc00098f36e25d1125f5ac 100644 |
--- a/media/filters/frame_processor.cc |
+++ b/media/filters/frame_processor.cc |
@@ -332,18 +332,15 @@ bool FrameProcessor::HandlePartialAppendWindowTrimming( |
const scoped_refptr<StreamParserBuffer>& buffer) { |
DCHECK(buffer->duration() > base::TimeDelta()); |
DCHECK_EQ(DemuxerStream::AUDIO, buffer->type()); |
+ DCHECK(buffer->IsKeyframe()); |
const base::TimeDelta frame_end_timestamp = |
buffer->timestamp() + buffer->duration(); |
- // Ignore any buffers which start after |append_window_start| or end after |
- // |append_window_end|. For simplicity, even those that start before |
- // |append_window_start|. |
- if (buffer->timestamp() > append_window_start || |
- frame_end_timestamp > append_window_end) { |
- // TODO(dalecurtis): Partial append window trimming could also be done |
- // around |append_window_end|, but is not necessary since splice frames |
- // cover overlaps there. |
+ // Ignore any buffers entirely after or inside of the append window. |
+ if (buffer->timestamp() > append_window_end || |
+ (buffer->timestamp() > append_window_start && |
+ frame_end_timestamp < append_window_end)) { |
return false; |
} |
@@ -360,44 +357,63 @@ bool FrameProcessor::HandlePartialAppendWindowTrimming( |
if (buffer->timestamp() == append_window_start && !audio_preroll_buffer_) |
return false; |
+ bool trimmed_buffer = false; |
+ |
// See if a partial discard can be done around |append_window_start|. |
- DCHECK(buffer->timestamp() <= append_window_start); |
- DCHECK(buffer->IsKeyframe()); |
- DVLOG(1) << "Truncating buffer which overlaps append window start." |
- << " presentation_timestamp " << buffer->timestamp().InSecondsF() |
- << " append_window_start " << append_window_start.InSecondsF(); |
- |
- // If this isn't the first buffer discarded by the append window, try to use |
- // the last buffer discarded for preroll. This ensures that the partially |
- // trimmed buffer can be correctly decoded. |
- if (audio_preroll_buffer_) { |
- // We only want to use the preroll buffer if it directly precedes (less than |
- // one sample apart) the current buffer. |
- const int64 delta = std::abs((audio_preroll_buffer_->timestamp() + |
- audio_preroll_buffer_->duration() - |
- buffer->timestamp()).InMicroseconds()); |
- if (delta < sample_duration_.InMicroseconds()) { |
- buffer->SetPrerollBuffer(audio_preroll_buffer_); |
- } else { |
- // TODO(dalecurtis): Add a MEDIA_LOG() for when this is dropped unused. |
+ if (buffer->timestamp() <= append_window_start) { |
+ DVLOG(1) << "Truncating buffer which overlaps append window start." |
+ << " presentation_timestamp " << buffer->timestamp().InSecondsF() |
+ << " frame_end_timestamp " << frame_end_timestamp.InSecondsF() |
+ << " append_window_start " << append_window_start.InSecondsF(); |
+ |
+ // If this isn't the first buffer discarded by the append window, try to use |
+ // the last buffer discarded for preroll. This ensures that the partially |
+ // trimmed buffer can be correctly decoded. |
+ if (audio_preroll_buffer_) { |
+ // We only want to use the preroll buffer if it directly precedes (less |
+ // than one sample apart) the current buffer. |
+ const int64 delta = std::abs((audio_preroll_buffer_->timestamp() + |
+ audio_preroll_buffer_->duration() - |
+ buffer->timestamp()).InMicroseconds()); |
+ if (delta < sample_duration_.InMicroseconds()) { |
+ buffer->SetPrerollBuffer(audio_preroll_buffer_); |
+ } else { |
+ // TODO(dalecurtis): Add a MEDIA_LOG() for when this is dropped unused. |
+ } |
+ audio_preroll_buffer_ = NULL; |
} |
- audio_preroll_buffer_ = NULL; |
+ |
+ // Decrease the duration appropriately. We only need to shorten the buffer |
+ // if it overlaps |append_window_start|. |
+ if (buffer->timestamp() < append_window_start) { |
+ buffer->set_discard_padding(std::make_pair( |
+ append_window_start - buffer->timestamp(), base::TimeDelta())); |
+ buffer->set_duration(frame_end_timestamp - append_window_start); |
+ } |
+ |
+ // Adjust the timestamp of this buffer forward to |append_window_start|. The |
+ // timestamps are always set, even if |buffer|'s timestamp is already set to |
+ // |append_window_start| to ensure the preroll buffer is setup correctly. |
+ buffer->set_timestamp(append_window_start); |
+ buffer->SetDecodeTimestamp(append_window_start); |
+ trimmed_buffer = true; |
} |
- // Decrease the duration appropriately. We only need to shorten the buffer if |
- // it overlaps |append_window_start|. |
- if (buffer->timestamp() < append_window_start) { |
- buffer->set_discard_padding(std::make_pair( |
- append_window_start - buffer->timestamp(), base::TimeDelta())); |
- buffer->set_duration(frame_end_timestamp - append_window_start); |
+ // See if a partial discard can be done around |append_window_end|. |
+ if (buffer->timestamp() <= append_window_end && |
acolwell GONE FROM CHROMIUM
2014/07/23 00:15:42
s/<=/</ ? How do you get into the == situation? It
DaleCurtis
2014/07/23 01:50:41
You're right, <= should have been skipped in the i
|
+ frame_end_timestamp > append_window_end) { |
+ DVLOG(1) << "Truncating buffer which overlaps append window end." |
+ << " presentation_timestamp " << buffer->timestamp().InSecondsF() |
+ << " frame_end_timestamp " << frame_end_timestamp.InSecondsF() |
+ << " append_window_end " << append_window_end.InSecondsF(); |
+ buffer->set_discard_padding( |
+ std::make_pair(buffer->discard_padding().first, |
+ frame_end_timestamp - append_window_end)); |
+ buffer->set_duration(append_window_end - buffer->timestamp()); |
+ trimmed_buffer = true; |
} |
- // Adjust the timestamp of this buffer forward to |append_window_start|. The |
- // timestamps are always set, even if |buffer|'s timestamp is already set to |
- // |append_window_start|, to ensure the preroll buffer is setup correctly. |
- buffer->set_timestamp(append_window_start); |
- buffer->SetDecodeTimestamp(append_window_start); |
- return true; |
+ return trimmed_buffer; |
} |
bool FrameProcessor::ProcessFrame( |
@@ -564,7 +580,7 @@ bool FrameProcessor::ProcessFrame( |
// 9. Let frame end timestamp equal the sum of presentation timestamp and |
// frame duration. |
- const base::TimeDelta frame_end_timestamp = |
+ base::TimeDelta frame_end_timestamp = |
presentation_timestamp + frame_duration; |
// 10. If presentation timestamp is less than appendWindowStart, then set |
@@ -593,9 +609,7 @@ bool FrameProcessor::ProcessFrame( |
// frame duration and reduces spurious discontinuity detection. |
decode_timestamp = frame->GetDecodeTimestamp(); |
presentation_timestamp = frame->timestamp(); |
- |
- // The end timestamp of the frame should be unchanged. |
- DCHECK(frame_end_timestamp == presentation_timestamp + frame->duration()); |
+ frame_end_timestamp = frame->timestamp() + frame->duration(); |
} |
if (presentation_timestamp < append_window_start || |