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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "media/base/media_tracks.h" |
12 #include "media/base/stream_parser_buffer.h" | 13 #include "media/base/stream_parser_buffer.h" |
13 #include "media/base/text_track_config.h" | 14 #include "media/base/text_track_config.h" |
14 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
15 #include "media/formats/mp2t/es_parser.h" | 16 #include "media/formats/mp2t/es_parser.h" |
16 #include "media/formats/mp2t/es_parser_adts.h" | 17 #include "media/formats/mp2t/es_parser_adts.h" |
17 #include "media/formats/mp2t/es_parser_h264.h" | 18 #include "media/formats/mp2t/es_parser_h264.h" |
18 #include "media/formats/mp2t/es_parser_mpeg1audio.h" | 19 #include "media/formats/mp2t/es_parser_mpeg1audio.h" |
19 #include "media/formats/mp2t/mp2t_common.h" | 20 #include "media/formats/mp2t/mp2t_common.h" |
20 #include "media/formats/mp2t/ts_packet.h" | 21 #include "media/formats/mp2t/ts_packet.h" |
21 #include "media/formats/mp2t/ts_section.h" | 22 #include "media/formats/mp2t/ts_section.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // Replace any non valid config with the 1st valid entry. | 496 // Replace any non valid config with the 1st valid entry. |
496 // This might happen if there was no available config before. | 497 // This might happen if there was no available config before. |
497 for (std::list<BufferQueueWithConfig>::iterator it = | 498 for (std::list<BufferQueueWithConfig>::iterator it = |
498 buffer_queue_chain_.begin(); it != buffer_queue_chain_.end(); ++it) { | 499 buffer_queue_chain_.begin(); it != buffer_queue_chain_.end(); ++it) { |
499 if (it->audio_config.IsValidConfig()) | 500 if (it->audio_config.IsValidConfig()) |
500 break; | 501 break; |
501 it->audio_config = audio_decoder_config; | 502 it->audio_config = audio_decoder_config; |
502 } | 503 } |
503 } | 504 } |
504 | 505 |
| 506 scoped_ptr<MediaTracks> GenerateMediaTrackInfo( |
| 507 const AudioDecoderConfig& audio_config, |
| 508 const VideoDecoderConfig& video_config) { |
| 509 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); |
| 510 // TODO(servolk): Implement proper sourcing of media track info as described |
| 511 // in crbug.com/590085 |
| 512 if (audio_config.IsValidConfig()) { |
| 513 media_tracks->AddAudioTrack(audio_config, "audio", "main", "", ""); |
| 514 } |
| 515 if (video_config.IsValidConfig()) { |
| 516 media_tracks->AddVideoTrack(video_config, "video", "main", "", ""); |
| 517 } |
| 518 return media_tracks; |
| 519 } |
| 520 |
505 bool Mp2tStreamParser::FinishInitializationIfNeeded() { | 521 bool Mp2tStreamParser::FinishInitializationIfNeeded() { |
506 // Nothing to be done if already initialized. | 522 // Nothing to be done if already initialized. |
507 if (is_initialized_) | 523 if (is_initialized_) |
508 return true; | 524 return true; |
509 | 525 |
510 // Wait for more data to come to finish initialization. | 526 // Wait for more data to come to finish initialization. |
511 if (buffer_queue_chain_.empty()) | 527 if (buffer_queue_chain_.empty()) |
512 return true; | 528 return true; |
513 | 529 |
514 // Wait for more data to come if one of the config is not available. | 530 // Wait for more data to come if one of the config is not available. |
515 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 531 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
516 if (selected_audio_pid_ > 0 && | 532 if (selected_audio_pid_ > 0 && |
517 !queue_with_config.audio_config.IsValidConfig()) | 533 !queue_with_config.audio_config.IsValidConfig()) |
518 return true; | 534 return true; |
519 if (selected_video_pid_ > 0 && | 535 if (selected_video_pid_ > 0 && |
520 !queue_with_config.video_config.IsValidConfig()) | 536 !queue_with_config.video_config.IsValidConfig()) |
521 return true; | 537 return true; |
522 | 538 |
523 // Pass the config before invoking the initialization callback. | 539 // Pass the config before invoking the initialization callback. |
524 RCHECK(config_cb_.Run(queue_with_config.audio_config, | 540 scoped_ptr<MediaTracks> media_tracks = GenerateMediaTrackInfo( |
525 queue_with_config.video_config, | 541 queue_with_config.audio_config, queue_with_config.video_config); |
526 TextTrackConfigMap())); | 542 RCHECK(config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())); |
527 queue_with_config.is_config_sent = true; | 543 queue_with_config.is_config_sent = true; |
528 | 544 |
529 // For Mpeg2 TS, the duration is not known. | 545 // For Mpeg2 TS, the duration is not known. |
530 DVLOG(1) << "Mpeg2TS stream parser initialization done"; | 546 DVLOG(1) << "Mpeg2TS stream parser initialization done"; |
531 base::ResetAndReturn(&init_cb_).Run(InitParameters(kInfiniteDuration())); | 547 base::ResetAndReturn(&init_cb_).Run(InitParameters(kInfiniteDuration())); |
532 is_initialized_ = true; | 548 is_initialized_ = true; |
533 | 549 |
534 return true; | 550 return true; |
535 } | 551 } |
536 | 552 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 // Start a segment if needed. | 629 // Start a segment if needed. |
614 if (!segment_started_) { | 630 if (!segment_started_) { |
615 DVLOG(1) << "Starting a new segment"; | 631 DVLOG(1) << "Starting a new segment"; |
616 segment_started_ = true; | 632 segment_started_ = true; |
617 new_segment_cb_.Run(); | 633 new_segment_cb_.Run(); |
618 } | 634 } |
619 | 635 |
620 // Update the audio and video config if needed. | 636 // Update the audio and video config if needed. |
621 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 637 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
622 if (!queue_with_config.is_config_sent) { | 638 if (!queue_with_config.is_config_sent) { |
623 if (!config_cb_.Run(queue_with_config.audio_config, | 639 scoped_ptr<MediaTracks> media_tracks = GenerateMediaTrackInfo( |
624 queue_with_config.video_config, | 640 queue_with_config.audio_config, queue_with_config.video_config); |
625 TextTrackConfigMap())) | 641 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) |
626 return false; | 642 return false; |
627 queue_with_config.is_config_sent = true; | 643 queue_with_config.is_config_sent = true; |
628 } | 644 } |
629 | 645 |
630 // Add buffers. | 646 // Add buffers. |
631 TextBufferQueueMap empty_text_map; | 647 TextBufferQueueMap empty_text_map; |
632 if (!queue_with_config.audio_queue.empty() || | 648 if (!queue_with_config.audio_queue.empty() || |
633 !queue_with_config.video_queue.empty()) { | 649 !queue_with_config.video_queue.empty()) { |
634 if (!new_buffers_cb_.Run(queue_with_config.audio_queue, | 650 if (!new_buffers_cb_.Run(queue_with_config.audio_queue, |
635 queue_with_config.video_queue, | 651 queue_with_config.video_queue, |
636 empty_text_map)) { | 652 empty_text_map)) { |
637 return false; | 653 return false; |
638 } | 654 } |
639 } | 655 } |
640 | 656 |
641 buffer_queue_chain_.pop_front(); | 657 buffer_queue_chain_.pop_front(); |
642 } | 658 } |
643 | 659 |
644 // Push an empty queue with the last audio/video config | 660 // Push an empty queue with the last audio/video config |
645 // so that buffers with the same config can be added later on. | 661 // so that buffers with the same config can be added later on. |
646 BufferQueueWithConfig queue_with_config( | 662 BufferQueueWithConfig queue_with_config( |
647 true, last_audio_config, last_video_config); | 663 true, last_audio_config, last_video_config); |
648 buffer_queue_chain_.push_back(queue_with_config); | 664 buffer_queue_chain_.push_back(queue_with_config); |
649 | 665 |
650 return true; | 666 return true; |
651 } | 667 } |
652 | 668 |
653 } // namespace mp2t | 669 } // namespace mp2t |
654 } // namespace media | 670 } // namespace media |
OLD | NEW |