Skip to content

Commit

Permalink
8338701: Provide media support for libavcodec version 61
Browse files Browse the repository at this point in the history
Reviewed-by: sykora, arapte
  • Loading branch information
Alexander Matveev committed Sep 3, 2024
1 parent 4652282 commit 6115b39
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 11 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3010,6 +3010,7 @@ project(":media") {
media name: "ffmpeg-4.0.2", ext: "tar.gz"
media name: "ffmpeg-5.1.2", ext: "tar.gz"
media name: "ffmpeg-6.0", ext: "tar.gz"
media name: "ffmpeg-7.0.2", ext: "tar.gz"
}
implementation project(":base")
implementation project(":graphics")
Expand Down Expand Up @@ -3356,8 +3357,8 @@ project(":media") {
doLast {
project.ext.libav = [:]
project.ext.libav.basedir = "${buildDir}/native/linux/ffmpeg"
project.ext.libav.versions = [ "3.3.3", "4.0.2", "5.1.2", "6.0" ]
project.ext.libav.versionmap = [ "3.3.3" : "57", "4.0.2" : "58", "5.1.2" : "59", "6.0" : "60" ]
project.ext.libav.versions = [ "3.3.3", "4.0.2", "5.1.2", "6.0", "7.0.2" ]
project.ext.libav.versionmap = [ "3.3.3" : "57", "4.0.2" : "58", "5.1.2" : "59", "6.0" : "60", "7.0.2" : "61" ]

libav.versions.each { version ->
def libavDir = "${libav.basedir}/ffmpeg-${version}"
Expand Down Expand Up @@ -3437,7 +3438,7 @@ project(":media") {
project.ext.libav.libavffmpeg.versions = [ "56" ]
project.ext.libav.ffmpeg = [:]
project.ext.libav.ffmpeg.basedir = "${buildDir}/native/linux/ffmpeg/ffmpeg"
project.ext.libav.ffmpeg.versions = [ "57", "58", "59", "60" ]
project.ext.libav.ffmpeg.versions = [ "57", "58", "59", "60", "61" ]

project.ext.libav.versions.each { version ->
def libavDir = "${project.ext.libav.basedir}-${version}"
Expand Down
5 changes: 5 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<sha256 value="f4ccf961403752c93961927715f524576d1f4dd02cd76d8c76aed3bbe6686656" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="" name="ffmpeg-7.0.2" version="">
<artifact name="ffmpeg-7.0.2-.tar.gz">
<sha256 value="1233b3a93dd7517cc3c56b72a67f64041c044848d981e3deff4bebffa25f1054" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="" name="icu4c-74_2-data-bin-l" version="">
<artifact name="icu4c-74_2-data-bin-l-.zip">
<sha256 value="2acdb1b982228040963d183b2dd9d321252c613e0f4db213d4bbc10417cde569" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -127,6 +127,7 @@ protected NativeMediaManager() {
dependencies.add("avplugin-ffmpeg-58");
dependencies.add("avplugin-ffmpeg-59");
dependencies.add("avplugin-ffmpeg-60");
dependencies.add("avplugin-ffmpeg-61");
}
if (PlatformUtil.isMac()) {
dependencies.add("fxplugins");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static const int AVCODEC_LIBAV_EXPLICIT_VERSIONS[] = { 54, 56 };
// For ffmpeg (libavcodec-ffmpeg.so)
static const int AVCODEC_FFMPEG_EXPLICIT_VERSIONS[] = { 56 };
// For libav or ffmpeg (libavcodec.so)
static const int AVCODEC_EXPLICIT_VERSIONS[] = { 57, 58, 59, 60 };
static const int AVCODEC_EXPLICIT_VERSIONS[] = { 57, 58, 59, 60, 61 };

/*
* Callback passed to dl_iterate_phdr(): finds the path of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,5 +53,13 @@
// Not required since 58 and removed in 59
#define NO_REGISTER_ALL (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,0,0))

// Do not use reordered_opaque to pass PTS. Use AVPacket.pts/AVFrame.pts instead.
// reordered_opaque is removed since 61.
#define NO_REORDERED_OPAQUE (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,0,0))

// Use AVCodecContext.frame_num instead of AVCodecContext.frame_number. They same
// except frame_num is 64-bit and frame_number is 32-bit. Since 61.
#define USE_FRAME_NUM (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,0,0))

#endif /* AVDEFINES_H */

Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,11 @@ static gboolean videodecoder_convert_frame(VideoDecoder *decoder)
if (ret < 0)
return FALSE;

#if NO_REORDERED_OPAQUE
decoder->dest_frame->pts = base->frame->pts;
#else // NO_REORDERED_OPAQUE
decoder->dest_frame->reordered_opaque = base->frame->reordered_opaque;
#endif // NO_REORDERED_OPAQUE

return TRUE;
}
Expand Down Expand Up @@ -679,7 +683,7 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe
GstMapInfo info2;
gboolean unmap_buf = FALSE;
gboolean set_frame_values = TRUE;
int64_t reordered_opaque = AV_NOPTS_VALUE;
int64_t pts = AV_NOPTS_VALUE;
unsigned int out_buf_size = 0;
gboolean copy_error = FALSE;
uint8_t* data0 = NULL;
Expand Down Expand Up @@ -711,10 +715,17 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe
if (av_new_packet(&decoder->packet, info.size) == 0)
{
memcpy(decoder->packet.data, info.data, info.size);
#if NO_REORDERED_OPAQUE
if (GST_BUFFER_TIMESTAMP_IS_VALID(buf))
decoder->packet.pts = (int64_t)GST_BUFFER_TIMESTAMP(buf);
else
decoder->packet.pts = AV_NOPTS_VALUE;
#else // NO_REORDERED_OPAQUE
if (GST_BUFFER_TIMESTAMP_IS_VALID(buf))
base->context->reordered_opaque = GST_BUFFER_TIMESTAMP(buf);
else
base->context->reordered_opaque = AV_NOPTS_VALUE;
#endif // NO_REORDERED_OPAQUE
#if USE_SEND_RECEIVE
num_dec = avcodec_send_packet(base->context, &decoder->packet);
if (num_dec == 0)
Expand Down Expand Up @@ -746,10 +757,17 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe
av_init_packet(&decoder->packet);
decoder->packet.data = info.data;
decoder->packet.size = info.size;
#if NO_REORDERED_OPAQUE
if (GST_BUFFER_TIMESTAMP_IS_VALID(buf))
decoder->packet.pts = (int64_t)GST_BUFFER_TIMESTAMP(buf);
else
decoder->packet.pts = AV_NOPTS_VALUE;
#else // NO_REORDERED_OPAQUE
if (GST_BUFFER_TIMESTAMP_IS_VALID(buf))
base->context->reordered_opaque = GST_BUFFER_TIMESTAMP(buf);
else
base->context->reordered_opaque = AV_NOPTS_VALUE;
#endif // NO_REORDERED_OPAQUE

#if USE_SEND_RECEIVE
num_dec = avcodec_send_packet(base->context, &decoder->packet);
Expand Down Expand Up @@ -796,7 +814,11 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe
goto _exit;
}

reordered_opaque = decoder->dest_frame->reordered_opaque;
#if NO_REORDERED_OPAQUE
pts = decoder->dest_frame->pts;
#else // NO_REORDERED_OPAQUE
pts = decoder->dest_frame->reordered_opaque;
#endif // NO_REORDERED_OPAQUE
data0 = decoder->dest_frame->data[0];
data1 = decoder->dest_frame->data[1];
data2 = decoder->dest_frame->data[2];
Expand All @@ -806,7 +828,11 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe

if (set_frame_values)
{
reordered_opaque = base->frame->reordered_opaque;
#if NO_REORDERED_OPAQUE
pts = base->frame->pts;
#else // NO_REORDERED_OPAQUE
pts = base->frame->reordered_opaque;
#endif // NO_REORDERED_OPAQUE
data0 = base->frame->data[0];
data1 = base->frame->data[1];
data2 = base->frame->data[2];
Expand All @@ -825,10 +851,14 @@ static GstFlowReturn videodecoder_chain(GstPad *pad, GstObject *parent, GstBuffe
}
else
{
#if USE_FRAME_NUM
GST_BUFFER_OFFSET(outbuf) = base->context->frame_num;
#else // USE_FRAME_NUM
GST_BUFFER_OFFSET(outbuf) = base->context->frame_number;
if (reordered_opaque != AV_NOPTS_VALUE)
#endif // USE_FRAME_NUM
if (pts != AV_NOPTS_VALUE)
{
GST_BUFFER_TIMESTAMP(outbuf) = reordered_opaque;
GST_BUFFER_TIMESTAMP(outbuf) = pts;
GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(buf); // Duration for video usually same
}

Expand Down

3 comments on commit 6115b39

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sashamatveev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jfx23u

@openjdk
Copy link

@openjdk openjdk bot commented on 6115b39 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sashamatveev the backport was successfully created on the branch backport-sashamatveev-6115b396-master in my personal fork of openjdk/jfx23u. To create a pull request with this backport targeting openjdk/jfx23u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6115b396 from the openjdk/jfx repository.

The commit being backported was authored by Alexander Matveev on 3 Sep 2024 and was reviewed by Joeri Sykora and Ambarish Rapte.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jfx23u:

$ git fetch https://github.com/openjdk-bots/jfx23u.git backport-sashamatveev-6115b396-master:backport-sashamatveev-6115b396-master
$ git checkout backport-sashamatveev-6115b396-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jfx23u.git backport-sashamatveev-6115b396-master

Please sign in to comment.