11use crate :: { PcmBuf , Sample } ;
22pub mod g722;
3+ #[ cfg( feature = "opus" ) ]
4+ pub mod opus;
35pub mod pcma;
46pub mod pcmu;
57pub mod resample;
@@ -11,6 +13,8 @@ pub enum CodecType {
1113 PCMU ,
1214 PCMA ,
1315 G722 ,
16+ #[ cfg( feature = "opus" ) ]
17+ Opus ,
1418 TelephoneEvent ,
1519}
1620
@@ -41,6 +45,8 @@ pub fn create_decoder(codec: CodecType) -> Box<dyn Decoder> {
4145 CodecType :: PCMU => Box :: new ( pcmu:: PcmuDecoder :: new ( ) ) ,
4246 CodecType :: PCMA => Box :: new ( pcma:: PcmaDecoder :: new ( ) ) ,
4347 CodecType :: G722 => Box :: new ( g722:: G722Decoder :: new ( ) ) ,
48+ #[ cfg( feature = "opus" ) ]
49+ CodecType :: Opus => Box :: new ( opus:: OpusDecoder :: new_default ( ) ) ,
4450 CodecType :: TelephoneEvent => Box :: new ( telephone_event:: TelephoneEventDecoder :: new ( ) ) ,
4551 }
4652}
@@ -50,6 +56,8 @@ pub fn create_encoder(codec: CodecType) -> Box<dyn Encoder> {
5056 CodecType :: PCMU => Box :: new ( pcmu:: PcmuEncoder :: new ( ) ) ,
5157 CodecType :: PCMA => Box :: new ( pcma:: PcmaEncoder :: new ( ) ) ,
5258 CodecType :: G722 => Box :: new ( g722:: G722Encoder :: new ( ) ) ,
59+ #[ cfg( feature = "opus" ) ]
60+ CodecType :: Opus => Box :: new ( opus:: OpusEncoder :: new_default ( ) ) ,
5361 CodecType :: TelephoneEvent => Box :: new ( telephone_event:: TelephoneEventEncoder :: new ( ) ) ,
5462 }
5563}
@@ -60,6 +68,8 @@ impl CodecType {
6068 CodecType :: PCMU => "audio/PCMU" ,
6169 CodecType :: PCMA => "audio/PCMA" ,
6270 CodecType :: G722 => "audio/G722" ,
71+ #[ cfg( feature = "opus" ) ]
72+ CodecType :: Opus => "audio/opus" ,
6373 CodecType :: TelephoneEvent => "audio/telephone-event" ,
6474 }
6575 }
@@ -68,6 +78,8 @@ impl CodecType {
6878 CodecType :: PCMU => "PCMU/8000" ,
6979 CodecType :: PCMA => "PCMA/8000" ,
7080 CodecType :: G722 => "G722/16000" ,
81+ #[ cfg( feature = "opus" ) ]
82+ CodecType :: Opus => "opus/48000" ,
7183 CodecType :: TelephoneEvent => "telephone-event/8000" ,
7284 }
7385 }
@@ -77,6 +89,8 @@ impl CodecType {
7789 CodecType :: PCMU => 8000 ,
7890 CodecType :: PCMA => 8000 ,
7991 CodecType :: G722 => 8000 ,
92+ #[ cfg( feature = "opus" ) ]
93+ CodecType :: Opus => 48000 ,
8094 CodecType :: TelephoneEvent => 8000 ,
8195 }
8296 }
@@ -85,6 +99,7 @@ impl CodecType {
8599 CodecType :: PCMU => 0 ,
86100 CodecType :: PCMA => 8 ,
87101 CodecType :: G722 => 9 ,
102+ CodecType :: Opus => 111 , // Dynamic payload type
88103 CodecType :: TelephoneEvent => 101 ,
89104 }
90105 }
@@ -93,12 +108,16 @@ impl CodecType {
93108 CodecType :: PCMU => 8000 ,
94109 CodecType :: PCMA => 8000 ,
95110 CodecType :: G722 => 16000 ,
111+ #[ cfg( feature = "opus" ) ]
112+ CodecType :: Opus => 48000 ,
96113 CodecType :: TelephoneEvent => 8000 ,
97114 }
98115 }
99116 pub fn is_audio ( & self ) -> bool {
100117 match self {
101118 CodecType :: PCMU | CodecType :: PCMA | CodecType :: G722 => true ,
119+ #[ cfg( feature = "opus" ) ]
120+ CodecType :: Opus => true ,
102121 _ => false ,
103122 }
104123 }
@@ -112,6 +131,8 @@ impl TryFrom<&String> for CodecType {
112131 "0" => Ok ( CodecType :: PCMU ) ,
113132 "8" => Ok ( CodecType :: PCMA ) ,
114133 "9" => Ok ( CodecType :: G722 ) ,
134+ #[ cfg( feature = "opus" ) ]
135+ "111" => Ok ( CodecType :: Opus ) , // Dynamic payload type
115136 "101" => Ok ( CodecType :: TelephoneEvent ) ,
116137 _ => Err ( anyhow:: anyhow!( "Invalid codec type: {}" , value) ) ,
117138 }
0 commit comments