Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
c62c07d3
Commit
c62c07d3
authored
Feb 23, 2004
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multithreaded mpeg2 decoding
Originally committed as revision 2810 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
c0a2c42f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
157 additions
and
67 deletions
+157
-67
ffmpeg.c
ffmpeg.c
+5
-0
ffplay.c
ffplay.c
+17
-2
error_resilience.c
libavcodec/error_resilience.c
+1
-1
mpeg12.c
libavcodec/mpeg12.c
+127
-62
mpegvideo.c
libavcodec/mpegvideo.c
+6
-2
mpegvideo.h
libavcodec/mpegvideo.h
+1
-0
No files found.
ffmpeg.c
View file @
c62c07d3
...
@@ -2256,6 +2256,11 @@ static void opt_input_file(const char *filename)
...
@@ -2256,6 +2256,11 @@ static void opt_input_file(const char *filename)
/* update the current parameters so that they match the one of the input stream */
/* update the current parameters so that they match the one of the input stream */
for
(
i
=
0
;
i
<
ic
->
nb_streams
;
i
++
)
{
for
(
i
=
0
;
i
<
ic
->
nb_streams
;
i
++
)
{
AVCodecContext
*
enc
=
&
ic
->
streams
[
i
]
->
codec
;
AVCodecContext
*
enc
=
&
ic
->
streams
[
i
]
->
codec
;
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
if
(
thread_count
>
1
)
avcodec_thread_init
(
enc
,
thread_count
);
#endif
enc
->
thread_count
=
thread_count
;
switch
(
enc
->
codec_type
)
{
switch
(
enc
->
codec_type
)
{
case
CODEC_TYPE_AUDIO
:
case
CODEC_TYPE_AUDIO
:
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
...
...
ffplay.c
View file @
c62c07d3
...
@@ -168,6 +168,7 @@ static int64_t start_time = AV_NOPTS_VALUE;
...
@@ -168,6 +168,7 @@ static int64_t start_time = AV_NOPTS_VALUE;
static
int
debug
=
0
;
static
int
debug
=
0
;
static
int
debug_mv
=
0
;
static
int
debug_mv
=
0
;
static
int
step
=
0
;
static
int
step
=
0
;
static
int
thread_count
=
1
;
/* current context */
/* current context */
static
int
is_full_screen
;
static
int
is_full_screen
;
...
@@ -1169,6 +1170,12 @@ static int stream_component_open(VideoState *is, int stream_index)
...
@@ -1169,6 +1170,12 @@ static int stream_component_open(VideoState *is, int stream_index)
if
(
!
codec
||
if
(
!
codec
||
avcodec_open
(
enc
,
codec
)
<
0
)
avcodec_open
(
enc
,
codec
)
<
0
)
return
-
1
;
return
-
1
;
enc
->
debug
=
debug
;
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
if
(
thread_count
>
1
)
avcodec_thread_init
(
enc
,
thread_count
);
#endif
enc
->
thread_count
=
thread_count
;
switch
(
enc
->
codec_type
)
{
switch
(
enc
->
codec_type
)
{
case
CODEC_TYPE_AUDIO
:
case
CODEC_TYPE_AUDIO
:
is
->
audio_stream
=
stream_index
;
is
->
audio_stream
=
stream_index
;
...
@@ -1197,7 +1204,6 @@ static int stream_component_open(VideoState *is, int stream_index)
...
@@ -1197,7 +1204,6 @@ static int stream_component_open(VideoState *is, int stream_index)
packet_queue_init
(
&
is
->
videoq
);
packet_queue_init
(
&
is
->
videoq
);
is
->
video_tid
=
SDL_CreateThread
(
video_thread
,
is
);
is
->
video_tid
=
SDL_CreateThread
(
video_thread
,
is
);
enc
->
debug
=
debug
;
enc
->
debug_mv
=
debug_mv
;
enc
->
debug_mv
=
debug_mv
;
break
;
break
;
default:
default:
...
@@ -1793,6 +1799,14 @@ static void opt_vismv(const char *arg)
...
@@ -1793,6 +1799,14 @@ static void opt_vismv(const char *arg)
{
{
debug_mv
=
atoi
(
arg
);
debug_mv
=
atoi
(
arg
);
}
}
static
void
opt_thread_count
(
const
char
*
arg
)
{
thread_count
=
atoi
(
arg
);
#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
fprintf
(
stderr
,
"Warning: not compiled with thread support, using thread emulation
\n
"
);
#endif
}
const
OptionDef
options
[]
=
{
const
OptionDef
options
[]
=
{
{
"h"
,
0
,
{(
void
*
)
show_help
},
"show help"
},
{
"h"
,
0
,
{(
void
*
)
show_help
},
"show help"
},
...
@@ -1814,7 +1828,8 @@ const OptionDef options[] = {
...
@@ -1814,7 +1828,8 @@ const OptionDef options[] = {
#ifdef CONFIG_NETWORK
#ifdef CONFIG_NETWORK
{
"rtp_tcp"
,
OPT_EXPERT
,
{(
void
*
)
&
opt_rtp_tcp
},
"force RTP/TCP protocol usage"
,
""
},
{
"rtp_tcp"
,
OPT_EXPERT
,
{(
void
*
)
&
opt_rtp_tcp
},
"force RTP/TCP protocol usage"
,
""
},
#endif
#endif
{
"sync"
,
HAS_ARG
|
OPT_EXPERT
,
{(
void
*
)
&
opt_sync
},
"set audio-video sync. type (type=audio/video/ext)"
,
"type"
},
{
"sync"
,
HAS_ARG
|
OPT_EXPERT
,
{(
void
*
)
opt_sync
},
"set audio-video sync. type (type=audio/video/ext)"
,
"type"
},
{
"threads"
,
HAS_ARG
|
OPT_EXPERT
,
{(
void
*
)
opt_thread_count
},
"thread count"
,
"count"
},
{
NULL
,
},
{
NULL
,
},
};
};
...
...
libavcodec/error_resilience.c
View file @
c62c07d3
...
@@ -652,7 +652,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en
...
@@ -652,7 +652,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en
s
->
error_status_table
[
start_xy
]
|=
VP_START
;
s
->
error_status_table
[
start_xy
]
|=
VP_START
;
if
(
start_xy
>
0
){
if
(
start_xy
>
0
&&
s
->
avctx
->
thread_count
<=
1
){
int
prev_status
=
s
->
error_status_table
[
s
->
mb_index2xy
[
start_i
-
1
]
];
int
prev_status
=
s
->
error_status_table
[
s
->
mb_index2xy
[
start_i
-
1
]
];
prev_status
&=
~
VP_START
;
prev_status
&=
~
VP_START
;
...
...
libavcodec/mpeg12.c
View file @
c62c07d3
...
@@ -1707,6 +1707,7 @@ typedef struct Mpeg1Context {
...
@@ -1707,6 +1707,7 @@ typedef struct Mpeg1Context {
int
mpeg_enc_ctx_allocated
;
/* true if decoding context allocated */
int
mpeg_enc_ctx_allocated
;
/* true if decoding context allocated */
int
repeat_field
;
/* true if we must repeat the field */
int
repeat_field
;
/* true if we must repeat the field */
AVPanScan
pan_scan
;
/** some temporary storage for the panscan */
AVPanScan
pan_scan
;
/** some temporary storage for the panscan */
int
slice_count
;
}
Mpeg1Context
;
}
Mpeg1Context
;
static
int
mpeg_decode_init
(
AVCodecContext
*
avctx
)
static
int
mpeg_decode_init
(
AVCodecContext
*
avctx
)
...
@@ -2015,43 +2016,14 @@ short * tmp;
...
@@ -2015,43 +2016,14 @@ short * tmp;
s
->
pblocks
[
5
]
=
tmp
;
s
->
pblocks
[
5
]
=
tmp
;
}
}
#define DECODE_SLICE_FATAL_ERROR -2
static
int
mpeg_field_start
(
MpegEncContext
*
s
){
#define DECODE_SLICE_ERROR -1
AVCodecContext
*
avctx
=
s
->
avctx
;
#define DECODE_SLICE_OK 0
Mpeg1Context
*
s1
=
(
Mpeg1Context
*
)
s
;
/**
* decodes a slice.
* @return DECODE_SLICE_FATAL_ERROR if a non recoverable error occured<br>
* DECODE_SLICE_ERROR if the slice is damaged<br>
* DECODE_SLICE_OK if this slice is ok<br>
*/
static
int
mpeg_decode_slice
(
AVCodecContext
*
avctx
,
AVFrame
*
pict
,
int
start_code
,
uint8_t
**
buf
,
int
buf_size
)
{
Mpeg1Context
*
s1
=
avctx
->
priv_data
;
MpegEncContext
*
s
=
&
s1
->
mpeg_enc_ctx
;
int
ret
;
const
int
field_pic
=
s
->
picture_structure
!=
PICT_FRAME
;
s
->
resync_mb_x
=
s
->
mb_x
=
s
->
resync_mb_y
=
s
->
mb_y
=
-
1
;
start_code
=
(
start_code
-
1
)
&
0xff
;
if
(
start_code
>=
s
->
mb_height
){
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"slice below image (%d >= %d)
\n
"
,
start_code
,
s
->
mb_height
);
return
-
1
;
}
ff_mpeg1_clean_buffers
(
s
);
s
->
interlaced_dct
=
0
;
/* start frame decoding */
/* start frame decoding */
if
(
s
->
first_slice
)
{
if
(
s
->
first_field
||
s
->
picture_structure
==
PICT_FRAME
){
if
(
s
->
first_field
||
s
->
picture_structure
==
PICT_FRAME
){
if
(
MPV_frame_start
(
s
,
avctx
)
<
0
)
if
(
MPV_frame_start
(
s
,
avctx
)
<
0
)
return
DECODE_SLICE_FATAL_ERROR
;
return
-
1
;
ff_er_frame_start
(
s
);
ff_er_frame_start
(
s
);
...
@@ -2069,7 +2041,7 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
...
@@ -2069,7 +2041,7 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
}
}
*
s
->
current_picture_ptr
->
pan_scan
=
s1
->
pan_scan
;
*
s
->
current_picture_ptr
->
pan_scan
=
s1
->
pan_scan
;
}
else
{
//second field
}
else
{
//second field
int
i
;
int
i
;
if
(
!
s
->
current_picture_ptr
){
if
(
!
s
->
current_picture_ptr
){
...
@@ -2083,30 +2055,48 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
...
@@ -2083,30 +2055,48 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
s
->
current_picture
.
data
[
i
]
+=
s
->
current_picture_ptr
->
linesize
[
i
];
s
->
current_picture
.
data
[
i
]
+=
s
->
current_picture_ptr
->
linesize
[
i
];
}
}
}
}
}
}
#ifdef HAVE_XVMC
#ifdef HAVE_XVMC
// MPV_frame_start will call this function too,
// MPV_frame_start will call this function too,
// but we need to call it on every field
// but we need to call it on every field
if
(
s
->
avctx
->
xvmc_acceleration
)
if
(
s
->
avctx
->
xvmc_acceleration
)
XVMC_field_start
(
s
,
avctx
);
XVMC_field_start
(
s
,
avctx
);
#endif
#endif
}
//fi(s->first_slice)
return
0
;
}
#define DECODE_SLICE_ERROR -1
#define DECODE_SLICE_OK 0
/**
* decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
* @return DECODE_SLICE_ERROR if the slice is damaged<br>
* DECODE_SLICE_OK if this slice is ok<br>
*/
static
int
mpeg_decode_slice
(
Mpeg1Context
*
s1
,
int
mb_y
,
uint8_t
**
buf
,
int
buf_size
)
{
MpegEncContext
*
s
=
&
s1
->
mpeg_enc_ctx
;
AVCodecContext
*
avctx
=
s
->
avctx
;
int
ret
;
const
int
field_pic
=
s
->
picture_structure
!=
PICT_FRAME
;
s
->
resync_mb_x
=
s
->
resync_mb_y
=
-
1
;
if
(
mb_y
>=
s
->
mb_height
){
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"slice below image (%d >= %d)
\n
"
,
s
->
mb_y
,
s
->
mb_height
);
return
-
1
;
}
init_get_bits
(
&
s
->
gb
,
*
buf
,
buf_size
*
8
);
init_get_bits
(
&
s
->
gb
,
*
buf
,
buf_size
*
8
);
ff_mpeg1_clean_buffers
(
s
);
s
->
interlaced_dct
=
0
;
s
->
qscale
=
get_qscale
(
s
);
s
->
qscale
=
get_qscale
(
s
);
if
(
s
->
first_slice
&&
(
s
->
first_field
||
s
->
picture_structure
==
PICT_FRAME
))
{
if
(
s
->
avctx
->
debug
&
FF_DEBUG_PICT_INFO
){
av_log
(
s
->
avctx
,
AV_LOG_DEBUG
,
"qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s
\n
"
,
s
->
qscale
,
s
->
mpeg_f_code
[
0
][
0
],
s
->
mpeg_f_code
[
0
][
1
],
s
->
mpeg_f_code
[
1
][
0
],
s
->
mpeg_f_code
[
1
][
1
],
s
->
pict_type
==
I_TYPE
?
"I"
:
(
s
->
pict_type
==
P_TYPE
?
"P"
:
(
s
->
pict_type
==
B_TYPE
?
"B"
:
"S"
)),
s
->
progressive_sequence
?
"ps"
:
""
,
s
->
progressive_frame
?
"pf"
:
""
,
s
->
alternate_scan
?
"alt"
:
""
,
s
->
top_field_first
?
"top"
:
""
,
s
->
intra_dc_precision
,
s
->
picture_structure
,
s
->
frame_pred_frame_dct
,
s
->
concealment_motion_vectors
,
s
->
q_scale_type
,
s
->
intra_vlc_format
,
s
->
repeat_first_field
,
s
->
chroma_420_type
?
"420"
:
""
);
}
}
s
->
first_slice
=
0
;
if
(
s
->
qscale
==
0
){
if
(
s
->
qscale
==
0
){
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"qscale == 0
\n
"
);
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"qscale == 0
\n
"
);
return
-
1
;
return
-
1
;
...
@@ -2135,12 +2125,23 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
...
@@ -2135,12 +2125,23 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
break
;
break
;
}
}
}
}
s
->
resync_mb_x
=
s
->
mb_x
;
s
->
resync_mb_x
=
s
->
mb_x
;
s
->
resync_mb_y
=
s
->
mb_y
=
start_code
;
s
->
resync_mb_y
=
s
->
mb_y
=
mb_y
;
s
->
mb_skip_run
=
0
;
s
->
mb_skip_run
=
0
;
ff_init_block_index
(
s
);
ff_init_block_index
(
s
);
if
(
s
->
mb_y
==
0
&&
s
->
mb_x
==
0
&&
(
s
->
first_field
||
s
->
picture_structure
==
PICT_FRAME
))
{
if
(
s
->
avctx
->
debug
&
FF_DEBUG_PICT_INFO
){
av_log
(
s
->
avctx
,
AV_LOG_DEBUG
,
"qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s
\n
"
,
s
->
qscale
,
s
->
mpeg_f_code
[
0
][
0
],
s
->
mpeg_f_code
[
0
][
1
],
s
->
mpeg_f_code
[
1
][
0
],
s
->
mpeg_f_code
[
1
][
1
],
s
->
pict_type
==
I_TYPE
?
"I"
:
(
s
->
pict_type
==
P_TYPE
?
"P"
:
(
s
->
pict_type
==
B_TYPE
?
"B"
:
"S"
)),
s
->
progressive_sequence
?
"ps"
:
""
,
s
->
progressive_frame
?
"pf"
:
""
,
s
->
alternate_scan
?
"alt"
:
""
,
s
->
top_field_first
?
"top"
:
""
,
s
->
intra_dc_precision
,
s
->
picture_structure
,
s
->
frame_pred_frame_dct
,
s
->
concealment_motion_vectors
,
s
->
q_scale_type
,
s
->
intra_vlc_format
,
s
->
repeat_first_field
,
s
->
chroma_420_type
?
"420"
:
""
);
}
}
for
(;;)
{
for
(;;)
{
#ifdef HAVE_XVMC
#ifdef HAVE_XVMC
//one 1 we memcpy blocks in xvmcvideo
//one 1 we memcpy blocks in xvmcvideo
...
@@ -2268,6 +2269,39 @@ eos: // end of slice
...
@@ -2268,6 +2269,39 @@ eos: // end of slice
return
0
;
return
0
;
}
}
static
int
slice_decode_thread
(
AVCodecContext
*
c
,
void
*
arg
){
MpegEncContext
*
s
=
arg
;
uint8_t
*
buf
=
s
->
gb
.
buffer
;
int
mb_y
=
s
->
start_mb_y
;
s
->
error_count
=
3
*
(
s
->
end_mb_y
-
s
->
start_mb_y
)
*
s
->
mb_width
;
for
(;;){
int
start_code
,
ret
;
ret
=
mpeg_decode_slice
((
Mpeg1Context
*
)
s
,
mb_y
,
&
buf
,
s
->
gb
.
buffer_end
-
buf
);
emms_c
();
//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
if
(
ret
<
0
){
if
(
s
->
resync_mb_x
>=
0
&&
s
->
resync_mb_y
>=
0
)
ff_er_add_slice
(
s
,
s
->
resync_mb_x
,
s
->
resync_mb_y
,
s
->
mb_x
,
s
->
mb_y
,
AC_ERROR
|
DC_ERROR
|
MV_ERROR
);
}
else
{
ff_er_add_slice
(
s
,
s
->
resync_mb_x
,
s
->
resync_mb_y
,
s
->
mb_x
-
1
,
s
->
mb_y
,
AC_END
|
DC_END
|
MV_END
);
}
if
(
s
->
mb_y
==
s
->
end_mb_y
)
return
0
;
start_code
=
find_start_code
(
&
buf
,
s
->
gb
.
buffer_end
);
mb_y
=
start_code
-
SLICE_MIN_START_CODE
;
if
(
mb_y
<
0
||
mb_y
>=
s
->
end_mb_y
)
return
-
1
;
}
return
0
;
//not reached
}
/**
/**
* handles slice ends.
* handles slice ends.
* @return 1 if it seems to be the last slice of
* @return 1 if it seems to be the last slice of
...
@@ -2621,12 +2655,21 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
...
@@ -2621,12 +2655,21 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
if
(
s
->
mpeg_enc_ctx_allocated
==
0
&&
avctx
->
codec_tag
==
ff_get_fourcc
(
"VCR2"
))
if
(
s
->
mpeg_enc_ctx_allocated
==
0
&&
avctx
->
codec_tag
==
ff_get_fourcc
(
"VCR2"
))
vcr2_init_sequence
(
avctx
);
vcr2_init_sequence
(
avctx
);
s
->
slice_count
=
0
;
for
(;;)
{
for
(;;)
{
/* find start next code */
/* find start next code */
start_code
=
find_start_code
(
&
buf_ptr
,
buf_end
);
start_code
=
find_start_code
(
&
buf_ptr
,
buf_end
);
if
(
start_code
<
0
){
if
(
start_code
<
0
){
if
(
s2
->
pict_type
!=
B_TYPE
||
avctx
->
hurry_up
==
0
){
if
(
s2
->
pict_type
!=
B_TYPE
||
avctx
->
hurry_up
==
0
){
if
(
avctx
->
thread_count
>
1
){
int
i
;
avctx
->
execute
(
avctx
,
slice_decode_thread
,
(
void
**
)
&
(
s2
->
thread_context
[
0
]),
NULL
,
s
->
slice_count
);
for
(
i
=
0
;
i
<
s
->
slice_count
;
i
++
)
s2
->
error_count
+=
s2
->
thread_context
[
i
]
->
error_count
;
}
if
(
slice_end
(
avctx
,
picture
))
{
if
(
slice_end
(
avctx
,
picture
))
{
if
(
s2
->
last_picture_ptr
||
s2
->
low_delay
)
//FIXME merge with the stuff in mpeg_decode_slice
if
(
s2
->
last_picture_ptr
||
s2
->
low_delay
)
//FIXME merge with the stuff in mpeg_decode_slice
*
data_size
=
sizeof
(
AVPicture
);
*
data_size
=
sizeof
(
AVPicture
);
...
@@ -2667,6 +2710,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
...
@@ -2667,6 +2710,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
default
:
default
:
if
(
start_code
>=
SLICE_MIN_START_CODE
&&
if
(
start_code
>=
SLICE_MIN_START_CODE
&&
start_code
<=
SLICE_MAX_START_CODE
)
{
start_code
<=
SLICE_MAX_START_CODE
)
{
int
mb_y
=
start_code
-
SLICE_MIN_START_CODE
;
/* skip b frames if we dont have reference frames */
/* skip b frames if we dont have reference frames */
if
(
s2
->
last_picture_ptr
==
NULL
&&
s2
->
pict_type
==
B_TYPE
)
break
;
if
(
s2
->
last_picture_ptr
==
NULL
&&
s2
->
pict_type
==
B_TYPE
)
break
;
...
@@ -2676,17 +2720,38 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
...
@@ -2676,17 +2720,38 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
if
(
avctx
->
hurry_up
>=
5
)
break
;
if
(
avctx
->
hurry_up
>=
5
)
break
;
if
(
!
s
->
mpeg_enc_ctx_allocated
)
break
;
if
(
!
s
->
mpeg_enc_ctx_allocated
)
break
;
ret
=
mpeg_decode_slice
(
avctx
,
picture
,
if
(
s2
->
first_slice
){
start_code
,
&
buf_ptr
,
input_size
);
s2
->
first_slice
=
0
;
emms_c
();
if
(
mpeg_field_start
(
s2
)
<
0
)
return
-
1
;
if
(
ret
<
0
){
}
if
(
s2
->
resync_mb_x
>=
0
&&
s2
->
resync_mb_y
>=
0
)
ff_er_add_slice
(
s2
,
s2
->
resync_mb_x
,
s2
->
resync_mb_y
,
s2
->
mb_x
,
s2
->
mb_y
,
AC_ERROR
|
DC_ERROR
|
MV_ERROR
);
if
(
avctx
->
thread_count
>
1
){
if
(
ret
==
DECODE_SLICE_FATAL_ERROR
)
return
-
1
;
int
threshold
=
(
s2
->
mb_height
*
s
->
slice_count
+
avctx
->
thread_count
/
2
)
/
avctx
->
thread_count
;
if
(
threshold
<=
mb_y
){
MpegEncContext
*
thread_context
=
s2
->
thread_context
[
s
->
slice_count
];
thread_context
->
start_mb_y
=
mb_y
;
thread_context
->
end_mb_y
=
s2
->
mb_height
;
if
(
s
->
slice_count
){
s2
->
thread_context
[
s
->
slice_count
-
1
]
->
end_mb_y
=
mb_y
;
ff_update_duplicate_context
(
thread_context
,
s2
);
}
init_get_bits
(
&
thread_context
->
gb
,
buf_ptr
,
input_size
*
8
);
s
->
slice_count
++
;
}
buf_ptr
+=
2
;
//FIXME add minimum num of bytes per slice
}
else
{
}
else
{
ff_er_add_slice
(
s2
,
s2
->
resync_mb_x
,
s2
->
resync_mb_y
,
s2
->
mb_x
-
1
,
s2
->
mb_y
,
AC_END
|
DC_END
|
MV_END
);
ret
=
mpeg_decode_slice
(
s
,
mb_y
,
&
buf_ptr
,
input_size
);
emms_c
();
if
(
ret
<
0
){
if
(
s2
->
resync_mb_x
>=
0
&&
s2
->
resync_mb_y
>=
0
)
ff_er_add_slice
(
s2
,
s2
->
resync_mb_x
,
s2
->
resync_mb_y
,
s2
->
mb_x
,
s2
->
mb_y
,
AC_ERROR
|
DC_ERROR
|
MV_ERROR
);
}
else
{
ff_er_add_slice
(
s2
,
s2
->
resync_mb_x
,
s2
->
resync_mb_y
,
s2
->
mb_x
-
1
,
s2
->
mb_y
,
AC_END
|
DC_END
|
MV_END
);
}
}
}
}
}
break
;
break
;
...
...
libavcodec/mpegvideo.c
View file @
c62c07d3
...
@@ -468,13 +468,17 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
...
@@ -468,13 +468,17 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
#undef COPY
#undef COPY
}
}
static
void
update_duplicate_context
(
MpegEncContext
*
dst
,
MpegEncContext
*
src
){
void
ff_
update_duplicate_context
(
MpegEncContext
*
dst
,
MpegEncContext
*
src
){
MpegEncContext
bak
;
MpegEncContext
bak
;
int
i
;
//FIXME copy only needed parts
//FIXME copy only needed parts
//START_TIMER
//START_TIMER
backup_duplicate_context
(
&
bak
,
dst
);
backup_duplicate_context
(
&
bak
,
dst
);
memcpy
(
dst
,
src
,
sizeof
(
MpegEncContext
));
memcpy
(
dst
,
src
,
sizeof
(
MpegEncContext
));
backup_duplicate_context
(
dst
,
&
bak
);
backup_duplicate_context
(
dst
,
&
bak
);
for
(
i
=
0
;
i
<
12
;
i
++
){
dst
->
pblocks
[
i
]
=
(
short
*
)(
&
dst
->
block
[
i
]);
}
//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
}
}
...
@@ -4632,7 +4636,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
...
@@ -4632,7 +4636,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s
->
mb_intra
=
0
;
//for the rate distoration & bit compare functions
s
->
mb_intra
=
0
;
//for the rate distoration & bit compare functions
for
(
i
=
1
;
i
<
s
->
avctx
->
thread_count
;
i
++
){
for
(
i
=
1
;
i
<
s
->
avctx
->
thread_count
;
i
++
){
update_duplicate_context
(
s
->
thread_context
[
i
],
s
);
ff_
update_duplicate_context
(
s
->
thread_context
[
i
],
s
);
}
}
/* Estimate motion for every MB */
/* Estimate motion for every MB */
...
...
libavcodec/mpegvideo.h
View file @
c62c07d3
...
@@ -736,6 +736,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
...
@@ -736,6 +736,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
void
ff_write_quant_matrix
(
PutBitContext
*
pb
,
int16_t
*
matrix
);
void
ff_write_quant_matrix
(
PutBitContext
*
pb
,
int16_t
*
matrix
);
int
ff_find_unused_picture
(
MpegEncContext
*
s
,
int
shared
);
int
ff_find_unused_picture
(
MpegEncContext
*
s
,
int
shared
);
void
ff_denoise_dct
(
MpegEncContext
*
s
,
DCTELEM
*
block
);
void
ff_denoise_dct
(
MpegEncContext
*
s
,
DCTELEM
*
block
);
void
ff_update_duplicate_context
(
MpegEncContext
*
dst
,
MpegEncContext
*
src
);
void
ff_er_frame_start
(
MpegEncContext
*
s
);
void
ff_er_frame_start
(
MpegEncContext
*
s
);
void
ff_er_frame_end
(
MpegEncContext
*
s
);
void
ff_er_frame_end
(
MpegEncContext
*
s
);
...
...
Write
Preview
Markdown
is supported
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