简体   繁体   中英

Can i write from MediaRecorder to my android / linux pipe's?

I'm creating android pipe with command

System.Diagnostics.Process.Start("mkfifo", $"/data/user/0/ru.petrovip.proxyclient/files/videopipe").WaitForExit();

This command make pipe videopipe , through application.

And open this pipe in application

var VideoStream = System.IO.File.Open("/data/user/0/ru.petrovip.proxyclient/files/videopipe", FileMode.Open);

Pipe is working, but i if start using MediaRecorder for my pipe, i catch error Java.Lang.IllegalStateException at MRecorder.Prepare();

MediaRecorder MRecorder = new MediaRecorder();

MRecorder.SetAudioSource(AudioSource.Mic);
MRecorder.SetVideoSource(VideoSource.Surface);
MRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
MRecorder.SetOutputFile(ParcelFileDescriptor.FromFd((int)VideoStream.Handle).FileDescriptor);
MRecorder.SetVideoSize(DisplayMetrics.WidthPixels, DisplayMetrics.HeightPixels);
MRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
MRecorder.SetVideoEncoder(VideoEncoder.H264);
MRecorder.SetVideoEncodingBitRate(512 * 1000);
MRecorder.SetVideoFrameRate(30);
MRecorder.Prepare();

Exception

01-18 20:23:55.471 E/MediaRecorder( 5990): prepare failed: -38
01-18 20:23:55.467 W/vip.proxyclient( 5990): type=1400 audit(0.0:876): avc: denied { read write } for path="/data/data/ru.petrovip.proxyclient/files/videopipe" dev="mmcblk0p24" ino=5435 scontext=u:r:mediaserver:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=fifo_file permissive=0
01-18 20:24:01.625 W/System.err( 5990): java.lang.IllegalStateException
01-18 20:24:01.627 W/System.err( 5990):     at android.media.MediaRecorder._prepare(Native Method)
01-18 20:24:01.628 W/System.err( 5990):     at android.media.MediaRecorder.prepare(MediaRecorder.java:988)
01-18 20:24:01.629 W/System.err( 5990):     at crc64c1965aae109aaff4.MainActivity.n_onCreate(Native Method)
01-18 20:24:01.629 W/System.err( 5990):     at crc64c1965aae109aaff4.MainActivity.onCreate(MainActivity.java:31)
01-18 20:24:01.630 W/System.err( 5990):     at android.app.Activity.performCreate(Activity.java:7023)
01-18 20:24:01.631 W/System.err( 5990):     at android.app.Activity.performCreate(Activity.java:7014)
01-18 20:24:01.632 W/System.err( 5990):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
01-18 20:24:01.633 W/System.err( 5990):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
01-18 20:24:01.637 W/System.err( 5990):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
01-18 20:24:01.638 W/System.err( 5990):     at android.app.ActivityThread.-wrap11(Unknown Source:0)
01-18 20:24:01.639 W/System.err( 5990):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
01-18 20:24:01.640 W/System.err( 5990):     at android.os.Handler.dispatchMessage(Handler.java:106)
01-18 20:24:01.640 W/System.err( 5990):     at android.os.Looper.loop(Looper.java:164)
01-18 20:24:01.641 W/System.err( 5990):     at android.app.ActivityThread.main(ActivityThread.java:6523)
01-18 20:24:01.642 W/System.err( 5990):     at java.lang.reflect.Method.invoke(Native Method)
01-18 20:24:01.643 W/System.err( 5990):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
01-18 20:24:01.649 W/System.err( 5990):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

For other system pipe's /dev/null , /dev/zero this will work correctly, without any errors.

Is this due to security restrictions and are there other ways out of this problem?

This problem occurs when enabled by enabled SELinux status. You need disable him by command

setenforce 0

Note: this method work only if you'r device rooted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM