Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XB1] Expand hardware video decoder logs #4137

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions starboard/shared/win32/media_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ MediaTransform::MediaTransform(CLSID clsid)
if (FAILED(hr) || !transform_) {
transform_ = nullptr;
state_ = kDrained;
transform_create_error_message_ =
"Could not create decoder transform. " +
::starboard::shared::win32::HResultToString(hr);
}
}

Expand Down Expand Up @@ -310,6 +313,10 @@ HRESULT MediaTransform::SendMessage(MFT_MESSAGE_TYPE msg,
return transform_->ProcessMessage(msg, data);
}

std::string MediaTransform::GetTransformCreateError() const {
return transform_create_error_message_;
}

void MediaTransform::Reset() {
if (stream_begun_) {
SendMessage(MFT_MESSAGE_COMMAND_FLUSH);
Expand Down
4 changes: 4 additions & 0 deletions starboard/shared/win32/media_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <mfidl.h>
#include <wrl\client.h>

#include <string>
#include <vector>

#include "starboard/media.h"
Expand Down Expand Up @@ -84,6 +85,8 @@ class MediaTransform {

HRESULT SendMessage(MFT_MESSAGE_TYPE msg, ULONG_PTR data = 0);

std::string GetTransformCreateError() const;

// Reset the media transform to its original state.
void Reset();

Expand All @@ -106,6 +109,7 @@ class MediaTransform {
bool stream_begun_;
bool discontinuity_;
bool throttle_inputs_;
std::string transform_create_error_message_;
};

} // namespace win32
Expand Down
41 changes: 28 additions & 13 deletions starboard/shared/win32/video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,20 @@ scoped_ptr<MediaTransform> CreateVideoTransform(
const GUID& decoder_guid,
const GUID& input_guid,
const GUID& output_guid,
const IMFDXGIDeviceManager* device_manager) {
const IMFDXGIDeviceManager* device_manager,
std::string* error_message) {
scoped_ptr<MediaTransform> media_transform(new MediaTransform(decoder_guid));
if (!media_transform->HasValidTransform()) {
// Decoder Transform setup failed
*error_message = media_transform->GetTransformCreateError();
return scoped_ptr<MediaTransform>().Pass();
}
media_transform->EnableInputThrottle(true);

ComPtr<IMFAttributes> attributes = media_transform->GetAttributes();
if (!attributes) {
// Decoder Transform setup failed
*error_message = "Invalid MediaTransform attributes";
return scoped_ptr<MediaTransform>().Pass();
}

Expand All @@ -124,6 +127,8 @@ scoped_ptr<MediaTransform> CreateVideoTransform(
hr = attributes->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, FALSE);
if (FAILED(hr)) {
SB_LOG(WARNING) << "Unable to disable DXVA.";
*error_message = "Unable to disable DXVA. " +
::starboard::shared::win32::HResultToString(hr);
return scoped_ptr<MediaTransform>().Pass();
}
} else {
Expand All @@ -139,11 +144,13 @@ scoped_ptr<MediaTransform> CreateVideoTransform(
// Tell the decoder to allocate resources for the maximum resolution in
// order to minimize glitching on resolution changes.
if (FAILED(attributes->SetUINT32(MF_MT_DECODER_USE_MAX_RESOLUTION, 1))) {
*error_message = "Cannot allocate resources for maximum resolution.";
return scoped_ptr<MediaTransform>().Pass();
}

ComPtr<IMFMediaType> input_type;
if (FAILED(MFCreateMediaType(&input_type)) || !input_type) {
*error_message = "Invalid IMFMediaType.";
return scoped_ptr<MediaTransform>().Pass();
}
CheckResult(input_type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
Expand Down Expand Up @@ -274,11 +281,13 @@ void VideoDecoder::Initialize(const DecoderStatusCB& decoder_status_cb,
SB_DCHECK(error_cb);
decoder_status_cb_ = decoder_status_cb;
error_cb_ = error_cb;
std::string error_message;
if (video_device_) {
InitializeCodec();
InitializeCodec(&error_message);
}
if (!decoder_) {
error_cb_(kSbPlayerErrorDecode, "Cannot initialize codec.");
error_cb_(kSbPlayerErrorDecode,
"Cannot initialize codec. Error: " + error_message);
}
}

Expand Down Expand Up @@ -421,43 +430,49 @@ SbDecodeTarget VideoDecoder::CreateDecodeTarget() {
return decode_target;
}

void VideoDecoder::InitializeCodec() {
void VideoDecoder::InitializeCodec(std::string* error_message) {
scoped_ptr<MediaTransform> media_transform;

// If this is updated then media_is_video_supported.cc also needs to be
// updated.
switch (video_codec_) {
case kSbMediaVideoCodecH264: {
media_transform =
CreateVideoTransform(CLSID_MSH264DecoderMFT, MFVideoFormat_H264,
MFVideoFormat_NV12, device_manager_.Get());
media_transform = CreateVideoTransform(
CLSID_MSH264DecoderMFT, MFVideoFormat_H264, MFVideoFormat_NV12,
device_manager_.Get(), error_message);
priming_output_count_ = 0;
if (!media_transform) {
SB_LOG(WARNING) << "H264 hardware decoder creation failed.";
*error_message =
"H264 hardware decoder creation failed. " + *error_message;
return;
}
break;
}
case kSbMediaVideoCodecVp9: {
if (IsHardwareVp9DecoderSupported()) {
media_transform =
CreateVideoTransform(CLSID_MSVPxDecoder, MFVideoFormat_VP90,
MFVideoFormat_NV12, device_manager_.Get());
media_transform = CreateVideoTransform(
CLSID_MSVPxDecoder, MFVideoFormat_VP90, MFVideoFormat_NV12,
device_manager_.Get(), error_message);
priming_output_count_ = kVp9PrimingFrameCount;
}
if (!media_transform) {
SB_LOG(WARNING) << "VP9 hardware decoder creation failed.";
*error_message =
"VP9 hardware decoder creation failed. " + *error_message;
return;
}
break;
}
case kSbMediaVideoCodecAv1: {
media_transform =
CreateVideoTransform(MFVideoFormat_AV1, MFVideoFormat_AV1,
MFVideoFormat_NV12, device_manager_.Get());
media_transform = CreateVideoTransform(
MFVideoFormat_AV1, MFVideoFormat_AV1, MFVideoFormat_NV12,
device_manager_.Get(), error_message);
priming_output_count_ = 0;
if (!media_transform) {
SB_LOG(WARNING) << "AV1 hardware decoder creation failed.";
*error_message =
"AV1 hardware decoder creation failed. " + *error_message;
return;
}
break;
Expand Down
3 changes: 2 additions & 1 deletion starboard/shared/win32/video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <atomic>
#include <list>
#include <memory>
#include <string>

#include "starboard/common/mutex.h"
#include "starboard/common/ref_counted.h"
Expand Down Expand Up @@ -100,7 +101,7 @@ class VideoDecoder
return true;
}

void InitializeCodec();
void InitializeCodec(std::string* error_message);
void ShutdownCodec();
static void ReleaseDecodeTargets(void* context);

Expand Down
Loading