fanplayer icon indicating copy to clipboard operation
fanplayer copied to clipboard

Crash with E/Surface: dequeueBuffer failed

Open SunMaungOo opened this issue 6 years ago • 8 comments

When I try to close the player and the open the video, it something doesn’t show video (but the audio is working fine).

Sometime the program crash with the below log.

I am playing mkv file with 1080p resolution.

01-20 21:11:24.430 2111-2174/com.rockcarry.fanplayer E/Surface: dequeueBuffer failed (Operation not permitted)
01-20 21:11:24.430 2111-2174/com.rockcarry.fanplayer A/libc: Fatal signal 7 (SIGBUS) at 0x4159a913 (code=1), thread 2174 (carry.fanplayer)

I have add the stop button and add button to the example code.

 private Button mBtnStop=null;
 private Button mBtnOpen=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        //example code

        mBtnStop=(Button)findViewById(R.id.btnStop);
        mBtnStop.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {

                  if(mIsPlaying) {
                    mPlayer.close();

                    mIsPlaying=false;


              }

            }


        });

        mBtnOpen=(Button)findViewById(R.id.btnOpen);
        mBtnOpen.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View view){

                mPlayer.open(mURL,"video_hwaccel=1;video_rotate=0");

            }

        });
      
   }

SunMaungOo avatar Mar 18 '18 12:03 SunMaungOo

the newest source code fix this issue.

please test it.

rockcarry avatar Mar 20 '18 00:03 rockcarry

The problem is not fix in the newest source code.

I have add the stop button and open button to the example code given in the project.

private String mURL="file://mnt/sdcard/Movies/a.mkv";

When movie is playing

  1. Click stop button
  2. Click open button (open the same video file)
  3. Audio is playing but the display is not showing up

Is it because I am playing the same video file?

SunMaungOo avatar Mar 21 '18 00:03 SunMaungOo

if still crash, it's a bug.

can you help me do more test. to find the root cause.

  1. play same video or different ?
  2. different file, .mkv .mp4 .rmvb
  3. do not click stop, but exit app

and please give the source code which you changed and full log

thank you.

rockcarry avatar Mar 21 '18 02:03 rockcarry

It doesn't crash but the video is not playing although the audio is working.

  1. I play the same video
  2. It is the same .mkv file

When I exit the app while the video is playing, it crash. The log is

01-23 13:30:03.700 2223-2223/? D/dalvikvm: Late-enabling CheckJNI
01-23 13:30:03.840 2223-2223/com.rockcarry.fanplayer I/MultiDex: VM with version 1.6.0 does not have multidex support
01-23 13:30:03.840 2223-2223/com.rockcarry.fanplayer I/MultiDex: Installing application
01-23 13:30:03.840 2223-2223/com.rockcarry.fanplayer I/MultiDex: MultiDexExtractor.load(/data/app/com.rockcarry.fanplayer-2.apk, false, )
01-23 13:30:03.850 2223-2223/com.rockcarry.fanplayer I/MultiDex: Blocking on lock /data/data/com.rockcarry.fanplayer/code_cache/secondary-dexes/MultiDex.lock
01-23 13:30:03.850 2223-2223/com.rockcarry.fanplayer I/MultiDex: /data/data/com.rockcarry.fanplayer/code_cache/secondary-dexes/MultiDex.lock locked
01-23 13:30:03.860 2223-2223/com.rockcarry.fanplayer I/MultiDex: loading existing secondary dex files
01-23 13:30:03.860 2223-2223/com.rockcarry.fanplayer I/MultiDex: load found 1 secondary dex files
01-23 13:30:03.890 2223-2223/com.rockcarry.fanplayer I/MultiDex: install done
01-23 13:30:04.150 2223-2223/com.rockcarry.fanplayer D/dalvikvm: Trying to load lib /data/app-lib/com.rockcarry.fanplayer-2/libfanplayer_jni.so 0x41855f18
01-23 13:30:04.190 2223-2223/com.rockcarry.fanplayer D/dalvikvm: Added shared lib /data/app-lib/com.rockcarry.fanplayer-2/libfanplayer_jni.so 0x41855f18
01-23 13:30:04.340 2223-2223/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libEGL_mali.so
01-23 13:30:04.350 2223-2223/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
01-23 13:30:04.350 2223-2223/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so
01-23 13:30:04.420 2223-2223/com.rockcarry.fanplayer D/OpenGLRenderer: Enabling debug mode 0
01-23 13:30:04.670 2223-2242/com.rockcarry.fanplayer D/ACodec: Calling process 2 is: com.rockcarry.fanplayer
01-23 13:30:04.680 2223-2242/com.rockcarry.fanplayer I/OMXClient: Using client-side OMX mux.
01-23 13:30:04.700 2223-2264/com.rockcarry.fanplayer I/OMXClient: Using client-side OMX mux.
01-23 13:30:04.710 2223-2264/com.rockcarry.fanplayer D/ACodec: Calling process 2 is: com.rockcarry.fanplayer
01-23 13:30:04.720 2223-2242/com.rockcarry.fanplayer D/fanplayer: java.lang.IllegalStateException occurred
01-23 13:30:04.720 2223-2242/com.rockcarry.fanplayer D/fanplayer: using android mediacodec hardware decoder h264_mediacodec !
01-23 13:30:04.970 2223-2244/com.rockcarry.fanplayer D/fanplayer: No accelerated colorspace conversion found from yuv420p to rgba.
01-23 13:30:25.090 2223-2244/com.rockcarry.fanplayer E/Surface: dequeueBuffer failed (Operation not permitted)
01-23 13:30:25.090 2223-2244/com.rockcarry.fanplayer A/libc: Fatal signal 7 (SIGBUS) at 0x414d1913 (code=1), thread 2244 (carry.fanplayer)

My layout file is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.rockcarry.fanplayer.playerView
        android:id="@+id/player_root"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <SurfaceView
            android:id="@+id/video_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerInParent="true" />
        <ProgressBar
            android:id="@+id/buffering"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:alpha="0.8"
            />
        <SeekBar
            android:id="@+id/seek_bar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:alpha="0.8" />
        <ImageView
            android:id="@+id/btn_playpause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/icn_media_pause"
            android:alpha="0.8"
            />
        <Button
            android:id="@+id/btnOpen"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Open"/>

        <Button
            android:id="@+id/btnStop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Close"
            android:layout_below="@id/btnOpen"/>
    </com.rockcarry.fanplayer.playerView>

</RelativeLayout>

The activity code is

package com.rockcarry.fanplayer;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.Toast;
import android.util.Log;

public class MainActivity extends Activity {
    private MediaPlayer  mPlayer    = null;
    private playerView   mRoot      = null;
    private SurfaceView  mVideo     = null;
    private SeekBar      mSeek      = null;
    private ProgressBar  mBuffering = null;
    private ImageView    mPause     = null;
    private boolean      mIsPlaying = false;
    private boolean      mIsLive    = false;
   // private String       mURL       = "rtmp://live.hkstv.hk.lxdns.com/live/hks";

    private String mURL="file://mnt/sdcard/Movies/a.mkv";

    private Button mBtnOpen;

    private Button mBtnStop;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = getIntent();
        String action = intent.getAction();
        if (intent.ACTION_VIEW.equals(action)) {
            Uri    uri    = (Uri) intent.getData();
            String scheme = uri.getScheme();
            if (scheme.equals("file")) {
                mURL = uri.getPath();
            } else if (  scheme.equals("http" )
                      || scheme.equals("https")
                      || scheme.equals("rtsp" )
                      || scheme.equals("rtmp" ) ) {
                mURL = uri.toString();
            } else if (scheme.equals("content")) {
                String[] proj = { MediaStore.Images.Media.DATA };
                Cursor cursor = managedQuery(uri, proj, null, null, null);
                int    colidx = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                mURL = cursor.getString(colidx);
            }
        }

        mBtnStop=(Button)findViewById(R.id.btnStop);
        mBtnStop.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View view){

                if(mIsPlaying){
                    mPlayer.close();

                    mIsPlaying=false;
                }
            }

        });

        mBtnOpen=(Button)findViewById(R.id.btnOpen);
        mBtnOpen.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View view){

                mPlayer.open(mURL,"video_hwaccel=1;video_rotate=0");

            }

        });


        mIsLive = mURL.startsWith("http://") && mURL.endsWith(".m3u8") || mURL.startsWith("rtmp://") || mURL.startsWith("rtsp://");
        mPlayer = new MediaPlayer(mURL, mHandler, "video_hwaccel=1;video_rotate=0");

        mRoot = (playerView)findViewById(R.id.player_root);
        mRoot.setOnSizeChangedListener(new playerView.OnSizeChangedListener() {
            @Override
            public void onSizeChanged(int w, int h, int oldw, int oldh) {
                mVideo.setVisibility(View.INVISIBLE);
                Message msg = new Message();
                msg.arg1 = w;
                msg.arg2 = h;
                msg.what = MSG_INIT_VIDEO_SIZE;
                mHandler.sendMessage(msg);
            }
        });

        mVideo = (SurfaceView)findViewById(R.id.video_view);
        mVideo.getHolder().addCallback(
            new Callback() {
                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
//                  mPlayer.setDisplaySurface(holder.getSurface());
                }

                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    mPlayer.setDisplaySurface(holder.getSurface());
                }

                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                    mPlayer.setDisplaySurface(null);
                }
            }
        );

        mSeek = (SeekBar)findViewById(R.id.seek_bar);
        mSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (fromUser) {
                    mPlayer.seek(progress);
                }
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });

        mPause = (ImageView)findViewById(R.id.btn_playpause);
        mPause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                testPlayerPlay(!mIsPlaying);
            }
        });

        mBuffering = (ProgressBar)findViewById(R.id.buffering);
        mBuffering.setVisibility(mIsLive ? View.VISIBLE : View.INVISIBLE);

        // show buttons with auto hide
        showUIControls(true, true);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mHandler.removeMessages(MSG_UPDATE_PROGRESS);
        mHandler.removeMessages(MSG_INIT_VIDEO_SIZE);
        mPlayer.close();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!mIsLive) testPlayerPlay(true);
    }

    @Override
    public void onPause() {
        if (!mIsLive) testPlayerPlay(false);
        super.onPause();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
            showUIControls(true, true);
        }
        return super.dispatchTouchEvent(ev);
    }

    private void testPlayerPlay(boolean play) {
        if (play) {
            mPlayer.play();
            mIsPlaying = true;
            mPause  .setImageResource(R.drawable.icn_media_pause);
            mHandler.sendEmptyMessage(MSG_UPDATE_PROGRESS);
        } else {
            mPlayer.pause();
            mIsPlaying = false;
            mPause  .setImageResource(R.drawable.icn_media_play );
            mHandler.removeMessages  (MSG_UPDATE_PROGRESS);
        }
    }

    private void showUIControls(boolean show, boolean autohide) {
        mHandler.removeMessages(MSG_HIDE_BUTTONS);
        if (mIsLive) show = false;
        if (show) {
            mSeek .setVisibility(View.VISIBLE);
            mPause.setVisibility(View.VISIBLE);
            if (autohide) {
                mHandler.sendEmptyMessageDelayed(MSG_HIDE_BUTTONS, 5000);
            }
        }
        else {
            mSeek .setVisibility(View.INVISIBLE);
            mPause.setVisibility(View.INVISIBLE);
        }
    }

    private static final int MSG_UPDATE_PROGRESS = 1;
    private static final int MSG_HIDE_BUTTONS    = 2;
    private static final int MSG_INIT_VIDEO_SIZE = 3;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MSG_UPDATE_PROGRESS: {
                    mHandler.sendEmptyMessageDelayed(MSG_UPDATE_PROGRESS, 200);
                    int progress = (int)mPlayer.getParam(MediaPlayer.PARAM_MEDIA_POSITION);
                    if (!mIsLive) {
                        if (progress >= 0) mSeek.setProgress(progress);
                    } else {
                        mBuffering.setVisibility(progress == -1 ? View.VISIBLE : View.INVISIBLE);
                    }
                }
                break;
            case MSG_HIDE_BUTTONS: {
                    mSeek .setVisibility(View.INVISIBLE);
                    mPause.setVisibility(View.INVISIBLE);
                }
                break;
            case MSG_INIT_VIDEO_SIZE: {
                    if (!mPlayer.initVideoSize(msg.arg1, msg.arg2, mVideo)) {
                        Message m = new Message();
                        m.arg1 = msg.arg1;
                        m.arg2 = msg.arg2;
                        m.what = MSG_INIT_VIDEO_SIZE;
                        mHandler.sendMessageDelayed(m, 200);
                    } else {
                        mVideo.setVisibility(View.VISIBLE);
                    }
                }
                break;
            case MediaPlayer.MSG_OPEN_DONE: {
                    mSeek.setMax((int)mPlayer.getParam(MediaPlayer.PARAM_MEDIA_DURATION));
                    testPlayerPlay(true);
                }
                break;
            case MediaPlayer.MSG_OPEN_FAILED: {
                    String str = String.format(getString(R.string.open_video_failed), mURL);
                    Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
                }
                break;
            case MediaPlayer.MSG_PLAY_COMPLETED: {
                    if (!mIsLive) finish();
                }
                break;
            }
        }
    };
}

It is the same activity as shown in example. I just add two button to it.

SunMaungOo avatar Mar 21 '18 04:03 SunMaungOo

I am sorry I don't have the enviroment to reproduce your issue.

I improved the code for ANativeWindow. I am not sure whether it can fix this issue or not.

you can try the lastest code.

thank you.

rockcarry avatar Apr 13 '18 10:04 rockcarry

@rockcarry The problem still exist in latest version.

I found a way to reproduce a crash.

  1. Open the video file
  2. Click home button (when the video is playing)
  3. Click recent button (https://developer.android.com/design/handhelds/index.html)
  4. Program crash

The program crash with 02-16 03:15:07.600 2615-2636/com.rockcarry.fanplayer A/libc: Fatal signal 11 (SIGSEGV) at 0x5da19000 (code=1), thread 2636 (carry.fanplayer). the complete log is as shown below

02-16 03:14:23.130 2499-2499/? D/dalvikvm: Late-enabling CheckJNI 02-16 03:14:23.550 2499-2499/com.rockcarry.fanplayer D/dalvikvm: Trying to load lib /data/app-lib/com.rockcarry.fanplayer-1/libfanplayer_jni.so 0x418eefd0 02-16 03:14:23.600 2499-2499/com.rockcarry.fanplayer D/dalvikvm: Added shared lib /data/app-lib/com.rockcarry.fanplayer-1/libfanplayer_jni.so 0x418eefd0 02-16 03:14:23.710 2499-2499/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libEGL_mali.so 02-16 03:14:23.710 2499-2499/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so 02-16 03:14:23.720 2499-2499/com.rockcarry.fanplayer D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so 02-16 03:14:23.750 2499-2499/com.rockcarry.fanplayer D/OpenGLRenderer: Enabling debug mode 0 02-16 03:14:23.970 2499-2513/com.rockcarry.fanplayer D/ACodec: Calling process 2 is: com.rockcarry.fanplayer 02-16 03:14:23.970 2499-2513/com.rockcarry.fanplayer I/OMXClient: Using client-side OMX mux. 02-16 03:14:23.990 2499-2528/com.rockcarry.fanplayer I/OMXClient: Using client-side OMX mux. 02-16 03:14:23.990 2499-2528/com.rockcarry.fanplayer D/ACodec: Calling process 2 is: com.rockcarry.fanplayer 02-16 03:14:24.010 2499-2513/com.rockcarry.fanplayer D/fanplayer: java.lang.IllegalStateException occurred 02-16 03:14:24.010 2499-2513/com.rockcarry.fanplayer D/fanplayer: using android mediacodec hardware decoder h264_mediacodec ! 02-16 03:14:24.310 2499-2515/com.rockcarry.fanplayer D/fanplayer: No accelerated colorspace conversion found from yuv420p to rgba. 02-16 03:14:35.120 2499-2515/com.rockcarry.fanplayer A/libc: Fatal signal 11 (SIGSEGV) at 0x5e1ec000 (code=1), thread 2515 (carry.fanplayer)

SunMaungOo avatar Apr 13 '18 18:04 SunMaungOo

Same here. I'm on Android 10 Pixel 3 with latest version of Chrome with the version code 386509238.

thomasmso avatar Oct 11 '19 01:10 thomasmso

recently I optimze the code for ANativeWindow. can you help to test again ?

rockcarry avatar Sep 10 '21 06:09 rockcarry