提交 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
*/
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.
*/
......@@ -90,6 +97,9 @@ export class PipeTransport extends Transport
// - .maxMessageSize
// - .sctpState
// Custom app data.
private readonly _enableRtx: boolean;
/**
* @private
* @emits sctpstatechange - (sctpState: SctpState)
......@@ -101,7 +111,7 @@ export class PipeTransport extends Transport
logger.debug('constructor()');
const { data } = params;
const { data, enableRtx } = params;
this._data =
{
......@@ -110,6 +120,8 @@ export class PipeTransport extends Transport
sctpState : data.sctpState
};
this._enableRtx = enableRtx;
this._handleWorkerNotifications();
}
......@@ -246,8 +258,8 @@ export class PipeTransport extends Transport
throw Error(`Producer with id "${producerId}" not found`);
// This may throw.
const rtpParameters =
ortc.getPipeConsumerRtpParameters(producer.consumableRtpParameters);
const rtpParameters = ortc.getPipeConsumerRtpParameters(
producer.consumableRtpParameters, this._enableRtx);
const internal = { ...this._internal, consumerId: uuidv4(), producerId };
const reqData =
......
......@@ -501,6 +501,7 @@ export class Router extends EnhancedEventEmitter
enableSctp = false,
numSctpStreams = { OS: 1024, MIS: 1024 },
maxSctpMessageSize = 1073741823,
enableRtx = false,
appData = {}
}: PipeTransportOptions
): Promise<PipeTransport>
......@@ -547,6 +548,7 @@ export class Router extends EnhancedEventEmitter
data,
channel : this._channel,
appData,
enableRtx,
getRouterRtpCapabilities : (): RtpCapabilities => this._data.rtpCapabilities,
getProducerById : (producerId: string): Producer => (
this._producers.get(producerId)
......
......@@ -1049,11 +1049,12 @@ export function getConsumerRtpParameters(
/**
* Generate RTP parameters for a pipe Consumer.
*
* It keeps all original consumable encodings, removes RTX support and also
* other features such as NACK.
* It keeps all original consumable encodings and removes support for BWE. If
* enableRtx is false, it also removes RTX and NACK support.
*/
export function getPipeConsumerRtpParameters(
consumableParams: RtpParameters
consumableParams: RtpParameters,
enableRtx = false
): RtpParameters
{
const consumerParams: RtpParameters =
......@@ -1069,15 +1070,14 @@ export function getPipeConsumerRtpParameters(
for (const codec of consumableCodecs)
{
if (isRtxCodec(codec))
if (!enableRtx && isRtxCodec(codec))
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
.filter((fb) => (
(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);
......@@ -1093,10 +1093,10 @@ export function getPipeConsumerRtpParameters(
const consumableEncodings =
utils.clone(consumableParams.encodings) as RtpEncodingParameters[];
// No support for NACK, PLI, FIR and RTX in PipeTransport.
for (const encoding of consumableEncodings)
{
delete encoding.rtx;
if (!enableRtx)
delete encoding.rtx;
consumerParams.encodings.push(encoding);
}
......
......@@ -454,6 +454,90 @@ test('router.pipeToRouter() succeeds with video', async () =>
expect(pipeProducer.paused).toBe(true);
}, 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 () =>
{
videoConsumer = await transport2.consume(
......
......@@ -318,11 +318,20 @@ namespace RTC
}
}
void PipeConsumer::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* /*nackPacket*/)
void PipeConsumer::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket)
{
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)
......@@ -507,9 +516,13 @@ namespace RTC
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");
......@@ -524,9 +537,8 @@ namespace RTC
}
// Create a RtpStreamSend for sending a single media stream.
// NOTE: PipeConsumer does not support NACK.
size_t bufferSize{ 0u };
auto* rtpStream = new RTC::RtpStreamSend(this, params, bufferSize);
size_t bufferSize = params.useNack ? 600u : 0u;
auto* rtpStream = new RTC::RtpStreamSend(this, params, bufferSize);
// If the Consumer is paused, tell the RtpStreamSend.
if (IsPaused() || IsProducerPaused())
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论