New ViE interface.

BUG=1667

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3869 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2013-04-18 12:02:52 +00:00
parent c14b728b71
commit 65f995a3df
4 changed files with 501 additions and 0 deletions

View File

@ -0,0 +1,121 @@
/*
* 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_NEW_INCLUDE_COMMON_H_
#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_COMMON_H_
#include <string>
#include "webrtc/common_types.h"
namespace webrtc {
class I420VideoFrame;
namespace newapi {
struct EncodedFrame;
class I420FrameCallback {
public:
// This function is called with a I420 frame allowing the user to modify the
// frame content.
virtual void FrameCallback(I420VideoFrame* video_frame) = 0;
protected:
virtual ~I420FrameCallback() {}
};
class EncodedFrameObserver {
public:
virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) = 0;
protected:
virtual ~EncodedFrameObserver() {}
};
class VideoRenderer {
public:
// This function should return as soon as possible and not block until it's
// time to render the frame.
// TODO(mflodman) Remove time_to_render_ms when I420VideoFrame contains NTP.
virtual void RenderFrame(const I420VideoFrame& video_frame,
int time_to_render_ms) = 0;
protected:
virtual ~VideoRenderer() {}
};
class Transport {
public:
virtual bool SendRTP(const void* packet, size_t length) = 0;
virtual bool SendRTCP(const void* packet, size_t length) = 0;
protected:
virtual ~Transport() {}
};
struct RtpStatistics {
uint32_t ssrc;
int fraction_loss;
int cumulative_loss;
int extended_max_sequence_number;
std::string c_name;
};
// RTCP mode to use. Compound mode is described by RFC 4585 and reduced sized
// RTCP mode is described by RFC 5506.
enum RtcpMode {
kRtcpCompound,
kRtcpReducedSize
};
// Settings for NACK, see RFC 4585 for details.
struct NackConfig {
// Send side: the time RTP packets are stored for retransmissions.
// Receive side: the time the receiver is prepared to wait for
// retransmissions.
// Set to '0' to disable
int rtp_history_ms;
};
// Settings for forward error correction, see RFC 5109 for details. Set the
// payload types to '-1' to disable.
struct FecConfig {
// Payload type used for ULPFEC packets.
int ulpfec_payload_type;
// Payload type used for RED packets.
int red_payload_type;
};
// Settings for RTP retransmission payload format, see RFC 4588 for details.
struct RtxConfig {
// SSRC to use for the RTX stream, set to '0' for a random generated SSRC.
uint32_t ssrc;
// Payload type to use for the RTX stream.
int rtx_payload_type;
// Original video payload this RTX stream is used for.
int video_payload_type;
};
// RTP header extension to use for the video stream, see RFC 5285.
struct RtpExtension {
// TODO(mflodman) Add API to query supported extensions.
std::string name;
int id;
};
} // namespace newapi
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_COMMON_H_

View File

@ -0,0 +1,104 @@
/*
* 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_NEW_INCLUDE_VIDEO_ENGINE_H_
#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_ENGINE_H_
#include <string>
#include <vector>
#include "webrtc/common_types.h"
#include "webrtc/video_engine/new_include/common.h"
#include "webrtc/video_engine/new_include/video_receive_stream.h"
#include "webrtc/video_engine/new_include/video_send_stream.h"
namespace webrtc {
namespace newapi {
class VoiceEngine;
const char* Version();
class PacketReceiver {
public:
virtual bool DeliverPacket(const void* packet, size_t length) = 0;
protected:
virtual ~PacketReceiver() {}
};
struct VideoEngineConfig {
VideoEngineConfig()
: voice_engine(NULL), trace_callback(NULL), trace_filter(kTraceNone) {}
// VoiceEngine used for audio/video synchronization for this VideoEngine.
VoiceEngine* voice_engine;
TraceCallback* trace_callback;
uint32_t trace_filter;
};
// A VideoCall instance can contain several send and/or receive streams. All
// streams are assumed to have the same remote endpoint and will share bitrate
// estimates etc.
class VideoCall {
public:
virtual void GetVideoCodecs(std::vector<VideoCodec>* codecs) = 0;
virtual void GetDefaultSendConfig(VideoSendStreamConfig* config) = 0;
virtual VideoSendStream* CreateSendStream(
const VideoSendStreamConfig& 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* CreateReceiveStream(
const VideoReceiveStreamConfig& config) = 0;
virtual void DestroyReceiveStream(VideoReceiveStream* receive_stream) = 0;
// All received RTP and RTCP packets for the call should be inserted to this
// PacketReceiver. The PacketReceiver pointer is valid as long as the
// VideoCall instance exists.
virtual PacketReceiver* Receiver() = 0;
// Returns the estimated total send bandwidth. Note: this can differ from the
// actual encoded bitrate.
virtual uint32_t SendBitrateEstimate() = 0;
// Returns the total estimated receive bandwidth for the call. Note: this can
// differ from the actual receive bitrate.
virtual uint32_t ReceiveBitrateEstimate() = 0;
protected:
virtual ~VideoCall() {}
};
// VideoEngine is the main class and there is only one instance serving several
// calls.
class VideoEngine {
public:
static VideoEngine* Create(const VideoEngineConfig& engine_config);
virtual VideoCall* CreateCall(Transport* send_transport) = 0;
protected:
virtual ~VideoEngine() {}
};
} // namespace newapi
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_ENGINE_H_

View File

@ -0,0 +1,134 @@
/*
* 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_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_
#include <string>
#include <vector>
#include "webrtc/common_types.h"
#include "webrtc/video_engine/new_include/common.h"
namespace webrtc {
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 {
// 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 {
// The actual decoder.
VideoDecoder* decoder;
// Received RTP packets with this payload type will be sent to this decoder
// instance.
int payload_type;
// 'true' if the decoder handles rendering as well.
bool renderer;
// The expected delay for decoding and rendering, i.e. the frame will be
// delivered this many milliseconds, if possible, earlier than the ideal
// render time.
// Note: Ignored if 'renderer' is false.
int expected_delay_ms;
};
struct VideoReceiveStreamConfig {
// 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:
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() {}
};
} // namespace newapi
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_RECEIVE_STREAM_H_

View File

@ -0,0 +1,142 @@
/*
* 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_NEW_INCLUDE_VIDEO_SEND_STREAM_H_
#define WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_
#include <string>
#include <vector>
#include "webrtc/common_types.h"
#include "webrtc/video_engine/new_include/common.h"
namespace webrtc {
class VideoEncoder;
namespace newapi {
struct SendStreamState;
struct SendStatistics {
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:
// 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;
protected:
virtual ~VideoSendStreamInput() {}
};
struct RtpSendConfig {
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 {
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:
// Gets interface used to insert captured frames. Valid as long as the
// VideoSendStream is valid.
virtual VideoSendStreamInput* Input() = 0;
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,
const std::vector<SimulcastStream>& streams) = 0;
virtual void GetSendCodec(VideoCodec* send_codec) = 0;
protected:
virtual ~VideoSendStream() {}
};
} // namespace newapi
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_NEW_INCLUDE_VIDEO_SEND_STREAM_H_