Skip to content

Commit

Permalink
[XB] Workaround to fix memory issue for Xbox One X (youtube#787)
Browse files Browse the repository at this point in the history
Number of the video decoder output buffers was decreased from 10 to 5

b/268591344

Change-Id: Icbbdab428196c119e606ef7653b3b17a8e9ec846
  • Loading branch information
iuriionishchenko committed Jul 18, 2023
1 parent 35d7572 commit 0a69bb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions starboard/shared/win32/video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ void VideoDecoder::InitializeCodec() {

ComPtr<IMFAttributes> attributes = transform->GetAttributes();
SB_DCHECK(attributes);
CheckResult(attributes->SetUINT32(MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT,
kMaxOutputSamples));
CheckResult(
attributes->SetUINT32(MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT,
static_cast<UINT32>(GetMaxNumberOfCachedFrames())));

UpdateVideoArea(transform->GetCurrentOutputType());

Expand Down Expand Up @@ -716,7 +717,7 @@ void VideoDecoder::DecoderThreadRun() {
// MF_SA_MINIMUM_OUTPUT_SAMPLE_COUNT.
thread_lock_.Acquire();
bool input_full = thread_events_.size() >= kMaxInputSamples;
bool output_full = thread_outputs_.size() >= kMaxOutputSamples;
bool output_full = thread_outputs_.size() >= GetMaxNumberOfCachedFrames();
thread_lock_.Release();

Status status = input_full ? kBufferFull : kNeedMoreInput;
Expand Down
13 changes: 13 additions & 0 deletions starboard/xb1/shared/video_decoder_uwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace starboard {
namespace xb1 {
namespace shared {

const int kXboxeOneXMaxOutputSamples = 5;

VideoDecoderUwp::~VideoDecoderUwp() {
if (IsHdrSupported() && IsHdrAngleModeEnabled()) {
SetHdrAngleModeEnabled(false);
Expand Down Expand Up @@ -78,6 +80,17 @@ bool VideoDecoderUwp::TryUpdateOutputForHdrVideo(
return true;
}

size_t VideoDecoderUwp::GetPrerollFrameCount() {
return GetMaxNumberOfCachedFrames();
}

size_t VideoDecoderUwp::GetMaxNumberOfCachedFrames() {
return (::starboard::shared::uwp::kXboxOneX ==
::starboard::shared::uwp::GetXboxType())
? kXboxeOneXMaxOutputSamples
: ::starboard::shared::win32::VideoDecoder::GetPrerollFrameCount();
}

} // namespace shared
} // namespace xb1
} // namespace starboard
4 changes: 4 additions & 0 deletions starboard/xb1/shared/video_decoder_uwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "starboard/shared/starboard/media/media_util.h"
#include "starboard/shared/uwp/application_uwp.h"
#include "starboard/shared/uwp/xb1_get_type.h"
#include "starboard/shared/win32/video_decoder.h"

namespace starboard {
Expand Down Expand Up @@ -48,6 +49,9 @@ class VideoDecoderUwp : public ::starboard::shared::win32::VideoDecoder {

bool TryUpdateOutputForHdrVideo(const VideoStreamInfo& stream_info) override;

size_t GetPrerollFrameCount() const override;
size_t GetMaxNumberOfCachedFrames() const override;

private:
SbMediaColorMetadata current_color_metadata_ = {};
bool is_first_input_ = true;
Expand Down

0 comments on commit 0a69bb9

Please sign in to comment.