2011-10-06 06:44:54 +00:00
|
|
|
/*
|
2012-04-12 06:59:14 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-10-06 06:44:54 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2011-12-08 07:42:18 +00:00
|
|
|
|
2013-07-16 12:32:05 +00:00
|
|
|
#include "webrtc/modules/video_coding/codecs/test/videoprocessor.h"
|
2011-10-06 06:44:54 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
#include <limits>
|
2016-02-29 05:51:59 -08:00
|
|
|
#include <memory>
|
2013-02-13 09:35:12 +00:00
|
|
|
#include <vector>
|
2011-10-06 06:44:54 +00:00
|
|
|
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/cpu_info.h"
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2013-07-30 15:18:31 +00:00
|
|
|
TestConfig::TestConfig()
|
|
|
|
|
: name(""),
|
|
|
|
|
description(""),
|
|
|
|
|
test_number(0),
|
|
|
|
|
input_filename(""),
|
|
|
|
|
output_filename(""),
|
|
|
|
|
output_dir("out"),
|
|
|
|
|
networking_config(),
|
|
|
|
|
exclude_frame_types(kExcludeOnlyFirstKeyFrame),
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
frame_length_in_bytes(0),
|
2013-07-30 15:18:31 +00:00
|
|
|
use_single_core(false),
|
|
|
|
|
keyframe_interval(0),
|
|
|
|
|
codec_settings(NULL),
|
|
|
|
|
verbose(true) {}
|
|
|
|
|
|
|
|
|
|
TestConfig::~TestConfig() {}
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
|
|
|
|
webrtc::VideoDecoder* decoder,
|
2011-12-08 07:42:18 +00:00
|
|
|
FrameReader* frame_reader,
|
|
|
|
|
FrameWriter* frame_writer,
|
2011-10-06 06:44:54 +00:00
|
|
|
PacketManipulator* packet_manipulator,
|
|
|
|
|
const TestConfig& config,
|
|
|
|
|
Stats* stats)
|
|
|
|
|
: encoder_(encoder),
|
|
|
|
|
decoder_(decoder),
|
2011-12-08 07:42:18 +00:00
|
|
|
frame_reader_(frame_reader),
|
|
|
|
|
frame_writer_(frame_writer),
|
2011-10-06 06:44:54 +00:00
|
|
|
packet_manipulator_(packet_manipulator),
|
|
|
|
|
config_(config),
|
|
|
|
|
stats_(stats),
|
|
|
|
|
encode_callback_(NULL),
|
|
|
|
|
decode_callback_(NULL),
|
|
|
|
|
source_buffer_(NULL),
|
|
|
|
|
first_key_frame_has_been_excluded_(false),
|
|
|
|
|
last_frame_missing_(false),
|
2012-06-05 21:07:28 +00:00
|
|
|
initialized_(false),
|
|
|
|
|
encoded_frame_size_(0),
|
2015-10-23 15:58:18 +02:00
|
|
|
encoded_frame_type_(kVideoFrameKey),
|
2012-06-05 21:07:28 +00:00
|
|
|
prev_time_stamp_(0),
|
|
|
|
|
num_dropped_frames_(0),
|
|
|
|
|
num_spatial_resizes_(0),
|
|
|
|
|
last_encoder_frame_width_(0),
|
|
|
|
|
last_encoder_frame_height_(0),
|
|
|
|
|
scaler_() {
|
2011-10-06 06:44:54 +00:00
|
|
|
assert(encoder);
|
|
|
|
|
assert(decoder);
|
2011-12-08 07:42:18 +00:00
|
|
|
assert(frame_reader);
|
|
|
|
|
assert(frame_writer);
|
2011-10-06 06:44:54 +00:00
|
|
|
assert(packet_manipulator);
|
|
|
|
|
assert(stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoProcessorImpl::Init() {
|
|
|
|
|
// Calculate a factor used for bit rate calculations:
|
2011-12-30 14:44:07 +00:00
|
|
|
bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
// Initialize data structures used by the encoder/decoder APIs
|
2013-02-13 09:35:12 +00:00
|
|
|
size_t frame_length_in_bytes = frame_reader_->FrameLength();
|
2013-04-08 11:13:29 +00:00
|
|
|
source_buffer_ = new uint8_t[frame_length_in_bytes];
|
|
|
|
|
last_successful_frame_buffer_ = new uint8_t[frame_length_in_bytes];
|
2012-10-24 18:33:04 +00:00
|
|
|
// Set fixed properties common for all frames.
|
2012-06-05 21:07:28 +00:00
|
|
|
// To keep track of spatial resize actions by encoder.
|
|
|
|
|
last_encoder_frame_width_ = config_.codec_settings->width;
|
|
|
|
|
last_encoder_frame_height_ = config_.codec_settings->height;
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
// Setup required callbacks for the encoder/decoder:
|
|
|
|
|
encode_callback_ = new VideoProcessorEncodeCompleteCallback(this);
|
|
|
|
|
decode_callback_ = new VideoProcessorDecodeCompleteCallback(this);
|
2013-04-08 11:13:29 +00:00
|
|
|
int32_t register_result =
|
2011-10-06 06:44:54 +00:00
|
|
|
encoder_->RegisterEncodeCompleteCallback(encode_callback_);
|
|
|
|
|
if (register_result != WEBRTC_VIDEO_CODEC_OK) {
|
2015-12-21 03:04:49 -08:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Failed to register encode complete callback, return code: "
|
|
|
|
|
"%d\n",
|
|
|
|
|
register_result);
|
2011-10-06 06:44:54 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
register_result = decoder_->RegisterDecodeCompleteCallback(decode_callback_);
|
|
|
|
|
if (register_result != WEBRTC_VIDEO_CODEC_OK) {
|
2015-12-21 03:04:49 -08:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Failed to register decode complete callback, return code: "
|
|
|
|
|
"%d\n",
|
|
|
|
|
register_result);
|
2011-10-06 06:44:54 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Init the encoder and decoder
|
2013-04-08 11:13:29 +00:00
|
|
|
uint32_t nbr_of_cores = 1;
|
2011-10-06 06:44:54 +00:00
|
|
|
if (!config_.use_single_core) {
|
2011-11-08 08:44:17 +00:00
|
|
|
nbr_of_cores = CpuInfo::DetectNumberOfCores();
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
2013-04-08 11:13:29 +00:00
|
|
|
int32_t init_result =
|
2011-12-30 14:44:07 +00:00
|
|
|
encoder_->InitEncode(config_.codec_settings, nbr_of_cores,
|
2011-10-06 06:44:54 +00:00
|
|
|
config_.networking_config.max_payload_size_in_bytes);
|
|
|
|
|
if (init_result != WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize VideoEncoder, return code: %d\n",
|
|
|
|
|
init_result);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-12-30 14:44:07 +00:00
|
|
|
init_result = decoder_->InitDecode(config_.codec_settings, nbr_of_cores);
|
2011-10-06 06:44:54 +00:00
|
|
|
if (init_result != WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
fprintf(stderr, "Failed to initialize VideoDecoder, return code: %d\n",
|
|
|
|
|
init_result);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-08 07:42:18 +00:00
|
|
|
if (config_.verbose) {
|
|
|
|
|
printf("Video Processor:\n");
|
|
|
|
|
printf(" #CPU cores used : %d\n", nbr_of_cores);
|
|
|
|
|
printf(" Total # of frames: %d\n", frame_reader_->NumberOfFrames());
|
|
|
|
|
printf(" Codec settings:\n");
|
|
|
|
|
printf(" Start bitrate : %d kbps\n",
|
2011-12-30 14:44:07 +00:00
|
|
|
config_.codec_settings->startBitrate);
|
|
|
|
|
printf(" Width : %d\n", config_.codec_settings->width);
|
|
|
|
|
printf(" Height : %d\n", config_.codec_settings->height);
|
2011-12-08 07:42:18 +00:00
|
|
|
}
|
2011-10-06 06:44:54 +00:00
|
|
|
initialized_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoProcessorImpl::~VideoProcessorImpl() {
|
|
|
|
|
delete[] source_buffer_;
|
|
|
|
|
delete[] last_successful_frame_buffer_;
|
|
|
|
|
encoder_->RegisterEncodeCompleteCallback(NULL);
|
|
|
|
|
delete encode_callback_;
|
|
|
|
|
decoder_->RegisterDecodeCompleteCallback(NULL);
|
|
|
|
|
delete decode_callback_;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 21:07:28 +00:00
|
|
|
void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
|
|
|
|
|
int set_rates_result = encoder_->SetRates(bit_rate, frame_rate);
|
|
|
|
|
assert(set_rates_result >= 0);
|
|
|
|
|
if (set_rates_result < 0) {
|
2015-12-21 03:04:49 -08:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Failed to update encoder with new rate %d, "
|
|
|
|
|
"return code: %d\n",
|
|
|
|
|
bit_rate, set_rates_result);
|
2012-06-05 21:07:28 +00:00
|
|
|
}
|
|
|
|
|
num_dropped_frames_ = 0;
|
|
|
|
|
num_spatial_resizes_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t VideoProcessorImpl::EncodedFrameSize() {
|
2012-06-05 21:07:28 +00:00
|
|
|
return encoded_frame_size_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 02:39:06 -07:00
|
|
|
FrameType VideoProcessorImpl::EncodedFrameType() {
|
2015-09-17 12:16:04 -07:00
|
|
|
return encoded_frame_type_;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-05 21:07:28 +00:00
|
|
|
int VideoProcessorImpl::NumberDroppedFrames() {
|
|
|
|
|
return num_dropped_frames_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VideoProcessorImpl::NumberSpatialResizes() {
|
|
|
|
|
return num_spatial_resizes_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
bool VideoProcessorImpl::ProcessFrame(int frame_number) {
|
2015-12-21 03:04:49 -08:00
|
|
|
assert(frame_number >= 0);
|
2011-10-06 06:44:54 +00:00
|
|
|
if (!initialized_) {
|
|
|
|
|
fprintf(stderr, "Attempting to use uninitialized VideoProcessor!\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-06-05 21:07:28 +00:00
|
|
|
// |prev_time_stamp_| is used for getting number of dropped frames.
|
|
|
|
|
if (frame_number == 0) {
|
|
|
|
|
prev_time_stamp_ = -1;
|
|
|
|
|
}
|
2011-12-08 07:42:18 +00:00
|
|
|
if (frame_reader_->ReadFrame(source_buffer_)) {
|
2012-07-31 15:53:44 +00:00
|
|
|
// Copy the source frame to the newly read frame data.
|
2015-12-21 03:04:49 -08:00
|
|
|
source_frame_.CreateFrame(source_buffer_, config_.codec_settings->width,
|
|
|
|
|
config_.codec_settings->height, kVideoRotation_0);
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
// Ensure we have a new statistics data object we can fill:
|
|
|
|
|
FrameStatistic& stat = stats_->NewFrame(frame_number);
|
|
|
|
|
|
|
|
|
|
encode_start_ = TickTime::Now();
|
|
|
|
|
// Use the frame number as "timestamp" to identify frames
|
2012-10-24 18:33:04 +00:00
|
|
|
source_frame_.set_timestamp(frame_number);
|
2011-10-07 06:50:22 +00:00
|
|
|
|
|
|
|
|
// Decide if we're going to force a keyframe:
|
2015-10-23 15:58:18 +02:00
|
|
|
std::vector<FrameType> frame_types(1, kVideoFrameDelta);
|
2011-10-07 06:50:22 +00:00
|
|
|
if (config_.keyframe_interval > 0 &&
|
|
|
|
|
frame_number % config_.keyframe_interval == 0) {
|
2015-10-23 15:58:18 +02:00
|
|
|
frame_types[0] = kVideoFrameKey;
|
2011-10-07 06:50:22 +00:00
|
|
|
}
|
2012-06-05 21:07:28 +00:00
|
|
|
|
|
|
|
|
// For dropped frames, we regard them as zero size encoded frames.
|
|
|
|
|
encoded_frame_size_ = 0;
|
2015-10-23 15:58:18 +02:00
|
|
|
encoded_frame_type_ = kVideoFrameDelta;
|
2012-06-05 21:07:28 +00:00
|
|
|
|
2013-04-08 11:13:29 +00:00
|
|
|
int32_t encode_result = encoder_->Encode(source_frame_, NULL, &frame_types);
|
2012-06-05 21:07:28 +00:00
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
if (encode_result != WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
fprintf(stderr, "Failed to encode frame %d, return code: %d\n",
|
|
|
|
|
frame_number, encode_result);
|
|
|
|
|
}
|
|
|
|
|
stat.encode_return_code = encode_result;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false; // we've reached the last frame
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 01:36:03 -08:00
|
|
|
void VideoProcessorImpl::FrameEncoded(
|
|
|
|
|
webrtc::VideoCodecType codec,
|
|
|
|
|
const EncodedImage& encoded_image,
|
|
|
|
|
const webrtc::RTPFragmentationHeader* fragmentation) {
|
2012-06-05 21:07:28 +00:00
|
|
|
// Timestamp is frame number, so this gives us #dropped frames.
|
2015-12-21 03:04:49 -08:00
|
|
|
int num_dropped_from_prev_encode =
|
|
|
|
|
encoded_image._timeStamp - prev_time_stamp_ - 1;
|
|
|
|
|
num_dropped_frames_ += num_dropped_from_prev_encode;
|
|
|
|
|
prev_time_stamp_ = encoded_image._timeStamp;
|
2012-06-05 21:07:28 +00:00
|
|
|
if (num_dropped_from_prev_encode > 0) {
|
|
|
|
|
// For dropped frames, we write out the last decoded frame to avoid getting
|
|
|
|
|
// out of sync for the computation of PSNR and SSIM.
|
|
|
|
|
for (int i = 0; i < num_dropped_from_prev_encode; i++) {
|
|
|
|
|
frame_writer_->WriteFrame(last_successful_frame_buffer_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Frame is not dropped, so update the encoded frame size
|
|
|
|
|
// (encoder callback is only called for non-zero length frames).
|
2014-12-01 15:23:21 +00:00
|
|
|
encoded_frame_size_ = encoded_image._length;
|
2012-06-05 21:07:28 +00:00
|
|
|
|
2015-09-17 12:16:04 -07:00
|
|
|
encoded_frame_type_ = encoded_image._frameType;
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
TickTime encode_stop = TickTime::Now();
|
2014-12-01 15:23:21 +00:00
|
|
|
int frame_number = encoded_image._timeStamp;
|
2011-10-06 06:44:54 +00:00
|
|
|
FrameStatistic& stat = stats_->stats_[frame_number];
|
2015-12-21 03:04:49 -08:00
|
|
|
stat.encode_time_in_us =
|
|
|
|
|
GetElapsedTimeMicroseconds(encode_start_, encode_stop);
|
2011-10-06 06:44:54 +00:00
|
|
|
stat.encoding_successful = true;
|
2014-12-01 15:23:21 +00:00
|
|
|
stat.encoded_frame_length_in_bytes = encoded_image._length;
|
|
|
|
|
stat.frame_number = encoded_image._timeStamp;
|
|
|
|
|
stat.frame_type = encoded_image._frameType;
|
|
|
|
|
stat.bit_rate_in_kbps = encoded_image._length * bit_rate_factor_;
|
2015-12-21 03:04:49 -08:00
|
|
|
stat.total_packets =
|
|
|
|
|
encoded_image._length / config_.networking_config.packet_size_in_bytes +
|
|
|
|
|
1;
|
2011-10-06 06:44:54 +00:00
|
|
|
|
|
|
|
|
// Perform packet loss if criteria is fullfilled:
|
|
|
|
|
bool exclude_this_frame = false;
|
|
|
|
|
// Only keyframes can be excluded
|
2015-10-23 15:58:18 +02:00
|
|
|
if (encoded_image._frameType == kVideoFrameKey) {
|
2011-10-06 06:44:54 +00:00
|
|
|
switch (config_.exclude_frame_types) {
|
|
|
|
|
case kExcludeOnlyFirstKeyFrame:
|
|
|
|
|
if (!first_key_frame_has_been_excluded_) {
|
|
|
|
|
first_key_frame_has_been_excluded_ = true;
|
|
|
|
|
exclude_this_frame = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case kExcludeAllKeyFrames:
|
|
|
|
|
exclude_this_frame = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-27 01:36:03 -08:00
|
|
|
|
|
|
|
|
// Make a raw copy of the |encoded_image| buffer.
|
2016-01-22 00:07:12 -08:00
|
|
|
size_t copied_buffer_size = encoded_image._length +
|
|
|
|
|
EncodedImage::GetBufferPaddingBytes(codec);
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<uint8_t[]> copied_buffer(new uint8_t[copied_buffer_size]);
|
2014-12-01 15:23:21 +00:00
|
|
|
memcpy(copied_buffer.get(), encoded_image._buffer, encoded_image._length);
|
2016-01-27 01:36:03 -08:00
|
|
|
// The image to feed to the decoder.
|
2014-12-01 15:23:21 +00:00
|
|
|
EncodedImage copied_image;
|
|
|
|
|
memcpy(&copied_image, &encoded_image, sizeof(copied_image));
|
2016-01-22 00:07:12 -08:00
|
|
|
copied_image._size = copied_buffer_size;
|
2014-12-01 15:23:21 +00:00
|
|
|
copied_image._buffer = copied_buffer.get();
|
2016-01-27 01:36:03 -08:00
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
if (!exclude_this_frame) {
|
|
|
|
|
stat.packets_dropped =
|
2015-12-21 03:04:49 -08:00
|
|
|
packet_manipulator_->ManipulatePackets(&copied_image);
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep track of if frames are lost due to packet loss so we can tell
|
|
|
|
|
// this to the encoder (this is handled by the RTP logic in the full stack)
|
|
|
|
|
decode_start_ = TickTime::Now();
|
|
|
|
|
// TODO(kjellander): Pass fragmentation header to the decoder when
|
|
|
|
|
// CL 172001 has been submitted and PacketManipulator supports this.
|
2014-12-01 15:23:21 +00:00
|
|
|
int32_t decode_result =
|
|
|
|
|
decoder_->Decode(copied_image, last_frame_missing_, NULL);
|
2011-10-06 06:44:54 +00:00
|
|
|
stat.decode_return_code = decode_result;
|
|
|
|
|
if (decode_result != WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
// Write the last successful frame the output file to avoid getting it out
|
|
|
|
|
// of sync with the source file for SSIM and PSNR comparisons:
|
2011-12-08 07:42:18 +00:00
|
|
|
frame_writer_->WriteFrame(last_successful_frame_buffer_);
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
// save status for losses so we can inform the decoder for the next frame:
|
2014-12-01 15:23:21 +00:00
|
|
|
last_frame_missing_ = copied_image._length == 0;
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
|
2011-10-06 06:44:54 +00:00
|
|
|
TickTime decode_stop = TickTime::Now();
|
2012-10-24 18:33:04 +00:00
|
|
|
int frame_number = image.timestamp();
|
2011-10-06 06:44:54 +00:00
|
|
|
// Report stats
|
|
|
|
|
FrameStatistic& stat = stats_->stats_[frame_number];
|
2015-12-21 03:04:49 -08:00
|
|
|
stat.decode_time_in_us =
|
|
|
|
|
GetElapsedTimeMicroseconds(decode_start_, decode_stop);
|
2011-10-06 06:44:54 +00:00
|
|
|
stat.decoding_successful = true;
|
|
|
|
|
|
2012-06-05 21:07:28 +00:00
|
|
|
// Check for resize action (either down or up):
|
2012-10-24 18:33:04 +00:00
|
|
|
if (static_cast<int>(image.width()) != last_encoder_frame_width_ ||
|
2015-12-21 03:04:49 -08:00
|
|
|
static_cast<int>(image.height()) != last_encoder_frame_height_) {
|
2012-06-05 21:07:28 +00:00
|
|
|
++num_spatial_resizes_;
|
2012-10-24 18:33:04 +00:00
|
|
|
last_encoder_frame_width_ = image.width();
|
|
|
|
|
last_encoder_frame_height_ = image.height();
|
2012-06-05 21:07:28 +00:00
|
|
|
}
|
|
|
|
|
// Check if codec size is different from native/original size, and if so,
|
|
|
|
|
// upsample back to original size: needed for PSNR and SSIM computations.
|
2015-12-21 03:04:49 -08:00
|
|
|
if (image.width() != config_.codec_settings->width ||
|
2012-10-24 18:33:04 +00:00
|
|
|
image.height() != config_.codec_settings->height) {
|
2015-05-29 17:21:40 -07:00
|
|
|
VideoFrame up_image;
|
2015-12-21 03:04:49 -08:00
|
|
|
int ret_val = scaler_.Set(
|
|
|
|
|
image.width(), image.height(), config_.codec_settings->width,
|
|
|
|
|
config_.codec_settings->height, kI420, kI420, kScaleBilinear);
|
2012-06-05 21:07:28 +00:00
|
|
|
assert(ret_val >= 0);
|
|
|
|
|
if (ret_val < 0) {
|
|
|
|
|
fprintf(stderr, "Failed to set scalar for frame: %d, return code: %d\n",
|
|
|
|
|
frame_number, ret_val);
|
|
|
|
|
}
|
2012-09-28 19:47:23 +00:00
|
|
|
ret_val = scaler_.Scale(image, &up_image);
|
2012-06-05 21:07:28 +00:00
|
|
|
assert(ret_val >= 0);
|
|
|
|
|
if (ret_val < 0) {
|
|
|
|
|
fprintf(stderr, "Failed to scale frame: %d, return code: %d\n",
|
|
|
|
|
frame_number, ret_val);
|
|
|
|
|
}
|
2012-10-24 18:33:04 +00:00
|
|
|
// TODO(mikhal): Extracting the buffer for now - need to update test.
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t length = CalcBufferSize(kI420, up_image.width(), up_image.height());
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
int extracted_length = ExtractBuffer(up_image, length, image_buffer.get());
|
|
|
|
|
assert(extracted_length > 0);
|
2012-06-05 21:07:28 +00:00
|
|
|
// Update our copy of the last successful frame:
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
memcpy(last_successful_frame_buffer_, image_buffer.get(), extracted_length);
|
2012-10-24 18:33:04 +00:00
|
|
|
bool write_success = frame_writer_->WriteFrame(image_buffer.get());
|
2012-06-05 21:07:28 +00:00
|
|
|
assert(write_success);
|
|
|
|
|
if (!write_success) {
|
|
|
|
|
fprintf(stderr, "Failed to write frame %d to disk!", frame_number);
|
|
|
|
|
}
|
|
|
|
|
} else { // No resize.
|
|
|
|
|
// Update our copy of the last successful frame:
|
2012-10-24 18:33:04 +00:00
|
|
|
// TODO(mikhal): Add as a member function, so won't be allocated per frame.
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t length = CalcBufferSize(kI420, image.width(), image.height());
|
2016-02-29 05:51:59 -08:00
|
|
|
std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
int extracted_length = ExtractBuffer(image, length, image_buffer.get());
|
|
|
|
|
assert(extracted_length > 0);
|
|
|
|
|
memcpy(last_successful_frame_buffer_, image_buffer.get(), extracted_length);
|
2012-10-24 18:33:04 +00:00
|
|
|
|
|
|
|
|
bool write_success = frame_writer_->WriteFrame(image_buffer.get());
|
2012-06-05 21:07:28 +00:00
|
|
|
assert(write_success);
|
|
|
|
|
if (!write_success) {
|
|
|
|
|
fprintf(stderr, "Failed to write frame %d to disk!", frame_number);
|
|
|
|
|
}
|
2011-10-06 06:44:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VideoProcessorImpl::GetElapsedTimeMicroseconds(
|
2015-12-21 03:04:49 -08:00
|
|
|
const webrtc::TickTime& start,
|
|
|
|
|
const webrtc::TickTime& stop) {
|
2013-04-08 11:13:29 +00:00
|
|
|
uint64_t encode_time = (stop - start).Microseconds();
|
2011-10-06 06:44:54 +00:00
|
|
|
assert(encode_time <
|
|
|
|
|
static_cast<unsigned int>(std::numeric_limits<int>::max()));
|
|
|
|
|
return static_cast<int>(encode_time);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-07 06:50:22 +00:00
|
|
|
const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) {
|
|
|
|
|
switch (e) {
|
|
|
|
|
case kExcludeOnlyFirstKeyFrame:
|
|
|
|
|
return "ExcludeOnlyFirstKeyFrame";
|
|
|
|
|
case kExcludeAllKeyFrames:
|
|
|
|
|
return "ExcludeAllKeyFrames";
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2011-11-02 16:34:52 +00:00
|
|
|
return "Unknown";
|
2011-10-07 06:50:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* VideoCodecTypeToStr(webrtc::VideoCodecType e) {
|
|
|
|
|
switch (e) {
|
|
|
|
|
case kVideoCodecVP8:
|
|
|
|
|
return "VP8";
|
|
|
|
|
case kVideoCodecI420:
|
|
|
|
|
return "I420";
|
|
|
|
|
case kVideoCodecRED:
|
|
|
|
|
return "RED";
|
|
|
|
|
case kVideoCodecULPFEC:
|
|
|
|
|
return "ULPFEC";
|
|
|
|
|
case kVideoCodecUnknown:
|
|
|
|
|
return "Unknown";
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
2011-11-02 16:34:52 +00:00
|
|
|
return "Unknown";
|
2011-10-07 06:50:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 06:44:54 +00:00
|
|
|
// Callbacks
|
2015-12-21 03:04:49 -08:00
|
|
|
int32_t VideoProcessorImpl::VideoProcessorEncodeCompleteCallback::Encoded(
|
2014-12-01 15:23:21 +00:00
|
|
|
const EncodedImage& encoded_image,
|
2011-10-06 06:44:54 +00:00
|
|
|
const webrtc::CodecSpecificInfo* codec_specific_info,
|
|
|
|
|
const webrtc::RTPFragmentationHeader* fragmentation) {
|
2016-01-27 01:36:03 -08:00
|
|
|
// Forward to parent class.
|
2016-01-22 00:07:12 -08:00
|
|
|
RTC_CHECK(codec_specific_info);
|
|
|
|
|
video_processor_->FrameEncoded(codec_specific_info->codecType,
|
2016-01-27 01:36:03 -08:00
|
|
|
encoded_image,
|
|
|
|
|
fragmentation);
|
2011-10-06 06:44:54 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded(
|
|
|
|
|
VideoFrame& image) {
|
2016-01-27 01:36:03 -08:00
|
|
|
// Forward to parent class.
|
|
|
|
|
video_processor_->FrameDecoded(image);
|
2011-10-06 06:44:54 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|