5 * Created by Karl Leplat on 22/02/10.
6 * Copyright 2010 Parrot SA. All rights reserved.
9 #include "opengl_stage.h"
11 #include <android/log.h>
13 static opengl_video_stage_config_t opengl_video_config;
15 const vp_api_stage_funcs_t opengl_video_stage_funcs = {
16 (vp_api_stage_handle_msg_t) NULL,
17 (vp_api_stage_open_t) opengl_video_stage_open,
18 (vp_api_stage_transform_t) opengl_video_stage_transform,
19 (vp_api_stage_close_t) opengl_video_stage_close
22 C_RESULT opengl_video_stage_open(vlib_stage_decoding_config_t *cfg)
24 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Enter in opengl_video_stage_open\n" );
25 vp_os_mutex_init( &opengl_video_config.mutex );
27 vp_os_mutex_lock( &opengl_video_config.mutex );
28 opengl_video_config.data = vp_os_malloc(VIDEO_HEIGHT * VIDEO_WIDTH * 4);
29 vp_os_memset(opengl_video_config.data, 0x0, VIDEO_HEIGHT * VIDEO_WIDTH * 4);
30 vp_os_mutex_unlock( &opengl_video_config.mutex );
32 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Exit opengl_video_stage_open\n" );
37 C_RESULT opengl_video_stage_transform(vlib_stage_decoding_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
39 vp_os_mutex_lock( &out->lock );
41 if(out->status == VP_API_STATUS_INIT)
43 out->status = VP_API_STATUS_PROCESSING;
46 if( in->status == VP_API_STATUS_ENDED )
48 out->status = in->status;
51 if(out->status == VP_API_STATUS_PROCESSING )
53 vp_os_mutex_lock( &opengl_video_config.mutex );
55 if(cfg->num_picture_decoded > opengl_video_config.num_picture_decoded)
57 opengl_video_config.num_picture_decoded = cfg->num_picture_decoded;
59 opengl_video_config.bytesPerPixel = 2;
60 opengl_video_config.widthImage = cfg->controller.width;
61 opengl_video_config.heightImage = cfg->controller.height;
63 if(opengl_video_config.bytesPerPixel == 2)
65 opengl_video_config.format = GL_RGB;
66 opengl_video_config.type = GL_UNSIGNED_SHORT_5_6_5;
69 if (opengl_video_config.data != NULL)
71 vp_os_memcpy(opengl_video_config.data, cfg->picture->y_buf, cfg->picture->width * cfg->picture->height );
74 out->numBuffers = in->numBuffers;
75 out->indexBuffer = in->indexBuffer;
76 out->buffers = in->buffers;
79 vp_os_mutex_unlock( &opengl_video_config.mutex );
82 vp_os_mutex_unlock( &out->lock );
87 C_RESULT opengl_video_stage_close(vlib_stage_decoding_config_t *cfg)
89 vp_os_free(opengl_video_config.data);
94 opengl_video_stage_config_t* opengl_video_stage_get(void)
96 return &opengl_video_config;