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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 std::unique_ptr<MediaTracks> GenerateMediaTrackInfo( | 508 std::unique_ptr<MediaTracks> GenerateMediaTrackInfo( |
509 const AudioDecoderConfig& audio_config, | 509 const AudioDecoderConfig& audio_config, |
510 const VideoDecoderConfig& video_config) { | 510 const VideoDecoderConfig& video_config) { |
511 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); | 511 std::unique_ptr<MediaTracks> media_tracks(new MediaTracks()); |
512 // TODO(servolk): Implement proper sourcing of media track info as described | 512 // TODO(servolk): Implement proper sourcing of media track info as described |
513 // in crbug.com/590085 | 513 // in crbug.com/590085 |
514 if (audio_config.IsValidConfig()) { | 514 if (audio_config.IsValidConfig()) { |
515 media_tracks->AddAudioTrack(audio_config, 1, "main", "", ""); | 515 media_tracks->AddAudioTrack(audio_config, kMp2tAudioTrackId, "main", "", |
| 516 ""); |
516 } | 517 } |
517 if (video_config.IsValidConfig()) { | 518 if (video_config.IsValidConfig()) { |
518 media_tracks->AddVideoTrack(video_config, 2, "main", "", ""); | 519 media_tracks->AddVideoTrack(video_config, kMp2tVideoTrackId, "main", "", |
| 520 ""); |
519 } | 521 } |
520 return media_tracks; | 522 return media_tracks; |
521 } | 523 } |
522 | 524 |
523 bool Mp2tStreamParser::FinishInitializationIfNeeded() { | 525 bool Mp2tStreamParser::FinishInitializationIfNeeded() { |
524 // Nothing to be done if already initialized. | 526 // Nothing to be done if already initialized. |
525 if (is_initialized_) | 527 if (is_initialized_) |
526 return true; | 528 return true; |
527 | 529 |
528 // Wait for more data to come to finish initialization. | 530 // Wait for more data to come to finish initialization. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); | 650 BufferQueueWithConfig& queue_with_config = buffer_queue_chain_.front(); |
649 if (!queue_with_config.is_config_sent) { | 651 if (!queue_with_config.is_config_sent) { |
650 std::unique_ptr<MediaTracks> media_tracks = GenerateMediaTrackInfo( | 652 std::unique_ptr<MediaTracks> media_tracks = GenerateMediaTrackInfo( |
651 queue_with_config.audio_config, queue_with_config.video_config); | 653 queue_with_config.audio_config, queue_with_config.video_config); |
652 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) | 654 if (!config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())) |
653 return false; | 655 return false; |
654 queue_with_config.is_config_sent = true; | 656 queue_with_config.is_config_sent = true; |
655 } | 657 } |
656 | 658 |
657 // Add buffers. | 659 // Add buffers. |
658 TextBufferQueueMap empty_text_map; | 660 BufferQueueMap buffer_queue_map; |
659 if (!queue_with_config.audio_queue.empty() || | 661 if (!queue_with_config.audio_queue.empty()) |
660 !queue_with_config.video_queue.empty()) { | 662 buffer_queue_map.insert( |
661 if (!new_buffers_cb_.Run(queue_with_config.audio_queue, | 663 std::make_pair(kMp2tAudioTrackId, queue_with_config.audio_queue)); |
662 queue_with_config.video_queue, | 664 if (!queue_with_config.video_queue.empty()) |
663 empty_text_map)) { | 665 buffer_queue_map.insert( |
664 return false; | 666 std::make_pair(kMp2tVideoTrackId, queue_with_config.video_queue)); |
665 } | 667 |
666 } | 668 if (!buffer_queue_map.empty() && !new_buffers_cb_.Run(buffer_queue_map)) |
| 669 return false; |
667 | 670 |
668 buffer_queue_chain_.pop_front(); | 671 buffer_queue_chain_.pop_front(); |
669 } | 672 } |
670 | 673 |
671 // Push an empty queue with the last audio/video config | 674 // Push an empty queue with the last audio/video config |
672 // so that buffers with the same config can be added later on. | 675 // so that buffers with the same config can be added later on. |
673 BufferQueueWithConfig queue_with_config( | 676 BufferQueueWithConfig queue_with_config( |
674 true, last_audio_config, last_video_config); | 677 true, last_audio_config, last_video_config); |
675 buffer_queue_chain_.push_back(queue_with_config); | 678 buffer_queue_chain_.push_back(queue_with_config); |
676 | 679 |
677 return true; | 680 return true; |
678 } | 681 } |
679 | 682 |
680 } // namespace mp2t | 683 } // namespace mp2t |
681 } // namespace media | 684 } // namespace media |
OLD | NEW |