Replace Atomic32 with std::atomic in video/

system_wrapper/Atomic32 has been deprecated (which is already just a
wrapper of std::atomic) in favor of platform-independent std::atomic
from C++11. This CL replaces all use of Atomic32 in video/

Bug: webrtc:8428
Change-Id: If4dab4909df06944c009e7b70141f58daef7be10
Reviewed-on: https://webrtc-review.googlesource.com/14720
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Yuwei Huang <yuweih@google.com>
Cr-Commit-Position: refs/heads/master@{#20417}
This commit is contained in:
Yuwei Huang 2017-10-24 15:40:52 -07:00 committed by Commit Bot
parent 9de3aaccc9
commit d9f99c1e7a
5 changed files with 25 additions and 19 deletions

View File

@ -16,33 +16,33 @@ namespace webrtc {
namespace internal {
TransportAdapter::TransportAdapter(Transport* transport)
: transport_(transport), enabled_(0) {
: transport_(transport), enabled_(false) {
RTC_DCHECK(nullptr != transport);
}
bool TransportAdapter::SendRtp(const uint8_t* packet,
size_t length,
const PacketOptions& options) {
if (enabled_.Value() == 0)
if (!enabled_.load())
return false;
return transport_->SendRtp(packet, length, options);
}
bool TransportAdapter::SendRtcp(const uint8_t* packet, size_t length) {
if (enabled_.Value() == 0)
if (!enabled_.load())
return false;
return transport_->SendRtcp(packet, length);
}
void TransportAdapter::Enable() {
// If this exchange fails it means enabled_ was already true, no need to
// check result and iterate.
enabled_.CompareExchange(1, 0);
enabled_.store(true);
}
void TransportAdapter::Disable() { enabled_.CompareExchange(0, 1); }
void TransportAdapter::Disable() {
enabled_.store(false);
}
} // namespace internal
} // namespace webrtc

View File

@ -10,9 +10,10 @@
#ifndef VIDEO_TRANSPORT_ADAPTER_H_
#define VIDEO_TRANSPORT_ADAPTER_H_
#include <atomic>
#include "api/call/transport.h"
#include "common_types.h" // NOLINT(build/include)
#include "system_wrappers/include/atomic32.h"
namespace webrtc {
namespace internal {
@ -31,7 +32,7 @@ class TransportAdapter : public Transport {
private:
Transport *transport_;
Atomic32 enabled_;
std::atomic<bool> enabled_;
};
} // namespace internal
} // namespace webrtc

View File

@ -879,7 +879,7 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
accumulated_payload_(0),
fec_packet_received_(false),
current_size_rtp_(start_size),
current_size_frame_(static_cast<int32_t>(start_size)) {
current_size_frame_(static_cast<int>(start_size)) {
// Fragmentation required, this test doesn't make sense without it.
encoder_.SetFrameSize(start_size);
RTC_DCHECK_GT(stop_size, max_packet_size);
@ -953,6 +953,8 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
} else if (fec_packet_received_) {
fec_packet_received_ = false;
++current_size_rtp_;
rtc::CritScope lock(&mutex_);
++current_size_frame_;
}
}
@ -983,13 +985,13 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
}
void EncodedFrameCallback(const EncodedFrame& encoded_frame) override {
rtc::CritScope lock(&mutex_);
// Increase frame size for next encoded frame, in the context of the
// encoder thread.
if (!use_fec_ &&
current_size_frame_.Value() < static_cast<int32_t>(stop_size_)) {
if (!use_fec_ && current_size_frame_ < static_cast<int32_t>(stop_size_)) {
++current_size_frame_;
}
encoder_.SetFrameSize(static_cast<size_t>(current_size_frame_.Value()));
encoder_.SetFrameSize(static_cast<size_t>(current_size_frame_));
}
Call::Config GetSenderCallConfig() override {
@ -1070,7 +1072,8 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
bool fec_packet_received_;
size_t current_size_rtp_;
Atomic32 current_size_frame_;
rtc::CriticalSection mutex_;
int current_size_frame_ RTC_GUARDED_BY(mutex_);
};
// Don't auto increment if FEC is used; continue sending frame size until

View File

@ -137,12 +137,13 @@ class VideoStreamEncoder::EncodeTask : public rtc::QueuedTask {
private:
bool Run() override {
RTC_DCHECK_RUN_ON(&video_stream_encoder_->encoder_queue_);
RTC_DCHECK_GT(
video_stream_encoder_->posted_frames_waiting_for_encode_.Value(), 0);
video_stream_encoder_->stats_proxy_->OnIncomingFrame(frame_.width(),
frame_.height());
++video_stream_encoder_->captured_frame_count_;
if (--video_stream_encoder_->posted_frames_waiting_for_encode_ == 0) {
const int posted_frames_waiting_for_encode =
video_stream_encoder_->posted_frames_waiting_for_encode_.fetch_sub(1);
RTC_DCHECK_GT(posted_frames_waiting_for_encode, 0);
if (posted_frames_waiting_for_encode == 1) {
video_stream_encoder_->EncodeVideoFrame(frame_, time_when_posted_us_);
} else {
// There is a newer frame in flight. Do not encode this frame.
@ -411,6 +412,7 @@ VideoStreamEncoder::VideoStreamEncoder(
clock_(Clock::GetRealTimeClock()),
degradation_preference_(
VideoSendStream::DegradationPreference::kDegradationDisabled),
posted_frames_waiting_for_encode_(0),
last_captured_timestamp_(0),
delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
clock_->TimeInMilliseconds()),

View File

@ -11,6 +11,7 @@
#ifndef VIDEO_VIDEO_STREAM_ENCODER_H_
#define VIDEO_VIDEO_STREAM_ENCODER_H_
#include <atomic>
#include <map>
#include <memory>
#include <string>
@ -29,7 +30,6 @@
#include "rtc_base/event.h"
#include "rtc_base/sequenced_task_checker.h"
#include "rtc_base/task_queue.h"
#include "system_wrappers/include/atomic32.h"
#include "typedefs.h" // NOLINT(build/include)
#include "video/overuse_frame_detector.h"
#include "call/video_send_stream.h"
@ -286,7 +286,7 @@ class VideoStreamEncoder : public rtc::VideoSinkInterface<VideoFrame>,
rtc::RaceChecker incoming_frame_race_checker_
RTC_GUARDED_BY(incoming_frame_race_checker_);
Atomic32 posted_frames_waiting_for_encode_;
std::atomic<int> posted_frames_waiting_for_encode_;
// Used to make sure incoming time stamp is increasing for every frame.
int64_t last_captured_timestamp_ RTC_GUARDED_BY(incoming_frame_race_checker_);
// Delta used for translating between NTP and internal timestamps.