#include "media/filters/tizen/category_selector.h"
+#include <ri-api.h>
+
#include "base/bits.h"
#include "media/base/tizen/logger/media_logger.h"
#include "media/filters/tizen/resource_manager_utils.h"
}
}
+bool IsValidCategory(ri_rsc_category_e category) {
+ return category > 0;
+}
+
ri_rsc_category_e FindDecoderForResolution(
base::ResourceManager* manager,
const char* codec_name,
}
}
-ri_rsc_category_e SelectVideoDecoderCategory(
+absl::optional<CategorySelectionResult> SelectVideoDecoderCategory(
base::ResourceManager* resource_manager,
const VideoDecoderSelectionOpts& options) {
const char* codec_name = VideoCodecToCodecName(options.codec);
if (!codec_name) {
TIZEN_MEDIA_LOG_NO_INSTANCE(ERROR)
<< "Unsupported codec: " << static_cast<uint32_t>(options.codec);
- return RI_CATEGORY_NONE;
+ return absl::nullopt;
}
// MJPEG has different path in Resource Manager.
if (options.codec == MediaVideoCodec::kCodecMJPEG) {
- return static_cast<ri_rsc_category_e>(resource_manager->GetJpegCategoryId(
- codec_name, options.coded_size.width()));
+ const auto category =
+ static_cast<ri_rsc_category_e>(resource_manager->GetJpegCategoryId(
+ codec_name, options.coded_size.width()));
+ if (!IsValidCategory(category)) {
+ return absl::nullopt;
+ }
+ return CategorySelectionResult{.category = category,
+ .coded_size = options.coded_size,
+ .framerate = kDefaultFramerate,
+ .sampling = options.sampling,
+ .bit_depth = options.bit_depth};
}
uint32_t framerate =
resource_manager, workaround_codec_name, options.bit_depth,
workaround_coded_size, workaround_framerate,
ConvertChromaSampling(options.sampling), prefer_texturing_support);
- if (result > 0) {
- return result;
+ if (IsValidCategory(result)) {
+ return CategorySelectionResult{.category = result,
+ .coded_size = workaround_coded_size,
+ .framerate = workaround_framerate,
+ .sampling = options.sampling,
+ .bit_depth = options.bit_depth};
}
}
// Note that for game streaming, we'll continue with original parameters
// allocation.
if (use_h264_level50_workaround == UseHigherDecoder::kRequired) {
- return RI_CATEGORY_NONE;
+ return absl::nullopt;
}
// Try to allocate decoder using requested parameters, because either:
// - we can't apply workaround e.g. board doesn't have DVDE decoder,
// - we failed to allocate better decoder (DVDE), so as a fallback
// try to use MFC.
- return FindDecoderForResolution(
+ auto result = FindDecoderForResolution(
resource_manager, codec_name, options.bit_depth, options.coded_size,
framerate, ConvertChromaSampling(options.sampling),
prefer_texturing_support);
+ if (!IsValidCategory(result)) {
+ return absl::nullopt;
+ }
+ return CategorySelectionResult{.category = result,
+ .coded_size = options.coded_size,
+ .framerate = framerate,
+ .sampling = options.sampling,
+ .bit_depth = options.bit_depth};
}
} // namespace media
VideoCodecLevel level,
gfx::Size coded_size,
LatencyMode latency,
- int category,
+ CategorySelectionResult selection_result,
AllocationCallbacks callbacks) {
// To avoid taking resources from this process, firstly check
// whether there are:
base::AutoReset allocation_state(&during_allocation_, true);
base::AutoUnlock auto_lock(lock_);
maybe_resource = resource_manager->AllocateResource(
- category_id, category,
+ category_id, selection_result.category,
base::BindRepeating(&DecoderPromotion::ResourceConflict,
base::Unretained(this), decoder_id));
}
maybe_resource->token.PassOwnership(std::move(holder));
- uint32_t framerate = DetectMaximalFramerate(codec, level, coded_size)
- .value_or(kDefaultFramerate);
-
Entry entry;
entry.codec = codec;
- entry.level = level;
entry.coded_size = coded_size;
entry.latency = latency;
- entry.category = category;
- entry.framerate = framerate;
+ entry.allocation = selection_result;
entry.component_id = maybe_resource->device_id;
entry.component_name = maybe_resource->component_name;
entry.resource_manager = resource_manager;
DecodingMode decoding_mode = DecodingMode::kDecodingNormal;
#if TIZEN_VERSION_AT_LEAST(6, 5, 0)
- if (category == RI_CATEGORY_VIDEO_DECODER_H264_HD_8BIT_30P) {
+ if (selection_result.category == RI_CATEGORY_VIDEO_DECODER_H264_HD_8BIT_30P) {
decoding_mode = DecodingMode::kDecodingMultiH264_720p;
- } else if (category == RM_CATEGORY_VIDEO_DECODER_H264_FHD_N_8BIT_30P) {
+ } else if (selection_result.category ==
+ RM_CATEGORY_VIDEO_DECODER_H264_FHD_N_8BIT_30P) {
decoding_mode = DecodingMode::kDecodingMultiH264_1080p;
- } else if (category == RM_CATEGORY_VIDEO_DECODER_VP8_qHD_8BIT_30P) {
+ } else if (selection_result.category ==
+ RM_CATEGORY_VIDEO_DECODER_VP8_qHD_8BIT_30P) {
decoding_mode = DecodingMode::kDecodingMultiVP8_576p;
}
#endif
TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE) << "Decoder id:" << decoder.first;
TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE)
<< " * " << decoder.second.component_name;
- TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE) << " * " << decoder.second.category;
TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE)
- << " * " << decoder.second.coded_size.ToString();
+ << " * " << decoder.second.allocation.category;
TIZEN_MEDIA_LOG_NO_INSTANCE(VERBOSE)
- << " * " << decoder.second.framerate << " fps";
+ << " * " << decoder.second.coded_size.ToString();
}
}
}
for (const auto& decoder : video_decoders_) {
- if (CategoryIsNDecoding(decoder.second.category)) {
+ if (CategoryIsNDecoding(decoder.second.allocation.category)) {
continue;
}
// ndecoding configuration.
if (decoder.second.coded_size.width() <= max_decoding_resolution.width() &&
decoder.second.coded_size.height() <=
- max_decoding_resolution.height() &&
- DetectMaximalFramerate(decoder.second.codec, decoder.second.level,
- max_decoding_resolution)
- .value_or(kDefaultFramerate) <= kMaxNDecodingFramerate) {
+ max_decoding_resolution.height()) {
decoders_to_merge.push_back(decoder.first);
}
}
TIZEN_MEDIA_LOG(VERBOSE) << "Token obtained";
}
+ CategorySelectionResult selection_result{
+ .category = category,
+ .coded_size = max_decoding_resolution,
+ .framerate = kDefaultFramerate,
+ .sampling = VideoChromaSampling::k420,
+ .bit_depth = 8};
+
// Provide new resources for switching process and pass them to
// holders that previously returned their resources.
for (std::size_t i = 0; i < pairs.size(); ++i) {
ID id = decoders_to_merge[i];
TIZEN_MEDIA_LOG(INFO) << "Try switching decoder for decoder: " << id;
auto new_decoder =
- StandardAllocation(codec, level, coded_size, pairs[i].latency, category,
- pairs[i].callbacks);
+ StandardAllocation(codec, level, coded_size, pairs[i].latency,
+ selection_result, pairs[i].callbacks);
if (new_decoder) {
pairs[i].callbacks.switch_cb.Run(std::move(new_decoder.value()));
} else {
// original resource allocation request.
TIZEN_MEDIA_LOG(VERBOSE) << "Try allocate new decoder for result";
auto new_decoder = StandardAllocation(codec, level, coded_size, latency,
- category, callbacks);
+ selection_result, callbacks);
return new_decoder;
}
for (const auto& decoder : video_decoders_) {
for (size_t i = 0; i < already_allocated.size(); ++i) {
- if (decoder.second.category == kNDecodings[i].category) {
+ if (decoder.second.allocation.category == kNDecodings[i].category) {
already_allocated[i]++;
}
}
for (size_t i = 0; i < already_allocated.size(); ++i) {
if (already_allocated[i] > 0 &&
already_allocated[i] < kNDecodings[i].max_decoders) {
+ CategorySelectionResult selection_result{
+ .category = kNDecodings[i].category,
+ .coded_size = kNDecodings[i].max_resolution,
+ .framerate = kDefaultFramerate,
+ .sampling = VideoChromaSampling::k420,
+ .bit_depth = 8};
auto opt_decoder = StandardAllocation(codec, level, coded_size, latency,
- kNDecodings[i].category, callbacks);
+ selection_result, callbacks);
if (opt_decoder) {
return opt_decoder;
}
DumpAllocationStateLocked();
- ri_rsc_category_e category_option =
- SelectVideoDecoderCategory(GetResourceManager(), options);
- if (category_option <= 0) {
- TIZEN_MEDIA_LOG(ERROR) << "Failed on ri_get_capable_video_category_id: "
- << category_option;
- return absl::nullopt;
- }
-
// Check if any ndecoding session is created and not all decoders are taken
auto opt_decoder =
ExtendNDecoding(options.codec, options.level, options.coded_size,
return opt_decoder;
}
+ auto maybe_selection_result =
+ SelectVideoDecoderCategory(GetResourceManager(), options);
+ if (!maybe_selection_result) {
+ TIZEN_MEDIA_LOG(ERROR) << "Selection video decoder category failed";
+ return absl::nullopt;
+ }
+
// Try standard decoder allocation
opt_decoder =
StandardAllocation(options.codec, options.level, options.coded_size,
- options.latency, category_option, callbacks);
+ options.latency, *maybe_selection_result, callbacks);
if (opt_decoder) {
return opt_decoder;
}
});
TIZEN_MEDIA_LOG_ASSERT(decoder_it != video_decoders_.end())
<< "Decoder used for reselection has to be currently allocated";
- auto new_category = SelectVideoDecoderCategory(GetResourceManager(), options);
- return new_category != decoder_it->second.category;
+
+ auto maybe_selection_result =
+ SelectVideoDecoderCategory(GetResourceManager(), options);
+ if (!maybe_selection_result) {
+ return true;
+ }
+ return maybe_selection_result->category !=
+ decoder_it->second.allocation.category;
}
absl::optional<AllocatedDecoder> DecoderPromotion::SelectAudioDecoder(