@@ -16,6 +16,8 @@ interface Codec
1616 string name { get ; }
1717 string mimeType { get ; }
1818 string sdpFmtpLine { get ; }
19+ int channelCount { get ; }
20+ int sampleRate { get ; }
1921 string optionTitle { get ; }
2022 }
2123
@@ -24,6 +26,8 @@ class AudioCodec : Codec
2426 public string name { get { return codec_ . name ; } }
2527 public string mimeType { get { return codec_ . mimeType ; } }
2628 public string sdpFmtpLine { get { return codec_ . sdpFmtpLine ; } }
29+ public int channelCount { get { return codec_ . channelCount ; } }
30+ public int sampleRate { get { return codec_ . sampleRate ; } }
2731
2832 public string optionTitle
2933 {
@@ -60,6 +64,10 @@ public string optionTitle
6064 return null ;
6165 }
6266 }
67+
68+ public int channelCount { get { throw new NotSupportedException ( ) ; } }
69+ public int sampleRate { get { throw new NotSupportedException ( ) ; } }
70+
6371 public VideoCodec ( VideoCodecInfo codec )
6472 {
6573 codec_ = codec ;
@@ -69,14 +77,17 @@ public VideoCodec(VideoCodecInfo codec)
6977
7078 SerializedProperty propertyMimeType ;
7179 SerializedProperty propertySdpFmtpLine ;
80+ SerializedProperty propertyChannelCount ;
81+ SerializedProperty propertySampleRate ;
82+
7283 IEnumerable < Codec > codecs ;
7384 string [ ] codecNames = new string [ ] { "Default" } ;
7485 string [ ] codecOptions = new string [ ] { } ;
75- string [ ] sdpFmtpLines = new string [ ] { } ;
86+ IEnumerable < Codec > selectedCodecs ;
7687 GUIContent codecLabel ;
7788
7889 int selectCodecIndex = 0 ;
79- int selectSdpFmtpLineIndex = 0 ;
90+ int selectCodecOptionIndex = 0 ;
8091 bool hasCodecOptions = false ;
8192 bool cache = false ;
8293 bool changed = false ;
@@ -120,27 +131,43 @@ static GUIContent GetCodecLabel(UnityEngine.Object target)
120131 throw new ArgumentException ( ) ;
121132 }
122133
134+ int FindOptionIndex ( IEnumerable < Codec > codecs )
135+ {
136+ return Array . FindIndex ( codecs . ToArray ( ) , codec =>
137+ {
138+ if ( codec is VideoCodec )
139+ return codec . sdpFmtpLine == propertySdpFmtpLine . stringValue ;
140+ else
141+ return
142+ codec . sdpFmtpLine == propertySdpFmtpLine . stringValue &&
143+ codec . channelCount == propertyChannelCount . intValue &&
144+ codec . sampleRate == propertySampleRate . intValue ;
145+ } ) ;
146+ }
147+
123148 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
124149 {
125150 if ( ! cache )
126151 {
127152 propertyMimeType = property . FindPropertyInChildren ( "m_MimeType" ) ;
128153 propertySdpFmtpLine = property . FindPropertyInChildren ( "m_SdpFmtpLine" ) ;
154+ propertyChannelCount = property . FindPropertyInChildren ( "m_ChannelCount" ) ;
155+ propertySampleRate = property . FindPropertyInChildren ( "m_SampleRate" ) ;
156+
129157 codecs = GetAvailableCodecs ( property . serializedObject . targetObject ) ;
130158 codecNames = codecNames . Concat ( codecs . Select ( codec => codec . name ) ) . Distinct ( ) . ToArray ( ) ;
131159 var mimeType = propertyMimeType . stringValue ;
132160 var codecName = mimeType . GetCodecName ( ) ;
133- var selectedCodecs = codecs . Where ( codec => codec . name == codecName ) ;
161+ selectedCodecs = codecs . Where ( codec => codec . name == codecName ) ;
134162 codecOptions = selectedCodecs . Select ( codec => codec . optionTitle ) . ToArray ( ) ;
135- sdpFmtpLines = selectedCodecs . Select ( codec => codec . sdpFmtpLine ) . ToArray ( ) ;
136163 if ( ! selectedCodecs . Any ( ) )
137164 selectCodecIndex = 0 ;
138165 else
139166 selectCodecIndex = Array . FindIndex ( codecNames , codec => codec == codecName ) ;
140167 codecLabel = GetCodecLabel ( property . serializedObject . targetObject ) ;
141168 hasCodecOptions = codecOptions . Length > 1 ;
142169 if ( hasCodecOptions )
143- selectSdpFmtpLineIndex = Array . FindIndex ( sdpFmtpLines , sdp => sdp == propertySdpFmtpLine . stringValue ) ;
170+ selectCodecOptionIndex = FindOptionIndex ( selectedCodecs ) ;
144171 cache = true ;
145172 }
146173
@@ -158,17 +185,25 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
158185 if ( 0 < selectCodecIndex )
159186 {
160187 string codecName = codecNames [ selectCodecIndex ] ;
161- var selectedCodecs = codecs . Where ( codec => codec . name == codecName ) ;
188+ selectedCodecs = codecs . Where ( codec => codec . name == codecName ) ;
162189 codecOptions = selectedCodecs . Select ( codec => codec . optionTitle ) . ToArray ( ) ;
163- sdpFmtpLines = selectedCodecs . Select ( codec => codec . sdpFmtpLine ) . ToArray ( ) ;
164190 hasCodecOptions = codecOptions . Length > 1 ;
165- propertyMimeType . stringValue = selectedCodecs . First ( ) . mimeType ;
166- propertySdpFmtpLine . stringValue = sdpFmtpLines [ 0 ] ;
191+ var codec = selectedCodecs . First ( ) ;
192+ propertyMimeType . stringValue = codec . mimeType ;
193+ propertySdpFmtpLine . stringValue = codec . sdpFmtpLine ;
194+ if ( propertyChannelCount != null )
195+ propertyChannelCount . intValue = codec . channelCount ;
196+ if ( propertySampleRate != null )
197+ propertySampleRate . intValue = codec . sampleRate ;
167198 }
168199 else
169200 {
170201 propertyMimeType . stringValue = null ;
171202 propertySdpFmtpLine . stringValue = null ;
203+ if ( propertyChannelCount != null )
204+ propertyChannelCount . intValue = 0 ;
205+ if ( propertySampleRate != null )
206+ propertySampleRate . intValue = 0 ;
172207 hasCodecOptions = false ;
173208 }
174209 }
@@ -184,11 +219,16 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
184219 EditorGUI . BeginProperty ( rect , label , propertySdpFmtpLine ) ;
185220
186221 EditorGUI . BeginChangeCheck ( ) ;
187- selectSdpFmtpLineIndex = EditorGUI . Popup ( rect , selectSdpFmtpLineIndex , codecOptions ) ;
222+ selectCodecOptionIndex = EditorGUI . Popup ( rect , selectCodecOptionIndex , codecOptions ) ;
188223
189224 if ( EditorGUI . EndChangeCheck ( ) )
190225 {
191- propertySdpFmtpLine . stringValue = sdpFmtpLines [ selectSdpFmtpLineIndex ] ;
226+ var codec = selectedCodecs . ElementAt ( selectCodecOptionIndex ) ;
227+ propertySdpFmtpLine . stringValue = codec . sdpFmtpLine ;
228+ if ( propertyChannelCount != null )
229+ propertyChannelCount . intValue = codec . channelCount ;
230+ if ( propertySampleRate != null )
231+ propertySampleRate . intValue = codec . sampleRate ;
192232 }
193233 EditorGUI . EndProperty ( ) ;
194234 }
0 commit comments