/* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
void VideoBroadcaster::OnFrame(const webrtc::VideoFrame& frame) {
webrtc::MutexLock lock(&sinks_and_wants_lock_); bool current_frame_was_discarded = false; for (auto& sink_pair : sink_pairs()) { if (sink_pair.wants.rotation_applied &&
frame.rotation() != webrtc::kVideoRotation_0) { // Calls to OnFrame are not synchronized with changes to the sink wants. // When rotation_applied is set to true, one or a few frames may get here // with rotation still pending. Protect sinks that don't expect any // pending rotation.
RTC_LOG(LS_VERBOSE) << "Discarding frame with unexpected rotation.";
sink_pair.sink->OnDiscardedFrame();
current_frame_was_discarded = true; continue;
} if (sink_pair.wants.black_frames) {
webrtc::VideoFrame black_frame =
webrtc::VideoFrame::Builder()
.set_video_frame_buffer(
GetBlackFrameBuffer(frame.width(), frame.height()))
.set_rotation(frame.rotation())
.set_timestamp_us(frame.timestamp_us())
.set_id(frame.id())
.build();
sink_pair.sink->OnFrame(black_frame);
} elseif (!previous_frame_sent_to_all_sinks_ && frame.has_update_rect()) { // Since last frame was not sent to some sinks, no reliable update // information is available, so we need to clear the update rect.
webrtc::VideoFrame copy = frame;
copy.clear_update_rect();
sink_pair.sink->OnFrame(copy);
} else {
sink_pair.sink->OnFrame(frame);
}
}
previous_frame_sent_to_all_sinks_ = !current_frame_was_discarded;
}
// TODO(webrtc:14451) : I think it makes sense to always // "ignore" encoders that are not active. But that would // probably require a controlled roll out with a field trials? // To play it safe, only ignore inactive encoders is there is an // active encoder using the new api (scale_resolution_down_to), // this means that there is only a behavioural change when using new // api. bool ignore_inactive_encoders_old_api = false; for (auto& sink : sink_pairs()) { if (sink.wants.is_active && sink.wants.requested_resolution.has_value()) {
ignore_inactive_encoders_old_api = true; break;
}
}
for (auto& sink : sink_pairs()) { if (!sink.wants.is_active &&
(sink.wants.requested_resolution || ignore_inactive_encoders_old_api)) { continue;
} // wants.rotation_applied == ANY(sink.wants.rotation_applied) if (sink.wants.rotation_applied) {
wants.rotation_applied = true;
} // wants.max_pixel_count == MIN(sink.wants.max_pixel_count) if (sink.wants.max_pixel_count < wants.max_pixel_count) {
wants.max_pixel_count = sink.wants.max_pixel_count;
} // Select the minimum requested target_pixel_count, if any, of all sinks so // that we don't over utilize the resources for any one. // TODO(sprang): Consider using the median instead, since the limit can be // expressed by max_pixel_count. if (sink.wants.target_pixel_count &&
(!wants.target_pixel_count ||
(*sink.wants.target_pixel_count < *wants.target_pixel_count))) {
wants.target_pixel_count = sink.wants.target_pixel_count;
} // Select the minimum for the requested max framerates. if (sink.wants.max_framerate_fps < wants.max_framerate_fps) {
wants.max_framerate_fps = sink.wants.max_framerate_fps;
}
wants.resolution_alignment =
std::lcm(wants.resolution_alignment, sink.wants.resolution_alignment);
// Pick MAX(requested_resolution) since the actual can be downscaled in // encoder instead. if (sink.wants.requested_resolution) { if (!wants.requested_resolution) {
wants.requested_resolution = sink.wants.requested_resolution;
} else {
wants.requested_resolution->width =
std::max(wants.requested_resolution->width,
sink.wants.requested_resolution->width);
wants.requested_resolution->height =
std::max(wants.requested_resolution->height,
sink.wants.requested_resolution->height);
}
} elseif (sink.wants.is_active) {
wants.aggregates->any_active_without_requested_resolution = true;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.