Overlay creation failed-what is an inexplicable error?

Source: Internet
Author: User

Please indicate the source for reprinting ~

Link: http://blog.csdn.net/zgyulongfei/article/details/7680956

I am disheartened when I encounter such an error in the android live video system.

This is the case. h. 264 hard coding is used for video collection. Because all the code is written in a file, it is messy and difficult to maintain, so I decided to refactor it, extract the encoding part separately to form an encoder. If H is used later. 264 encoding can be transplanted to the encoder. Next, I got this error that gave me all my feelings, but fortunately I finally solved it. Although I don't know the cause of the problem, I hope my friends who know the cause can enlighten me.

The error code is as follows:

Overlay create failed-retrying

Overlay create failed-retrying

Overlay create failed-retrying

There are several such error logs, and the last log is overlay creation failed...

Then the video cannot be encoded, and no preview image is displayed.


When I encountered an error, I decided to Google Baidu, but I couldn't find any solution after looking for a long time. This error gave me two days to get stuck, it makes me feel cold and cool ......

At the beginning, the encoder I designed only needs to pass a surfaceview object and use this object to preview the recorded video. The Code is as follows:

Public class hsf-encoder implements surfaceholder. callback {surfaceholder holder; Public hsf-encoder (surfaceview view) {holder = view. getholder (); Hodler. addcallback (this); holder. settype (surfaceholder. surface_type_push_buffers);} public initmediarecorder (){... mediarecorder. setpreviewdisplay (holder. getsurface ());... mediarecorder. prepare (); // exception occurred here ...}}

View is the surfaceview view = (surfaceview) This. findviewbyid (R. Id. View)

I carefully checked the code several times and did not know what went wrong.

The error code C found on the internet is as follows:

if (mOverlayRef.get() == NULL) {// FIXME:// Surfaceflinger may hold onto the previous overlay reference for some// time after we try to destroy it. retry a few times. In the future, we// should make the destroy call block, or possibly specify that we can// wait in the createOverlay call if the previous overlay is in the // process of being destroyed.for (int retry = 0; retry < 50; ++retry) {mOverlayRef = mSurface->createOverlay(w, h, OVERLAY_FORMAT_YCbCr_420_SP);if (mOverlayRef != NULL) break;LOGD("Overlay create failed - retrying");usleep(20000);}if ( mOverlayRef.get() == NULL ){LOGE("Overlay Creation Failed!");return -EINVAL;}ret = mHardware->setOverlay(new Overlay(mOverlayRef));}

The fixme section above explains why so many overlay create failed-retrying will be printed. This comment roughly means that the overlay you prepare for destroy is still in the referenced state, so that you cannot create a new overlay .. Nima, the problem is here. I want to destroy an overlay during my time. I just referenced surfaceview. Isn't that true?

So I modified the code like this: instead of passing in surfaceview as a parameter, I passed in holder.

The Code is as follows:

Public class hsf-encoder {surfaceholder holder; Public hsf-encoder (surfaceholder holder) {This. hoder = holder;} public initmediarecorder (){... mediarecorder. setpreviewdisplay (holder. getsurface ());... mediarecorder. prepare (); // If Hodler is passed in, no exception occurs ...}}

The passed holder parameter is defined as follows:

SurfaceView view = (SurfaceView)this.findViewById(R.id.view)SurfaceHolder holder = view.getHolder();hodler.addCallback(this);holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

If no, I just defined the holder outside and passed it to the encoder. However, when the view is passed in, and then the holder is defined, an error will be reported.

Passing a view is a reference to the view object. Is the view. getholder () in the code different from the view. getholder () defined outside the encoder?

Why does the same thing have different effects? I am so depressed !!!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.