提交 af65f7a2 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

PipeTransport: add enableRtx setting

- Add enableRtx boolean into PipeTransportOptions.
- If set to true (defaults to false) in both PipeTransports and there is
  packet lost, NACK and RTX will happen.
- Useful if both Routers are located in different hosts and there is
  packet lost in the link.
上级 aea159eb
...@@ -35,6 +35,13 @@ export interface PipeTransportOptions ...@@ -35,6 +35,13 @@ export interface PipeTransportOptions
*/ */
maxSctpMessageSize?: number; maxSctpMessageSize?: number;
/**
* Enable RTX and NACK for RTP retransmission. Useful if both Routers are
* located in different hosts and there is packet lost in the link. For this
* to work, both PipeTransports must enable this setting. Default false.
*/
enableRtx?: boolean;
/** /**
* Custom application data. * Custom application data.
*/ */
...@@ -90,6 +97,9 @@ export class PipeTransport extends Transport ...@@ -90,6 +97,9 @@ export class PipeTransport extends Transport
// - .maxMessageSize // - .maxMessageSize
// - .sctpState // - .sctpState
// Custom app data.
private readonly _enableRtx: boolean;
/** /**
* @private * @private
* @emits sctpstatechange - (sctpState: SctpState) * @emits sctpstatechange - (sctpState: SctpState)
...@@ -101,7 +111,7 @@ export class PipeTransport extends Transport ...@@ -101,7 +111,7 @@ export class PipeTransport extends Transport
logger.debug('constructor()'); logger.debug('constructor()');
const { data } = params; const { data, enableRtx } = params;
this._data = this._data =
{ {
...@@ -110,6 +120,8 @@ export class PipeTransport extends Transport ...@@ -110,6 +120,8 @@ export class PipeTransport extends Transport
sctpState : data.sctpState sctpState : data.sctpState
}; };
this._enableRtx = enableRtx;
this._handleWorkerNotifications(); this._handleWorkerNotifications();
} }
...@@ -246,8 +258,8 @@ export class PipeTransport extends Transport ...@@ -246,8 +258,8 @@ export class PipeTransport extends Transport
throw Error(`Producer with id "${producerId}" not found`); throw Error(`Producer with id "${producerId}" not found`);
// This may throw. // This may throw.
const rtpParameters = const rtpParameters = ortc.getPipeConsumerRtpParameters(
ortc.getPipeConsumerRtpParameters(producer.consumableRtpParameters); producer.consumableRtpParameters, this._enableRtx);
const internal = { ...this._internal, consumerId: uuidv4(), producerId }; const internal = { ...this._internal, consumerId: uuidv4(), producerId };
const reqData = const reqData =
......
...@@ -501,6 +501,7 @@ export class Router extends EnhancedEventEmitter ...@@ -501,6 +501,7 @@ export class Router extends EnhancedEventEmitter
enableSctp = false, enableSctp = false,
numSctpStreams = { OS: 1024, MIS: 1024 }, numSctpStreams = { OS: 1024, MIS: 1024 },
maxSctpMessageSize = 1073741823, maxSctpMessageSize = 1073741823,
enableRtx = false,
appData = {} appData = {}
}: PipeTransportOptions }: PipeTransportOptions
): Promise<PipeTransport> ): Promise<PipeTransport>
...@@ -547,6 +548,7 @@ export class Router extends EnhancedEventEmitter ...@@ -547,6 +548,7 @@ export class Router extends EnhancedEventEmitter
data, data,
channel : this._channel, channel : this._channel,
appData, appData,
enableRtx,
getRouterRtpCapabilities : (): RtpCapabilities => this._data.rtpCapabilities, getRouterRtpCapabilities : (): RtpCapabilities => this._data.rtpCapabilities,
getProducerById : (producerId: string): Producer => ( getProducerById : (producerId: string): Producer => (
this._producers.get(producerId) this._producers.get(producerId)
......
...@@ -1049,11 +1049,12 @@ export function getConsumerRtpParameters( ...@@ -1049,11 +1049,12 @@ export function getConsumerRtpParameters(
/** /**
* Generate RTP parameters for a pipe Consumer. * Generate RTP parameters for a pipe Consumer.
* *
* It keeps all original consumable encodings, removes RTX support and also * It keeps all original consumable encodings and removes support for BWE. If
* other features such as NACK. * enableRtx is false, it also removes RTX and NACK support.
*/ */
export function getPipeConsumerRtpParameters( export function getPipeConsumerRtpParameters(
consumableParams: RtpParameters consumableParams: RtpParameters,
enableRtx = false
): RtpParameters ): RtpParameters
{ {
const consumerParams: RtpParameters = const consumerParams: RtpParameters =
...@@ -1069,15 +1070,14 @@ export function getPipeConsumerRtpParameters( ...@@ -1069,15 +1070,14 @@ export function getPipeConsumerRtpParameters(
for (const codec of consumableCodecs) for (const codec of consumableCodecs)
{ {
if (isRtxCodec(codec)) if (!enableRtx && isRtxCodec(codec))
continue; continue;
// No support for NACK, PLI, FIR and RTX in PipeTransport.
// Reduce RTCP feedbacks by removing NACK support and other features.
codec.rtcpFeedback = codec.rtcpFeedback codec.rtcpFeedback = codec.rtcpFeedback
.filter((fb) => ( .filter((fb) => (
(fb.type === 'nack' && fb.parameter === 'pli') || (fb.type === 'nack' && fb.parameter === 'pli') ||
(fb.type === 'ccm' && fb.parameter === 'fir') (fb.type === 'ccm' && fb.parameter === 'fir') ||
(enableRtx && fb.type === 'nack' && !fb.parameter)
)); ));
consumerParams.codecs.push(codec); consumerParams.codecs.push(codec);
...@@ -1093,10 +1093,10 @@ export function getPipeConsumerRtpParameters( ...@@ -1093,10 +1093,10 @@ export function getPipeConsumerRtpParameters(
const consumableEncodings = const consumableEncodings =
utils.clone(consumableParams.encodings) as RtpEncodingParameters[]; utils.clone(consumableParams.encodings) as RtpEncodingParameters[];
// No support for NACK, PLI, FIR and RTX in PipeTransport.
for (const encoding of consumableEncodings) for (const encoding of consumableEncodings)
{ {
delete encoding.rtx; if (!enableRtx)
delete encoding.rtx;
consumerParams.encodings.push(encoding); consumerParams.encodings.push(encoding);
} }
......
...@@ -454,6 +454,90 @@ test('router.pipeToRouter() succeeds with video', async () => ...@@ -454,6 +454,90 @@ test('router.pipeToRouter() succeeds with video', async () =>
expect(pipeProducer.paused).toBe(true); expect(pipeProducer.paused).toBe(true);
}, 2000); }, 2000);
test('router.createPipeTransport() with enableRtx succeeds', async () =>
{
const pipeTransport = await router1.createPipeTransport(
{
listenIp : '127.0.0.1',
enableRtx : true
});
const pipeConsumer =
await pipeTransport.consume({ producerId: videoProducer.id });
expect(pipeConsumer.id).toBeType('string');
expect(pipeConsumer.closed).toBe(false);
expect(pipeConsumer.kind).toBe('video');
expect(pipeConsumer.rtpParameters).toBeType('object');
expect(pipeConsumer.rtpParameters.mid).toBe(undefined);
expect(pipeConsumer.rtpParameters.codecs).toEqual(
[
{
mimeType : 'video/VP8',
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters : {},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' }
]
},
{
mimeType : 'video/rtx',
payloadType : 102,
clockRate : 90000,
channels : 1,
parameters : { apt: 101 },
rtcpFeedback : []
}
]);
expect(pipeConsumer.rtpParameters.headerExtensions).toEqual(
[
// NOTE: Remove this once framemarking draft becomes RFC.
{
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7,
encrypt : false,
parameters : {}
},
{
uri : 'urn:3gpp:video-orientation',
id : 11,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12,
encrypt : false,
parameters : {}
}
]);
expect(pipeConsumer.rtpParameters.encodings).toEqual(
[
videoProducer.consumableRtpParameters.encodings[0],
videoProducer.consumableRtpParameters.encodings[1],
videoProducer.consumableRtpParameters.encodings[2]
]);
expect(pipeConsumer.type).toBe('pipe');
expect(pipeConsumer.paused).toBe(false);
expect(pipeConsumer.producerPaused).toBe(true);
expect(pipeConsumer.score).toEqual({ score: 10, producerScore: 10 });
expect(pipeConsumer.appData).toEqual({});
pipeTransport.close();
}, 2000);
test('transport.consume() for a pipe Producer succeeds', async () => test('transport.consume() for a pipe Producer succeeds', async () =>
{ {
videoConsumer = await transport2.consume( videoConsumer = await transport2.consume(
......
...@@ -318,11 +318,20 @@ namespace RTC ...@@ -318,11 +318,20 @@ namespace RTC
} }
} }
void PipeConsumer::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* /*nackPacket*/) void PipeConsumer::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket)
{ {
MS_TRACE(); MS_TRACE();
// Do nothing since we do not enable NACK. if (!IsActive())
return;
// May emit 'trace' event.
EmitTraceEventNackType();
auto ssrc = nackPacket->GetMediaSsrc();
auto* rtpStream = this->mapMappedSsrcRtpStream.at(ssrc);
rtpStream->ReceiveNack(nackPacket);
} }
void PipeConsumer::ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) void PipeConsumer::ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc)
...@@ -507,9 +516,13 @@ namespace RTC ...@@ -507,9 +516,13 @@ namespace RTC
for (auto& fb : mediaCodec->rtcpFeedback) for (auto& fb : mediaCodec->rtcpFeedback)
{ {
// NOTE: Do not consider NACK in PipeConsumer. if (!params.useNack && fb.type == "nack" && fb.parameter == "")
{
MS_DEBUG_2TAGS(rtp, rtcp, "NACK supported");
if (!params.usePli && fb.type == "nack" && fb.parameter == "pli") params.useNack = true;
}
else if (!params.usePli && fb.type == "nack" && fb.parameter == "pli")
{ {
MS_DEBUG_2TAGS(rtp, rtcp, "PLI supported"); MS_DEBUG_2TAGS(rtp, rtcp, "PLI supported");
...@@ -524,9 +537,8 @@ namespace RTC ...@@ -524,9 +537,8 @@ namespace RTC
} }
// Create a RtpStreamSend for sending a single media stream. // Create a RtpStreamSend for sending a single media stream.
// NOTE: PipeConsumer does not support NACK. size_t bufferSize = params.useNack ? 600u : 0u;
size_t bufferSize{ 0u }; auto* rtpStream = new RTC::RtpStreamSend(this, params, bufferSize);
auto* rtpStream = new RTC::RtpStreamSend(this, params, bufferSize);
// If the Consumer is paused, tell the RtpStreamSend. // If the Consumer is paused, tell the RtpStreamSend.
if (IsPaused() || IsProducerPaused()) if (IsPaused() || IsProducerPaused())
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论