| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "media/base/audio_decoder_config.h" | 12 #include "media/base/audio_decoder_config.h" |
| 13 #include "media/base/stream_parser_buffer.h" | 13 #include "media/base/stream_parser_buffer.h" |
| 14 #include "media/base/video_decoder_config.h" | 14 #include "media/base/video_decoder_config.h" |
| 15 #include "media/filters/chunk_demuxer_client.h" | 15 #include "media/filters/chunk_demuxer_client.h" |
| 16 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 16 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 17 #include "media/mp4/mp4_stream_parser.h" | 17 #include "media/mp4/mp4_stream_parser.h" |
| 18 #endif | 18 #endif |
| 19 #include "media/webm/webm_stream_parser.h" | 19 #include "media/webm/webm_stream_parser.h" |
| 20 | 20 |
| 21 using base::TimeDelta; | 21 using base::TimeDelta; |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 struct CodecInfo { | 25 struct CodecInfo { |
| 26 const char* pattern; | 26 const char* pattern; |
| 27 DemuxerStream::Type type; | 27 DemuxerStream::Type type; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 typedef StreamParser* (*ParserFactoryFunction)(); | 30 typedef StreamParser* (*ParserFactoryFunction)( |
| 31 const std::vector<std::string>& codecs); |
| 31 | 32 |
| 32 struct SupportedTypeInfo { | 33 struct SupportedTypeInfo { |
| 33 const char* type; | 34 const char* type; |
| 34 const ParserFactoryFunction factory_function; | 35 const ParserFactoryFunction factory_function; |
| 35 const CodecInfo** codecs; | 36 const CodecInfo** codecs; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 static const CodecInfo kVP8CodecInfo = { "vp8", DemuxerStream::VIDEO }; | 39 static const CodecInfo kVP8CodecInfo = { "vp8", DemuxerStream::VIDEO }; |
| 39 static const CodecInfo kVorbisCodecInfo = { "vorbis", DemuxerStream::AUDIO }; | 40 static const CodecInfo kVorbisCodecInfo = { "vorbis", DemuxerStream::AUDIO }; |
| 40 | 41 |
| 41 static const CodecInfo* kVideoWebMCodecs[] = { | 42 static const CodecInfo* kVideoWebMCodecs[] = { |
| 42 &kVP8CodecInfo, | 43 &kVP8CodecInfo, |
| 43 &kVorbisCodecInfo, | 44 &kVorbisCodecInfo, |
| 44 NULL | 45 NULL |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 static const CodecInfo* kAudioWebMCodecs[] = { | 48 static const CodecInfo* kAudioWebMCodecs[] = { |
| 48 &kVorbisCodecInfo, | 49 &kVorbisCodecInfo, |
| 49 NULL | 50 NULL |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 static StreamParser* BuildWebMParser() { | 53 static StreamParser* BuildWebMParser(const std::vector<std::string>& codecs) { |
| 53 return new WebMStreamParser(); | 54 return new WebMStreamParser(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 57 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 57 static const CodecInfo kH264CodecInfo = { "avc1.*", DemuxerStream::VIDEO }; | 58 static const CodecInfo kH264CodecInfo = { "avc1.*", DemuxerStream::VIDEO }; |
| 58 static const CodecInfo kAACCodecInfo = { "mp4a.40.*", DemuxerStream::AUDIO }; | 59 static const CodecInfo kAACCodecInfo = { "mp4a.40.*", DemuxerStream::AUDIO }; |
| 59 | 60 |
| 60 static const CodecInfo* kVideoMP4Codecs[] = { | 61 static const CodecInfo* kVideoMP4Codecs[] = { |
| 61 &kH264CodecInfo, | 62 &kH264CodecInfo, |
| 62 &kAACCodecInfo, | 63 &kAACCodecInfo, |
| 63 NULL | 64 NULL |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 static const CodecInfo* kAudioMP4Codecs[] = { | 67 static const CodecInfo* kAudioMP4Codecs[] = { |
| 67 &kAACCodecInfo, | 68 &kAACCodecInfo, |
| 68 NULL | 69 NULL |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 static StreamParser* BuildMP4Parser() { | 72 // Mimetype codec string that indicates the content contains AAC SBR frames. |
| 72 return new mp4::MP4StreamParser(); | 73 static const char* kSBRCodecId = "mp4a.40.5"; |
| 74 |
| 75 static StreamParser* BuildMP4Parser(const std::vector<std::string>& codecs) { |
| 76 bool has_sbr = false; |
| 77 for (size_t i = 0; i < codecs.size(); ++i) { |
| 78 if (codecs[i] == kSBRCodecId) { |
| 79 has_sbr = true; |
| 80 break; |
| 81 } |
| 82 } |
| 83 |
| 84 return new mp4::MP4StreamParser(has_sbr); |
| 73 } | 85 } |
| 74 #endif | 86 #endif |
| 75 | 87 |
| 76 static const SupportedTypeInfo kSupportedTypeInfo[] = { | 88 static const SupportedTypeInfo kSupportedTypeInfo[] = { |
| 77 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, | 89 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, |
| 78 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, | 90 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, |
| 79 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) | 91 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) |
| 80 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, | 92 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, |
| 81 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, | 93 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, |
| 82 #endif | 94 #endif |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 audio_cb = base::Bind(&ChunkDemuxer::OnAudioBuffers, | 644 audio_cb = base::Bind(&ChunkDemuxer::OnAudioBuffers, |
| 633 base::Unretained(this)); | 645 base::Unretained(this)); |
| 634 } | 646 } |
| 635 | 647 |
| 636 if (has_video) { | 648 if (has_video) { |
| 637 source_id_video_ = id; | 649 source_id_video_ = id; |
| 638 video_cb = base::Bind(&ChunkDemuxer::OnVideoBuffers, | 650 video_cb = base::Bind(&ChunkDemuxer::OnVideoBuffers, |
| 639 base::Unretained(this)); | 651 base::Unretained(this)); |
| 640 } | 652 } |
| 641 | 653 |
| 642 scoped_ptr<StreamParser> stream_parser(factory_function()); | 654 scoped_ptr<StreamParser> stream_parser(factory_function(codecs)); |
| 643 CHECK(stream_parser.get()); | 655 CHECK(stream_parser.get()); |
| 644 | 656 |
| 645 stream_parser->Init( | 657 stream_parser->Init( |
| 646 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), | 658 base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), |
| 647 base::Bind(&ChunkDemuxer::OnNewConfigs, base::Unretained(this), | 659 base::Bind(&ChunkDemuxer::OnNewConfigs, base::Unretained(this), |
| 648 has_audio, has_video), | 660 has_audio, has_video), |
| 649 audio_cb, | 661 audio_cb, |
| 650 video_cb, | 662 video_cb, |
| 651 base::Bind(&ChunkDemuxer::OnNeedKey, base::Unretained(this)), | 663 base::Bind(&ChunkDemuxer::OnNeedKey, base::Unretained(this)), |
| 652 base::Bind(&ChunkDemuxer::OnNewMediaSegment, base::Unretained(this), id)); | 664 base::Bind(&ChunkDemuxer::OnNewMediaSegment, base::Unretained(this), id)); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 video_->SetStartTime(start_time_); | 1061 video_->SetStartTime(start_time_); |
| 1050 video_->Seek(start_time_); | 1062 video_->Seek(start_time_); |
| 1051 } | 1063 } |
| 1052 | 1064 |
| 1053 // The demuxer is now initialized after the |start_timestamp_| was set. | 1065 // The demuxer is now initialized after the |start_timestamp_| was set. |
| 1054 ChangeState_Locked(INITIALIZED); | 1066 ChangeState_Locked(INITIALIZED); |
| 1055 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1067 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 1056 } | 1068 } |
| 1057 | 1069 |
| 1058 } // namespace media | 1070 } // namespace media |
| OLD | NEW |