76357c09352f40c85bb9fdf722bc3c68385d9840
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VLIB / video_controller.h
1 #ifndef _VIDEO_CONTROLLER_H_
2 #define _VIDEO_CONTROLLER_H_
3
4 #include <VP_Os/vp_os_types.h>
5 #include <VP_Api/vp_api_picture.h>
6
7 #include <VLIB/video_picture.h>
8 #include <VLIB/video_gob.h>
9
10 enum {
11   VIDEO_ENCODE  = 1,
12   VIDEO_DECODE  = 2
13 };
14
15 enum {
16   VIDEO_PICTURE_INTRA = 0,  // Picture is a reference frame
17   VIDEO_PICTURE_INTER = 1,  // Picture is encoded using motion estimation / compensation
18   VIDEO_PICTURE_PB    = 2,  // Picture is encoded using a PB frame
19   VIDEO_PICTURE_B     = 3,
20   VIDEO_PICTURE_EI    = 4,
21   VIDEO_PICTURE_EP    = 5,
22 };
23
24 enum {
25   VIDEO_STREAM_LITTLE_ENDIAN  = 1,
26   VIDEO_STREAM_BIG_ENDIAN     = 2
27 };
28
29 typedef struct _video_controller_t  video_controller_t;
30 typedef struct _video_codec_t       video_codec_t;
31 typedef struct _video_stream_t      video_stream_t;
32
33 struct _video_stream_t {
34   int32_t   length;     // Number of bits used in code (TODO why is it signed?)
35   uint32_t  code;       // Currently read/write data
36   uint32_t  used;       // Number of bytes used in stream
37   uint32_t* bytes;      // Must be aligned on a 4-bytes boundary
38   uint32_t  index;      // Position of next dword available for reading/writing
39   uint32_t  size;       // Max size (in bytes, times of 4) of this stream
40   uint32_t  endianess;  // Endianess of the stream
41 };
42
43 typedef C_RESULT (*encode_blockline_fc)( video_controller_t* controller, const vp_api_picture_t* blockline, bool_t picture_complete );
44 typedef C_RESULT (*decode_blockline_fc)( video_controller_t* controller, vp_api_picture_t* blockline, bool_t* got_image );
45 typedef C_RESULT (*update_fc)( video_controller_t* controller );
46 typedef C_RESULT (*cache_stream_fc)( video_controller_t* controller, video_stream_t* in );
47
48 struct _video_controller_t {
49   // Configuration Data
50   uint32_t        mode;           // encoding or decoding
51   bool_t          use_me;         // use motion estimation / compensation
52   bool_t          do_azq;
53   int32_t         aq, bq;
54   uint32_t        target_bitrate; // Target bitrate in bit/s
55   uint32_t        target_size;    // Target size per image
56
57   // External & internal buffer used by packetizer layer
58   // video_stream_t* ex_stream;      // External buffer
59   video_stream_t  in_stream;      // Internal buffer
60
61   // Internal statistics
62   uint32_t  num_frames;           // Frame index
63   int32_t   current_bits;         // Number of bits in the buffer
64   int32_t   output_bits;          // Number of bits occupied by the previous encoded picture
65   int32_t   original_framerate;   // Frame rate of the original video sequence in pictures per second
66   int32_t   target_framerate;     // Target frame rate in pictures per second (original_framerate / target_framerate must be an int)
67
68   // Video Data for currently processed picture
69   uint32_t  picture_type;
70   int32_t   width;                // Size of picture currently decoded
71   int32_t   height;
72   bool_t    resolution_changed;   // if current frame resolution differs from previous one, this flag is set to TRUE
73   int32_t   num_blockline;        // Number of blocklines per picture
74   int32_t   mb_blockline;         // Number of macroblocks per blockline for this picture
75   int32_t   blockline;            // Current blockline in picture
76   bool_t    picture_complete;     // tells if picture is complete
77
78   int32_t   quant;
79   int32_t   dquant;
80   int32_t   Qp;
81   int32_t   invQp;
82
83   video_gob_t*  gobs;             // Description of the picture as an array of gob
84   int16_t*      cache;            // Cache that holds data for the whole picture (used internally by gobs)
85
86   video_macroblock_t* cache_mbs;  // Array of macroblocks describing blockline_cache (used for decoding)
87   int16_t*      blockline_cache;  // Cache used to hold intermediate results (for hardware DCT for example)
88
89   // Codec specific functions
90   uint32_t        codec_type;
91   video_codec_t*  video_codec;
92 };
93
94 C_RESULT video_controller_update( video_controller_t* controller, bool_t complete );
95
96 C_RESULT video_controller_set_mode( video_controller_t* controller, uint32_t mode );
97
98 C_RESULT video_controller_cleanup( video_controller_t* controller );
99
100 // Configuration api
101 // video_controller_set_bitrate allows you to set the target bitrate
102 C_RESULT video_controller_set_bitrate( video_controller_t* controller, uint32_t target );
103
104 // video_controller_set_target_size allows you yo set a target size for each picture
105 C_RESULT video_controller_set_target_size( video_controller_t* controller, uint32_t target );
106
107 // Set format for picture to be decoded
108 // This function resize internal buffers if needed
109 C_RESULT video_controller_set_format( video_controller_t* controller, int32_t width, int32_t height );
110
111 // Set picture type ( INTRA or INTER )
112 C_RESULT  video_controller_set_picture_type( video_controller_t* controller, uint32_t type );
113
114 // Set motion estimation usage
115 C_RESULT  video_controller_set_motion_estimation( video_controller_t* controller, bool_t use_me );
116
117 static INLINE uint8_t* video_controller_get_stream_ptr( video_controller_t* controller ) {
118   return (uint8_t*)&controller->in_stream.bytes[0];
119 }
120
121 static INLINE uint32_t video_controller_get_stream_size( video_controller_t* controller ) {
122   return controller->in_stream.used;
123 }
124
125 #endif // _VIDEO_CONTROLLER_H_