7d8f5a55e192589fe88892870892d0cbfb785776
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / Soft / Lib / ardrone_tool / Video / vlib_stage_decode.c
1 #include <config.h>
2 #include <VP_Os/vp_os_malloc.h>
3 #include <VP_Os/vp_os_print.h>
4
5 #include <ardrone_tool/Video/vlib_stage_decode.h>
6
7 const vp_api_stage_funcs_t vlib_decoding_funcs = {
8   (vp_api_stage_handle_msg_t) NULL,
9   (vp_api_stage_open_t) vlib_stage_decoding_open,
10   (vp_api_stage_transform_t) vlib_stage_decoding_transform,
11   (vp_api_stage_close_t) vlib_stage_decoding_close
12 };
13
14 C_RESULT vlib_stage_decoding_open(vlib_stage_decoding_config_t *cfg)
15 {
16   video_codec_open( &cfg->controller, UVLC_CODEC );
17   video_controller_set_motion_estimation( &cfg->controller, FALSE );
18   video_controller_set_format( &cfg->controller, ACQ_WIDTH, ACQ_HEIGHT );
19
20   vp_os_free( cfg->controller.in_stream.bytes );
21
22   return C_OK;
23 }
24
25 C_RESULT vlib_stage_decoding_transform(vlib_stage_decoding_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
26 {
27   bool_t got_image;
28
29   vp_os_mutex_lock( &out->lock );
30
31   if(out->status == VP_API_STATUS_INIT)
32   {
33     out->numBuffers   = 1;
34     out->buffers      = (int8_t**)&cfg->picture;
35     out->indexBuffer  = 0;
36     out->lineSize     = 0;
37
38     out->status = VP_API_STATUS_PROCESSING;
39   }
40
41   if( in->status == VP_API_STATUS_ENDED ) {
42     out->status = in->status;
43   }
44
45   if(out->status == VP_API_STATUS_PROCESSING )
46   {
47     // If out->size == 1 it means picture is ready
48     out->size = 0;
49
50     cfg->controller.in_stream.bytes   = (uint32_t*)in->buffers[0];
51     cfg->controller.in_stream.used    = in->size;
52     cfg->controller.in_stream.size    = in->size;
53     cfg->controller.in_stream.index   = 0;
54     cfg->controller.in_stream.length  = 32;
55     cfg->controller.in_stream.code    = 0;
56
57     got_image = FALSE;
58     video_decode_blockline( &cfg->controller, cfg->picture, &got_image );
59
60     if( got_image )
61     {
62       // we got one picture
63       out->size = 1;
64
65 #ifndef USE_VIDEO_YUV
66       int32_t i;
67       for(i = 0; i < cfg->picture->width * cfg->picture->height / 4; i++ )
68       {
69         cfg->picture->cr_buf[i] = 0x80;
70         cfg->picture->cb_buf[i] = 0x80;
71       }
72 #endif
73     }
74   }
75
76   vp_os_mutex_unlock( &out->lock );
77
78   return C_OK;
79 }
80
81 C_RESULT vlib_stage_decoding_close(vlib_stage_decoding_config_t *cfg)
82 {
83   return video_codec_close( &cfg->controller );
84 }