| OLD | NEW |
| 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/mp2t_stream_parser.h" | 5 #include "media/formats/mp2t/mp2t_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // stream parser already involves the end of the current segment. | 211 // stream parser already involves the end of the current segment. |
| 212 segment_started_ = false; | 212 segment_started_ = false; |
| 213 | 213 |
| 214 // Remove any bytes left in the TS buffer. | 214 // Remove any bytes left in the TS buffer. |
| 215 // (i.e. any partial TS packet => less than 188 bytes). | 215 // (i.e. any partial TS packet => less than 188 bytes). |
| 216 ts_byte_queue_.Reset(); | 216 ts_byte_queue_.Reset(); |
| 217 | 217 |
| 218 // Reset the selected PIDs. | 218 // Reset the selected PIDs. |
| 219 selected_audio_pid_ = -1; | 219 selected_audio_pid_ = -1; |
| 220 selected_video_pid_ = -1; | 220 selected_video_pid_ = -1; |
| 221 |
| 222 // Reset the timestamp unroller. |
| 223 timestamp_unroller_.Reset(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 bool Mp2tStreamParser::Parse(const uint8* buf, int size) { | 226 bool Mp2tStreamParser::Parse(const uint8* buf, int size) { |
| 224 DVLOG(1) << "Mp2tStreamParser::Parse size=" << size; | 227 DVLOG(1) << "Mp2tStreamParser::Parse size=" << size; |
| 225 | 228 |
| 226 // Add the data to the parser state. | 229 // Add the data to the parser state. |
| 227 ts_byte_queue_.Push(buf, size); | 230 ts_byte_queue_.Push(buf, size); |
| 228 | 231 |
| 229 while (true) { | 232 while (true) { |
| 230 const uint8* ts_buffer; | 233 const uint8* ts_buffer; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 pes_pid), | 364 pes_pid), |
| 362 log_cb_)); | 365 log_cb_)); |
| 363 is_audio = true; | 366 is_audio = true; |
| 364 } else { | 367 } else { |
| 365 return; | 368 return; |
| 366 } | 369 } |
| 367 | 370 |
| 368 // Create the PES state here. | 371 // Create the PES state here. |
| 369 DVLOG(1) << "Create a new PES state"; | 372 DVLOG(1) << "Create a new PES state"; |
| 370 scoped_ptr<TsSection> pes_section_parser( | 373 scoped_ptr<TsSection> pes_section_parser( |
| 371 new TsSectionPes(es_parser.Pass())); | 374 new TsSectionPes(es_parser.Pass(), ×tamp_unroller_)); |
| 372 PidState::PidType pid_type = | 375 PidState::PidType pid_type = |
| 373 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; | 376 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; |
| 374 scoped_ptr<PidState> pes_pid_state( | 377 scoped_ptr<PidState> pes_pid_state( |
| 375 new PidState(pes_pid, pid_type, pes_section_parser.Pass())); | 378 new PidState(pes_pid, pid_type, pes_section_parser.Pass())); |
| 376 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); | 379 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); |
| 377 | 380 |
| 378 // A new PES pid has been added, the PID filter might change. | 381 // A new PES pid has been added, the PID filter might change. |
| 379 UpdatePidFilter(); | 382 UpdatePidFilter(); |
| 380 } | 383 } |
| 381 | 384 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 DVLOG(LOG_LEVEL_ES) | 527 DVLOG(LOG_LEVEL_ES) |
| 525 << "OnEmitAudioBuffer: " | 528 << "OnEmitAudioBuffer: " |
| 526 << " size=" | 529 << " size=" |
| 527 << stream_parser_buffer->data_size() | 530 << stream_parser_buffer->data_size() |
| 528 << " dts=" | 531 << " dts=" |
| 529 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() | 532 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() |
| 530 << " pts=" | 533 << " pts=" |
| 531 << stream_parser_buffer->timestamp().InMilliseconds() | 534 << stream_parser_buffer->timestamp().InMilliseconds() |
| 532 << " dur=" | 535 << " dur=" |
| 533 << stream_parser_buffer->duration().InMilliseconds(); | 536 << stream_parser_buffer->duration().InMilliseconds(); |
| 534 stream_parser_buffer->set_timestamp( | |
| 535 stream_parser_buffer->timestamp() - time_offset_); | |
| 536 stream_parser_buffer->SetDecodeTimestamp( | |
| 537 stream_parser_buffer->GetDecodeTimestamp() - time_offset_); | |
| 538 | 537 |
| 539 // Ignore the incoming buffer if it is not associated with any config. | 538 // Ignore the incoming buffer if it is not associated with any config. |
| 540 if (buffer_queue_chain_.empty()) { | 539 if (buffer_queue_chain_.empty()) { |
| 541 NOTREACHED() << "Cannot provide buffers before configs"; | 540 NOTREACHED() << "Cannot provide buffers before configs"; |
| 542 return; | 541 return; |
| 543 } | 542 } |
| 544 | 543 |
| 545 buffer_queue_chain_.back().audio_queue.push_back(stream_parser_buffer); | 544 buffer_queue_chain_.back().audio_queue.push_back(stream_parser_buffer); |
| 546 } | 545 } |
| 547 | 546 |
| 548 void Mp2tStreamParser::OnEmitVideoBuffer( | 547 void Mp2tStreamParser::OnEmitVideoBuffer( |
| 549 int pes_pid, | 548 int pes_pid, |
| 550 scoped_refptr<StreamParserBuffer> stream_parser_buffer) { | 549 scoped_refptr<StreamParserBuffer> stream_parser_buffer) { |
| 551 DCHECK_EQ(pes_pid, selected_video_pid_); | 550 DCHECK_EQ(pes_pid, selected_video_pid_); |
| 552 | 551 |
| 553 DVLOG(LOG_LEVEL_ES) | 552 DVLOG(LOG_LEVEL_ES) |
| 554 << "OnEmitVideoBuffer" | 553 << "OnEmitVideoBuffer" |
| 555 << " size=" | 554 << " size=" |
| 556 << stream_parser_buffer->data_size() | 555 << stream_parser_buffer->data_size() |
| 557 << " dts=" | 556 << " dts=" |
| 558 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() | 557 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() |
| 559 << " pts=" | 558 << " pts=" |
| 560 << stream_parser_buffer->timestamp().InMilliseconds() | 559 << stream_parser_buffer->timestamp().InMilliseconds() |
| 561 << " dur=" | 560 << " dur=" |
| 562 << stream_parser_buffer->duration().InMilliseconds() | 561 << stream_parser_buffer->duration().InMilliseconds() |
| 563 << " IsKeyframe=" | 562 << " IsKeyframe=" |
| 564 << stream_parser_buffer->IsKeyframe(); | 563 << stream_parser_buffer->IsKeyframe(); |
| 565 stream_parser_buffer->set_timestamp( | |
| 566 stream_parser_buffer->timestamp() - time_offset_); | |
| 567 stream_parser_buffer->SetDecodeTimestamp( | |
| 568 stream_parser_buffer->GetDecodeTimestamp() - time_offset_); | |
| 569 | 564 |
| 570 // Ignore the incoming buffer if it is not associated with any config. | 565 // Ignore the incoming buffer if it is not associated with any config. |
| 571 if (buffer_queue_chain_.empty()) { | 566 if (buffer_queue_chain_.empty()) { |
| 572 NOTREACHED() << "Cannot provide buffers before configs"; | 567 NOTREACHED() << "Cannot provide buffers before configs"; |
| 573 return; | 568 return; |
| 574 } | 569 } |
| 575 | 570 |
| 576 buffer_queue_chain_.back().video_queue.push_back(stream_parser_buffer); | 571 buffer_queue_chain_.back().video_queue.push_back(stream_parser_buffer); |
| 577 } | 572 } |
| 578 | 573 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 // so that buffers with the same config can be added later on. | 630 // so that buffers with the same config can be added later on. |
| 636 BufferQueueWithConfig queue_with_config( | 631 BufferQueueWithConfig queue_with_config( |
| 637 true, last_audio_config, last_video_config); | 632 true, last_audio_config, last_video_config); |
| 638 buffer_queue_chain_.push_back(queue_with_config); | 633 buffer_queue_chain_.push_back(queue_with_config); |
| 639 | 634 |
| 640 return true; | 635 return true; |
| 641 } | 636 } |
| 642 | 637 |
| 643 } // namespace mp2t | 638 } // namespace mp2t |
| 644 } // namespace media | 639 } // namespace media |
| OLD | NEW |