forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
H264 HW encode using MediaFoundation
This CL adds MediaFoundationVideoEncodeAccelerator which enables H264 encode support using MediaFoundation on Windows 8.1+. Also, it includes a refactor of common MediaFoundation classes under mf_helpers.*. Note that, this is the first CL and H264 codec is still behind a flag. Design Doc(with perf measurements): http://goo.gl/UCnwyA BUG=590060 TEST= Tested AppRTC loopback with Chrome flag "--enable-webrtc-hw-h264-encoding" and "--enable-mf-h264-encoding" on https://apprtc.appspot.com/?debug=loopback&vsc=h264 Also, added WIN specific sections at vea_unittests. Review-Url: https://codereview.chromium.org/2058413003 Cr-Commit-Position: refs/heads/master@{#406876}
- Loading branch information
Showing
16 changed files
with
980 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "media/base/win/mf_helpers.h" | ||
|
||
namespace media { | ||
|
||
namespace mf { | ||
|
||
void LogDXVAError(int line) { | ||
LOG(ERROR) << "Error in dxva_video_decode_accelerator_win.cc on line " | ||
<< line; | ||
} | ||
|
||
IMFSample* CreateEmptySampleWithBuffer(uint32_t buffer_length, int align) { | ||
CHECK_GT(buffer_length, 0U); | ||
|
||
base::win::ScopedComPtr<IMFSample> sample; | ||
HRESULT hr = MFCreateSample(sample.Receive()); | ||
RETURN_ON_HR_FAILURE(hr, "MFCreateSample failed", NULL); | ||
|
||
base::win::ScopedComPtr<IMFMediaBuffer> buffer; | ||
if (align == 0) { | ||
// Note that MFCreateMemoryBuffer is same as MFCreateAlignedMemoryBuffer | ||
// with the align argument being 0. | ||
hr = MFCreateMemoryBuffer(buffer_length, buffer.Receive()); | ||
} else { | ||
hr = | ||
MFCreateAlignedMemoryBuffer(buffer_length, align - 1, buffer.Receive()); | ||
} | ||
RETURN_ON_HR_FAILURE(hr, "Failed to create memory buffer for sample", NULL); | ||
|
||
hr = sample->AddBuffer(buffer.get()); | ||
RETURN_ON_HR_FAILURE(hr, "Failed to add buffer to sample", NULL); | ||
|
||
buffer->SetCurrentLength(0); | ||
return sample.Detach(); | ||
} | ||
|
||
MediaBufferScopedPointer::MediaBufferScopedPointer(IMFMediaBuffer* media_buffer) | ||
: media_buffer_(media_buffer), | ||
buffer_(nullptr), | ||
max_length_(0), | ||
current_length_(0) { | ||
HRESULT hr = media_buffer_->Lock(&buffer_, &max_length_, ¤t_length_); | ||
CHECK(SUCCEEDED(hr)); | ||
} | ||
|
||
MediaBufferScopedPointer::~MediaBufferScopedPointer() { | ||
HRESULT hr = media_buffer_->Unlock(); | ||
CHECK(SUCCEEDED(hr)); | ||
} | ||
|
||
} // namespace mf | ||
|
||
} // namespace media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef MEDIA_BASE_WIN_MF_HELPERS_H_ | ||
#define MEDIA_BASE_WIN_MF_HELPERS_H_ | ||
|
||
#include <mfapi.h> | ||
#include <stdint.h> | ||
|
||
#include "base/win/scoped_comptr.h" | ||
#include "media/base/win/mf_initializer_export.h" | ||
|
||
namespace media { | ||
|
||
namespace mf { | ||
|
||
#define RETURN_ON_FAILURE(result, log, ret) \ | ||
do { \ | ||
if (!(result)) { \ | ||
DLOG(ERROR) << log; \ | ||
mf::LogDXVAError(__LINE__); \ | ||
return ret; \ | ||
} \ | ||
} while (0) | ||
|
||
#define RETURN_ON_HR_FAILURE(result, log, ret) \ | ||
RETURN_ON_FAILURE(SUCCEEDED(result), \ | ||
log << ", HRESULT: 0x" << std::hex << result, ret); | ||
|
||
#define RETURN_AND_NOTIFY_ON_FAILURE(result, log, error_code, ret) \ | ||
do { \ | ||
if (!(result)) { \ | ||
DVLOG(1) << log; \ | ||
mf::LogDXVAError(__LINE__); \ | ||
StopOnError(error_code); \ | ||
return ret; \ | ||
} \ | ||
} while (0) | ||
|
||
#define RETURN_AND_NOTIFY_ON_HR_FAILURE(result, log, error_code, ret) \ | ||
RETURN_AND_NOTIFY_ON_FAILURE(SUCCEEDED(result), \ | ||
log << ", HRESULT: 0x" << std::hex << result, \ | ||
error_code, ret); | ||
|
||
MF_INITIALIZER_EXPORT void LogDXVAError(int line); | ||
|
||
// Creates a Media Foundation sample with one buffer of length |buffer_length| | ||
// on a |align|-byte boundary. Alignment must be a perfect power of 2 or 0. | ||
MF_INITIALIZER_EXPORT IMFSample* CreateEmptySampleWithBuffer( | ||
uint32_t buffer_length, | ||
int align); | ||
|
||
// Provides scoped access to the underlying buffer in an IMFMediaBuffer | ||
// instance. | ||
class MF_INITIALIZER_EXPORT MediaBufferScopedPointer { | ||
public: | ||
MediaBufferScopedPointer(IMFMediaBuffer* media_buffer); | ||
~MediaBufferScopedPointer(); | ||
|
||
uint8_t* get() { return buffer_; } | ||
DWORD current_length() const { return current_length_; } | ||
|
||
private: | ||
base::win::ScopedComPtr<IMFMediaBuffer> media_buffer_; | ||
uint8_t* buffer_; | ||
DWORD max_length_; | ||
DWORD current_length_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(MediaBufferScopedPointer); | ||
}; | ||
|
||
} // namespace mf | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_BASE_WIN_MF_HELPERS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.