2626import com .yanzhenjie .permission .AndPermission ;
2727import com .yanzhenjie .permission .runtime .Permission ;
2828
29- import org .json .JSONException ;
30- import org .json .JSONObject ;
31-
3229import io .agora .api .example .MainApplication ;
3330import io .agora .api .example .R ;
3431import io .agora .api .example .annotation .Example ;
@@ -64,7 +61,7 @@ public class VideoProcessExtension extends BaseFragment implements View.OnClickL
6461 private FrameLayout fl_local , fl_remote ;
6562 private LinearLayout controlPanel ;
6663 private Button join ;
67- private Switch beauty , lightness , colorful , noiseReduce , virtualBackground , lightness2 , colorful2 , noiseReduce2 ;
64+ private Switch beauty , virtualBackground , lightness2 , colorful2 , noiseReduce2 ;
6865 private SeekBar seek_lightness , seek_redness , seek_sharpness , seek_smoothness , seek_strength , seek_skin ;
6966 private EditText et_channel ;
7067 private RtcEngine engine ;
@@ -95,19 +92,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9592 controlPanel = view .findViewById (R .id .controlPanel );
9693 beauty = view .findViewById (R .id .switch_face_beautify );
9794 beauty .setOnCheckedChangeListener (this );
98- lightness = view .findViewById (R .id .switch_lightness );
9995 lightness2 = view .findViewById (R .id .switch_lightness2 );
100- lightness .setOnCheckedChangeListener (this );
10196 lightness2 .setOnCheckedChangeListener (this );
102- colorful = view .findViewById (R .id .switch_color );
10397 colorful2 = view .findViewById (R .id .switch_color2 );
104- colorful .setOnCheckedChangeListener (this );
10598 colorful2 .setOnCheckedChangeListener (this );
10699 virtualBackground = view .findViewById (R .id .switch_virtual_background );
107100 virtualBackground .setOnCheckedChangeListener (this );
108- noiseReduce = view .findViewById (R .id .switch_video_noise_reduce );
109101 noiseReduce2 = view .findViewById (R .id .switch_video_noise_reduce2 );
110- noiseReduce .setOnCheckedChangeListener (this );
111102 noiseReduce2 .setOnCheckedChangeListener (this );
112103 seek_lightness = view .findViewById (R .id .lightening );
113104 seek_lightness .setOnSeekBarChangeListener (this );
@@ -162,8 +153,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState)
162153 /**
163154 * enable video process extension
164155 */
165- config .addExtension ("agora_video_process_extension" );
166- config .addExtension ("agora_segmentation_extension" );
167156 engine = RtcEngine .create (config );
168157 }
169158 catch (Exception e )
@@ -233,11 +222,6 @@ private void joinChannel(String channelId)
233222 {
234223 accessToken = null ;
235224 }
236- /**
237- * enable face beauty by default
238- */
239- engine .enableExtension ("agora" , "beauty" , true );
240- engine .enableExtension ("agora_segmentation" , "PortraitSegmentation" , true );
241225 engine .startPreview ();
242226 /** Allows a user to join a channel.
243227 if you do not specify the uid, we will generate the uid for you*/
@@ -321,113 +305,31 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
321305 if (buttonView .getId () == beauty .getId ()){
322306 engine .setBeautyEffectOptions (isChecked , beautyOptions );
323307 }
324- else if (buttonView .getId () == lightness .getId ()){
325- lightness2 .setEnabled (!isChecked );
326- JSONObject beautyObj = new JSONObject ();
327- try {
328- beautyObj .put ("enable" , isChecked ? 1 : 0 );
329- /**
330- * level:
331- * 0 (default), better quality
332- * 1, better performance
333- */
334- beautyObj .put ("level" , 1 );
335- /**
336- * mode:
337- * 0 (default), auto mode, sdk determine enable/disable according to environment.
338- * 1, force enable.
339- */
340- beautyObj .put ("mode" , 0 );
341- if (engine != null )
342- engine .setExtensionProperty ("agora" ,
343- "beauty" , "lowlight_enhance_option" , beautyObj .toString ());
344- } catch (JSONException e ) {
345- e .printStackTrace ();
346- }
347- }
348308 else if (buttonView .getId () == lightness2 .getId ()){
349309 LowLightEnhanceOptions options = new LowLightEnhanceOptions ();
350310 options .lowlightEnhanceLevel = LowLightEnhanceOptions .LOW_LIGHT_ENHANCE_LEVEL_FAST ;
351311 options .lowlightEnhanceMode = LowLightEnhanceOptions .LOW_LIGHT_ENHANCE_AUTO ;
352312 engine .setLowlightEnhanceOptions (isChecked , options );
353- lightness .setEnabled (!isChecked );
354- }
355- else if (buttonView .getId () == colorful .getId ()){
356- colorful2 .setEnabled (!isChecked );
357- setColorEnhance (isChecked );
358313 }
359314 else if (buttonView .getId () == colorful2 .getId ()){
360- colorful .setEnabled (!isChecked );
361315 setColorEnhance (isChecked );
362316 }
363317 else if (buttonView .getId () == virtualBackground .getId ()){
364318 engine .enableVirtualBackground (isChecked , virtualBackgroundSource , new SegmentationProperty ());
365319 }
366- else if (buttonView .getId () == noiseReduce .getId ()){
367- noiseReduce2 .setEnabled (!isChecked );
368- JSONObject beautyObj = new JSONObject ();
369- try {
370- beautyObj .put ("enable" , isChecked ? 1 : 0 );
371- /**
372- * level:
373- * 0 (default), medium denoise level,
374- * 1, fast denoise, for fixed camera scenario
375- * 2, best denoise level, for high video noise scenario
376- */
377- beautyObj .put ("level" , 0 );
378- /**
379- * mode:
380- * 0 (default), auto mode, sdk determine enable/disable according to environment.
381- * 1, force enable.
382- */
383- beautyObj .put ("mode" , 0 );
384-
385- if (engine != null )
386- engine .setExtensionProperty ("agora" , "beauty" , "video_denoiser_option" , beautyObj .toString ());
387-
388- } catch (JSONException e ) {
389- e .printStackTrace ();
390- }
391- } else if (buttonView .getId () == noiseReduce2 .getId ()){
320+ else if (buttonView .getId () == noiseReduce2 .getId ()){
392321 VideoDenoiserOptions options = new VideoDenoiserOptions ();
393322 options .denoiserLevel = VideoDenoiserOptions .VIDEO_DENOISER_AUTO ;
394323 options .denoiserMode = VideoDenoiserOptions .VIDEO_DENOISER_LEVEL_HIGH_QUALITY ;
395324 engine .setVideoDenoiserOptions (isChecked , options );
396- noiseReduce .setEnabled (!isChecked );
397325 }
398326 }
399327
400328 private void setColorEnhance (boolean isChecked ){
401- boolean isRtc = colorful2 .isChecked ();
402- if (isRtc ){
403- ColorEnhanceOptions options = new ColorEnhanceOptions ();
404- options .strengthLevel = (float ) strength ;
405- options .skinProtectLevel = (float ) skinProtect ;
406- engine .setColorEnhanceOptions (isChecked , options );
407- }
408- else {
409- JSONObject beautyObj = new JSONObject ();
410- try {
411- beautyObj .put ("enable" , isChecked ? 1 : 0 );
412- /**
413- * strength: [0.0, 1.0]
414- * color strength
415- */
416- beautyObj .put ("strength" , strength );
417- /**
418- * skinProtect: [0.0, 1.0]
419- * higher skinProtect value, less impact for skin color.
420- */
421- beautyObj .put ("skinProtect" , skinProtect );
422-
423- if (engine != null )
424- engine .setExtensionProperty ("agora" ,
425- "beauty" , "color_enhance_option" , beautyObj .toString ());
426- } catch (JSONException e ) {
427- e .printStackTrace ();
428- }
429- }
430-
329+ ColorEnhanceOptions options = new ColorEnhanceOptions ();
330+ options .strengthLevel = (float ) strength ;
331+ options .skinProtectLevel = (float ) skinProtect ;
332+ engine .setColorEnhanceOptions (isChecked , options );
431333 }
432334
433335 @ Override
@@ -451,11 +353,11 @@ else if(seekBar.getId() == seek_smoothness.getId()){
451353 }
452354 else if (seekBar .getId () == seek_strength .getId ()) {
453355 strength = value ;
454- setColorEnhance (colorful .isChecked ());
356+ setColorEnhance (colorful2 .isChecked ());
455357 }
456358 else if (seekBar .getId () == seek_skin .getId ()) {
457359 skinProtect = value ;
458- setColorEnhance (colorful .isChecked ());
360+ setColorEnhance (colorful2 .isChecked ());
459361 }
460362 }
461363
0 commit comments