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

Unified Diff: media/formats/mp2t/mp2t_stream_parser.cc

Issue 364823008: Mpeg2TS - estimate duration for video frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix MEDIA_EXPORT needed by the ES adapter unit test. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/formats/mp2t/mp2t_stream_parser.h ('k') | media/formats/mp2t/mp2t_stream_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/formats/mp2t/mp2t_stream_parser.cc
diff --git a/media/formats/mp2t/mp2t_stream_parser.cc b/media/formats/mp2t/mp2t_stream_parser.cc
index 48497559d6a4bd502e9a72dba56eb29e71da2caf..2c659a2fa805ba508cc7dd9c0190eacf104b1b81 100644
--- a/media/formats/mp2t/mp2t_stream_parser.cc
+++ b/media/formats/mp2t/mp2t_stream_parser.cc
@@ -157,8 +157,7 @@ Mp2tStreamParser::Mp2tStreamParser(bool sbr_in_mimetype)
selected_audio_pid_(-1),
selected_video_pid_(-1),
is_initialized_(false),
- segment_started_(false),
- first_video_frame_in_segment_(true) {
+ segment_started_(false) {
}
Mp2tStreamParser::~Mp2tStreamParser() {
@@ -210,8 +209,6 @@ void Mp2tStreamParser::Flush() {
// Note: does not need to invoke |end_of_segment_cb_| since flushing the
// stream parser already involves the end of the current segment.
segment_started_ = false;
- first_video_frame_in_segment_ = true;
- discarded_frames_dts_.clear();
// Remove any bytes left in the TS buffer.
// (i.e. any partial TS packet => less than 188 bytes).
@@ -505,7 +502,9 @@ void Mp2tStreamParser::OnEmitAudioBuffer(
<< " dts="
<< stream_parser_buffer->GetDecodeTimestamp().InMilliseconds()
<< " pts="
- << stream_parser_buffer->timestamp().InMilliseconds();
+ << stream_parser_buffer->timestamp().InMilliseconds()
+ << " dur="
+ << stream_parser_buffer->duration().InMilliseconds();
stream_parser_buffer->set_timestamp(
stream_parser_buffer->timestamp() - time_offset_);
stream_parser_buffer->SetDecodeTimestamp(
@@ -513,7 +512,7 @@ void Mp2tStreamParser::OnEmitAudioBuffer(
// Ignore the incoming buffer if it is not associated with any config.
if (buffer_queue_chain_.empty()) {
- DVLOG(1) << "Ignoring audio buffer with no corresponding audio config";
+ NOTREACHED() << "Cannot provide buffers before configs";
return;
}
@@ -533,6 +532,8 @@ void Mp2tStreamParser::OnEmitVideoBuffer(
<< stream_parser_buffer->GetDecodeTimestamp().InMilliseconds()
<< " pts="
<< stream_parser_buffer->timestamp().InMilliseconds()
+ << " dur="
+ << stream_parser_buffer->duration().InMilliseconds()
<< " IsKeyframe="
<< stream_parser_buffer->IsKeyframe();
stream_parser_buffer->set_timestamp(
@@ -540,29 +541,12 @@ void Mp2tStreamParser::OnEmitVideoBuffer(
stream_parser_buffer->SetDecodeTimestamp(
stream_parser_buffer->GetDecodeTimestamp() - time_offset_);
- // Discard the incoming buffer:
- // - if it is not associated with any config,
- // - or if only non-key frames have been added to a new segment.
- if (buffer_queue_chain_.empty() ||
- (first_video_frame_in_segment_ && !stream_parser_buffer->IsKeyframe())) {
- DVLOG(1) << "Discard video buffer:"
- << " keyframe=" << stream_parser_buffer->IsKeyframe()
- << " dts="
- << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds();
- if (discarded_frames_dts_.empty() ||
- discarded_frames_min_pts_ > stream_parser_buffer->timestamp()) {
- discarded_frames_min_pts_ = stream_parser_buffer->timestamp();
- }
- discarded_frames_dts_.push_back(
- stream_parser_buffer->GetDecodeTimestamp());
+ // Ignore the incoming buffer if it is not associated with any config.
+ if (buffer_queue_chain_.empty()) {
+ NOTREACHED() << "Cannot provide buffers before configs";
return;
}
- // Fill the gap created by frames that have been discarded.
- if (!discarded_frames_dts_.empty())
- FillVideoGap(stream_parser_buffer);
-
- first_video_frame_in_segment_ = false;
buffer_queue_chain_.back().video_queue.push_back(stream_parser_buffer);
}
@@ -630,33 +614,5 @@ bool Mp2tStreamParser::EmitRemainingBuffers() {
return true;
}
-void Mp2tStreamParser::FillVideoGap(
- const scoped_refptr<StreamParserBuffer>& stream_parser_buffer) {
- DCHECK(!buffer_queue_chain_.empty());
- DCHECK(!discarded_frames_dts_.empty());
- DCHECK(stream_parser_buffer->IsKeyframe());
-
- // PTS is interpolated between the min PTS of discarded frames
- // and the PTS of the first valid buffer.
- base::TimeDelta pts = discarded_frames_min_pts_;
- base::TimeDelta pts_delta =
- (stream_parser_buffer->timestamp() - pts) / discarded_frames_dts_.size();
-
- while (!discarded_frames_dts_.empty()) {
- scoped_refptr<StreamParserBuffer> frame =
- StreamParserBuffer::CopyFrom(
- stream_parser_buffer->data(),
- stream_parser_buffer->data_size(),
- stream_parser_buffer->IsKeyframe(),
- stream_parser_buffer->type(),
- stream_parser_buffer->track_id());
- frame->SetDecodeTimestamp(discarded_frames_dts_.front());
- frame->set_timestamp(pts);
- buffer_queue_chain_.back().video_queue.push_back(frame);
- pts += pts_delta;
- discarded_frames_dts_.pop_front();
- }
-}
-
} // namespace mp2t
} // namespace media
« no previous file with comments | « media/formats/mp2t/mp2t_stream_parser.h ('k') | media/formats/mp2t/mp2t_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698