opengl 如何渲染视频流.

opengl 如何渲染视频流.
void render(void)  
{
 DWORD wait_result = dsvl_vs->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_zrot,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_zrot += 0.4f;

    // Swap The Buffers To Become Our Rendering Visible
    glutSwapBuffers ( );
}

至于iphone上如何实现一个可用的解决方案,有待于进一步研究和实验. 昨天那位朋友, 可能让你失望了. 因为我也不是很熟opengl es. 毕竟又有些与opengl 不同之处。

 也许可以用 MediaPlayer Framework 来完成.

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 would 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.
    [[NSNotificationCenter defaultCenter] 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];
 
    [[NSNotificationCenter defaultCenter] removeObserver:self
                name:MPMoviePlayerPlaybackDidFinishNotification
                thePlayer];
 
    // Release the movie instance created in playMovieAtURL:
    [thePlayer release];
}

原文地址:https://www.cnblogs.com/cnsoft/p/1363848.html