github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/utils/codec.go (about)

     1  package utils
     2  
     3  import (
     4  	"github.com/whoyao/protocol/livekit"
     5  	"github.com/whoyao/protocol/logger"
     6  	"github.com/whoyao/webrtc/v3"
     7  )
     8  
     9  func GetMimeTypeForVideoCodec(codec livekit.VideoCodec) string {
    10  	switch codec {
    11  	case livekit.VideoCodec_H264_BASELINE,
    12  		livekit.VideoCodec_H264_MAIN,
    13  		livekit.VideoCodec_H264_HIGH:
    14  		return webrtc.MimeTypeH264
    15  	case livekit.VideoCodec_VP8:
    16  		return webrtc.MimeTypeVP8
    17  	default:
    18  		logger.Errorw("GetMimeTypeForVideoCodec unimplemented", nil, "codec", codec.String())
    19  		return ""
    20  	}
    21  }
    22  
    23  func GetMimeTypeForAudioCodec(codec livekit.AudioCodec) string {
    24  	// AAC is not supported in webrtc
    25  
    26  	switch codec {
    27  	case livekit.AudioCodec_OPUS:
    28  		return webrtc.MimeTypeOpus
    29  	default:
    30  		logger.Errorw("GetMimeTypeForAudioCodec unimplemented", nil, "codec", codec.String())
    31  		return ""
    32  	}
    33  }