mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 21:08:36 +08:00
Current broadcaster details admin api (#206)
* Add support for ending the inbound stream. Closes #191 * Add a simple success response to API requests * Store inbound broadcast details for admin purposes * Add /api/admin/broadcaster endpoint * Reset broadcaster on disconnect * Move controller to admin directory
This commit is contained in:
64
core/rtmp/utils.go
Normal file
64
core/rtmp/utils.go
Normal file
@ -0,0 +1,64 @@
|
||||
package rtmp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/gabek/owncast/models"
|
||||
"github.com/nareix/joy5/format/flv/flvio"
|
||||
)
|
||||
|
||||
func getInboundDetailsFromMetadata(metadata []interface{}) (models.RTMPStreamMetadata, error) {
|
||||
metadataComponentsString := fmt.Sprintf("%+v", metadata)
|
||||
re := regexp.MustCompile(`\{(.*?)\}`)
|
||||
submatchall := re.FindAllString(metadataComponentsString, 1)
|
||||
|
||||
if len(submatchall) == 0 {
|
||||
return models.RTMPStreamMetadata{}, errors.New("unable to parse inbound metadata")
|
||||
}
|
||||
|
||||
metadataJSONString := submatchall[0]
|
||||
var details models.RTMPStreamMetadata
|
||||
json.Unmarshal([]byte(metadataJSONString), &details)
|
||||
return details, nil
|
||||
}
|
||||
|
||||
func getAudioCodec(codec interface{}) string {
|
||||
var codecID float64
|
||||
if assertedCodecID, ok := codec.(float64); ok {
|
||||
codecID = assertedCodecID
|
||||
} else {
|
||||
return codec.(string)
|
||||
}
|
||||
|
||||
switch codecID {
|
||||
case flvio.SOUND_MP3:
|
||||
return "MP3"
|
||||
case flvio.SOUND_AAC:
|
||||
return "AAC"
|
||||
case flvio.SOUND_SPEEX:
|
||||
return "Speex"
|
||||
}
|
||||
|
||||
return "Unknown"
|
||||
}
|
||||
|
||||
func getVideoCodec(codec interface{}) string {
|
||||
var codecID float64
|
||||
if assertedCodecID, ok := codec.(float64); ok {
|
||||
codecID = assertedCodecID
|
||||
} else {
|
||||
return codec.(string)
|
||||
}
|
||||
|
||||
switch codecID {
|
||||
case flvio.VIDEO_H264:
|
||||
return "H.264"
|
||||
case flvio.VIDEO_H265:
|
||||
return "H.265"
|
||||
}
|
||||
|
||||
return "Unknown"
|
||||
}
|
||||
Reference in New Issue
Block a user