Do not crash if codec is not available

Check if codec was successfully created and exit from RunTest if not
before creating VideoProcessor.

Bug: none
Change-Id: Ia6d7171650dbc9824fb78f4a8e2851f755cfd63b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209362
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33372}
This commit is contained in:
Sergey Silkin
2021-03-03 13:34:49 +01:00
committed by Commit Bot
parent 652ada5029
commit db0b4a8935
3 changed files with 78 additions and 33 deletions

View File

@ -20,6 +20,7 @@
#include <utility>
#include <vector>
#include "absl/strings/str_replace.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/transport/field_trial_based_config.h"
@ -408,8 +409,14 @@ void VideoCodecTestFixtureImpl::RunTest(
// codecs on a task queue.
TaskQueueForTest task_queue("VidProc TQ");
SetUpAndInitObjects(&task_queue, rate_profiles[0].target_kbps,
rate_profiles[0].input_fps);
bool is_setup_succeeded = SetUpAndInitObjects(
&task_queue, rate_profiles[0].target_kbps, rate_profiles[0].input_fps);
EXPECT_TRUE(is_setup_succeeded);
if (!is_setup_succeeded) {
ReleaseAndCloseObjects(&task_queue);
return;
}
PrintSettings(&task_queue);
ProcessAllFrames(&task_queue, rate_profiles);
ReleaseAndCloseObjects(&task_queue);
@ -597,7 +604,7 @@ void VideoCodecTestFixtureImpl::VerifyVideoStatistic(
}
}
void VideoCodecTestFixtureImpl::CreateEncoderAndDecoder() {
bool VideoCodecTestFixtureImpl::CreateEncoderAndDecoder() {
SdpVideoFormat::Parameters params;
if (config_.codec_settings.codecType == kVideoCodecH264) {
const char* packetization_mode =
@ -616,6 +623,9 @@ void VideoCodecTestFixtureImpl::CreateEncoderAndDecoder() {
encoder_ = encoder_factory_->CreateVideoEncoder(format);
EXPECT_TRUE(encoder_) << "Encoder not successfully created.";
if (encoder_ == nullptr) {
return false;
}
const size_t num_simulcast_or_spatial_layers = std::max(
config_.NumberOfSimulcastStreams(), config_.NumberOfSpatialLayers());
@ -626,7 +636,12 @@ void VideoCodecTestFixtureImpl::CreateEncoderAndDecoder() {
for (const auto& decoder : decoders_) {
EXPECT_TRUE(decoder) << "Decoder not successfully created.";
if (decoder == nullptr) {
return false;
}
}
return true;
}
void VideoCodecTestFixtureImpl::DestroyEncoderAndDecoder() {
@ -638,7 +653,7 @@ VideoCodecTestStats& VideoCodecTestFixtureImpl::GetStats() {
return stats_;
}
void VideoCodecTestFixtureImpl::SetUpAndInitObjects(
bool VideoCodecTestFixtureImpl::SetUpAndInitObjects(
TaskQueueForTest* task_queue,
size_t initial_bitrate_kbps,
double initial_framerate_fps) {
@ -661,17 +676,45 @@ void VideoCodecTestFixtureImpl::SetUpAndInitObjects(
RTC_DCHECK(encoded_frame_writers_.empty());
RTC_DCHECK(decoded_frame_writers_.empty());
stats_.Clear();
cpu_process_time_.reset(new CpuProcessTime(config_));
bool is_codec_created = false;
task_queue->SendTask(
[this, &is_codec_created]() {
is_codec_created = CreateEncoderAndDecoder();
},
RTC_FROM_HERE);
if (!is_codec_created) {
return false;
}
task_queue->SendTask(
[this]() {
processor_ = std::make_unique<VideoProcessor>(
encoder_.get(), &decoders_, source_frame_reader_.get(), config_,
&stats_, &encoded_frame_writers_,
decoded_frame_writers_.empty() ? nullptr : &decoded_frame_writers_);
},
RTC_FROM_HERE);
if (config_.visualization_params.save_encoded_ivf ||
config_.visualization_params.save_decoded_y4m) {
std::string encoder_name = GetCodecName(task_queue, /*is_encoder=*/true);
encoder_name = absl::StrReplaceAll(encoder_name, {{":", ""}, {" ", "-"}});
const size_t num_simulcast_or_spatial_layers = std::max(
config_.NumberOfSimulcastStreams(), config_.NumberOfSpatialLayers());
const size_t num_temporal_layers = config_.NumberOfTemporalLayers();
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers;
++simulcast_svc_idx) {
const std::string output_filename_base = JoinFilename(
config_.output_path, FilenameWithParams(config_) + "_sl" +
std::to_string(simulcast_svc_idx));
const std::string output_filename_base =
JoinFilename(config_.output_path,
FilenameWithParams(config_) + "_" + encoder_name +
"_sl" + std::to_string(simulcast_svc_idx));
if (config_.visualization_params.save_encoded_ivf) {
for (size_t temporal_idx = 0; temporal_idx < num_temporal_layers;
@ -699,19 +742,7 @@ void VideoCodecTestFixtureImpl::SetUpAndInitObjects(
}
}
stats_.Clear();
cpu_process_time_.reset(new CpuProcessTime(config_));
task_queue->SendTask(
[this]() {
CreateEncoderAndDecoder();
processor_ = std::make_unique<VideoProcessor>(
encoder_.get(), &decoders_, source_frame_reader_.get(), config_,
&stats_, &encoded_frame_writers_,
decoded_frame_writers_.empty() ? nullptr : &decoded_frame_writers_);
},
RTC_FROM_HERE);
return true;
}
void VideoCodecTestFixtureImpl::ReleaseAndCloseObjects(
@ -737,22 +768,32 @@ void VideoCodecTestFixtureImpl::ReleaseAndCloseObjects(
decoded_frame_writers_.clear();
}
std::string VideoCodecTestFixtureImpl::GetCodecName(
TaskQueueForTest* task_queue,
bool is_encoder) const {
std::string codec_name;
task_queue->SendTask(
[this, is_encoder, &codec_name] {
if (is_encoder) {
codec_name = encoder_->GetEncoderInfo().implementation_name;
} else {
codec_name = decoders_.at(0)->ImplementationName();
}
},
RTC_FROM_HERE);
return codec_name;
}
void VideoCodecTestFixtureImpl::PrintSettings(
TaskQueueForTest* task_queue) const {
RTC_LOG(LS_INFO) << "==> Config";
RTC_LOG(LS_INFO) << config_.ToString();
RTC_LOG(LS_INFO) << "==> Codec names";
std::string encoder_name;
std::string decoder_name;
task_queue->SendTask(
[this, &encoder_name, &decoder_name] {
encoder_name = encoder_->GetEncoderInfo().implementation_name;
decoder_name = decoders_.at(0)->GetDecoderInfo().implementation_name;
},
RTC_FROM_HERE);
RTC_LOG(LS_INFO) << "enc_impl_name: " << encoder_name;
RTC_LOG(LS_INFO) << "dec_impl_name: " << decoder_name;
RTC_LOG(LS_INFO) << "enc_impl_name: "
<< GetCodecName(task_queue, /*is_encoder=*/true);
RTC_LOG(LS_INFO) << "dec_impl_name: "
<< GetCodecName(task_queue, /*is_encoder=*/false);
}
} // namespace test

View File

@ -59,9 +59,9 @@ class VideoCodecTestFixtureImpl : public VideoCodecTestFixture {
private:
class CpuProcessTime;
void CreateEncoderAndDecoder();
bool CreateEncoderAndDecoder();
void DestroyEncoderAndDecoder();
void SetUpAndInitObjects(TaskQueueForTest* task_queue,
bool SetUpAndInitObjects(TaskQueueForTest* task_queue,
size_t initial_bitrate_kbps,
double initial_framerate_fps);
void ReleaseAndCloseObjects(TaskQueueForTest* task_queue);
@ -82,6 +82,7 @@ class VideoCodecTestFixtureImpl : public VideoCodecTestFixture {
size_t target_bitrate_kbps,
double input_framerate_fps);
std::string GetCodecName(TaskQueueForTest* task_queue, bool is_encoder) const;
void PrintSettings(TaskQueueForTest* task_queue) const;
// Codecs.