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

Side by Side Diff: media/formats/mp2t/es_adapter_video.cc

Issue 712593003: Move key frame flag from StreamParserBuffer to DecoderBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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/formats/mp2t/es_adapter_video.h" 5 #include "media/formats/mp2t/es_adapter_video.h"
6 6
7 #include "media/base/buffers.h" 7 #include "media/base/buffers.h"
8 #include "media/base/stream_parser_buffer.h" 8 #include "media/base/stream_parser_buffer.h"
9 #include "media/base/video_decoder_config.h" 9 #include "media/base/video_decoder_config.h"
10 #include "media/formats/mp2t/mp2t_common.h" 10 #include "media/formats/mp2t/mp2t_common.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 min_dts_ = stream_parser_buffer->GetDecodeTimestamp(); 105 min_dts_ = stream_parser_buffer->GetDecodeTimestamp();
106 has_valid_initial_timestamp_ = true; 106 has_valid_initial_timestamp_ = true;
107 } 107 }
108 if (stream_parser_buffer->timestamp() < min_pts_) 108 if (stream_parser_buffer->timestamp() < min_pts_)
109 min_pts_ = stream_parser_buffer->timestamp(); 109 min_pts_ = stream_parser_buffer->timestamp();
110 110
111 // Discard the incoming frame: 111 // Discard the incoming frame:
112 // - if it is not associated with any config, 112 // - if it is not associated with any config,
113 // - or if no valid key frame has been found so far. 113 // - or if no valid key frame has been found so far.
114 if (!has_valid_config_ || 114 if (!has_valid_config_ ||
115 (!has_valid_frame_ && !stream_parser_buffer->IsKeyframe())) { 115 (!has_valid_frame_ && !stream_parser_buffer->is_keyframe())) {
116 discarded_frame_count_++; 116 discarded_frame_count_++;
117 return true; 117 return true;
118 } 118 }
119 119
120 has_valid_frame_ = true; 120 has_valid_frame_ = true;
121 121
122 if (discarded_frame_count_ > 0) 122 if (discarded_frame_count_ > 0)
123 ReplaceDiscardedFrames(stream_parser_buffer); 123 ReplaceDiscardedFrames(stream_parser_buffer);
124 124
125 buffer_list_.push_back(stream_parser_buffer); 125 buffer_list_.push_back(stream_parser_buffer);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (next_pts == kNoTimestamp() || next_pts > *it) 189 if (next_pts == kNoTimestamp() || next_pts > *it)
190 next_pts = *it; 190 next_pts = *it;
191 } 191 }
192 192
193 return next_pts; 193 return next_pts;
194 } 194 }
195 195
196 void EsAdapterVideo::ReplaceDiscardedFrames( 196 void EsAdapterVideo::ReplaceDiscardedFrames(
197 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer) { 197 const scoped_refptr<StreamParserBuffer>& stream_parser_buffer) {
198 DCHECK_GT(discarded_frame_count_, 0); 198 DCHECK_GT(discarded_frame_count_, 0);
199 DCHECK(stream_parser_buffer->IsKeyframe()); 199 DCHECK(stream_parser_buffer->is_keyframe());
200 200
201 // PTS/DTS are interpolated between the min PTS/DTS of discarded frames 201 // PTS/DTS are interpolated between the min PTS/DTS of discarded frames
202 // and the PTS/DTS of the first valid buffer. 202 // and the PTS/DTS of the first valid buffer.
203 // Note: |pts_delta| and |dts_delta| are calculated using integer division. 203 // Note: |pts_delta| and |dts_delta| are calculated using integer division.
204 // Interpolation thus accumulutes small errors. However, since timestamps 204 // Interpolation thus accumulutes small errors. However, since timestamps
205 // are given in microseconds, only a high number of discarded frames 205 // are given in microseconds, only a high number of discarded frames
206 // (in the order of 10000s) could have an impact and create a gap (from MSE 206 // (in the order of 10000s) could have an impact and create a gap (from MSE
207 // point of view) between the last interpolated frame and 207 // point of view) between the last interpolated frame and
208 // |stream_parser_buffer|. 208 // |stream_parser_buffer|.
209 base::TimeDelta pts = min_pts_; 209 base::TimeDelta pts = min_pts_;
210 base::TimeDelta pts_delta = 210 base::TimeDelta pts_delta =
211 (stream_parser_buffer->timestamp() - pts) / discarded_frame_count_; 211 (stream_parser_buffer->timestamp() - pts) / discarded_frame_count_;
212 DecodeTimestamp dts = min_dts_; 212 DecodeTimestamp dts = min_dts_;
213 base::TimeDelta dts_delta = 213 base::TimeDelta dts_delta =
214 (stream_parser_buffer->GetDecodeTimestamp() - dts) / 214 (stream_parser_buffer->GetDecodeTimestamp() - dts) /
215 discarded_frame_count_; 215 discarded_frame_count_;
216 216
217 for (int i = 0; i < discarded_frame_count_; i++) { 217 for (int i = 0; i < discarded_frame_count_; i++) {
218 scoped_refptr<StreamParserBuffer> frame = 218 scoped_refptr<StreamParserBuffer> frame =
219 StreamParserBuffer::CopyFrom( 219 StreamParserBuffer::CopyFrom(
220 stream_parser_buffer->data(), 220 stream_parser_buffer->data(),
221 stream_parser_buffer->data_size(), 221 stream_parser_buffer->data_size(),
222 stream_parser_buffer->IsKeyframe(), 222 stream_parser_buffer->is_keyframe(),
223 stream_parser_buffer->type(), 223 stream_parser_buffer->type(),
224 stream_parser_buffer->track_id()); 224 stream_parser_buffer->track_id());
225 frame->SetDecodeTimestamp(dts); 225 frame->SetDecodeTimestamp(dts);
226 frame->set_timestamp(pts); 226 frame->set_timestamp(pts);
227 frame->set_duration(pts_delta); 227 frame->set_duration(pts_delta);
228 buffer_list_.push_back(frame); 228 buffer_list_.push_back(frame);
229 pts += pts_delta; 229 pts += pts_delta;
230 dts += dts_delta; 230 dts += dts_delta;
231 } 231 }
232 discarded_frame_count_ = 0; 232 discarded_frame_count_ = 0;
233 } 233 }
234 234
235 } // namespace mp2t 235 } // namespace mp2t
236 } // namespace media 236 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698