void video_render(long tick, int width, int height) { opengl_video_stage_config_t *config; static int num = 0; screen_width = width; screen_height = height; //glViewport(0, 0, width, height); glBindTexture(GL_TEXTURE_2D, texture); config = opengl_video_stage_get(); if (config->num_picture_decoded != num) { /* a new frame is available, update texture */ if ((config != NULL) && (config->data != NULL) && (config->num_picture_decoded > 0)) { vp_os_mutex_lock( &config->mutex ); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VIDEO_WIDTH, VIDEO_HEIGHT, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, config->data ); num = config->num_picture_decoded; vp_os_mutex_unlock( &config->mutex ); } } /* and draw it on the screen */ __android_log_print( ANDROID_LOG_INFO, "ARDrone", "screen_width=%d, screen_height=%d\n", screen_width, screen_height ); glDrawTexiOES(0, 0, 0, screen_width, screen_height); }
JNIEXPORT jboolean JNICALL Java_com_parrot_freeflight_activities_base_ParrotCardboardActivity_onUpdateVideoTextureOriNative(JNIEnv *env, jobject obj, jint program, jint textureId) { if (texture_initialized == FALSE) { init_texture(); texture_initialized = TRUE; } opengl_video_stage_config_t *config = opengl_video_stage_get(); if ((config != NULL) && (config->data != NULL) && (config->num_picture_decoded > current_num_picture_decoded)) { if (texture.image_size.width != config->widthImage) { recalculate_video_texture = TRUE; } texture.bytesPerPixel = config->bytesPerPixel; texture.image_size.width = config->widthImage; texture.image_size.height = config->heightImage; texture.texture_size.width = config->widthTexture; texture.texture_size.height = config->heightTexture; texture.format = config->format; texture.type = config->type; texture.data = config->data; texture.state = OPENGL_STATE_GENERATED; current_num_picture_decoded = config->num_picture_decoded; current_num_frames = config->num_frames; } if (recalculate_video_texture) { recalculate_video_texture_bounds(env, obj, &texture); recalculate_video_texture = FALSE; } if(texture.state == OPENGL_STATE_GENERATED) { // Load the texture in the GPU if (texture.data != NULL) { // LOGD("GL_BG_VIDEO_SPRITE", "fmt: %d, w: %f, h: %f, type: %d, data: %p", texture.format, texture.texture_size.width, texture.texture_size.height, texture.type, texture.data); // glTexSubImage2D(GL_TEXTURE_2D, 0, texture.texture_size.width/4, 0, texture.texture_size.width/2, texture.texture_size.height, texture.format, texture.type, texture.data); glActiveTexture(textureId); glBindTexture(GL_TEXTURE_2D, textureId); glTexImage2D(GL_TEXTURE_2D, 0, texture.format, texture.texture_size.width, texture.texture_size.height, 0, texture.format, texture.type, texture.data); texture.state = OPENGL_STATE_SEND_TO_GPU; return TRUE; } } return FALSE; }
JNIEXPORT jboolean JNICALL Java_com_vmc_ipc_view_gl_GLBGVideoSprite_getVideoFrameNative(JNIEnv *env, jobject obj, jobject bitmap, jfloatArray videoSize) { AndroidBitmapInfo info; void* pixels; int ret; jboolean result = FALSE; if (screen_size.width == 0 || screen_size.height == 0) return FALSE; if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) { return FALSE; } if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) { return FALSE; } opengl_video_stage_config_t *config = opengl_video_stage_get(); if ((config != NULL) && (config->data != NULL) && (config->num_picture_decoded > current_num_picture_decoded)) { if (texture.image_size.width != config->widthImage) { recalculate_video_texture = TRUE; } texture.bytesPerPixel = config->bytesPerPixel; texture.image_size.width = config->widthImage; texture.image_size.height = config->heightImage; texture.texture_size.width = config->widthTexture; texture.texture_size.height = config->heightTexture; texture.format = config->format; texture.type = config->type; texture.data = config->data; texture.state = OPENGL_STATE_GENERATED; current_num_picture_decoded = config->num_picture_decoded; current_num_frames = config->num_frames; } if (recalculate_video_texture && screen_size.width != 0 && screen_size.height != 0) { opengl_texture_scale_compute(&texture, screen_size, FIT_X); // LOGD("VIDEO", "Screen Widht: %f", screen_size.width); recalculate_video_texture = FALSE; } if (texture.state == OPENGL_STATE_GENERATED) { if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) { } result = TRUE; memcpy(pixels, texture.data, texture.image_size.width * texture.image_size.height * texture.bytesPerPixel); texture.state = OPENGL_STATE_SEND_TO_GPU; jfloat *body = env->GetFloatArrayElements(videoSize, 0); body[0] = (float)texture.image_size.width; body[1] = (float)texture.image_size.height; body[2] = (float)texture.scaleModelX; body[3] = (float)texture.scaleModelY; env->ReleaseFloatArrayElements(videoSize, body, 0); AndroidBitmap_unlockPixels(env, bitmap); } return result; }
JNIEXPORT jboolean JNICALL Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative(JNIEnv *env, jobject obj, jint program, jint textureId) { // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative"); if (texture_initialized == FALSE){// && videostream::IsVideoInited()) { init_texture(); texture_initialized = TRUE; } opengl_video_stage_config_t *config = opengl_video_stage_get(); #if 1 int width,height; #else int width = texture.texture_size.width; int height = texture.texture_size.height; #endif videostream::lock_disp_buffer(); if(videostream::GetVideoMetrics(&width,&height) != 0){ videostream::unlock_disp_buffer(); return FALSE; } if(width == 0 || height == 0){ LOGI("-->width or height is zero."); videostream::unlock_disp_buffer(); return FALSE; } config->widthImage = width; config->widthTexture = width; config->heightImage = height; config->heightTexture = height; config->data = videostream::GetYUVBuffer(); // if(((indexd++)*30 / 3000)%2==0){ // LOGI("-->------------------show 720p"); // width = 1280; // height = 720; // config->widthImage = width; // config->widthTexture = width; // config->heightImage = height; // config->heightTexture = height; // config->data = yuvbuffer720p.data; // } // else{ // LOGI("-->------------------show 360p"); // width = 640; // height = 360; // config->widthImage = width; // config->widthTexture = width; // config->heightImage = height; // config->heightTexture = height; // config->data = yuvbuffer360p.data; // } // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative1"); if ((config != NULL) && (config->data != NULL))// && (config->num_picture_decoded > current_num_picture_decoded)) { if (texture.image_size.width != config->widthImage) { recalculate_video_texture = TRUE; // LOGI("size has changed to (%d,%d)",width,height); // LOGI("size has changed to (%d,%d)",texture.image_size.width,config->widthImage); // createStream(width,height); indexf = 0; } // writeYUVData((char *)config->data,width,height); texture.bytesPerPixel = config->bytesPerPixel; texture.image_size.width = config->widthImage; texture.image_size.height = config->heightImage; texture.texture_size.width = config->widthTexture; texture.texture_size.height = config->heightTexture; texture.format = config->format; texture.type = config->type; texture.data = config->data; texture.state = OPENGL_STATE_GENERATED; current_num_picture_decoded = config->num_picture_decoded; current_num_frames = config->num_frames; } if (recalculate_video_texture) { recalculate_video_texture_bounds(env, obj, &texture); recalculate_video_texture = FALSE; } indexf++; if(indexf<10){ LOGI("-->recalculate_video_texture_bounds"); videostream::unlock_disp_buffer(); return TRUE; } else { indexf = 10; } if(texture.state == OPENGL_STATE_GENERATED) { // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative2"); // Load the texture in the GPU if (texture.data != NULL) { // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative3"); // renderFrame(); // LOGI("fmt: %d, w: %f, h: %f, type: %d, data: %p", texture.format, texture.texture_size.width, texture.texture_size.height, texture.type, texture.data); // glTexImage2D(GL_TEXTURE_2D, 0, texture.format, texture.texture_size.width, texture.texture_size.height, 0, texture.format, texture.type, texture.data); // checkGlError("glTexImage2D"); // LOGI("-->video size(%d,%d)",width,height); // char *p = (char *)videostream::GetYUVBuffer(); bindTexture(g_texYId, (char *)texture.data, width, height); bindTexture(g_texUId, (char *)texture.data + width * height, width/2, height/2); bindTexture(g_texVId, (char *)texture.data + width * height * 5 / 4, width/2, height/2); bindYUV(program); //MyStat(); videostream::unlock_disp_buffer(); texture.state = OPENGL_STATE_SEND_TO_GPU; return TRUE; } } return FALSE; /** LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative"); if (texture_initialized == FALSE && videostream::IsVideoInited()) { init_texture(); texture_initialized = TRUE; } opengl_video_stage_config_t *config = opengl_video_stage_get(); // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative1"); if ((config != NULL) && (config->data != NULL))// && (config->num_picture_decoded > current_num_picture_decoded)) { if (texture.image_size.width != config->widthImage) { recalculate_video_texture = TRUE; } texture.bytesPerPixel = config->bytesPerPixel; texture.image_size.width = config->widthImage; texture.image_size.height = config->heightImage; texture.texture_size.width = config->widthTexture; texture.texture_size.height = config->heightTexture; texture.format = config->format; texture.type = config->type; texture.data = config->data; texture.state = OPENGL_STATE_GENERATED; current_num_picture_decoded = config->num_picture_decoded; current_num_frames = config->num_frames; } if (recalculate_video_texture) { recalculate_video_texture_bounds(env, obj, &texture); recalculate_video_texture = FALSE; } if(texture.state == OPENGL_STATE_GENERATED) { // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative2"); // Load the texture in the GPU if (texture.data != NULL) { // LOGI("-->Java_com_vmc_ipc_view_gl_GLBGVideoSprite_onUpdateVideoTextureNative3"); renderFrame(); // LOGI("fmt: %d, w: %f, h: %f, type: %d, data: %p", texture.format, texture.texture_size.width, texture.texture_size.height, texture.type, texture.data); // glTexImage2D(GL_TEXTURE_2D, 0, texture.format, texture.texture_size.width, texture.texture_size.height, 0, texture.format, texture.type, texture.data); // checkGlError("glTexImage2D"); #if 1 int width,height; #else int width = texture.texture_size.width; int height = texture.texture_size.height; #endif videostream::lock_disp_buffer(); videostream::GetVideoMetrics(&width,&height); LOGI("-->video size(%d,%d)",width,height); char *p = (char *)videostream::GetYUVBuffer(); bindTexture(g_texYId, p, width, height); bindTexture(g_texUId, p + width * height, width/2, height/2); bindTexture(g_texVId, p + width * height * 5 / 4, width/2, height/2); bindYUV(program); //MyStat(); videostream::unlock_disp_buffer(); texture.state = OPENGL_STATE_SEND_TO_GPU; return TRUE; } } return FALSE; **/ }