00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#ifndef EXPERIMENT_H
00025
#define EXPERIMENT_H
00026
00027
#define NO_MN
00028
#ifdef NO_MN
00029
#ifdef linux
00030 typedef unsigned long u_int64;
00031
#endif
00032 typedef unsigned int u_int32;
00033 typedef unsigned int u_int32_t;
00034 typedef int stream_event_t;
00035
#define EV_OK 0
00036
#define EV_EOF -1
00037
#define EV_ERROR -2
00038
#define RTPCODEC_READ_ERROR -3
00039
#define OPTIONAL
00040
#endif
00041
00042
class PlainPacket;
00043
00044 class MNRTPCodecH261
00045 {
00046
struct GOB
00047 {
00048
int _head_drop;
00049
int _tail_drop;
00050
unsigned char* _buf;
00051
int _size;
00052
int _number;
00053
bool _picture;
00054
int _tempref;
00055 GOB* _next;
00056
00057 GOB(
int head_drop )
00058 {
00059 _head_drop = head_drop;
00060 _tail_drop = 0;
00061 _buf =
new unsigned char[4096];
00062 _size = 0;
00063 _number = 0;
00064 _next = NULL;
00065 _picture =
false;
00066 _tempref = 0;
00067 }
00068
00069 ~GOB()
00070 {
00071
delete [] _buf;
00072 }
00073
00074
inline int size()
const {
return _size; }
00075
inline int max()
const {
return 4096; }
00076
inline void add(
int byte )
00077 {
00078 _buf[_size] = byte;
00079 _size++;
00080 }
00081
00082
inline int getTempRef()
const {
return _tempref; }
00083
00084
void checkPicture( );
00085
bool isPicture( );
00086
00087
inline int copy(
char* dest)
00088 {
00089 memcpy(dest,_buf,_size);
00090
return _size;
00091 }
00092
00093
void fillHeader(
char* buffer );
00094 };
00095
00096
struct Frame
00097 {
00098
int timestamp;
00099 GOB* head;
00100 GOB* tail;
00101
00102 Frame()
00103 {
00104 timestamp = 0;
00105 head = NULL;
00106 tail = NULL;
00107 }
00108
00109
void append( GOB* g )
00110 {
00111 assert( head != tail );
00112 tail->_next = g;
00113 tail = g;
00114 }
00115
00116
void set_picture_header( GOB* g,
int tempref )
00117 {
00118 timestamp = g->getTempRef();
00119 head = g;
00120 tail = g;
00121 }
00122
00123
void drop_head()
00124 {
00125
if ( head == tail )
00126 {
00127
delete head;
00128 head = tail = NULL;
00129 }
00130
else
00131 {
00132 GOB* t = head;
00133 head = head->_next;
00134
delete t;
00135 }
00136 }
00137 };
00138
00139
class Movie
00140 {
00141 Frame* _current;
00142 Frame* _next;
00143
00144
public:
00145 Movie()
00146 {
00147 _current = NULL;
00148 _next = NULL;
00149 }
00150
00151
bool first()
const
00152
{
00153
return ( _current == NULL );
00154 }
00155
00156
void setFrame( Frame* f )
00157 {
00158
if ( _current == NULL ) _current = f;
00159
else _next = f;
00160 }
00161
00162
bool needData()
const
00163
{
00164
return ( _next == NULL );
00165 }
00166
00167
void addToCurrent( GOB* g )
00168 {
00169 assert( _current );
00170 _current->append(g);
00171 }
00172
00173
int hasMoreData()
const
00174
{
00175
return ( _next != NULL );
00176 }
00177
00178
int nextGopSize()
const
00179
{
00180
return _current->head->size();
00181 }
00182
00183
inline void fillHeader(
char* buffer )
00184 {
00185 _current->head->fillHeader( buffer );
00186 }
00187
00188
int copyGop(
char* dest)
00189 {
00190
int size = _current->head->copy(dest);
00191 _current->drop_head();
00192
if ( _current->head == NULL )
00193 {
00194
delete _current;
00195 _current = _next;
00196 _next = NULL;
00197 }
00198
return size;
00199 }
00200 };
00201
00202 Movie _movie;
00203
00204
bool _ok;
00205
bool _first;
00206
int _last_tail_drop;
00207
unsigned int _last_gob_marker;
00208
int _last_temp_ref;
00209
unsigned int _bb;
00210
00211
PlainPacket* _file;
00212
00213
void callInitializer(
int fd );
00214
00215
void fillHeader(
char* buffer,
00216
int previous_head_drop,
00217
int tail_drop,
00218
int gob_number );
00219
void getGobInfo(
char* buffer,
00220
int head_drop,
00221
int* gob_number );
00222
void updateTimeRef(
int newTimeRef );
00223
int currentTimeRef( );
00224
00225
public:
00226
MNRTPCodecH261();
00227
00228
virtual ~MNRTPCodecH261();
00229
00230
bool ok()
const;
00231
00232
int get();
00233
00234
int startCode(
int& head_drop );
00235
00236
00237
00238
00239
int initFirst( );
00240
00241
int fillBuffer( GOB* g );
00242
int fillBuffer(
char* buffer,
int max,
00243
int* head_drop,
int* tail_drop );
00244
00245
int fillPacket(
int fd,
char* buffer,
int max );
00246
00247 virtual u_int32_t get_std_bw(
int fd) {
return 1000; }
00248 virtual u_int32_t get_std_packetsize(
int fd) {
return 1400; }
00249
virtual struct timeval get_std_timeout(int fd);
00250
00251
virtual int get_data(
int fd,
00252 u_int64 maxlength,
00253
char* buffer,
00254 u_int64* fpos,
00255
int* marker,
00256
int* ts,
00257
struct timeval* codec_next_timeout,
00258
bool seekable,
00259 stream_event_t* except,
00260
int packetsize,
00261 u_int32 time_offset,
00262 u_int32 ts_offset );
00263
00264
00265 virtual int write_next_data(
int fd,
char* buffer,
int len) {
return -1; }
00266 int write_blank(
int fd, u_int32 blank_size) {
return -1; }
00267 };
00268
00269
#endif
00270