Arm11 hardware codec routine

Source: Internet
Author: User

Http://space.itpub.net/13771794/viewspace-619614

Arm11 hardware codec routine
The arm11 hardware codec routine provided by Hua Heng.

Abstract: This article introduces how to transmit the data collected by cameras over the network after hardware Encoding Based on the hh3c platform. The client (Linux) receives and displays the data in real time over the network; this article mainly introduces the hardware encoding feature and v4l2 programming of the h264 of.

Keywords: initi6410 H.264 video monitoring v4l2

0 Introduction
Hhs36410 is a low-power, high-performanceEmbeddedDevelopment Board, with Samsung 667 ARM1176JZF-S processor, the maximum clock speed up to MHz; the integrated multimedia codecs (MFC) inside the s3c246410 support MPEG4/H.263/h. 264 encoding and decoding, and supports vc1 decoding, the performance can reach full-duplex 30fps @ 640x480 simultaneous codec and half-duplex 30fps @ 720x480 or 25fps @ 720x576 codec.
H. the 264/AVC standard is a set of wide-area standards that take into account both broadcasting and telecommunications, covering from low-bit-rate communication to high-definition television. Compared with the previous standards, it has a higher compression rate, high-quality images, and fault tolerance functions, and have strong network adaptability.

1. Overall Design
The monitoring system consists of a monitoring front-end, a monitoring terminal, and a network. The monitoring front-end is an embedded Linux system that uses the camera if camera (saa7113) to collect data, it is also sent to the hardware encoding/decoding (MFC) module, and the obtained h264 compressed data is packaged and sent to the IP network. The monitoring terminal (Linux) receives data packets over the network and decoded for real-time playback. Overall framework 1:
 
Figure 1. Overall framework
The entire embedded video acquisition system consistsSoftwareAnd hardware. In terms of hardware, the camera data is received through the camera if interface with the core of the processor. After being encoded by the MFC hardware, the camera data is sent through the dm9000 and UART is used as the development debugging interface. In terms of software, the boot program and the Linux Kernel, the device drivers form a basic embedded operating environment. The application layer is responsible for video collection, compression, and transmission.

2 Software Design
The software design includes two parts: Embedded system construction and application software. The embedded system is constructed according to the user manual of huaheng technology, including bootloader, Linux kernel, cross compiler, and driver; the following describes the application software design:

Monitoring front-end:
The monitoring front-end mainly includes the video acquisition module and the video compression and encoding module.
The video capture module uses the v4l2 interface to collect camera data into the buffer zone. The video compression module calls the MFC driver to compress the yuv420 data and specify the encoding parameters. ExampleCodeAs follows:

Cam_fp = open (cam_name, o_rdwr); // enable the camera Device
...
Mfc_fd = open (mfc_dev_name, o_rdwr | o_ndelay); // open the MFC Device
...
ADDR = (char *) MMAP (0, buf_size, prot_read | prot_write, map_shared, mfc_fd, 0); // MMAP MFC
// Set the encoding Parameters
Enc_init.in_width = out_width;
Enc_init.in_height = out_height;
Enc_init.in_framerateres = atoi (argv [2]);
Enc_init.in_frameratediv = 0;
Enc_init.in_bitrate = atoi (argv [3]);
Enc_init.in_gopnum = atoi (argv [4]);

IOCTL (mfc_fd, ioctl_mfc_h1__enc_init, & enc_init );

Frame_size = (enc_init.in_width * enc_init.in_height * 3)> 1;
// Obtain the buffer address entered by MFC
Get_buf_addr.in_usr_data = (INT) ADDR;
IOCTL (mfc_fd, ioctl_mfc_get_fram_buf_addr, & get_buf_addr );
In_buf = (char *) get_buf_addr.out_buf_addr;
// Obtain the MFC output buffer address
Get_buf_addr.in_usr_data = (INT) ADDR;
IOCTL (mfc_fd, ioctl_mfc_get_line_buf_addr, & get_buf_addr );
Out_buf = (char *) get_buf_addr.out_buf_addr;
// V4l2 Programming
IOCTL (cam_fp, vidioc_querycap, & Cap );
// Select input/output
IOCTL (cam_fp, vidioc_s_input, & Index );
IOCTL (cam_fp, vidioc_s_output, & Index );
// Set the format. Note that the output must be in yuv420 format.
IOCTL (cam_fp, vidioc_g_fbuf, & FB );
FB. Capability = CAP. capabilities;
FB. FMT. width = out_width;
FB. FMT. Height = out_height;
FB. FMT. pixelformat = v4l2_pix_fmt_yuv420;
IOCTL (cam_fp, vidioc_s_fbuf, & FB );

On = 1;
IOCTL (cam_fp, vidioc_overlay, & on );

While (1)
{
...
// Receives the camera data to the input buffer of the MFC.
Read (cam_fp, in_buf, (out_width * out_height * 3/2 ));
// Control the start encoding of MFC
IOCTL (mfc_fd, ioctl_mfc_h1__enc_exe, & enc_exe );
// Send the size and data of the encoded POST-Frame
Send (net_fd, & enc_exe.out_encoded_size, 2, 0 );
Send (net_fd, out_buf, enc_exe.out_encoded_size, 0 );
...
}
Setting the output of the camera to the input of MFC can save one memory operation.

Monitoring terminal:
The monitoring terminal is a PC running Linux. It is mainly responsible for receiving compressed packages from the network, decoding and displaying them using SDL and avcodec. The sample code is as follows:
...
While (1)
{
...
// Receives the compressed package
Recv (sock_fd, & size, 2, msg_waitall );
Recv (sock_fd, & frame_buf [0], size, msg_waitall );
// Initialize avcodec
If (! Pcodecctx)
{
Avcodec_init ();
Pcodecctx = avcodec_alloc_context ();
Avcodec_open (pcodecctx, pcodec );
// Set parameters
If (pcodec-> capabilities & codec_cap_truncated)
{
Pcodecctx-> flags | = codec_flag_truncated;
Pcodecctx-> Height = 480;
Pcodecctx-> width = 640;
}
Pframe = avcodec_alloc_frame ();
Avcodec_decode_video (pcodecctx, pframe, & frame_finishd, sps_buf, sizeof (sps_buf ));
// Initialize SDL
Sdl_init (sdl_init_video );
Screen = sdl_setvideomode (pcodecctx-> width, pcodecctx-> height, 0, 0 );
YUV = sdl_createyuvoverlay (pcodecctx-> width, pcodecctx-> height, sdl_yv12_overlay, screen );

Sdl_wm_setcaption (BUF, "h264/tcp ");
Rect. Y = rect. x = 0;
Rect. W = pcodecctx-> width;
Rect. H = pcodecctx-> height;

PICT. Data [0] = YUV-> pixels [0];
PICT. Data [1] = YUV-> pixels [2];
PICT. Data [2] = YUV-> pixels [1];

PICT. linesize [0] = YUV-> pitches [0];
PICT. linesize [1] = YUV-> pitches [2];
PICT. linesize [2] = YUV-> pitches [1];
}

If (pcodecctx)
{
// Decode the video stream
Avcodec_decode_video (pcodecctx, pframe, & frame_finishd, frame_buf, size );
If (frame_finishd & YUV)
{
Sdl_lockyuvoverlay (YUV );
If ((! Swsctx &&! (Swsctx = sws_getcontext (pcodecctx-> width,
Pcodecctx-> height, pcodecctx-> pix_fmt,
Pcodecctx-> width, pcodecctx-> height,
Pix_fmt_yuv420p, sws_bicubic, null, null) |
Sws_scale (swsctx, pframe-> data, pframe-> linesize, 0,
Pcodecctx-> height, Pict. Data, Pict. linesize ))
Perror ("SWS ");

Sdl_unlockyuvoverlay (YUV );
// Display
Sdl_displayyuvoverlay (YUV, & rect );
}
}
}
The above program compilation requires libsdl, libavcodec, and libswscale.

3 Summary
The system collects, encodes, and transmits data in real time based on, and basically implements the video monitoring function,TestThe acquisition, encoding, and transmission of VGA images can reach 25 FPS. After multi-thread optimization, the VGA resolution image can be higher. after encoding 264, the average size of each frame is only about 12 kb, which occupies a small amount of network bandwidth.

[Ezstreamsvr] arm11 codec (v4l collects FFMPEG encoding and decodes H.264 + SDL playback)

Http://bbs.rosoo.net/thread-1030-1-1.html

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.