Index: pjproject/trunk/pjmedia/include/pjmedia-videodev/opengl_dev.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia-videodev/opengl_dev.h	(revision 4924)
+++ pjproject/trunk/pjmedia/include/pjmedia-videodev/opengl_dev.h	(revision 4925)
@@ -41,12 +41,11 @@
 
 /* Create OpenGL buffers. */
-void        pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool,
+void        pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct,
                                                   gl_buffers **glb);
 /* Initialize OpenGL buffers. */
 pj_status_t pjmedia_vid_dev_opengl_init_buffers(gl_buffers *glb);
 /* Render a texture. */
-pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb,
-                                        unsigned int texture,
-                                        unsigned int name);
+pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb,unsigned int width,
+                                        unsigned int height, void *pixels);
 /* Destroy OpenGL buffers. */
 void        pjmedia_vid_dev_opengl_destroy_buffers(gl_buffers *glb);
Index: pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h	(revision 4924)
+++ pjproject/trunk/pjmedia/include/pjmedia-videodev/videodev.h	(revision 4925)
@@ -59,5 +59,15 @@
      * Native window handle on Windows.
      */
-    PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS
+    PJMEDIA_VID_DEV_HWND_TYPE_WINDOWS,
+
+    /**
+     * Native view on iOS.
+     */
+    PJMEDIA_VID_DEV_HWND_TYPE_IOS,
+
+    /**
+     * Native window handle on Android.
+     */
+    PJMEDIA_VID_DEV_HWND_TYPE_ANDROID
 
 } pjmedia_vid_dev_hwnd_type;
@@ -91,4 +101,7 @@
 	    void    *window;    /**< Window	*/
 	} ios;
+	struct {
+	    void    *window;    /**< Native window */
+	} android;
 	void 	    *window;
     } info;
Index: pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_opengl_dev.m
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_opengl_dev.m	(revision 4924)
+++ pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_opengl_dev.m	(revision 4925)
@@ -35,5 +35,4 @@
 {
     pjmedia_format_id   pjmedia_format;
-    UInt32		iosgl_format;
 } iosgl_fmt_info;
 
@@ -41,5 +40,5 @@
 static iosgl_fmt_info iosgl_fmts[] =
 {
-    {PJMEDIA_FORMAT_BGRA, kCVPixelFormatType_32BGRA} ,
+    {PJMEDIA_FORMAT_BGRA} ,
 };
 
@@ -66,12 +65,9 @@
     unsigned                ts_inc;
     pjmedia_rect_size       vid_size;
+    const pjmedia_frame    *frame;
     
     gl_buffers                  *gl_buf;
     GLView                      *gl_view;
     EAGLContext                 *ogl_context;
-    CVOpenGLESTextureCacheRef    vid_texture;
-    CVImageBufferRef             pb;
-    void                        *pb_addr;
-    CVOpenGLESTextureRef         texture;
 };
 
@@ -154,5 +150,6 @@
     
     /* Create GL buffers */
-    pjmedia_vid_dev_opengl_create_buffers(stream->pool, &stream->gl_buf);
+    pjmedia_vid_dev_opengl_create_buffers(stream->pool, PJ_FALSE,
+                                          &stream->gl_buf);
     
     [stream->ogl_context renderbufferStorage:GL_RENDERBUFFER
@@ -175,7 +172,6 @@
     }
     
-    pjmedia_vid_dev_opengl_draw(stream->gl_buf,
-        (unsigned int)CVOpenGLESTextureGetTarget(stream->texture),
-        (unsigned int)CVOpenGLESTextureGetName(stream->texture));
+    pjmedia_vid_dev_opengl_draw(stream->gl_buf, stream->vid_size.w, stream->vid_size.h,
+                                stream->frame->buf);
 }
 
@@ -194,5 +190,4 @@
     pj_status_t status = PJ_SUCCESS;
     CGRect rect;
-    CVReturn err;
     
     strm = PJ_POOL_ZALLOC_T(pool, struct iosgl_stream);
@@ -228,15 +223,4 @@
     if ((status = strm->status) != PJ_SUCCESS) {
         PJ_LOG(3, (THIS_FILE, "Unable to create and init OpenGL buffers"));
-        goto on_error;
-    }
-    
-    /*  Create a new CVOpenGLESTexture cache */
-    err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL,
-                                       strm->ogl_context, NULL,
-                                       &strm->vid_texture);
-    if (err) {
-        PJ_LOG(3, (THIS_FILE, "Unable to create OpenGL texture cache %d",
-                   err));
-        status = PJMEDIA_EVID_SYSERR;
         goto on_error;
     }
@@ -344,11 +328,5 @@
         if (strm->param.disp_size.w == 0 || strm->param.disp_size.h == 0)
             pj_memcpy(&strm->param.disp_size, &vfd->size, sizeof(vfd->size));
-        
-        /* Invalidate the buffer */
-        if (strm->pb) {
-            CVPixelBufferRelease(strm->pb);
-            strm->pb = NULL;
-        }
-        
+
 	return PJ_SUCCESS;
     } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) {
@@ -411,43 +389,6 @@
 {
     struct iosgl_stream *stream = (struct iosgl_stream*)strm;
-    CVReturn err;
-
-    /* Pixel buffer will only create a wrapper for the frame's buffer,
-     * so if the frame buffer changes, we have to recreate pb
-     */
-    if (!stream->pb || (frame->buf && stream->pb_addr != frame->buf)) {
-        if (stream->pb) {
-            CVPixelBufferRelease(stream->pb);
-            stream->pb = NULL;
-        }
-        err = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
-                                           stream->vid_size.w,
-                                           stream->vid_size.h,
-                                           kCVPixelFormatType_32BGRA,
-                                           frame->buf,
-                                           stream->vid_size.w * 4,
-                                           NULL, NULL, NULL, &stream->pb);
-        if (err) {
-            PJ_LOG(3, (THIS_FILE, "Unable to create pixel buffer %d", err));
-            return PJMEDIA_EVID_SYSERR;
-        }
-        stream->pb_addr = frame->buf;
-    }
-
-    /* Create a CVOpenGLESTexture from the CVImageBuffer */
-    err=CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
-                                                     stream->vid_texture,
-                                                     stream->pb, NULL,
-                                                     GL_TEXTURE_2D, GL_RGBA,
-                                                     stream->vid_size.w,
-                                                     stream->vid_size.h,
-                                                     GL_BGRA,
-                                                     GL_UNSIGNED_BYTE,
-                                                     0, &stream->texture);
-    if (!stream->texture || err) {
-        PJ_LOG(3, (THIS_FILE, "Unable to create OpenGL texture %d", err));
-        return PJMEDIA_EVID_SYSERR;
-    }
-    
+    
+    stream->frame = frame;
     /* Perform OpenGL drawing in the main thread. */
     [stream->gl_view performSelectorOnMainThread:@selector(render)
@@ -457,8 +398,4 @@
     
     [stream->ogl_context presentRenderbuffer:GL_RENDERBUFFER];
- 
-    /* Flush the CVOpenGLESTexture cache and release the texture */
-    CVOpenGLESTextureCacheFlush(stream->vid_texture, 0);
-    CFRelease(stream->texture);
     
     return PJ_SUCCESS;
@@ -487,14 +424,4 @@
     iosgl_stream_stop(strm);
     
-    if (stream->pb) {
-        CVPixelBufferRelease(stream->pb);
-        stream->pb = NULL;
-    }
-    
-    if (stream->vid_texture) {
-        CFRelease(stream->vid_texture);
-        stream->vid_texture = NULL;
-    }
-
     if ([EAGLContext currentContext] == stream->ogl_context)
         [EAGLContext setCurrentContext:nil];
Index: pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c	(revision 4924)
+++ pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c	(revision 4925)
@@ -27,6 +27,12 @@
 #include <pjmedia-videodev/opengl_dev.h>
 #ifdef PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES
-#   include <OpenGLES/ES2/gl.h>
-#   include <OpenGLES/ES2/glext.h>
+#   if PJ_ANDROID
+#       include <GLES2/gl2.h>
+#       include <GLES2/gl2ext.h>
+#	define GL_BGRA GL_RGBA
+#   else
+#       include <OpenGLES/ES2/gl.h>
+#       include <OpenGLES/ES2/glext.h>
+#   endif
 #else
 #   include <GL/gl.h>
@@ -40,5 +46,9 @@
 #define DEFAULT_FPS		15
 
-#define LOG(a)
+#if PJ_ANDROID
+#    define LOG(a) PJ_LOG(3, (THIS_FILE, a))
+#else
+#    define LOG(a)
+#endif
 
 enum {
@@ -70,10 +80,12 @@
 /* OpenGL buffers structure. */
 struct gl_buffers {
-    GLuint  frameBuf;
-    GLuint  rendBuf;
-    GLuint  directProg;
-    
-    int     rendBufW;
-    int     rendBufH;
+    GLuint 	frameBuf;
+    GLuint  	rendBuf;
+    GLuint  	rendTex;
+    GLuint  	directProg;
+    
+    int     	rendBufW;
+    int     	rendBufH;
+    pj_bool_t 	direct;
 };
 
@@ -201,5 +213,6 @@
 }
 
-void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, gl_buffers **glb)
+void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct,
+					   gl_buffers **glb)
 {
     gl_buffers *glbuf = PJ_POOL_ZALLOC_T(pool, gl_buffers);
@@ -208,9 +221,13 @@
     glDisable(GL_DEPTH_TEST);
     
-    glGenFramebuffers(1, &glbuf->frameBuf);
-    glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf);
-    
-    glGenRenderbuffers(1, &glbuf->rendBuf);
-    glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf);
+    if (!(glbuf->direct = direct)) {
+    	glGenFramebuffers(1, &glbuf->frameBuf);
+    	glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf);
+    
+    	glGenRenderbuffers(1, &glbuf->rendBuf);
+    	glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf);
+    }
+    
+    glGenTextures(1, &glbuf->rendTex);
 }
 
@@ -222,14 +239,16 @@
     GLchar *attribName[NUM_ATTRIBUTES] = { "position", "texCoord" };
     
-    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH,
-                                 &glb->rendBufW);
-    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT,
-                                 &glb->rendBufH);
-    
-    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                              GL_RENDERBUFFER, glb->rendBuf);
-    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
-        LOG("Unable to create frame buffer");
-        return -1;
+    if (!glb->direct ) {
+    	glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH,
+                                     &glb->rendBufW);
+    	glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT,
+                                     &glb->rendBufH);
+    
+    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                  GL_RENDERBUFFER, glb->rendBuf);
+    	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
+            LOG("Unable to create frame buffer");
+            return -1;
+        }
     }
     
@@ -246,6 +265,6 @@
 }
 
-pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int texture,
-                                        unsigned int name)
+pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int width,
+                                        unsigned int height, void *pixels)
 {
     static const GLfloat squareVertices[] = {
@@ -258,8 +277,6 @@
         0, 1, 1, 1, 0, 0, 1, 0
     };
-    GLenum tex = (GLenum) texture;
-    GLuint nam = (GLuint) name;
-
-    glBindTexture(tex, nam);
+
+    glBindTexture(GL_TEXTURE_2D, glb->rendTex);
     
     /* Set texture parameters */
@@ -269,8 +286,15 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     
-    glBindFramebuffer(GL_FRAMEBUFFER, glb->frameBuf);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height,
+    		 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pixels);
+    
+    glFlush();
+    
+    /* Do we render directly to the screen? */
+    glBindFramebuffer(GL_FRAMEBUFFER, (glb->direct? 0: glb->frameBuf));
     
     /* Set the view port to the entire view */
-    glViewport(0, 0, glb->rendBufW, glb->rendBufH);
+    glViewport(0, 0, (glb->direct? width: glb->rendBufW),
+               (glb->direct? height: glb->rendBufH));
     
     /* Draw the texture on the screen with OpenGL ES 2 */
@@ -289,5 +313,6 @@
     
     /* Present */
-    glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf);
+    if (!glb->direct)
+        glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf);
     
     return PJ_SUCCESS;
@@ -304,4 +329,9 @@
         glDeleteRenderbuffers(1, &glb->rendBuf);
         glb->rendBuf = 0;
+    }
+    
+    if (glb->rendTex) {
+        glDeleteTextures(1, &glb->rendTex);
+        glb->rendTex = 0;
     }
     
