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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Give all surfaces in available_surfaces_ to the decoder. | 74 // Give all surfaces in available_surfaces_ to the decoder. |
75 void RefillSurfaces(); | 75 void RefillSurfaces(); |
76 | 76 |
77 // Free the current set of surfaces and allocate a new set of | 77 // Free the current set of surfaces and allocate a new set of |
78 // surfaces. Returns true when successful. | 78 // surfaces. Returns true when successful. |
79 bool AllocateNewSurfaces(); | 79 bool AllocateNewSurfaces(); |
80 | 80 |
81 // Use the data in the frame: write to file and update MD5 sum. | 81 // Use the data in the frame: write to file and update MD5 sum. |
82 bool ProcessVideoFrame(const scoped_refptr<media::VideoFrame>& frame); | 82 bool ProcessVideoFrame(const scoped_refptr<media::VideoFrame>& frame); |
83 | 83 |
84 scoped_refptr<VaapiWrapper> wrapper_; | 84 scoped_ptr<VaapiWrapper> wrapper_; |
85 scoped_ptr<VaapiH264Decoder> decoder_; | 85 scoped_ptr<VaapiH264Decoder> decoder_; |
86 std::string data_; // data read from input_file | 86 std::string data_; // data read from input_file |
87 base::FilePath output_file_; // output data is written to this file | 87 base::FilePath output_file_; // output data is written to this file |
88 std::vector<VASurfaceID> available_surfaces_; | 88 std::vector<VASurfaceID> available_surfaces_; |
89 | 89 |
90 // These members (num_outputted_pictures_, num_surfaces_) | 90 // These members (x_display_, num_outputted_pictures_, num_surfaces_) |
91 // need to be initialized and possibly freed manually. | 91 // need to be initialized and possibly freed manually. |
| 92 Display* x_display_; |
92 int num_outputted_pictures_; // number of pictures already outputted | 93 int num_outputted_pictures_; // number of pictures already outputted |
93 size_t num_surfaces_; // number of surfaces in the current set of surfaces | 94 size_t num_surfaces_; // number of surfaces in the current set of surfaces |
94 base::MD5Context md5_context_; | 95 base::MD5Context md5_context_; |
95 }; | 96 }; |
96 | 97 |
97 VaapiH264DecoderLoop::VaapiH264DecoderLoop() | 98 VaapiH264DecoderLoop::VaapiH264DecoderLoop() |
98 : num_outputted_pictures_(0), num_surfaces_(0) { | 99 : x_display_(NULL), num_outputted_pictures_(0), num_surfaces_(0) { |
99 base::MD5Init(&md5_context_); | 100 base::MD5Init(&md5_context_); |
100 } | 101 } |
101 | 102 |
102 VaapiH264DecoderLoop::~VaapiH264DecoderLoop() { | 103 VaapiH264DecoderLoop::~VaapiH264DecoderLoop() { |
| 104 // We need to destruct decoder and wrapper first because: |
| 105 // (1) The decoder has a reference to the wrapper. |
| 106 // (2) The wrapper has a reference to x_display_. |
| 107 decoder_.reset(); |
| 108 wrapper_.reset(); |
| 109 |
| 110 if (x_display_) { |
| 111 XCloseDisplay(x_display_); |
| 112 } |
103 } | 113 } |
104 | 114 |
105 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { | 115 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { |
106 LOG(FATAL) << "Oh noes! Decoder failed: " << error; | 116 LOG(FATAL) << "Oh noes! Decoder failed: " << error; |
107 } | 117 } |
108 | 118 |
109 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, | 119 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, |
110 base::FilePath output_file) { | 120 base::FilePath output_file) { |
| 121 x_display_ = XOpenDisplay(NULL); |
| 122 if (!x_display_) { |
| 123 LOG(ERROR) << "Can't open X display"; |
| 124 return false; |
| 125 } |
| 126 |
111 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; | 127 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; |
112 base::Closure report_error_cb = | 128 base::Closure report_error_cb = |
113 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); | 129 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); |
114 wrapper_ = | 130 wrapper_ = VaapiWrapper::Create( |
115 VaapiWrapper::Create(VaapiWrapper::kDecode, profile, report_error_cb); | 131 VaapiWrapper::kDecode, profile, x_display_, report_error_cb); |
116 if (!wrapper_.get()) { | 132 if (!wrapper_.get()) { |
117 LOG(ERROR) << "Can't create vaapi wrapper"; | 133 LOG(ERROR) << "Can't create vaapi wrapper"; |
118 return false; | 134 return false; |
119 } | 135 } |
120 | 136 |
121 decoder_.reset(new VaapiH264Decoder( | 137 decoder_.reset(new VaapiH264Decoder( |
122 wrapper_.get(), | 138 wrapper_.get(), |
123 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), | 139 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), |
124 base::Bind(&LogOnError))); | 140 base::Bind(&LogOnError))); |
125 | 141 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 289 } |
274 | 290 |
275 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { | 291 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { |
276 available_surfaces_.push_back(va_surface_id); | 292 available_surfaces_.push_back(va_surface_id); |
277 } | 293 } |
278 | 294 |
279 void VaapiH264DecoderLoop::RefillSurfaces() { | 295 void VaapiH264DecoderLoop::RefillSurfaces() { |
280 for (size_t i = 0; i < available_surfaces_.size(); i++) { | 296 for (size_t i = 0; i < available_surfaces_.size(); i++) { |
281 VASurface::ReleaseCB release_cb = base::Bind( | 297 VASurface::ReleaseCB release_cb = base::Bind( |
282 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); | 298 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); |
283 scoped_refptr<VASurface> surface(new VASurface( | 299 scoped_refptr<VASurface> surface( |
284 available_surfaces_[i], decoder_->GetPicSize(), release_cb)); | 300 new VASurface(available_surfaces_[i], release_cb)); |
285 decoder_->ReuseSurface(surface); | 301 decoder_->ReuseSurface(surface); |
286 } | 302 } |
287 available_surfaces_.clear(); | 303 available_surfaces_.clear(); |
288 } | 304 } |
289 | 305 |
290 bool VaapiH264DecoderLoop::AllocateNewSurfaces() { | 306 bool VaapiH264DecoderLoop::AllocateNewSurfaces() { |
291 CHECK_EQ(num_surfaces_, available_surfaces_.size()) | 307 CHECK_EQ(num_surfaces_, available_surfaces_.size()) |
292 << "not all surfaces are returned"; | 308 << "not all surfaces are returned"; |
293 | 309 |
294 available_surfaces_.clear(); | 310 available_surfaces_.clear(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 content::g_md5sum = it->second; | 376 content::g_md5sum = it->second; |
361 continue; | 377 continue; |
362 } | 378 } |
363 if (it->first == "v" || it->first == "vmodule") | 379 if (it->first == "v" || it->first == "vmodule") |
364 continue; | 380 continue; |
365 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 381 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
366 } | 382 } |
367 | 383 |
368 return RUN_ALL_TESTS(); | 384 return RUN_ALL_TESTS(); |
369 } | 385 } |
OLD | NEW |