Windows Mobile video call development record

Source: Internet
Author: User
Tags bmp image
System Architecture (do not Process audio calls temporarily ):

Get camera data --> encoding --> transmission-> decoding-> playback

1. Obtain camera data
You can use dshow to obtain 16 RGB or 24rgb values (omitted)

2. convert data to yuv420
// Conversion from RGB to yuv420
Int rgb2yuv_yr [256], rgb2yuv_yg [256], rgb2yuv_yb [256];
Int rgb2yuv_ur [256], rgb2yuv_ug [256], rgb2yuv_ubvr [256];
Int rgb2yuv_vg [256], rgb2yuv_vb [256];

Void initlookuptable ()
{
Int I;

For (I = 0; I <256; I ++) rgb2yuv_yr [I] = (float) 65.481 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_yg [I] = (float) 128.553 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_yb [I] = (float) 24.966 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_ur [I] = (float) 37.797 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_ug [I] = (float) 74.203 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_vg [I] = (float) 93.786 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_vb [I] = (float) 18.214 * (I <8 );
For (I = 0; I <256; I ++) rgb2yuv_ubvr [I] = (float) 112 * (I <8 );
}

//
// Convert from rgb24 to yuv420
//
Int convertrgb2yuv (int w, int H, unsigned char * BMP, unsigned int * YUV)
{

Unsigned int * u, * V, * y, * Uu, * vv;
Unsigned int * pu1, * pu2, * pu3, * pu4;
Unsigned int * pv1, * pv2, * pv3, * PV4;
Unsigned char * r, * g, * B;
Int I, J;

UU = new unsigned int [w * H];
VV = new unsigned int [w * H];

If (uu = NULL | vv = NULL)
Return 0;

Y = YUV;
U = Uu;
V = vv;

// Get R, G, B pointers from BMP image data ....
R = BMP;
G = BMP + 1;
B = BMP + 2;

// Get YUV values for RGB values...

For (I = 0; I {

For (j = 0; j <W; j ++)
{
* Y ++ = (rgb2yuv_yr [* r] + rgb2yuv_yg [* g] + rgb2yuv_yb [* B] + 1048576)> 16;
* U ++ = (-rgb2yuv_ur [* r]-rgb2yuv_ug [* g] + rgb2yuv_ubvr [* B] + 8388608)> 16;
* V ++ = (rgb2yuv_ubvr [* r]-rgb2yuv_vg [* g]-rgb2yuv_vb [* B] + 8388608)> 16;

R + = 3;
G + = 3;
B + = 3;
}

}

This is a classic conversion on the InternetCodeIt should be correct, but it cannot be converted correctly at first. Later, we changed all unsigned int to unsigned char, which can be converted, but the image is inverted and the color is green, classic is highly efficient.

The following describes another type of conversion:

Void readbmp (unsigned char * RGB, file * FP) // It is easy for debugging to load data with a local image
{
Int I, J;
Unsigned char temp;

Fseek (FP, 54, seek_set );

Fread (RGB + width * height * 3, 1, width * height * 3, FP); // read
For (I = height-1, j = 0; I> = 0; I --, J ++) // adjust the sequence
{
Memcpy (RGB + J * width * 3, RGB + width * height * 3 + I * width * 3, width * 3 );
}
// The sequence is adjusted here, so the image is in the normal direction. It can be seen that the first method does not perform data sequence conversion.
// Adjust the order
For (I = 0; (unsigned INT) I <width * height * 3; I + = 3)
{
Temp = RGB [I];
RGB [I] = RGB [I + 2];
RGB [I + 2] = temp;
}
}

Void convert (unsigned char * RGB, unsigned char * YUV)
{
// Variable Declaration
Unsigned int I, X, Y, J;
Unsigned char * Y = NULL;
Unsigned char * u = NULL;
Unsigned char * V = NULL;

Y = YUV;
U = YUV + width * height;
V = u + (width * Height)> 2 );

For (y = 0; y For (x = 0; x <width; X ++)
{
J = y * width + X;
I = J * 3;
Y [J] = (unsigned char) (DY (RGB [I], RGB [I + 1], RGB [I + 2]);

If (X % 2 = 1 & Y % 2 = 1)
{
J = (width> 1) * (Y> 1) + (x> 1 );
// The above I is still valid
U [J] = (unsigned char)
(DU (RGB [I], RGB [I + 1], RGB [I + 2]) +
Du (RGB [I-3], RGB [I-2], RGB [I-1]) +
Du (RGB [I-width * 3], RGB [I + 1-width * 3], RGB [I + 2-width * 3]) +
Du (RGB [i-3-WIDTH * 3], RGB [i-2-WIDTH * 3], RGB [i-1-WIDTH * 3])/4 );

V [J] = (unsigned char)
(DV (RGB [I], RGB [I + 1], RGB [I + 2]) +
DV (RGB [I-3], RGB [I-2], RGB [I-1]) +
DV (RGB [I-width * 3], RGB [I + 1-width * 3], RGB [I + 2-width * 3]) +
DV (RGB [i-3-WIDTH ** 3], RGB [i-2-WIDTH * 3], RGB [i-1-WIDTH * 3])/4 );
}

}
}

The second method is OK, which is converted to yuv420 and then compared with the original BMP. the naked eye can hardly tell the distortion. But ...... The efficiency is too low. The two conversions run on the same simulator. The first one is about 320-350 ms, and the second is about 6000 ms.
Comparison chart:

Second (no distortion, low efficiency) First (distortion, high efficiency)

In the following time, the deviation of the first conversion method will be solved as soon as possible.

OK ~ I didn't expect it to take a few minutes to adjust the order. The first method was done, and it seems that the display effect is better than the second method.
Figure:

11.13
Supports 144x176x120x160x240x320
Only 240x320 480x640
Then,

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.