Re: [FFmpeg-devel] [PATCH v2] avcodec/vp8: fix multiple ff_thread_finish_setup() calls

2019-11-26 Thread Peter Ross
On Mon, Nov 25, 2019 at 10:14:41PM +0800, zhilizhao wrote:
> Please help to merge the patch if it’s acceptable, thanks!

no code changes, it is acceptable as-is.

>
> > On Nov 18, 2019, at 7:00 PM, Peter Ross  wrote:
> > 
> > On Mon, Nov 18, 2019 at 10:34:32AM +0800, zhilizhao wrote:
> >> Ping for review, thanks!
> > 
> > approve. 还有这块补丁也跟vp7有关,可以在推送前改一下。
> 
> Since the vp7 decoder doesn’t have multi-thread capabilities, it is not 
> affected. It’s more robust with the check, of course.

you are right.
the vp7 decoder calls ff_thread_finish_setup(), but ff_thread_finish_setup 
checks the context->active_thread_type bitmask before doing anything.

> 
> vp7因不支持多线程,所以检查与否,功能上不受影响。当然,修改之后,代码看着更合理也更健壮。
> 
> > 
> >> 
> >>> On Nov 14, 2019, at 12:29 PM, quinkbl...@foxmail.com wrote:
> >>> 
> >>> From: Zhao Zhili 
> >>> 
> >>> webp decoder doesn't set update_thread_context field
> >>> 
> >>> $ ffmpeg -i rgb_q80.webp -f null -
> >>> [webp @ 0x7ffbd5823200] Multiple ff_thread_finish_setup() calls
> >>> ---
> >>> libavcodec/vp8.c | 3 ++-
> >>> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>> 
> >>> diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
> >>> index eb51d1f3c9..b4deb3ed67 100644
> >>> --- a/libavcodec/vp8.c
> >>> +++ b/libavcodec/vp8.c
> >>> @@ -2715,7 +2715,8 @@ int vp78_decode_frame(AVCodecContext *avctx, void 
> >>> *data, int *got_frame,
> >>> 
> >>>s->next_framep[VP56_FRAME_CURRENT] = curframe;
> >>> 
> >>> -ff_thread_finish_setup(avctx);
> >>> +if (avctx->codec->update_thread_context)
> >>> +ff_thread_finish_setup(avctx);
> >>> 
> >>>if (avctx->hwaccel) {
> >>>ret = avctx->hwaccel->start_frame(avctx, avpkt->data, avpkt->size);
> >>> -- 
> >>> 2.22.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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
> > -- Peter
> > (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 29/29] avformat/matroskaenc: Don't needlessly copy AVCodecParameters

2019-11-26 Thread Andreas Rheinhardt
At the end of encoding, the flac encoder sends a packet whose side-data
contains updated extradata (e.g. a correct md5 checksum). The Matroska
muxer uses this to update the CodecPrivate.

In doing so, the streams codecpar was copied. But given that writing
a flac CodecPrivate does not modify the used AVCodecParameters at all,
there is no need to do so and this commit changes this.

Signed-off-by: Andreas Rheinhardt 
---
In this patch the old extradata is restored after writing (as it is
now). I wonder whether this is really necessary or whether one should
simply overwrite the old extradata?

 libavformat/matroskaenc.c | 16 
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 10599b11df..a3426bf926 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2196,27 +2196,19 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
const AVPacket *pkt)
 break;
 case AV_CODEC_ID_FLAC:
 if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && 
!mkv->is_live) {
-AVCodecParameters *codecpriv_par;
+uint8_t *old_extradata = par->extradata;
 int64_t curpos;
 if (side_data_size != par->extradata_size) {
 av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for 
output stream %d\n",
pkt->stream_index);
 return AVERROR(EINVAL);
 }
-codecpriv_par = avcodec_parameters_alloc();
-if (!codecpriv_par)
-return AVERROR(ENOMEM);
-ret = avcodec_parameters_copy(codecpriv_par, par);
-if (ret < 0) {
-avcodec_parameters_free(_par);
-return ret;
-}
-memcpy(codecpriv_par->extradata, side_data, side_data_size);
+par->extradata = side_data;
 curpos = avio_tell(mkv->tracks_bc);
 avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
-mkv_write_codecprivate(s, mkv->tracks_bc, codecpriv_par, 1, 0);
+mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0);
 avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
-avcodec_parameters_free(_par);
+par->extradata = old_extradata;
 }
 break;
 // FIXME: Remove the following once libaom starts propagating extradata 
during init()
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 28/29] avformat/matroskaenc: Add const where appropriate

2019-11-26 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 6e1d575e3f..10599b11df 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -573,7 +573,8 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues 
*cues, mkv_track *tra
 return currentpos;
 }
 
-static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, 
AVCodecParameters *par)
+static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
+  const AVCodecParameters *par)
 {
 const uint8_t *header_start[3];
 int header_len[3];
@@ -601,7 +602,7 @@ static int put_xiph_codecpriv(AVFormatContext *s, 
AVIOContext *pb, AVCodecParame
 return 0;
 }
 
-static int put_wv_codecpriv(AVIOContext *pb, AVCodecParameters *par)
+static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
 {
 if (par->extradata && par->extradata_size == 2)
 avio_write(pb, par->extradata, 2);
@@ -611,7 +612,7 @@ static int put_wv_codecpriv(AVIOContext *pb, 
AVCodecParameters *par)
 }
 
 static int put_flac_codecpriv(AVFormatContext *s,
-  AVIOContext *pb, AVCodecParameters *par)
+  AVIOContext *pb, const AVCodecParameters *par)
 {
 int write_comment = (par->channel_layout &&
  !(par->channel_layout & ~0x3ULL) &&
@@ -659,8 +660,9 @@ static int put_flac_codecpriv(AVFormatContext *s,
 return 0;
 }
 
-static int get_aac_sample_rates(AVFormatContext *s, uint8_t *extradata, int 
extradata_size,
-int *sample_rate, int *output_sample_rate)
+static int get_aac_sample_rates(AVFormatContext *s, const uint8_t *extradata,
+int extradata_size, int *sample_rate,
+int *output_sample_rate)
 {
 MPEG4AudioConfig mp4ac;
 int ret;
@@ -692,7 +694,7 @@ static int get_aac_sample_rates(AVFormatContext *s, uint8_t 
*extradata, int extr
 }
 
 static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb,
- AVCodecParameters *par,
+ const AVCodecParameters *par,
  AVIOContext *dyn_cp)
 {
 switch (par->codec_id) {
@@ -810,7 +812,9 @@ static int mkv_write_codecprivate(AVFormatContext *s, 
AVIOContext *pb,
 return ret;
 }
 
-static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, 
AVStream *st) {
+static int mkv_write_video_color(AVIOContext *pb, const AVCodecParameters *par,
+ const AVStream *st)
+{
 AVIOContext *dyn_cp;
 uint8_t *colorinfo_ptr;
 int side_data_size = 0;
@@ -901,7 +905,7 @@ static int mkv_write_video_color(AVIOContext *pb, 
AVCodecParameters *par, AVStre
 }
 
 static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb,
-  AVStream *st)
+  const AVStream *st)
 {
 ebml_master projection;
 int side_data_size = 0;
@@ -1984,7 +1988,7 @@ fail:
 }
 
 static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
-uint32_t blockid, AVPacket *pkt, int keyframe)
+uint32_t blockid, const AVPacket *pkt, int 
keyframe)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
@@ -2090,7 +2094,7 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 }
 }
 
-static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket 
*pkt)
+static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const 
AVPacket *pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 mkv_track *track = >tracks[pkt->stream_index];
@@ -2147,7 +2151,7 @@ static void mkv_end_cluster(AVFormatContext *s)
 avio_flush(s->pb);
 }
 
-static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt)
+static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 mkv_track *track= >tracks[pkt->stream_index];
@@ -2255,7 +2259,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 return 0;
 }
 
-static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
+static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb;
@@ -2341,7 +2345,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return 0;
 }
 
-static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
+static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 int codec_type  = 

[FFmpeg-devel] [PATCH 27/29] avformat/flacenc: Add const to ff_flac_write_header() parameter

2019-11-26 Thread Andreas Rheinhardt
The extradata is not changed at all.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/flacenc.h| 2 +-
 libavformat/flacenc_header.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/flacenc.h b/libavformat/flacenc.h
index d5d53a5dcb..b308d0d021 100644
--- a/libavformat/flacenc.h
+++ b/libavformat/flacenc.h
@@ -26,7 +26,7 @@
 #include "libavcodec/bytestream.h"
 #include "avformat.h"
 
-int ff_flac_write_header(AVIOContext *pb, uint8_t *extradata,
+int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata,
  int extradata_size, int last_block);
 
 int ff_flac_is_native_layout(uint64_t channel_layout);
diff --git a/libavformat/flacenc_header.c b/libavformat/flacenc_header.c
index 61833cc8b9..aba22a59d8 100644
--- a/libavformat/flacenc_header.c
+++ b/libavformat/flacenc_header.c
@@ -26,7 +26,7 @@
 #include "avformat.h"
 #include "flacenc.h"
 
-int ff_flac_write_header(AVIOContext *pb, uint8_t *extradata,
+int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata,
  int extradata_size, int last_block)
 {
 uint8_t header[8] = {
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 26/29] avformat/matroskaenc: Check return value of ff_isom_write_hvcc()

2019-11-26 Thread Andreas Rheinhardt
The Matroska muxer currently does not check the return value of
ff_isom_write_hvcc(), the function used to write mp4-style
HEVC-extradata as Matroska also uses it. This was intentionally done in
7a5356c72 to allow remuxing from mpeg-ts.

But if ff_isom_write_hvcc() fails, it has not output anything and the
file ends up without CodecPrivate and, if the input was annex b, with
annex b data, which is against the spec. So check the return value
again.

The underlying issue of not having extradata seems to have been fixed by
the introduction of the extract_extradata bitstream filter.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 43966a4378..6e1d575e3f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -707,9 +707,8 @@ static int mkv_write_native_codecprivate(AVFormatContext 
*s, AVIOContext *pb,
 return ff_isom_write_avcc(dyn_cp, par->extradata,
   par->extradata_size);
 case AV_CODEC_ID_HEVC:
-ff_isom_write_hvcc(dyn_cp, par->extradata,
-   par->extradata_size, 0);
-return 0;
+return ff_isom_write_hvcc(dyn_cp, par->extradata,
+  par->extradata_size, 0);
 case AV_CODEC_ID_AV1:
 if (par->extradata_size)
 return ff_isom_write_av1c(dyn_cp, par->extradata,
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 25/29] avformat/matroskaenc: Adapt documentation of put_ebml_num

2019-11-26 Thread Andreas Rheinhardt
to its actual behaviour: That it uses the least amount of bytes unless
overridden.

The current documentation leaves it undefined how many bytes will be used
when no number to use has been given explicitly. But several estimates
(used to write EBML Master elements with a small length field) require
this number to be the least amount of bytes to work. Therefore change
the documentation; and remove a comment about writing length fields
indicating "unkown length". It has been outdated since 0580a122.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 4589e25707..43966a4378 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -221,7 +221,7 @@ static void put_ebml_uid(AVIOContext *pb, uint32_t 
elementid, uint64_t uid)
  * Write a number in EBML variable length format.
  *
  * @param bytes The number of bytes that need to be used to write the number.
- *  If zero, any number of bytes can be used.
+ *  If zero, the minimal number of bytes will be used.
  */
 static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
 {
@@ -231,10 +231,9 @@ static void put_ebml_num(AVIOContext *pb, uint64_t num, 
int bytes)
 av_assert0(num < (1ULL << 56) - 1);
 
 if (bytes == 0)
-// don't care how many bytes are used, so use the min
 bytes = needed_bytes;
-// the bytes needed to write the given size would exceed the bytes
-// that we need to use, so write unknown size. This shouldn't happen.
+// The bytes needed to write the given size must not exceed
+// the bytes that we ought to use.
 av_assert0(bytes >= needed_bytes);
 
 num |= 1ULL << bytes * 7;
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] doc/encoder: add the missing qsv encoders

2019-11-26 Thread Gyan



On 27-11-2019 12:34 pm, Zhong Li wrote:

Signed-off-by: Zhong Li 
---
  doc/encoders.texi | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6cf3a74..efa28ef 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2776,7 +2776,7 @@ recommended value) and do not set a size constraint.
  
  @section QSV encoders
  
-The family of Intel QuickSync Video encoders (MPEG-2, H.264 and HEVC)

+The family of Intel QuickSync Video encoders (MPEG-2, H.264, HEVC, JPEG/MJPEG 
and VP9)
  
  The ratecontrol method is selected as follows:
  

LGTM

Gyan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2] doc/demuxers: correct grammatical errors of m3u8_hold_counters option

2019-11-26 Thread Gyan



On 27-11-2019 11:33 am, Steven Liu wrote:

Suggested-by: Rodney Baker 
Signed-off-by: Steven Liu 
---
  doc/demuxers.texi | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 4e1a5cb6aa..0d13bdd1b3 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -332,7 +332,7 @@ Maximum number of times a insufficient list is attempted to 
be reloaded.
  Default value is 1000.
  
  @item m3u8_hold_counters

-Maximum number of times to load m3u8 when the m3u8 dose not refresh with new 
segments.
+The maximum number of times to load m3u8 when it refreshes without new 
segments.
  Default value is 1000.
  
  @item http_persistent


LGTM.

Suggest you change the description to this in the AVOption as well.

Gyan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] doc/encoder: add the missing qsv encoders

2019-11-26 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 doc/encoders.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6cf3a74..efa28ef 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2776,7 +2776,7 @@ recommended value) and do not set a size constraint.
 
 @section QSV encoders
 
-The family of Intel QuickSync Video encoders (MPEG-2, H.264 and HEVC)
+The family of Intel QuickSync Video encoders (MPEG-2, H.264, HEVC, JPEG/MJPEG 
and VP9)
 
 The ratecontrol method is selected as follows:
 
-- 
1.8.3.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 03/23] avformat/matroskaenc: Use random TrackUID

2019-11-26 Thread Andreas Rheinhardt
On Mon, Nov 25, 2019 at 2:57 PM Michael Niedermayer 
wrote:

> On Sun, Nov 24, 2019 at 11:05:03PM +0100, Andreas Rheinhardt wrote:
> > On Sun, Nov 24, 2019 at 8:28 PM Michael Niedermayer
> 
> > wrote:
> >
> > > On Sun, Nov 24, 2019 at 09:08:00AM +, Andreas Rheinhardt wrote:
> > > > Michael Niedermayer:
> > > > > On Wed, Nov 06, 2019 at 03:49:02AM +0100, Andreas Rheinhardt wrote:
> > > > >> Up until now, the TrackUID of a Matroska track which is supposed
> to be
> > > > >> random was not random at all: It always coincided with the
> TrackNumber
> > > > >> which is usually the 1-based index of the corresponding stream in
> the
> > > > >> array of AVStreams. This has been changed: It is now set via an
> AVLFG
> > > > >> if AVFMT_FLAG_BITEXACT is not set. Otherwise it is set like it is
> set
> > > > >> now (the only change happens if an explicit track number has been
> > > > >> choosen via dash_track_number, because the system used in the
> normal
> > > > >> situation is now used, too). In particular, no FATE tests need to
> be
> > > > >> updated.
> > > > >>
> > > > >> This also fixes a bug in case the dash_track_number option was
> used:
> > > > >> In this case the TrackUID was set to the track number, but the
> tags
> > > were
> > > > >> written with a TagTrackUID simply based upon the index, so that
> the
> > > tags
> > > > >> didn't apply to the track they ought to apply to.
> > > > >>
> > > > >> Signed-off-by: Andreas Rheinhardt 
> > > > >> ---
> > > > >> mkv_get_uid() might be overkill, but I simply wanted to be sure
> that
> > > > >> there are no collisions.
> > > > >>
> > > > >>  libavformat/matroskaenc.c | 65
> > > ++-
> > > > >>  1 file changed, 57 insertions(+), 8 deletions(-)
> > > > >>
> > > > >> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> > > > >> index de57e474be..b87d15b7ff 100644
> > > > >> --- a/libavformat/matroskaenc.c
> > > > >> +++ b/libavformat/matroskaenc.c
> > > > >> @@ -94,6 +94,7 @@ typedef struct mkv_cues {
> > > > >>  typedef struct mkv_track {
> > > > >>  int write_dts;
> > > > >>  int has_cue;
> > > > >> +uint32_tuid;
> > > > >>  int sample_rate;
> > > > >>  int64_t sample_rate_offset;
> > > > >>  int64_t last_timestamp;
> > > > >> @@ -1199,8 +1200,7 @@ static int mkv_write_track(AVFormatContext
> *s,
> > > MatroskaMuxContext *mkv,
> > > > >>  track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
> > > > >>  put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
> > > > >> mkv->is_dash ? mkv->dash_track_number : i +
> 1);
> > > > >> -put_ebml_uint (pb, MATROSKA_ID_TRACKUID,
> > > > >> -   mkv->is_dash ? mkv->dash_track_number : i +
> 1);
> > > > >> +put_ebml_uint (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
> > > > >>  put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0);// no
> > > lacing (yet)
> > > > >>
> > > > >>  if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
> > > > >> @@ -1650,7 +1650,8 @@ static int mkv_write_tags(AVFormatContext
> *s)
> > > > >>  if (!mkv_check_tag(st->metadata,
> > > MATROSKA_ID_TAGTARGETS_TRACKUID))
> > > > >>  continue;
> > > > >>
> > > > >> -ret = mkv_write_tag(s, st->metadata,
> > > MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1);
> > > > >> +ret = mkv_write_tag(s, st->metadata,
> > > MATROSKA_ID_TAGTARGETS_TRACKUID,
> > > > >> +mkv->tracks[i].uid);
> > > > >>  if (ret < 0) return ret;
> > > > >>  }
> > > > >>
> > > > >> @@ -1658,13 +1659,15 @@ static int mkv_write_tags(AVFormatContext
> *s)
> > > > >>  for (i = 0; i < s->nb_streams; i++) {
> > > > >>  AVIOContext *pb;
> > > > >>  AVStream *st = s->streams[i];
> > > > >> +mkv_track *track = >tracks[i];
> > > > >>  ebml_master tag_target;
> > > > >>  ebml_master tag;
> > > > >>
> > > > >>  if (st->codecpar->codec_type ==
> AVMEDIA_TYPE_ATTACHMENT)
> > > > >>  continue;
> > > > >>
> > > > >> -mkv_write_tag_targets(s,
> > > MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, _target);
> > > > >> +mkv_write_tag_targets(s,
> MATROSKA_ID_TAGTARGETS_TRACKUID,
> > > > >> +  track->uid, _target);
> > > > >>  pb = mkv->tags_bc;
> > > > >>
> > > > >>  tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG,
> 0);
> > > > >> @@ -1863,10 +1866,6 @@ static int
> mkv_write_header(AVFormatContext *s)
> > > > >>  version = 4;
> > > > >>  }
> > > > >>
> > > > >> -mkv->tracks = av_mallocz_array(s->nb_streams,
> > > sizeof(*mkv->tracks));
> > > > >> -if (!mkv->tracks) {
> > > > >> -return AVERROR(ENOMEM);
> > > > >> -}
> > > > >>  ebml_header = start_ebml_master(pb, EBML_ID_HEADER,
> > > MAX_EBML_HEADER_SIZE);
> > > > >>  put_ebml_uint  

[FFmpeg-devel] [PATCH v3] avformat/matroskaenc: Ignore attachments for track limit

2019-11-26 Thread Andreas Rheinhardt
Attachments are streams in FFmpeg, but they are not tracks in Matroska.
Yet they were counted when checking a limit for the number of tracks that
the Matroska muxer imposes. This is unnecessary and has been changed.

(The Matroska file format actually has practically no limit on the
number of tracks and this is purely what our muxer supports. But even if
this limit were removed/relaxed in the future, it still makes sense to
use small track numbers as this patch does, because greater numbers need
more bytes to encode.)

Signed-off-by: Andreas Rheinhardt 
---
Resending because of a merge conflict resulting from changing the type
of uid to 64 bits.

 libavformat/matroskaenc.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 86822371d1..0bef626482 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -96,6 +96,7 @@ typedef struct mkv_track {
 int write_dts;
 int has_cue;
 uint64_tuid;
+int track_num;
 int sample_rate;
 int64_t sample_rate_offset;
 int64_t last_timestamp;
@@ -1148,8 +1149,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 }
 
 track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
-put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
-   mkv->is_dash ? mkv->dash_track_number : i + 1);
+put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER, mkv->tracks[i].track_num);
 put_ebml_uid  (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
 put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0);// no lacing (yet)
 
@@ -2004,7 +2004,7 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
 uint64_t additional_id = 0;
 int64_t discard_padding = 0;
-uint8_t track_number = (mkv->is_dash ? mkv->dash_track_number : 
(pkt->stream_index + 1));
+int track_number = track->track_num;
 ebml_master block_group, block_additions, block_more;
 
 ts += track->ts_offset;
@@ -2103,6 +2103,7 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket 
*pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
+mkv_track *track = >tracks[pkt->stream_index];
 ebml_master blockgroup;
 int id_size, settings_size, size;
 uint8_t *id, *settings;
@@ -2126,13 +2127,13 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, 
AVIOContext *pb, AVPacket *p
"duration %" PRId64 " at relative offset %" PRId64 " in cluster "
"at offset %" PRId64 ". TrackNumber %d, keyframe %d\n",
size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
-   mkv->cluster_pos, pkt->stream_index + 1, 1);
+   mkv->cluster_pos, track->track_num, 1);
 
 blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 
mkv_blockgroup_size(size));
 
 put_ebml_id(pb, MATROSKA_ID_BLOCK);
 put_ebml_num(pb, size + 4, 0);
-avio_w8(pb, 0x80 | (pkt->stream_index + 1)); // this assumes 
stream_index is less than 126
+avio_w8(pb, 0x80 | track->track_num); // this assumes track_num is 
less than 126
 avio_wb16(pb, ts - mkv->cluster_pts);
 avio_w8(pb, flags);
 avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, 
pkt->size, pkt->data);
@@ -2271,7 +2272,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, 
AVPacket *pkt, int add_
 int ret;
 int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
 int64_t relative_packet_pos;
-int tracknum = mkv->is_dash ? mkv->dash_track_number : pkt->stream_index + 
1;
+int tracknum = track->track_num;
 
 if (ts == AV_NOPTS_VALUE) {
 av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
@@ -2608,14 +2609,7 @@ static int mkv_init(struct AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVLFG c;
-int i;
-
-if (s->nb_streams > MAX_TRACKS) {
-av_log(s, AV_LOG_ERROR,
-   "At most %d streams are supported for muxing in Matroska\n",
-   MAX_TRACKS);
-return AVERROR(EINVAL);
-}
+int i, nb_tracks = 0;
 
 for (i = 0; i < s->nb_streams; i++) {
 if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 ||
@@ -2650,6 +2644,7 @@ static int mkv_init(struct AVFormatContext *s)
 }
 
 for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = s->streams[i];
 mkv_track *track = >tracks[i];
 
 if (s->flags & AVFMT_FLAG_BITEXACT) {
@@ -2660,6 +2655,19 @@ static int mkv_init(struct AVFormatContext *s)
 
 // ms precision is the de-facto standard timescale for mkv files
 avpriv_set_pts_info(s->streams[i], 64, 1, 1000);
+
+if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
+  

[FFmpeg-devel] [PATCH v2] doc/demuxers: correct grammatical errors of m3u8_hold_counters option

2019-11-26 Thread Steven Liu
Suggested-by: Rodney Baker 
Signed-off-by: Steven Liu 
---
 doc/demuxers.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 4e1a5cb6aa..0d13bdd1b3 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -332,7 +332,7 @@ Maximum number of times a insufficient list is attempted to 
be reloaded.
 Default value is 1000.
 
 @item m3u8_hold_counters
-Maximum number of times to load m3u8 when the m3u8 dose not refresh with new 
segments.
+The maximum number of times to load m3u8 when it refreshes without new 
segments.
 Default value is 1000.
 
 @item http_persistent
-- 
2.15.1




___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v3 2/2] cmdutils: add show_help_protocol for get protocol options

2019-11-26 Thread Steven Liu
Signed-off-by: Steven Liu 
---
 fftools/cmdutils.c   | 14 ++
 fftools/ffmpeg_opt.c |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 84f98b7c04..0e1bb4dbb6 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1870,6 +1870,18 @@ static void show_help_demuxer(const char *name)
 show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
 }
 
+static void show_help_protocol(const char *name)
+{
+const AVClass *proto_class = avio_protocol_get_class(name);
+
+if (!proto_class) {
+av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
+return;
+}
+
+show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM);
+}
+
 static void show_help_muxer(const char *name)
 {
 const AVCodecDescriptor *desc;
@@ -2000,6 +2012,8 @@ int show_help(void *optctx, const char *opt, const char 
*arg)
 show_help_demuxer(par);
 } else if (!strcmp(topic, "muxer")) {
 show_help_muxer(par);
+} else if (!strcmp(topic, "protocol")) {
+show_help_protocol(par);
 #if CONFIG_AVFILTER
 } else if (!strcmp(topic, "filter")) {
 show_help_filter(par);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 71063cc443..8d73fa8a78 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3194,7 +3194,7 @@ void show_help_default(const char *opt, const char *arg)
"-h  -- print basic options\n"
"-h long -- print more options\n"
"-h full -- print all options (including all format and codec 
specific options, very long)\n"
-   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf\n"
+   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
"See man %s for detailed description of the options.\n"
"\n", program_name);
 
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v3 1/2] avformat/avio: add avio_protocol_get_class

2019-11-26 Thread Steven Liu
Suggested-by: Hendrik Leppkes 
Suggested-by: Nicolas George 
Signed-off-by: Steven Liu 
---
 doc/APIchanges  |  3 +++
 libavformat/avio.h  |  7 +++
 libavformat/protocols.c | 10 ++
 libavformat/version.h   |  2 +-
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 401c65a753..2798bec400 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-11-26 - xx - lavf 58.36.100 - avio.h
+  Add avio_protocol_get_class().
+
 2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
   Add av_expr_count_vars().
 
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 9141642e75..d022820a6e 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -807,6 +807,13 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
  */
 const char *avio_enum_protocols(void **opaque, int output);
 
+/**
+ * Get AVClass by names of available protocols.
+ *
+ * @return A AVClass of input protocol name or NULL
+ */
+const AVClass *avio_protocol_get_class(const char *name);
+
 /**
  * Pause and resume playing - only meaningful if using a network streaming
  * protocol (e.g. MMS).
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index face5b29b5..29fb99e7fa 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -107,6 +107,16 @@ const char *avio_enum_protocols(void **opaque, int output)
 return avio_enum_protocols(opaque, output);
 }
 
+const AVClass *avio_protocol_get_class(const char *name)
+{
+int i = 0;
+for (i = 0; url_protocols[i]; i++) {
+if (!strcmp(url_protocols[i]->name, name))
+return url_protocols[i]->priv_data_class;
+}
+return NULL;
+}
+
 const URLProtocol **ffurl_get_protocols(const char *whitelist,
 const char *blacklist)
 {
diff --git a/libavformat/version.h b/libavformat/version.h
index bac54aed9d..f72fb9478a 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  35
+#define LIBAVFORMAT_VERSION_MINOR  36
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 2/2] cmdutils: add show_help_protocol for get protocol options

2019-11-26 Thread Steven Liu


> 在 2019年11月27日,12:52,Limin Wang  写道:
> 
> On Wed, Nov 27, 2019 at 11:11:58AM +0800, Steven Liu wrote:
>> Signed-off-by: Steven Liu 
>> ---
>> fftools/cmdutils.c   | 18 ++
>> fftools/ffmpeg_opt.c |  2 +-
>> 2 files changed, 19 insertions(+), 1 deletion(-)
>> 
>> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
>> index 84f98b7c04..96b823f74a 100644
>> --- a/fftools/cmdutils.c
>> +++ b/fftools/cmdutils.c
>> @@ -1870,6 +1870,22 @@ static void show_help_demuxer(const char *name)
>> show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
>> }
>> 
>> +static void show_help_protocol(const char *name)
>> +{
>> +const AVClass *proto_class = avio_protocol_get_class(name);
>> +
>> +printf("Protocol [%s]:\n"
>> +   " D. = Input supported\n"
>> +   " .E = Output supported\n"
>> +   " --\n", name);
> 
> It's better to move the print message after the next NULL pointer checking.
I think i should remove it, because the encoder/muxer/decoder/demuxer have no 
this message too.
> 
>> +if (!proto_class) {
>> +av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
>> +return;
>> +}
>> +
>> +show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | 
>> AV_OPT_FLAG_ENCODING_PARAM);
>> +}
>> +
>> static void show_help_muxer(const char *name)
>> {
>> const AVCodecDescriptor *desc;
>> @@ -2000,6 +2016,8 @@ int show_help(void *optctx, const char *opt, const 
>> char *arg)
>> show_help_demuxer(par);
>> } else if (!strcmp(topic, "muxer")) {
>> show_help_muxer(par);
>> +} else if (!strcmp(topic, "protocol")) {
>> +show_help_protocol(par);
>> #if CONFIG_AVFILTER
>> } else if (!strcmp(topic, "filter")) {
>> show_help_filter(par);
>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> index 71063cc443..8d73fa8a78 100644
>> --- a/fftools/ffmpeg_opt.c
>> +++ b/fftools/ffmpeg_opt.c
>> @@ -3194,7 +3194,7 @@ void show_help_default(const char *opt, const char 
>> *arg)
>>"-h  -- print basic options\n"
>>"-h long -- print more options\n"
>>"-h full -- print all options (including all format and codec 
>> specific options, very long)\n"
>> -   "-h type=name -- print all options for the named 
>> decoder/encoder/demuxer/muxer/filter/bsf\n"
>> +   "-h type=name -- print all options for the named 
>> decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
>>"See man %s for detailed description of the options.\n"
>>"\n", program_name);
>> 
>> -- 
>> 2.15.1
>> 
>> 
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Thanks
Steven





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avformat/matroskaenc: Don't waste bytes on length fields

2019-11-26 Thread Andreas Rheinhardt
Several EBML master elements for which a good upper bound of the final
length was available were nevertheless written as unknown-length
EBML-elements, so that their length field was eight bytes long. This has
been changed.

Signed-off-by: Andreas Rheinhardt 
---
Resending because of updated FATE-tests.

 libavformat/matroskaenc.c|  8 ++---
 tests/fate/wavpack.mak   |  4 +--
 tests/ref/fate/aac-autobsf-adtstoasc |  4 +--
 tests/ref/fate/rgb24-mkv |  4 +--
 tests/ref/lavf/mka   |  4 +--
 tests/ref/lavf/mkv   |  4 +--
 tests/ref/lavf/mkv_attachment|  4 +--
 tests/ref/seek/lavf-mkv  | 44 ++--
 8 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 0de38cd5fa..3e88adb037 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -862,7 +862,7 @@ static int mkv_write_video_color(AVIOContext *pb, 
AVCodecParameters *par, AVStre
 _data_size);
 if (side_data_size == sizeof(AVMasteringDisplayMetadata)) {
 ebml_master meta_element = start_ebml_master(
-dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0);
+dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 10 * (2 + 1 + 8));
 const AVMasteringDisplayMetadata *metadata =
 (const AVMasteringDisplayMetadata*)side_data;
 if (metadata->has_primaries) {
@@ -1339,7 +1339,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 // no mkv-specific ID, use ACM mode
 put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
 
-subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0);
+subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
 put_ebml_uint  (pb, MATROSKA_ID_AUDIOCHANNELS, par->channels);
 
 mkv->tracks[i].sample_rate_offset = avio_tell(pb);
@@ -1522,7 +1522,7 @@ static int mkv_write_tag_targets(AVFormatContext *s, 
uint32_t elementid,
 pb = mkv->tags_bc;
 
 *tag= start_ebml_master(pb, MATROSKA_ID_TAG,0);
-targets = start_ebml_master(pb, MATROSKA_ID_TAGTARGETS, 0);
+targets = start_ebml_master(pb, MATROSKA_ID_TAGTARGETS, 4 + 1 + 8);
 if (elementid)
 put_ebml_uid(pb, elementid, uid);
 end_ebml_master(pb, targets);
@@ -1621,7 +1621,7 @@ static int mkv_write_tags(AVFormatContext *s)
 return ret;
 pb = mkv->tags_bc;
 
-tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 0);
+tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 2 + 1 + 8 + 23);
 put_ebml_string(pb, MATROSKA_ID_TAGNAME, "DURATION");
 mkv->tracks[i].duration_offset = avio_tell(pb);
 
diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak
index 9beaec188d..b0d4b8684d 100644
--- a/tests/fate/wavpack.mak
+++ b/tests/fate/wavpack.mak
@@ -91,12 +91,12 @@ fate-wavpack-matroskamode: CMD = md5 -i 
$(TARGET_SAMPLES)/wavpack/special/matros
 FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono
 fate-wavpack-matroska_mux-mono: CMD = md5pipe -i 
$(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -fflags 
+bitexact -f matroska
 fate-wavpack-matroska_mux-mono: CMP = oneline
-fate-wavpack-matroska_mux-mono: REF = 9108dd5afb464a190e9a8a651f2c837d
+fate-wavpack-matroska_mux-mono: REF = b9042fc61a7ca18346d51a0aafaccc49
 
 FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-61
 fate-wavpack-matroska_mux-61: CMD = md5pipe -i 
$(TARGET_SAMPLES)/wavpack/num_channels/eva_2.22_6.1_16bit-partial.wv -c copy 
-fflags +bitexact -f matroska
 fate-wavpack-matroska_mux-61: CMP = oneline
-fate-wavpack-matroska_mux-61: REF = 7de5d61441b6e69f88cde309052c674a
+fate-wavpack-matroska_mux-61: REF = f89fa8284b3aed34551ad0c24c2f6e9b
 
 FATE_SAMPLES_AVCONV += $(FATE_WAVPACK-yes)
 fate-wavpack: $(FATE_WAVPACK-yes)
diff --git a/tests/ref/fate/aac-autobsf-adtstoasc 
b/tests/ref/fate/aac-autobsf-adtstoasc
index 6071094b32..dfd4dae812 100644
--- a/tests/ref/fate/aac-autobsf-adtstoasc
+++ b/tests/ref/fate/aac-autobsf-adtstoasc
@@ -1,5 +1,5 @@
-846cf1175327be8dfab5bc815c127d8b 
*tests/data/fate/aac-autobsf-adtstoasc.matroska
-6653 tests/data/fate/aac-autobsf-adtstoasc.matroska
+dba2af7796d301833a55ab1c24363ff5 
*tests/data/fate/aac-autobsf-adtstoasc.matroska
+6632 tests/data/fate/aac-autobsf-adtstoasc.matroska
 #extradata 0:2, 0x0030001c
 #tb 0: 1/1000
 #media_type 0: audio
diff --git a/tests/ref/fate/rgb24-mkv b/tests/ref/fate/rgb24-mkv
index 7ce09a967e..34b9c016ed 100644
--- a/tests/ref/fate/rgb24-mkv
+++ b/tests/ref/fate/rgb24-mkv
@@ -1,5 +1,5 @@
-5ad0f72ea98538a361ee22be58e36694 *tests/data/fate/rgb24-mkv.matroska
-58242 tests/data/fate/rgb24-mkv.matroska
+351a0bedb6bf18179e2b02d15e677241 *tests/data/fate/rgb24-mkv.matroska
+58221 tests/data/fate/rgb24-mkv.matroska
 #tb 0: 1/10
 

[FFmpeg-devel] [PATCH v2] avformat/matroskaenc: Improve cues in case of no-video

2019-11-26 Thread Andreas Rheinhardt
The Matroska muxer currently only adds CuePoints in three cases:
a) For video keyframes. b) For the first audio frame in a new cluster if
in dash-mode. c) For subtitles. This means that ordinary Matroska audio
files won't have any cues which impedes seeking.

This commit changes this. For every track in a file without video track
it is checked and tracked whether a cue entry has already been added
for said track for the current cluster. This is used to add a cue entry
for each first packet of each track in each cluster.

Implements #3149.

Signed-off-by: Andreas Rheinhardt 
---
Resending because of updated FATE-tests.

 libavformat/matroskaenc.c| 21 -
 tests/ref/fate/aac-autobsf-adtstoasc |  4 ++--
 tests/ref/lavf/mka   |  4 ++--
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c684603575..ec96e1e5f0 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2147,6 +2147,10 @@ static void mkv_end_cluster(AVFormatContext *s)
 MatroskaMuxContext *mkv = s->priv_data;
 
 end_ebml_master_crc32(s->pb, >cluster_bc, mkv);
+if (!mkv->have_video) {
+for (int i = 0; i < s->nb_streams; i++)
+mkv->tracks[i].has_cue = 0;
+}
 mkv->cluster_pos = -1;
 avio_flush(s->pb);
 }
@@ -2259,7 +2263,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
AVPacket *pkt)
 return 0;
 }
 
-static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int 
add_cue)
+static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *pb;
@@ -2303,10 +2307,12 @@ static int mkv_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt, int add_
 
 if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
 mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
-if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == 
AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) {
+if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && keyframe &&
+(par->codec_type == AVMEDIA_TYPE_VIDEO || !mkv->have_video && 
!track->has_cue)) {
 ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, ts,
mkv->cluster_pos, relative_packet_pos, -1);
 if (ret < 0) return ret;
+track->has_cue = 1;
 }
 } else {
 if (par->codec_id == AV_CODEC_ID_WEBVTT) {
@@ -2371,8 +2377,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 // on seeing key frames.
 start_new_cluster = keyframe;
 } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO &&
-   (mkv->cluster_pos == -1 ||
-cluster_time > mkv->cluster_time_limit)) {
+   cluster_time > mkv->cluster_time_limit) {
 // For DASH audio, we create a Cluster based on cluster_time_limit
 start_new_cluster = 1;
 } else if (!mkv->is_dash &&
@@ -2396,9 +2401,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 // check if we have an audio packet cached
 if (mkv->cur_audio_pkt.size > 0) {
-// for DASH audio, a CuePoint has to be added when there is a new 
cluster.
-ret = mkv_write_packet_internal(s, >cur_audio_pkt,
-mkv->is_dash ? start_new_cluster : 0);
+ret = mkv_write_packet_internal(s, >cur_audio_pkt);
 av_packet_unref(>cur_audio_pkt);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR,
@@ -2413,7 +2416,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (pkt->size > 0)
 ret = av_packet_ref(>cur_audio_pkt, pkt);
 } else
-ret = mkv_write_packet_internal(s, pkt, 0);
+ret = mkv_write_packet_internal(s, pkt);
 return ret;
 }
 
@@ -2442,7 +2445,7 @@ static int mkv_write_trailer(AVFormatContext *s)
 
 // check if we have an audio packet cached
 if (mkv->cur_audio_pkt.size > 0) {
-ret = mkv_write_packet_internal(s, >cur_audio_pkt, 0);
+ret = mkv_write_packet_internal(s, >cur_audio_pkt);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR,
"Could not write cached audio packet ret:%d\n", ret);
diff --git a/tests/ref/fate/aac-autobsf-adtstoasc 
b/tests/ref/fate/aac-autobsf-adtstoasc
index 311af5d5fa..6071094b32 100644
--- a/tests/ref/fate/aac-autobsf-adtstoasc
+++ b/tests/ref/fate/aac-autobsf-adtstoasc
@@ -1,5 +1,5 @@
-64fef0158181534b35c716e89663df3a 
*tests/data/fate/aac-autobsf-adtstoasc.matroska
-6625 tests/data/fate/aac-autobsf-adtstoasc.matroska
+846cf1175327be8dfab5bc815c127d8b 
*tests/data/fate/aac-autobsf-adtstoasc.matroska
+6653 tests/data/fate/aac-autobsf-adtstoasc.matroska
 #extradata 0:2, 0x0030001c
 #tb 0: 1/1000
 #media_type 0: audio
diff --git a/tests/ref/lavf/mka b/tests/ref/lavf/mka
index 

[FFmpeg-devel] [PATCH v2] avformat/matroskaenc: Avoid allocations for seekheads

2019-11-26 Thread Andreas Rheinhardt
Up until e7ddafd5, the Matroska muxer wrote two seekheads: One at the
beginning referencing the main level 1 elements (i.e. not the clusters)
and one at the end, referencing the clusters. This second seekhead was
useless and has therefore been removed. Yet the seekhead-related
functions and structures are still geared towards this usecase: They
are built around an allocated array of variable size that gets
reallocated every time an element is added to it although the maximum
number of seekheads is a small compile-time constant, so that one should
rather include the array in the seekhead structure itself; and said
structure should be contained in the MatroskaMuxContext instead of being
allocated separately.

The earlier code reserved space for a SeekHead with 10 entries, although
we currently write at most 6. Reducing said number implied that every
Matroska/Webm file will be 84 bytes smaller and required to adapt
several FATE tests.

Signed-off-by: Andreas Rheinhardt 
---
Resending because of updated FATE-tests.

 libavformat/matroskaenc.c| 113 ---
 tests/fate/matroska.mak  |   2 +-
 tests/fate/wavpack.mak   |   4 +-
 tests/ref/fate/aac-autobsf-adtstoasc |   4 +-
 tests/ref/fate/binsub-mksenc |   2 +-
 tests/ref/fate/rgb24-mkv |   4 +-
 tests/ref/lavf/mka   |   4 +-
 tests/ref/lavf/mkv   |   4 +-
 tests/ref/lavf/mkv_attachment|   4 +-
 tests/ref/seek/lavf-mkv  |  44 +--
 10 files changed, 67 insertions(+), 118 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 31ea1800b3..b60908a587 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -56,6 +56,10 @@
 #include "libavcodec/mpeg4audio.h"
 #include "libavcodec/internal.h"
 
+/* Level 1 elements we create a SeekHead entry for:
+ * Info, Tracks, Chapters, Attachments, Tags and Cues */
+#define MAX_SEEKHEAD_ENTRIES 6
+
 typedef struct ebml_master {
 int64_t pos;///< absolute offset in the containing 
AVIOContext where the master's elements start
 int sizebytes;  ///< how many bytes were reserved for 
the size
@@ -68,11 +72,9 @@ typedef struct mkv_seekhead_entry {
 
 typedef struct mkv_seekhead {
 int64_t filepos;
-int64_t segment_offset; ///< the file offset to the 
beginning of the segment
-int reserved_size;  ///< -1 if appending to file
-int max_entries;
-mkv_seekhead_entry  *entries;
+mkv_seekhead_entry  entries[MAX_SEEKHEAD_ENTRIES];
 int num_entries;
+int reserved_size;
 } mkv_seekhead;
 
 typedef struct mkv_cuepoint {
@@ -126,7 +128,7 @@ typedef struct MatroskaMuxContext {
 int64_t cluster_pts;
 int64_t duration_offset;
 int64_t duration;
-mkv_seekhead*seekhead;
+mkv_seekheadseekhead;
 mkv_cues*cues;
 mkv_track   *tracks;
 
@@ -398,10 +400,6 @@ static void mkv_deinit(AVFormatContext *s)
 ffio_free_dyn_buf(>tracks_bc);
 ffio_free_dyn_buf(>tags_bc);
 
-if (mkv->seekhead) {
-av_freep(>seekhead->entries);
-av_freep(>seekhead);
-}
 if (mkv->cues) {
 av_freep(>cues->entries);
 av_freep(>cues);
@@ -410,61 +408,32 @@ static void mkv_deinit(AVFormatContext *s)
 }
 
 /**
- * Initialize a mkv_seekhead element to be ready to index level 1 Matroska
- * elements. If a maximum number of elements is specified, enough space
- * will be reserved at the current file location to write a seek head of
- * that size.
- *
- * @param segment_offset The absolute offset to the position in the file
- *   where the segment begins.
- * @param numelements The maximum number of elements that will be indexed
- *by this seek head, 0 if unlimited.
+ * Initialize the seekhead element to be ready to index level 1 Matroska
+ * elements. Enough space to write MAX_SEEKHEAD_ENTRIES seekhead entries
+ * will be reserved at the current file location.
  */
-static mkv_seekhead *mkv_start_seekhead(AVIOContext *pb, int64_t 
segment_offset,
-int numelements)
+static void mkv_start_seekhead(MatroskaMuxContext *mkv, AVIOContext *pb)
 {
-mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead));
-if (!new_seekhead)
-return NULL;
-
-new_seekhead->segment_offset = segment_offset;
-
-if (numelements > 0) {
-new_seekhead->filepos = avio_tell(pb);
+mkv->seekhead.filepos = avio_tell(pb);
 // 21 bytes max for a seek entry, 10 bytes max for the SeekHead ID
 // and size, 6 bytes for a CRC32 element, and 3 bytes to guarantee
 // that an EBML void element will fit afterwards
-new_seekhead->reserved_size = numelements * MAX_SEEKENTRY_SIZE + 19;

[FFmpeg-devel] [PATCH v2 5/5] avformat/matroskaenc: Make output more deterministic

2019-11-26 Thread Andreas Rheinhardt
Using random values for TrackUID and FileUID (as happens when the
AVFMT_FLAG_BITEXACT flag is not set) has the obvious downside of making
the output indeterministic. This commit mitigates this by writing the
potentially random values with a fixed size of eight byte, even if their
actual values would fit into less than eight bytes. This ensures that
even in non-bitexact mode, the differences between two files generated
with the same settings are restricted to a few bytes in the header.
(Namely the SegmentUID, the TrackUIDs (in Tracks as well as when
referencing them in the TagTrackUID), the FileUIDs (in Attachments as
well as in TagAttachmentUID) as well as the CRC-32 checksums of the
Info, Tracks, Attachments and Tags level-1-elements.) Without this
patch, there might be an offset/a size difference between two such
files.

The FATE-tests had to be updated because the fixed-sized UIDs are also
used in bitexact-mode.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c| 16 --
 tests/fate/matroska.mak  |  2 +-
 tests/fate/wavpack.mak   |  4 +--
 tests/ref/fate/aac-autobsf-adtstoasc |  4 +--
 tests/ref/fate/binsub-mksenc |  2 +-
 tests/ref/fate/rgb24-mkv |  4 +--
 tests/ref/lavf/mka   |  4 +--
 tests/ref/lavf/mkv   |  4 +--
 tests/ref/lavf/mkv_attachment|  4 +--
 tests/ref/seek/lavf-mkv  | 44 ++--
 10 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 1833d2a122..89bf68114c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -205,6 +205,16 @@ static int ebml_num_size(uint64_t num)
 return bytes;
 }
 
+/**
+ * Write a (random) UID with fixed size to make the output more deterministic
+ */
+static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid)
+{
+put_ebml_id(pb, elementid);
+avio_w8(pb, 0x88);
+avio_wb64(pb, uid);
+}
+
 /**
  * Write a number in EBML variable length format.
  *
@@ -1186,7 +1196,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
 put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
mkv->is_dash ? mkv->dash_track_number : i + 1);
-put_ebml_uint (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
+put_ebml_uid  (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
 put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0);// no lacing (yet)
 
 if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
@@ -1562,7 +1572,7 @@ static int mkv_write_tag_targets(AVFormatContext *s, 
uint32_t elementid,
 *tag= start_ebml_master(pb, MATROSKA_ID_TAG,0);
 targets = start_ebml_master(pb, MATROSKA_ID_TAGTARGETS, 0);
 if (elementid)
-put_ebml_uint(pb, elementid, uid);
+put_ebml_uid(pb, elementid, uid);
 end_ebml_master(pb, targets);
 return 0;
 }
@@ -1766,7 +1776,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 
 put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
 put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, 
st->codecpar->extradata_size);
-put_ebml_uint(dyn_cp, MATROSKA_ID_FILEUID, track->uid);
+put_ebml_uid(dyn_cp, MATROSKA_ID_FILEUID, track->uid);
 end_ebml_master(dyn_cp, attached_file);
 }
 end_ebml_master_crc32(pb, _cp, mkv);
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 98a49a4d74..7c48de1a61 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -4,7 +4,7 @@
 FATE_MATROSKA-$(call DEMMUX, MATROSKA, MATROSKA) += fate-matroska-remux
 fate-matroska-remux: CMD = md5pipe -i 
$(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-2pass-akiyo.webm -color_trc 4 -c:v 
copy -fflags +bitexact -strict -2 -f matroska
 fate-matroska-remux: CMP = oneline
-fate-matroska-remux: REF = e5457e5fa606d564a54914bd12f426c8
+fate-matroska-remux: REF = 5ae8144848acd392eaca8d43ff4aa5e6
 
 FATE_MATROSKA_FFPROBE-$(call ALLYES, MATROSKA_DEMUXER) += 
fate-matroska-spherical-mono
 fate-matroska-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream_side_data_list -select_streams v -v 0 
$(TARGET_SAMPLES)/mkv/spherical.mkv
diff --git a/tests/fate/wavpack.mak b/tests/fate/wavpack.mak
index 286e17f2ae..b7bb563802 100644
--- a/tests/fate/wavpack.mak
+++ b/tests/fate/wavpack.mak
@@ -91,12 +91,12 @@ fate-wavpack-matroskamode: CMD = md5 -i 
$(TARGET_SAMPLES)/wavpack/special/matros
 FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono
 fate-wavpack-matroska_mux-mono: CMD = md5pipe -i 
$(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -fflags 
+bitexact -f matroska
 fate-wavpack-matroska_mux-mono: CMP = oneline
-fate-wavpack-matroska_mux-mono: REF = c5a2b46d8b31c9c2e7bfb436f9d56f02
+fate-wavpack-matroska_mux-mono: REF = 

[FFmpeg-devel] [PATCH v2 4/5] avformat/matroskaenc: Remove allocations for attachments

2019-11-26 Thread Andreas Rheinhardt
If there are attachments to write, the Matroska muxer currently
allocates two objects: An array that contains an entry for each
attachment containing just the stream index of the corresponding
stream and the uid used for this attachment; and a structure with
a pointer to said array and a counter for said array. These uids are
generated via code special to attachments: It uses an AVLFG in the
normal and a sha of the attachment data in the bitexact case. (Said sha
requires an allocation, too.)

But now that an uid is generated for each stream in mkv_init(), there is
no need any more to use special code for generating the uids of
attachments: One can simply use the uid already generated for the
attachment stream. And this makes the whole allocations of the structures
for attachments as well as the structures itself superfluous. They have
been removed.

In case AVFMT_FLAG_BITEXACT is set, the uids will be different from the
old ones which is the reason why the FATE-test lavf-mkv_attachment
needed to be updated. The old method had the drawback that muxing the
same attachment twice in the same file would create a file where two
attachments have the same uid. The new one doesn't.

Also notice that the dynamic buffer used to write the attachments leaks
if an error happens when writing the buffer. By removing the
allocations potential sources of errors have been removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 63 +--
 tests/ref/lavf/mkv_attachment |  4 +--
 2 files changed, 11 insertions(+), 56 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index aecd776157..1833d2a122 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -50,7 +50,6 @@
 #include "libavutil/random_seed.h"
 #include "libavutil/rational.h"
 #include "libavutil/samplefmt.h"
-#include "libavutil/sha.h"
 #include "libavutil/stereo3d.h"
 
 #include "libavcodec/xiph.h"
@@ -104,16 +103,6 @@ typedef struct mkv_track {
 int64_t ts_offset;
 } mkv_track;
 
-typedef struct mkv_attachment {
-int stream_idx;
-uint32_tfileuid;
-} mkv_attachment;
-
-typedef struct mkv_attachments {
-mkv_attachment  *entries;
-int num_entries;
-} mkv_attachments;
-
 #define MODE_MATROSKAv2 0x01
 #define MODE_WEBM   0x02
 
@@ -140,7 +129,6 @@ typedef struct MatroskaMuxContext {
 mkv_seekhead*seekhead;
 mkv_cues*cues;
 mkv_track   *tracks;
-mkv_attachments *attachments;
 
 AVPacketcur_audio_pkt;
 
@@ -408,10 +396,6 @@ static void mkv_deinit(AVFormatContext *s)
 av_freep(>cues->entries);
 av_freep(>cues);
 }
-if (mkv->attachments) {
-av_freep(>attachments->entries);
-av_freep(>attachments);
-}
 av_freep(>tracks);
 }
 
@@ -1700,14 +1684,17 @@ static int mkv_write_tags(AVFormatContext *s)
 }
 
 if (mkv->have_attachments && mkv->mode != MODE_WEBM) {
-for (i = 0; i < mkv->attachments->num_entries; i++) {
-mkv_attachment *attachment = >attachments->entries[i];
-AVStream *st = s->streams[attachment->stream_idx];
+for (i = 0; i < s->nb_streams; i++) {
+mkv_track *track = >tracks[i];
+AVStream *st = s->streams[i];
+
+if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
+continue;
 
 if (!mkv_check_tag(st->metadata, MATROSKA_ID_TAGTARGETS_ATTACHUID))
 continue;
 
-ret = mkv_write_tag(s, st->metadata, 
MATROSKA_ID_TAGTARGETS_ATTACHUID, attachment->fileuid);
+ret = mkv_write_tag(s, st->metadata, 
MATROSKA_ID_TAGTARGETS_ATTACHUID, track->uid);
 if (ret < 0)
 return ret;
 }
@@ -1726,18 +1713,11 @@ static int mkv_write_attachments(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVIOContext *dyn_cp, *pb = s->pb;
-AVLFG c;
 int i, ret;
 
 if (!mkv->have_attachments)
 return 0;
 
-mkv->attachments = av_mallocz(sizeof(*mkv->attachments));
-if (!mkv->attachments)
-return AVERROR(ENOMEM);
-
-av_lfg_init(, av_get_random_seed());
-
 ret = mkv_add_seekhead_entry(mkv->seekhead, MATROSKA_ID_ATTACHMENTS, 
avio_tell(pb));
 if (ret < 0) return ret;
 
@@ -1746,20 +1726,14 @@ static int mkv_write_attachments(AVFormatContext *s)
 
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
+mkv_track *track = >tracks[i];
 ebml_master attached_file;
-mkv_attachment *attachment = mkv->attachments->entries;
 AVDictionaryEntry *t;
 const char *mimetype = NULL;
-uint32_t fileuid;
 
 if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
 continue;
 
-attachment = av_realloc_array(attachment, 
mkv->attachments->num_entries + 1, sizeof(mkv_attachment));
-if (!attachment)
-

[FFmpeg-devel] [PATCH v2 2/5] avformat/matroskaenc: Use random TrackUID

2019-11-26 Thread Andreas Rheinhardt
Up until now, the TrackUID of a Matroska track which is supposed to be
random was not random at all: It always coincided with the TrackNumber
which is usually the 1-based index of the corresponding stream in the
array of AVStreams. This has been changed: It is now set via an AVLFG
if AVFMT_FLAG_BITEXACT is not set. Otherwise it is set like it is set
now (the only change happens if an explicit track number has been
chosen via dash_track_number, because the system used in the normal
situation is now used, too). In particular, no FATE tests need to be
updated.

This also fixes a bug in case the dash_track_number option was used:
In this case the TrackUID was set to the track number, but the tags were
written with a TagTrackUID simply based upon the index, so that the tags
didn't apply to the track they ought to apply to.

Signed-off-by: Andreas Rheinhardt 
---
Changed the UID to 64bit and also removed the possibility to call
av_get_random_seed() more than once during init. Furthermore improved
the choice of UID a bit more in case of collisions.

 libavformat/matroskaenc.c | 65 ++-
 1 file changed, 57 insertions(+), 8 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 1d3203c969..98be7f7a2f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -94,6 +94,7 @@ typedef struct mkv_cues {
 typedef struct mkv_track {
 int write_dts;
 int has_cue;
+uint64_tuid;
 int sample_rate;
 int64_t sample_rate_offset;
 int64_t last_timestamp;
@@ -1199,8 +1200,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
 put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
mkv->is_dash ? mkv->dash_track_number : i + 1);
-put_ebml_uint (pb, MATROSKA_ID_TRACKUID,
-   mkv->is_dash ? mkv->dash_track_number : i + 1);
+put_ebml_uint (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
 put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0);// no lacing (yet)
 
 if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
@@ -1651,7 +1651,8 @@ static int mkv_write_tags(AVFormatContext *s)
 if (!mkv_check_tag(st->metadata, MATROSKA_ID_TAGTARGETS_TRACKUID))
 continue;
 
-ret = mkv_write_tag(s, st->metadata, MATROSKA_ID_TAGTARGETS_TRACKUID, 
i + 1);
+ret = mkv_write_tag(s, st->metadata, MATROSKA_ID_TAGTARGETS_TRACKUID,
+mkv->tracks[i].uid);
 if (ret < 0) return ret;
 }
 
@@ -1659,13 +1660,15 @@ static int mkv_write_tags(AVFormatContext *s)
 for (i = 0; i < s->nb_streams; i++) {
 AVIOContext *pb;
 AVStream *st = s->streams[i];
+mkv_track *track = >tracks[i];
 ebml_master tag_target;
 ebml_master tag;
 
 if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
 continue;
 
-mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, 
_target);
+mkv_write_tag_targets(s, MATROSKA_ID_TAGTARGETS_TRACKUID,
+  track->uid, _target);
 pb = mkv->tags_bc;
 
 tag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG, 0);
@@ -1865,10 +1868,6 @@ static int mkv_write_header(AVFormatContext *s)
 version = 4;
 }
 
-mkv->tracks = av_mallocz_array(s->nb_streams, sizeof(*mkv->tracks));
-if (!mkv->tracks) {
-return AVERROR(ENOMEM);
-}
 ebml_header = start_ebml_master(pb, EBML_ID_HEADER, MAX_EBML_HEADER_SIZE);
 put_ebml_uint  (pb, EBML_ID_EBMLVERSION   ,   1);
 put_ebml_uint  (pb, EBML_ID_EBMLREADVERSION   ,   1);
@@ -2670,8 +2669,42 @@ static int webm_query_codec(enum AVCodecID codec_id, int 
std_compliance)
 return 0;
 }
 
+static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
+{
+uint64_t uid;
+
+for (int j = 0, k; j < 5; j++) {
+uid  = (uint64_t)av_lfg_get(c) << 32;
+uid |= av_lfg_get(c);
+if (!uid)
+continue;
+for (k = 0; k < i; k++) {
+if (tracks[k].uid == uid)
+break;
+}
+if (k == i)
+return uid;
+}
+
+/* Make the uid odd so that it is invertible mod 2^n.
+ * This implies that the multiples of uid below are all distinct. */
+uid |= 1;
+for (int j = 1, k; j < i + 1; j++) {
+for (k = 0; k < i; k++) {
+if (tracks[k].uid == j * uid)
+break;
+}
+if (k == i)
+return j * uid;
+}
+/* Return (i + 1) * uid. It can't coincide with another uid. */
+return (i + 1) * uid;
+}
+
 static int mkv_init(struct AVFormatContext *s)
 {
+MatroskaMuxContext *mkv = s->priv_data;
+AVLFG c;
 int i;
 
 if (s->nb_streams > MAX_TRACKS) {
@@ -2700,7 

[FFmpeg-devel] [PATCH v2 1/5] avformat/matroskaenc: Ensure that ChapterUID are != 0

2019-11-26 Thread Andreas Rheinhardt
AVChapters have an int as id field and therefore this value can appear
<= 0. When remuxing from Matroska, this value is actually the lower 32
bits of the original ChapterUID (which can be 64 bits).

In order to ensure that the ChapterUID be always > 0, they were offset
as follows (since 07704c61): First max(0, 1LL - chapter[i].id) was computed
and stored in an uint32_t. And then the IDs were offset using this value.

This has two downsides:
1. It does not ensure that the UID is actually != 0: Namely if there is
a chapter with id == INT_MIN, then the offset will be 2^31 + 1 and a
chapter with id == INT_MAX will become 2^31 - 1 + 2^31 + 1 = 2^32 = 0,
because the actual calculation was performed in 32 bits.
2. As soon as a chapter id appears to be negative, a nontrivial offset
is used, so that not even a ChapterUID that only uses 32 bits is
preserved.

So change this by treating the id as an unsigned value internally and
only offset (by 1) if an id vanishes. The actual offsetting then has to
be performed in 64 bits in order to make sure that no UINT32_MAX wraps
around.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 5c04ec98f6..1d3203c969 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1500,7 +1500,8 @@ static int mkv_write_chapters(AVFormatContext *s)
 }
 
 chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0);
-put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID, c->id + 
mkv->chapter_id_offset);
+put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID,
+  (uint32_t)c->id + (uint64_t)mkv->chapter_id_offset);
 put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
 put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
 if (mkv->mode != MODE_WEBM) {
@@ -1557,7 +1558,7 @@ static int mkv_write_simpletag(AVIOContext *pb, 
AVDictionaryEntry *t)
 }
 
 static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid,
- unsigned int uid, ebml_master *tag)
+ uint64_t uid, ebml_master *tag)
 {
 AVIOContext *pb;
 MatroskaMuxContext *mkv = s->priv_data;
@@ -1595,7 +1596,7 @@ static int mkv_check_tag_name(const char *name, uint32_t 
elementid)
 }
 
 static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, uint32_t 
elementid,
- unsigned int uid)
+ uint64_t uid)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 ebml_master tag;
@@ -1686,7 +1687,8 @@ static int mkv_write_tags(AVFormatContext *s)
 if (!mkv_check_tag(ch->metadata, 
MATROSKA_ID_TAGTARGETS_CHAPTERUID))
 continue;
 
-ret = mkv_write_tag(s, ch->metadata, 
MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id + mkv->chapter_id_offset);
+ret = mkv_write_tag(s, ch->metadata, 
MATROSKA_ID_TAGTARGETS_CHAPTERUID,
+(uint32_t)ch->id + 
(uint64_t)mkv->chapter_id_offset);
 if (ret < 0)
 return ret;
 }
@@ -1961,7 +1963,10 @@ static int mkv_write_header(AVFormatContext *s)
 return ret;
 
 for (i = 0; i < s->nb_chapters; i++)
-mkv->chapter_id_offset = FFMAX(mkv->chapter_id_offset, 1LL - 
s->chapters[i]->id);
+if (!s->chapters[i]->id) {
+mkv->chapter_id_offset = 1;
+break;
+}
 
 ret = mkv_write_chapters(s);
 if (ret < 0)
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 3/5] avformat/matroskaenc: Reuse random seed

2019-11-26 Thread Andreas Rheinhardt
This commit reuses the random seed generated in mkv_init() to determine
the TrackUIDs for the SegmentUID in order to avoid a potentially
expensive call to av_get_random_seed().

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/matroskaenc.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 98be7f7a2f..aecd776157 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -160,6 +160,8 @@ typedef struct MatroskaMuxContext {
 int wrote_chapters;
 
 int allow_raw_vfw;
+
+uint32_t segment_uid[4];
 } MatroskaMuxContext;
 
 /** 2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint,
@@ -1909,15 +1911,7 @@ static int mkv_write_header(AVFormatContext *s)
 put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);
 
 if (mkv->mode != MODE_WEBM) {
-uint32_t segment_uid[4];
-AVLFG lfg;
-
-av_lfg_init(, av_get_random_seed());
-
-for (i = 0; i < 4; i++)
-segment_uid[i] = av_lfg_get();
-
-put_ebml_binary(pb, MATROSKA_ID_SEGMENTUID, segment_uid, 16);
+put_ebml_binary(pb, MATROSKA_ID_SEGMENTUID, mkv->segment_uid, 16);
 }
 } else {
 const char *ident = "Lavf";
@@ -2738,9 +2732,14 @@ static int mkv_init(struct AVFormatContext *s)
 return AVERROR(ENOMEM);
 }
 
-if (!(s->flags & AVFMT_FLAG_BITEXACT))
+if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
 av_lfg_init(, av_get_random_seed());
 
+// Calculate the SegmentUID now in order not to waste our random seed.
+for (i = 0; i < 4; i++)
+mkv->segment_uid[i] = av_lfg_get();
+}
+
 for (i = 0; i < s->nb_streams; i++) {
 mkv_track *track = >tracks[i];
 
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 2/2] cmdutils: add show_help_protocol for get protocol options

2019-11-26 Thread Limin Wang
On Wed, Nov 27, 2019 at 11:11:58AM +0800, Steven Liu wrote:
> Signed-off-by: Steven Liu 
> ---
>  fftools/cmdutils.c   | 18 ++
>  fftools/ffmpeg_opt.c |  2 +-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 84f98b7c04..96b823f74a 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -1870,6 +1870,22 @@ static void show_help_demuxer(const char *name)
>  show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
>  }
>  
> +static void show_help_protocol(const char *name)
> +{
> +const AVClass *proto_class = avio_protocol_get_class(name);
> +
> +printf("Protocol [%s]:\n"
> +   " D. = Input supported\n"
> +   " .E = Output supported\n"
> +   " --\n", name);

It's better to move the print message after the next NULL pointer checking.

> +if (!proto_class) {
> +av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
> +return;
> +}
> +
> +show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | 
> AV_OPT_FLAG_ENCODING_PARAM);
> +}
> +
>  static void show_help_muxer(const char *name)
>  {
>  const AVCodecDescriptor *desc;
> @@ -2000,6 +2016,8 @@ int show_help(void *optctx, const char *opt, const char 
> *arg)
>  show_help_demuxer(par);
>  } else if (!strcmp(topic, "muxer")) {
>  show_help_muxer(par);
> +} else if (!strcmp(topic, "protocol")) {
> +show_help_protocol(par);
>  #if CONFIG_AVFILTER
>  } else if (!strcmp(topic, "filter")) {
>  show_help_filter(par);
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 71063cc443..8d73fa8a78 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -3194,7 +3194,7 @@ void show_help_default(const char *opt, const char *arg)
> "-h  -- print basic options\n"
> "-h long -- print more options\n"
> "-h full -- print all options (including all format and codec 
> specific options, very long)\n"
> -   "-h type=name -- print all options for the named 
> decoder/encoder/demuxer/muxer/filter/bsf\n"
> +   "-h type=name -- print all options for the named 
> decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
> "See man %s for detailed description of the options.\n"
> "\n", program_name);
>  
> -- 
> 2.15.1
> 
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/2] cmdutils: add show_help_protocol for get protocol options

2019-11-26 Thread Steven Liu
Signed-off-by: Steven Liu 
---
 fftools/cmdutils.c   | 18 ++
 fftools/ffmpeg_opt.c |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 84f98b7c04..96b823f74a 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1870,6 +1870,22 @@ static void show_help_demuxer(const char *name)
 show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
 }
 
+static void show_help_protocol(const char *name)
+{
+const AVClass *proto_class = avio_protocol_get_class(name);
+
+printf("Protocol [%s]:\n"
+   " D. = Input supported\n"
+   " .E = Output supported\n"
+   " --\n", name);
+if (!proto_class) {
+av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
+return;
+}
+
+show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM);
+}
+
 static void show_help_muxer(const char *name)
 {
 const AVCodecDescriptor *desc;
@@ -2000,6 +2016,8 @@ int show_help(void *optctx, const char *opt, const char 
*arg)
 show_help_demuxer(par);
 } else if (!strcmp(topic, "muxer")) {
 show_help_muxer(par);
+} else if (!strcmp(topic, "protocol")) {
+show_help_protocol(par);
 #if CONFIG_AVFILTER
 } else if (!strcmp(topic, "filter")) {
 show_help_filter(par);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 71063cc443..8d73fa8a78 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3194,7 +3194,7 @@ void show_help_default(const char *opt, const char *arg)
"-h  -- print basic options\n"
"-h long -- print more options\n"
"-h full -- print all options (including all format and codec 
specific options, very long)\n"
-   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf\n"
+   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
"See man %s for detailed description of the options.\n"
"\n", program_name);
 
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] avformat/avio: add avio_protocol_get_class

2019-11-26 Thread Steven Liu
Suggested-by: Hendrik Leppkes 
Suggested-by: Nicolas George 
Signed-off-by: Steven Liu 
---
 doc/APIchanges  |  3 +++
 libavformat/avio.h  |  7 +++
 libavformat/protocols.c | 10 ++
 libavformat/version.h   |  2 +-
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 401c65a753..2798bec400 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-11-26 - xx - lavf 58.36.100 - avio.h
+  Add avio_protocol_get_class().
+
 2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
   Add av_expr_count_vars().
 
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 9141642e75..d022820a6e 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -807,6 +807,13 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
  */
 const char *avio_enum_protocols(void **opaque, int output);
 
+/**
+ * Get AVClass by names of available protocols.
+ *
+ * @return A AVClass of input protocol name or NULL
+ */
+const AVClass *avio_protocol_get_class(const char *name);
+
 /**
  * Pause and resume playing - only meaningful if using a network streaming
  * protocol (e.g. MMS).
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index face5b29b5..29fb99e7fa 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -107,6 +107,16 @@ const char *avio_enum_protocols(void **opaque, int output)
 return avio_enum_protocols(opaque, output);
 }
 
+const AVClass *avio_protocol_get_class(const char *name)
+{
+int i = 0;
+for (i = 0; url_protocols[i]; i++) {
+if (!strcmp(url_protocols[i]->name, name))
+return url_protocols[i]->priv_data_class;
+}
+return NULL;
+}
+
 const URLProtocol **ffurl_get_protocols(const char *whitelist,
 const char *blacklist)
 {
diff --git a/libavformat/version.h b/libavformat/version.h
index bac54aed9d..f72fb9478a 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  35
+#define LIBAVFORMAT_VERSION_MINOR  36
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat: expose avlanguage.h

2019-11-26 Thread Aman Gupta
From: Aman Gupta 

Signed-off-by: Aman Gupta 
---
 doc/APIchanges   | 3 +++
 libavformat/Makefile | 1 +
 libavformat/avlanguage.c | 2 --
 libavformat/avlanguage.h | 5 +
 libavformat/version.h| 2 +-
 5 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 401c65a753..0cf9a6e2a3 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-11-26 - xx - lavf 58.36.100 - avlanguage.h
+  Add av_convert_lang_to().
+
 2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
   Add av_expr_count_vars().
 
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 52f29b1a6d..7460f73fa2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -3,6 +3,7 @@ DESC = FFmpeg container format library
 
 HEADERS = avformat.h\
   avio.h\
+  avlanguage.h  \
   version.h \
 
 OBJS = allformats.o \
diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
index f5d2ddf304..1673dc4726 100644
--- a/libavformat/avlanguage.c
+++ b/libavformat/avlanguage.c
@@ -764,9 +764,7 @@ const char *ff_convert_lang_to(const char *lang, enum 
AVLangCodespace target_cod
 return NULL;
 }
 
-#if LIBAVFORMAT_VERSION_MAJOR < 58
 const char *av_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace)
 {
 return ff_convert_lang_to(lang, target_codespace);
 }
-#endif
diff --git a/libavformat/avlanguage.h b/libavformat/avlanguage.h
index 1d72dcb3cb..00f2b15f03 100644
--- a/libavformat/avlanguage.h
+++ b/libavformat/avlanguage.h
@@ -37,10 +37,7 @@ enum AVLangCodespace {
  * Convert a language code to a target codespace. The source codespace is 
guessed.
  * @return NULL if the provided lang is null or invalid.
  */
-const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace);
-#if LIBAVFORMAT_VERSION_MAJOR < 58
-attribute_deprecated
 const char *av_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace);
-#endif
+const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace);
 
 #endif /* AVFORMAT_AVLANGUAGE_H */
diff --git a/libavformat/version.h b/libavformat/version.h
index bac54aed9d..f72fb9478a 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  35
+#define LIBAVFORMAT_VERSION_MINOR  36
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: Fix some code indentations

2019-11-26 Thread Zhong Li
LGTM. WIll apply

Linjie Fu  于2019年11月26日周二 下午12:01写道:
>
> Signed-off-by: Linjie Fu 
> ---
>  libavcodec/qsvenc.c | 8 
>  libavcodec/qsvenc.h | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 93d49ba..e176d57 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -764,10 +764,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>
>  #if QSV_HAVE_EXT_VP9_PARAM
>  if (avctx->codec_id == AV_CODEC_ID_VP9) {
> -   q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
> -   q->extvp9param.Header.BufferSz = sizeof(q->extvp9param);
> -   q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
> -   q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
> *)>extvp9param;
> +q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
> +q->extvp9param.Header.BufferSz = sizeof(q->extvp9param);
> +q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
> +q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
> *)>extvp9param;
>  }
>  #endif
>
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index a3e9357..ee35582 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -125,7 +125,7 @@ typedef struct QSVEncContext {
>  mfxExtMultiFrameControl extmfc;
>  #endif
>  #if QSV_HAVE_EXT_VP9_PARAM
> -   mfxExtVP9Param  extvp9param;
> +mfxExtVP9Param  extvp9param;
>  #endif
>
>  mfxExtOpaqueSurfaceAlloc opaque_alloc;
> --
> 2.7.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/avlanguage: deprecate av_convert_lang_to and make it internal

2019-11-26 Thread James Almer
On 11/26/2019 9:29 PM, Aman Gupta wrote:
> On Fri, May 13, 2016 at 2:29 PM James Almer  wrote:
> 
>> The header was never installed and the function is only used in libavformat
>>
> 
> I think av_convert_lang_to would be a useful public function. Do you mind
> if I redefine it, and export the header this time?
> 
> libavformat returns iso639-2 codes in AVStream.metadata's "language" entry.
> This can be problematic on some platforms like iOS where NSLocale can only
> understand iso639-1 codes. ff_convert_lang_to is used for the same purpose
> internally, so exposing it would make it easier for users to perform the
> same conversion.
> 
> Aman

Feel free to send a patch. I was doing some ABI clean up when i
committed this, and have no opinion on this functionality. Others might,
though.

Also, you made me realize i never deleted the dead code left after the
bump in avlanguage.*
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/avlanguage: deprecate av_convert_lang_to and make it internal

2019-11-26 Thread Aman Gupta
On Fri, May 13, 2016 at 2:29 PM James Almer  wrote:

> The header was never installed and the function is only used in libavformat
>

I think av_convert_lang_to would be a useful public function. Do you mind
if I redefine it, and export the header this time?

libavformat returns iso639-2 codes in AVStream.metadata's "language" entry.
This can be problematic on some platforms like iOS where NSLocale can only
understand iso639-1 codes. ff_convert_lang_to is used for the same purpose
internally, so exposing it would make it easier for users to perform the
same conversion.

Aman


>
> Signed-off-by: James Almer 
> ---
>  libavformat/asfdec_f.c|  2 +-
>  libavformat/asfdec_o.c|  2 +-
>  libavformat/asfenc.c  |  2 +-
>  libavformat/avienc.c  |  2 +-
>  libavformat/avlanguage.c  | 11 +--
>  libavformat/avlanguage.h  |  7 +++
>  libavformat/matroskaenc.c |  2 +-
>  7 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
> index 2c81b13..b973eff 100644
> --- a/libavformat/asfdec_f.c
> +++ b/libavformat/asfdec_f.c
> @@ -912,7 +912,7 @@ static int asf_read_header(AVFormatContext *s)
>  const char *rfc1766 =
> asf->stream_languages[asf->streams[i].stream_language_index];
>  if (rfc1766 && strlen(rfc1766) > 1) {
>  const char primary_tag[3] = { rfc1766[0], rfc1766[1],
> '\0' }; // ignore country code if any
> -const char *iso6392   =
> av_convert_lang_to(primary_tag,
> +const char *iso6392   =
> ff_convert_lang_to(primary_tag,
>
> AV_LANG_ISO639_2_BIBL);
>  if (iso6392)
>  av_dict_set(>metadata, "language", iso6392,
> 0);
> diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
> index 1c564a8..f8caf16 100644
> --- a/libavformat/asfdec_o.c
> +++ b/libavformat/asfdec_o.c
> @@ -829,7 +829,7 @@ static void set_language(AVFormatContext *s, const
> char *rfc1766, AVDictionary *
>  // language abbr should contain at least 2 chars
>  if (rfc1766 && strlen(rfc1766) > 1) {
>  const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; //
> ignore country code if any
> -const char *iso6392   = av_convert_lang_to(primary_tag,
> +const char *iso6392   = ff_convert_lang_to(primary_tag,
>
> AV_LANG_ISO639_2_BIBL);
>  if (iso6392)
>  if (av_dict_set(met, "language", iso6392, 0) < 0)
> diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
> index cfa4fad..93ab167 100644
> --- a/libavformat/asfenc.c
> +++ b/libavformat/asfenc.c
> @@ -431,7 +431,7 @@ static int asf_write_header1(AVFormatContext *s,
> int64_t file_size,
>
>  entry = av_dict_get(s->streams[n]->metadata, "language", NULL, 0);
>  if (entry) {
> -const char *iso6391lang = av_convert_lang_to(entry->value,
> AV_LANG_ISO639_1);
> +const char *iso6391lang = ff_convert_lang_to(entry->value,
> AV_LANG_ISO639_1);
>  if (iso6391lang) {
>  int i;
>  for (i = 0; i < asf->nb_languages; i++) {
> diff --git a/libavformat/avienc.c b/libavformat/avienc.c
> index c908c21..59ad2b2 100644
> --- a/libavformat/avienc.c
> +++ b/libavformat/avienc.c
> @@ -435,7 +435,7 @@ static int avi_write_header(AVFormatContext *s)
>  }
>  if (par->codec_id == AV_CODEC_ID_XSUB
>  && (t = av_dict_get(s->streams[i]->metadata, "language",
> NULL, 0))) {
> -const char* langstr = av_convert_lang_to(t->value,
> AV_LANG_ISO639_1);
> +const char* langstr = ff_convert_lang_to(t->value,
> AV_LANG_ISO639_1);
>  t = NULL;
>  if (langstr) {
>  char* str = av_asprintf("Subtitle - %s-xx;02",
> langstr);
> diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
> index 39f2560..f5d2ddf 100644
> --- a/libavformat/avlanguage.c
> +++ b/libavformat/avlanguage.c
> @@ -733,7 +733,7 @@ static int lang_table_compare(const void *lhs, const
> void *rhs)
>  return strcmp(lhs, ((const LangEntry *)rhs)->str);
>  }
>
> -const char *av_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
> +const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
>  {
>  int i;
>  const LangEntry *entry = NULL;
> @@ -759,7 +759,14 @@ const char *av_convert_lang_to(const char *lang, enum
> AVLangCodespace target_cod
>  entry = lang_table + entry->next_equivalent;
>
>  if (target_codespace == AV_LANG_ISO639_2_TERM)
> -return av_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
> +return ff_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
>
>  return NULL;
>  }
> +
> +#if LIBAVFORMAT_VERSION_MAJOR < 58
> +const char *av_convert_lang_to(const char *lang, enum AVLangCodespace
> target_codespace)
> +{
> +return ff_convert_lang_to(lang, target_codespace);
> +}

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/26/19, James Almer  wrote:
> On 11/25/2019 6:09 PM, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol 
>> ---
>>  libavcodec/Makefile |   1 +
>>  libavcodec/allcodecs.c  |   1 +
>>  libavcodec/avcodec.h|   1 +
>>  libavcodec/codec_desc.c |   7 ++
>>  libavcodec/midivid.c| 272 
>>  libavformat/riff.c  |   1 +
>>  6 files changed, 283 insertions(+)
>>  create mode 100644 libavcodec/midivid.c
>
> [...]
>
>> diff --git a/libavcodec/midivid.c b/libavcodec/midivid.c
>> new file mode 100644
>> index 00..36ed4b83bd
>> --- /dev/null
>> +++ b/libavcodec/midivid.c
>> @@ -0,0 +1,272 @@
>> +/*
>> + * MidiVid decoder
>> + * Copyright (c) 2019 Paul B Mahol
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "libavutil/imgutils.h"
>> +#include "libavutil/internal.h"
>> +#include "libavutil/intreadwrite.h"
>> +#include "libavutil/mem.h"
>> +
>> +#define BITSTREAM_READER_LE
>> +#include "avcodec.h"
>> +#include "get_bits.h"
>> +#include "bytestream.h"
>> +#include "internal.h"
>> +
>> +typedef struct MidiVidContext {
>> +GetByteContext gb;
>> +
>> +uint8_t *uncompressed;
>> +int uncompressed_size;
>
> Should be unsigned int, seeing it's used as argument for
> av_fast_padded_malloc().

Ok.

>
>> +uint8_t *skip;
>> +
>> +AVFrame *frame;
>> +} MidiVidContext;
>> +
>> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame
>> *frame)
>> +{
>> +GetByteContext *gb = >gb;
>> +GetBitContext mask;
>> +GetByteContext idx9;
>> +uint16_t nb_vectors, intra_flag;
>> +const uint8_t *vec;
>> +const uint8_t *mask_start;
>> +uint8_t *skip;
>> +int mask_size;
>> +int idx9bits = 0;
>> +int idx9val = 0;
>> +int num_blocks;
>> +
>> +nb_vectors = bytestream2_get_le16(gb);
>> +intra_flag = bytestream2_get_le16(gb);
>> +if (intra_flag) {
>> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>> +} else {
>> +int skip_linesize;
>> +
>> +num_blocks = bytestream2_get_le32(gb);
>> +skip_linesize = avctx->width >> 1;
>> +mask_start = gb->buffer_start + bytestream2_tell(gb);
>> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>> +init_get_bits8(, mask_start, mask_size);
>> +bytestream2_skip(gb, mask_size);
>> +skip = s->skip;
>> +
>> +for (int y = 0; y < avctx->height >> 2; y++) {
>> +for (int x = 0; x < avctx->width >> 2; x++) {
>> +int flag = !get_bits1();
>> +
>> +skip[(y*2)  *skip_linesize + x*2  ] = flag;
>> +skip[(y*2)  *skip_linesize + x*2+1] = flag;
>> +skip[(y*2+1)*skip_linesize + x*2  ] = flag;
>> +skip[(y*2+1)*skip_linesize + x*2+1] = flag;
>> +}
>> +}
>> +}
>> +
>> +vec = gb->buffer_start + bytestream2_tell(gb);
>
> Isn't this the same as doing vec = g->buffer?

No point in changing now.

>
>> +if (bytestream2_get_bytes_left(gb) < nb_vectors * 12)
>> +return AVERROR_INVALIDDATA;
>> +bytestream2_skip(gb, nb_vectors * 12);
>> +if (nb_vectors > 256) {
>> +if (bytestream2_get_bytes_left(gb) < (num_blocks + 7) / 8)
>> +return AVERROR_INVALIDDATA;
>> +bytestream2_init(, gb->buffer_start + bytestream2_tell(gb),
>> (num_blocks + 7) / 8);
>
> Ditto.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/avc: write the missing bits in the AVC Decoder Configuration Box

2019-11-26 Thread James Almer
On 11/26/2019 2:32 PM, Carl Eugen Hoyos wrote:
> Am Di., 26. Nov. 2019 um 14:07 Uhr schrieb James Almer :
>>
>> Signed-off-by: James Almer 
>> ---
>>  libavformat/avc.c | 38 +-
>>  libavformat/avc.h |  1 +
>>  2 files changed, 34 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavformat/avc.c b/libavformat/avc.c
>> index a041e84357..9bd215c07f 100644
>> --- a/libavformat/avc.c
>> +++ b/libavformat/avc.c
>> @@ -107,11 +107,11 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
>> uint8_t **buf, int *size)
>>
>>  int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
>>  {
>> -AVIOContext *sps_pb = NULL, *pps_pb = NULL;
>> +AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
>>  uint8_t *buf = NULL, *end, *start = NULL;
>> -uint8_t *sps = NULL, *pps = NULL;
>> -uint32_t sps_size = 0, pps_size = 0;
>> -int ret, nb_sps = 0, nb_pps = 0;
>> +uint8_t *sps = NULL, *pps = NULL, *sps_ext = NULL;
>> +uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
>> +int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
>>
>>  if (len <= 6)
>>  return AVERROR_INVALIDDATA;
>> @@ -133,6 +133,9 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
>> *data, int len)
>>  if (ret < 0)
>>  goto fail;
>>  ret = avio_open_dyn_buf(_pb);
>> +if (ret < 0)
>> +goto fail;
>> +ret = avio_open_dyn_buf(_ext_pb);
>>  if (ret < 0)
>>  goto fail;
>>
>> @@ -160,12 +163,21 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
>> *data, int len)
>>  }
>>  avio_wb16(pps_pb, size);
>>  avio_write(pps_pb, buf, size);
>> +} else if (nal_type == 13) { /* SPS_EXT */
>> +nb_sps_ext++;
>> +if (size > UINT16_MAX || nb_sps_ext >= 256) {
>> +ret = AVERROR_INVALIDDATA;
>> +goto fail;
>> +}
>> +avio_wb16(sps_ext_pb, size);
>> +avio_write(sps_ext_pb, buf, size);
>>  }
>>
>>  buf += size;
>>  }
>>  sps_size = avio_close_dyn_buf(sps_pb, );
>>  pps_size = avio_close_dyn_buf(pps_pb, );
>> +sps_ext_size = avio_close_dyn_buf(sps_ext_pb, _ext);
>>
>>  if (sps_size < 6 || !pps_size) {
>>  ret = AVERROR_INVALIDDATA;
>> @@ -183,13 +195,29 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
>> *data, int len)
>>  avio_w8(pb, nb_pps); /* number of pps */
>>  avio_write(pb, pps, pps_size);
>>
>> +if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
>> +H264SequenceParameterSet *seq = ff_avc_decode_sps(sps, sps_size);
>> +if (!seq)
>> +goto fail;
>> +avio_w8(pb, 0xfc | seq->chroma_format_idc); /* 6 bits reserved 
>> (11) + chroma_format_idc */
>> +avio_w8(pb, 0xf8 | seq->bit_depth_luma - 8); /* 5 bits reserved 
>> (1) + bit_depth_luma_minus8 */
>> +avio_w8(pb, 0xf8 | seq->bit_depth_chroma - 8); /* 5 bits reserved 
>> (1) + bit_depth_chroma_minus8 */
>> +avio_w8(pb, nb_sps_ext); /* number of sps ext */
>> +if (nb_sps_ext)
>> +avio_write(pb, sps_ext, sps_ext_size);
>> +av_free(seq);
>> +}
>> +
>>  fail:
>>  if (!sps)
>>  avio_close_dyn_buf(sps_pb, );
>>  if (!pps)
>>  avio_close_dyn_buf(pps_pb, );
>> +if (!sps_ext)
>> +avio_close_dyn_buf(sps_ext_pb, _ext);
>>  av_free(sps);
>>  av_free(pps);
>> +av_free(sps_ext);
>>  av_free(start);
>>
>>  return ret;
>> @@ -351,7 +379,7 @@ H264SequenceParameterSet *ff_avc_decode_sps(const 
>> uint8_t *buf, int buf_size)
>>  skip_bits1(); // separate_colour_plane_flag
>>  }
>>  sps->bit_depth_luma = get_ue_golomb() + 8;
>> -get_ue_golomb(); // bit_depth_chroma_minus8
>> +sps->bit_depth_chroma = get_ue_golomb() + 8;
>>  skip_bits1(); // qpprime_y_zero_transform_bypass_flag
>>  if (get_bits1()) { // seq_scaling_matrix_present_flag
>>  for (i = 0; i < ((sps->chroma_format_idc != 3) ? 8 : 12); i++) {
>> diff --git a/libavformat/avc.h b/libavformat/avc.h
>> index a79bf9b2db..5286d19d89 100644
>> --- a/libavformat/avc.h
>> +++ b/libavformat/avc.h
>> @@ -43,6 +43,7 @@ typedef struct {
>>  uint8_t constraint_set_flags;
>>  uint8_t chroma_format_idc;
>>  uint8_t bit_depth_luma;
>> +uint8_t bit_depth_chroma;
>>  uint8_t frame_mbs_only_flag;
>>  AVRational sar;
>>  } H264SequenceParameterSet;
> 
> Sorry if this is obvious:
> What does this patch fix?
> 
> Carl Eugen

It adds the remaining portion of the avcC box as defined in the spec.
Some parsers complain when the box ends abruptly, but most don't because
they simply stop parsing after the pps part and skip the rest, so nobody
noticed it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/26/19, James Almer  wrote:
> On 11/26/2019 4:29 PM, Paul B Mahol wrote:
>> On 11/26/19, James Almer  wrote:
>>> On 11/26/2019 6:47 AM, Paul B Mahol wrote:
 On 11/25/19, Tomas Härdin  wrote:
> mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
>> Signed-off-by: Paul B Mahol 
>> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx,
>> AVFrame
>> *frame)
>> +{
>> +GetByteContext *gb = >gb;
>> +GetBitContext mask;
>> +GetByteContext idx9;
>> +uint16_t nb_vectors, intra_flag;
>> +const uint8_t *vec;
>> +const uint8_t *mask_start;
>> +uint8_t *skip;
>> +int mask_size;
>> +int idx9bits = 0;
>> +int idx9val = 0;
>> +int num_blocks;
>> +
>> +nb_vectors = bytestream2_get_le16(gb);
>> +intra_flag = bytestream2_get_le16(gb);
>> +if (intra_flag) {
>> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>
> Will UB if width*height/4 > INT_MAX
>
>> +} else {
>> +int skip_linesize;
>> +
>> +num_blocks = bytestream2_get_le32(gb);
>
> Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
>
>> +skip_linesize = avctx->width >> 1;
>> +mask_start = gb->buffer_start + bytestream2_tell(gb);
>> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>
> This can also UB
>
> /Tomas
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

 Nothing of this can actually happen.
>>>
>>> It can and i'm fairly sure it will happen as soon as the fuzzer starts
>>> testing this decoder using big dimensions.
>>
>> I'm not that guy doing such work. Please stop bikesheding those
>> patches for once.
>>
>>>
>>> You don't need asserts here, you just need to check the calculations
>>> will not overflow. Do something like "if ((int64_t)avctx->width *
>>> avctx->height / 4 > INT_MAX) return AVERROR_INVALIDDATA" and call it a
>>> day.
>>> Also, maybe num_blocks should be unsigned, seeing you set it using
>>> bytestream2_get_le32() for P-frames.
>>
>> No decoder does this.
>
> Most decoders call av_image_check_size2() directly or indirectly to set
> dimensions, which does w*h overflow checks similar to the one above.
>

Only if they store width/height out of container.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread James Almer
On 11/26/2019 4:29 PM, Paul B Mahol wrote:
> On 11/26/19, James Almer  wrote:
>> On 11/26/2019 6:47 AM, Paul B Mahol wrote:
>>> On 11/25/19, Tomas Härdin  wrote:
 mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
> Signed-off-by: Paul B Mahol 
> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx,
> AVFrame
> *frame)
> +{
> +GetByteContext *gb = >gb;
> +GetBitContext mask;
> +GetByteContext idx9;
> +uint16_t nb_vectors, intra_flag;
> +const uint8_t *vec;
> +const uint8_t *mask_start;
> +uint8_t *skip;
> +int mask_size;
> +int idx9bits = 0;
> +int idx9val = 0;
> +int num_blocks;
> +
> +nb_vectors = bytestream2_get_le16(gb);
> +intra_flag = bytestream2_get_le16(gb);
> +if (intra_flag) {
> +num_blocks = (avctx->width / 2) * (avctx->height / 2);

 Will UB if width*height/4 > INT_MAX

> +} else {
> +int skip_linesize;
> +
> +num_blocks = bytestream2_get_le32(gb);

 Might want to use uint32_t so this doesn't lead to weirdness on 32-bit

> +skip_linesize = avctx->width >> 1;
> +mask_start = gb->buffer_start + bytestream2_tell(gb);
> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);

 This can also UB

 /Tomas

 ___
 ffmpeg-devel mailing list
 ffmpeg-devel@ffmpeg.org
 https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

 To unsubscribe, visit link above, or email
 ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>>
>>> Nothing of this can actually happen.
>>
>> It can and i'm fairly sure it will happen as soon as the fuzzer starts
>> testing this decoder using big dimensions.
> 
> I'm not that guy doing such work. Please stop bikesheding those
> patches for once.
> 
>>
>> You don't need asserts here, you just need to check the calculations
>> will not overflow. Do something like "if ((int64_t)avctx->width *
>> avctx->height / 4 > INT_MAX) return AVERROR_INVALIDDATA" and call it a day.
>> Also, maybe num_blocks should be unsigned, seeing you set it using
>> bytestream2_get_le32() for P-frames.
> 
> No decoder does this.

Most decoders call av_image_check_size2() directly or indirectly to set
dimensions, which does w*h overflow checks similar to the one above.

> 
>>
>>>
>>> Applied.
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@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-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/26/19, James Almer  wrote:
> On 11/26/2019 6:47 AM, Paul B Mahol wrote:
>> On 11/25/19, Tomas Härdin  wrote:
>>> mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
 Signed-off-by: Paul B Mahol 
 +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx,
 AVFrame
 *frame)
 +{
 +GetByteContext *gb = >gb;
 +GetBitContext mask;
 +GetByteContext idx9;
 +uint16_t nb_vectors, intra_flag;
 +const uint8_t *vec;
 +const uint8_t *mask_start;
 +uint8_t *skip;
 +int mask_size;
 +int idx9bits = 0;
 +int idx9val = 0;
 +int num_blocks;
 +
 +nb_vectors = bytestream2_get_le16(gb);
 +intra_flag = bytestream2_get_le16(gb);
 +if (intra_flag) {
 +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>>>
>>> Will UB if width*height/4 > INT_MAX
>>>
 +} else {
 +int skip_linesize;
 +
 +num_blocks = bytestream2_get_le32(gb);
>>>
>>> Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
>>>
 +skip_linesize = avctx->width >> 1;
 +mask_start = gb->buffer_start + bytestream2_tell(gb);
 +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>>>
>>> This can also UB
>>>
>>> /Tomas
>>>
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>>
>> Nothing of this can actually happen.
>
> It can and i'm fairly sure it will happen as soon as the fuzzer starts
> testing this decoder using big dimensions.

I'm not that guy doing such work. Please stop bikesheding those
patches for once.

>
> You don't need asserts here, you just need to check the calculations
> will not overflow. Do something like "if ((int64_t)avctx->width *
> avctx->height / 4 > INT_MAX) return AVERROR_INVALIDDATA" and call it a day.
> Also, maybe num_blocks should be unsigned, seeing you set it using
> bytestream2_get_le32() for P-frames.

No decoder does this.

>
>>
>> Applied.
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread James Almer
On 11/25/2019 6:09 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h|   1 +
>  libavcodec/codec_desc.c |   7 ++
>  libavcodec/midivid.c| 272 
>  libavformat/riff.c  |   1 +
>  6 files changed, 283 insertions(+)
>  create mode 100644 libavcodec/midivid.c

[...]

> diff --git a/libavcodec/midivid.c b/libavcodec/midivid.c
> new file mode 100644
> index 00..36ed4b83bd
> --- /dev/null
> +++ b/libavcodec/midivid.c
> @@ -0,0 +1,272 @@
> +/*
> + * MidiVid decoder
> + * Copyright (c) 2019 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/mem.h"
> +
> +#define BITSTREAM_READER_LE
> +#include "avcodec.h"
> +#include "get_bits.h"
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +typedef struct MidiVidContext {
> +GetByteContext gb;
> +
> +uint8_t *uncompressed;
> +int uncompressed_size;

Should be unsigned int, seeing it's used as argument for
av_fast_padded_malloc().

> +uint8_t *skip;
> +
> +AVFrame *frame;
> +} MidiVidContext;
> +
> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame 
> *frame)
> +{
> +GetByteContext *gb = >gb;
> +GetBitContext mask;
> +GetByteContext idx9;
> +uint16_t nb_vectors, intra_flag;
> +const uint8_t *vec;
> +const uint8_t *mask_start;
> +uint8_t *skip;
> +int mask_size;
> +int idx9bits = 0;
> +int idx9val = 0;
> +int num_blocks;
> +
> +nb_vectors = bytestream2_get_le16(gb);
> +intra_flag = bytestream2_get_le16(gb);
> +if (intra_flag) {
> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
> +} else {
> +int skip_linesize;
> +
> +num_blocks = bytestream2_get_le32(gb);
> +skip_linesize = avctx->width >> 1;
> +mask_start = gb->buffer_start + bytestream2_tell(gb);
> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
> +init_get_bits8(, mask_start, mask_size);
> +bytestream2_skip(gb, mask_size);
> +skip = s->skip;
> +
> +for (int y = 0; y < avctx->height >> 2; y++) {
> +for (int x = 0; x < avctx->width >> 2; x++) {
> +int flag = !get_bits1();
> +
> +skip[(y*2)  *skip_linesize + x*2  ] = flag;
> +skip[(y*2)  *skip_linesize + x*2+1] = flag;
> +skip[(y*2+1)*skip_linesize + x*2  ] = flag;
> +skip[(y*2+1)*skip_linesize + x*2+1] = flag;
> +}
> +}
> +}
> +
> +vec = gb->buffer_start + bytestream2_tell(gb);

Isn't this the same as doing vec = g->buffer?

> +if (bytestream2_get_bytes_left(gb) < nb_vectors * 12)
> +return AVERROR_INVALIDDATA;
> +bytestream2_skip(gb, nb_vectors * 12);
> +if (nb_vectors > 256) {
> +if (bytestream2_get_bytes_left(gb) < (num_blocks + 7) / 8)
> +return AVERROR_INVALIDDATA;
> +bytestream2_init(, gb->buffer_start + bytestream2_tell(gb), 
> (num_blocks + 7) / 8);

Ditto.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread James Almer
On 11/26/2019 6:47 AM, Paul B Mahol wrote:
> On 11/25/19, Tomas Härdin  wrote:
>> mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
>>> Signed-off-by: Paul B Mahol 
>>> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame
>>> *frame)
>>> +{
>>> +GetByteContext *gb = >gb;
>>> +GetBitContext mask;
>>> +GetByteContext idx9;
>>> +uint16_t nb_vectors, intra_flag;
>>> +const uint8_t *vec;
>>> +const uint8_t *mask_start;
>>> +uint8_t *skip;
>>> +int mask_size;
>>> +int idx9bits = 0;
>>> +int idx9val = 0;
>>> +int num_blocks;
>>> +
>>> +nb_vectors = bytestream2_get_le16(gb);
>>> +intra_flag = bytestream2_get_le16(gb);
>>> +if (intra_flag) {
>>> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>>
>> Will UB if width*height/4 > INT_MAX
>>
>>> +} else {
>>> +int skip_linesize;
>>> +
>>> +num_blocks = bytestream2_get_le32(gb);
>>
>> Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
>>
>>> +skip_linesize = avctx->width >> 1;
>>> +mask_start = gb->buffer_start + bytestream2_tell(gb);
>>> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>>
>> This can also UB
>>
>> /Tomas
>>
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> Nothing of this can actually happen.

It can and i'm fairly sure it will happen as soon as the fuzzer starts
testing this decoder using big dimensions.

You don't need asserts here, you just need to check the calculations
will not overflow. Do something like "if ((int64_t)avctx->width *
avctx->height / 4 > INT_MAX) return AVERROR_INVALIDDATA" and call it a day.
Also, maybe num_blocks should be unsigned, seeing you set it using
bytestream2_get_le32() for P-frames.

> 
> Applied.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/26/19, Nicolas George  wrote:
> Paul B Mahol (12019-11-26):
>> >> Nothing of this can actually happen.
>> > Then you could add asserts (and cut your quotes).
>> Asserts for checking UBs? Non sense.
>
> Assert to have debug builds check that the things you say cannot happen
> do not actually happen. That is what asserts are for: check a code
> invariant that is useful but not obvious.
>

Thank you for reminding me what are asserts for.

I will not bloat code with pointless asserts or other kind of lines.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Nicolas George
Paul B Mahol (12019-11-26):
> >> Nothing of this can actually happen.
> > Then you could add asserts (and cut your quotes).
> Asserts for checking UBs? Non sense.

Assert to have debug builds check that the things you say cannot happen
do not actually happen. That is what asserts are for: check a code
invariant that is useful but not obvious.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/utils.c: allows av_read_frame to return after a timeout period.

2019-11-26 Thread gga



On 26/11/19 14:31, Michael Niedermayer wrote:

On Thu, Nov 21, 2019 at 06:27:10PM -0300, ggarr...@gmail.com wrote:

From: Gonzalo Garramuño 

This patch is based on a patch by bsenftner at earthlink.net.
---
  libavformat/utils.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8196442dd1..c3c2c77c0c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1838,6 +1838,11 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
  }
  }
  
+if (ff_check_interrupt(>interrupt_callback)) {

+av_log(s, AV_LOG_DEBUG, "interrupted\n");
+return AVERROR_EXIT;
+}
+

I think this can be moved into the if() above, which might
reduce the number of calls.

thx
[...]

It would probably reduce only one call, as pktl (the if above) is a list 
that will get filled probably as soon as there is a packet.  Or maybe I 
am reading the code wrong?  Also, if it does not get filled, we probably 
want to exit anyway, too.


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/avc: write the missing bits in the AVC Decoder Configuration Box

2019-11-26 Thread Carl Eugen Hoyos
Am Di., 26. Nov. 2019 um 14:07 Uhr schrieb James Almer :
>
> Signed-off-by: James Almer 
> ---
>  libavformat/avc.c | 38 +-
>  libavformat/avc.h |  1 +
>  2 files changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/avc.c b/libavformat/avc.c
> index a041e84357..9bd215c07f 100644
> --- a/libavformat/avc.c
> +++ b/libavformat/avc.c
> @@ -107,11 +107,11 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
> uint8_t **buf, int *size)
>
>  int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
>  {
> -AVIOContext *sps_pb = NULL, *pps_pb = NULL;
> +AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
>  uint8_t *buf = NULL, *end, *start = NULL;
> -uint8_t *sps = NULL, *pps = NULL;
> -uint32_t sps_size = 0, pps_size = 0;
> -int ret, nb_sps = 0, nb_pps = 0;
> +uint8_t *sps = NULL, *pps = NULL, *sps_ext = NULL;
> +uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
> +int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
>
>  if (len <= 6)
>  return AVERROR_INVALIDDATA;
> @@ -133,6 +133,9 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
> *data, int len)
>  if (ret < 0)
>  goto fail;
>  ret = avio_open_dyn_buf(_pb);
> +if (ret < 0)
> +goto fail;
> +ret = avio_open_dyn_buf(_ext_pb);
>  if (ret < 0)
>  goto fail;
>
> @@ -160,12 +163,21 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
> *data, int len)
>  }
>  avio_wb16(pps_pb, size);
>  avio_write(pps_pb, buf, size);
> +} else if (nal_type == 13) { /* SPS_EXT */
> +nb_sps_ext++;
> +if (size > UINT16_MAX || nb_sps_ext >= 256) {
> +ret = AVERROR_INVALIDDATA;
> +goto fail;
> +}
> +avio_wb16(sps_ext_pb, size);
> +avio_write(sps_ext_pb, buf, size);
>  }
>
>  buf += size;
>  }
>  sps_size = avio_close_dyn_buf(sps_pb, );
>  pps_size = avio_close_dyn_buf(pps_pb, );
> +sps_ext_size = avio_close_dyn_buf(sps_ext_pb, _ext);
>
>  if (sps_size < 6 || !pps_size) {
>  ret = AVERROR_INVALIDDATA;
> @@ -183,13 +195,29 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
> *data, int len)
>  avio_w8(pb, nb_pps); /* number of pps */
>  avio_write(pb, pps, pps_size);
>
> +if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
> +H264SequenceParameterSet *seq = ff_avc_decode_sps(sps, sps_size);
> +if (!seq)
> +goto fail;
> +avio_w8(pb, 0xfc | seq->chroma_format_idc); /* 6 bits reserved 
> (11) + chroma_format_idc */
> +avio_w8(pb, 0xf8 | seq->bit_depth_luma - 8); /* 5 bits reserved 
> (1) + bit_depth_luma_minus8 */
> +avio_w8(pb, 0xf8 | seq->bit_depth_chroma - 8); /* 5 bits reserved 
> (1) + bit_depth_chroma_minus8 */
> +avio_w8(pb, nb_sps_ext); /* number of sps ext */
> +if (nb_sps_ext)
> +avio_write(pb, sps_ext, sps_ext_size);
> +av_free(seq);
> +}
> +
>  fail:
>  if (!sps)
>  avio_close_dyn_buf(sps_pb, );
>  if (!pps)
>  avio_close_dyn_buf(pps_pb, );
> +if (!sps_ext)
> +avio_close_dyn_buf(sps_ext_pb, _ext);
>  av_free(sps);
>  av_free(pps);
> +av_free(sps_ext);
>  av_free(start);
>
>  return ret;
> @@ -351,7 +379,7 @@ H264SequenceParameterSet *ff_avc_decode_sps(const uint8_t 
> *buf, int buf_size)
>  skip_bits1(); // separate_colour_plane_flag
>  }
>  sps->bit_depth_luma = get_ue_golomb() + 8;
> -get_ue_golomb(); // bit_depth_chroma_minus8
> +sps->bit_depth_chroma = get_ue_golomb() + 8;
>  skip_bits1(); // qpprime_y_zero_transform_bypass_flag
>  if (get_bits1()) { // seq_scaling_matrix_present_flag
>  for (i = 0; i < ((sps->chroma_format_idc != 3) ? 8 : 12); i++) {
> diff --git a/libavformat/avc.h b/libavformat/avc.h
> index a79bf9b2db..5286d19d89 100644
> --- a/libavformat/avc.h
> +++ b/libavformat/avc.h
> @@ -43,6 +43,7 @@ typedef struct {
>  uint8_t constraint_set_flags;
>  uint8_t chroma_format_idc;
>  uint8_t bit_depth_luma;
> +uint8_t bit_depth_chroma;
>  uint8_t frame_mbs_only_flag;
>  AVRational sar;
>  } H264SequenceParameterSet;

Sorry if this is obvious:
What does this patch fix?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/26/19, Carl Eugen Hoyos  wrote:
> Am Di., 26. Nov. 2019 um 10:53 Uhr schrieb Paul B Mahol :
>>
>> On 11/25/19, Tomas Härdin  wrote:
>> > mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
>> >> Signed-off-by: Paul B Mahol 
>> >> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx,
>> >> AVFrame
>> >> *frame)
>> >> +{
>> >> +GetByteContext *gb = >gb;
>> >> +GetBitContext mask;
>> >> +GetByteContext idx9;
>> >> +uint16_t nb_vectors, intra_flag;
>> >> +const uint8_t *vec;
>> >> +const uint8_t *mask_start;
>> >> +uint8_t *skip;
>> >> +int mask_size;
>> >> +int idx9bits = 0;
>> >> +int idx9val = 0;
>> >> +int num_blocks;
>> >> +
>> >> +nb_vectors = bytestream2_get_le16(gb);
>> >> +intra_flag = bytestream2_get_le16(gb);
>> >> +if (intra_flag) {
>> >> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>> >
>> > Will UB if width*height/4 > INT_MAX
>> >
>> >> +} else {
>> >> +int skip_linesize;
>> >> +
>> >> +num_blocks = bytestream2_get_le32(gb);
>> >
>> > Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
>> >
>> >> +skip_linesize = avctx->width >> 1;
>> >> +mask_start = gb->buffer_start + bytestream2_tell(gb);
>> >> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>> >
>> > This can also UB
>
>> Nothing of this can actually happen.
>
> Then you could add asserts (and cut your quotes).

Asserts for checking UBs? Non sense.

>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Carl Eugen Hoyos
Am Di., 26. Nov. 2019 um 10:53 Uhr schrieb Paul B Mahol :
>
> On 11/25/19, Tomas Härdin  wrote:
> > mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
> >> Signed-off-by: Paul B Mahol 
> >> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame
> >> *frame)
> >> +{
> >> +GetByteContext *gb = >gb;
> >> +GetBitContext mask;
> >> +GetByteContext idx9;
> >> +uint16_t nb_vectors, intra_flag;
> >> +const uint8_t *vec;
> >> +const uint8_t *mask_start;
> >> +uint8_t *skip;
> >> +int mask_size;
> >> +int idx9bits = 0;
> >> +int idx9val = 0;
> >> +int num_blocks;
> >> +
> >> +nb_vectors = bytestream2_get_le16(gb);
> >> +intra_flag = bytestream2_get_le16(gb);
> >> +if (intra_flag) {
> >> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
> >
> > Will UB if width*height/4 > INT_MAX
> >
> >> +} else {
> >> +int skip_linesize;
> >> +
> >> +num_blocks = bytestream2_get_le32(gb);
> >
> > Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
> >
> >> +skip_linesize = avctx->width >> 1;
> >> +mask_start = gb->buffer_start + bytestream2_tell(gb);
> >> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
> >
> > This can also UB

> Nothing of this can actually happen.

Then you could add asserts (and cut your quotes).

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/utils.c: allows av_read_frame to return after a timeout period.

2019-11-26 Thread Michael Niedermayer
On Thu, Nov 21, 2019 at 06:27:10PM -0300, ggarr...@gmail.com wrote:
> From: Gonzalo Garramuño 
> 
> This patch is based on a patch by bsenftner at earthlink.net.
> ---
>  libavformat/utils.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 8196442dd1..c3c2c77c0c 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -1838,6 +1838,11 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
>  }
>  }
>  
> +if (ff_check_interrupt(>interrupt_callback)) {
> +av_log(s, AV_LOG_DEBUG, "interrupted\n");
> +return AVERROR_EXIT;
> +}
> +

I think this can be moved into the if() above, which might
reduce the number of calls.

thx
[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you drop bombs on a foreign country and kill a hundred thousand
innocent people, expect your government to call the consequence
"unprovoked inhuman terrorist attacks" and use it to justify dropping
more bombs and killing more people. The technology changed, the idea is old.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] Allow using primary CUDA device context

2019-11-26 Thread Timo Rothenpieler

applied with some changes regarding flags and device flags
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Hendrik Leppkes
On Tue, Nov 26, 2019 at 12:27 PM Steven Liu  wrote:
>
> Signed-off-by: Steven Liu 
> ---
>  doc/APIchanges  |  3 +++
>  libavformat/avio.h  |  8 
>  libavformat/protocols.c | 10 ++
>  libavformat/version.h   |  2 +-
>  4 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 401c65a753..39896146d3 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>
>  API changes, most recent first:
>
> +2019-11-26 - xx - lavf 58.26.100 - avio.h
> +  Add av_urlcontext_get_class_by_name().
> +
>  2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
>Add av_expr_count_vars().
>
> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index 9141642e75..bf8cf120f2 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -807,6 +807,14 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t 
> **pbuffer);
>   */
>  const char *avio_enum_protocols(void **opaque, int output);
>
> +/**
> + * Get AVClass by names of available protocols.
> + *
> + * @param name protocol name
> + * @return A AVClass of input protocol name or NULL
> + */
> +const AVClass *av_urlcontext_get_class_by_name(const char *name);
> +

The function should probably follow naming similar to the other
functions in that file,  use avio_protocol as a prefix, not
urlcontext, so eg. avio_protocol_get_class_by_name (or perhaps even
drop the by_name part)

- Hendrik
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Nicolas George
Liu Steven (12019-11-26):
>   What should i do next step? remove the comment of the parameter? or 
> just looks good?

My opinion is to remove the comment because it brings nothing.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Liu Steven


> 在 2019年11月26日,下午8:35,Nicolas George  写道:
> 
> Andriy Gelman (12019-11-26):
>>> + * @param name protocol name
>> extra name   ^
> 
> No, it is the normal pattern, to mean "the variable 'name' is the name
> of the protocol".
> 
> But it is indeed a completely useless precision, much like the infamous
> "to print, use the print menu”.
Hi Nicolas,
What should i do next step? remove the comment of the parameter? or 
just looks good?
> 
> Regards,
> 
> -- 
>  Nicolas George

Thanks
Steven

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avformat/avc: write the missing bits in the AVC Decoder Configuration Box

2019-11-26 Thread Andreas Rheinhardt
On Tue, Nov 26, 2019 at 2:07 PM James Almer  wrote:

> Signed-off-by: James Almer 
> ---
>  libavformat/avc.c | 38 +-
>  libavformat/avc.h |  1 +
>  2 files changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/avc.c b/libavformat/avc.c
> index a041e84357..9bd215c07f 100644
> --- a/libavformat/avc.c
> +++ b/libavformat/avc.c
> @@ -107,11 +107,11 @@ int ff_avc_parse_nal_units_buf(const uint8_t
> *buf_in, uint8_t **buf, int *size)
>
>  int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
>  {
> -AVIOContext *sps_pb = NULL, *pps_pb = NULL;
> +AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
>  uint8_t *buf = NULL, *end, *start = NULL;
> -uint8_t *sps = NULL, *pps = NULL;
> -uint32_t sps_size = 0, pps_size = 0;
> -int ret, nb_sps = 0, nb_pps = 0;
> +uint8_t *sps = NULL, *pps = NULL, *sps_ext = NULL;
> +uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
> +int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
>
>  if (len <= 6)
>  return AVERROR_INVALIDDATA;
> @@ -133,6 +133,9 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t
> *data, int len)
>  if (ret < 0)
>  goto fail;
>  ret = avio_open_dyn_buf(_pb);
> +if (ret < 0)
> +goto fail;
> +ret = avio_open_dyn_buf(_ext_pb);
>  if (ret < 0)
>  goto fail;
>
> @@ -160,12 +163,21 @@ int ff_isom_write_avcc(AVIOContext *pb, const
> uint8_t *data, int len)
>  }
>  avio_wb16(pps_pb, size);
>  avio_write(pps_pb, buf, size);
> +} else if (nal_type == 13) { /* SPS_EXT */
> +nb_sps_ext++;
> +if (size > UINT16_MAX || nb_sps_ext >= 256) {
> +ret = AVERROR_INVALIDDATA;
> +goto fail;
> +}
> +avio_wb16(sps_ext_pb, size);
> +avio_write(sps_ext_pb, buf, size);
>  }
>
>  buf += size;
>  }
>  sps_size = avio_close_dyn_buf(sps_pb, );
>  pps_size = avio_close_dyn_buf(pps_pb, );
> +sps_ext_size = avio_close_dyn_buf(sps_ext_pb, _ext);
>
>  if (sps_size < 6 || !pps_size) {
>  ret = AVERROR_INVALIDDATA;
> @@ -183,13 +195,29 @@ int ff_isom_write_avcc(AVIOContext *pb, const
> uint8_t *data, int len)
>  avio_w8(pb, nb_pps); /* number of pps */
>  avio_write(pb, pps, pps_size);
>
> +if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
> +H264SequenceParameterSet *seq = ff_avc_decode_sps(sps, sps_size);
> +if (!seq)
> +goto fail;
> +avio_w8(pb, 0xfc | seq->chroma_format_idc); /* 6 bits reserved
> (11) + chroma_format_idc */
> +avio_w8(pb, 0xf8 | seq->bit_depth_luma - 8); /* 5 bits reserved
> (1) + bit_depth_luma_minus8 */
> +avio_w8(pb, 0xf8 | seq->bit_depth_chroma - 8); /* 5 bits reserved
> (1) + bit_depth_chroma_minus8 */
> +avio_w8(pb, nb_sps_ext); /* number of sps ext */
> +if (nb_sps_ext)
> +avio_write(pb, sps_ext, sps_ext_size);
> +av_free(seq);
> +}
> +
>  fail:
>  if (!sps)
>  avio_close_dyn_buf(sps_pb, );
>  if (!pps)
>  avio_close_dyn_buf(pps_pb, );
> +if (!sps_ext)
> +avio_close_dyn_buf(sps_ext_pb, _ext);
>

I don't like how these buffers are freed. How about the following approach:
You don't close the dynamic buffer above; instead you just call
avio_get_dyn_buf(). And here on fail you use ffio_free_dyn_buf()
unconditionally instead of these combinations of avio_close_dyn_buf() and
av_free().

(I have recently looked a bit into the dynamic buffers (mainly because the
Matroska muxer benefits tremendously from setting direct for the dynamic
buffer for the cluster) and there is a potential for improvements from
which the above approach would benefit: One can modify avio_get_dyn_buf()
to return a pointer to the small (1024 B) IO-buffer if nothing has been
written to the big buffer yet; and if one also modifies ffio_free_dyn_buf
to not call avio_close_dyn_buf(), but to free everything directly, an
allocation could be saved if the data one intends to write fits into the
IO-buffer.)

I haven't looked at the rest.

- Andreas

PS: The SPS/PPS ids are supposed to be monotonically increasing, yet
nothing in the above code ensures that. (This is not supposed to block your
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-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/avc: write the missing bits in the AVC Decoder Configuration Box

2019-11-26 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/avc.c | 38 +-
 libavformat/avc.h |  1 +
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/libavformat/avc.c b/libavformat/avc.c
index a041e84357..9bd215c07f 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -107,11 +107,11 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, 
uint8_t **buf, int *size)
 
 int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
 {
-AVIOContext *sps_pb = NULL, *pps_pb = NULL;
+AVIOContext *sps_pb = NULL, *pps_pb = NULL, *sps_ext_pb = NULL;
 uint8_t *buf = NULL, *end, *start = NULL;
-uint8_t *sps = NULL, *pps = NULL;
-uint32_t sps_size = 0, pps_size = 0;
-int ret, nb_sps = 0, nb_pps = 0;
+uint8_t *sps = NULL, *pps = NULL, *sps_ext = NULL;
+uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
+int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
 
 if (len <= 6)
 return AVERROR_INVALIDDATA;
@@ -133,6 +133,9 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
*data, int len)
 if (ret < 0)
 goto fail;
 ret = avio_open_dyn_buf(_pb);
+if (ret < 0)
+goto fail;
+ret = avio_open_dyn_buf(_ext_pb);
 if (ret < 0)
 goto fail;
 
@@ -160,12 +163,21 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
*data, int len)
 }
 avio_wb16(pps_pb, size);
 avio_write(pps_pb, buf, size);
+} else if (nal_type == 13) { /* SPS_EXT */
+nb_sps_ext++;
+if (size > UINT16_MAX || nb_sps_ext >= 256) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+avio_wb16(sps_ext_pb, size);
+avio_write(sps_ext_pb, buf, size);
 }
 
 buf += size;
 }
 sps_size = avio_close_dyn_buf(sps_pb, );
 pps_size = avio_close_dyn_buf(pps_pb, );
+sps_ext_size = avio_close_dyn_buf(sps_ext_pb, _ext);
 
 if (sps_size < 6 || !pps_size) {
 ret = AVERROR_INVALIDDATA;
@@ -183,13 +195,29 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t 
*data, int len)
 avio_w8(pb, nb_pps); /* number of pps */
 avio_write(pb, pps, pps_size);
 
+if (sps[3] != 66 && sps[3] != 77 && sps[3] != 88) {
+H264SequenceParameterSet *seq = ff_avc_decode_sps(sps, sps_size);
+if (!seq)
+goto fail;
+avio_w8(pb, 0xfc | seq->chroma_format_idc); /* 6 bits reserved 
(11) + chroma_format_idc */
+avio_w8(pb, 0xf8 | seq->bit_depth_luma - 8); /* 5 bits reserved 
(1) + bit_depth_luma_minus8 */
+avio_w8(pb, 0xf8 | seq->bit_depth_chroma - 8); /* 5 bits reserved 
(1) + bit_depth_chroma_minus8 */
+avio_w8(pb, nb_sps_ext); /* number of sps ext */
+if (nb_sps_ext)
+avio_write(pb, sps_ext, sps_ext_size);
+av_free(seq);
+}
+
 fail:
 if (!sps)
 avio_close_dyn_buf(sps_pb, );
 if (!pps)
 avio_close_dyn_buf(pps_pb, );
+if (!sps_ext)
+avio_close_dyn_buf(sps_ext_pb, _ext);
 av_free(sps);
 av_free(pps);
+av_free(sps_ext);
 av_free(start);
 
 return ret;
@@ -351,7 +379,7 @@ H264SequenceParameterSet *ff_avc_decode_sps(const uint8_t 
*buf, int buf_size)
 skip_bits1(); // separate_colour_plane_flag
 }
 sps->bit_depth_luma = get_ue_golomb() + 8;
-get_ue_golomb(); // bit_depth_chroma_minus8
+sps->bit_depth_chroma = get_ue_golomb() + 8;
 skip_bits1(); // qpprime_y_zero_transform_bypass_flag
 if (get_bits1()) { // seq_scaling_matrix_present_flag
 for (i = 0; i < ((sps->chroma_format_idc != 3) ? 8 : 12); i++) {
diff --git a/libavformat/avc.h b/libavformat/avc.h
index a79bf9b2db..5286d19d89 100644
--- a/libavformat/avc.h
+++ b/libavformat/avc.h
@@ -43,6 +43,7 @@ typedef struct {
 uint8_t constraint_set_flags;
 uint8_t chroma_format_idc;
 uint8_t bit_depth_luma;
+uint8_t bit_depth_chroma;
 uint8_t frame_mbs_only_flag;
 AVRational sar;
 } H264SequenceParameterSet;
-- 
2.24.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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Nicolas George
Andriy Gelman (12019-11-26):
> > + * @param name protocol name
> extra name   ^

No, it is the normal pattern, to mean "the variable 'name' is the name
of the protocol".

But it is indeed a completely useless precision, much like the infamous
"to print, use the print menu".

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Andriy Gelman
On Tue, 26. Nov 19:26, Steven Liu wrote:
> Signed-off-by: Steven Liu 
> ---
>  doc/APIchanges  |  3 +++
>  libavformat/avio.h  |  8 
>  libavformat/protocols.c | 10 ++
>  libavformat/version.h   |  2 +-
>  4 files changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 401c65a753..39896146d3 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>  
>  API changes, most recent first:
>  
> +2019-11-26 - xx - lavf 58.26.100 - avio.h
> +  Add av_urlcontext_get_class_by_name().
> +
>  2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
>Add av_expr_count_vars().
>  
> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index 9141642e75..bf8cf120f2 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -807,6 +807,14 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t 
> **pbuffer);
>   */
>  const char *avio_enum_protocols(void **opaque, int output);
>  
> +/**
> + * Get AVClass by names of available protocols.
> + *

> + * @param name protocol name

extra name   ^

-- 
Andriy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v6 1/3] hevc_mp4toannexb: Insert correct parameter sets before IRAP

2019-11-26 Thread Andriy Gelman
On Tue, 26. Nov 10:52, Michael Niedermayer wrote:
> On Mon, Nov 25, 2019 at 09:35:04PM -0500, Andriy Gelman wrote:
> > On Mon, 25. Nov 01:50, Michael Niedermayer wrote:
> > > On Sun, Nov 24, 2019 at 11:29:18AM -0500, Andriy Gelman wrote:
> > > > On Sun, 24. Nov 00:02, Michael Niedermayer wrote:
> > > > > On Tue, Oct 15, 2019 at 10:50:39PM -0400, Andriy Gelman wrote:
> > > > > > From: Andriy Gelman 
> > > > > > 
> > > > > > Fixes #7799
> > > > > > 
> > > > > > Currently, the mp4toannexb filter always inserts the same extradata 
> > > > > > at
> > > > > > the start of the first IRAP unit. As in ticket #7799, this can lead 
> > > > > > to
> > > > > > decoding errors if modified parameter sets are signalled in-band.
> > > > > > 
> > > > > > Decoding errors/visual artifacts are also present in the following 
> > > > > > fate-suite/hevc-conformance datasets for hevc->mp4->hevc conversion:
> > > > > >  -RAP_B_Bossen_1.bit
> > > > > >  -RPS_C_ericsson_5.bit
> > > > > >  -SLIST_A_Sony_4.bit
> > > > > >  -SLIST_B_Sony_8.bit
> > > > > >  -SLIST_C_Sony_3.bit
> > > > > >  -SLIST_D_Sony_9.bit
> > > > > >  -TSKIP_A_MS_2.bit
> > > > > > 
> > > > > > This commit solves these errors by keeping track of VPS/SPS/PPS 
> > > > > > parameter sets
> > > > > > during the conversion. The correct combination is inserted at the 
> > > > > > start
> > > > > > of the first IRAP. SEIs from extradata are inserted before each 
> > > > > > IRAP.
> > > > > > 
> > > > > > This commit also makes an update to the hevc-bsf-mp4toannexb fate 
> > > > > > test
> > > > > > since the result before this patch contained duplicate parameter 
> > > > > > sets
> > > > > > in-band.
> > > > > > ---
> > > > > >  libavcodec/hevc_mp4toannexb_bsf.c | 503 
> > > > > > --
> > > > > >  tests/fate/hevc.mak   |   2 +-
> > > > > >  2 files changed, 472 insertions(+), 33 deletions(-)
> > > [...]
> > > > > 
> > > > > [...]
> > > > > > +/*
> > > > > > + * Function converts mp4 access unit into annexb
> > > > > > + * Output packet structure
> > > > > > + * VPS, SPS, PPS, [SEI(from extradata)], [SEI_PREFIX(from access 
> > > > > > unit)], IRAP, [SEI_SUFFIX]
> > > > > > + * or
> > > > > > + * [SEI_PREFIX (from access unit)], [PPS (if not already 
> > > > > > signalled)], VCL(non-irap), [SEI_SUFFIX]
> > > > > > + */
> > > > > >  static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket 
> > > > > > *out)
> > > > > >  {
> > > > > >  HEVCBSFContext *s = ctx->priv_data;
> > > > > >  AVPacket *in;
> > > > > > -GetByteContext gb;
> > > > > > -
> > > > > > -int got_irap = 0;
> > > > > > -int i, ret = 0;
> > > > > > +H2645Packet pkt;
> > > > > > +int i, j, prev_size, ret;
> > > > > > +int irap_done;
> > > > > >  
> > > > > >  ret = ff_bsf_get_packet(ctx, );
> > > > > >  if (ret < 0)
> > > > > >  return ret;
> > > > > >  
> > > > > > +/* output the annexb nalu if extradata is not parsed*/
> > > > > >  if (!s->extradata_parsed) {
> > > > > >  av_packet_move_ref(out, in);
> > > > > >  av_packet_free();
> > > > > >  return 0;
> > > > > >  }
> > > > > >  
> > > > > 
> > > > > > -bytestream2_init(, in->data, in->size);
> > > > > 
> > > > > Is this really better without using an existing bytestream* API ?
> > > > 
> > > > If I use the API, then I'd have to call bytestraem2_init for each nal 
> > > > unit. I
> > > > also don't use the bytestream2_get_byte function. It seemed simpler to 
> > > > use the WRITE_NAL macro.
> > > > 
> > > > But maybe I've misunderstood your question.
> > > 
> > > i had nothing really specific in mind, just the feeling that using none of
> > > the existing APIs there is a bit odd.
> > > 
> > > but more specifically, what about the write side ?
> > 
> > If I use the bytestream* API, then I'd have to add extra boiler plate code 
> > each time I resize the output with av_grow_packet(). I'd have to add 
> > something like: 
> > 
> > prev_size = bytestream2_tell_p(...); 
> > bytestream2_init_writer(...);
> > bytestream2_skip_p(..., prev_size);
> > 
> > Or maybe the API needs an extra function that reinitializes the pointers but
> > keeps the current state of the writer. 
> 
> grow/realloc seems suboptimal to me for any API.
> cant you find out how much space is needed and allocate/grow just once then
> init the bytestream2 on that ?
> 

ok, I'll do it this way.

Thanks,
-- 
Andriy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] avformat/matroskaenc: Check mimetypes earlier

2019-11-26 Thread Andreas Rheinhardt
This avoids errors lateron after the file header has already been
partially written.

Signed-off-by: Andreas Rheinhardt 
---
get_mimetype() doesn't change st, so it can be const. I forgot that in
the first version.

 libavformat/matroskaenc.c | 35 ++-
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 4ca262a706..ecd3dc9f9f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1659,6 +1659,21 @@ static int mkv_write_tags(AVFormatContext *s)
 return 0;
 }
 
+static const char *get_mimetype(const AVStream *st)
+{
+AVDictionaryEntry *t;
+
+if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
+return t->value;
+if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
+const AVCodecDescriptor *desc = 
avcodec_descriptor_get(st->codecpar->codec_id);
+if (desc && desc->mime_types)
+return desc->mime_types[0];
+}
+
+return NULL;
+}
+
 static int mkv_write_attachments(AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
@@ -1678,7 +1693,7 @@ static int mkv_write_attachments(AVFormatContext *s)
 mkv_track *track = >tracks[i];
 ebml_master attached_file;
 AVDictionaryEntry *t;
-const char *mimetype = NULL;
+const char *mimetype;
 const char *filename;
 
 if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT)
@@ -1693,18 +1708,8 @@ static int mkv_write_attachments(AVFormatContext *s)
 } else
 filename = "";
 put_ebml_string(dyn_cp, MATROSKA_ID_FILENAME, filename);
-if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
-mimetype = t->value;
-else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {
-const AVCodecDescriptor *desc = 
avcodec_descriptor_get(st->codecpar->codec_id);
-if (desc && desc->mime_types)
-mimetype = desc->mime_types[0];
-}
-if (!mimetype) {
-av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag 
and "
-"it cannot be deduced from the codec 
id.\n", i);
-return AVERROR(EINVAL);
-}
+mimetype = get_mimetype(st);
+av_assert0(mimetype);
 
 put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
 put_ebml_binary(dyn_cp, MATROSKA_ID_FILEDATA, st->codecpar->extradata, 
st->codecpar->extradata_size);
@@ -2638,6 +2643,10 @@ static int mkv_init(struct AVFormatContext *s)
 if (mkv->mode == MODE_WEBM) {
 av_log(s, AV_LOG_WARNING, "Stream %d will be ignored "
"as WebM doesn't support attachments.\n", i);
+} else if (!get_mimetype(st)) {
+av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag 
and "
+"it cannot be deduced from the codec 
id.\n", i);
+return AVERROR(EINVAL);
 }
 continue;
 }
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avformat/matroskaenc: Ignore attachments for track limit

2019-11-26 Thread Andreas Rheinhardt
Attachments are streams in FFmpeg, but they are not tracks in Matroska.
Yet they were counted when checking a limit for the number of tracks that
the Matroska muxer imposes. This is unnecessary and has been changed.

(The Matroska file format actually has practically no limit on the
number of tracks and this is purely what our muxer supports. But even if
this limit were removed/relaxed in the future, it still makes sense to
use small track numbers as this patch does, because greater numbers need
more bytes to encode.)

Signed-off-by: Andreas Rheinhardt 
---
I forgot to update the av_log call in mkv_write_vtt_block.

 libavformat/matroskaenc.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index be98832a13..43ee9c8a92 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -95,6 +95,7 @@ typedef struct mkv_cues {
 typedef struct mkv_track {
 int write_dts;
 int has_cue;
+int track_num;
 uint32_tuid;
 int sample_rate;
 int64_t sample_rate_offset;
@@ -1138,8 +1139,7 @@ static int mkv_write_track(AVFormatContext *s, 
MatroskaMuxContext *mkv,
 }
 
 track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
-put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER,
-   mkv->is_dash ? mkv->dash_track_number : i + 1);
+put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER, mkv->tracks[i].track_num);
 put_ebml_uint (pb, MATROSKA_ID_TRACKUID, mkv->tracks[i].uid);
 put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0);// no lacing (yet)
 
@@ -1989,7 +1989,7 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
 uint64_t additional_id = 0;
 int64_t discard_padding = 0;
-uint8_t track_number = (mkv->is_dash ? mkv->dash_track_number : 
(pkt->stream_index + 1));
+int track_number = track->track_num;
 ebml_master block_group, block_additions, block_more;
 
 ts += track->ts_offset;
@@ -2088,6 +2088,7 @@ static void mkv_write_block(AVFormatContext *s, 
AVIOContext *pb,
 static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket 
*pkt)
 {
 MatroskaMuxContext *mkv = s->priv_data;
+mkv_track *track = >tracks[pkt->stream_index];
 ebml_master blockgroup;
 int id_size, settings_size, size;
 uint8_t *id, *settings;
@@ -2111,13 +2112,13 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, 
AVIOContext *pb, AVPacket *p
"duration %" PRId64 " at relative offset %" PRId64 " in cluster "
"at offset %" PRId64 ". TrackNumber %d, keyframe %d\n",
size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
-   mkv->cluster_pos, pkt->stream_index + 1, 1);
+   mkv->cluster_pos, track->track_num, 1);
 
 blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 
mkv_blockgroup_size(size));
 
 put_ebml_id(pb, MATROSKA_ID_BLOCK);
 put_ebml_num(pb, size + 4, 0);
-avio_w8(pb, 0x80 | (pkt->stream_index + 1)); // this assumes 
stream_index is less than 126
+avio_w8(pb, 0x80 | track->track_num); // this assumes track_num is 
less than 126
 avio_wb16(pb, ts - mkv->cluster_pts);
 avio_w8(pb, flags);
 avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, 
pkt->size, pkt->data);
@@ -2256,7 +2257,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, 
AVPacket *pkt, int add_
 int ret;
 int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
 int64_t relative_packet_pos;
-int tracknum = mkv->is_dash ? mkv->dash_track_number : pkt->stream_index + 
1;
+int tracknum = track->track_num;
 
 if (ts == AV_NOPTS_VALUE) {
 av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
@@ -2592,14 +2593,7 @@ static int mkv_init(struct AVFormatContext *s)
 {
 MatroskaMuxContext *mkv = s->priv_data;
 AVLFG c;
-int i;
-
-if (s->nb_streams > MAX_TRACKS) {
-av_log(s, AV_LOG_ERROR,
-   "At most %d streams are supported for muxing in Matroska\n",
-   MAX_TRACKS);
-return AVERROR(EINVAL);
-}
+int i, nb_tracks = 0;
 
 for (i = 0; i < s->nb_streams; i++) {
 if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 ||
@@ -2634,6 +2628,7 @@ static int mkv_init(struct AVFormatContext *s)
 }
 
 for (i = 0; i < s->nb_streams; i++) {
+AVStream *st = s->streams[i];
 mkv_track *track = >tracks[i];
 
 if (s->flags & AVFMT_FLAG_BITEXACT) {
@@ -2644,6 +2639,19 @@ static int mkv_init(struct AVFormatContext *s)
 
 // ms precision is the de-facto standard timescale for mkv files
 avpriv_set_pts_info(s->streams[i], 64, 1, 1000);
+
+if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT)
+continue;
+
+nb_tracks++;
+

[FFmpeg-devel] [PATCH 2/2] cmdutils: add show_help_protocol for get protocol options

2019-11-26 Thread Steven Liu
Signed-off-by: Steven Liu 
---
 fftools/cmdutils.c   | 18 ++
 fftools/ffmpeg_opt.c |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 84f98b7c04..e0516296d5 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1870,6 +1870,22 @@ static void show_help_demuxer(const char *name)
 show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
 }
 
+static void show_help_protocol(const char *name)
+{
+const AVClass *proto_class = av_urlcontext_get_class_by_name(name);
+
+printf("Protocol [%s]:\n"
+   " D. = Input supported\n"
+   " .E = Output supported\n"
+   " --\n", name);
+if (!proto_class) {
+av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
+return;
+}
+
+show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM);
+}
+
 static void show_help_muxer(const char *name)
 {
 const AVCodecDescriptor *desc;
@@ -2000,6 +2016,8 @@ int show_help(void *optctx, const char *opt, const char 
*arg)
 show_help_demuxer(par);
 } else if (!strcmp(topic, "muxer")) {
 show_help_muxer(par);
+} else if (!strcmp(topic, "protocol")) {
+show_help_protocol(par);
 #if CONFIG_AVFILTER
 } else if (!strcmp(topic, "filter")) {
 show_help_filter(par);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 71063cc443..8d73fa8a78 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3194,7 +3194,7 @@ void show_help_default(const char *opt, const char *arg)
"-h  -- print basic options\n"
"-h long -- print more options\n"
"-h full -- print all options (including all format and codec 
specific options, very long)\n"
-   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf\n"
+   "-h type=name -- print all options for the named 
decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
"See man %s for detailed description of the options.\n"
"\n", program_name);
 
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH 1/2] avformat/avio: add av_urlcontext_get_class_by_name

2019-11-26 Thread Steven Liu
Signed-off-by: Steven Liu 
---
 doc/APIchanges  |  3 +++
 libavformat/avio.h  |  8 
 libavformat/protocols.c | 10 ++
 libavformat/version.h   |  2 +-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 401c65a753..39896146d3 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2019-11-26 - xx - lavf 58.26.100 - avio.h
+  Add av_urlcontext_get_class_by_name().
+
 2019-11-17 - 1c23abc88f - lavu 56.36.100 - eval API
   Add av_expr_count_vars().
 
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 9141642e75..bf8cf120f2 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -807,6 +807,14 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
  */
 const char *avio_enum_protocols(void **opaque, int output);
 
+/**
+ * Get AVClass by names of available protocols.
+ *
+ * @param name protocol name
+ * @return A AVClass of input protocol name or NULL
+ */
+const AVClass *av_urlcontext_get_class_by_name(const char *name);
+
 /**
  * Pause and resume playing - only meaningful if using a network streaming
  * protocol (e.g. MMS).
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index face5b29b5..512cdd6d2e 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -107,6 +107,16 @@ const char *avio_enum_protocols(void **opaque, int output)
 return avio_enum_protocols(opaque, output);
 }
 
+const AVClass *av_urlcontext_get_class_by_name(const char *name)
+{
+int i = 0;
+for (i = 0; url_protocols[i]; i++) {
+if (!strcmp(url_protocols[i]->name, name))
+return url_protocols[i]->priv_data_class;
+}
+return NULL;
+}
+
 const URLProtocol **ffurl_get_protocols(const char *whitelist,
 const char *blacklist)
 {
diff --git a/libavformat/version.h b/libavformat/version.h
index bac54aed9d..f72fb9478a 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  35
+#define LIBAVFORMAT_VERSION_MINOR  36
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.15.1



___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder

2019-11-26 Thread Paul B Mahol
On 11/25/19, Tomas Härdin  wrote:
> mån 2019-11-25 klockan 22:09 +0100 skrev Paul B Mahol:
>> Signed-off-by: Paul B Mahol 
>> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame
>> *frame)
>> +{
>> +GetByteContext *gb = >gb;
>> +GetBitContext mask;
>> +GetByteContext idx9;
>> +uint16_t nb_vectors, intra_flag;
>> +const uint8_t *vec;
>> +const uint8_t *mask_start;
>> +uint8_t *skip;
>> +int mask_size;
>> +int idx9bits = 0;
>> +int idx9val = 0;
>> +int num_blocks;
>> +
>> +nb_vectors = bytestream2_get_le16(gb);
>> +intra_flag = bytestream2_get_le16(gb);
>> +if (intra_flag) {
>> +num_blocks = (avctx->width / 2) * (avctx->height / 2);
>
> Will UB if width*height/4 > INT_MAX
>
>> +} else {
>> +int skip_linesize;
>> +
>> +num_blocks = bytestream2_get_le32(gb);
>
> Might want to use uint32_t so this doesn't lead to weirdness on 32-bit
>
>> +skip_linesize = avctx->width >> 1;
>> +mask_start = gb->buffer_start + bytestream2_tell(gb);
>> +mask_size = (avctx->width >> 5) * (avctx->height >> 2);
>
> This can also UB
>
> /Tomas
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Nothing of this can actually happen.

Applied.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v6 1/3] hevc_mp4toannexb: Insert correct parameter sets before IRAP

2019-11-26 Thread Michael Niedermayer
On Mon, Nov 25, 2019 at 09:35:04PM -0500, Andriy Gelman wrote:
> On Mon, 25. Nov 01:50, Michael Niedermayer wrote:
> > On Sun, Nov 24, 2019 at 11:29:18AM -0500, Andriy Gelman wrote:
> > > On Sun, 24. Nov 00:02, Michael Niedermayer wrote:
> > > > On Tue, Oct 15, 2019 at 10:50:39PM -0400, Andriy Gelman wrote:
> > > > > From: Andriy Gelman 
> > > > > 
> > > > > Fixes #7799
> > > > > 
> > > > > Currently, the mp4toannexb filter always inserts the same extradata at
> > > > > the start of the first IRAP unit. As in ticket #7799, this can lead to
> > > > > decoding errors if modified parameter sets are signalled in-band.
> > > > > 
> > > > > Decoding errors/visual artifacts are also present in the following 
> > > > > fate-suite/hevc-conformance datasets for hevc->mp4->hevc conversion:
> > > > >  -RAP_B_Bossen_1.bit
> > > > >  -RPS_C_ericsson_5.bit
> > > > >  -SLIST_A_Sony_4.bit
> > > > >  -SLIST_B_Sony_8.bit
> > > > >  -SLIST_C_Sony_3.bit
> > > > >  -SLIST_D_Sony_9.bit
> > > > >  -TSKIP_A_MS_2.bit
> > > > > 
> > > > > This commit solves these errors by keeping track of VPS/SPS/PPS 
> > > > > parameter sets
> > > > > during the conversion. The correct combination is inserted at the 
> > > > > start
> > > > > of the first IRAP. SEIs from extradata are inserted before each IRAP.
> > > > > 
> > > > > This commit also makes an update to the hevc-bsf-mp4toannexb fate test
> > > > > since the result before this patch contained duplicate parameter sets
> > > > > in-band.
> > > > > ---
> > > > >  libavcodec/hevc_mp4toannexb_bsf.c | 503 
> > > > > --
> > > > >  tests/fate/hevc.mak   |   2 +-
> > > > >  2 files changed, 472 insertions(+), 33 deletions(-)
> > [...]
> > > > 
> > > > [...]
> > > > > +/*
> > > > > + * Function converts mp4 access unit into annexb
> > > > > + * Output packet structure
> > > > > + * VPS, SPS, PPS, [SEI(from extradata)], [SEI_PREFIX(from access 
> > > > > unit)], IRAP, [SEI_SUFFIX]
> > > > > + * or
> > > > > + * [SEI_PREFIX (from access unit)], [PPS (if not already 
> > > > > signalled)], VCL(non-irap), [SEI_SUFFIX]
> > > > > + */
> > > > >  static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
> > > > >  {
> > > > >  HEVCBSFContext *s = ctx->priv_data;
> > > > >  AVPacket *in;
> > > > > -GetByteContext gb;
> > > > > -
> > > > > -int got_irap = 0;
> > > > > -int i, ret = 0;
> > > > > +H2645Packet pkt;
> > > > > +int i, j, prev_size, ret;
> > > > > +int irap_done;
> > > > >  
> > > > >  ret = ff_bsf_get_packet(ctx, );
> > > > >  if (ret < 0)
> > > > >  return ret;
> > > > >  
> > > > > +/* output the annexb nalu if extradata is not parsed*/
> > > > >  if (!s->extradata_parsed) {
> > > > >  av_packet_move_ref(out, in);
> > > > >  av_packet_free();
> > > > >  return 0;
> > > > >  }
> > > > >  
> > > > 
> > > > > -bytestream2_init(, in->data, in->size);
> > > > 
> > > > Is this really better without using an existing bytestream* API ?
> > > 
> > > If I use the API, then I'd have to call bytestraem2_init for each nal 
> > > unit. I
> > > also don't use the bytestream2_get_byte function. It seemed simpler to 
> > > use the WRITE_NAL macro.
> > > 
> > > But maybe I've misunderstood your question.
> > 
> > i had nothing really specific in mind, just the feeling that using none of
> > the existing APIs there is a bit odd.
> > 
> > but more specifically, what about the write side ?
> 
> If I use the bytestream* API, then I'd have to add extra boiler plate code 
> each time I resize the output with av_grow_packet(). I'd have to add 
> something like: 
> 
> prev_size = bytestream2_tell_p(...); 
> bytestream2_init_writer(...);
> bytestream2_skip_p(..., prev_size);
> 
> Or maybe the API needs an extra function that reinitializes the pointers but
> keeps the current state of the writer. 

grow/realloc seems suboptimal to me for any API.
cant you find out how much space is needed and allocate/grow just once then
init the bytestream2 on that ?

thx


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] ffmpeg attached picture

2019-11-26 Thread Владислав Гаврилов
Hi,

 

I try to insert image picture to m4b as cover of the file.

I can read picture like this:

 

QPixmap pixmap;

if ( avformat_find_stream_info( fmt_ctx, nullptr ) >= 0 ) {

for ( int i = 0; i < fmt_ctx->nb_streams; ++i ) {

AVStream *stream = fmt_ctx->streams[ i ];

if ( stream->disposition & AV_DISPOSITION_ATTACHED_PIC ) {

AVPacket pkt = stream->attached_pic;

 pixmap = QPixmap::fromImage( QImage::fromData( ( uchar* )pkt.data, pkt.size
) );

break;

}

}

 

}

I change my pixmap for example.

But I can't find information how I can insert new picture in a new
AVFormatContext:

 

 

Best regards,

 

Vladislav Gavrilov

 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".