mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-24 12:01:56 -08:00
parent
4aef466103
commit
79ee4e06f3
4 changed files with 35 additions and 6 deletions
|
|
@ -305,6 +305,7 @@ func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) {
|
|||
audioCodec: ctx.Query("audio_codec"),
|
||||
videoBitrate: ctx.Query("video_bitrate"),
|
||||
audioBitrate: ctx.Query("audio_bitrate"),
|
||||
audioVoice: ctx.Query("audio_voice") == "true",
|
||||
})
|
||||
if res.err != nil {
|
||||
if res.errStatusCode != 0 {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ type webRTCSessionNewReq struct {
|
|||
audioCodec string
|
||||
videoBitrate string
|
||||
audioBitrate string
|
||||
audioVoice bool
|
||||
res chan webRTCSessionNewRes
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ select {
|
|||
|
||||
audio bitrate (kbps):
|
||||
<input id="audio_bitrate" type="text" value="32" />
|
||||
|
||||
<div>
|
||||
<input id="audio_voice" type="checkbox" checked>
|
||||
<label for="audio_voice">optimize for voice</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="submit_line">
|
||||
<button id="publish_confirm">publish</button>
|
||||
|
|
@ -226,12 +231,14 @@ class Transmitter {
|
|||
const audioCodec = document.getElementById('audio_codec').value;
|
||||
const videoBitrate = document.getElementById('video_bitrate').value;
|
||||
const audioBitrate = document.getElementById('audio_bitrate').value;
|
||||
const audioVoice = document.getElementById('audio_voice').checked;
|
||||
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
p.set('video_codec', videoCodec);
|
||||
p.set('audio_codec', audioCodec);
|
||||
p.set('video_bitrate', videoBitrate);
|
||||
p.set('audio_bitrate', audioBitrate);
|
||||
p.set('audio_voice', audioVoice ? 'true' : 'false');
|
||||
|
||||
fetch(new URL('whip', window.location.href) + '?' + p.toString(), {
|
||||
method: 'POST',
|
||||
|
|
@ -362,6 +369,13 @@ const onPublish = () => {
|
|||
audio = {
|
||||
deviceId: audioId,
|
||||
};
|
||||
|
||||
const voice = document.getElementById('audio_voice').checked;
|
||||
if (!voice) {
|
||||
audio.autoGainControl = false;
|
||||
audio.echoCancellation = false;
|
||||
audio.noiseSuppression = false;
|
||||
}
|
||||
}
|
||||
|
||||
navigator.mediaDevices.getUserMedia({ video, audio })
|
||||
|
|
|
|||
|
|
@ -61,7 +61,12 @@ func findOpusPayloadFormat(attributes []sdp.Attribute) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func editAnswer(offer *webrtc.SessionDescription, videoBitrateStr string, audioBitrateStr string) error {
|
||||
func editAnswer(
|
||||
offer *webrtc.SessionDescription,
|
||||
videoBitrateStr string,
|
||||
audioBitrateStr string,
|
||||
audioVoice bool,
|
||||
) error {
|
||||
var sd sdp.SessionDescription
|
||||
err := sd.Unmarshal([]byte(offer.SDP))
|
||||
if err != nil {
|
||||
|
|
@ -97,10 +102,18 @@ func editAnswer(offer *webrtc.SessionDescription, videoBitrateStr string, audioB
|
|||
if pl != 0 {
|
||||
for i, attr := range media.Attributes {
|
||||
if attr.Key == "fmtp" && strings.HasPrefix(attr.Value, strconv.FormatInt(int64(pl), 10)+" ") {
|
||||
media.Attributes[i] = sdp.Attribute{
|
||||
Key: "fmtp",
|
||||
Value: strconv.FormatInt(int64(pl), 10) + " stereo=1;sprop-stereo=1;maxaveragebitrate=" +
|
||||
strconv.FormatUint(audioBitrate*1024, 10),
|
||||
if audioVoice {
|
||||
media.Attributes[i] = sdp.Attribute{
|
||||
Key: "fmtp",
|
||||
Value: strconv.FormatInt(int64(pl), 10) + " minptime=10;useinbandfec=1;maxaveragebitrate=" +
|
||||
strconv.FormatUint(audioBitrate*1024, 10),
|
||||
}
|
||||
} else {
|
||||
media.Attributes[i] = sdp.Attribute{
|
||||
Key: "fmtp",
|
||||
Value: strconv.FormatInt(int64(pl), 10) + " stereo=1;sprop-stereo=1;maxaveragebitrate=" +
|
||||
strconv.FormatUint(audioBitrate*1024, 10),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -368,7 +381,7 @@ func (s *webRTCSession) runPublish() (int, error) {
|
|||
tmp := pc.LocalDescription()
|
||||
answer = *tmp
|
||||
|
||||
err = editAnswer(&answer, s.req.videoBitrate, s.req.audioBitrate)
|
||||
err = editAnswer(&answer, s.req.videoBitrate, s.req.audioBitrate, s.req.audioVoice)
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue