Remove VideoProcessor interface.
BUG=webrtc:6634 Review-Url: https://codereview.webrtc.org/2994613002 Cr-Commit-Position: refs/heads/master@{#19256}
This commit is contained in:
@ -105,7 +105,7 @@ const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder,
|
||||||
webrtc::VideoDecoder* decoder,
|
webrtc::VideoDecoder* decoder,
|
||||||
FrameReader* analysis_frame_reader,
|
FrameReader* analysis_frame_reader,
|
||||||
FrameWriter* analysis_frame_writer,
|
FrameWriter* analysis_frame_writer,
|
||||||
@ -144,12 +144,12 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
|||||||
frame_infos_.reserve(analysis_frame_reader->NumberOfFrames());
|
frame_infos_.reserve(analysis_frame_reader->NumberOfFrames());
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoProcessorImpl::~VideoProcessorImpl() {
|
VideoProcessor::~VideoProcessor() {
|
||||||
encoder_->RegisterEncodeCompleteCallback(nullptr);
|
encoder_->RegisterEncodeCompleteCallback(nullptr);
|
||||||
decoder_->RegisterDecodeCompleteCallback(nullptr);
|
decoder_->RegisterDecodeCompleteCallback(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProcessorImpl::Init() {
|
void VideoProcessor::Init() {
|
||||||
RTC_DCHECK(!initialized_) << "VideoProcessor already initialized.";
|
RTC_DCHECK(!initialized_) << "VideoProcessor already initialized.";
|
||||||
RTC_DCHECK(config_.codec_settings) << "No codec settings supplied.";
|
RTC_DCHECK(config_.codec_settings) << "No codec settings supplied.";
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
@ -196,7 +196,7 @@ void VideoProcessorImpl::Init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoProcessorImpl::ProcessFrame(int frame_number) {
|
bool VideoProcessor::ProcessFrame(int frame_number) {
|
||||||
RTC_DCHECK_GE(frame_number, 0);
|
RTC_DCHECK_GE(frame_number, 0);
|
||||||
RTC_DCHECK_LE(frame_number, frame_infos_.size())
|
RTC_DCHECK_LE(frame_number, frame_infos_.size())
|
||||||
<< "Must process frames without gaps.";
|
<< "Must process frames without gaps.";
|
||||||
@ -253,7 +253,7 @@ bool VideoProcessorImpl::ProcessFrame(int frame_number) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
|
void VideoProcessor::SetRates(int bit_rate, int frame_rate) {
|
||||||
config_.codec_settings->maxFramerate = frame_rate;
|
config_.codec_settings->maxFramerate = frame_rate;
|
||||||
int set_rates_result = encoder_->SetRateAllocation(
|
int set_rates_result = encoder_->SetRateAllocation(
|
||||||
bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate),
|
bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate),
|
||||||
@ -264,35 +264,35 @@ void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
|
|||||||
num_spatial_resizes_ = 0;
|
num_spatial_resizes_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) {
|
size_t VideoProcessor::EncodedFrameSize(int frame_number) {
|
||||||
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
||||||
return frame_infos_[frame_number].encoded_frame_size;
|
return frame_infos_[frame_number].encoded_frame_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) {
|
FrameType VideoProcessor::EncodedFrameType(int frame_number) {
|
||||||
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
||||||
return frame_infos_[frame_number].encoded_frame_type;
|
return frame_infos_[frame_number].encoded_frame_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoProcessorImpl::GetQpFromEncoder(int frame_number) {
|
int VideoProcessor::GetQpFromEncoder(int frame_number) {
|
||||||
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
||||||
return frame_infos_[frame_number].qp_encoder;
|
return frame_infos_[frame_number].qp_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoProcessorImpl::GetQpFromBitstream(int frame_number) {
|
int VideoProcessor::GetQpFromBitstream(int frame_number) {
|
||||||
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
RTC_DCHECK_LT(frame_number, frame_infos_.size());
|
||||||
return frame_infos_[frame_number].qp_bitstream;
|
return frame_infos_[frame_number].qp_bitstream;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoProcessorImpl::NumberDroppedFrames() {
|
int VideoProcessor::NumberDroppedFrames() {
|
||||||
return num_dropped_frames_;
|
return num_dropped_frames_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoProcessorImpl::NumberSpatialResizes() {
|
int VideoProcessor::NumberSpatialResizes() {
|
||||||
return num_spatial_resizes_;
|
return num_spatial_resizes_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProcessorImpl::FrameEncoded(
|
void VideoProcessor::FrameEncoded(
|
||||||
webrtc::VideoCodecType codec,
|
webrtc::VideoCodecType codec,
|
||||||
const EncodedImage& encoded_image,
|
const EncodedImage& encoded_image,
|
||||||
const webrtc::RTPFragmentationHeader* fragmentation) {
|
const webrtc::RTPFragmentationHeader* fragmentation) {
|
||||||
@ -428,7 +428,7 @@ void VideoProcessorImpl::FrameEncoded(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
|
void VideoProcessor::FrameDecoded(const VideoFrame& image) {
|
||||||
// For the highest measurement accuracy of the decode time, the start/stop
|
// For the highest measurement accuracy of the decode time, the start/stop
|
||||||
// time recordings should wrap the Decode call as tightly as possible.
|
// time recordings should wrap the Decode call as tightly as possible.
|
||||||
int64_t decode_stop_ns = rtc::TimeNanos();
|
int64_t decode_stop_ns = rtc::TimeNanos();
|
||||||
@ -496,14 +496,14 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
|
|||||||
last_decoded_frame_buffer_ = std::move(extracted_buffer);
|
last_decoded_frame_buffer_ = std::move(extracted_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t VideoProcessorImpl::FrameNumberToTimestamp(int frame_number) {
|
uint32_t VideoProcessor::FrameNumberToTimestamp(int frame_number) {
|
||||||
RTC_DCHECK_GE(frame_number, 0);
|
RTC_DCHECK_GE(frame_number, 0);
|
||||||
const int ticks_per_frame =
|
const int ticks_per_frame =
|
||||||
kRtpClockRateHz / config_.codec_settings->maxFramerate;
|
kRtpClockRateHz / config_.codec_settings->maxFramerate;
|
||||||
return (frame_number + 1) * ticks_per_frame;
|
return (frame_number + 1) * ticks_per_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoProcessorImpl::TimestampToFrameNumber(uint32_t timestamp) {
|
int VideoProcessor::TimestampToFrameNumber(uint32_t timestamp) {
|
||||||
RTC_DCHECK_GT(timestamp, 0);
|
RTC_DCHECK_GT(timestamp, 0);
|
||||||
const int ticks_per_frame =
|
const int ticks_per_frame =
|
||||||
kRtpClockRateHz / config_.codec_settings->maxFramerate;
|
kRtpClockRateHz / config_.codec_settings->maxFramerate;
|
||||||
|
|||||||
@ -136,46 +136,9 @@ struct TestConfig {
|
|||||||
//
|
//
|
||||||
// Note this class is not thread safe in any way and is meant for simple testing
|
// Note this class is not thread safe in any way and is meant for simple testing
|
||||||
// purposes.
|
// purposes.
|
||||||
//
|
|
||||||
// TODO(brandtr): Remove this interface.
|
|
||||||
class VideoProcessor {
|
class VideoProcessor {
|
||||||
public:
|
public:
|
||||||
virtual ~VideoProcessor() {}
|
VideoProcessor(webrtc::VideoEncoder* encoder,
|
||||||
|
|
||||||
// Sets up callbacks and initializes the encoder and decoder.
|
|
||||||
virtual void Init() = 0;
|
|
||||||
|
|
||||||
// Processes a single frame. Returns true as long as there's more frames
|
|
||||||
// available in the source clip.
|
|
||||||
// |frame_number| must be an integer >= 0.
|
|
||||||
virtual bool ProcessFrame(int frame_number) = 0;
|
|
||||||
|
|
||||||
// Updates the encoder with the target |bit_rate| and the |frame_rate|.
|
|
||||||
virtual void SetRates(int bit_rate, int frame_rate) = 0;
|
|
||||||
|
|
||||||
// Return the size of the encoded frame in bytes. Dropped frames by the
|
|
||||||
// encoder are regarded as zero size.
|
|
||||||
virtual size_t EncodedFrameSize(int frame_number) = 0;
|
|
||||||
|
|
||||||
// Return the encoded frame type (key or delta).
|
|
||||||
virtual FrameType EncodedFrameType(int frame_number) = 0;
|
|
||||||
|
|
||||||
// Return the qp used by encoder.
|
|
||||||
virtual int GetQpFromEncoder(int frame_number) = 0;
|
|
||||||
|
|
||||||
// Return the qp from the qp parser.
|
|
||||||
virtual int GetQpFromBitstream(int frame_number) = 0;
|
|
||||||
|
|
||||||
// Return the number of dropped frames.
|
|
||||||
virtual int NumberDroppedFrames() = 0;
|
|
||||||
|
|
||||||
// Return the number of spatial resizes.
|
|
||||||
virtual int NumberSpatialResizes() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VideoProcessorImpl : public VideoProcessor {
|
|
||||||
public:
|
|
||||||
VideoProcessorImpl(webrtc::VideoEncoder* encoder,
|
|
||||||
webrtc::VideoDecoder* decoder,
|
webrtc::VideoDecoder* decoder,
|
||||||
FrameReader* analysis_frame_reader,
|
FrameReader* analysis_frame_reader,
|
||||||
FrameWriter* analysis_frame_writer,
|
FrameWriter* analysis_frame_writer,
|
||||||
@ -185,18 +148,37 @@ class VideoProcessorImpl : public VideoProcessor {
|
|||||||
FrameWriter* source_frame_writer,
|
FrameWriter* source_frame_writer,
|
||||||
IvfFileWriter* encoded_frame_writer,
|
IvfFileWriter* encoded_frame_writer,
|
||||||
FrameWriter* decoded_frame_writer);
|
FrameWriter* decoded_frame_writer);
|
||||||
~VideoProcessorImpl() override;
|
~VideoProcessor();
|
||||||
|
|
||||||
// Implements VideoProcessor.
|
// Sets up callbacks and initializes the encoder and decoder.
|
||||||
void Init() override;
|
void Init();
|
||||||
bool ProcessFrame(int frame_number) override;
|
|
||||||
void SetRates(int bit_rate, int frame_rate) override;
|
// Processes a single frame. Returns true as long as there's more frames
|
||||||
size_t EncodedFrameSize(int frame_number) override;
|
// available in the source clip.
|
||||||
FrameType EncodedFrameType(int frame_number) override;
|
// |frame_number| must be an integer >= 0.
|
||||||
int GetQpFromEncoder(int frame_number) override;
|
bool ProcessFrame(int frame_number);
|
||||||
int GetQpFromBitstream(int frame_number) override;
|
|
||||||
int NumberDroppedFrames() override;
|
// Updates the encoder with the target |bit_rate| and the |frame_rate|.
|
||||||
int NumberSpatialResizes() override;
|
void SetRates(int bit_rate, int frame_rate);
|
||||||
|
|
||||||
|
// Return the size of the encoded frame in bytes. Dropped frames by the
|
||||||
|
// encoder are regarded as zero size.
|
||||||
|
size_t EncodedFrameSize(int frame_number);
|
||||||
|
|
||||||
|
// Return the encoded frame type (key or delta).
|
||||||
|
FrameType EncodedFrameType(int frame_number);
|
||||||
|
|
||||||
|
// Return the qp used by encoder.
|
||||||
|
int GetQpFromEncoder(int frame_number);
|
||||||
|
|
||||||
|
// Return the qp from the qp parser.
|
||||||
|
int GetQpFromBitstream(int frame_number);
|
||||||
|
|
||||||
|
// Return the number of dropped frames.
|
||||||
|
int NumberDroppedFrames();
|
||||||
|
|
||||||
|
// Return the number of spatial resizes.
|
||||||
|
int NumberSpatialResizes();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Container that holds per-frame information that needs to be stored between
|
// Container that holds per-frame information that needs to be stored between
|
||||||
@ -231,8 +213,9 @@ class VideoProcessorImpl : public VideoProcessor {
|
|||||||
class VideoProcessorEncodeCompleteCallback
|
class VideoProcessorEncodeCompleteCallback
|
||||||
: public webrtc::EncodedImageCallback {
|
: public webrtc::EncodedImageCallback {
|
||||||
public:
|
public:
|
||||||
explicit VideoProcessorEncodeCompleteCallback(VideoProcessorImpl* vp)
|
explicit VideoProcessorEncodeCompleteCallback(
|
||||||
: video_processor_(vp) {}
|
VideoProcessor* video_processor)
|
||||||
|
: video_processor_(video_processor) {}
|
||||||
Result OnEncodedImage(
|
Result OnEncodedImage(
|
||||||
const webrtc::EncodedImage& encoded_image,
|
const webrtc::EncodedImage& encoded_image,
|
||||||
const webrtc::CodecSpecificInfo* codec_specific_info,
|
const webrtc::CodecSpecificInfo* codec_specific_info,
|
||||||
@ -245,15 +228,16 @@ class VideoProcessorImpl : public VideoProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoProcessorImpl* const video_processor_;
|
VideoProcessor* const video_processor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callback class required to implement according to the VideoDecoder API.
|
// Callback class required to implement according to the VideoDecoder API.
|
||||||
class VideoProcessorDecodeCompleteCallback
|
class VideoProcessorDecodeCompleteCallback
|
||||||
: public webrtc::DecodedImageCallback {
|
: public webrtc::DecodedImageCallback {
|
||||||
public:
|
public:
|
||||||
explicit VideoProcessorDecodeCompleteCallback(VideoProcessorImpl* vp)
|
explicit VideoProcessorDecodeCompleteCallback(
|
||||||
: video_processor_(vp) {}
|
VideoProcessor* video_processor)
|
||||||
|
: video_processor_(video_processor) {}
|
||||||
int32_t Decoded(webrtc::VideoFrame& image) override {
|
int32_t Decoded(webrtc::VideoFrame& image) override {
|
||||||
// Forward to parent class.
|
// Forward to parent class.
|
||||||
video_processor_->FrameDecoded(image);
|
video_processor_->FrameDecoded(image);
|
||||||
@ -270,7 +254,7 @@ class VideoProcessorImpl : public VideoProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoProcessorImpl* const video_processor_;
|
VideoProcessor* const video_processor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Invoked by the callback when a frame has completed encoding.
|
// Invoked by the callback when a frame has completed encoding.
|
||||||
|
|||||||
@ -40,6 +40,7 @@
|
|||||||
#include "webrtc/rtc_base/checks.h"
|
#include "webrtc/rtc_base/checks.h"
|
||||||
#include "webrtc/rtc_base/file.h"
|
#include "webrtc/rtc_base/file.h"
|
||||||
#include "webrtc/rtc_base/logging.h"
|
#include "webrtc/rtc_base/logging.h"
|
||||||
|
#include "webrtc/rtc_base/ptr_util.h"
|
||||||
#include "webrtc/test/gtest.h"
|
#include "webrtc/test/gtest.h"
|
||||||
#include "webrtc/test/testsupport/fileutils.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
#include "webrtc/test/testsupport/frame_reader.h"
|
#include "webrtc/test/testsupport/frame_reader.h"
|
||||||
@ -260,11 +261,11 @@ class VideoProcessorIntegrationTest : public testing::Test {
|
|||||||
|
|
||||||
packet_manipulator_.reset(new test::PacketManipulatorImpl(
|
packet_manipulator_.reset(new test::PacketManipulatorImpl(
|
||||||
&packet_reader_, config_.networking_config, config_.verbose));
|
&packet_reader_, config_.networking_config, config_.verbose));
|
||||||
processor_.reset(new test::VideoProcessorImpl(
|
processor_ = rtc::MakeUnique<VideoProcessor>(
|
||||||
encoder_.get(), decoder_.get(), analysis_frame_reader_.get(),
|
encoder_.get(), decoder_.get(), analysis_frame_reader_.get(),
|
||||||
analysis_frame_writer_.get(), packet_manipulator_.get(), config_,
|
analysis_frame_writer_.get(), packet_manipulator_.get(), config_,
|
||||||
&stats_, source_frame_writer_.get(), encoded_frame_writer_.get(),
|
&stats_, source_frame_writer_.get(), encoded_frame_writer_.get(),
|
||||||
decoded_frame_writer_.get()));
|
decoded_frame_writer_.get());
|
||||||
processor_->Init();
|
processor_->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ class VideoProcessorTest : public testing::Test {
|
|||||||
.WillRepeatedly(Return(kNumFrames));
|
.WillRepeatedly(Return(kNumFrames));
|
||||||
EXPECT_CALL(frame_reader_mock_, FrameLength())
|
EXPECT_CALL(frame_reader_mock_, FrameLength())
|
||||||
.WillRepeatedly(Return(kFrameSize));
|
.WillRepeatedly(Return(kFrameSize));
|
||||||
video_processor_ = rtc::MakeUnique<VideoProcessorImpl>(
|
video_processor_ = rtc::MakeUnique<VideoProcessor>(
|
||||||
&encoder_mock_, &decoder_mock_, &frame_reader_mock_,
|
&encoder_mock_, &decoder_mock_, &frame_reader_mock_,
|
||||||
&frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_,
|
&frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_,
|
||||||
nullptr /* source_frame_writer */, nullptr /* encoded_frame_writer */,
|
nullptr /* source_frame_writer */, nullptr /* encoded_frame_writer */,
|
||||||
@ -80,7 +80,7 @@ class VideoProcessorTest : public testing::Test {
|
|||||||
VideoCodec codec_settings_;
|
VideoCodec codec_settings_;
|
||||||
TestConfig config_;
|
TestConfig config_;
|
||||||
Stats stats_;
|
Stats stats_;
|
||||||
std::unique_ptr<VideoProcessorImpl> video_processor_;
|
std::unique_ptr<VideoProcessor> video_processor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(VideoProcessorTest, Init) {
|
TEST_F(VideoProcessorTest, Init) {
|
||||||
|
|||||||
@ -506,12 +506,10 @@ int main(int argc, char* argv[]) {
|
|||||||
if (FLAGS_disable_fixed_random_seed) {
|
if (FLAGS_disable_fixed_random_seed) {
|
||||||
packet_manipulator.InitializeRandomSeed(time(NULL));
|
packet_manipulator.InitializeRandomSeed(time(NULL));
|
||||||
}
|
}
|
||||||
webrtc::test::VideoProcessor* processor =
|
webrtc::test::VideoProcessor* processor = new webrtc::test::VideoProcessor(
|
||||||
new webrtc::test::VideoProcessorImpl(
|
|
||||||
encoder, decoder, &frame_reader, &frame_writer, &packet_manipulator,
|
encoder, decoder, &frame_reader, &frame_writer, &packet_manipulator,
|
||||||
config, &stats, nullptr /* source_frame_writer */,
|
config, &stats, nullptr /* source_frame_writer */,
|
||||||
nullptr /* encoded_frame_writer */,
|
nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */);
|
||||||
nullptr /* decoded_frame_writer */);
|
|
||||||
processor->Init();
|
processor->Init();
|
||||||
|
|
||||||
int frame_number = 0;
|
int frame_number = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user