-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[media] Refine DecoderBufferAllocator memory budget
Now SbMedia budget functions are properly respected when deciding MediaSource buffer memory limits. `demuxer_memory_limit_starboard.cc` has been added to //media/base instead of //media/starboard to avoid circular dependency, and to be consistent with the existing Chromium mechanism to branch Demuxer memory limits on different platforms. DecoderBuffer::Allocator interface has been refined to remove SbMedia types, and all Starboard dependency is resolved inside the concrete DecoderBufferAllocator implementation in //media/starboard. The logic to determine whether a video is 10 bits has been refined, as the video mime type is no longer available. b/322027866
- Loading branch information
Showing
6 changed files
with
106 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2022 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "media/base/demuxer_memory_limit.h" | ||
|
||
#include "build/build_config.h" | ||
#include "media/base/decoder_buffer.h" | ||
#include "media/base/video_codecs.h" | ||
#include "base/logging.h" | ||
|
||
#if !BUILDFLAG(USE_STARBOARD_MEDIA) | ||
#error "This file only works with Starboard media." | ||
#endif // !BUILDFLAG(USE_STARBOARD_MEDIA) | ||
|
||
namespace media { | ||
namespace { | ||
|
||
int GetBitsPerPixel(const VideoDecoderConfig* video_config) { | ||
DCHECK(video_config); | ||
|
||
if (video_config->codec() == VideoCodec::kH264) { | ||
LOG(INFO) << "H264 encountered, assume 8 bits."; | ||
return 8; | ||
} | ||
|
||
int bits = 8; | ||
|
||
if (video_config->codec() == VideoCodec::kVP9) { | ||
if (video_config->profile() == VP9PROFILE_PROFILE2 || | ||
video_config->profile() == VP9PROFILE_PROFILE3) { | ||
bits = 10; | ||
} | ||
|
||
LOG(INFO) << "VP9 profile " | ||
<< (video_config->profile() - VP9PROFILE_PROFILE0) | ||
<< " encountered, assume " << bits << " bits."; | ||
return bits; | ||
} | ||
|
||
if (video_config->codec() == VideoCodec::kAV1) { | ||
if (video_config->color_space_info().primaries >= VideoColorSpace::PrimaryID::BT2020 || | ||
video_config->color_space_info().transfer >= VideoColorSpace::TransferID::BT2020_10) { | ||
bits = 10; | ||
} | ||
LOG(INFO) << "AV1 with color space " << video_config->color_space_info().ToString() | ||
<< " encountered, assume " << bits << " bits."; | ||
} | ||
|
||
return 8; | ||
} | ||
|
||
} // namespace | ||
|
||
size_t GetDemuxerStreamAudioMemoryLimit( | ||
const AudioDecoderConfig* /*audio_config*/) { | ||
return DecoderBuffer::Allocator::GetInstance()->GetAudioBufferBudget(); | ||
} | ||
|
||
size_t GetDemuxerStreamVideoMemoryLimit( | ||
Demuxer::DemuxerTypes /*demuxer_type*/, | ||
const VideoDecoderConfig* video_config) { | ||
if (!video_config) { | ||
return DecoderBuffer::Allocator::GetInstance()->GetVideoBufferBudget( | ||
VideoCodec::kH264, 1920, 1080, 8); | ||
} | ||
|
||
auto width = video_config->visible_rect().size().width(); | ||
auto height = video_config->visible_rect().size().height(); | ||
auto bits_per_pixel = GetBitsPerPixel(video_config); | ||
auto codec = video_config->codec(); | ||
return DecoderBuffer::Allocator::GetInstance()->GetVideoBufferBudget( | ||
codec, width, height, bits_per_pixel); | ||
} | ||
|
||
size_t GetDemuxerMemoryLimit(Demuxer::DemuxerTypes demuxer_type) { | ||
return GetDemuxerStreamAudioMemoryLimit(nullptr) + | ||
GetDemuxerStreamVideoMemoryLimit(demuxer_type, nullptr); | ||
} | ||
|
||
} // 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
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