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