How does OpenGL render video streams.

Source: Internet
Author: User

How does OpenGL render video streams.
Void render (void)
{
DWORD wait_result = dsvl_vs-& gt; waitfornextsample (100/60 );
// If (wait_result = wait_object_0)
{
# Ifdef _ debug
Frame_counter ++;
# Endif

// Dsvl_vs-> lock ();
If (succeeded (dsvl_vs-> checkoutmemorybuffer (& g_mbhandle, & g_ppixelbuffer )))
{
Glbindtexture (gl_texture_2d, g_texid [cube_tex]);
Gltexsubimage2d (gl_texture_2d, 0, 0, 0, cap_width, cap_height,
Gl_bgra, gl_unsigned_byte, (void *) g_ppixelbuffer );

G_timestamp = dsvl_vs-> getcurrenttimestamp ();
Dsvl_vs-> checkinmemorybuffer (g_mbhandle );
}
}

Glclear (gl_color_buffer_bit | gl_depth_buffer_bit); // clear the screen and the depth buffer

Glmatrixmode (gl_modelview); // select the modelview Matrix
Glloadidentity ();
Glmatrixmode (gl_projection );
Glpushmatrix ();
Glloadidentity ();

Float u_rt = (float) cap_width/tex_width;
Float v_rt = (float) cap_height/tex_height;

Gldisable (gl_depth_test );
Glbindtexture (gl_texture_2d, g_texid [cube_tex]);
Glbegin (gl_quads );
// Video backplate
Gltexcoord2f (0.0f, 0.0f); glvertex3f (-1.0f,-1.0f, 0.0f );
Gltexcoord2f (u_rt, 0.0f); glvertex3f (1.0f,-1.0f, 0.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (1.0f, 1.0f, 0.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (-1.0f, 1.0f, 0.0f );
Glend ();
Glenable (gl_depth_test );

Glpopmatrix ();

Glmatrixmode (gl_modelview); // select the modelview Matrix
Gltranslatef (0.0f, 0.0f,-5.0f );

 

Glrotatef (g_xrot, 1.0f, 0.0f, 0.0f );
Glrotatef (g_yrot, 0.0f, 1.0f, 0.0f );
Glrotatef (g_zrt, 0.0f, 0.0f, 1.0f );

Glbindtexture (gl_texture_2d, g_texid [cube_tex]);

If (showrotatingcube)
{
Glbegin (gl_quads );
// Front face
Gltexcoord2f (0.0f, 0.0f); glvertex3f (-1.0f,-1.0f, 1.0f );
Gltexcoord2f (u_rt, 0.0f); glvertex3f (1.0f,-1.0f, 1.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (1.0f, 1.0f, 1.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (-1.0f, 1.0f, 1.0f );
// Back face
Gltexcoord2f (u_rt, 0.0f); glvertex3f (-1.0f,-1.0f,-1.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (-1.0f, 1.0f,-1.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (1.0f, 1.0f,-1.0f );
Gltexcoord2f (0.0f, 0.0f); glvertex3f (1.0f,-1.0f,-1.0f );
// Top face
Gltexcoord2f (0.0f, v_rt); glvertex3f (-1.0f, 1.0f,-1.0f );
Gltexcoord2f (0.0f, 0.0f); glvertex3f (-1.0f, 1.0f, 1.0f );
Gltexcoord2f (u_rt, 0.0f); glvertex3f (1.0f, 1.0f, 1.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (1.0f, 1.0f,-1.0f );
// Bottom face
Gltexcoord2f (u_rt, v_rt); glvertex3f (-1.0f,-1.0f,-1.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (1.0f,-1.0f,-1.0f );
Gltexcoord2f (0.0f, 0.0f); glvertex3f (1.0f,-1.0f, 1.0f );
Gltexcoord2f (u_rt, 0.0f); glvertex3f (-1.0f,-1.0f, 1.0f );
// Right face
Gltexcoord2f (u_rt, 0.0f); glvertex3f (1.0f,-1.0f,-1.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (1.0f, 1.0f,-1.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (1.0f, 1.0f, 1.0f );
Gltexcoord2f (0.0f, 0.0f); glvertex3f (1.0f,-1.0f, 1.0f );
// Left face
Gltexcoord2f (0.0f, 0.0f); glvertex3f (-1.0f,-1.0f,-1.0f );
Gltexcoord2f (u_rt, 0.0f); glvertex3f (-1.0f,-1.0f, 1.0f );
Gltexcoord2f (u_rt, v_rt); glvertex3f (-1.0f, 1.0f, 1.0f );
Gltexcoord2f (0.0f, v_rt); glvertex3f (-1.0f, 1.0f,-1.0f );
Glend ();
}

G_xrot + = 0.3f;
G_yrot + = 0.2f;
G_zrt + = 0.4f;

// Swap the buffers to become our rendering visible
Gluswapbuffers ();
}

As for how to implement an available solution on the iPhone, further research and experiments are required. the friend yesterday may disappoint you. because I am not familiar with OpenGL ES either. after all, there are some differences with OpenGL.

You can use mediaplayer framework to complete the process.

Http://developer.apple.com/DOCUMENTATION/quicktime/Conceptual/QT7UpdateGuide/Chapter02/chapter_2_section_7.html#//apple_ref/doc/uid/TP40001163-CH313-BBCFCEII

 

Playing video files in iPhone OS
IPhone OS supports the ability to play back video files directly from your application using the media player framework (mediaplayer. framework ). video Playback is supported in full screen mode only and can be used by game developers who want to play cut scene animations or by other developers who want to play media files. when you start a video from your application, the media player interface takes over, fading the screen to black and then fading in the video content. you can play a video with or without transport controls; enabling transport controls lets the user pause or adjust the playback of the video. if you do not enable these controls, the video plays until completion or until you explicitly stop it in your code.

To initiate video playback, you must know the URL of the file you want to play. for files your application provides, this wowould typically be a pointer to a file in your applications bundle; however, it can also be a pointer to a file on a remote server or elsewhere in the directory containing your application. you use this URL to instantiate a new instance of the mpmovieplayercontroller class. this class presides over the playback of your video file and manages user interactions, such user taps in the transport controls (if shown ). to initiate playback, simply call the play method of the controller.

Listing 4-4 shows a sample method that playbacks the video at the specified URL. the play method is an asynchronous call that returns control to the caller while the movie plays. the movie controller loads the movie in a full-screen view, and animates the movie into place on top of the applications existing content. when playback is finished, the movie controller sends a notification to the object, which releases the movie controller now that it is no longer needed.

Listing 4-4 playing full screen movies.
-(Void) playmovieaturl :( nsurl *) theurl
{
Mpmovieplayercontroller * theplayer = [[mpmovieplayercontroller alloc] initwithcontenturl: theurl];
 
Theplayer. scalingmode = mpmoviescalingmodeaspectfill;
Theplayer. usercanshowtransportcontrols = no;
 
// Register for the playback finished notification.
[[Nsicationcenter center defacenter center] addobserver: Self
Selector: @ selector (mymoviefinishedcallback :)
Name: mpmovieplayerplaybackdidfinishnotification
Theplayer];
 
// Movie playback is asynchronous, so this method returns immediately.
[Theplayer play];
}
 
// When the movie is done, release the controller.
-(Void) mymoviefinishedcallback :( nsnotification *) anotification
{
Mpmovieplayercontroller * theplayer = [anotification object];
 
[[Nsicationcenter center defacenter center] removeobserver: Self
Name: mpmovieplayerplaybackdidfinishnotification
Theplayer];
 
// Release the movie instance created in playmovieaturl:
[Theplayer release];
}

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.