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/webm/webm_stream_parser.h" | 5 #include "media/webm/webm_stream_parser.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "media/ffmpeg/ffmpeg_common.h" | 11 #include "media/ffmpeg/ffmpeg_common.h" |
12 #include "media/filters/ffmpeg_glue.h" | 12 #include "media/filters/ffmpeg_glue.h" |
13 #include "media/filters/in_memory_url_protocol.h" | 13 #include "media/filters/in_memory_url_protocol.h" |
14 #include "media/webm/webm_cluster_parser.h" | 14 #include "media/webm/webm_cluster_parser.h" |
15 #include "media/webm/webm_constants.h" | 15 #include "media/webm/webm_constants.h" |
16 #include "media/webm/webm_content_encodings.h" | 16 #include "media/webm/webm_content_encodings.h" |
| 17 #include "media/webm/webm_crypto_helpers.h" |
17 #include "media/webm/webm_info_parser.h" | 18 #include "media/webm/webm_info_parser.h" |
18 #include "media/webm/webm_tracks_parser.h" | 19 #include "media/webm/webm_tracks_parser.h" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 // TODO(xhwang): Figure out the init data type appropriately once it's spec'ed. | |
23 static const char kWebMInitDataType[] = "video/webm"; | |
24 | |
25 // Helper class that uses FFmpeg to create AudioDecoderConfig & | 23 // Helper class that uses FFmpeg to create AudioDecoderConfig & |
26 // VideoDecoderConfig objects. | 24 // VideoDecoderConfig objects. |
27 // | 25 // |
28 // This dependency on FFmpeg can be removed once we update WebMTracksParser | 26 // This dependency on FFmpeg can be removed once we update WebMTracksParser |
29 // to parse the necessary data to construct AudioDecoderConfig & | 27 // to parse the necessary data to construct AudioDecoderConfig & |
30 // VideoDecoderConfig objects. http://crbug.com/108756 | 28 // VideoDecoderConfig objects. http://crbug.com/108756 |
31 class FFmpegConfigHelper { | 29 class FFmpegConfigHelper { |
32 public: | 30 public: |
33 FFmpegConfigHelper(); | 31 FFmpegConfigHelper(); |
34 ~FFmpegConfigHelper(); | 32 ~FFmpegConfigHelper(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 bool FFmpegConfigHelper::SetupStreamConfigs() { | 141 bool FFmpegConfigHelper::SetupStreamConfigs() { |
144 AVFormatContext* format_context = glue_->format_context(); | 142 AVFormatContext* format_context = glue_->format_context(); |
145 int result = avformat_find_stream_info(format_context, NULL); | 143 int result = avformat_find_stream_info(format_context, NULL); |
146 | 144 |
147 if (result < 0) | 145 if (result < 0) |
148 return false; | 146 return false; |
149 | 147 |
150 bool no_supported_streams = true; | 148 bool no_supported_streams = true; |
151 for (size_t i = 0; i < format_context->nb_streams; ++i) { | 149 for (size_t i = 0; i < format_context->nb_streams; ++i) { |
152 AVStream* stream = format_context->streams[i]; | 150 AVStream* stream = format_context->streams[i]; |
153 AVCodecContext* codec_context = stream->codec; | 151 AVMediaType codec_type = stream->codec->codec_type; |
154 AVMediaType codec_type = codec_context->codec_type; | |
155 | 152 |
156 if (codec_type == AVMEDIA_TYPE_AUDIO && | 153 if (codec_type == AVMEDIA_TYPE_AUDIO && |
157 stream->codec->codec_id == CODEC_ID_VORBIS && | 154 stream->codec->codec_id == CODEC_ID_VORBIS && |
158 !audio_config_.IsValidConfig()) { | 155 !audio_config_.IsValidConfig()) { |
159 AVCodecContextToAudioDecoderConfig(stream->codec, &audio_config_); | 156 AVStreamToAudioDecoderConfig(stream, &audio_config_); |
160 no_supported_streams = false; | 157 no_supported_streams = false; |
161 continue; | 158 continue; |
162 } | 159 } |
163 | 160 |
164 if (codec_type == AVMEDIA_TYPE_VIDEO && | 161 if (codec_type == AVMEDIA_TYPE_VIDEO && |
165 stream->codec->codec_id == CODEC_ID_VP8 && | 162 stream->codec->codec_id == CODEC_ID_VP8 && |
166 !video_config_.IsValidConfig()) { | 163 !video_config_.IsValidConfig()) { |
167 AVStreamToVideoDecoderConfig(stream, &video_config_); | 164 AVStreamToVideoDecoderConfig(stream, &video_config_); |
168 no_supported_streams = false; | 165 no_supported_streams = false; |
169 continue; | 166 continue; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 end_of_segment_cb_.Run(); | 463 end_of_segment_cb_.Run(); |
467 | 464 |
468 return bytes_parsed; | 465 return bytes_parsed; |
469 } | 466 } |
470 | 467 |
471 void WebMStreamParser::FireNeedKey(const std::string& key_id) { | 468 void WebMStreamParser::FireNeedKey(const std::string& key_id) { |
472 int key_id_size = key_id.size(); | 469 int key_id_size = key_id.size(); |
473 DCHECK_GT(key_id_size, 0); | 470 DCHECK_GT(key_id_size, 0); |
474 scoped_array<uint8> key_id_array(new uint8[key_id_size]); | 471 scoped_array<uint8> key_id_array(new uint8[key_id_size]); |
475 memcpy(key_id_array.get(), key_id.data(), key_id_size); | 472 memcpy(key_id_array.get(), key_id.data(), key_id_size); |
476 need_key_cb_.Run(kWebMInitDataType, key_id_array.Pass(), key_id_size); | 473 need_key_cb_.Run(kWebMEncryptInitDataType, key_id_array.Pass(), key_id_size); |
477 } | 474 } |
478 | 475 |
479 } // namespace media | 476 } // namespace media |
OLD | NEW |