| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "media/base/buffers.h" | 6 #include "media/base/buffers.h" |
| 7 #include "media/base/pts_stream.h" | 7 #include "media/base/pts_stream.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 Flush(); | 24 Flush(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void PtsStream::Flush() { | 27 void PtsStream::Flush() { |
| 28 while (!pts_heap_.IsEmpty()) | 28 while (!pts_heap_.IsEmpty()) |
| 29 pts_heap_.Pop(); | 29 pts_heap_.Pop(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PtsStream::EnqueuePts(StreamSample* sample) { | 32 void PtsStream::EnqueuePts(StreamSample* sample) { |
| 33 DCHECK(sample); | 33 DCHECK(sample); |
| 34 if (!sample->IsEndOfStream() && sample->GetTimestamp() != kNoTimestamp) { | 34 if (!sample->IsEndOfStream() && sample->GetTimestamp() != kNoTimestamp()) { |
| 35 pts_heap_.Push(sample->GetTimestamp()); | 35 pts_heap_.Push(sample->GetTimestamp()); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 void PtsStream::UpdatePtsAndDuration(StreamSample* sample) { | 39 void PtsStream::UpdatePtsAndDuration(StreamSample* sample) { |
| 40 // First search the |sample| for the pts. This is the most authoritative. | 40 // First search the |sample| for the pts. This is the most authoritative. |
| 41 // Make a special exclusion for the value pts == 0. Though this is | 41 // Make a special exclusion for the value pts == 0. Though this is |
| 42 // technically a valid value, it seems a number of FFmpeg codecs will | 42 // technically a valid value, it seems a number of FFmpeg codecs will |
| 43 // mistakenly always set pts to 0. | 43 // mistakenly always set pts to 0. |
| 44 // | 44 // |
| 45 // TODO(scherkus): FFmpegVideoDecodeEngine should be able to detect this | 45 // TODO(scherkus): FFmpegVideoDecodeEngine should be able to detect this |
| 46 // situation and set the timestamp to kInvalidTimestamp. | 46 // situation and set the timestamp to kInvalidTimestamp. |
| 47 DCHECK(sample); | 47 DCHECK(sample); |
| 48 base::TimeDelta timestamp = sample->GetTimestamp(); | 48 base::TimeDelta timestamp = sample->GetTimestamp(); |
| 49 if (timestamp != kNoTimestamp && | 49 if (timestamp != kNoTimestamp() && |
| 50 timestamp.ToInternalValue() != 0) { | 50 timestamp.ToInternalValue() != 0) { |
| 51 current_pts_ = timestamp; | 51 current_pts_ = timestamp; |
| 52 // We need to clean up the timestamp we pushed onto the |pts_heap_|. | 52 // We need to clean up the timestamp we pushed onto the |pts_heap_|. |
| 53 if (!pts_heap_.IsEmpty()) | 53 if (!pts_heap_.IsEmpty()) |
| 54 pts_heap_.Pop(); | 54 pts_heap_.Pop(); |
| 55 } else if (!pts_heap_.IsEmpty()) { | 55 } else if (!pts_heap_.IsEmpty()) { |
| 56 // If the frame did not have pts, try to get the pts from the |pts_heap|. | 56 // If the frame did not have pts, try to get the pts from the |pts_heap|. |
| 57 current_pts_ = pts_heap_.Top(); | 57 current_pts_ = pts_heap_.Top(); |
| 58 pts_heap_.Pop(); | 58 pts_heap_.Pop(); |
| 59 } else if (current_pts_ != kNoTimestamp) { | 59 } else if (current_pts_ != kNoTimestamp()) { |
| 60 // Guess assuming this frame was the same as the last frame. | 60 // Guess assuming this frame was the same as the last frame. |
| 61 current_pts_ = current_pts_ + current_duration_; | 61 current_pts_ = current_pts_ + current_duration_; |
| 62 } else { | 62 } else { |
| 63 // Now we really have no clue!!! Mark an invalid timestamp and let the | 63 // Now we really have no clue!!! Mark an invalid timestamp and let the |
| 64 // video renderer handle it (i.e., drop frame). | 64 // video renderer handle it (i.e., drop frame). |
| 65 current_pts_ = kNoTimestamp; | 65 current_pts_ = kNoTimestamp(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Fill in the duration, using the frame itself as the authoratative source. | 68 // Fill in the duration, using the frame itself as the authoratative source. |
| 69 base::TimeDelta duration = sample->GetDuration(); | 69 base::TimeDelta duration = sample->GetDuration(); |
| 70 if (duration != kNoTimestamp && | 70 if (duration != kNoTimestamp() && |
| 71 duration.ToInternalValue() != 0) { | 71 duration.ToInternalValue() != 0) { |
| 72 current_duration_ = duration; | 72 current_duration_ = duration; |
| 73 } else { | 73 } else { |
| 74 // Otherwise assume a normal frame duration. | 74 // Otherwise assume a normal frame duration. |
| 75 current_duration_ = default_duration_; | 75 current_duration_ = default_duration_; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace media | 79 } // namespace media |
| OLD | NEW |