summaryrefslogtreecommitdiffstats
path: root/libavcodec/mpegvideo.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-01-03 02:25:56 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-01-03 03:06:45 +0100
commit7d8f1158436c261d2d1657c33e731f9bec650c51 (patch)
treecf3c0261ba5202ad949af637a026b11dc4631a00 /libavcodec/mpegvideo.c
parent45552371e3434fb7aa4d0bc566fd4ef954f9af14 (diff)
parent881a5e047dc78ec9ab771817497dffec503d77ee (diff)
downloadffmpeg-streaming-7d8f1158436c261d2d1657c33e731f9bec650c51.zip
ffmpeg-streaming-7d8f1158436c261d2d1657c33e731f9bec650c51.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: mpegenc: use avctx->slices as number of slices v410enc: fix undefined signed left shift caused by integer promotion Release notes: mention cleaned up header includes fix Changelog file Fix a bunch of typos. Drop some pointless void* return value casts from av_malloc() invocations. wavpack: fix typos in previous cosmetic clean-up commit wavpack: cosmetics: K&R pretty-printing avconv: remove the 'codec framerate is different from stream' warning wavpack: determine sample_fmt before requesting a buffer bmv audio: implement new audio decoding API mpegaudiodec: skip all channels when skipping granules mpegenc: simplify muxrate calculation Conflicts: Changelog avconv.c doc/RELEASE_NOTES libavcodec/h264.c libavcodec/mpeg12.c libavcodec/mpegaudiodec.c libavcodec/mpegvideo.c libavformat/mpegenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegvideo.c')
-rw-r--r--libavcodec/mpegvideo.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 5c04e9d..90eb737 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -638,6 +638,8 @@ void MPV_common_defaults(MpegEncContext *s)
s->picture_range_start = 0;
s->picture_range_end = MAX_PICTURE_COUNT;
+
+ s->slice_context_count = 1;
}
/**
@@ -656,11 +658,13 @@ void MPV_decode_defaults(MpegEncContext *s)
*/
av_cold int MPV_common_init(MpegEncContext *s)
{
- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y,
- threads = (s->encoding ||
- (HAVE_THREADS &&
- s->avctx->active_thread_type & FF_THREAD_SLICE)) ?
- s->avctx->thread_count : 1;
+ int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
+ int nb_slices = (HAVE_THREADS &&
+ s->avctx->active_thread_type & FF_THREAD_SLICE) ?
+ s->avctx->thread_count : 1;
+
+ if (s->encoding && s->avctx->slices)
+ nb_slices = s->avctx->slices;
if (s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
s->mb_height = (s->height + 31) / 32 * 2;
@@ -673,14 +677,15 @@ av_cold int MPV_common_init(MpegEncContext *s)
return -1;
}
- if ((s->encoding || (s->avctx->active_thread_type & FF_THREAD_SLICE)) &&
- (s->avctx->thread_count > MAX_THREADS ||
- (s->avctx->thread_count > s->mb_height && s->mb_height))) {
- int max_threads = FFMIN(MAX_THREADS, s->mb_height);
- av_log(s->avctx, AV_LOG_WARNING,
- "too many threads (%d), reducing to %d\n",
- s->avctx->thread_count, max_threads);
- threads = max_threads;
+ if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) {
+ int max_slices;
+ if (s->mb_height)
+ max_slices = FFMIN(MAX_THREADS, s->mb_height);
+ else
+ max_slices = MAX_THREADS;
+ av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d),"
+ " reducing to %d\n", nb_slices, max_slices);
+ nb_slices = max_slices;
}
if ((s->width || s->height) &&
@@ -831,17 +836,20 @@ av_cold int MPV_common_init(MpegEncContext *s)
s->context_initialized = 1;
s->thread_context[0] = s;
- if (s->encoding || (HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_SLICE)) {
- for (i = 1; i < threads; i++) {
+// if (s->width && s->height) {
+ if (nb_slices > 1) {
+ for (i = 1; i < nb_slices; i++) {
s->thread_context[i] = av_malloc(sizeof(MpegEncContext));
memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
}
- for (i = 0; i < threads; i++) {
+ for (i = 0; i < nb_slices; i++) {
if (init_duplicate_context(s->thread_context[i], s) < 0)
goto fail;
- s->thread_context[i]->start_mb_y = (s->mb_height*(i ) + s->avctx->thread_count / 2) / s->avctx->thread_count;
- s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count / 2) / s->avctx->thread_count;
+ s->thread_context[i]->start_mb_y =
+ (s->mb_height * (i) + nb_slices / 2) / nb_slices;
+ s->thread_context[i]->end_mb_y =
+ (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;
}
} else {
if (init_duplicate_context(s, s) < 0)
@@ -849,6 +857,8 @@ av_cold int MPV_common_init(MpegEncContext *s)
s->start_mb_y = 0;
s->end_mb_y = s->mb_height;
}
+ s->slice_context_count = nb_slices;
+// }
return 0;
fail:
@@ -861,13 +871,14 @@ void MPV_common_end(MpegEncContext *s)
{
int i, j, k;
- if (s->encoding || (HAVE_THREADS && s->avctx->active_thread_type & FF_THREAD_SLICE)) {
- for (i = 0; i < s->avctx->thread_count; i++) {
+ if (s->slice_context_count > 1) {
+ for (i = 0; i < s->slice_context_count; i++) {
free_duplicate_context(s->thread_context[i]);
}
- for (i = 1; i < s->avctx->thread_count; i++) {
+ for (i = 1; i < s->slice_context_count; i++) {
av_freep(&s->thread_context[i]);
}
+ s->slice_context_count = 1;
} else free_duplicate_context(s);
av_freep(&s->parse_context.buffer);
OpenPOWER on IntegriCloud