MediaDataCodec.cpp (1886B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "MediaDataCodec.h" 6 7 #include "PDMFactory.h" 8 #include "WebrtcGmpVideoCodec.h" 9 #include "WebrtcMediaDataDecoderCodec.h" 10 #include "WebrtcMediaDataEncoderCodec.h" 11 #include "mozilla/StaticPrefs_media.h" 12 13 namespace mozilla { 14 15 /* static */ 16 WebrtcVideoEncoder* MediaDataCodec::CreateEncoder( 17 const webrtc::SdpVideoFormat& aFormat) { 18 if (!WebrtcMediaDataEncoder::CanCreate( 19 webrtc::PayloadStringToCodecType(aFormat.name))) { 20 return nullptr; 21 } 22 23 return new WebrtcVideoEncoderProxy(new WebrtcMediaDataEncoder(aFormat)); 24 } 25 26 /* static */ 27 WebrtcVideoDecoder* MediaDataCodec::CreateDecoder( 28 webrtc::VideoCodecType aCodecType, TrackingId aTrackingId) { 29 switch (aCodecType) { 30 case webrtc::VideoCodecType::kVideoCodecVP8: 31 case webrtc::VideoCodecType::kVideoCodecVP9: 32 if (!StaticPrefs::media_navigator_mediadatadecoder_vpx_enabled()) { 33 return nullptr; 34 } 35 break; 36 case webrtc::VideoCodecType::kVideoCodecH264: 37 if (!StaticPrefs::media_navigator_mediadatadecoder_h264_enabled()) { 38 return nullptr; 39 } 40 break; 41 default: 42 return nullptr; 43 } 44 45 nsAutoCString codec; 46 switch (aCodecType) { 47 case webrtc::VideoCodecType::kVideoCodecVP8: 48 codec = "video/vp8"; 49 break; 50 case webrtc::VideoCodecType::kVideoCodecVP9: 51 codec = "video/vp9"; 52 break; 53 case webrtc::VideoCodecType::kVideoCodecH264: 54 codec = "video/avc"; 55 break; 56 default: 57 return nullptr; 58 } 59 RefPtr<PDMFactory> pdm = new PDMFactory(); 60 if (pdm->SupportsMimeType(codec).isEmpty()) { 61 return nullptr; 62 } 63 64 return new WebrtcMediaDataDecoder(codec, aTrackingId); 65 } 66 67 } // namespace mozilla