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_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; **/ }