github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/utils/codec.go (about) 1 // Copyright 2023 LiveKit, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package utils 16 17 import ( 18 "github.com/livekit/protocol/livekit" 19 "github.com/livekit/protocol/logger" 20 "github.com/pion/webrtc/v3" 21 ) 22 23 func GetMimeTypeForVideoCodec(codec livekit.VideoCodec) string { 24 switch codec { 25 case livekit.VideoCodec_H264_BASELINE, 26 livekit.VideoCodec_H264_MAIN, 27 livekit.VideoCodec_H264_HIGH: 28 return webrtc.MimeTypeH264 29 case livekit.VideoCodec_VP8: 30 return webrtc.MimeTypeVP8 31 default: 32 logger.Errorw("GetMimeTypeForVideoCodec unimplemented", nil, "codec", codec.String()) 33 return "" 34 } 35 } 36 37 func GetMimeTypeForAudioCodec(codec livekit.AudioCodec) string { 38 // AAC is not supported in webrtc 39 40 switch codec { 41 case livekit.AudioCodec_OPUS: 42 return webrtc.MimeTypeOpus 43 default: 44 logger.Errorw("GetMimeTypeForAudioCodec unimplemented", nil, "codec", codec.String()) 45 return "" 46 } 47 }