Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: webrtc/modules/video_coding/codecs/test/videoprocessor.cc

Issue 2741953002: Step #4: Run VideoProcessor integration test batch mode on task queue. (Closed)
Patch Set: Fix gn again. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/codecs/test/videoprocessor.cc
diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
index 21fd67fbee84b749d6ed689c0dd8d92c8f28f3d4..8bd8697971379653b17f078f6362721c58c23d25 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
@@ -129,16 +129,17 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
: encoder_(encoder),
decoder_(decoder),
bitrate_allocator_(CreateBitrateAllocator(config)),
- encode_callback_(new VideoProcessorEncodeCompleteCallback(this)),
- decode_callback_(new VideoProcessorDecodeCompleteCallback(this)),
packet_manipulator_(packet_manipulator),
config_(config),
analysis_frame_reader_(analysis_frame_reader),
analysis_frame_writer_(analysis_frame_writer),
+ num_frames_(analysis_frame_reader->NumberOfFrames()),
source_frame_writer_(source_frame_writer),
encoded_frame_writer_(encoded_frame_writer),
decoded_frame_writer_(decoded_frame_writer),
initialized_(false),
+ frame_infos_(num_frames_),
+ last_inputed_frame_num_(-1),
last_encoded_frame_num_(-1),
last_decoded_frame_num_(-1),
first_key_frame_has_been_excluded_(false),
@@ -152,17 +153,23 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
RTC_DCHECK(analysis_frame_reader);
RTC_DCHECK(analysis_frame_writer);
RTC_DCHECK(stats);
- frame_infos_.reserve(analysis_frame_reader->NumberOfFrames());
+
+ task_checker_.Detach();
}
+VideoProcessorImpl::~VideoProcessorImpl() {}
+
void VideoProcessorImpl::Init() {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK(!initialized_) << "VideoProcessor already initialized.";
initialized_ = true;
// Setup required callbacks for the encoder/decoder.
+ encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this));
RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()),
WEBRTC_VIDEO_CODEC_OK)
<< "Failed to register encode complete callback";
+ decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this));
RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()),
WEBRTC_VIDEO_CODEC_OK)
<< "Failed to register decode complete callback";
@@ -183,8 +190,7 @@ void VideoProcessorImpl::Init() {
if (config_.verbose) {
printf("Video Processor:\n");
printf(" #CPU cores used : %d\n", num_cores);
- printf(" Total # of frames: %d\n",
- analysis_frame_reader_->NumberOfFrames());
+ printf(" Total # of frames: %d\n", num_frames_);
printf(" Codec settings:\n");
printf(" Encoder implementation name: %s\n",
encoder_->ImplementationName());
@@ -201,12 +207,20 @@ void VideoProcessorImpl::Init() {
}
}
-VideoProcessorImpl::~VideoProcessorImpl() {
+void VideoProcessorImpl::Release() {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
+ RTC_DCHECK(initialized_) << "VideoProcessor is not initialized.";
+ initialized_ = false;
+
encoder_->RegisterEncodeCompleteCallback(nullptr);
decoder_->RegisterDecodeCompleteCallback(nullptr);
+
+ RTC_DCHECK_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
+ RTC_DCHECK_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
}
void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
int set_rates_result = encoder_->SetRateAllocation(
bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate),
frame_rate);
@@ -217,36 +231,43 @@ void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
}
size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK_LT(frame_number, frame_infos_.size());
return frame_infos_[frame_number].encoded_frame_size;
}
FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK_LT(frame_number, frame_infos_.size());
return frame_infos_[frame_number].encoded_frame_type;
}
int VideoProcessorImpl::GetQpFromEncoder(int frame_number) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK_LT(frame_number, frame_infos_.size());
return frame_infos_[frame_number].qp_encoder;
}
int VideoProcessorImpl::GetQpFromBitstream(int frame_number) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK_LT(frame_number, frame_infos_.size());
return frame_infos_[frame_number].qp_bitstream;
}
int VideoProcessorImpl::NumberDroppedFrames() {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
return num_dropped_frames_;
}
int VideoProcessorImpl::NumberSpatialResizes() {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
return num_spatial_resizes_;
}
bool VideoProcessorImpl::ProcessFrame(int frame_number) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
RTC_DCHECK_GE(frame_number, 0);
- RTC_DCHECK_LE(frame_number, frame_infos_.size())
+ RTC_DCHECK_EQ(frame_number, ++last_inputed_frame_num_)
<< "Must process frames without gaps.";
RTC_DCHECK(initialized_) << "VideoProcessor not initialized.";
@@ -271,11 +292,6 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
uint32_t timestamp = FrameNumberToTimestamp(frame_number);
VideoFrame source_frame(buffer, timestamp, 0, webrtc::kVideoRotation_0);
- // Store frame information during the different stages of encode and decode.
- frame_infos_.emplace_back();
- FrameInfo* frame_info = &frame_infos_.back();
- frame_info->timestamp = timestamp;
-
// Decide if we are going to force a keyframe.
std::vector<FrameType> frame_types(1, kVideoFrameDelta);
if (config_.keyframe_interval > 0 &&
@@ -283,6 +299,10 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
frame_types[0] = kVideoFrameKey;
}
+ // Store frame information during the different stages of encode and decode.
+ RTC_DCHECK_LT(frame_number, frame_infos_.size());
+ FrameInfo* frame_info = &frame_infos_[frame_number];
+
// Create frame statistics object used for aggregation at end of test run.
FrameStatistic* frame_stat = &stats_->NewFrame(frame_number);
@@ -304,8 +324,12 @@ void VideoProcessorImpl::FrameEncoded(
webrtc::VideoCodecType codec,
const EncodedImage& encoded_image,
const webrtc::RTPFragmentationHeader* fragmentation) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
+
// For the highest measurement accuracy of the encode time, the start/stop
// time recordings should wrap the Encode call as tightly as possible.
+ // TODO(brandtr): Consider moving this measurement into the callback wrapper
+ // class.
int64_t encode_stop_ns = rtc::TimeNanos();
if (encoded_frame_writer_) {
@@ -339,6 +363,7 @@ void VideoProcessorImpl::FrameEncoded(
}
}
+ RTC_DCHECK_LT(last_encoded_frame_num_, frame_infos_.size());
last_frame_missing =
(frame_infos_[last_encoded_frame_num_].manipulated_length == 0);
}
@@ -437,8 +462,12 @@ void VideoProcessorImpl::FrameEncoded(
}
void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
+
// For the highest measurement accuracy of the decode time, the start/stop
// time recordings should wrap the Decode call as tightly as possible.
+ // TODO(brandtr): Consider moving this measurement into the callback wrapper
+ // class.
int64_t decode_stop_ns = rtc::TimeNanos();
// Update frame information and statistics.

Powered by Google App Engine
This is Rietveld 408576698