Rename spatial/temporal index variables and fields in videoprocessor.

This fixes inconsistency in names of variables and fields which
represent spatial/temporal index of layer:
simulcast_svc_idx -> spatial_idx
spatial_layer_idx -> spatial_idx
temporal_layer_idx -> temporal_idx

Also, this adds printing of spatial/temporal index and target bitrate
to RD report.

Bug: none
Change-Id: Ic4dfdadc57a1577bb3d35d1782a152a9dbef0280
Reviewed-on: https://webrtc-review.googlesource.com/69981
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22869}
This commit is contained in:
Sergey Silkin
2018-04-15 21:06:16 +02:00
committed by Commit Bot
parent eb99d84341
commit bc20fe1221
4 changed files with 126 additions and 141 deletions

View File

@ -56,17 +56,17 @@ size_t GetMaxNaluSizeBytes(const EncodedImage& encoded_frame,
}
void GetLayerIndices(const CodecSpecificInfo& codec_specific,
size_t* simulcast_svc_idx,
size_t* spatial_idx,
size_t* temporal_idx) {
if (codec_specific.codecType == kVideoCodecVP8) {
*simulcast_svc_idx = codec_specific.codecSpecific.VP8.simulcastIdx;
*spatial_idx = codec_specific.codecSpecific.VP8.simulcastIdx;
*temporal_idx = codec_specific.codecSpecific.VP8.temporalIdx;
} else if (codec_specific.codecType == kVideoCodecVP9) {
*simulcast_svc_idx = codec_specific.codecSpecific.VP9.spatial_idx;
*spatial_idx = codec_specific.codecSpecific.VP9.spatial_idx;
*temporal_idx = codec_specific.codecSpecific.VP9.temporal_idx;
}
if (*simulcast_svc_idx == kNoSpatialIdx) {
*simulcast_svc_idx = 0;
if (*spatial_idx == kNoSpatialIdx) {
*spatial_idx = 0;
}
if (*temporal_idx == kNoTemporalIdx) {
*temporal_idx = 0;
@ -205,19 +205,15 @@ VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder,
config_.max_payload_size_bytes),
WEBRTC_VIDEO_CODEC_OK);
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers_;
++simulcast_svc_idx) {
for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) {
decode_callback_.push_back(
rtc::MakeUnique<VideoProcessorDecodeCompleteCallback>(
this, simulcast_svc_idx));
RTC_CHECK_EQ(decoders_->at(simulcast_svc_idx)
->InitDecode(&config_.codec_settings,
static_cast<int>(config_.NumberOfCores())),
WEBRTC_VIDEO_CODEC_OK);
RTC_CHECK_EQ(decoders_->at(simulcast_svc_idx)
->RegisterDecodeCompleteCallback(
decode_callback_.at(simulcast_svc_idx).get()),
rtc::MakeUnique<VideoProcessorDecodeCompleteCallback>(this, i));
RTC_CHECK_EQ(
decoders_->at(i)->InitDecode(&config_.codec_settings,
static_cast<int>(config_.NumberOfCores())),
WEBRTC_VIDEO_CODEC_OK);
RTC_CHECK_EQ(decoders_->at(i)->RegisterDecodeCompleteCallback(
decode_callback_.at(i).get()),
WEBRTC_VIDEO_CODEC_OK);
}
}
@ -238,10 +234,8 @@ VideoProcessor::~VideoProcessor() {
RTC_CHECK_LE(input_frames_.size(), kMaxBufferedInputFrames);
// Deal with manual memory management of EncodedImage's.
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers_;
++simulcast_svc_idx) {
uint8_t* buffer = merged_encoded_frames_.at(simulcast_svc_idx)._buffer;
for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) {
uint8_t* buffer = merged_encoded_frames_.at(i)._buffer;
if (buffer) {
delete[] buffer;
}
@ -270,20 +264,15 @@ void VideoProcessor::ProcessFrame() {
post_encode_time_ns_ = 0;
// Create frame statistics object for all simulcast/spatial layers.
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers_;
++simulcast_svc_idx) {
stats_->AddFrame(timestamp, simulcast_svc_idx);
for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) {
stats_->AddFrame(timestamp, i);
}
// For the highest measurement accuracy of the encode time, the start/stop
// time recordings should wrap the Encode call as tightly as possible.
const int64_t encode_start_ns = rtc::TimeNanos();
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers_;
++simulcast_svc_idx) {
FrameStatistics* frame_stat =
stats_->GetFrame(frame_number, simulcast_svc_idx);
for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) {
FrameStatistics* frame_stat = stats_->GetFrame(frame_number, i);
frame_stat->encode_start_ns = encode_start_ns;
}
@ -292,11 +281,8 @@ void VideoProcessor::ProcessFrame() {
config_.FrameTypeForFrame(frame_number);
const int encode_return_code =
encoder_->Encode(input_frame, nullptr, &frame_types);
for (size_t simulcast_svc_idx = 0;
simulcast_svc_idx < num_simulcast_or_spatial_layers_;
++simulcast_svc_idx) {
FrameStatistics* frame_stat =
stats_->GetFrame(frame_number, simulcast_svc_idx);
for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) {
FrameStatistics* frame_stat = stats_->GetFrame(frame_number, i);
frame_stat->encode_return_code = encode_return_code;
}
}
@ -327,45 +313,45 @@ void VideoProcessor::FrameEncoded(
}
// Layer metadata.
size_t simulcast_svc_idx = 0;
size_t spatial_idx = 0;
size_t temporal_idx = 0;
GetLayerIndices(codec_specific, &simulcast_svc_idx, &temporal_idx);
GetLayerIndices(codec_specific, &spatial_idx, &temporal_idx);
FrameStatistics* frame_stat = stats_->GetFrameWithTimestamp(
encoded_image._timeStamp, simulcast_svc_idx);
FrameStatistics* frame_stat =
stats_->GetFrameWithTimestamp(encoded_image._timeStamp, spatial_idx);
const size_t frame_number = frame_stat->frame_number;
// Ensure that the encode order is monotonically increasing, within this
// simulcast/spatial layer.
RTC_CHECK(first_encoded_frame_[simulcast_svc_idx] ||
last_encoded_frame_num_[simulcast_svc_idx] < frame_number);
RTC_CHECK(first_encoded_frame_[spatial_idx] ||
last_encoded_frame_num_[spatial_idx] < frame_number);
// Ensure SVC spatial layers are delivered in ascending order.
if (!first_encoded_frame_[simulcast_svc_idx] &&
if (!first_encoded_frame_[spatial_idx] &&
config_.NumberOfSpatialLayers() > 1) {
for (size_t i = 0; i < simulcast_svc_idx; ++i) {
for (size_t i = 0; i < spatial_idx; ++i) {
RTC_CHECK_LE(last_encoded_frame_num_[i], frame_number);
}
for (size_t i = simulcast_svc_idx + 1; i < num_simulcast_or_spatial_layers_;
for (size_t i = spatial_idx + 1; i < num_simulcast_or_spatial_layers_;
++i) {
RTC_CHECK_GT(frame_number, last_encoded_frame_num_[i]);
}
}
first_encoded_frame_[simulcast_svc_idx] = false;
last_encoded_frame_num_[simulcast_svc_idx] = frame_number;
first_encoded_frame_[spatial_idx] = false;
last_encoded_frame_num_[spatial_idx] = frame_number;
// Update frame statistics.
frame_stat->encoding_successful = true;
frame_stat->encode_time_us = GetElapsedTimeMicroseconds(
frame_stat->encode_start_ns, encode_stop_ns - post_encode_time_ns_);
frame_stat->target_bitrate_kbps = (bitrate_allocation_.GetTemporalLayerSum(
simulcast_svc_idx, temporal_idx) +
500) /
1000;
frame_stat->target_bitrate_kbps =
(bitrate_allocation_.GetTemporalLayerSum(spatial_idx, temporal_idx) +
500) /
1000;
frame_stat->length_bytes = encoded_image._length;
frame_stat->frame_type = encoded_image._frameType;
frame_stat->temporal_layer_idx = temporal_idx;
frame_stat->simulcast_svc_idx = simulcast_svc_idx;
frame_stat->temporal_idx = temporal_idx;
frame_stat->spatial_idx = spatial_idx;
frame_stat->max_nalu_size_bytes = GetMaxNaluSizeBytes(encoded_image, config_);
frame_stat->qp = encoded_image.qp_;
@ -384,31 +370,29 @@ void VideoProcessor::FrameEncoded(
if (config_.decode || encoded_frame_writers_) {
if (num_spatial_layers > 1) {
encoded_image_for_decode = BuildAndStoreSuperframe(
encoded_image, codec_type, frame_number, simulcast_svc_idx,
encoded_image, codec_type, frame_number, spatial_idx,
frame_stat->inter_layer_predicted);
}
}
if (config_.decode) {
DecodeFrame(*encoded_image_for_decode, simulcast_svc_idx);
DecodeFrame(*encoded_image_for_decode, spatial_idx);
if (end_of_superframe && inter_layer_prediction) {
// If inter-layer prediction is enabled and upper layer was dropped then
// base layer should be passed to upper layer decoder. Otherwise decoder
// won't be able to decode next superframe.
const EncodedImage* base_image = nullptr;
for (size_t spatial_idx = 0; spatial_idx < num_spatial_layers;
++spatial_idx) {
const bool layer_dropped =
last_decoded_frame_num_[spatial_idx] < frame_number;
for (size_t i = 0; i < num_spatial_layers; ++i) {
const bool layer_dropped = last_decoded_frame_num_[i] < frame_number;
// Ensure current layer was decoded.
RTC_CHECK(layer_dropped == false || spatial_idx != simulcast_svc_idx);
RTC_CHECK(layer_dropped == false || i != spatial_idx);
if (!layer_dropped) {
base_image = &merged_encoded_frames_[spatial_idx];
base_image = &merged_encoded_frames_[i];
} else if (base_image) {
DecodeFrame(*base_image, spatial_idx);
DecodeFrame(*base_image, i);
}
}
}
@ -417,7 +401,7 @@ void VideoProcessor::FrameEncoded(
}
if (encoded_frame_writers_) {
RTC_CHECK(encoded_frame_writers_->at(simulcast_svc_idx)
RTC_CHECK(encoded_frame_writers_->at(spatial_idx)
->WriteFrame(*encoded_image_for_decode,
config_.codec_settings.codecType));
}
@ -430,23 +414,23 @@ void VideoProcessor::FrameEncoded(
}
void VideoProcessor::FrameDecoded(const VideoFrame& decoded_frame,
size_t simulcast_svc_idx) {
size_t spatial_idx) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
// For the highest measurement accuracy of the decode time, the start/stop
// time recordings should wrap the Decode call as tightly as possible.
const int64_t decode_stop_ns = rtc::TimeNanos();
FrameStatistics* frame_stat = stats_->GetFrameWithTimestamp(
decoded_frame.timestamp(), simulcast_svc_idx);
FrameStatistics* frame_stat =
stats_->GetFrameWithTimestamp(decoded_frame.timestamp(), spatial_idx);
const size_t frame_number = frame_stat->frame_number;
// Ensure that the decode order is monotonically increasing, within this
// simulcast/spatial layer.
RTC_CHECK(first_decoded_frame_[simulcast_svc_idx] ||
last_decoded_frame_num_[simulcast_svc_idx] < frame_number);
first_decoded_frame_[simulcast_svc_idx] = false;
last_decoded_frame_num_[simulcast_svc_idx] = frame_number;
RTC_CHECK(first_decoded_frame_[spatial_idx] ||
last_decoded_frame_num_[spatial_idx] < frame_number);
first_decoded_frame_[spatial_idx] = false;
last_decoded_frame_num_[spatial_idx] = frame_number;
// Update frame statistics.
frame_stat->decoding_successful = true;
@ -483,28 +467,28 @@ void VideoProcessor::FrameDecoded(const VideoFrame& decoded_frame,
ExtractI420BufferWithSize(decoded_frame, config_.codec_settings.width,
config_.codec_settings.height, &tmp_i420_buffer_);
RTC_CHECK_EQ(tmp_i420_buffer_.size(),
decoded_frame_writers_->at(simulcast_svc_idx)->FrameLength());
RTC_CHECK(decoded_frame_writers_->at(simulcast_svc_idx)
decoded_frame_writers_->at(spatial_idx)->FrameLength());
RTC_CHECK(decoded_frame_writers_->at(spatial_idx)
->WriteFrame(tmp_i420_buffer_.data()));
}
}
void VideoProcessor::DecodeFrame(const EncodedImage& encoded_image,
size_t simulcast_svc_idx) {
size_t spatial_idx) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
FrameStatistics* frame_stat = stats_->GetFrameWithTimestamp(
encoded_image._timeStamp, simulcast_svc_idx);
FrameStatistics* frame_stat =
stats_->GetFrameWithTimestamp(encoded_image._timeStamp, spatial_idx);
frame_stat->decode_start_ns = rtc::TimeNanos();
frame_stat->decode_return_code =
decoders_->at(simulcast_svc_idx)->Decode(encoded_image, false, nullptr);
decoders_->at(spatial_idx)->Decode(encoded_image, false, nullptr);
}
const webrtc::EncodedImage* VideoProcessor::BuildAndStoreSuperframe(
const EncodedImage& encoded_image,
const VideoCodecType codec,
size_t frame_number,
size_t simulcast_svc_idx,
size_t spatial_idx,
bool inter_layer_predicted) {
// Should only be called for SVC.
RTC_CHECK_GT(config_.NumberOfSpatialLayers(), 1);
@ -515,7 +499,7 @@ const webrtc::EncodedImage* VideoProcessor::BuildAndStoreSuperframe(
// Each SVC layer is decoded with dedicated decoder. Find the nearest
// non-dropped base frame and merge it and current frame into superframe.
if (inter_layer_predicted) {
for (int base_idx = static_cast<int>(simulcast_svc_idx) - 1; base_idx >= 0;
for (int base_idx = static_cast<int>(spatial_idx) - 1; base_idx >= 0;
--base_idx) {
EncodedImage lower_layer = merged_encoded_frames_.at(base_idx);
if (lower_layer._timeStamp == encoded_image._timeStamp) {
@ -545,13 +529,13 @@ const webrtc::EncodedImage* VideoProcessor::BuildAndStoreSuperframe(
copied_image._size = buffer_size_bytes;
// Replace previous EncodedImage for this spatial layer.
uint8_t* old_buffer = merged_encoded_frames_.at(simulcast_svc_idx)._buffer;
uint8_t* old_buffer = merged_encoded_frames_.at(spatial_idx)._buffer;
if (old_buffer) {
delete[] old_buffer;
}
merged_encoded_frames_.at(simulcast_svc_idx) = copied_image;
merged_encoded_frames_.at(spatial_idx) = copied_image;
return &merged_encoded_frames_.at(simulcast_svc_idx);
return &merged_encoded_frames_.at(spatial_idx);
}
} // namespace test