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/ffmpeg_video_decoder.h" | 5 #include "media/filters/ffmpeg_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 if (!stream) { | 146 if (!stream) { |
147 status_cb.Run(PIPELINE_ERROR_DECODE); | 147 status_cb.Run(PIPELINE_ERROR_DECODE); |
148 return; | 148 return; |
149 } | 149 } |
150 | 150 |
151 demuxer_stream_ = stream; | 151 demuxer_stream_ = stream; |
152 statistics_cb_ = statistics_cb; | 152 statistics_cb_ = statistics_cb; |
153 | 153 |
154 if (!ConfigureDecoder()) { | 154 if (!ConfigureDecoder()) { |
155 status_cb.Run(PIPELINE_ERROR_DECODE); | 155 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
156 return; | 156 return; |
157 } | 157 } |
158 | 158 |
159 // Success! | 159 // Success! |
160 state_ = kNormal; | 160 state_ = kNormal; |
161 status_cb.Run(PIPELINE_OK); | 161 status_cb.Run(PIPELINE_OK); |
162 } | 162 } |
163 | 163 |
164 void FFmpegVideoDecoder::Read(const ReadCB& read_cb) { | 164 void FFmpegVideoDecoder::Read(const ReadCB& read_cb) { |
165 // Complete operation asynchronously on different stack of execution as per | 165 // Complete operation asynchronously on different stack of execution as per |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 491 } |
492 | 492 |
493 bool FFmpegVideoDecoder::ConfigureDecoder() { | 493 bool FFmpegVideoDecoder::ConfigureDecoder() { |
494 const VideoDecoderConfig& config = demuxer_stream_->video_decoder_config(); | 494 const VideoDecoderConfig& config = demuxer_stream_->video_decoder_config(); |
495 | 495 |
496 if (!config.IsValidConfig()) { | 496 if (!config.IsValidConfig()) { |
497 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); | 497 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); |
498 return false; | 498 return false; |
499 } | 499 } |
500 | 500 |
| 501 if (config.is_encrypted() && !decryptor_) { |
| 502 DLOG(ERROR) << "Encrypted video stream not supported."; |
| 503 return false; |
| 504 } |
| 505 |
501 // Release existing decoder resources if necessary. | 506 // Release existing decoder resources if necessary. |
502 ReleaseFFmpegResources(); | 507 ReleaseFFmpegResources(); |
503 | 508 |
504 // Initialize AVCodecContext structure. | 509 // Initialize AVCodecContext structure. |
505 codec_context_ = avcodec_alloc_context3(NULL); | 510 codec_context_ = avcodec_alloc_context3(NULL); |
506 VideoDecoderConfigToAVCodecContext(config, codec_context_); | 511 VideoDecoderConfigToAVCodecContext(config, codec_context_); |
507 | 512 |
508 // Enable motion vector search (potentially slow), strong deblocking filter | 513 // Enable motion vector search (potentially slow), strong deblocking filter |
509 // for damaged macroblocks, and set our error detection sensitivity. | 514 // for damaged macroblocks, and set our error detection sensitivity. |
510 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 515 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
511 codec_context_->err_recognition = AV_EF_CAREFUL; | 516 codec_context_->err_recognition = AV_EF_CAREFUL; |
512 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); | 517 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); |
513 codec_context_->opaque = this; | 518 codec_context_->opaque = this; |
514 codec_context_->flags |= CODEC_FLAG_EMU_EDGE; | 519 codec_context_->flags |= CODEC_FLAG_EMU_EDGE; |
515 codec_context_->get_buffer = GetVideoBufferImpl; | 520 codec_context_->get_buffer = GetVideoBufferImpl; |
516 codec_context_->release_buffer = ReleaseVideoBufferImpl; | 521 codec_context_->release_buffer = ReleaseVideoBufferImpl; |
517 | 522 |
518 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 523 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
519 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { | 524 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
520 ReleaseFFmpegResources(); | 525 ReleaseFFmpegResources(); |
521 return false; | 526 return false; |
522 } | 527 } |
523 | 528 |
524 av_frame_ = avcodec_alloc_frame(); | 529 av_frame_ = avcodec_alloc_frame(); |
525 return true; | 530 return true; |
526 } | 531 } |
527 | 532 |
528 } // namespace media | 533 } // namespace media |
OLD | NEW |