FrameGenerator class for future fake capture device.

BUG=
R=mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1511004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4093 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org 2013-05-23 12:37:11 +00:00
parent 771cdcbb09
commit 9b30348cfc
7 changed files with 174 additions and 11 deletions

View File

@ -24,7 +24,8 @@ namespace webrtc {
namespace internal {
VideoSendStream::VideoSendStream(
newapi::Transport* transport, webrtc::VideoEngine* video_engine,
newapi::Transport* transport,
webrtc::VideoEngine* video_engine,
const newapi::VideoSendStreamConfig& send_stream_config)
: transport_(transport), config_(send_stream_config) {
@ -74,7 +75,9 @@ VideoSendStream::~VideoSendStream() {
}
void VideoSendStream::PutFrame(const I420VideoFrame& frame,
int32_t delta_capture_time) {
uint32_t time_since_capture_ms) {
// TODO(pbos): frame_copy should happen after the VideoProcessingModule has
// resized the frame.
I420VideoFrame frame_copy;
frame_copy.CopyFrame(frame);
@ -95,7 +98,7 @@ void VideoSendStream::PutFrame(const I420VideoFrame& frame,
vf.width = frame.width();
vf.height = frame.height();
external_capture_->IncomingFrameI420(vf, frame.timestamp());
external_capture_->IncomingFrameI420(vf, frame.render_time_ms());
if (config_.local_renderer != NULL) {
config_.local_renderer->RenderFrame(frame, 0);
@ -105,11 +108,13 @@ void VideoSendStream::PutFrame(const I420VideoFrame& frame,
newapi::VideoSendStreamInput* VideoSendStream::Input() { return this; }
void VideoSendStream::StartSend() {
if (video_engine_base_->StartSend(channel_) != 0) abort();
if (video_engine_base_->StartSend(channel_) != 0)
abort();
}
void VideoSendStream::StopSend() {
if (video_engine_base_->StopSend(channel_) != 0) abort();
if (video_engine_base_->StopSend(channel_) != 0)
abort();
}
void VideoSendStream::GetSendStatistics(
@ -118,7 +123,8 @@ void VideoSendStream::GetSendStatistics(
}
bool VideoSendStream::SetTargetBitrate(
int min_bitrate, int max_bitrate,
int min_bitrate,
int max_bitrate,
const std::vector<SimulcastStream>& streams) {
return false;
}
@ -127,7 +133,8 @@ void VideoSendStream::GetSendCodec(VideoCodec* send_codec) {
*send_codec = config_.codec;
}
int VideoSendStream::SendPacket(int /*channel*/, const void* packet,
int VideoSendStream::SendPacket(int /*channel*/,
const void* packet,
int length) {
// TODO(pbos): Lock these methods and the destructor so it can't be processing
// a packet when the destructor has been called.
@ -135,7 +142,8 @@ int VideoSendStream::SendPacket(int /*channel*/, const void* packet,
return transport_->SendRTP(packet, static_cast<size_t>(length)) ? 0 : -1;
}
int VideoSendStream::SendRTCPPacket(int /*channel*/, const void* packet,
int VideoSendStream::SendRTCPPacket(int /*channel*/,
const void* packet,
int length) {
assert(length >= 0);
return transport_->SendRTCP(packet, static_cast<size_t>(length)) ? 0 : -1;

View File

@ -38,8 +38,8 @@ class VideoSendStream : public newapi::VideoSendStream,
virtual ~VideoSendStream();
virtual void PutFrame(const I420VideoFrame& frame, int32_t delta_capture_time)
OVERRIDE;
virtual void PutFrame(const I420VideoFrame& frame,
uint32_t time_since_capture_ms) OVERRIDE;
virtual newapi::VideoSendStreamInput* Input() OVERRIDE;

View File

@ -46,7 +46,7 @@ class VideoSendStreamInput {
// TODO(mflodman) Replace time_since_capture_ms when I420VideoFrame uses NTP
// time.
virtual void PutFrame(const I420VideoFrame& video_frame,
int time_since_capture_ms) = 0;
uint32_t time_since_capture_ms) = 0;
protected:
virtual ~VideoSendStreamInput() {}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "webrtc/video_engine/test/common/frame_generator.h"
#include <cmath>
#include <cstring>
#include "webrtc/system_wrappers/interface/clock.h"
namespace webrtc {
namespace test {
FrameGenerator* FrameGenerator::Create(size_t width,
size_t height,
Clock* clock) {
return new ChromaFrameGenerator(width, height, clock);
}
void FrameGenerator::InsertFrame(newapi::VideoSendStreamInput* input) {
int64_t time_before = clock_->TimeInMilliseconds();
frame_.set_render_time_ms(time_before);
GenerateNextFrame();
int64_t time_after = clock_->TimeInMilliseconds();
input->PutFrame(frame_, static_cast<uint32_t>(time_after - time_before));
}
FrameGenerator::FrameGenerator(size_t width, size_t height, Clock* clock)
: width_(width), height_(height), clock_(clock) {
// Generate frame by constructor arguments
assert(width > 0);
assert(height > 0);
frame_.CreateEmptyFrame(static_cast<int>(width), static_cast<int>(height),
width, (width + 1) / 2, (width + 1) / 2);
}
BlackFrameGenerator::BlackFrameGenerator(size_t width,
size_t height,
Clock* clock)
: FrameGenerator(width, height, clock) {
memset(frame_.buffer(kYPlane), 0x00, frame_.allocated_size(kYPlane));
memset(frame_.buffer(kUPlane), 0x80, frame_.allocated_size(kUPlane));
memset(frame_.buffer(kVPlane), 0x80, frame_.allocated_size(kVPlane));
}
void BlackFrameGenerator::GenerateNextFrame() {}
WhiteFrameGenerator::WhiteFrameGenerator(size_t width,
size_t height,
Clock* clock)
: FrameGenerator(width, height, clock) {
memset(frame_.buffer(kYPlane), 0xFF, frame_.allocated_size(kYPlane));
memset(frame_.buffer(kUPlane), 0x80, frame_.allocated_size(kUPlane));
memset(frame_.buffer(kVPlane), 0x80, frame_.allocated_size(kVPlane));
}
void WhiteFrameGenerator::GenerateNextFrame() {}
ChromaFrameGenerator::ChromaFrameGenerator(size_t width,
size_t height,
Clock* clock)
: FrameGenerator(width, height, clock) {
memset(frame_.buffer(kYPlane), 0x80, frame_.allocated_size(kYPlane));
}
void ChromaFrameGenerator::GenerateNextFrame() {
double angle = static_cast<double>(frame_.render_time_ms()) / 1000.0;
uint8_t u = fabs(sin(angle)) * 0xFF;
uint8_t v = fabs(cos(angle)) * 0xFF;
memset(frame_.buffer(kUPlane), u, frame_.allocated_size(kUPlane));
memset(frame_.buffer(kVPlane), v, frame_.allocated_size(kVPlane));
}
} // test
} // webrtc

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_FRAME_GENERATOR_H_
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_FRAME_GENERATOR_H_
#include "webrtc/common_video/interface/i420_video_frame.h"
#include "webrtc/typedefs.h"
#include "webrtc/video_engine/new_include/video_send_stream.h"
namespace webrtc {
class Clock;
namespace test {
// A set of classes that generate sequences of I420VideoFrames for testing
// without using the webcam.
class FrameGenerator {
public:
static FrameGenerator* Create(size_t width, size_t height, Clock* clock);
virtual ~FrameGenerator() {}
void InsertFrame(newapi::VideoSendStreamInput* input);
protected:
FrameGenerator(size_t width, size_t height, Clock* clock);
virtual void GenerateNextFrame() = 0;
size_t width_, height_;
I420VideoFrame frame_;
Clock* clock_;
};
class BlackFrameGenerator : public FrameGenerator {
public:
BlackFrameGenerator(size_t width, size_t height, Clock* clock);
private:
virtual void GenerateNextFrame() OVERRIDE;
};
class WhiteFrameGenerator : public FrameGenerator {
public:
WhiteFrameGenerator(size_t width, size_t height, Clock* clock);
private:
virtual void GenerateNextFrame() OVERRIDE;
};
class ChromaFrameGenerator : public FrameGenerator {
public:
ChromaFrameGenerator(size_t width, size_t height, Clock* clock);
private:
virtual void GenerateNextFrame() OVERRIDE;
};
} // test
} // webrtc
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_FRAME_GENERATOR_H_

View File

@ -21,6 +21,8 @@ class VideoRenderer : public newapi::VideoRenderer {
size_t width,
size_t height);
virtual ~VideoRenderer() {}
protected:
VideoRenderer() {}
};
} // test
} // webrtc

View File

@ -29,6 +29,8 @@
'sources': [
'common/flags.cc',
'common/flags.h',
'common/frame_generator.cc',
'common/frame_generator.h',
'common/generate_ssrcs.h',
'common/vcm_capturer.h',
'common/vcm_capturer.cc',