| 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/gpu/dxva_video_decode_accelerator_win.h" | 5 #include "media/gpu/dxva_video_decode_accelerator_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #if !defined(OS_WIN) | 9 #if !defined(OS_WIN) |
| 10 #error This file should only be built on Windows. | 10 #error This file should only be built on Windows. |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 config_changed_ = true; | 444 config_changed_ = true; |
| 445 } else { | 445 } else { |
| 446 pending_config_changed_ = true; | 446 pending_config_changed_ = true; |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 last_pps_.swap(pps); | 449 last_pps_.swap(pps); |
| 450 } | 450 } |
| 451 return true; | 451 return true; |
| 452 } | 452 } |
| 453 | 453 |
| 454 gfx::ColorSpace H264ConfigChangeDetector::current_color_space() const { | 454 VideoColorSpace H264ConfigChangeDetector::current_color_space() const { |
| 455 if (!parser_) | 455 if (!parser_) |
| 456 return gfx::ColorSpace(); | 456 return VideoColorSpace(); |
| 457 // TODO(hubbe): Is using last_sps_id_ correct here? | 457 // TODO(hubbe): Is using last_sps_id_ correct here? |
| 458 const H264SPS* sps = parser_->GetSPS(last_sps_id_); | 458 const H264SPS* sps = parser_->GetSPS(last_sps_id_); |
| 459 if (sps) | 459 if (sps) |
| 460 return sps->GetColorSpace(); | 460 return sps->GetColorSpace(); |
| 461 return gfx::ColorSpace(); | 461 return VideoColorSpace(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 DXVAVideoDecodeAccelerator::PendingSampleInfo::PendingSampleInfo( | 464 DXVAVideoDecodeAccelerator::PendingSampleInfo::PendingSampleInfo( |
| 465 int32_t buffer_id, | 465 int32_t buffer_id, |
| 466 base::win::ScopedComPtr<IMFSample> sample, | 466 base::win::ScopedComPtr<IMFSample> sample, |
| 467 const gfx::ColorSpace& color_space) | 467 const gfx::ColorSpace& color_space) |
| 468 : input_buffer_id(buffer_id), | 468 : input_buffer_id(buffer_id), |
| 469 picture_buffer_id(-1), | 469 picture_buffer_id(-1), |
| 470 color_space(color_space), | 470 color_space(color_space), |
| 471 output_sample(sample) {} | 471 output_sample(sample) {} |
| (...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_DRAIN, 0), | 2166 RETURN_AND_NOTIFY_ON_FAILURE(SendMFTMessage(MFT_MESSAGE_COMMAND_DRAIN, 0), |
| 2167 "Failed to send drain message", | 2167 "Failed to send drain message", |
| 2168 PLATFORM_FAILURE, ); | 2168 PLATFORM_FAILURE, ); |
| 2169 sent_drain_message_ = true; | 2169 sent_drain_message_ = true; |
| 2170 } | 2170 } |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 // Attempt to retrieve an output frame from the decoder. If we have one, | 2173 // Attempt to retrieve an output frame from the decoder. If we have one, |
| 2174 // return and proceed when the output frame is processed. If we don't have a | 2174 // return and proceed when the output frame is processed. If we don't have a |
| 2175 // frame then we are done. | 2175 // frame then we are done. |
| 2176 gfx::ColorSpace color_space = config_change_detector_->current_color_space(); | 2176 VideoColorSpace color_space = config_change_detector_->current_color_space(); |
| 2177 if (!color_space.IsValid()) | 2177 if (color_space == VideoColorSpace()) |
| 2178 color_space = config_.color_space; | 2178 color_space = config_.color_space; |
| 2179 DoDecode(color_space); | 2179 DoDecode(color_space.ToGfxColorSpace()); |
| 2180 if (OutputSamplesPresent()) | 2180 if (OutputSamplesPresent()) |
| 2181 return; | 2181 return; |
| 2182 | 2182 |
| 2183 if (!processing_config_changed_) { | 2183 if (!processing_config_changed_) { |
| 2184 SetState(kFlushing); | 2184 SetState(kFlushing); |
| 2185 | 2185 |
| 2186 main_thread_task_runner_->PostTask( | 2186 main_thread_task_runner_->PostTask( |
| 2187 FROM_HERE, | 2187 FROM_HERE, |
| 2188 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone, weak_ptr_)); | 2188 base::Bind(&DXVAVideoDecodeAccelerator::NotifyFlushDone, weak_ptr_)); |
| 2189 } else { | 2189 } else { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2218 PLATFORM_FAILURE, ); | 2218 PLATFORM_FAILURE, ); |
| 2219 | 2219 |
| 2220 processing_config_changed_ = config_changed; | 2220 processing_config_changed_ = config_changed; |
| 2221 | 2221 |
| 2222 if (config_changed) { | 2222 if (config_changed) { |
| 2223 pending_input_buffers_.push_back(sample); | 2223 pending_input_buffers_.push_back(sample); |
| 2224 FlushInternal(); | 2224 FlushInternal(); |
| 2225 return; | 2225 return; |
| 2226 } | 2226 } |
| 2227 | 2227 |
| 2228 gfx::ColorSpace color_space = config_change_detector_->current_color_space(); | 2228 VideoColorSpace color_space = config_change_detector_->current_color_space(); |
| 2229 if (!color_space.IsValid()) | 2229 if (color_space == VideoColorSpace()) |
| 2230 color_space = config_.color_space; | 2230 color_space = config_.color_space; |
| 2231 | 2231 |
| 2232 if (!inputs_before_decode_) { | 2232 if (!inputs_before_decode_) { |
| 2233 TRACE_EVENT_ASYNC_BEGIN0("gpu", "DXVAVideoDecodeAccelerator.Decoding", | 2233 TRACE_EVENT_ASYNC_BEGIN0("gpu", "DXVAVideoDecodeAccelerator.Decoding", |
| 2234 this); | 2234 this); |
| 2235 } | 2235 } |
| 2236 inputs_before_decode_++; | 2236 inputs_before_decode_++; |
| 2237 { | 2237 { |
| 2238 ScopedExceptionCatcher catcher(using_ms_vp9_mft_); | 2238 ScopedExceptionCatcher catcher(using_ms_vp9_mft_); |
| 2239 hr = decoder_->ProcessInput(0, sample.get(), 0); | 2239 hr = decoder_->ProcessInput(0, sample.get(), 0); |
| 2240 } | 2240 } |
| 2241 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it | 2241 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it |
| 2242 // has enough data to produce one or more output samples. In this case the | 2242 // has enough data to produce one or more output samples. In this case the |
| 2243 // recommended options are to | 2243 // recommended options are to |
| 2244 // 1. Generate new output by calling IMFTransform::ProcessOutput until it | 2244 // 1. Generate new output by calling IMFTransform::ProcessOutput until it |
| 2245 // returns MF_E_TRANSFORM_NEED_MORE_INPUT. | 2245 // returns MF_E_TRANSFORM_NEED_MORE_INPUT. |
| 2246 // 2. Flush the input data | 2246 // 2. Flush the input data |
| 2247 // We implement the first option, i.e to retrieve the output sample and then | 2247 // We implement the first option, i.e to retrieve the output sample and then |
| 2248 // process the input again. Failure in either of these steps is treated as a | 2248 // process the input again. Failure in either of these steps is treated as a |
| 2249 // decoder failure. | 2249 // decoder failure. |
| 2250 if (hr == MF_E_NOTACCEPTING) { | 2250 if (hr == MF_E_NOTACCEPTING) { |
| 2251 DoDecode(color_space); | 2251 DoDecode(color_space.ToGfxColorSpace()); |
| 2252 // If the DoDecode call resulted in an output frame then we should not | 2252 // If the DoDecode call resulted in an output frame then we should not |
| 2253 // process any more input until that frame is copied to the target surface. | 2253 // process any more input until that frame is copied to the target surface. |
| 2254 if (!OutputSamplesPresent()) { | 2254 if (!OutputSamplesPresent()) { |
| 2255 State state = GetState(); | 2255 State state = GetState(); |
| 2256 RETURN_AND_NOTIFY_ON_FAILURE( | 2256 RETURN_AND_NOTIFY_ON_FAILURE( |
| 2257 (state == kStopped || state == kNormal || state == kFlushing), | 2257 (state == kStopped || state == kNormal || state == kFlushing), |
| 2258 "Failed to process output. Unexpected decoder state: " << state, | 2258 "Failed to process output. Unexpected decoder state: " << state, |
| 2259 PLATFORM_FAILURE, ); | 2259 PLATFORM_FAILURE, ); |
| 2260 hr = decoder_->ProcessInput(0, sample.get(), 0); | 2260 hr = decoder_->ProcessInput(0, sample.get(), 0); |
| 2261 } | 2261 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2273 decoder_thread_task_runner_->PostTask( | 2273 decoder_thread_task_runner_->PostTask( |
| 2274 FROM_HERE, | 2274 FROM_HERE, |
| 2275 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, | 2275 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, |
| 2276 base::Unretained(this))); | 2276 base::Unretained(this))); |
| 2277 return; | 2277 return; |
| 2278 } | 2278 } |
| 2279 } | 2279 } |
| 2280 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to process input sample", | 2280 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to process input sample", |
| 2281 PLATFORM_FAILURE, ); | 2281 PLATFORM_FAILURE, ); |
| 2282 | 2282 |
| 2283 DoDecode(color_space); | 2283 DoDecode(color_space.ToGfxColorSpace()); |
| 2284 | 2284 |
| 2285 State state = GetState(); | 2285 State state = GetState(); |
| 2286 RETURN_AND_NOTIFY_ON_FAILURE( | 2286 RETURN_AND_NOTIFY_ON_FAILURE( |
| 2287 (state == kStopped || state == kNormal || state == kFlushing), | 2287 (state == kStopped || state == kNormal || state == kFlushing), |
| 2288 "Failed to process output. Unexpected decoder state: " << state, | 2288 "Failed to process output. Unexpected decoder state: " << state, |
| 2289 ILLEGAL_STATE, ); | 2289 ILLEGAL_STATE, ); |
| 2290 | 2290 |
| 2291 LONGLONG input_buffer_id = 0; | 2291 LONGLONG input_buffer_id = 0; |
| 2292 RETURN_ON_HR_FAILURE( | 2292 RETURN_ON_HR_FAILURE( |
| 2293 sample->GetSampleTime(&input_buffer_id), | 2293 sample->GetSampleTime(&input_buffer_id), |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2953 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, | 2953 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, |
| 2954 base::Unretained(this))); | 2954 base::Unretained(this))); |
| 2955 } | 2955 } |
| 2956 | 2956 |
| 2957 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { | 2957 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { |
| 2958 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; | 2958 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; |
| 2959 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; | 2959 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; |
| 2960 } | 2960 } |
| 2961 | 2961 |
| 2962 } // namespace media | 2962 } // namespace media |
| OLD | NEW |