You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I try to use webrtc and connect to zlmediakit, i got some exception. I wish to get some suggestion
there is some udp package which length is 2144, so i have changed the UdpReceiver :protected const int RECEIVE_BUFFER_SIZE = 1024 * 16 , Then int bytesRead = m_socket.EndReceiveFrom(ar, ref remoteEP); can work well.
But i can't solve the next exception: How can i solve it.
it try to copy this array(len=2144) to a buffer(len=1472)
================
here is my code
using Microsoft.Extensions.Logging;using Microsoft.Extensions.Logging.Abstractions;using Serilog.Extensions.Logging;using Serilog;using SIPSorcery.Media;using SIPSorcery.Net;using SIPSorceryMedia.Abstractions;using WebSocketSharp.Server;using System.Net;using System.Net.Http.Headers;using System.Net.Mime;using Org.BouncyCastle.Asn1.X509;using System.Net.Security;using System.Security.Cryptography.X509Certificates;using System.Text.Json;namespace webrtc1;internalclasspushtest{publicasync Task test(){conststringffmpegLibFullPath=@"D:\d\softnormal\ffmpeg\ffmpeg-master-latest-win64-gpl-shared\bin";// /!\ A valid path to FFmpeg libraryconststringMP4_PATH=@"D:\e\testmedia\trans\t1.mkv";// /!\ A valid path to Video file
Microsoft.Extensions.Logging.ILogger logger= NullLogger.Instance;logger= AddConsoleLogger();// See https://aka.ms/new-console-template for more information
Console.WriteLine("WebRTC MP4 Source Demo");// Start web socket.await InitConnection();// Ctrl-c will gracefully exit the call at any point.ManualResetEventexitMre=new ManualResetEvent(false);
Console.CancelKeyPress +=delegate(objectsender,ConsoleCancelEventArgse){
e.Cancel =true;
exitMre.Set();};// Wait for a signal saying the call failed, was cancelled with ctrl-c or completed.
exitMre.WaitOne();async Task InitConnection(){
SIPSorceryMedia.FFmpeg.FFmpegInit.Initialise(SIPSorceryMedia.FFmpeg.FfmpegLogLevelEnum.AV_LOG_VERBOSE, ffmpegLibFullPath, logger);varmediaFileSource=new SIPSorceryMedia.FFmpeg.FFmpegFileSource(MP4_PATH,false,new AudioEncoder());
mediaFileSource.RestrictFormats(x => x.Codec == VideoCodecsEnum.VP8);//mediaFileSource.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMU);
mediaFileSource.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMU);RTCPeerConnectionpc1=new RTCPeerConnection(new RTCConfiguration(){X_UseRtpFeedbackProfile=true});//设置数据源MediaStreamTrackvideoTrack=new MediaStreamTrack(mediaFileSource.GetVideoSourceFormats(), MediaStreamStatusEnum.SendOnly);
pc1.addTrack(videoTrack);MediaStreamTrackaudioTrack=new MediaStreamTrack(mediaFileSource.GetAudioSourceFormats(), MediaStreamStatusEnum.SendOnly);
pc1.addTrack(audioTrack);//mediaFileSource.OnVideoSourceEncodedSample += pc1.SendVideo;//mediaFileSource.OnAudioSourceEncodedSample += pc1.SendAudio;varoffer= pc1.createOffer();await pc1.setLocalDescription(offer);//发送给远端stringtarget="https://10.219.25.29/index/api/webrtc?app=live&stream=test1&type=push";varhttphandler=new HttpClientHandler();
httphandler.ServerCertificateCustomValidationCallback =(HttpRequestMessagea,X509Certificate2?b,X509Chain?c,SslPolicyErrorsd)=>true;HttpClientclient=new HttpClient(httphandler);StringContentcontent=new StringContent(offer.sdp);
content.Headers.ContentType =new MediaTypeHeaderValue(MediaTypeNames.Text.Plain);varre1=await client.PostAsync(new Uri(target), content);varsend_result= JsonSerializer.Deserialize<SendOfferResult>(await re1.Content.ReadAsStringAsync());
Console.WriteLine($"收到 {JsonSerializer.Serialize(send_result)}");
pc1.setRemoteDescription(new RTCSessionDescriptionInit
{type= RTCSdpType.answer,sdp= send_result.sdp
});
Console.WriteLine("set remote成功");}}
Microsoft.Extensions.Logging.ILogger AddConsoleLogger(){varseriLogger=new LoggerConfiguration().Enrich.FromLogContext().MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug).WriteTo.Console().CreateLogger();varfactory=new SerilogLoggerFactory(seriLogger);
SIPSorcery.LogFactory.Set(factory);return factory.CreateLogger<Program>();}}publicclassSendOfferResult{publicintcode{get;set;}publicstringid{get;set;}publicstringsdp{get;set;}publicstringtype{get;set;}}
The text was updated successfully, but these errors were encountered:
While I try to use webrtc and connect to zlmediakit, i got some exception. I wish to get some suggestion
there is some udp package which length is 2144, so i have changed the
UdpReceiver :protected const int RECEIVE_BUFFER_SIZE = 1024 * 16
, Thenint bytesRead = m_socket.EndReceiveFrom(ar, ref remoteEP);
can work well.But i can't solve the next exception: How can i solve it.
it try to copy this array(len=2144) to a buffer(len=1472)
================
here is my code
The text was updated successfully, but these errors were encountered: