Fix VideoStreamEncoder to not reference encoded data from the RunPostEncode task.

Bug: webrtc:9378
Change-Id: I1ada7018507d0c78fee51523f8cd4fab76c35432
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160306
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29903}
This commit is contained in:
philipel
2019-11-25 15:01:09 +01:00
committed by Commit Bot
parent 712a26f384
commit c7a46c49a0
3 changed files with 20 additions and 11 deletions

View File

@ -146,6 +146,13 @@ class RTC_EXPORT EncodedImage {
buffer_ = nullptr; buffer_ = nullptr;
} }
void ClearEncodedData() {
encoded_data_ = nullptr;
size_ = 0;
buffer_ = nullptr;
capacity_ = 0;
}
// TODO(nisse): Delete, provide only read-only access to the buffer. // TODO(nisse): Delete, provide only read-only access to the buffer.
uint8_t* data() { uint8_t* data() {
return buffer_ ? buffer_ return buffer_ ? buffer_

View File

@ -1737,7 +1737,8 @@ EncodedImageCallback::Result VideoStreamEncoder::OnEncodedImage(
// We are only interested in propagating the meta-data about the image, not // We are only interested in propagating the meta-data about the image, not
// encoded data itself, to the post encode function. Since we cannot be sure // encoded data itself, to the post encode function. Since we cannot be sure
// the pointer will still be valid when run on the task queue, set it to null. // the pointer will still be valid when run on the task queue, set it to null.
image_copy.set_buffer(nullptr, 0); DataSize frame_size = DataSize::bytes(image_copy.size());
image_copy.ClearEncodedData();
int temporal_index = 0; int temporal_index = 0;
if (codec_specific_info) { if (codec_specific_info) {
@ -1751,7 +1752,7 @@ EncodedImageCallback::Result VideoStreamEncoder::OnEncodedImage(
temporal_index = 0; temporal_index = 0;
} }
RunPostEncode(image_copy, rtc::TimeMicros(), temporal_index); RunPostEncode(image_copy, rtc::TimeMicros(), temporal_index, frame_size);
if (result.error == Result::OK) { if (result.error == Result::OK) {
// In case of an internal encoder running on a separate thread, the // In case of an internal encoder running on a separate thread, the
@ -2207,11 +2208,12 @@ VideoStreamEncoder::GetConstAdaptCounter() {
void VideoStreamEncoder::RunPostEncode(EncodedImage encoded_image, void VideoStreamEncoder::RunPostEncode(EncodedImage encoded_image,
int64_t time_sent_us, int64_t time_sent_us,
int temporal_index) { int temporal_index,
DataSize frame_size) {
if (!encoder_queue_.IsCurrent()) { if (!encoder_queue_.IsCurrent()) {
encoder_queue_.PostTask( encoder_queue_.PostTask([this, encoded_image, time_sent_us, temporal_index,
[this, encoded_image, time_sent_us, temporal_index] { frame_size] {
RunPostEncode(encoded_image, time_sent_us, temporal_index); RunPostEncode(encoded_image, time_sent_us, temporal_index, frame_size);
}); });
return; return;
} }
@ -2229,12 +2231,11 @@ void VideoStreamEncoder::RunPostEncode(EncodedImage encoded_image,
// Run post encode tasks, such as overuse detection and frame rate/drop // Run post encode tasks, such as overuse detection and frame rate/drop
// stats for internal encoders. // stats for internal encoders.
const size_t frame_size = encoded_image.size();
const bool keyframe = const bool keyframe =
encoded_image._frameType == VideoFrameType::kVideoFrameKey; encoded_image._frameType == VideoFrameType::kVideoFrameKey;
if (frame_size > 0) { if (!frame_size.IsZero()) {
frame_dropper_.Fill(frame_size, !keyframe); frame_dropper_.Fill(frame_size.bytes(), !keyframe);
} }
if (HasInternalSource()) { if (HasInternalSource()) {

View File

@ -229,7 +229,8 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
RTC_RUN_ON(&encoder_queue_); RTC_RUN_ON(&encoder_queue_);
void RunPostEncode(EncodedImage encoded_image, void RunPostEncode(EncodedImage encoded_image,
int64_t time_sent_us, int64_t time_sent_us,
int temporal_index); int temporal_index,
DataSize frame_size);
bool HasInternalSource() const RTC_RUN_ON(&encoder_queue_); bool HasInternalSource() const RTC_RUN_ON(&encoder_queue_);
void ReleaseEncoder() RTC_RUN_ON(&encoder_queue_); void ReleaseEncoder() RTC_RUN_ON(&encoder_queue_);