Debugging notes for android display

Source: Internet
Author: User

First, let's take a look at the initialization interface implementation. In this example, the device is first opened, and the input video source is set in the device to query the drive capability of the Video device. Then, the video mode is set to V4L2_MODE_VIDEO, set video parameters, such as width and height, pixel format, and filed. then apply for a buffer, bind a buffer address, and start the video device data stream, the entire device is working. Code details: [cpp] status_t CCSIDecoderHardware: v4l2Init (int mOldSystem) {F_LOG; CHECK_ERROR (openCameraDev (); // set capture mode struct v4l2_streamparm params; params. parm. capture. timeperframe. numerator = 1; params. parm. capture. timeperframe. denominator = 25; params. type = V4L2_BUF_TYPE_VIDEO_CAPTURE; params. parm. capture. capturemode = V4L2_MODE_VIDEO; // V4L2_MODE_IMAGE v4l2setCaptureParams (milliseconds); // se T v4l2 device parameters CHECK_ERROR (callback (mOldSystem); // v4l2 request buffers CHECK_ERROR (v4l2ReqBufs (); // v4l2 query buffers CHECK_ERROR (v4l2QueryBuf ()); // stream on the v4l2 device CHECK_ERROR (v4l2StartStreaming (); return OK;} the author transplanted tryFmt () to find the corresponding fmt. There will be a parameter Association, for example, the fmt Format of the input CSI, the CSI output data format, and the CSI data interface type are as follows: [cpp] struct v4l2_fmtdesc fmtdesc; fmtdesc. type = V4L2_BUF_TYPE_VIDEO_CA PTURE; for (int I = 0; I <12; I ++) {fmtdesc. index = I; if (-1 = ioctl (mV4l2Handle, VIDIOC_ENUM_FMT, & fmtdesc) {break;} LOGV ("format index = % d, name = % s, v4l2 pixel format = % x \ n ", I, fmtdesc. description, fmtdesc. pixelformat); if (fmtdesc. pixelformat = format) {return OK;} [cpp]} set the video parameter; [cpp] struct v4l2_format format; LOGD ("#################### VIDIOC_S_PARM \ n"); memset (& format, 0, sizeof (format); format. type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format. fmt. pix. width = mVideoWidth; format. fmt. pix. height = mVideoHeight; format. fmt. pix. pixelformat = mVideoFormat; // pix_fmt format. fmt. pix. field = V4L2_FIELD_NONE; ret = ioctl (mV4l2Handle, VIDIOC_S_FMT, & format); if (ret <0) {LOGE ("VIDIOC_S_FMT Failed: % s", strerror (errno )); return ret;} starts a thread to read data frames and process them out. In this thread, you also need to add real-time detection of the video signal and the signal standard, whether NTSC or PAL. The monitoring code is as follows: [cpp] struct v4l2_control ctrl; ctrl. value = 0; ctrl. id = V4L2_CID_BRIGHTNESS;/* just use this channel to read fmt & detect signals */ret = ioctl (mV4l2Handle, VIDIOC_G_CTRL, & ctrl); if (ret <0) {LOGE ("vidioc_g_ctrl: % s", strerror (errno);} LOGE ("get_system ctrl. value 0x % 02x ", ctrl. value); mDetectcvbsSignal = (ctrl. value & 0x10) = 0x10 )? 0: 1;/* bit4 1: no signal 0: has signal */fmt = ctrl. value & 0x7; if (0 = fmt) | (1 = fmt) * _ system = 0; /* NTSC */else * _ system = 1;/* PAL */The author made some changes in the processing of the signal standard, because these two formats are different in size, but we can use a larger buffer, so we do not need to reset these buffers, you only need to control the data size of the buffer, Which is easy. At the same time, I found that the NTSC standard had a dirty data of more than a dozen pixels at the beginning, and the display was messy, in this way, I can use a large buffer to cut down the entire data in the N system and move the starting address to the next point. This is true and effective, and the native window operation is used in it, the buffer address of the data frame is directly assigned to the hwcoposer, that is, to the hardware driver in the kernel. This reduces data copying and reduces cpu usage, in this way, the main chip can do many other things. The Code is as follows: [cpp] int hight = 0; hight = (mOldSystem = 0 )? 480: 576; LOGV ("mOldSystem = % d, hight = % d \ n", mOldSystem, hight); [cpp] ret = native_window_set_buffers_geometryex (mPreviewWindow, mVideoWidth, hight, birthday, // */HWC_FORMAT_DEFAULT, HWC_FORMAT_YUV420PLANAR 0); if (ret! = NO_ERROR) {LOGE ("% s: Error in set_buffers_geometry % d-> % s" ,__ FUNCTION __,-ret, strerror (-ret )); return ret ;}.... <p>/* when NTSC shoud shift display buffer */overlay_para.bProgressiveSrc = 0; overlay_para.bTopFieldFirst = 1; overlay_para.pVideoInfo.frame_rate = 25000; if (1 = mOldSystem) {/* PAL */overlay_para.top_y = (unsigned int) buf. m. offset; overlay_para.top_c = (unsigned int) buf. m. offset + MVideoWidth * mVideoHeight;} else {/* NTSC */overlay_para.top_y = (unsigned int) buf. m. offset + 1440;/* 720*20 point */overlay_para.top_c = (unsigned int) buf. m. offset + mVideoWidth * mVideoHeight + 7200;/* 720*20*1/2 20 point */} overlay_para.bottom_y = 0; overlay_para.bottom_c = 0; overlay_para.number = 0; </p> <p> if (mOverlayFirstFrame) {LOGD ("first frame true"); overlay_para.first_frame_flg = 1; mOverlayFirstFrame = false;} else {bytes = 0 ;}</p> <p> ret = mPreviewWindow-> perform (mPreviewWindow, NATIVE_WINDOW_SETPARAMETER, distance, (uint32_t) & overlay_para); if (ret! = OK) {LOGE ("NATIVE_WINDOW_SETPARAMETER failed"); return ret; </p> HWC_FORMAT_YUV422PLANAR_UV_COMBINED is the custom format of the author. This format is not used in the Platform, in the hardware abstraction layer of hwc, you need to add the corresponding code implementation, and paste the following part: [cpp] case when: disp_format = DISP_FORMAT_YUV422; fb_mode = idle; disp_seq = DISP_SEQ_UYVY; break; of course, if you want to perform video recording in the future, you need to cut down the data frame and compress the encoding and storage files through the library on the multimedia side. For details, refer to the implementation in camera. The code at the hardware abstraction layer is almost the same. JNI and the application APK can be slightly modified on TVD, which is difficult and will not be detailed here. Paste an application after implementation!

Related Article

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: 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.