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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // Wait for more data to come if one of the config is not available. | 515 // Wait for more data to come if one of the config is not available. |
515 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 516 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
516 if (selected_audio_pid_ > 0 && | 517 if (selected_audio_pid_ > 0 && |
517 !queue_with_config.audio_config.IsValidConfig()) | 518 !queue_with_config.audio_config.IsValidConfig()) |
518 return true; | 519 return true; |
519 if (selected_video_pid_ > 0 && | 520 if (selected_video_pid_ > 0 && |
520 !queue_with_config.video_config.IsValidConfig()) | 521 !queue_with_config.video_config.IsValidConfig()) |
521 return true; | 522 return true; |
522 | 523 |
523 // Pass the config before invoking the initialization callback. | 524 // Pass the config before invoking the initialization callback. |
524 RCHECK(config_cb_.Run(queue_with_config.audio_config, | 525 const AudioDecoderConfig& audio_config = queue_with_config.audio_config; |
525 queue_with_config.video_config, | 526 const VideoDecoderConfig& video_config = queue_with_config.video_config; |
526 TextTrackConfigMap())); | 527 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); |
| 528 if (audio_config.IsValidConfig()) { |
| 529 media_tracks->AddAudioTrack(audio_config, "audio", "", "", ""); |
| 530 } |
| 531 if (video_config.IsValidConfig()) { |
| 532 media_tracks->AddVideoTrack(video_config, "video", "", "", ""); |
| 533 } |
| 534 RCHECK(config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())); |
527 queue_with_config.is_config_sent = true; | 535 queue_with_config.is_config_sent = true; |
528 | 536 |
529 // For Mpeg2 TS, the duration is not known. | 537 // For Mpeg2 TS, the duration is not known. |
530 DVLOG(1) << "Mpeg2TS stream parser initialization done"; | 538 DVLOG(1) << "Mpeg2TS stream parser initialization done"; |
531 base::ResetAndReturn(&init_cb_).Run(InitParameters(kInfiniteDuration())); | 539 base::ResetAndReturn(&init_cb_).Run(InitParameters(kInfiniteDuration())); |
532 is_initialized_ = true; | 540 is_initialized_ = true; |
533 | 541 |
534 return true; | 542 return true; |
535 } | 543 } |
536 | 544 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 // Start a segment if needed. | 621 // Start a segment if needed. |
614 if (!segment_started_) { | 622 if (!segment_started_) { |
615 DVLOG(1) << "Starting a new segment"; | 623 DVLOG(1) << "Starting a new segment"; |
616 segment_started_ = true; | 624 segment_started_ = true; |
617 new_segment_cb_.Run(); | 625 new_segment_cb_.Run(); |
618 } | 626 } |
619 | 627 |
620 // Update the audio and video config if needed. | 628 // Update the audio and video config if needed. |
621 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 629 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
622 if (!queue_with_config.is_config_sent) { | 630 if (!queue_with_config.is_config_sent) { |
623 if (!config_cb_.Run(queue_with_config.audio_config, | 631 const AudioDecoderConfig& audio_config = queue_with_config.audio_config; |
624 queue_with_config.video_config, | 632 const VideoDecoderConfig& video_config = queue_with_config.video_config; |
625 TextTrackConfigMap())) | 633 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); |
| 634 if (audio_config.IsValidConfig()) { |
| 635 media_tracks->AddAudioTrack(audio_config, "audio", "", "", ""); |
| 636 } |
| 637 if (video_config.IsValidConfig()) { |
| 638 media_tracks->AddVideoTrack(video_config, "video", "", "", ""); |
| 639 } |
| 640 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) |
626 return false; | 641 return false; |
627 queue_with_config.is_config_sent = true; | 642 queue_with_config.is_config_sent = true; |
628 } | 643 } |
629 | 644 |
630 // Add buffers. | 645 // Add buffers. |
631 TextBufferQueueMap empty_text_map; | 646 TextBufferQueueMap empty_text_map; |
632 if (!queue_with_config.audio_queue.empty() || | 647 if (!queue_with_config.audio_queue.empty() || |
633 !queue_with_config.video_queue.empty()) { | 648 !queue_with_config.video_queue.empty()) { |
634 if (!new_buffers_cb_.Run(queue_with_config.audio_queue, | 649 if (!new_buffers_cb_.Run(queue_with_config.audio_queue, |
635 queue_with_config.video_queue, | 650 queue_with_config.video_queue, |
636 empty_text_map)) { | 651 empty_text_map)) { |
637 return false; | 652 return false; |
638 } | 653 } |
639 } | 654 } |
640 | 655 |
641 buffer_queue_chain_.pop_front(); | 656 buffer_queue_chain_.pop_front(); |
642 } | 657 } |
643 | 658 |
644 // Push an empty queue with the last audio/video config | 659 // Push an empty queue with the last audio/video config |
645 // so that buffers with the same config can be added later on. | 660 // so that buffers with the same config can be added later on. |
646 BufferQueueWithConfig queue_with_config( | 661 BufferQueueWithConfig queue_with_config( |
647 true, last_audio_config, last_video_config); | 662 true, last_audio_config, last_video_config); |
648 buffer_queue_chain_.push_back(queue_with_config); | 663 buffer_queue_chain_.push_back(queue_with_config); |
649 | 664 |
650 return true; | 665 return true; |
651 } | 666 } |
652 | 667 |
653 } // namespace mp2t | 668 } // namespace mp2t |
654 } // namespace media | 669 } // namespace media |
OLD | NEW |