After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768763 - vorbisenc, opusenc reconfiguration broken
vorbisenc, opusenc reconfiguration broken
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
unspecified
Other All
: Normal blocker
: 1.10.0
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-07-13 09:37 UTC by Arun Raghavan
Modified: 2016-10-31 14:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Revert "vorbisenc: push an updated segment stop time when we know it" (2.09 KB, patch)
2016-07-13 09:37 UTC, Arun Raghavan
committed Details | Review
Test case for vorbisenc renegotiation (1.14 KB, text/x-csrc)
2016-07-13 22:53 UTC, Arun Raghavan
  Details
vorbisenc: strip after eos samples from the end of the buffer (1.42 KB, patch)
2016-09-26 15:52 UTC, Vincent Penquerc'h
none Details | Review
oggmux: take audio clip meta into account (1.50 KB, patch)
2016-09-26 15:52 UTC, Vincent Penquerc'h
none Details | Review
vorbisenc: strip after eos samples from the end of the buffer (1.15 KB, patch)
2016-09-27 07:57 UTC, Vincent Penquerc'h
none Details | Review
oggmux: take audio clip meta into account (1.69 KB, patch)
2016-09-27 07:58 UTC, Vincent Penquerc'h
committed Details | Review
opusenc: remove segment stop modification on eos (2.01 KB, patch)
2016-09-27 08:25 UTC, Vincent Penquerc'h
committed Details | Review
vorbisenc: strip after eos samples from the end of the buffer (7.91 KB, patch)
2016-09-27 09:44 UTC, Vincent Penquerc'h
committed Details | Review
fix codebooks packet identifier (951 bytes, patch)
2016-10-07 11:51 UTC, Vincent Penquerc'h
committed Details | Review

Description Arun Raghavan 2016-07-13 09:37:28 UTC
This reverts commit a16cd5d2a5cbdf084163ead68b59d537d7db99f7:

  "vorbisenc: push an updated segment stop time when we know it"
Comment 1 Arun Raghavan 2016-07-13 09:37:33 UTC
Created attachment 331392 [details] [review]
Revert "vorbisenc: push an updated segment stop time when we know it"

This reverts commit a16cd5d2a5cbdf084163ead68b59d537d7db99f7.

Setting the stop time on the segment breaks reconfiguration, as the
encoder signals an EOS, but we reconfigure it an continue to produce
buffers.

This information  should not be required via the segment downstream
since we already have the sample count being used to generate buffer
durations.
Comment 2 Arun Raghavan 2016-07-13 09:38:19 UTC
cc'ing Vincent to double check.
Comment 3 Tim-Philipp Müller 2016-07-13 18:24:13 UTC
Regression presumably, so marking as blocker.

Do we have a test case for this by any chance Arun?
Comment 4 Arun Raghavan 2016-07-13 22:53:47 UTC
Created attachment 331450 [details]
Test case for vorbisenc renegotiation

Attaching a test case. Run it, and you'll see output from fakesink stop after 2 seconds (when caps change). Works with my patch.
Comment 5 Vincent Penquerc'h 2016-07-14 09:55:00 UTC
Seems OK to rely on buffer durations. If that breaks something, we can always fix it another way. Though ideally, having an end time breaking downstream seems wrong in some way. Does it work with segment seeks ?
Comment 6 Arun Raghavan 2016-07-14 10:15:35 UTC
It breaks because the end time is incorrect w.r.t. to the stream. What's happening is, to a first approximation):

[buffer ts=1 dur=1]
[buffer ts=2 dur=1]
[caps change => new segment stop=2+1=3]
[buffer ts=3 dur=1]
[buffer ts=4 dur=1]

The third buffer onwards are of different caps from the first two. The timestamps, though, continue as normal. But the segment stop is from wherever buffer 2 ends, so subsequent buffers get dropped.
Comment 7 Arun Raghavan 2016-07-21 09:58:39 UTC
I've pushed out the revert now. Leaving this open for a few things:

1. Might be nice to have the test case code as a make check test

2. Not sure what the original commit was trying to do, so there might be some other case we still need to deal with

3. Would be good to have this in the 1.8 branch
Comment 8 Sebastian Dröge (slomo) 2016-07-25 10:24:07 UTC
I think without further changes, this breaks stuff. This is needed for gapless muxing AFAIU, and you will otherwise need to use the new API used by opusenc.
Comment 9 Arun Raghavan 2016-07-25 10:48:38 UTC
Turns out we need to deal with the same thing on opusenc as well (same test, s/vorbis/opus/ shows no buffers after caps change).
Comment 10 Arun Raghavan 2016-09-10 04:10:53 UTC
So what should we do here? I can cook up a patch to not throw out segment stops in opusenc as well, but how do we not break gapless muxing?
Comment 11 Sebastian Dröge (slomo) 2016-09-10 07:54:28 UTC
It does in Ogg, yes. The solution would be to use the new audio clipping meta in both vorbisenc and oggmux for this instead of breaking the segment.
Comment 12 Vincent Penquerc'h 2016-09-26 15:51:27 UTC
The Vorbis case was a bit annoying, as I get a granulepos that corresponds to the end, but there's no otherwise known duration of the "full" buffer to remove from, so I resized the buffer to match the granpos instead.
Comment 13 Vincent Penquerc'h 2016-09-26 15:52:10 UTC
Created attachment 336275 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer
Comment 14 Vincent Penquerc'h 2016-09-26 15:52:38 UTC
Created attachment 336276 [details] [review]
oggmux: take audio clip meta into account
Comment 15 Sebastian Dröge (slomo) 2016-09-27 07:36:54 UTC
Need to change the same for opusenc
Comment 16 Sebastian Dröge (slomo) 2016-09-27 07:38:54 UTC
Comment on attachment 336275 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer

This looks wrong. You should still output the whole *compressed* packet, and not just do some random calculation by using the *uncompressed* size
Comment 17 Sebastian Dröge (slomo) 2016-09-27 07:41:12 UTC
Review of attachment 336276 [details] [review]:

::: ext/ogg/gstoggmux.c
@@ +876,3 @@
+      if (meta->format == GST_FORMAT_DEFAULT) {
+        if (meta->end > duration) {
+          g_assert_not_reached ();

Maybe clip here instead?

@@ +881,3 @@
+        }
+      } else {
+        g_assert_not_reached ();

Maybe without this landmine :) Make it a GST_WARNING and don't clip
Comment 18 Vincent Penquerc'h 2016-09-27 07:57:43 UTC
Created attachment 336316 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer

Oops, way too used to decoders :)
Comment 19 Vincent Penquerc'h 2016-09-27 07:58:10 UTC
Created attachment 336317 [details] [review]
oggmux: take audio clip meta into account
Comment 20 Vincent Penquerc'h 2016-09-27 07:58:41 UTC
(In reply to Sebastian Dröge (slomo) from comment #15)
> Need to change the same for opusenc

opusenc already uses the clip meta.
Comment 21 Sebastian Dröge (slomo) 2016-09-27 08:12:05 UTC
(In reply to Vincent Penquerc'h from comment #20)
> (In reply to Sebastian Dröge (slomo) from comment #15)
> > Need to change the same for opusenc
> 
> opusenc already uses the clip meta.

But it still modifies the segment, which is the main problem here
Comment 22 Sebastian Dröge (slomo) 2016-09-27 08:12:44 UTC
Comment on attachment 336316 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer

Now you only need to actually add the clip meta to the buffer :)
Comment 23 Vincent Penquerc'h 2016-09-27 08:22:09 UTC
(In reply to Sebastian Dröge (slomo) from comment #22)
> Comment on attachment 336316 [details] [review] [review]
> vorbisenc: strip after eos samples from the end of the buffer
> 
> Now you only need to actually add the clip meta to the buffer :)

I don't use a clip meta here, I just use the buffer duration to control the amount to clip. This is because I don't know the actual duration of the whole buffer it's returned, I just know how much there should be (from op.granulepos), so I don't know how much samples to clip.
Comment 24 Sebastian Dröge (slomo) 2016-09-27 08:24:02 UTC
(In reply to Vincent Penquerc'h from comment #23)
> (In reply to Sebastian Dröge (slomo) from comment #22)
> > Comment on attachment 336316 [details] [review] [review] [review]
> > vorbisenc: strip after eos samples from the end of the buffer
> > 
> > Now you only need to actually add the clip meta to the buffer :)
> 
> I don't use a clip meta here, I just use the buffer duration to control the
> amount to clip. This is because I don't know the actual duration of the
> whole buffer it's returned, I just know how much there should be (from
> op.granulepos), so I don't know how much samples to clip.

Why not? You know how many samples there are in this frame (including padding)?

Without adding the clip meta here, this is rather useless.
Comment 25 Vincent Penquerc'h 2016-09-27 08:25:40 UTC
Created attachment 336318 [details] [review]
opusenc: remove segment stop modification on eos
Comment 26 Vincent Penquerc'h 2016-09-27 08:30:03 UTC
(In reply to Sebastian Dröge (slomo) from comment #24)
> Why not? You know how many samples there are in this frame (including
> padding)?

I did not see it, but I will have another look. This is in a loop, where vorbisenc gives us packets, so theoretically it can split however it wants.
 
> Without adding the clip meta here, this is rather useless.

I don't get why. The clip meta will modify the duration by trim_end, so it seems like a similar operation here.
Comment 27 Sebastian Dröge (slomo) 2016-09-27 08:33:43 UTC
(In reply to Vincent Penquerc'h from comment #26)
> (In reply to Sebastian Dröge (slomo) from comment #24)
> > Why not? You know how many samples there are in this frame (including
> > padding)?
> 
> I did not see it, but I will have another look. This is in a loop, where
> vorbisenc gives us packets, so theoretically it can split however it wants.

Vorbis has fixed length packets, and you can look at the packet to know the number of samples.

> > Without adding the clip meta here, this is rather useless.
> 
> I don't get why. The clip meta will modify the duration by trim_end, so it
> seems like a similar operation here.

You mean that oggmux would clip by using the duration instead of the clip meta? The problem then only is that the duration includes rounding errors... and it won't work well for other muxers.
Comment 28 Vincent Penquerc'h 2016-09-27 08:58:55 UTC
(In reply to Sebastian Dröge (slomo) from comment #27)

> Vorbis has fixed length packets, and you can look at the packet to know the
> number of samples.

At the risk of missing something obvious, is there something simpler than gst_parse_vorbis_setup_packet on the codebooks, then packet_duration_vorbis on actual packets ?
Comment 29 Tim-Philipp Müller 2016-09-27 09:10:35 UTC
Sadly not, as far as I know (and for extra fun the info needed is at the very end of the setup data so no shortcuts).
Comment 30 Vincent Penquerc'h 2016-09-27 09:44:43 UTC
Created attachment 336323 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer
Comment 31 Sebastian Dröge (slomo) 2016-09-27 12:20:05 UTC
Review of attachment 336323 [details] [review]:

::: ext/vorbis/gstvorbisenc.c
@@ +982,3 @@
+              "Adding trim-end %" G_GUINT64_FORMAT, trim_end);
+          gst_buffer_add_audio_clipping_meta (buf, GST_FORMAT_DEFAULT, 0,
+              trim_end);

Looks good but is there also trimming at the very beginning needed maybe?
Comment 32 Vincent Penquerc'h 2016-09-27 14:12:18 UTC
I don't understand how this might make sense, since we're looking at the end granule to see if any samples have been skipped.

If you mean that some other part of the code might want to trim samples at th beginning for another reason, then maybe. Can there be just one clipping meta on a buffer ?
Comment 33 Sebastian Dröge (slomo) 2016-09-27 14:13:45 UTC
The very first output packet might have some padding at the beginning that should be clipped. Usually audio codecs do that.
Comment 34 Vincent Penquerc'h 2016-09-30 14:54:27 UTC
It might be, but that does not seem relevant here, since this is about adjusting the end time precisely. Could it have an influence somehow ?
Comment 35 Sebastian Dröge (slomo) 2016-09-30 15:07:33 UTC
Yes, it prevents gapless decoding, which is the whole point of adjusting the duration of the last packet.
Comment 36 Vincent Penquerc'h 2016-09-30 15:34:02 UTC
Ah, right. I think Vorbis allows that too, I'll go check spec probably next week.
Comment 37 Vincent Penquerc'h 2016-10-05 09:24:25 UTC
I *think* that it doesn't need clipping at the beginning, since the encoder will yield a packet that starts with the first raw sample. This is not like the decoder, which needs clipping based on the first granule. I admit I'm not super sure about this.

Also, can there be a clip meta on incoming buffers that every element would have to also honour ? So we'd need to intersect clip start/stop, so the output buffer ends up with the strictest clipping ?
Comment 38 Sebastian Dröge (slomo) 2016-10-05 09:42:28 UTC
(In reply to Vincent Penquerc'h from comment #37)
> I *think* that it doesn't need clipping at the beginning, since the encoder
> will yield a packet that starts with the first raw sample. This is not like
> the decoder, which needs clipping based on the first granule. I admit I'm
> not super sure about this.

That would be surprising. Usually encoders have some kind of "run in" at the beginning, unless this is automatically handled by the decoder in which case we wouldn't have to care. If you decode the first Vorbis frame, does it start with the beginning or does it first have some silence/noise?

> Also, can there be a clip meta on incoming buffers that every element would
> have to also honour ? So we'd need to intersect clip start/stop, so the
> output buffer ends up with the strictest clipping ?

I don't understand your question :)
Comment 39 Vincent Penquerc'h 2016-10-05 09:49:41 UTC
There's some automatic accounting for this (end of 1.3.2 in doc/index.html in libvorbis):

>    Data is not returned from the first frame; it must be used to ’prime’ the decode engine. The encoder
>    accounts for this priming when calculating PCM offsets; after the first frame, the proper PCM output
>    offset is ’0’ (as no data has been returned yet).

I don't think there's anything else to do about this.

As for my question about incoming buffers, it is: if I get a raw PCM buffer of 100 samples, and there is a clip meta on it with start=20 and end=20, those presumably need to be applied to the outgoing buffer as well, right (and, with this patch, the end needs to be set to max(20, X) if X is the result of the calculation in this patch) ?
Comment 40 Sebastian Dröge (slomo) 2016-10-05 09:58:28 UTC
(In reply to Vincent Penquerc'h from comment #39)
> There's some automatic accounting for this (end of 1.3.2 in doc/index.html
> in libvorbis):
> 
> >    Data is not returned from the first frame; it must be used to ’prime’ the decode engine. The encoder
> >    accounts for this priming when calculating PCM offsets; after the first frame, the proper PCM output
> >    offset is ’0’ (as no data has been returned yet).
> 
> I don't think there's anything else to do about this.

So it seems, simpler than Opus then ;)

> As for my question about incoming buffers, it is: if I get a raw PCM buffer
> of 100 samples, and there is a clip meta on it with start=20 and end=20,
> those presumably need to be applied to the outgoing buffer as well, right
> (and, with this patch, the end needs to be set to max(20, X) if X is the
> result of the calculation in this patch) ?

clip meta is only really supposed to be on encoded data, and it is applied/consumed after decoding. It makes no sense on raw PCM buffers, adding a meta is more work than just creating a subbuffer.
Comment 41 Vincent Penquerc'h 2016-10-05 10:01:05 UTC
(In reply to Vincent Penquerc'h from comment #39)
> There's some automatic accounting for this (end of 1.3.2 in doc/index.html
> in libvorbis):

End of 1.3.2 in doc/Vorbis_I_spec.html of course.
Comment 42 Sebastian Dröge (slomo) 2016-10-05 12:38:51 UTC
Comment on attachment 336323 [details] [review]
vorbisenc: strip after eos samples from the end of the buffer

Let's go ahead with this then
Comment 43 Vincent Penquerc'h 2016-10-05 14:00:34 UTC
commit 9599c3416ca907a4201765230aa0786fd8fb861a
Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Date:   Tue Sep 27 09:24:08 2016 +0100

    opusenc: remove segment stop modification on eos
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768763

commit a30c713e43823390889ea847531785a9253ecaaa
Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Date:   Mon Sep 26 16:31:06 2016 +0100

    oggmux: take audio clip meta into account for buffer duration
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768763

commit 1a4ba790446ef0e043bec9cd9d78aa296235d47b
Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Date:   Mon Sep 26 16:25:14 2016 +0100

    vorbisenc: strip after-eos samples from the end of the eos buffer
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768763
Comment 44 Vincent Penquerc'h 2016-10-07 11:51:47 UTC
Created attachment 337160 [details] [review]
fix codebooks packet identifier

"oops"