Changeset 4925
- Timestamp:
- Sep 22, 2014 7:03:25 AM (10 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia-videodev/opengl_dev.h
r4821 r4925 41 41 42 42 /* Create OpenGL buffers. */ 43 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, 43 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct, 44 44 gl_buffers **glb); 45 45 /* Initialize OpenGL buffers. */ 46 46 pj_status_t pjmedia_vid_dev_opengl_init_buffers(gl_buffers *glb); 47 47 /* Render a texture. */ 48 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, 49 unsigned int texture, 50 unsigned int name); 48 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb,unsigned int width, 49 unsigned int height, void *pixels); 51 50 /* Destroy OpenGL buffers. */ 52 51 void pjmedia_vid_dev_opengl_destroy_buffers(gl_buffers *glb); -
pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h
r4704 r4925 59 59 * Native window handle on Windows. 60 60 */ 61 PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS 61 PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS, 62 63 /** 64 * Native view on iOS. 65 */ 66 PJMEDIA_VID_DEV_HWND_TYPE_IOS, 67 68 /** 69 * Native window handle on Android. 70 */ 71 PJMEDIA_VID_DEV_HWND_TYPE_ANDROID 62 72 63 73 } pjmedia_vid_dev_hwnd_type; … … 91 101 void *window; /**< Window */ 92 102 } ios; 103 struct { 104 void *window; /**< Native window */ 105 } android; 93 106 void *window; 94 107 } info; -
pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_opengl_dev.m
r4917 r4925 35 35 { 36 36 pjmedia_format_id pjmedia_format; 37 UInt32 iosgl_format;38 37 } iosgl_fmt_info; 39 38 … … 41 40 static iosgl_fmt_info iosgl_fmts[] = 42 41 { 43 {PJMEDIA_FORMAT_BGRA , kCVPixelFormatType_32BGRA} ,42 {PJMEDIA_FORMAT_BGRA} , 44 43 }; 45 44 … … 66 65 unsigned ts_inc; 67 66 pjmedia_rect_size vid_size; 67 const pjmedia_frame *frame; 68 68 69 69 gl_buffers *gl_buf; 70 70 GLView *gl_view; 71 71 EAGLContext *ogl_context; 72 CVOpenGLESTextureCacheRef vid_texture;73 CVImageBufferRef pb;74 void *pb_addr;75 CVOpenGLESTextureRef texture;76 72 }; 77 73 … … 154 150 155 151 /* Create GL buffers */ 156 pjmedia_vid_dev_opengl_create_buffers(stream->pool, &stream->gl_buf); 152 pjmedia_vid_dev_opengl_create_buffers(stream->pool, PJ_FALSE, 153 &stream->gl_buf); 157 154 158 155 [stream->ogl_context renderbufferStorage:GL_RENDERBUFFER … … 175 172 } 176 173 177 pjmedia_vid_dev_opengl_draw(stream->gl_buf, 178 (unsigned int)CVOpenGLESTextureGetTarget(stream->texture), 179 (unsigned int)CVOpenGLESTextureGetName(stream->texture)); 174 pjmedia_vid_dev_opengl_draw(stream->gl_buf, stream->vid_size.w, stream->vid_size.h, 175 stream->frame->buf); 180 176 } 181 177 … … 194 190 pj_status_t status = PJ_SUCCESS; 195 191 CGRect rect; 196 CVReturn err;197 192 198 193 strm = PJ_POOL_ZALLOC_T(pool, struct iosgl_stream); … … 228 223 if ((status = strm->status) != PJ_SUCCESS) { 229 224 PJ_LOG(3, (THIS_FILE, "Unable to create and init OpenGL buffers")); 230 goto on_error;231 }232 233 /* Create a new CVOpenGLESTexture cache */234 err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL,235 strm->ogl_context, NULL,236 &strm->vid_texture);237 if (err) {238 PJ_LOG(3, (THIS_FILE, "Unable to create OpenGL texture cache %d",239 err));240 status = PJMEDIA_EVID_SYSERR;241 225 goto on_error; 242 226 } … … 344 328 if (strm->param.disp_size.w == 0 || strm->param.disp_size.h == 0) 345 329 pj_memcpy(&strm->param.disp_size, &vfd->size, sizeof(vfd->size)); 346 347 /* Invalidate the buffer */ 348 if (strm->pb) { 349 CVPixelBufferRelease(strm->pb); 350 strm->pb = NULL; 351 } 352 330 353 331 return PJ_SUCCESS; 354 332 } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) { … … 411 389 { 412 390 struct iosgl_stream *stream = (struct iosgl_stream*)strm; 413 CVReturn err; 414 415 /* Pixel buffer will only create a wrapper for the frame's buffer, 416 * so if the frame buffer changes, we have to recreate pb 417 */ 418 if (!stream->pb || (frame->buf && stream->pb_addr != frame->buf)) { 419 if (stream->pb) { 420 CVPixelBufferRelease(stream->pb); 421 stream->pb = NULL; 422 } 423 err = CVPixelBufferCreateWithBytes(kCFAllocatorDefault, 424 stream->vid_size.w, 425 stream->vid_size.h, 426 kCVPixelFormatType_32BGRA, 427 frame->buf, 428 stream->vid_size.w * 4, 429 NULL, NULL, NULL, &stream->pb); 430 if (err) { 431 PJ_LOG(3, (THIS_FILE, "Unable to create pixel buffer %d", err)); 432 return PJMEDIA_EVID_SYSERR; 433 } 434 stream->pb_addr = frame->buf; 435 } 436 437 /* Create a CVOpenGLESTexture from the CVImageBuffer */ 438 err=CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, 439 stream->vid_texture, 440 stream->pb, NULL, 441 GL_TEXTURE_2D, GL_RGBA, 442 stream->vid_size.w, 443 stream->vid_size.h, 444 GL_BGRA, 445 GL_UNSIGNED_BYTE, 446 0, &stream->texture); 447 if (!stream->texture || err) { 448 PJ_LOG(3, (THIS_FILE, "Unable to create OpenGL texture %d", err)); 449 return PJMEDIA_EVID_SYSERR; 450 } 451 391 392 stream->frame = frame; 452 393 /* Perform OpenGL drawing in the main thread. */ 453 394 [stream->gl_view performSelectorOnMainThread:@selector(render) … … 457 398 458 399 [stream->ogl_context presentRenderbuffer:GL_RENDERBUFFER]; 459 460 /* Flush the CVOpenGLESTexture cache and release the texture */461 CVOpenGLESTextureCacheFlush(stream->vid_texture, 0);462 CFRelease(stream->texture);463 400 464 401 return PJ_SUCCESS; … … 487 424 iosgl_stream_stop(strm); 488 425 489 if (stream->pb) {490 CVPixelBufferRelease(stream->pb);491 stream->pb = NULL;492 }493 494 if (stream->vid_texture) {495 CFRelease(stream->vid_texture);496 stream->vid_texture = NULL;497 }498 499 426 if ([EAGLContext currentContext] == stream->ogl_context) 500 427 [EAGLContext setCurrentContext:nil]; -
pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c
r4821 r4925 27 27 #include <pjmedia-videodev/opengl_dev.h> 28 28 #ifdef PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES 29 # include <OpenGLES/ES2/gl.h> 30 # include <OpenGLES/ES2/glext.h> 29 # if PJ_ANDROID 30 # include <GLES2/gl2.h> 31 # include <GLES2/gl2ext.h> 32 # define GL_BGRA GL_RGBA 33 # else 34 # include <OpenGLES/ES2/gl.h> 35 # include <OpenGLES/ES2/glext.h> 36 # endif 31 37 #else 32 38 # include <GL/gl.h> … … 40 46 #define DEFAULT_FPS 15 41 47 42 #define LOG(a) 48 #if PJ_ANDROID 49 # define LOG(a) PJ_LOG(3, (THIS_FILE, a)) 50 #else 51 # define LOG(a) 52 #endif 43 53 44 54 enum { … … 70 80 /* OpenGL buffers structure. */ 71 81 struct gl_buffers { 72 GLuint frameBuf; 73 GLuint rendBuf; 74 GLuint directProg; 75 76 int rendBufW; 77 int rendBufH; 82 GLuint frameBuf; 83 GLuint rendBuf; 84 GLuint rendTex; 85 GLuint directProg; 86 87 int rendBufW; 88 int rendBufH; 89 pj_bool_t direct; 78 90 }; 79 91 … … 201 213 } 202 214 203 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, gl_buffers **glb) 215 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct, 216 gl_buffers **glb) 204 217 { 205 218 gl_buffers *glbuf = PJ_POOL_ZALLOC_T(pool, gl_buffers); … … 208 221 glDisable(GL_DEPTH_TEST); 209 222 210 glGenFramebuffers(1, &glbuf->frameBuf); 211 glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf); 212 213 glGenRenderbuffers(1, &glbuf->rendBuf); 214 glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf); 223 if (!(glbuf->direct = direct)) { 224 glGenFramebuffers(1, &glbuf->frameBuf); 225 glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf); 226 227 glGenRenderbuffers(1, &glbuf->rendBuf); 228 glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf); 229 } 230 231 glGenTextures(1, &glbuf->rendTex); 215 232 } 216 233 … … 222 239 GLchar *attribName[NUM_ATTRIBUTES] = { "position", "texCoord" }; 223 240 224 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, 225 &glb->rendBufW); 226 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, 227 &glb->rendBufH); 228 229 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 230 GL_RENDERBUFFER, glb->rendBuf); 231 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { 232 LOG("Unable to create frame buffer"); 233 return -1; 241 if (!glb->direct ) { 242 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, 243 &glb->rendBufW); 244 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, 245 &glb->rendBufH); 246 247 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 248 GL_RENDERBUFFER, glb->rendBuf); 249 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { 250 LOG("Unable to create frame buffer"); 251 return -1; 252 } 234 253 } 235 254 … … 246 265 } 247 266 248 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int texture,249 unsigned int name)267 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int width, 268 unsigned int height, void *pixels) 250 269 { 251 270 static const GLfloat squareVertices[] = { … … 258 277 0, 1, 1, 1, 0, 0, 1, 0 259 278 }; 260 GLenum tex = (GLenum) texture; 261 GLuint nam = (GLuint) name; 262 263 glBindTexture(tex, nam); 279 280 glBindTexture(GL_TEXTURE_2D, glb->rendTex); 264 281 265 282 /* Set texture parameters */ … … 269 286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 270 287 271 glBindFramebuffer(GL_FRAMEBUFFER, glb->frameBuf); 288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 289 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pixels); 290 291 glFlush(); 292 293 /* Do we render directly to the screen? */ 294 glBindFramebuffer(GL_FRAMEBUFFER, (glb->direct? 0: glb->frameBuf)); 272 295 273 296 /* Set the view port to the entire view */ 274 glViewport(0, 0, glb->rendBufW, glb->rendBufH); 297 glViewport(0, 0, (glb->direct? width: glb->rendBufW), 298 (glb->direct? height: glb->rendBufH)); 275 299 276 300 /* Draw the texture on the screen with OpenGL ES 2 */ … … 289 313 290 314 /* Present */ 291 glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 315 if (!glb->direct) 316 glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 292 317 293 318 return PJ_SUCCESS; … … 304 329 glDeleteRenderbuffers(1, &glb->rendBuf); 305 330 glb->rendBuf = 0; 331 } 332 333 if (glb->rendTex) { 334 glDeleteTextures(1, &glb->rendTex); 335 glb->rendTex = 0; 306 336 } 307 337
Note: See TracChangeset
for help on using the changeset viewer.