+ if (stream_parser_buffer->timestamp() == kNoTimestamp()) {
+ if (has_valid_frame_) {
+ // There is currently no error concealment for a missing timestamp
+ // in the middle of the stream.
+ DVLOG(1) << "Missing timestamp in the middle of the stream";
+ return false;
+ }
+
+ if (!has_valid_initial_timestamp_) {
+ // MPEG-2 TS requires the first access unit to be given a timestamp.
+ // However, some streams do not comply with this requirement.
+ // So simply drop the frame if it is a leading frame with no timestamp.
+ DVLOG(1)
+ << "Stream not compliant: ignoring leading frame with no timestamp";
+ return true;
+ }
+
+ // In all the other cases, this frame will be replaced by the following
+ // valid key frame, using timestamp interpolation.
+ DCHECK(has_valid_initial_timestamp_);
+ DCHECK_GE(discarded_frame_count_, 1);
+ discarded_frame_count_++;
+ return true;
+ }
+
+ // At this point, timestamps of the incoming frame are valid.
+ if (!has_valid_initial_timestamp_) {
+ min_pts_ = stream_parser_buffer->timestamp();
+ min_dts_ = stream_parser_buffer->GetDecodeTimestamp();
+ has_valid_initial_timestamp_ = true;
+ }
+ if (stream_parser_buffer->timestamp() < min_pts_)
+ min_pts_ = stream_parser_buffer->timestamp();
+