Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
x264
Commits
e0920d6f
Commit
e0920d6f
authored
Sep 23, 2009
by
Anton Mitrofanov
Committed by
Fiona Glaser
Sep 23, 2009
Browse files
Improve threaded frame handling
Avoid unnecessary cond_wait
parent
510fa4fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
common/common.h
View file @
e0920d6f
...
...
@@ -245,8 +245,8 @@ typedef struct
typedef
struct
x264_lookahead_t
{
volatile
uint8_t
b_exit_thread
;
uint8_t
b_thread_active
;
uint8_t
b_exit_thread
;
uint8_t
b_analyse_keyframe
;
int
i_last_idr
;
int
i_slicetype_length
;
...
...
common/frame.c
View file @
e0920d6f
...
...
@@ -1055,12 +1055,3 @@ void x264_synch_frame_list_push( x264_synch_frame_list_t *slist, x264_frame_t *f
x264_pthread_mutex_unlock
(
&
slist
->
mutex
);
x264_pthread_cond_broadcast
(
&
slist
->
cv_fill
);
}
int
x264_synch_frame_list_get_size
(
x264_synch_frame_list_t
*
slist
)
{
int
size
;
x264_pthread_mutex_lock
(
&
slist
->
mutex
);
size
=
slist
->
i_size
;
x264_pthread_mutex_unlock
(
&
slist
->
mutex
);
return
size
;
}
common/frame.h
View file @
e0920d6f
...
...
@@ -165,7 +165,6 @@ void x264_frame_delete_list( x264_frame_t **list );
int
x264_synch_frame_list_init
(
x264_synch_frame_list_t
*
slist
,
int
nelem
);
void
x264_synch_frame_list_delete
(
x264_synch_frame_list_t
*
slist
);
void
x264_synch_frame_list_push
(
x264_synch_frame_list_t
*
slist
,
x264_frame_t
*
frame
);
int
x264_synch_frame_list_get_size
(
x264_synch_frame_list_t
*
slist
);
#define x264_frame_sort_dts(list) x264_frame_sort(list, 1)
#define x264_frame_sort_pts(list) x264_frame_sort(list, 0)
...
...
encoder/encoder.c
View file @
e0920d6f
...
...
@@ -2369,8 +2369,12 @@ int x264_encoder_delayed_frames( x264_t *h )
h
=
h
->
thread
[
h
->
i_thread_phase
%
h
->
param
.
i_threads
];
for
(
i
=
0
;
h
->
frames
.
current
[
i
];
i
++
)
delayed_frames
++
;
delayed_frames
+=
x264_synch_frame_list_get_size
(
&
h
->
lookahead
->
ifbuf
);
delayed_frames
+=
x264_synch_frame_list_get_size
(
&
h
->
lookahead
->
next
);
delayed_frames
+=
x264_synch_frame_list_get_size
(
&
h
->
lookahead
->
ofbuf
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
next
.
mutex
);
delayed_frames
+=
h
->
lookahead
->
ifbuf
.
i_size
+
h
->
lookahead
->
next
.
i_size
+
h
->
lookahead
->
ofbuf
.
i_size
;
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
next
.
mutex
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
return
delayed_frames
;
}
encoder/lookahead.c
View file @
e0920d6f
...
...
@@ -43,7 +43,7 @@ static void x264_lookahead_shift( x264_synch_frame_list_t *dst, x264_synch_frame
int
i
=
count
;
while
(
i
--
)
{
assert
(
dst
->
i_size
!=
dst
->
i_max_size
);
assert
(
dst
->
i_size
<
dst
->
i_max_size
);
assert
(
src
->
i_size
);
dst
->
list
[
dst
->
i_size
++
]
=
x264_frame_shift
(
src
->
list
);
src
->
i_size
--
;
...
...
@@ -95,7 +95,6 @@ static void x264_lookahead_thread( x264_t *h )
if
(
h
->
param
.
cpu
&
X264_CPU_SSE_MISALIGN
)
x264_cpu_mask_misalign_sse
();
#endif
h
->
lookahead
->
b_thread_active
=
1
;
while
(
!
h
->
lookahead
->
b_exit_thread
)
{
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
...
...
@@ -115,14 +114,17 @@ static void x264_lookahead_thread( x264_t *h )
x264_lookahead_slicetype_decide
(
h
);
}
}
/* end of input frames */
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
next
.
mutex
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
next
.
mutex
);
x264_lookahead_shift
(
&
h
->
lookahead
->
next
,
&
h
->
lookahead
->
ifbuf
,
h
->
lookahead
->
ifbuf
.
i_size
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
next
.
mutex
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ifbuf
.
mutex
);
while
(
h
->
lookahead
->
next
.
i_size
)
x264_lookahead_slicetype_decide
(
h
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
h
->
lookahead
->
b_thread_active
=
0
;
x264_pthread_cond_broadcast
(
&
h
->
lookahead
->
ofbuf
.
cv_fill
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
}
#endif
...
...
@@ -155,6 +157,7 @@ int x264_lookahead_init( x264_t *h, int i_slicetype_length )
if
(
x264_pthread_create
(
&
look_h
->
thread_handle
,
NULL
,
(
void
*
)
x264_lookahead_thread
,
look_h
)
)
goto
fail
;
look
->
b_thread_active
=
1
;
return
0
;
fail:
...
...
@@ -190,8 +193,13 @@ void x264_lookahead_put_frame( x264_t *h, x264_frame_t *frame )
int
x264_lookahead_is_empty
(
x264_t
*
h
)
{
return
!
x264_synch_frame_list_get_size
(
&
h
->
lookahead
->
ofbuf
)
&&
!
x264_synch_frame_list_get_size
(
&
h
->
lookahead
->
next
);
int
b_empty
;
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
x264_pthread_mutex_lock
(
&
h
->
lookahead
->
next
.
mutex
);
b_empty
=
!
h
->
lookahead
->
next
.
i_size
&&
!
h
->
lookahead
->
ofbuf
.
i_size
;
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
next
.
mutex
);
x264_pthread_mutex_unlock
(
&
h
->
lookahead
->
ofbuf
.
mutex
);
return
b_empty
;
}
static
void
x264_lookahead_encoder_shift
(
x264_t
*
h
)
...
...
@@ -201,8 +209,6 @@ static void x264_lookahead_encoder_shift( x264_t *h )
while
(
h
->
lookahead
->
ofbuf
.
list
[
i_frames
]
)
{
while
(
h
->
lookahead
->
b_thread_active
&&
!
h
->
lookahead
->
ofbuf
.
i_size
)
x264_pthread_cond_wait
(
&
h
->
lookahead
->
ofbuf
.
cv_fill
,
&
h
->
lookahead
->
ofbuf
.
mutex
);
if
(
IS_X264_TYPE_B
(
h
->
lookahead
->
ofbuf
.
list
[
bframes
]
->
i_type
)
)
bframes
++
;
else
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment