MLVBLiveRoom
component to help you quickly implement the mic connect feature. To better cater to your mic connect needs, Tencent Cloud has launched an RTC-based mic connect scheme and offered simpler and more flexible V2 APIs.Item | RTMP | RTC |
Protocol | Based on TCP | Based on UDP (more suitable for streaming) |
QoS | Poor adaptability to bad network connection | Video streaming unaffected with 50% packets loss; audio mic connect unaffected with 70% packets loss |
Region | Chinese mainland | Worldwide |
Tencent Cloud products used | MLVB, CSS | MLVB, CSS, TRTC |
Price | 0.0028 USD/min |
V2TXLivePusher
(publishing) and V2TXLivePlayer
(playback) to power larger-scale live streaming scenarios with greater flexibility and lower latency. Hosts can use the capabilities provided by the APIs for RTC-based publishing. Audience, by default, play streams via CDNs, whose cost is relatively low. To connect mic with hosts, audience can switch to RTC-based playback, which has lower latency and guarantees better interactive experience. To enable RTC-based mic connect, you must activate TRTC.
Below are the UI views of the MLVB-API-Example demo.Host (Phone A) | Mic-connecting audience (Phone B) | Audience (Phone C) |
| | |
Host (Phone A) | Mic-connecting audience (Phone B) | Audience (Phone C) |
| | |
trtc://
protocol and switch from CDN playback to the ultra-low-latency trtc://
protocol.V2TXLivePusher
to publish a stream. For how to splice a publishing URL, please see Publish/Playback URL.V2TXLivePusher pusher = new V2TXLivePusherImpl(this, V2TXLiveMode.TXLiveMode_RTC);pushURLA= "trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=A&usersig=xxx";pusher.startPush(pushURLA);
V2TXLivePusher *pusher = [[V2TXLivePusher alloc] initWithLiveMode:V2TXLiveMode_RTC];NSString *pushURLA = @"trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=A&usersig=xxx";[pusher startPush:pushURLA];
V2TXLivePlayer
to play user A’s stream. For how to splice a playback URL, please see Publish/Playback URL.V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);/*** Streams are played via CDNs in the example. The protocols supported include FLV, HLS, and WebRTC. Standard protocols such as FLV and HLS are more cost-effective, but WebRTC delivers interactive experience with lower latency.* playURLA= "http://3891.liveplay.myqcloud.com/live/streamidA.flv";* playURLA= "http://3891.liveplay.myqcloud.com/live/streamidA.hls";* playURLA= "webrtc://3891.liveplay.myqcloud.com/live/streamidA"*/player.startPlay(playURLA);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];/*** Streams are played via CDNs in the example. The protocols supported include FLV, HLS, and WebRTC. Standard protocols such as FLV and HLS are more cost-effective, but WebRTC delivers interactive experience with lower latency.* NSString *playURLA= @"http://3891.liveplay.myqcloud.com/live/streamidA.flv";* NSString *playURLA= @"http://3891.liveplay.myqcloud.com/live/streamidA.hls";* NSString *playURLA= @"webrtc://3891.liveplay.myqcloud.com/live/streamidA"*/[player setRenderView:view];[player startPlay:playURLA];
V2TXLivePusher
to publish streams.V2TXLivePusher pusher = new V2TXLivePusherImpl(this,V2TXLiveMode.TXLiveMode_RTC);pushURLB= "trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=B&usersig=xxx";pusher.startPush(pushURLB);
V2TXLivePusher *pusher = [[V2TXLivePusher alloc] initWithLiveMode:V2TXLiveMode_RTC];NSString *pushURLB = @"trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=B&usersig=xxx";[pusher startPush:pushURLB];
V2TXLivePlayer
to play the stream of the mic-connecting user B via RTC.V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);playURLB= "trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=B&usersig=xxx&appscene=live";player.startPlay(playURLB);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];NSString* playURLB = @"trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=B&usersig=xxx&appscene=live";[player setRenderView:view];[player startPlay:playURLB];
V2TXLivePlayer
to switch to RTC and play user A’s stream.V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);playURLA= "trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=A&usersig=xxx&appscene=live";player.startPlay(playURLA);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];NSString* playURLA = @"trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=A&usersig=xxx&appscene=live";[player setRenderView:view];[player startPlay:playURLA];
setMixTranscodingConfig
API to start On-Cloud MixTranscoding, specifying audio-related parameters including audioSampleRate
, audioBitrate
, and audioChannels
.
If your application involves the transfer of video data, you must also set video-related parameters such as videoWidth
, videoHeight
, videoBitrate
, and videoFramerate
.V2TXLiveDef.V2TXLiveTranscodingConfig config = new V2TXLiveDef.V2TXLiveTranscodingConfig();// Set the resolution to 720 × 1280 px, bitrate 1500 Kbps, and frame rate 20 fpsconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;config.mixStreams = new ArrayList<>();// Position of the camera image of the hostV2TXLiveDef.V2TXLiveMixStream local = new V2TXLiveDef.V2TXLiveMixStream();local.userId = "localUserId";local.streamId = null; // `streamID` is required for the remote user but not for the local userlocal.x = 0;local.y = 0;local.width = videoWidth;local.height = videoHeight;local.zOrder = 0; // When `zOrder` is set to `0`, it indicates that the host’s image is displayed at the bottomconfig.mixStreams.add(local);// Image position of the mic-connecting userV2TXLiveDef.V2TXLiveMixStream remoteA = new V2TXLiveDef.V2TXLiveMixStream();remoteA.userId = "remoteUserIdA";remoteA.streamId = "remoteStreamIdA"; // `streamID` is required for the remote user but not for the local userremoteA.x = 400; // For reference onlyremoteA.y = 800; // For reference onlyremoteA.width = 180; // For reference onlyremoteA.height = 240; // For reference onlyremoteA.zOrder = 1;config.mixStreams.add(remoteA);// Image position of the mic-connecting userV2TXLiveDef.V2TXLiveMixStream remoteB = new V2TXLiveDef.V2TXLiveMixStream();remoteB.userId = "remoteUserIdB";remoteB.streamId = "remoteStreamIdB"; // `streamID` is required for the remote user but not for the local userremoteB.x = 400; // For reference onlyremoteB.y = 800; // For reference onlyremoteB.width = 180; // For reference onlyremoteB.height = 240; // For reference onlyremoteB.zOrder = 1;config.mixStreams.add(remoteB);// Start On-Cloud MixTranscodingpusher.setMixTranscodingConfig(config);
V2TXLiveTranscodingConfig *config = [[V2TXLiveTranscodingConfig alloc] init];// Set the resolution to 720 × 1280 px, bitrate 1500 Kbps, and frame rate 20 fpsconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;// Position of the camera image of the hostV2TXLiveMixStream *local = [[V2TXLiveMixStream alloc] init];local.userId = @"localUserId";local.streamId = nil; // `streamID` is required for the remote user but not for the local userlocal.x = 0;local.y = 0;local.width = videoWidth;local.height = videoHeight;local.zOrder = 0; // When `zOrder` is set to `0`, it indicates that the host’s image is displayed at the bottom// Image position of the mic-connecting userV2TXLiveMixStream *remoteA = [[V2TXLiveMixStream alloc] init];remoteA.userId = @"remoteUserIdA";remoteA.streamId = @"remoteStreamIdA"; // `streamID` is required for the remote user but not for the local userremoteA.x = 400; // For reference onlyremoteA.y = 800; // For reference onlyremoteA.width = 180; // For reference onlyremoteA.height = 240; // For reference onlyremoteA.zOrder = 1;// Image position of the mic-connecting userV2TXLiveMixStream *remoteB = [[V2TXLiveMixStream alloc] init];remoteB.userId = @"remoteUserIdB";remoteB.streamId = @"remoteStreamIdB"; // `streamID` is required for the remote user but not for the local userremoteB.x = 400; // For reference onlyremoteB.y = 800; // For reference onlyremoteB.width = 180; // For reference onlyremoteB.height = 240; // For reference onlyremoteB.zOrder = 1;// Specify the streams to mixconfig.mixStreams = @[local,remoteA,remoteB];// Start On-Cloud MixTranscodingpusher.setMixTranscodingConfig(config);
streamid
on the same device possible with TXLivePusher
and TXLivePlayer
but not with V2TXLivePusher
and V2TXLivePlayer
?V2TXLivePusher
and V2TXLivePlayer
are based on Tencent Cloud’s TRTC protocol. This is a UDP-based private protocol that features ultra-low latency and does not support using the same streamid
for ultra-low-latency publishing and playback on the same device. We have determined that it’s not necessary to support this given the current use cases, but may consider optimizing the protocol in the future.SDKAppID
identifies your application, and UserID
your user. UserSig
is a security signature calculated based on the two parameters using the HMAC SHA256 encryption algorithm. Attackers cannot use your Tencent Cloud traffic without authorization as long as they cannot forge a UserSig
. UserSig
calculation involves hashing crucial information such as SDKAppID
, UserID
, and ExpireTime
, as shown below.// UserSig formula, in which `secretkey` is the key used to calculate UserSigusersig = hmacsha256(secretkey, (userid + sdkappid + currtime + expire +base64(userid + sdkappid + currtime + expire)))
V2TXLivePusher
and V2TXLivePlayer
?-5
mean?-5
means failure to call an API due to invalid license. The enumerated value is V2TXLIVE_ERROR_INVALID_LICENSE. For other error codes, please see V2TXLiveCode.404
error occurs when I try to play streams via CDNs after successfully publishing streams over RTC?
Was this page helpful?