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_ptr<VaapiWrapper> wrapper_; | 84 scoped_refptr<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 (x_display_, num_outputted_pictures_, num_surfaces_) | 90 // These members (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_; | |
93 int num_outputted_pictures_; // number of pictures already outputted | 92 int num_outputted_pictures_; // number of pictures already outputted |
94 size_t num_surfaces_; // number of surfaces in the current set of surfaces | 93 size_t num_surfaces_; // number of surfaces in the current set of surfaces |
95 base::MD5Context md5_context_; | 94 base::MD5Context md5_context_; |
96 }; | 95 }; |
97 | 96 |
98 VaapiH264DecoderLoop::VaapiH264DecoderLoop() | 97 VaapiH264DecoderLoop::VaapiH264DecoderLoop() |
99 : x_display_(NULL), num_outputted_pictures_(0), num_surfaces_(0) { | 98 : num_outputted_pictures_(0), num_surfaces_(0) { |
100 base::MD5Init(&md5_context_); | 99 base::MD5Init(&md5_context_); |
101 } | 100 } |
102 | 101 |
103 VaapiH264DecoderLoop::~VaapiH264DecoderLoop() { | 102 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 } | |
113 } | 103 } |
114 | 104 |
115 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { | 105 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { |
116 LOG(FATAL) << "Oh noes! Decoder failed: " << error; | 106 LOG(FATAL) << "Oh noes! Decoder failed: " << error; |
117 } | 107 } |
118 | 108 |
119 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, | 109 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, |
120 base::FilePath output_file) { | 110 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 | |
127 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; | 111 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; |
128 base::Closure report_error_cb = | 112 base::Closure report_error_cb = |
129 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); | 113 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); |
130 wrapper_ = VaapiWrapper::Create( | 114 wrapper_ = |
131 VaapiWrapper::kDecode, profile, x_display_, report_error_cb); | 115 VaapiWrapper::Create(VaapiWrapper::kDecode, profile, report_error_cb); |
132 if (!wrapper_.get()) { | 116 if (!wrapper_.get()) { |
133 LOG(ERROR) << "Can't create vaapi wrapper"; | 117 LOG(ERROR) << "Can't create vaapi wrapper"; |
134 return false; | 118 return false; |
135 } | 119 } |
136 | 120 |
137 decoder_.reset(new VaapiH264Decoder( | 121 decoder_.reset(new VaapiH264Decoder( |
138 wrapper_.get(), | 122 wrapper_.get(), |
139 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), | 123 base::Bind(&VaapiH264DecoderLoop::OutputPicture, base::Unretained(this)), |
140 base::Bind(&LogOnError))); | 124 base::Bind(&LogOnError))); |
141 | 125 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 273 } |
290 | 274 |
291 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { | 275 void VaapiH264DecoderLoop::RecycleSurface(VASurfaceID va_surface_id) { |
292 available_surfaces_.push_back(va_surface_id); | 276 available_surfaces_.push_back(va_surface_id); |
293 } | 277 } |
294 | 278 |
295 void VaapiH264DecoderLoop::RefillSurfaces() { | 279 void VaapiH264DecoderLoop::RefillSurfaces() { |
296 for (size_t i = 0; i < available_surfaces_.size(); i++) { | 280 for (size_t i = 0; i < available_surfaces_.size(); i++) { |
297 VASurface::ReleaseCB release_cb = base::Bind( | 281 VASurface::ReleaseCB release_cb = base::Bind( |
298 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); | 282 &VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this)); |
299 scoped_refptr<VASurface> surface( | 283 scoped_refptr<VASurface> surface(new VASurface( |
300 new VASurface(available_surfaces_[i], release_cb)); | 284 available_surfaces_[i], decoder_->GetPicSize(), release_cb)); |
301 decoder_->ReuseSurface(surface); | 285 decoder_->ReuseSurface(surface); |
302 } | 286 } |
303 available_surfaces_.clear(); | 287 available_surfaces_.clear(); |
304 } | 288 } |
305 | 289 |
306 bool VaapiH264DecoderLoop::AllocateNewSurfaces() { | 290 bool VaapiH264DecoderLoop::AllocateNewSurfaces() { |
307 CHECK_EQ(num_surfaces_, available_surfaces_.size()) | 291 CHECK_EQ(num_surfaces_, available_surfaces_.size()) |
308 << "not all surfaces are returned"; | 292 << "not all surfaces are returned"; |
309 | 293 |
310 available_surfaces_.clear(); | 294 available_surfaces_.clear(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 content::g_md5sum = it->second; | 360 content::g_md5sum = it->second; |
377 continue; | 361 continue; |
378 } | 362 } |
379 if (it->first == "v" || it->first == "vmodule") | 363 if (it->first == "v" || it->first == "vmodule") |
380 continue; | 364 continue; |
381 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 365 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
382 } | 366 } |
383 | 367 |
384 return RUN_ALL_TESTS(); | 368 return RUN_ALL_TESTS(); |
385 } | 369 } |
OLD | NEW |