* [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread
@ 2023-11-01 9:01 angus.chen-at-intel.com
2023-11-01 11:17 ` Zhao Zhili
2023-11-01 21:44 ` Michael Niedermayer
0 siblings, 2 replies; 3+ messages in thread
From: angus.chen-at-intel.com @ 2023-11-01 9:01 UTC (permalink / raw)
To: angus.chen, ffmpeg-devel
From: "Chen, Angus" <angus.chen@intel.com>
sdl2_muxer(wayland):
In ffmpeg6, we create a separate thread for muxer after calling avformat_write_header().
It may generate EGL_BAD_ACCESS when we call write_packet. This is because egl_context
is bound to previous thread.
From EGL spec: If ctx is current to some other thread, or if either draw or read are
bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
Signed-off-by: Chen, Angus <angus.chen@intel.com>
---
fftools/ffmpeg_mux.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 7a924dba6c..d9eee3bb6d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -215,12 +215,21 @@ static void *muxer_thread(void *arg)
OutputFile *of = &mux->of;
AVPacket *pkt = NULL;
int ret = 0;
+ AVFormatContext *fc = mux->fc;
pkt = av_packet_alloc();
if (!pkt) {
ret = AVERROR(ENOMEM);
goto finish;
}
+ ret = avformat_write_header(fc, &mux->opts);
+ if (ret < 0) {
+ av_log(mux, AV_LOG_ERROR, "Could not write header (incorrect codec "
+ "parameters ?): %s\n", av_err2str(ret));
+ goto finish;
+ }
+ //assert_avoptions(of->opts);
+ mux->header_written = 1;
thread_set_name(of);
@@ -599,15 +608,6 @@ int mux_check_init(Muxer *mux)
return 0;
}
- ret = avformat_write_header(fc, &mux->opts);
- if (ret < 0) {
- av_log(mux, AV_LOG_ERROR, "Could not write header (incorrect codec "
- "parameters ?): %s\n", av_err2str(ret));
- return ret;
- }
- //assert_avoptions(of->opts);
- mux->header_written = 1;
-
av_dump_format(fc, of->index, fc->url, 1);
nb_output_dumped++;
--
2.29.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread
2023-11-01 9:01 [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread angus.chen-at-intel.com
@ 2023-11-01 11:17 ` Zhao Zhili
2023-11-01 21:44 ` Michael Niedermayer
1 sibling, 0 replies; 3+ messages in thread
From: Zhao Zhili @ 2023-11-01 11:17 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: angus.chen
> On Nov 1, 2023, at 17:01, angus.chen-at-intel.com@ffmpeg.org wrote:
>
> From: "Chen, Angus" <angus.chen@intel.com>
>
> sdl2_muxer(wayland):
> In ffmpeg6, we create a separate thread for muxer after calling avformat_write_header().
> It may generate EGL_BAD_ACCESS when we call write_packet. This is because egl_context
> is bound to previous thread.
> From EGL spec: If ctx is current to some other thread, or if either draw or read are
> bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
As I replied in
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230918063728.198377-1-haihao.xiang@intel.com/
The patch only works on some platforms. SDL should run in main thread.
I don’t think it can be fixed at here.
There are at least two methods:
1. Use ffmpeg main thread to handle special tasks like this.
2. Give up and suggests user to pipe ffmpeg output to ffplay, or something like this.
>
> Signed-off-by: Chen, Angus <angus.chen@intel.com>
> ---
> fftools/ffmpeg_mux.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
> index 7a924dba6c..d9eee3bb6d 100644
> --- a/fftools/ffmpeg_mux.c
> +++ b/fftools/ffmpeg_mux.c
> @@ -215,12 +215,21 @@ static void *muxer_thread(void *arg)
> OutputFile *of = &mux->of;
> AVPacket *pkt = NULL;
> int ret = 0;
> + AVFormatContext *fc = mux->fc;
>
> pkt = av_packet_alloc();
> if (!pkt) {
> ret = AVERROR(ENOMEM);
> goto finish;
> }
> + ret = avformat_write_header(fc, &mux->opts);
> + if (ret < 0) {
> + av_log(mux, AV_LOG_ERROR, "Could not write header (incorrect codec "
> + "parameters ?): %s\n", av_err2str(ret));
> + goto finish;
> + }
> + //assert_avoptions(of->opts);
> + mux->header_written = 1;
>
> thread_set_name(of);
>
> @@ -599,15 +608,6 @@ int mux_check_init(Muxer *mux)
> return 0;
> }
>
> - ret = avformat_write_header(fc, &mux->opts);
> - if (ret < 0) {
> - av_log(mux, AV_LOG_ERROR, "Could not write header (incorrect codec "
> - "parameters ?): %s\n", av_err2str(ret));
> - return ret;
> - }
> - //assert_avoptions(of->opts);
> - mux->header_written = 1;
> -
> av_dump_format(fc, of->index, fc->url, 1);
> nb_output_dumped++;
>
> --
> 2.29.0
>
> _______________________________________________
> 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".
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread
2023-11-01 9:01 [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread angus.chen-at-intel.com
2023-11-01 11:17 ` Zhao Zhili
@ 2023-11-01 21:44 ` Michael Niedermayer
1 sibling, 0 replies; 3+ messages in thread
From: Michael Niedermayer @ 2023-11-01 21:44 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1150 bytes --]
On Wed, Nov 01, 2023 at 05:01:15PM +0800, angus.chen-at-intel.com@ffmpeg.org wrote:
> From: "Chen, Angus" <angus.chen@intel.com>
>
> sdl2_muxer(wayland):
> In ffmpeg6, we create a separate thread for muxer after calling avformat_write_header().
> It may generate EGL_BAD_ACCESS when we call write_packet. This is because egl_context
> is bound to previous thread.
> From EGL spec: If ctx is current to some other thread, or if either draw or read are
> bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
>
> Signed-off-by: Chen, Angus <angus.chen@intel.com>
> ---
> fftools/ffmpeg_mux.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
this breaks
./ffmpeg -itsoffset 1 -re -i ~/videos/mm-short.mpg -acodec libspeex -ar 16K -ac 1 -vn -bitexact -t 1 -f rtp rtp://127.0.0.1:12345 -sdp_file /tmp/speexfile.sd
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Whats the most studid thing your enemy could do ? Blow himself up
Whats the most studid thing you could do ? Give up your rights and
freedom because your enemy blew himself up.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-01 21:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01 9:01 [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: keep write_header and write_packet in the same thread angus.chen-at-intel.com
2023-11-01 11:17 ` Zhao Zhili
2023-11-01 21:44 ` Michael Niedermayer
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