1 #ifndef _VIDEO_CONTROLLER_H_
2 #define _VIDEO_CONTROLLER_H_
4 #include <VP_Os/vp_os_types.h>
5 #include <VP_Api/vp_api_picture.h>
7 #include <VLIB/video_picture.h>
8 #include <VLIB/video_gob.h>
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
25 VIDEO_STREAM_LITTLE_ENDIAN = 1,
26 VIDEO_STREAM_BIG_ENDIAN = 2
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;
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
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 );
48 struct _video_controller_t {
50 uint32_t mode; // encoding or decoding
51 bool_t use_me; // use motion estimation / compensation
54 uint32_t target_bitrate; // Target bitrate in bit/s
55 uint32_t target_size; // Target size per image
57 // External & internal buffer used by packetizer layer
58 // video_stream_t* ex_stream; // External buffer
59 video_stream_t in_stream; // Internal buffer
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)
68 // Video Data for currently processed picture
69 uint32_t picture_type;
70 int32_t width; // Size of picture currently decoded
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
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)
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)
89 // Codec specific functions
91 video_codec_t* video_codec;
94 C_RESULT video_controller_update( video_controller_t* controller, bool_t complete );
96 C_RESULT video_controller_set_mode( video_controller_t* controller, uint32_t mode );
98 C_RESULT video_controller_cleanup( video_controller_t* controller );
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 );
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 );
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 );
111 // Set picture type ( INTRA or INTER )
112 C_RESULT video_controller_set_picture_type( video_controller_t* controller, uint32_t type );
114 // Set motion estimation usage
115 C_RESULT video_controller_set_motion_estimation( video_controller_t* controller, bool_t use_me );
117 static INLINE uint8_t* video_controller_get_stream_ptr( video_controller_t* controller ) {
118 return (uint8_t*)&controller->in_stream.bytes[0];
121 static INLINE uint32_t video_controller_get_stream_size( video_controller_t* controller ) {
122 return controller->in_stream.used;
125 #endif // _VIDEO_CONTROLLER_H_