ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VLIB / UVLC / uvlc_picture_layer.c
1 #include <VLIB/video_controller.h>
2 #include <VLIB/video_packetizer.h>
3
4 #include "uvlc_codec.h"
5 #include "uvlc_layers.h"
6
7 C_RESULT uvlc_write_picture_layer( video_controller_t* controller, video_stream_t* stream )
8 {
9   uint32_t format = 0, resolution = 0, width, height;
10
11   uvlc_codec_t* uvlc_codec = (uvlc_codec_t*) controller->video_codec;
12   uvlc_picture_layer_t* picture_layer = &uvlc_codec->picture_layer;
13
14   width   = controller->width;
15   height  = controller->height;
16
17   while( format == 0 )
18   {
19     if( width == QQCIF_WIDTH )
20       format = UVLC_FORMAT_CIF;
21
22     if( width == QQVGA_WIDTH )
23       format = UVLC_FORMAT_VGA;
24
25     width   >>= 1;
26     height  >>= 1;
27
28     resolution ++;
29   }
30
31   picture_layer->format     = format;
32   picture_layer->resolution = resolution;
33
34   video_write_data( stream, picture_layer->format, 2 );
35   video_write_data( stream, picture_layer->resolution, 3 );
36   video_write_data( stream, picture_layer->picture_type, 3 );
37   video_write_data( stream, picture_layer->quant, 5 );
38   video_write_data( stream, controller->num_frames, 32 );
39
40   return C_OK;
41 }
42
43 C_RESULT uvlc_read_picture_layer( video_controller_t* controller, video_stream_t* stream )
44 {
45   uint32_t width, height;
46
47   uvlc_codec_t* uvlc_codec = (uvlc_codec_t*) controller->video_codec;
48   uvlc_picture_layer_t* picture_layer = &uvlc_codec->picture_layer;
49
50   picture_layer->format       = 0;
51   picture_layer->resolution   = 0;
52   picture_layer->picture_type = 0;
53   picture_layer->quant        = 0;
54
55   video_read_data( stream, &picture_layer->format, 2 );
56   video_read_data( stream, &picture_layer->resolution, 3 );
57   video_read_data( stream, &picture_layer->picture_type, 3 );
58   video_read_data( stream, &picture_layer->quant, 5 );
59   video_read_data( stream, &controller->num_frames, 32 );
60
61   switch( picture_layer->format )
62   {
63     case UVLC_FORMAT_CIF:
64       width   = QQCIF_WIDTH << (picture_layer->resolution-1);
65       height  = QQCIF_HEIGHT << (picture_layer->resolution-1);
66       break;
67
68     case UVLC_FORMAT_VGA:
69       width   = QQVGA_WIDTH << (picture_layer->resolution-1);
70       height  = QQVGA_HEIGHT << (picture_layer->resolution-1);
71       break;
72
73     default:
74       width   = 0;
75       height  = 0;
76       break;
77   }
78
79   video_controller_set_format( controller, width, height );
80
81   return C_OK;
82 }