From: Lukas Fellechner <Lukas.Fellechner@gmx.net>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v3 2/3] lavf/dashdec: Multithreaded DASH initialization
Date: Sun, 4 Sep 2022 23:29:06 +0200
Message-ID: <trinity-34ec8333-0fcb-49bb-8966-2a4c3d8a952a-1662326946407@3c-app-gmx-bs72> (raw)
In-Reply-To: <GV1P250MB0737A8B67A8BE9EA9D89CDCB8F789@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Aug 31 05:54:12 EEST 2022
>
> > +#if HAVE_THREADS
> > +
> > +struct work_pool_data
> > +{
> > + AVFormatContext *ctx;
> > + struct representation *pls;
> > + struct representation *common_pls;
> > + pthread_mutex_t *common_mutex;
> > + pthread_cond_t *common_condition;
> > + int is_common;
> > + int is_started;
> > + int result;
> > +};
> > +
> > +struct thread_data
>
> This is against our naming conventions: CamelCase for struct tags and
> typedefs, lowercase names with underscore for variable names.
In the code files I looked at, CamelCase is only used for typedef structs.
All structs without typedef are lower case with underscores, so I aligned
with that, originally.
I will make this a typedef struct and use CamelCase for next patch.
> > +static int init_streams_multithreaded(AVFormatContext *s, int nstreams, int threads)
> > +{
> > + DASHContext *c = s->priv_data;
> > + int ret = 0;
> > + int stream_index = 0;
> > + int i;
>
> We allow "for (int i = 0;"
Oh, I did not know that, and I did not see it being used here anywhere.
Will use in next patch, it's my preferred style, actually.
> > +
> > + // alloc data
> > + struct work_pool_data *init_data = (struct work_pool_data*)av_mallocz(sizeof(struct work_pool_data) * nstreams);
> > + if (!init_data)
> > + return AVERROR(ENOMEM);
> > +
> > + struct thread_data *thread_data = (struct thread_data*)av_mallocz(sizeof(struct thread_data) * threads);
> > + if (!thread_data)
> > + return AVERROR(ENOMEM);
>
> 1. init_data leaks here on error.
> 2. In fact, it seems to me that both init_data and thread_data are
> nowhere freed.
True, I must have lost the av_free call at some point.
> > + // init work pool data
> > + struct work_pool_data* current_data = init_data;
> > +
> > + for (i = 0; i < c->n_videos; i++) {
> > + create_work_pool_data(s, stream_index, c->videos[i],
> > + c->is_init_section_common_video ? c->videos[0] : NULL,
> > + current_data, &common_video_mutex, &common_video_cond);
> > +
> > + stream_index++;
> > + current_data++;
> > + }
> > +
> > + for (i = 0; i < c->n_audios; i++) {
> > + create_work_pool_data(s, stream_index, c->audios[i],
> > + c->is_init_section_common_audio ? c->audios[0] : NULL,
> > + current_data, &common_audio_mutex, &common_audio_cond);
> > +
> > + stream_index++;
> > + current_data++;
> > + }
> > +
> > + for (i = 0; i < c->n_subtitles; i++) {
> > + create_work_pool_data(s, stream_index, c->subtitles[i],
> > + c->is_init_section_common_subtitle ? c->subtitles[0] : NULL,
> > + current_data, &common_subtitle_mutex, &common_subtitle_cond);
> > +
> > + stream_index++;
> > + current_data++;
> > + }
>
> This is very repetitive.
Will improve for next patch.
> 1. We actually have an API to process multiple tasks by different
> threads: Look at libavutil/slicethread.h. Why can't you reuse that?
> 2. In case initialization of one of the conditions/mutexes fails, you
> are nevertheless destroying them; you are even destroying completely
> uninitialized mutexes. This is undefined behaviour. Checking the result
> of it does not fix this.
>
> - Andreas
1. The slicethread implementation is pretty hard to understand.
I was not sure if it can be used for normal parallelization, because
it looked more like some kind of thread pool for continuous data
processing. But after taking a second look, I think I can use it here.
I will try and see if it works well.
2. I was not aware that this is undefined behavior. Will switch to
PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER macros,
which return a safely initialized mutex/cond.
I also noticed one cross-thread issue that I will solve in the next patch.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-09-04 21:29 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-20 21:35 [FFmpeg-devel] [PATCH 1/1] " Lukas Fellechner
2022-08-20 21:53 ` Lukas Fellechner
2022-08-21 4:10 ` Steven Liu
2022-08-21 12:47 ` Lukas Fellechner
2022-08-21 19:26 ` [FFmpeg-devel] [PATCH v2] " Lukas Fellechner
2022-08-23 3:19 ` Steven Liu
2022-08-23 19:09 ` Lukas Fellechner
2022-08-23 19:03 ` [FFmpeg-devel] [PATCH v3 0/3] " Lukas Fellechner
2022-08-23 19:03 ` [FFmpeg-devel] [PATCH v3 1/3] lavf/dashdec: Prepare DASH decoder for multithreading Lukas Fellechner
2022-08-31 2:09 ` Steven Liu
2022-08-23 19:03 ` [FFmpeg-devel] [PATCH v3 2/3] lavf/dashdec: Multithreaded DASH initialization Lukas Fellechner
2022-08-31 2:54 ` Andreas Rheinhardt
2022-08-31 7:25 ` Steven Liu
2022-08-31 12:17 ` Andreas Rheinhardt
2022-09-04 21:29 ` Lukas Fellechner [this message]
2022-09-04 22:50 ` Andreas Rheinhardt
2022-09-05 10:15 ` Lukas Fellechner
2022-09-05 10:45 ` Andreas Rheinhardt
2022-09-05 14:28 ` Lukas Fellechner
2022-09-11 20:35 ` Lukas Fellechner
2022-08-23 19:03 ` [FFmpeg-devel] [PATCH v3 3/3] lavf/dashdec: Fix indentation after multithreading Lukas Fellechner
2022-09-05 21:16 ` [FFmpeg-devel] [PATCH v4 0/4] lavf/dashdec: Multithreaded DASH initialization Lukas Fellechner
2022-09-05 21:16 ` [FFmpeg-devel] [PATCH v4 1/4] lavf/dashdec: Prepare DASH decoder for multithreading Lukas Fellechner
2022-09-05 21:16 ` [FFmpeg-devel] [PATCH v4 2/4] lavf/dashdec: Multithreaded DASH initialization Lukas Fellechner
2022-09-05 21:16 ` [FFmpeg-devel] [PATCH v4 3/4] lavf/dashdec: Prevent cross-thread avio_opts modification Lukas Fellechner
2022-09-05 21:16 ` [FFmpeg-devel] [PATCH v4 4/4] lavf/dashdec: Fix indentation after adding multithreading Lukas Fellechner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-34ec8333-0fcb-49bb-8966-2a4c3d8a952a-1662326946407@3c-app-gmx-bs72 \
--to=lukas.fellechner@gmx.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git