Chromium Code Reviews| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // stream parser already involves the end of the current segment. | 210 // stream parser already involves the end of the current segment. |
| 211 segment_started_ = false; | 211 segment_started_ = false; |
| 212 | 212 |
| 213 // Remove any bytes left in the TS buffer. | 213 // Remove any bytes left in the TS buffer. |
| 214 // (i.e. any partial TS packet => less than 188 bytes). | 214 // (i.e. any partial TS packet => less than 188 bytes). |
| 215 ts_byte_queue_.Reset(); | 215 ts_byte_queue_.Reset(); |
| 216 | 216 |
| 217 // Reset the selected PIDs. | 217 // Reset the selected PIDs. |
| 218 selected_audio_pid_ = -1; | 218 selected_audio_pid_ = -1; |
| 219 selected_video_pid_ = -1; | 219 selected_video_pid_ = -1; |
| 220 | |
| 221 // Reset the timestamp unroller. | |
| 222 timestamp_unroller_.Reset(); | |
| 220 } | 223 } |
| 221 | 224 |
| 222 bool Mp2tStreamParser::Parse(const uint8* buf, int size) { | 225 bool Mp2tStreamParser::Parse(const uint8* buf, int size) { |
| 223 DVLOG(1) << "Mp2tStreamParser::Parse size=" << size; | 226 DVLOG(1) << "Mp2tStreamParser::Parse size=" << size; |
| 224 | 227 |
| 225 // Add the data to the parser state. | 228 // Add the data to the parser state. |
| 226 ts_byte_queue_.Push(buf, size); | 229 ts_byte_queue_.Push(buf, size); |
| 227 | 230 |
| 228 while (true) { | 231 while (true) { |
| 229 const uint8* ts_buffer; | 232 const uint8* ts_buffer; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 pes_pid), | 352 pes_pid), |
| 350 sbr_in_mimetype_)); | 353 sbr_in_mimetype_)); |
| 351 is_audio = true; | 354 is_audio = true; |
| 352 } else { | 355 } else { |
| 353 return; | 356 return; |
| 354 } | 357 } |
| 355 | 358 |
| 356 // Create the PES state here. | 359 // Create the PES state here. |
| 357 DVLOG(1) << "Create a new PES state"; | 360 DVLOG(1) << "Create a new PES state"; |
| 358 scoped_ptr<TsSection> pes_section_parser( | 361 scoped_ptr<TsSection> pes_section_parser( |
| 359 new TsSectionPes(es_parser.Pass())); | 362 new TsSectionPes(es_parser.Pass(), ×tamp_unroller_)); |
| 360 PidState::PidType pid_type = | 363 PidState::PidType pid_type = |
| 361 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; | 364 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; |
| 362 scoped_ptr<PidState> pes_pid_state( | 365 scoped_ptr<PidState> pes_pid_state( |
| 363 new PidState(pes_pid, pid_type, pes_section_parser.Pass())); | 366 new PidState(pes_pid, pid_type, pes_section_parser.Pass())); |
| 364 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); | 367 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); |
| 365 | 368 |
| 366 // A new PES pid has been added, the PID filter might change. | 369 // A new PES pid has been added, the PID filter might change. |
| 367 UpdatePidFilter(); | 370 UpdatePidFilter(); |
| 368 } | 371 } |
| 369 | 372 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 DVLOG(LOG_LEVEL_ES) | 515 DVLOG(LOG_LEVEL_ES) |
| 513 << "OnEmitAudioBuffer: " | 516 << "OnEmitAudioBuffer: " |
| 514 << " size=" | 517 << " size=" |
| 515 << stream_parser_buffer->data_size() | 518 << stream_parser_buffer->data_size() |
| 516 << " dts=" | 519 << " dts=" |
| 517 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() | 520 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() |
| 518 << " pts=" | 521 << " pts=" |
| 519 << stream_parser_buffer->timestamp().InMilliseconds() | 522 << stream_parser_buffer->timestamp().InMilliseconds() |
| 520 << " dur=" | 523 << " dur=" |
| 521 << stream_parser_buffer->duration().InMilliseconds(); | 524 << stream_parser_buffer->duration().InMilliseconds(); |
| 522 stream_parser_buffer->set_timestamp( | |
| 523 stream_parser_buffer->timestamp() - time_offset_); | |
| 524 stream_parser_buffer->SetDecodeTimestamp( | |
| 525 stream_parser_buffer->GetDecodeTimestamp() - time_offset_); | |
| 526 | 525 |
| 527 // Ignore the incoming buffer if it is not associated with any config. | 526 // Ignore the incoming buffer if it is not associated with any config. |
| 528 if (buffer_queue_chain_.empty()) { | 527 if (buffer_queue_chain_.empty()) { |
| 529 NOTREACHED() << "Cannot provide buffers before configs"; | 528 NOTREACHED() << "Cannot provide buffers before configs"; |
| 530 return; | 529 return; |
| 531 } | 530 } |
| 532 | 531 |
| 533 buffer_queue_chain_.back().audio_queue.push_back(stream_parser_buffer); | 532 buffer_queue_chain_.back().audio_queue.push_back(stream_parser_buffer); |
| 534 } | 533 } |
| 535 | 534 |
| 536 void Mp2tStreamParser::OnEmitVideoBuffer( | 535 void Mp2tStreamParser::OnEmitVideoBuffer( |
| 537 int pes_pid, | 536 int pes_pid, |
| 538 scoped_refptr<StreamParserBuffer> stream_parser_buffer) { | 537 scoped_refptr<StreamParserBuffer> stream_parser_buffer) { |
| 539 DCHECK_EQ(pes_pid, selected_video_pid_); | 538 DCHECK_EQ(pes_pid, selected_video_pid_); |
| 540 | 539 |
| 541 DVLOG(LOG_LEVEL_ES) | 540 DVLOG(LOG_LEVEL_ES) |
| 542 << "OnEmitVideoBuffer" | 541 << "OnEmitVideoBuffer" |
| 543 << " size=" | 542 << " size=" |
| 544 << stream_parser_buffer->data_size() | 543 << stream_parser_buffer->data_size() |
| 545 << " dts=" | 544 << " dts=" |
| 546 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() | 545 << stream_parser_buffer->GetDecodeTimestamp().InMilliseconds() |
| 547 << " pts=" | 546 << " pts=" |
| 548 << stream_parser_buffer->timestamp().InMilliseconds() | 547 << stream_parser_buffer->timestamp().InMilliseconds() |
| 549 << " dur=" | 548 << " dur=" |
| 550 << stream_parser_buffer->duration().InMilliseconds() | 549 << stream_parser_buffer->duration().InMilliseconds() |
| 551 << " IsKeyframe=" | 550 << " IsKeyframe=" |
| 552 << stream_parser_buffer->IsKeyframe(); | 551 << stream_parser_buffer->IsKeyframe(); |
| 553 stream_parser_buffer->set_timestamp( | |
| 554 stream_parser_buffer->timestamp() - time_offset_); | |
| 555 stream_parser_buffer->SetDecodeTimestamp( | |
| 556 stream_parser_buffer->GetDecodeTimestamp() - time_offset_); | |
| 557 | 552 |
| 558 // Ignore the incoming buffer if it is not associated with any config. | 553 // Ignore the incoming buffer if it is not associated with any config. |
| 559 if (buffer_queue_chain_.empty()) { | 554 if (buffer_queue_chain_.empty()) { |
| 560 NOTREACHED() << "Cannot provide buffers before configs"; | 555 NOTREACHED() << "Cannot provide buffers before configs"; |
| 561 return; | 556 return; |
| 562 } | 557 } |
| 563 | 558 |
| 564 buffer_queue_chain_.back().video_queue.push_back(stream_parser_buffer); | 559 buffer_queue_chain_.back().video_queue.push_back(stream_parser_buffer); |
| 565 } | 560 } |
| 566 | 561 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 581 buffer_queue_chain_.back().video_config; | 576 buffer_queue_chain_.back().video_config; |
| 582 | 577 |
| 583 // Do not have all the configs, need more data. | 578 // Do not have all the configs, need more data. |
| 584 if (selected_audio_pid_ >= 0 && !last_audio_config.IsValidConfig()) | 579 if (selected_audio_pid_ >= 0 && !last_audio_config.IsValidConfig()) |
| 585 return true; | 580 return true; |
| 586 if (selected_video_pid_ >= 0 && !last_video_config.IsValidConfig()) | 581 if (selected_video_pid_ >= 0 && !last_video_config.IsValidConfig()) |
| 587 return true; | 582 return true; |
| 588 | 583 |
| 589 // Buffer emission. | 584 // Buffer emission. |
| 590 while (!buffer_queue_chain_.empty()) { | 585 while (!buffer_queue_chain_.empty()) { |
| 586 | |
|
damienv1
2014/09/05 23:02:20
Remove line.
| |
| 591 // Start a segment if needed. | 587 // Start a segment if needed. |
| 592 if (!segment_started_) { | 588 if (!segment_started_) { |
| 593 DVLOG(1) << "Starting a new segment"; | 589 DVLOG(1) << "Starting a new segment"; |
| 594 segment_started_ = true; | 590 segment_started_ = true; |
| 595 new_segment_cb_.Run(); | 591 new_segment_cb_.Run(); |
| 596 } | 592 } |
| 597 | 593 |
| 598 // Update the audio and video config if needed. | 594 // Update the audio and video config if needed. |
| 599 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 595 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
| 600 if (!queue_with_config.is_config_sent) { | 596 if (!queue_with_config.is_config_sent) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 623 // so that buffers with the same config can be added later on. | 619 // so that buffers with the same config can be added later on. |
| 624 BufferQueueWithConfig queue_with_config( | 620 BufferQueueWithConfig queue_with_config( |
| 625 true, last_audio_config, last_video_config); | 621 true, last_audio_config, last_video_config); |
| 626 buffer_queue_chain_.push_back(queue_with_config); | 622 buffer_queue_chain_.push_back(queue_with_config); |
| 627 | 623 |
| 628 return true; | 624 return true; |
| 629 } | 625 } |
| 630 | 626 |
| 631 } // namespace mp2t | 627 } // namespace mp2t |
| 632 } // namespace media | 628 } // namespace media |
| OLD | NEW |