Stats+Config moved into VideoSend/ReceiveStreams.

BUG=
R=mflodman@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4182 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org
2013-06-05 11:33:21 +00:00
parent fec34d7afa
commit 025f4f152b
11 changed files with 239 additions and 233 deletions

View File

@ -59,14 +59,14 @@ std::vector<VideoCodec> VideoCall::GetVideoCodecs() {
return codecs;
}
void VideoCall::GetDefaultSendConfig(
newapi::VideoSendStreamConfig* send_stream_config) {
*send_stream_config = newapi::VideoSendStreamConfig();
codec_->GetCodec(0, send_stream_config->codec);
VideoSendStream::Config VideoCall::GetDefaultSendConfig() {
VideoSendStream::Config config;
codec_->GetCodec(0, config.codec);
return config;
}
newapi::VideoSendStream* VideoCall::CreateSendStream(
const newapi::VideoSendStreamConfig& send_stream_config) {
const newapi::VideoSendStream::Config& send_stream_config) {
assert(send_stream_config.rtp.ssrcs.size() > 0);
assert(send_stream_config.codec.numberOfSimulcastStreams == 0 ||
send_stream_config.codec.numberOfSimulcastStreams ==
@ -95,14 +95,12 @@ newapi::SendStreamState* VideoCall::DestroySendStream(
return NULL;
}
void VideoCall::GetDefaultReceiveConfig(
newapi::VideoReceiveStreamConfig* receive_stream_config) {
// TODO(pbos): This is not the default config.
*receive_stream_config = newapi::VideoReceiveStreamConfig();
VideoReceiveStream::Config VideoCall::GetDefaultReceiveConfig() {
return newapi::VideoReceiveStream::Config();
}
newapi::VideoReceiveStream* VideoCall::CreateReceiveStream(
const newapi::VideoReceiveStreamConfig& receive_stream_config) {
const newapi::VideoReceiveStream::Config& receive_stream_config) {
assert(receive_ssrcs_[receive_stream_config.rtp.ssrc] == NULL);
VideoReceiveStream* receive_stream = new VideoReceiveStream(

View File

@ -38,20 +38,18 @@ class VideoCall : public newapi::VideoCall, public newapi::PacketReceiver {
virtual newapi::PacketReceiver* Receiver() OVERRIDE;
virtual std::vector<VideoCodec> GetVideoCodecs() OVERRIDE;
virtual void GetDefaultSendConfig(
newapi::VideoSendStreamConfig* send_stream_config) OVERRIDE;
virtual newapi::VideoSendStream::Config GetDefaultSendConfig() OVERRIDE;
virtual newapi::VideoSendStream* CreateSendStream(
const newapi::VideoSendStreamConfig& send_stream_config) OVERRIDE;
const newapi::VideoSendStream::Config& send_stream_config) OVERRIDE;
virtual newapi::SendStreamState* DestroySendStream(
newapi::VideoSendStream* send_stream) OVERRIDE;
virtual void GetDefaultReceiveConfig(
newapi::VideoReceiveStreamConfig* receive_stream_config) OVERRIDE;
virtual newapi::VideoReceiveStream::Config GetDefaultReceiveConfig() OVERRIDE;
virtual newapi::VideoReceiveStream* CreateReceiveStream(
const newapi::VideoReceiveStreamConfig& receive_stream_config) OVERRIDE;
const newapi::VideoReceiveStream::Config& receive_stream_config) OVERRIDE;
virtual void DestroyReceiveStream(newapi::VideoReceiveStream* receive_stream)
OVERRIDE;

View File

@ -28,7 +28,7 @@ namespace internal {
VideoReceiveStream::VideoReceiveStream(
webrtc::VideoEngine* video_engine,
const newapi::VideoReceiveStreamConfig& config,
const newapi::VideoReceiveStream::Config& config,
newapi::Transport* transport)
: transport_(transport), config_(config) {
video_engine_base_ = ViEBase::GetInterface(video_engine);
@ -98,11 +98,6 @@ void VideoReceiveStream::GetCurrentReceiveCodec(VideoCodec* receive_codec) {
// TODO(pbos): Implement
}
void VideoReceiveStream::GetReceiveStatistics(
newapi::ReceiveStatistics* statistics) {
// TODO(pbos): Implement
}
bool VideoReceiveStream::DeliverRtcp(const void* packet, size_t length) {
return network_->ReceivedRTCPPacket(channel_, packet, length) == 0;
}

View File

@ -34,7 +34,7 @@ class VideoReceiveStream : public newapi::VideoReceiveStream,
public webrtc::Transport {
public:
VideoReceiveStream(webrtc::VideoEngine* video_engine,
const newapi::VideoReceiveStreamConfig& config,
const newapi::VideoReceiveStream::Config& config,
newapi::Transport* transport);
virtual ~VideoReceiveStream();
@ -42,8 +42,6 @@ class VideoReceiveStream : public newapi::VideoReceiveStream,
virtual void StopReceive() OVERRIDE;
virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) OVERRIDE;
virtual void GetReceiveStatistics(newapi::ReceiveStatistics* statistics)
OVERRIDE;
virtual bool DeliverRtcp(const void* packet, size_t length);
virtual bool DeliverRtp(const void* packet, size_t length);
@ -62,7 +60,7 @@ class VideoReceiveStream : public newapi::VideoReceiveStream,
private:
newapi::Transport* transport_;
newapi::VideoReceiveStreamConfig config_;
newapi::VideoReceiveStream::Config config_;
Clock* clock_;
ViEBase* video_engine_base_;

View File

@ -26,8 +26,8 @@ namespace internal {
VideoSendStream::VideoSendStream(
newapi::Transport* transport,
webrtc::VideoEngine* video_engine,
const newapi::VideoSendStreamConfig& send_stream_config)
: transport_(transport), config_(send_stream_config) {
const newapi::VideoSendStream::Config& config)
: transport_(transport), config_(config) {
if (config_.codec.numberOfSimulcastStreams > 0) {
assert(config_.rtp.ssrcs.size() == config_.codec.numberOfSimulcastStreams);
@ -117,11 +117,6 @@ void VideoSendStream::StopSend() {
abort();
}
void VideoSendStream::GetSendStatistics(
std::vector<newapi::SendStatistics>* statistics) {
// TODO(pbos): Implement
}
bool VideoSendStream::SetTargetBitrate(
int min_bitrate,
int max_bitrate,

View File

@ -34,7 +34,7 @@ class VideoSendStream : public newapi::VideoSendStream,
public:
VideoSendStream(newapi::Transport* transport,
webrtc::VideoEngine* video_engine,
const newapi::VideoSendStreamConfig& send_stream_config);
const newapi::VideoSendStream::Config& config);
virtual ~VideoSendStream();
@ -47,9 +47,6 @@ class VideoSendStream : public newapi::VideoSendStream,
virtual void StopSend() OVERRIDE;
virtual void GetSendStatistics(
std::vector<newapi::SendStatistics>* statistics) OVERRIDE;
virtual bool SetTargetBitrate(int min_bitrate, int max_bitrate,
const std::vector<SimulcastStream>& streams)
OVERRIDE;
@ -64,7 +61,7 @@ class VideoSendStream : public newapi::VideoSendStream,
private:
newapi::Transport* transport_;
newapi::VideoSendStreamConfig config_;
newapi::VideoSendStream::Config config_;
ViEBase* video_engine_base_;
ViECapture* capture_;

View File

@ -51,20 +51,20 @@ class VideoCall {
public:
virtual std::vector<VideoCodec> GetVideoCodecs() = 0;
virtual void GetDefaultSendConfig(VideoSendStreamConfig* config) = 0;
virtual VideoSendStream::Config GetDefaultSendConfig() = 0;
virtual VideoSendStream* CreateSendStream(
const VideoSendStreamConfig& config) = 0;
const VideoSendStream::Config& config) = 0;
// Returns the internal state of the send stream, for resume sending with a
// new stream with different settings.
// Note: Only the last returned send-stream state is valid.
virtual SendStreamState* DestroySendStream(VideoSendStream* send_stream) = 0;
virtual void GetDefaultReceiveConfig(VideoReceiveStreamConfig* config) = 0;
virtual VideoReceiveStream::Config GetDefaultReceiveConfig() = 0;
virtual VideoReceiveStream* CreateReceiveStream(
const VideoReceiveStreamConfig& config) = 0;
const VideoReceiveStream::Config& config) = 0;
virtual void DestroyReceiveStream(VideoReceiveStream* receive_stream) = 0;
// All received RTP and RTCP packets for the call should be inserted to this

View File

@ -26,41 +26,6 @@ class VideoDecoder;
namespace newapi {
struct ReceiveStatistics {
RtpStatistics rtp_stats;
int network_frame_rate;
int decode_frame_rate;
int render_frame_rate;
uint32_t key_frames;
uint32_t delta_frames;
uint32_t video_packets;
uint32_t retransmitted_packets;
uint32_t fec_packets;
uint32_t padding_packets;
uint32_t discarded_packets;
int32_t received_bitrate_bps;
int receive_side_delay_ms;
};
// Receive stream specific RTP settings.
struct RtpReceiveConfig {
RtpReceiveConfig() : ssrc(0), nack(NULL), fec(NULL) {}
// TODO(mflodman) Do we require a set ssrc? What happens if the ssrc changes?
uint32_t ssrc;
// See NackConfig for description, 'NULL' disables NACK.
NackConfig* nack;
// See FecConfig for description, 'NULL' disables FEC.
FecConfig* fec;
// RTX settings for possible payloads. RTX is disabled if the vector is empty.
std::vector<RtxConfig> rtx;
// RTP header extensions used for the received stream.
std::vector<RtpExtension> rtp_extensions;
};
// TODO(mflodman) Move all these settings to VideoDecoder and move the
// declaration to common_types.h.
struct ExternalVideoDecoder {
@ -83,60 +48,117 @@ struct ExternalVideoDecoder {
int expected_delay_ms;
};
struct VideoReceiveStreamConfig {
VideoReceiveStreamConfig()
: renderer(NULL),
render_delay_ms(0),
audio_channel_id(0),
pre_decode_callback(NULL),
post_decode_callback(NULL),
target_delay_ms(0) {}
// Codecs the receive stream
std::vector<VideoCodec> codecs;
RtpReceiveConfig rtp;
// VideoRenderer will be called for each decoded frame. 'NULL' disables
// rendering of this stream.
VideoRenderer* renderer;
// Expected delay needed by the renderer, i.e. the frame will be delivered
// this many milliseconds, if possible, earlier than the ideal render time.
// Only valid if 'renderer' is set.
int render_delay_ms;
// Audio channel corresponding to this video stream, used for audio/video
// synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
// when creating the VideoEngine instance. '-1' disables a/v sync.
int audio_channel_id;
// Called for each incoming video frame, i.e. in encoded state. E.g. used when
// saving the stream to a file. 'NULL' disables the callback.
EncodedFrameObserver* pre_decode_callback;
// Called for each decoded frame. E.g. used when adding effects to the decoded
// stream. 'NULL' disables the callback.
I420FrameCallback* post_decode_callback;
// External video decoders to be used if incoming payload type matches the
// registered type for an external decoder.
std::vector<ExternalVideoDecoder> external_decoders;
// Target delay in milliseconds. A positive value indicates this stream is
// used for streaming instead of a real-time call.
int target_delay_ms;
};
class VideoReceiveStream {
public:
struct Stats {
Stats()
: network_frame_rate(0),
decode_frame_rate(0),
render_frame_rate(0),
key_frames(0),
delta_frames(0),
video_packets(0),
retransmitted_packets(0),
fec_packets(0),
padding_packets(0),
discarded_packets(0),
received_bitrate_bps(0),
receive_side_delay_ms(0) {}
RtpStatistics rtp_stats;
int network_frame_rate;
int decode_frame_rate;
int render_frame_rate;
uint32_t key_frames;
uint32_t delta_frames;
uint32_t video_packets;
uint32_t retransmitted_packets;
uint32_t fec_packets;
uint32_t padding_packets;
uint32_t discarded_packets;
int32_t received_bitrate_bps;
int receive_side_delay_ms;
};
class StatsCallback {
public:
virtual ~StatsCallback() {}
virtual void ReceiveStats(const Stats& stats) = 0;
};
struct Config {
Config()
: renderer(NULL),
render_delay_ms(0),
audio_channel_id(0),
pre_decode_callback(NULL),
post_decode_callback(NULL),
target_delay_ms(0) {}
// Codecs the receive stream
std::vector<VideoCodec> codecs;
// Receive-stream specific RTP settings.
struct Rtp {
Rtp() : ssrc(0) {}
// TODO(mflodman) Do we require a set ssrc? What happens if the ssrc
// changes?
uint32_t ssrc;
// See NackConfig for description.
NackConfig nack;
// See FecConfig for description.
FecConfig fec;
// RTX settings for possible payloads. RTX is disabled if the vector is
// empty.
std::vector<RtxConfig> rtx;
// RTP header extensions used for the received stream.
std::vector<RtpExtension> extensions;
} rtp;
// VideoRenderer will be called for each decoded frame. 'NULL' disables
// rendering of this stream.
VideoRenderer* renderer;
// Expected delay needed by the renderer, i.e. the frame will be delivered
// this many milliseconds, if possible, earlier than the ideal render time.
// Only valid if 'renderer' is set.
int render_delay_ms;
// Audio channel corresponding to this video stream, used for audio/video
// synchronization. 'audio_channel_id' is ignored if no VoiceEngine is set
// when creating the VideoEngine instance. '-1' disables a/v sync.
int audio_channel_id;
// Called for each incoming video frame, i.e. in encoded state. E.g. used
// when
// saving the stream to a file. 'NULL' disables the callback.
EncodedFrameObserver* pre_decode_callback;
// Called for each decoded frame. E.g. used when adding effects to the
// decoded
// stream. 'NULL' disables the callback.
I420FrameCallback* post_decode_callback;
// External video decoders to be used if incoming payload type matches the
// registered type for an external decoder.
std::vector<ExternalVideoDecoder> external_decoders;
// Target delay in milliseconds. A positive value indicates this stream is
// used for streaming instead of a real-time call.
int target_delay_ms;
// Callback for periodically receiving receiver stats.
StatsCallback* stats_callback;
};
virtual void StartReceive() = 0;
virtual void StopReceive() = 0;
// TODO(mflodman) Replace this with callback.
virtual void GetCurrentReceiveCodec(VideoCodec* receive_codec) = 0;
virtual void GetReceiveStatistics(ReceiveStatistics* statistics) = 0;
protected:
virtual ~VideoReceiveStream() {}
};

View File

@ -25,34 +25,8 @@ class VideoEncoder;
namespace newapi {
struct SendStreamState;
struct SendStatistics {
SendStatistics()
: input_frame_rate(0),
encode_frame(0),
key_frames(0),
delta_frames(0),
video_packets(0),
retransmitted_packets(0),
fec_packets(0),
padding_packets(0),
send_bitrate_bps(0),
delay_ms(0) {}
RtpStatistics rtp;
int input_frame_rate;
int encode_frame;
uint32_t key_frames;
uint32_t delta_frames;
uint32_t video_packets;
uint32_t retransmitted_packets;
uint32_t fec_packets;
uint32_t padding_packets;
int32_t send_bitrate_bps;
int delay_ms;
};
// Class to deliver captured frame to the video send stream.
class VideoSendStreamInput {
public:
@ -65,84 +39,117 @@ class VideoSendStreamInput {
virtual ~VideoSendStreamInput() {}
};
struct RtpSendConfig {
RtpSendConfig()
: mode(kRtcpReducedSize),
max_packet_size(0),
nack(NULL),
fec(NULL),
rtx(NULL) {}
RtcpMode mode;
std::vector<uint32_t> ssrcs;
// Max RTP packet size delivered to send transport from VideoEngine.
size_t max_packet_size;
// RTP header extensions to use for this send stream.
std::vector<RtpExtension> rtp_extensions;
// 'NULL' disables NACK.
NackConfig* nack;
// 'NULL' disables FEC.
FecConfig* fec;
// 'NULL' disables RTX.
RtxConfig* rtx;
// RTCP CNAME, see RFC 3550.
std::string c_name;
};
struct VideoSendStreamConfig {
VideoSendStreamConfig()
: pre_encode_callback(NULL),
encoded_callback(NULL),
local_renderer(NULL),
render_delay_ms(0),
encoder(NULL),
internal_source(false),
target_delay_ms(0),
start_state(NULL) {}
VideoCodec codec;
RtpSendConfig rtp;
// Called for each I420 frame before encoding the frame. Can be used for
// effects, snapshots etc. 'NULL' disables the callback.
I420FrameCallback* pre_encode_callback;
// Called for each encoded frame, e.g. used for file storage. 'NULL' disables
// the callback.
EncodedFrameObserver* encoded_callback;
// Renderer for local preview. The local renderer will be called even if
// sending hasn't started. 'NULL' disables local rendering.
VideoRenderer* local_renderer;
// Expected delay needed by the renderer, i.e. the frame will be delivered
// this many milliseconds, if possible, earlier than expected render time.
// Only valid if |renderer| is set.
int render_delay_ms;
// TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
// External encoding. 'encoder' is the external encoder instance and
// 'internal_source' is set to true if the encoder also captures the video
// frames.
VideoEncoder* encoder;
bool internal_source;
// Target delay in milliseconds. A positive value indicates this stream is
// used for streaming instead of a real-time call.
int target_delay_ms;
// Set to resume a previously destroyed send stream.
SendStreamState* start_state;
};
class VideoSendStream {
public:
struct Stats {
Stats()
: input_frame_rate(0),
encode_frame(0),
key_frames(0),
delta_frames(0),
video_packets(0),
retransmitted_packets(0),
fec_packets(0),
padding_packets(0),
send_bitrate_bps(0),
delay_ms(0) {}
RtpStatistics rtp;
int input_frame_rate;
int encode_frame;
uint32_t key_frames;
uint32_t delta_frames;
uint32_t video_packets;
uint32_t retransmitted_packets;
uint32_t fec_packets;
uint32_t padding_packets;
int32_t send_bitrate_bps;
int delay_ms;
};
class StatsCallback {
public:
virtual ~StatsCallback() {}
virtual void ReceiveStats(const std::vector<Stats>& stats) = 0;
};
struct Config {
Config()
: pre_encode_callback(NULL),
encoded_callback(NULL),
local_renderer(NULL),
render_delay_ms(0),
encoder(NULL),
internal_source(false),
target_delay_ms(0),
stats_callback(NULL),
start_state(NULL) {}
VideoCodec codec;
struct Rtp {
Rtp()
: mode(kRtcpReducedSize),
max_packet_size(0),
nack(NULL),
fec(NULL),
rtx(NULL) {}
RtcpMode mode;
std::vector<uint32_t> ssrcs;
// Max RTP packet size delivered to send transport from VideoEngine.
size_t max_packet_size;
// RTP header extensions to use for this send stream.
std::vector<RtpExtension> extensions;
// See NackConfig for description.
NackConfig nack;
// See FecConfig for description.
FecConfig fec;
// See RtxConfig for description.
RtxConfig rtx;
// RTCP CNAME, see RFC 3550.
std::string c_name;
} rtp;
// Called for each I420 frame before encoding the frame. Can be used for
// effects, snapshots etc. 'NULL' disables the callback.
I420FrameCallback* pre_encode_callback;
// Called for each encoded frame, e.g. used for file storage. 'NULL'
// disables the callback.
EncodedFrameObserver* encoded_callback;
// Renderer for local preview. The local renderer will be called even if
// sending hasn't started. 'NULL' disables local rendering.
VideoRenderer* local_renderer;
// Expected delay needed by the renderer, i.e. the frame will be delivered
// this many milliseconds, if possible, earlier than expected render time.
// Only valid if |renderer| is set.
int render_delay_ms;
// TODO(mflodman) Move VideoEncoder to common_types.h and redefine.
// External encoding. 'encoder' is the external encoder instance and
// 'internal_source' is set to true if the encoder also captures the video
// frames.
VideoEncoder* encoder;
bool internal_source;
// Target delay in milliseconds. A positive value indicates this stream is
// used for streaming instead of a real-time call.
int target_delay_ms;
// Callback for periodically receiving send stats.
StatsCallback* stats_callback;
// Set to resume a previously destroyed send stream.
SendStreamState* start_state;
};
// Gets interface used to insert captured frames. Valid as long as the
// VideoSendStream is valid.
virtual VideoSendStreamInput* Input() = 0;
@ -150,9 +157,6 @@ class VideoSendStream {
virtual void StartSend() = 0;
virtual void StopSend() = 0;
// Gets the current statistics for the send stream.
virtual void GetSendStatistics(std::vector<SendStatistics>* statistics) = 0;
// TODO(mflodman) Change VideoCodec struct and use here.
virtual bool SetTargetBitrate(
int min_bitrate, int max_bitrate,

View File

@ -20,7 +20,7 @@
namespace webrtc {
namespace test {
void GenerateRandomSsrcs(newapi::VideoSendStreamConfig* config,
void GenerateRandomSsrcs(newapi::VideoSendStream::Config* config,
std::map<uint32_t, bool>* reserved_ssrcs) {
size_t num_ssrcs = config->codec.numberOfSimulcastStreams;
std::vector<uint32_t>* ssrcs = &config->rtp.ssrcs;

View File

@ -45,8 +45,7 @@ TEST_F(LoopbackTest, Test) {
// Loopback, call sends to itself.
transport.SetReceiver(call->Receiver());
newapi::VideoSendStreamConfig send_config;
call->GetDefaultSendConfig(&send_config);
newapi::VideoSendStream::Config send_config = call->GetDefaultSendConfig();
test::GenerateRandomSsrcs(&send_config, &reserved_ssrcs);
send_config.local_renderer = local_preview;
@ -73,8 +72,8 @@ TEST_F(LoopbackTest, Test) {
test::flags::Fps(),
test_clock);
newapi::VideoReceiveStreamConfig receive_config;
call->GetDefaultReceiveConfig(&receive_config);
newapi::VideoReceiveStream::Config receive_config =
call->GetDefaultReceiveConfig();
receive_config.rtp.ssrc = send_config.rtp.ssrcs[0];
receive_config.renderer = loopback_video;