| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| 11 #include "media/base/stream_parser_buffer.h" | 11 #include "media/base/stream_parser_buffer.h" |
| 12 #include "media/base/video_decoder_config.h" | 12 #include "media/base/video_decoder_config.h" |
| 13 #include "media/filters/chunk_demuxer_client.h" | 13 #include "media/filters/chunk_demuxer_client.h" |
| 14 #include "media/mp4/mp4_stream_parser.h" |
| 14 #include "media/webm/webm_stream_parser.h" | 15 #include "media/webm/webm_stream_parser.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 struct CodecInfo { | 19 struct CodecInfo { |
| 19 const char* name; | 20 const char* name; |
| 20 DemuxerStream::Type type; | 21 DemuxerStream::Type type; |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 typedef StreamParser* (*ParserFactoryFunction)(); | 24 typedef StreamParser* (*ParserFactoryFunction)(); |
| 24 | 25 |
| 25 struct SupportedTypeInfo { | 26 struct SupportedTypeInfo { |
| 26 const char* type; | 27 const char* type; |
| 27 const ParserFactoryFunction factory_function; | 28 const ParserFactoryFunction factory_function; |
| 28 const CodecInfo** codecs; | 29 const CodecInfo** codecs; |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 static const CodecInfo kVP8CodecInfo = { "vp8", DemuxerStream::VIDEO }; | 32 static const CodecInfo kVP8CodecInfo = { "vp8", DemuxerStream::VIDEO }; |
| 32 static const CodecInfo kVorbisCodecInfo = { "vorbis", DemuxerStream::AUDIO }; | 33 static const CodecInfo kVorbisCodecInfo = { "vorbis", DemuxerStream::AUDIO }; |
| 33 | 34 |
| 35 // TODO(strobe): Perform matching against supported profiles and levels, or |
| 36 // simply accept codecs that match a prefix. |
| 37 static const CodecInfo kH264CodecInfo = { "avc1.4D4041", DemuxerStream::VIDEO }; |
| 38 static const CodecInfo kAACCodecInfo = { "mp4a.40.2", DemuxerStream::AUDIO }; |
| 39 |
| 34 static const CodecInfo* kVideoWebMCodecs[] = { | 40 static const CodecInfo* kVideoWebMCodecs[] = { |
| 35 &kVP8CodecInfo, | 41 &kVP8CodecInfo, |
| 36 &kVorbisCodecInfo, | 42 &kVorbisCodecInfo, |
| 37 NULL | 43 NULL |
| 38 }; | 44 }; |
| 39 | 45 |
| 40 static const CodecInfo* kAudioWebMCodecs[] = { | 46 static const CodecInfo* kAudioWebMCodecs[] = { |
| 41 &kVorbisCodecInfo, | 47 &kVorbisCodecInfo, |
| 42 NULL | 48 NULL |
| 43 }; | 49 }; |
| 44 | 50 |
| 51 static const CodecInfo* kVideoMP4Codecs[] = { |
| 52 &kH264CodecInfo, |
| 53 &kAACCodecInfo, |
| 54 NULL |
| 55 }; |
| 56 |
| 57 static const CodecInfo* kAudioMP4Codecs[] = { |
| 58 &kAACCodecInfo, |
| 59 NULL |
| 60 }; |
| 61 |
| 45 static StreamParser* BuildWebMParser() { | 62 static StreamParser* BuildWebMParser() { |
| 46 return new WebMStreamParser(); | 63 return new WebMStreamParser(); |
| 47 } | 64 } |
| 48 | 65 |
| 66 static StreamParser* BuildMP4Parser() { |
| 67 return new mp4::MP4StreamParser(); |
| 68 } |
| 69 |
| 49 static const SupportedTypeInfo kSupportedTypeInfo[] = { | 70 static const SupportedTypeInfo kSupportedTypeInfo[] = { |
| 50 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, | 71 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, |
| 51 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, | 72 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, |
| 73 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, |
| 74 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, |
| 52 }; | 75 }; |
| 53 | 76 |
| 54 // Checks to see if the specified |type| and |codecs| list are supported. | 77 // Checks to see if the specified |type| and |codecs| list are supported. |
| 55 // Returns true if |type| and all codecs listed in |codecs| are supported. | 78 // Returns true if |type| and all codecs listed in |codecs| are supported. |
| 56 // |factory_function| contains a function that can build a StreamParser | 79 // |factory_function| contains a function that can build a StreamParser |
| 57 // for this type. | 80 // for this type. |
| 58 // |has_audio| is true if an audio codec was specified. | 81 // |has_audio| is true if an audio codec was specified. |
| 59 // |has_video| is true if a video codec was specified. | 82 // |has_video| is true if a video codec was specified. |
| 60 // Returns false otherwise. The values of |factory_function|, |has_audio|, | 83 // Returns false otherwise. The values of |factory_function|, |has_audio|, |
| 61 // and |has_video| are undefined. | 84 // and |has_video| are undefined. |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 532 |
| 510 base::AutoLock auto_lock(lock_); | 533 base::AutoLock auto_lock(lock_); |
| 511 | 534 |
| 512 return source_buffer_->GetBufferedRanges(ranges_out); | 535 return source_buffer_->GetBufferedRanges(ranges_out); |
| 513 } | 536 } |
| 514 | 537 |
| 515 bool ChunkDemuxer::AppendData(const std::string& id, | 538 bool ChunkDemuxer::AppendData(const std::string& id, |
| 516 const uint8* data, | 539 const uint8* data, |
| 517 size_t length) { | 540 size_t length) { |
| 518 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | 541 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
| 519 | |
| 520 // TODO(acolwell): Remove when http://webk.it/83788 fix lands. | |
| 521 if (source_id_.empty()) { | |
| 522 std::vector<std::string> codecs(2); | |
| 523 codecs[0] = "vp8"; | |
| 524 codecs[1] = "vorbis"; | |
| 525 AddId(id, "video/webm", codecs); | |
| 526 } | |
| 527 | |
| 528 DCHECK(!source_id_.empty()); | 542 DCHECK(!source_id_.empty()); |
| 529 DCHECK_EQ(source_id_, id); | 543 DCHECK_EQ(source_id_, id); |
| 530 DCHECK(!id.empty()); | 544 DCHECK(!id.empty()); |
| 531 DCHECK(data); | 545 DCHECK(data); |
| 532 DCHECK_GT(length, 0u); | 546 DCHECK_GT(length, 0u); |
| 533 | 547 |
| 534 int64 buffered_bytes = 0; | 548 int64 buffered_bytes = 0; |
| 535 | 549 |
| 536 PipelineStatusCB cb; | 550 PipelineStatusCB cb; |
| 537 { | 551 { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 return true; | 789 return true; |
| 776 } | 790 } |
| 777 | 791 |
| 778 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, | 792 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, |
| 779 int init_data_size) { | 793 int init_data_size) { |
| 780 client_->KeyNeeded(init_data.Pass(), init_data_size); | 794 client_->KeyNeeded(init_data.Pass(), init_data_size); |
| 781 return true; | 795 return true; |
| 782 } | 796 } |
| 783 | 797 |
| 784 } // namespace media | 798 } // namespace media |
| OLD | NEW |