Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

Issue 10829470: Support for parsing encrypted WebM streams by src. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tool player_x11 Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/ffmpeg/ffmpeg_common.h ('k') | media/filters/chunk_demuxer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ffmpeg/ffmpeg_common.h" 5 #include "media/ffmpeg/ffmpeg_common.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 case 7: 288 case 7:
289 return CHANNEL_LAYOUT_6_1; 289 return CHANNEL_LAYOUT_6_1;
290 case 8: 290 case 8:
291 return CHANNEL_LAYOUT_7_1; 291 return CHANNEL_LAYOUT_7_1;
292 default: 292 default:
293 DVLOG(1) << "Unsupported channel count: " << channels; 293 DVLOG(1) << "Unsupported channel count: " << channels;
294 } 294 }
295 return CHANNEL_LAYOUT_UNSUPPORTED; 295 return CHANNEL_LAYOUT_UNSUPPORTED;
296 } 296 }
297 297
298 void AVCodecContextToAudioDecoderConfig( 298 static void AVCodecContextToAudioDecoderConfig(
299 const AVCodecContext* codec_context, 299 const AVCodecContext* codec_context,
300 bool is_encrypted,
300 AudioDecoderConfig* config) { 301 AudioDecoderConfig* config) {
301 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); 302 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO);
302 303
303 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); 304 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id);
304 305
305 SampleFormat sample_format = 306 SampleFormat sample_format =
306 AVSampleFormatToSampleFormat(codec_context->sample_fmt); 307 AVSampleFormatToSampleFormat(codec_context->sample_fmt);
307 308
308 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( 309 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout(
309 codec_context->channel_layout, codec_context->channels); 310 codec_context->channel_layout, codec_context->channels);
310 311
311 if (codec == kCodecOpus) { 312 if (codec == kCodecOpus) {
312 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is 313 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is
313 // not enabled in FFmpeg, so we need to manually set the sample format. 314 // not enabled in FFmpeg, so we need to manually set the sample format.
314 sample_format = kSampleFormatS16; 315 sample_format = kSampleFormatS16;
315 } 316 }
316 317
317 config->Initialize(codec, 318 config->Initialize(codec,
318 sample_format, 319 sample_format,
319 channel_layout, 320 channel_layout,
320 codec_context->sample_rate, 321 codec_context->sample_rate,
321 codec_context->extradata, 322 codec_context->extradata,
322 codec_context->extradata_size, 323 codec_context->extradata_size,
323 false, // Not encrypted. 324 is_encrypted,
324 true); 325 true);
325 if (codec != kCodecOpus) { 326 if (codec != kCodecOpus) {
326 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, 327 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
327 config->bits_per_channel()); 328 config->bits_per_channel());
328 } 329 }
329 } 330 }
330 331
332 void AVStreamToAudioDecoderConfig(
333 const AVStream* stream,
334 AudioDecoderConfig* config) {
335 bool is_encrypted = false;
336 AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0);
337 if (key)
338 is_encrypted = true;
339 return AVCodecContextToAudioDecoderConfig(stream->codec,
340 is_encrypted, config);
341 }
342
331 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, 343 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
332 AVCodecContext* codec_context) { 344 AVCodecContext* codec_context) {
333 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; 345 codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
334 codec_context->codec_id = AudioCodecToCodecID(config.codec(), 346 codec_context->codec_id = AudioCodecToCodecID(config.codec(),
335 config.sample_format()); 347 config.sample_format());
336 codec_context->sample_fmt = SampleFormatToAVSampleFormat( 348 codec_context->sample_fmt = SampleFormatToAVSampleFormat(
337 config.sample_format()); 349 config.sample_format());
338 350
339 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses 351 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses
340 // said information to decode. 352 // said information to decode.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 gfx::Size natural_size = GetNaturalSize( 396 gfx::Size natural_size = GetNaturalSize(
385 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); 397 visible_rect.size(), aspect_ratio.num, aspect_ratio.den);
386 398
387 VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt); 399 VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt);
388 if (codec == kCodecVP9) { 400 if (codec == kCodecVP9) {
389 // TODO(tomfinegan): libavcodec doesn't know about VP9. 401 // TODO(tomfinegan): libavcodec doesn't know about VP9.
390 format = VideoFrame::YV12; 402 format = VideoFrame::YV12;
391 coded_size = natural_size; 403 coded_size = natural_size;
392 } 404 }
393 405
406 bool is_encrypted = false;
407 AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0);
408 if (key)
409 is_encrypted = true;
410
394 config->Initialize(codec, 411 config->Initialize(codec,
395 profile, 412 profile,
396 format, 413 format,
397 coded_size, visible_rect, natural_size, 414 coded_size, visible_rect, natural_size,
398 stream->codec->extradata, stream->codec->extradata_size, 415 stream->codec->extradata, stream->codec->extradata_size,
399 false, // Not encrypted. 416 is_encrypted,
400 true); 417 true);
401 } 418 }
402 419
403 void VideoDecoderConfigToAVCodecContext( 420 void VideoDecoderConfigToAVCodecContext(
404 const VideoDecoderConfig& config, 421 const VideoDecoderConfig& config,
405 AVCodecContext* codec_context) { 422 AVCodecContext* codec_context) {
406 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; 423 codec_context->codec_type = AVMEDIA_TYPE_VIDEO;
407 codec_context->codec_id = VideoCodecToCodecID(config.codec()); 424 codec_context->codec_id = VideoCodecToCodecID(config.codec());
408 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); 425 codec_context->profile = VideoCodecProfileToProfileID(config.profile());
409 codec_context->coded_width = config.coded_size().width(); 426 codec_context->coded_width = config.coded_size().width();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return PIX_FMT_YUV422P; 528 return PIX_FMT_YUV422P;
512 case VideoFrame::YV12: 529 case VideoFrame::YV12:
513 return PIX_FMT_YUV420P; 530 return PIX_FMT_YUV420P;
514 default: 531 default:
515 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; 532 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format;
516 } 533 }
517 return PIX_FMT_NONE; 534 return PIX_FMT_NONE;
518 } 535 }
519 536
520 } // namespace media 537 } // namespace media
OLDNEW
« no previous file with comments | « media/ffmpeg/ffmpeg_common.h ('k') | media/filters/chunk_demuxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698