| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <deque> | 7 #include <deque> |
| 8 | 8 |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "media/base/callback.h" | 10 #include "media/base/callback.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 height_ > Limits::kMaxDimension || | 71 height_ > Limits::kMaxDimension || |
| 72 (width_ * height_) > Limits::kMaxCanvas) { | 72 (width_ * height_) > Limits::kMaxCanvas) { |
| 73 VideoCodecInfo info = {0}; | 73 VideoCodecInfo info = {0}; |
| 74 FFmpegVideoDecoder::OnInitializeComplete(info); | 74 FFmpegVideoDecoder::OnInitializeComplete(info); |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 VideoCodecConfig config; | 78 VideoCodecConfig config; |
| 79 switch (av_stream->codec->codec_id) { | 79 switch (av_stream->codec->codec_id) { |
| 80 case CODEC_ID_VC1: | 80 case CODEC_ID_VC1: |
| 81 config.codec_ = kCodecVC1; break; | 81 config.codec = kCodecVC1; break; |
| 82 case CODEC_ID_H264: | 82 case CODEC_ID_H264: |
| 83 config.codec_ = kCodecH264; break; | 83 config.codec = kCodecH264; break; |
| 84 case CODEC_ID_THEORA: | 84 case CODEC_ID_THEORA: |
| 85 config.codec_ = kCodecTheora; break; | 85 config.codec = kCodecTheora; break; |
| 86 case CODEC_ID_MPEG2VIDEO: | 86 case CODEC_ID_MPEG2VIDEO: |
| 87 config.codec_ = kCodecMPEG2; break; | 87 config.codec = kCodecMPEG2; break; |
| 88 case CODEC_ID_MPEG4: | 88 case CODEC_ID_MPEG4: |
| 89 config.codec_ = kCodecMPEG4; break; | 89 config.codec = kCodecMPEG4; break; |
| 90 case CODEC_ID_VP8: | 90 case CODEC_ID_VP8: |
| 91 config.codec_ = kCodecVP8; break; | 91 config.codec = kCodecVP8; break; |
| 92 default: | 92 default: |
| 93 NOTREACHED(); | 93 NOTREACHED(); |
| 94 } | 94 } |
| 95 config.opaque_context_ = av_stream; | 95 config.opaque_context = av_stream; |
| 96 config.width_ = width_; | 96 config.width = width_; |
| 97 config.height_ = height_; | 97 config.height = height_; |
| 98 decode_engine_->Initialize(message_loop(), this, config); | 98 decode_engine_->Initialize(message_loop(), this, config); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void FFmpegVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { | 101 void FFmpegVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { |
| 102 DCHECK_EQ(MessageLoop::current(), message_loop()); | 102 DCHECK_EQ(MessageLoop::current(), message_loop()); |
| 103 DCHECK(initialize_callback_.get()); | 103 DCHECK(initialize_callback_.get()); |
| 104 | 104 |
| 105 info_ = info; // Save a copy. | 105 info_ = info; // Save a copy. |
| 106 | 106 |
| 107 if (info.success_) { | 107 if (info.success) { |
| 108 media_format_.SetAsString(MediaFormat::kMimeType, | 108 media_format_.SetAsString(MediaFormat::kMimeType, |
| 109 mime_type::kUncompressedVideo); | 109 mime_type::kUncompressedVideo); |
| 110 media_format_.SetAsInteger(MediaFormat::kWidth, width_); | 110 media_format_.SetAsInteger(MediaFormat::kWidth, width_); |
| 111 media_format_.SetAsInteger(MediaFormat::kHeight, height_); | 111 media_format_.SetAsInteger(MediaFormat::kHeight, height_); |
| 112 media_format_.SetAsInteger( | 112 media_format_.SetAsInteger( |
| 113 MediaFormat::kSurfaceType, | 113 MediaFormat::kSurfaceType, |
| 114 static_cast<int>(info.stream_info_.surface_type_)); | 114 static_cast<int>(info.stream_info.surface_type)); |
| 115 media_format_.SetAsInteger( | 115 media_format_.SetAsInteger( |
| 116 MediaFormat::kSurfaceFormat, | 116 MediaFormat::kSurfaceFormat, |
| 117 static_cast<int>(info.stream_info_.surface_format_)); | 117 static_cast<int>(info.stream_info.surface_format)); |
| 118 state_ = kNormal; | 118 state_ = kNormal; |
| 119 } else { | 119 } else { |
| 120 host()->SetError(PIPELINE_ERROR_DECODE); | 120 host()->SetError(PIPELINE_ERROR_DECODE); |
| 121 } | 121 } |
| 122 | 122 |
| 123 initialize_callback_->Run(); | 123 initialize_callback_->Run(); |
| 124 initialize_callback_.reset(); | 124 initialize_callback_.reset(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void FFmpegVideoDecoder::Stop(FilterCallback* callback) { | 127 void FFmpegVideoDecoder::Stop(FilterCallback* callback) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 pts.duration = duration; | 403 pts.duration = duration; |
| 404 } else { | 404 } else { |
| 405 // Otherwise assume a normal frame duration. | 405 // Otherwise assume a normal frame duration. |
| 406 pts.duration = ConvertTimestamp(time_base, 1); | 406 pts.duration = ConvertTimestamp(time_base, 1); |
| 407 } | 407 } |
| 408 | 408 |
| 409 return pts; | 409 return pts; |
| 410 } | 410 } |
| 411 | 411 |
| 412 bool FFmpegVideoDecoder::ProvidesBuffer() { | 412 bool FFmpegVideoDecoder::ProvidesBuffer() { |
| 413 DCHECK(info_.success_); | 413 DCHECK(info_.success); |
| 414 return info_.provides_buffers_; | 414 return info_.provides_buffers; |
| 415 } | 415 } |
| 416 | 416 |
| 417 void FFmpegVideoDecoder::FlushBuffers() { | 417 void FFmpegVideoDecoder::FlushBuffers() { |
| 418 while (!frame_queue_flushed_.empty()) { | 418 while (!frame_queue_flushed_.empty()) { |
| 419 scoped_refptr<VideoFrame> video_frame; | 419 scoped_refptr<VideoFrame> video_frame; |
| 420 video_frame = frame_queue_flushed_.front(); | 420 video_frame = frame_queue_flushed_.front(); |
| 421 frame_queue_flushed_.pop_front(); | 421 frame_queue_flushed_.pop_front(); |
| 422 | 422 |
| 423 // Depends on who own the buffers, we either return it to the renderer | 423 // Depends on who own the buffers, we either return it to the renderer |
| 424 // or return it to the decode engine. | 424 // or return it to the decode engine. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 441 } | 441 } |
| 442 | 442 |
| 443 // static | 443 // static |
| 444 bool FFmpegVideoDecoder::IsMediaFormatSupported(const MediaFormat& format) { | 444 bool FFmpegVideoDecoder::IsMediaFormatSupported(const MediaFormat& format) { |
| 445 std::string mime_type; | 445 std::string mime_type; |
| 446 return format.GetAsString(MediaFormat::kMimeType, &mime_type) && | 446 return format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 447 mime_type::kFFmpegVideo == mime_type; | 447 mime_type::kFFmpegVideo == mime_type; |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace media | 450 } // namespace media |
| OLD | NEW |