ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Android / ardrone / project / jni / opengl_stage.c
1 /*
2  *  opengl_stage.c
3  *  Test
4  *
5  *  Created by Karl Leplat on 22/02/10.
6  *  Copyright 2010 Parrot SA. All rights reserved.
7  *
8  */
9 #include "opengl_stage.h"
10 #include "app.h"
11 #include <android/log.h>
12
13 static opengl_video_stage_config_t opengl_video_config;
14
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
20 };
21
22 C_RESULT opengl_video_stage_open(vlib_stage_decoding_config_t *cfg)
23 {
24    __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Enter in opengl_video_stage_open\n" );
25         vp_os_mutex_init( &opengl_video_config.mutex );
26         
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 );
31    
32    __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Exit opengl_video_stage_open\n" );
33         
34         return C_OK;
35 }
36
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)
38 {
39         vp_os_mutex_lock( &out->lock );
40
41         if(out->status == VP_API_STATUS_INIT)
42         {
43                 out->status = VP_API_STATUS_PROCESSING;
44         }
45         
46         if( in->status == VP_API_STATUS_ENDED ) 
47         {
48                 out->status = in->status;
49         }
50         
51         if(out->status == VP_API_STATUS_PROCESSING )
52         {
53                 vp_os_mutex_lock( &opengl_video_config.mutex );
54                 
55                 if(cfg->num_picture_decoded > opengl_video_config.num_picture_decoded)
56                 {
57                         opengl_video_config.num_picture_decoded = cfg->num_picture_decoded;
58                         /*
59          opengl_video_config.bytesPerPixel      = 2;
60                         opengl_video_config.widthImage          = cfg->controller.width;
61                         opengl_video_config.heightImage         = cfg->controller.height;               
62                         
63                         if(opengl_video_config.bytesPerPixel == 2)
64                         {
65                                 opengl_video_config.format = GL_RGB;
66                                 opengl_video_config.type = GL_UNSIGNED_SHORT_5_6_5;                             
67                         }
68                    */ 
69                         if (opengl_video_config.data != NULL)
70                         {   
71                                 vp_os_memcpy(opengl_video_config.data, cfg->picture->y_buf, cfg->picture->width * cfg->picture->height );
72                         }
73                 
74                         out->numBuffers = in->numBuffers;
75                         out->indexBuffer = in->indexBuffer;
76                         out->buffers = in->buffers;
77                 }
78
79                 vp_os_mutex_unlock( &opengl_video_config.mutex );
80         }
81         
82         vp_os_mutex_unlock( &out->lock );
83
84         return C_OK;
85 }
86
87 C_RESULT opengl_video_stage_close(vlib_stage_decoding_config_t *cfg)
88 {
89         vp_os_free(opengl_video_config.data);
90         
91         return C_OK;
92 }
93
94 opengl_video_stage_config_t* opengl_video_stage_get(void)
95 {
96         return &opengl_video_config;
97 }