VoIP interface headers in api/voip directory. This separates the implementation that will come in audio/voip.

Bug: webrtc:11251
Change-Id: I26b6915d3ad6bb5a50f9898a6866889867fd53f5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169000
Commit-Queue: Tim Na <natim@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30594}
This commit is contained in:
Tim Na 2020-02-21 11:09:08 -08:00 committed by Commit Bot
parent 49734dc0fa
commit c63bf10790
5 changed files with 277 additions and 0 deletions

23
api/voip/BUILD.gn Normal file
View File

@ -0,0 +1,23 @@
#Copyright(c) 2020 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.
import("../../webrtc.gni")
rtc_source_set("voip_api") {
visibility = [ "*" ]
sources = [
"voip_base.h",
"voip_codec.h",
"voip_engine.h",
"voip_network.h",
]
deps = [
"..:transport_api",
"../audio_codecs:audio_codecs_api",
]
}

81
api/voip/voip_base.h Normal file
View File

@ -0,0 +1,81 @@
//
// Copyright (c) 2020 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 API_VOIP_VOIP_BASE_H_
#define API_VOIP_VOIP_BASE_H_
#include "api/call/transport.h"
namespace webrtc {
// VoipBase interface
//
// VoipBase provides a management interface on a media session using a
// concept called 'channel'. A channel represents an interface handle
// for application to request various media session operations. This
// notion of channel is used throughout other interfaces as well.
//
// Underneath the interface, a channel handle is mapped into an audio session
// object that is capable of sending and receiving a single RTP stream with
// another media endpoint. It's possible to create and use multiple active
// channels simultaneously which would mean that particular application
// session has RTP streams with multiple remote endpoints.
//
// A typical example for the usage context is outlined in VoipEngine
// header file.
class VoipBase {
public:
// This config enables application to set webrtc::Transport callback pointer
// to receive rtp/rtcp packets from corresponding media session in VoIP
// engine. VoipEngine framework expects applications to handle network I/O
// directly and injection for incoming RTP from remote endpoint is handled
// via VoipNetwork interface.
struct Config {
Transport* transport = nullptr;
uint32_t local_ssrc = 0;
};
// Create a channel handle.
// Valid handle value is zero or greater integer whereas -1 represents error
// during media session construction. Each channel handle maps into one
// audio media session where each has its own separate module for
// send/receive rtp packet with one peer.
virtual int CreateChannel(const Config& config) = 0;
// Following methods return boolean to indicate if the operation is succeeded.
// API is subject to expand to reflect error condition to application later.
// Release |channel| that has served the purpose.
// Released channel handle will be re-allocated again. Invoking
// an operation on released channel will lead to undefined behavior.
virtual bool ReleaseChannel(int channel) = 0;
// Start sending on |channel|. This will start microphone if first to start.
virtual bool StartSend(int channel) = 0;
// Stop sending on |channel|. If this is the last active channel, it will
// stop microphone input from underlying audio platform layer.
virtual bool StopSend(int channel) = 0;
// Start playing on speaker device for |channel|.
// This will start underlying platform speaker device if not started.
virtual bool StartPlayout(int channel) = 0;
// Stop playing on speaker device for |channel|. If this is the last
// active channel playing, then it will stop speaker from the platform layer.
virtual bool StopPlayout(int channel) = 0;
protected:
virtual ~VoipBase() = default;
};
} // namespace webrtc
#endif // API_VOIP_VOIP_BASE_H_

49
api/voip/voip_codec.h Normal file
View File

@ -0,0 +1,49 @@
//
// Copyright (c) 2020 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 API_VOIP_VOIP_CODEC_H_
#define API_VOIP_VOIP_CODEC_H_
#include <map>
#include "api/audio_codecs/audio_format.h"
namespace webrtc {
// VoipCodec interface currently provides any codec related interface
// such as setting encoder and decoder types that are negotiated with
// remote endpoint. Typically after SDP offer and answer exchange,
// the local endpoint understands what are the codec payload types that
// are used with negotiated codecs. This interface is subject to expand
// as needed in future.
//
// This interface requires a channel handle created via VoipBase interface.
class VoipCodec {
public:
// Set encoder type here along with its payload type to use.
virtual bool SetSendCodec(int channel,
int payload_type,
const SdpAudioFormat& encoder_spec) = 0;
// Set decoder payload type here. In typical offer and answer model,
// this should be called after payload type has been agreed in media
// session. Note that payload type can differ with same codec in each
// direction.
virtual bool SetReceiveCodecs(
int channel,
const std::map<int, SdpAudioFormat>& decoder_specs) = 0;
protected:
virtual ~VoipCodec() = default;
};
} // namespace webrtc
#endif // API_VOIP_VOIP_CODEC_H_

79
api/voip/voip_engine.h Normal file
View File

@ -0,0 +1,79 @@
//
// Copyright (c) 2020 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 API_VOIP_VOIP_ENGINE_H_
#define API_VOIP_VOIP_ENGINE_H_
#include <memory>
#include "api/voip/voip_base.h"
#include "api/voip/voip_codec.h"
#include "api/voip/voip_network.h"
namespace webrtc {
// VoipEngine interfaces
//
// These pointer interfaces are valid as long as VoipEngine is available.
// Therefore, application must synchronize the usage within the life span of
// created VoipEngine instance.
//
// auto voip_engine =
// webrtc::VoipEngineBuilder()
// .SetAudioEncoderFactory(CreateBuiltinAudioEncoderFactory())
// .SetAudioDecoderFactory(CreateBuiltinAudioDecoderFactory())
// .Create();
//
// auto* voip_base = voip_engine->Base();
// auto* voip_codec = voip_engine->Codec();
// auto* voip_network = voip_engine->Network();
//
// VoipChannel::Config config = { &app_transport_, 0xdeadc0de };
// int channel = voip_base->CreateChannel(config);
//
// // After SDP offer/answer, payload type and codec usage have been
// // decided through negotiation.
// voip_codec->SetSendCodec(channel, ...);
// voip_codec->SetReceiveCodecs(channel, ...);
//
// // Start Send/Playout on voip channel.
// voip_base->StartSend(channel);
// voip_base->StartPlayout(channel);
//
// // Inject received rtp/rtcp thru voip network interface.
// voip_network->ReceivedRTPPacket(channel, rtp_data, rtp_size);
// voip_network->ReceivedRTCPPacket(channel, rtcp_data, rtcp_size);
//
// // Stop and release voip channel.
// voip_base->StopSend(channel);
// voip_base->StopPlayout(channel);
//
// voip_base->ReleaseChannel(channel);
//
class VoipEngine {
public:
// VoipBase is the audio session management interface that
// create/release/start/stop one-to-one audio media session.
virtual VoipBase* Base() = 0;
// VoipNetwork provides injection APIs that would enable application
// to send and receive RTP/RTCP packets. There is no default network module
// that provides RTP transmission and reception.
virtual VoipNetwork* Network() = 0;
// VoipCodec provides codec configuration APIs for encoder and decoders.
virtual VoipCodec* Codec() = 0;
virtual ~VoipEngine() = default;
};
} // namespace webrtc
#endif // API_VOIP_VOIP_ENGINE_H_

45
api/voip/voip_network.h Normal file
View File

@ -0,0 +1,45 @@
//
// Copyright (c) 2020 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 API_VOIP_VOIP_NETWORK_H_
#define API_VOIP_VOIP_NETWORK_H_
#include "api/call/transport.h"
namespace webrtc {
// VoipNetwork interface currently provides any network related interface
// such as processing received RTP/RTCP packet from remote endpoint.
// The interface subject to expand as needed.
//
// This interface requires a channel handle created via VoipBase interface.
class VoipNetwork {
public:
// The packets received from the network should be passed to this
// function. Note that the data including the RTP-header must also be
// given to the VoipEngine.
virtual bool ReceivedRTPPacket(int channel,
const uint8_t* data,
size_t length) = 0;
// The packets received from the network should be passed to this
// function. Note that the data including the RTCP-header must also be
// given to the VoipEngine.
virtual bool ReceivedRTCPPacket(int channel,
const uint8_t* data,
size_t length) = 0;
protected:
virtual ~VoipNetwork() = default;
};
} // namespace webrtc
#endif // API_VOIP_VOIP_NETWORK_H_