| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 base::AutoLock auto_lock(lock_); | 549 base::AutoLock auto_lock(lock_); |
| 527 | 550 |
| 528 // TODO(annacc): Calculate buffered ranges (http://crbug.com/129852 ). | 551 // TODO(annacc): Calculate buffered ranges (http://crbug.com/129852 ). |
| 529 return false; | 552 return false; |
| 530 } | 553 } |
| 531 | 554 |
| 532 bool ChunkDemuxer::AppendData(const std::string& id, | 555 bool ChunkDemuxer::AppendData(const std::string& id, |
| 533 const uint8* data, | 556 const uint8* data, |
| 534 size_t length) { | 557 size_t length) { |
| 535 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | 558 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
| 536 | |
| 537 // TODO(acolwell): Remove when http://webk.it/83788 fix lands. | |
| 538 if (source_id_.empty()) { | |
| 539 std::vector<std::string> codecs(2); | |
| 540 codecs[0] = "vp8"; | |
| 541 codecs[1] = "vorbis"; | |
| 542 AddId(id, "video/webm", codecs); | |
| 543 } | |
| 544 | |
| 545 DCHECK(!source_id_.empty()); | 559 DCHECK(!source_id_.empty()); |
| 546 DCHECK_EQ(source_id_, id); | 560 DCHECK_EQ(source_id_, id); |
| 547 DCHECK(!id.empty()); | 561 DCHECK(!id.empty()); |
| 548 DCHECK(data); | 562 DCHECK(data); |
| 549 DCHECK_GT(length, 0u); | 563 DCHECK_GT(length, 0u); |
| 550 | 564 |
| 551 int64 buffered_bytes = 0; | 565 int64 buffered_bytes = 0; |
| 552 | 566 |
| 553 PipelineStatusCB cb; | 567 PipelineStatusCB cb; |
| 554 { | 568 { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 return true; | 814 return true; |
| 801 } | 815 } |
| 802 | 816 |
| 803 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, | 817 bool ChunkDemuxer::OnKeyNeeded(scoped_array<uint8> init_data, |
| 804 int init_data_size) { | 818 int init_data_size) { |
| 805 client_->KeyNeeded(init_data.Pass(), init_data_size); | 819 client_->KeyNeeded(init_data.Pass(), init_data_size); |
| 806 return true; | 820 return true; |
| 807 } | 821 } |
| 808 | 822 |
| 809 } // namespace media | 823 } // namespace media |
| OLD | NEW |