| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 // These members (x_display_, 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 Display* x_display_; |
| 93 int num_outputted_pictures_; // number of pictures already outputted | 93 int num_outputted_pictures_; // number of pictures already outputted |
| 94 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 |
| 95 base::MD5Context md5_context_; | 95 base::MD5Context md5_context_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 VaapiH264DecoderLoop::VaapiH264DecoderLoop() | 98 VaapiH264DecoderLoop::VaapiH264DecoderLoop() |
| 99 : x_display_(NULL), num_outputted_pictures_(0), num_surfaces_(0) { | 99 : x_display_(nullptr), num_outputted_pictures_(0), num_surfaces_(0) { |
| 100 base::MD5Init(&md5_context_); | 100 base::MD5Init(&md5_context_); |
| 101 } | 101 } |
| 102 | 102 |
| 103 VaapiH264DecoderLoop::~VaapiH264DecoderLoop() { | 103 VaapiH264DecoderLoop::~VaapiH264DecoderLoop() { |
| 104 // We need to destruct decoder and wrapper first because: | 104 // We need to destruct decoder and wrapper first because: |
| 105 // (1) The decoder has a reference to the wrapper. | 105 // (1) The decoder has a reference to the wrapper. |
| 106 // (2) The wrapper has a reference to x_display_. | 106 // (2) The wrapper has a reference to x_display_. |
| 107 decoder_.reset(); | 107 decoder_.reset(); |
| 108 wrapper_.reset(); | 108 wrapper_.reset(); |
| 109 | 109 |
| 110 if (x_display_) { | 110 if (x_display_) { |
| 111 XCloseDisplay(x_display_); | 111 XCloseDisplay(x_display_); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { | 115 void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) { |
| 116 LOG(FATAL) << "Oh noes! Decoder failed: " << error; | 116 LOG(FATAL) << "Oh noes! Decoder failed: " << error; |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, | 119 bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file, |
| 120 base::FilePath output_file) { | 120 base::FilePath output_file) { |
| 121 x_display_ = XOpenDisplay(NULL); | 121 x_display_ = XOpenDisplay(nullptr); |
| 122 if (!x_display_) { | 122 if (!x_display_) { |
| 123 LOG(ERROR) << "Can't open X display"; | 123 LOG(ERROR) << "Can't open X display"; |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; | 127 media::VideoCodecProfile profile = media::H264PROFILE_BASELINE; |
| 128 base::Closure report_error_cb = | 128 base::Closure report_error_cb = |
| 129 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); | 129 base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR); |
| 130 wrapper_ = VaapiWrapper::Create( | 130 wrapper_ = VaapiWrapper::Create( |
| 131 VaapiWrapper::kDecode, profile, x_display_, report_error_cb); | 131 VaapiWrapper::kDecode, profile, x_display_, report_error_cb); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 const int input_id = 0; // We don't use input_id in this class. | 147 const int input_id = 0; // We don't use input_id in this class. |
| 148 decoder_->SetStream( | 148 decoder_->SetStream( |
| 149 reinterpret_cast<const uint8*>(data_.c_str()), data_.size(), input_id); | 149 reinterpret_cast<const uint8*>(data_.c_str()), data_.size(), input_id); |
| 150 | 150 |
| 151 // This creates or truncates output_file. | 151 // This creates or truncates output_file. |
| 152 // Without it, AppendToFile() will not work. | 152 // Without it, AppendToFile() will not work. |
| 153 if (!output_file.empty()) { | 153 if (!output_file.empty()) { |
| 154 if (base::WriteFile(output_file, NULL, 0) != 0) { | 154 if (base::WriteFile(output_file, nullptr, 0) != 0) { |
| 155 return false; | 155 return false; |
| 156 } | 156 } |
| 157 output_file_ = output_file; | 157 output_file_ = output_file; |
| 158 } | 158 } |
| 159 | 159 |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 bool VaapiH264DecoderLoop::Run() { | 163 bool VaapiH264DecoderLoop::Run() { |
| 164 while (1) { | 164 while (1) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 content::g_md5sum = it->second; | 376 content::g_md5sum = it->second; |
| 377 continue; | 377 continue; |
| 378 } | 378 } |
| 379 if (it->first == "v" || it->first == "vmodule") | 379 if (it->first == "v" || it->first == "vmodule") |
| 380 continue; | 380 continue; |
| 381 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 381 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 382 } | 382 } |
| 383 | 383 |
| 384 return RUN_ALL_TESTS(); | 384 return RUN_ALL_TESTS(); |
| 385 } | 385 } |
| OLD | NEW |