OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 // This has to be included first. | 7 // This has to be included first. |
8 // See http://code.google.com/p/googletest/issues/detail?id=371 | 8 // See http://code.google.com/p/googletest/issues/detail?id=371 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { | 105 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { |
106 LOG(FATAL) << "Oh noes! Decoder failed: " << error; | 106 LOG(FATAL) << "Oh noes! Decoder failed: " << error; |
107 } | 107 } |
108 | 108 |
109 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, | 109 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, |
110 base::FilePath output_file) { | 110 base::FilePath output_file) { |
111 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; | 111 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; |
112 base::Closure report_error_cb = | 112 base::Closure report_error_cb = |
113 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); | 113 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); |
114 wrapper_ = | 114 wrapper_ = VaapiWrapper::CreateForVideoCodec(VaapiWrapper::kDecode, profile, |
115 VaapiWrapper::Create(VaapiWrapper::kDecode, profile, report_error_cb); | 115 report_error_cb); |
116 if (!wrapper_.get()) { | 116 if (!wrapper_.get()) { |
117 LOG(ERROR) << "Can't create vaapi wrapper"; | 117 LOG(ERROR) << "Can't create vaapi wrapper"; |
118 return false; | 118 return false; |
119 } | 119 } |
120 | 120 |
121 decoder_.reset(new VaapiH264Decoder( | 121 decoder_.reset(new VaapiH264Decoder( |
122 wrapper_.get(), | 122 wrapper_.get(), |
123 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), | 123 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), |
124 base::Bind(&LogOnError))); | 124 base::Bind(&LogOnError))); |
125 | 125 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 void VaapiH264DecoderLoop::OutputPicture( | 242 void VaapiH264DecoderLoop::OutputPicture( |
243 int32 input_id, | 243 int32 input_id, |
244 const scoped_refptr<VASurface>& va_surface) { | 244 const scoped_refptr<VASurface>& va_surface) { |
245 DVLOG(1) << "OutputPicture: picture " << num_outputted_pictures_++; | 245 DVLOG(1) << "OutputPicture: picture " << num_outputted_pictures_++; |
246 | 246 |
247 VAImage image; | 247 VAImage image; |
248 void* mem; | 248 void* mem; |
249 | 249 |
250 if (!wrapper_->GetVaImageForTesting(va_surface->id(), &image, &mem)) { | 250 if (!wrapper_->GetDerivedVaImage(va_surface->id(), &image, &mem)) { |
251 LOG(ERROR) << "Cannot get VAImage."; | 251 LOG(ERROR) << "Cannot get VAImage."; |
252 return; | 252 return; |
253 } | 253 } |
254 | 254 |
255 if (image.format.fourcc != VA_FOURCC_NV12) { | 255 if (image.format.fourcc != VA_FOURCC_NV12) { |
256 LOG(ERROR) << "Unexpected image format: " << image.format.fourcc; | 256 LOG(ERROR) << "Unexpected image format: " << image.format.fourcc; |
257 wrapper_->ReturnVaImageForTesting(&image); | 257 wrapper_->ReturnVaImage(&image); |
258 return; | 258 return; |
259 } | 259 } |
260 | 260 |
261 // Convert NV12 to I420 format. | 261 // Convert NV12 to I420 format. |
262 scoped_refptr<media::VideoFrame> frame = CopyNV12ToI420(&image, mem); | 262 scoped_refptr<media::VideoFrame> frame = CopyNV12ToI420(&image, mem); |
263 | 263 |
264 if (frame.get()) { | 264 if (frame.get()) { |
265 if (!ProcessVideoFrame(frame)) { | 265 if (!ProcessVideoFrame(frame)) { |
266 LOG(ERROR) << "Write to file failed"; | 266 LOG(ERROR) << "Write to file failed"; |
267 } | 267 } |
268 } else { | 268 } else { |
269 LOG(ERROR) << "Cannot convert image to I420."; | 269 LOG(ERROR) << "Cannot convert image to I420."; |
270 } | 270 } |
271 | 271 |
272 wrapper_->ReturnVaImageForTesting(&image); | 272 wrapper_->ReturnVaImage(&image); |
273 } | 273 } |
274 | 274 |
275 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { | 275 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { |
276 available_surfaces_.push_back(va_surface_id); | 276 available_surfaces_.push_back(va_surface_id); |
277 } | 277 } |
278 | 278 |
279 void VaapiH264DecoderLoop::RefillSurfaces() { | 279 void VaapiH264DecoderLoop::RefillSurfaces() { |
280 for (size_t i = 0; i < available_surfaces_.size(); i++) { | 280 for (size_t i = 0; i < available_surfaces_.size(); i++) { |
281 VASurface::ReleaseCB release_cb = base::Bind( | 281 VASurface::ReleaseCB release_cb = base::Bind( |
282 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); | 282 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 content::g_md5sum = it->second; | 360 content::g_md5sum = it->second; |
361 continue; | 361 continue; |
362 } | 362 } |
363 if (it->first == "v" || it->first == "vmodule") | 363 if (it->first == "v" || it->first == "vmodule") |
364 continue; | 364 continue; |
365 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 365 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
366 } | 366 } |
367 | 367 |
368 return RUN_ALL_TESTS(); | 368 return RUN_ALL_TESTS(); |
369 } | 369 } |
OLD | NEW |