-
Notifications
You must be signed in to change notification settings - Fork 1
/
slicerow.hpp
65 lines (49 loc) · 1.56 KB
/
slicerow.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef SLICEROW_HPP
#define SLICEROW_HPP
#include <pthread.h>
#include "mpegheader.hpp"
#include "mutexobj.hpp"
#include "exceptions.hpp"
enum SliceRowState { SR_BLANK, SR_READY, SR_LOCKED, SR_RENDERED };
class SliceRow
{
private:
uint row;
uint mb_height;
int forward_highest_dependent_row, forward_lowest_dependent_row;
int backward_highest_dependent_row, backward_lowest_dependent_row;
pthread_mutex_t mutex;
pthread_cond_t activity;
SliceRowState state;
public:
SliceRow( uint s_row, uint s_mb_height );
~SliceRow();
void init( int f_code_fv, int f_code_bv, Picture *forward, Picture *backward );
SliceRowState lock( void ) {
MutexLock x( &mutex );
SliceRowState return_value = state;
if ( state != SR_READY ) return return_value;
state = SR_LOCKED;
return return_value;
}
void set_rendered( void )
{
MutexLock x( &mutex );
state = SR_RENDERED;
unixassert( pthread_cond_broadcast( &activity ) );
}
void wait_rendered( void )
{
MutexLock x( &mutex );
while ( state != SR_RENDERED ) {
pthread_cond_wait( &activity, &mutex );
}
}
void set_blank( void ) { MutexLock x( &mutex ); state = SR_BLANK; }
SliceRowState get_state( void ) { MutexLock x( &mutex ); return state; }
int get_forward_highrow( void ) { return forward_highest_dependent_row; }
int get_forward_lowrow( void ) { return forward_lowest_dependent_row; }
int get_backward_highrow( void ) { return backward_highest_dependent_row; }
int get_backward_lowrow( void ) { return backward_lowest_dependent_row; }
};
#endif