HTC devices crash with MediaRecorder
<p>Htc device crashes with using MediaRecorder for recording screen of the device.</p>

<p>When i stop recording on the home screen of device, i dont the issue.
But when i stop recording on any app screen, it crashes the surfaceflinger library.</p>

<p>Here the code to setup the recorder : </p>

<pre><code>    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    mMediaRecorder.setVideoEncodingBitRate(700 * 1000);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoSize(recordDisplayWidth, recordDisplayHeight);
    mMediaRecorder.prepare();
       mMediaProjection.createVirtualDisplay(mFragment.getActivity().getLocalClassName(),
            recordDisplayWidth, recordDisplayHeight, mScreenDensity,
            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mMediaRecorder.getSurface(), null, null)

   mMediaRecorder.start();
</code></pre>

<p>The recording starts successfully, but when i do mMediaRecorder.stop(),
surfaceflinger crashes.
Here is the log for the crash : </p>

<pre><code>02-10 11:35:01.180    4807-9696/? D/OMX-VENC-720p﹕ close m_pipe_in(27)
02-10 11:35:01.180    4807-9696/? D/OMX-VENC-720p﹕ close m_pipe_out(28)
02-10 11:35:01.180    4807-9696/? D/OMX-VENC-720p﹕ omx_video: Waiting on Msg Thread(0xB8932770) exit
02-10 11:35:01.180    4807-9702/? D/OMX-VENC-720p﹕ omx_venc: message thread stop
02-10 11:35:01.180    4807-9696/? D/OMX-VENC-720p﹕ omx_video: Waiting on Async Thread(0xB8842140) exit
02-10 11:35:01.187    4807-5131/? E/BufferQueueProducer﹕ [GraphicBufferSource] dequeueBuffer: BufferQueue has been abandoned
02-10 11:35:01.189    4804-4804/? E/SurfaceFlinger﹕ [ui.SettingsActivity] dequeueBuffer: no buffer, bailing out
    --------- beginning of crash
02-10 11:35:01.190    4804-4804/? A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30c6 in tid 4804 (surfaceflinger)
02-10 11:35:01.198    4807-9703/? E/OMX-VENC-720p﹕ WRNING:ioctl VEN_IOCTL_CMD_READ_NEXT_MSG failed
02-10 11:35:01.199    4807-9703/? D/OMX-VENC-720p﹕ omx_venc: Async Thread exit
02-10 11:35:01.199    4807-9696/? D/OMX-VENC-720p﹕ Calling close() on venc ion device fd = 24
02-10 11:35:01.199    4807-9696/? D/OMX-VENC-720p﹕ Successfully destroyed venc ionlock
02-10 11:35:01.199    4807-9696/? D/OMX-VENC-720p﹕ m_etb_count = 0, m_fbd_count = 0
02-10 11:35:01.199    4807-9696/? D/OMX-VENC-720p﹕ Exiting OMX Video Encoder ...
02-10 11:35:01.199    4807-9696/? D/OMX-VENC-720p﹕ Destroy C2D instance
02-10 11:35:01.200    4807-9694/? D/MediaCodec﹕ ~MediaCodec
02-10 11:35:01.200    4807-9694/? I/MediaCodecSource﹕ encoder (video) stopped
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ Video track source stopped
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ E android::status_t android::MPEG4Writer::Track::stop(): pthread_join Video track
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ L android::status_t android::MPEG4Writer::Track::stop(): pthread_join Video track, result=0
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ Video track stopped
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ Stopping writer thread
02-10 11:35:01.200    4807-4807/? I/MPEG4Writer﹕ Obtain lock in stopWriterThread
02-10 11:35:01.200    4807-9705/? D/MPEG4Writer﹕ 0 chunks are written in the last batch
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ Writer thread stopped
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ MPEG4Writer destructor
02-10 11:35:01.200    4807-4807/? D/MPEG4Writer﹕ Video track stopping
02-10 11:35:01.201    4807-4807/? D/MediaPlayerService﹕ addBatteryData
02-10 11:35:01.201    4807-4807/? D/MediaPlayerService﹕ addBatteryData E
02-10 11:35:01.201    4807-4807/? D/MediaPlayerService﹕ addBatteryData X
02-10 11:35:01.201    5241-5241/? D/IMediaRecorder﹕ stop(299) return
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ process_media_recorder_call
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ native_reset
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ getMediaRecorder E
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ process_media_recorder_call
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ release
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ setMediaRecorder E: mr = null
02-10 11:35:01.201    5241-5241/? D/MediaRecorderJNI﹕ setMediaRecorder X
02-10 11:35:01.201    4807-5058/? D/IMediaRecorder﹕ BnMediaRecorder::onTransact(), code=1,
02-10 11:35:01.201    4807-5058/? D/StagefrightRecorder﹕ Destructor
02-10 11:35:01.201    4807-5058/? D/StagefrightRecorder﹕ stop
02-10 11:35:01.202    4807-5058/? V/MediaPlayerService﹕ Delete media recorder client
02-10 11:35:01.202    5241-5241/? D/IMediaRecorder﹕ release(329) return
02-10 11:35:01.203    4966-5419/? I/DisplayManagerService﹕ Display device removed: DisplayDeviceInfo{"ui.SettingsActivity": uniqueId="virtual:com.fiberlink.maas360.android.control,10137,ui.SettingsActivity,0", 720 x 1280, 60.0 fps, supportedRefreshRates [60.0], density 480, 480.0 x 480.0 dpi, appVsyncOff 0, presDeadline 16666666, touch NONE, rotation 0, type VIRTUAL, state ON, owner com.fiberlink.maas360.android.control (uid 10137), FLAG_PRIVATE, FLAG_PRESENTATION}
02-10 11:35:01.292      287-287/? I/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-10 11:35:01.292      287-287/? I/DEBUG﹕ Build fingerprint: 'htc/m7_google/m7:5.1/LMY47O.H6/536258:user/release-keys'
02-10 11:35:01.292      287-287/? I/DEBUG﹕ Revision: '3'
02-10 11:35:01.292      287-287/? I/DEBUG﹕ ABI: 'arm'
02-10 11:35:01.292      287-287/? I/DEBUG﹕ pid: 4804, tid: 4804, name: surfaceflinger  &gt;&gt;&gt; /system/bin/surfaceflinger &lt;&lt;&lt;
02-10 11:35:01.292      287-287/? I/DEBUG﹕ signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30c6
02-10 11:35:01.296    4966-5143/? W/NativeCrashListener﹕ Couldn't find ProcessRecord for pid 4804
02-10 11:35:01.303    4807-5046/? D/AudioStreamOutALSA﹕ write:: buffer 0xb8930680, bytes 1024
02-10 11:35:01.307      287-287/? I/DEBUG﹕ r0 b6f664f5  r1 b6f70e40  r2 b6f664f5  r3 00000068
02-10 11:35:01.307      287-287/? E/DEBUG﹕ AM write failure (32 / Broken pipe)
02-10 11:35:01.307      287-287/? I/DEBUG﹕ Write to AM fail, close AM fd
02-10 11:35:01.307      287-287/? I/DEBUG﹕ r4 b871f8b0  r5 b871df18  r6 becbd808  r7 0000308a
02-10 11:35:01.307      287-287/? I/DEBUG﹕ r8 becbd810  r9 becbd84c  sl b85e36b8  fp 00000000
02-10 11:35:01.307      287-287/? I/DEBUG﹕ ip b6582f34  sp becbd7b8  lr b6f32f65  pc b657b60a  cpsr 60070030
02-10 11:35:01.308      287-287/? I/DEBUG﹕ backtrace:
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #00 pc 0000360a  /system/vendor/lib/egl/eglsubAndroid.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #01 pc 0000b474  /system/vendor/lib/egl/libEGL_adreno.so (egliSyncBackBuffer+252)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #02 pc 0007ef8b  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_surface_sync_for_resolve+34)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #03 pc 0007eff5  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_perform_rendering_target_sync+40)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #04 pc 0007f26b  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_setup_resolve+22)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #05 pc 0007f459  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_perform_resolve+192)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #06 pc 0007f73b  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_resolve+398)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #07 pc 00084729  /system/vendor/lib/egl/libGLESv2_adreno.so (rb_surface_swap+216)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #08 pc 00065747  /system/vendor/lib/egl/libGLESv2_adreno.so (gl2_surface_swap+74)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #09 pc 000572bd  /system/vendor/lib/egl/libGLESv2_adreno.so (oglSwapBuffer+176)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #10 pc 00013840  /system/vendor/lib/egl/libEGL_adreno.so (qeglDrvAPI_eglSwapBuffers+408)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #11 pc 0000791c  /system/vendor/lib/egl/libEGL_adreno.so (eglSwapBuffers+16)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #12 pc 000129f5  /system/lib/libEGL.so (eglSwapBuffers+320)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #13 pc 0000ece5  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #14 pc 0001ae71  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #15 pc 0001a031  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #16 pc 0001932f  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #17 pc 0001909d  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #18 pc 00012d2f  /system/lib/libutils.so (android::Looper::pollInner(int)+522)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #19 pc 00012e39  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+92)
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #20 pc 00016479  /system/lib/libsurfaceflinger.so
02-10 11:35:01.308      287-287/? I/DEBUG﹕ #21 pc 00018c21  /system/lib/libsurfaceflinger.so (android::SurfaceFlinger::run()+8)
02-10 11:35:01.309      287-287/? I/DEBUG﹕ #22 pc 00000b4d  /system/bin/surfaceflinger
02-10 11:35:01.309      287-287/? I/DEBUG﹕ #23 pc 000125ed  /system/lib/libc.so (__libc_init+44)
02-10 11:35:01.309      287-287/? I/DEBUG﹕ #24 pc 00000c08  /system/bin/surfaceflinger
02-10 11:35:01.380    4966-5124/? D/WifiController﹕ battery changed pluggedType: 2
02-10 11:35:01.570    4807-5046/? D/AudioStreamOutALSA﹕ write:: buffer 0xb8930680, bytes 1024
02-10 11:35:01.661    4966-5123/? E/WifiStateMachine﹕ handleMessage: E msg.what=131143
02-10 11:35:01.661    4966-5123/? E/WifiStateMachine﹕ processMsg: ConnectedState
02-10 11:35:01.661    4966-5123/? E/WifiStateMachine﹕ processMsg: L2ConnectedState
02-10 11:35:01.662    4966-5123/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN source -2 txSuccessRate=5.25 rxSuccessRate=4.65 targetRoamBSSID=00:00:00:00:00:00 RSSI=-64
02-10 11:35:01.662    4966-5123/? E/WifiStateMachine﹕ startDelayedScan send -&gt; 23 milli 20000
02-10 11:35:01.662    4966-5123/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN with age=40009 interval=30000 maxinterval=300000
02-10 11:35:01.662    4966-5123/? E/WifiStateMachine﹕ WifiStateMachine CMD_START_SCAN try full band scan age=40009 interval=30000 maxinterval=300000
</code></pre>

<p>Can some please help.
This does not happen on devices other than HTC.</p>