Synchronize modifications to frame_extra_info_ in jni::VideoEncoderWrapper.
Since https://webrtc-review.googlesource.com/c/src/+/161447, frame_extra_info_ is modified from both the encoder thread and the callback thread. Bug: None Change-Id: Idece4d19cae6d8363428234721616f6ca6f85832 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184121 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32095}
This commit is contained in:

committed by
Commit Bot

parent
e7b19c2d7f
commit
8452ea86c5
@ -113,7 +113,10 @@ int32_t VideoEncoderWrapper::Release() {
|
|||||||
int32_t status = JavaToNativeVideoCodecStatus(
|
int32_t status = JavaToNativeVideoCodecStatus(
|
||||||
jni, Java_VideoEncoder_release(jni, encoder_));
|
jni, Java_VideoEncoder_release(jni, encoder_));
|
||||||
RTC_LOG(LS_INFO) << "release: " << status;
|
RTC_LOG(LS_INFO) << "release: " << status;
|
||||||
frame_extra_infos_.clear();
|
{
|
||||||
|
MutexLock lock(&frame_extra_infos_lock_);
|
||||||
|
frame_extra_infos_.clear();
|
||||||
|
}
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -138,7 +141,10 @@ int32_t VideoEncoderWrapper::Encode(
|
|||||||
FrameExtraInfo info;
|
FrameExtraInfo info;
|
||||||
info.capture_time_ns = frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec;
|
info.capture_time_ns = frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec;
|
||||||
info.timestamp_rtp = frame.timestamp();
|
info.timestamp_rtp = frame.timestamp();
|
||||||
frame_extra_infos_.push_back(info);
|
{
|
||||||
|
MutexLock lock(&frame_extra_infos_lock_);
|
||||||
|
frame_extra_infos_.push_back(info);
|
||||||
|
}
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> j_frame = NativeToJavaVideoFrame(jni, frame);
|
ScopedJavaLocalRef<jobject> j_frame = NativeToJavaVideoFrame(jni, frame);
|
||||||
ScopedJavaLocalRef<jobject> ret =
|
ScopedJavaLocalRef<jobject> ret =
|
||||||
@ -229,19 +235,23 @@ void VideoEncoderWrapper::OnEncodedFrame(
|
|||||||
// entries that don't belong to us, and we need to be careful not to
|
// entries that don't belong to us, and we need to be careful not to
|
||||||
// remove them. Removing only those entries older than the current frame
|
// remove them. Removing only those entries older than the current frame
|
||||||
// provides this guarantee.
|
// provides this guarantee.
|
||||||
while (!frame_extra_infos_.empty() &&
|
FrameExtraInfo frame_extra_info;
|
||||||
frame_extra_infos_.front().capture_time_ns < capture_time_ns) {
|
{
|
||||||
|
MutexLock lock(&frame_extra_infos_lock_);
|
||||||
|
while (!frame_extra_infos_.empty() &&
|
||||||
|
frame_extra_infos_.front().capture_time_ns < capture_time_ns) {
|
||||||
|
frame_extra_infos_.pop_front();
|
||||||
|
}
|
||||||
|
if (frame_extra_infos_.empty() ||
|
||||||
|
frame_extra_infos_.front().capture_time_ns != capture_time_ns) {
|
||||||
|
RTC_LOG(LS_WARNING)
|
||||||
|
<< "Java encoder produced an unexpected frame with timestamp: "
|
||||||
|
<< capture_time_ns;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
frame_extra_info = frame_extra_infos_.front();
|
||||||
frame_extra_infos_.pop_front();
|
frame_extra_infos_.pop_front();
|
||||||
}
|
}
|
||||||
if (frame_extra_infos_.empty() ||
|
|
||||||
frame_extra_infos_.front().capture_time_ns != capture_time_ns) {
|
|
||||||
RTC_LOG(LS_WARNING)
|
|
||||||
<< "Java encoder produced an unexpected frame with timestamp: "
|
|
||||||
<< capture_time_ns;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FrameExtraInfo frame_extra_info = std::move(frame_extra_infos_.front());
|
|
||||||
frame_extra_infos_.pop_front();
|
|
||||||
|
|
||||||
// This is a bit subtle. The |frame| variable from the lambda capture is
|
// This is a bit subtle. The |frame| variable from the lambda capture is
|
||||||
// const. Which implies that (i) we need to make a copy to be able to
|
// const. Which implies that (i) we need to make a copy to be able to
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "api/video_codecs/video_encoder.h"
|
#include "api/video_codecs/video_encoder.h"
|
||||||
#include "common_video/h264/h264_bitstream_parser.h"
|
#include "common_video/h264/h264_bitstream_parser.h"
|
||||||
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
|
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
|
||||||
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/video_frame.h"
|
#include "sdk/android/src/jni/video_frame.h"
|
||||||
|
|
||||||
@ -82,7 +83,10 @@ class VideoEncoderWrapper : public VideoEncoder {
|
|||||||
const ScopedJavaGlobalRef<jobject> encoder_;
|
const ScopedJavaGlobalRef<jobject> encoder_;
|
||||||
const ScopedJavaGlobalRef<jclass> int_array_class_;
|
const ScopedJavaGlobalRef<jclass> int_array_class_;
|
||||||
|
|
||||||
std::deque<FrameExtraInfo> frame_extra_infos_;
|
// Modified both on the encoder thread and the callback thread.
|
||||||
|
Mutex frame_extra_infos_lock_;
|
||||||
|
std::deque<FrameExtraInfo> frame_extra_infos_
|
||||||
|
RTC_GUARDED_BY(frame_extra_infos_lock_);
|
||||||
EncodedImageCallback* callback_;
|
EncodedImageCallback* callback_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
int num_resets_;
|
int num_resets_;
|
||||||
|
Reference in New Issue
Block a user