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 777211 - omxaacenc: Fix samples per buffer calculation
omxaacenc: Fix samples per buffer calculation
Status: RESOLVED INVALID
Product: GStreamer
Classification: Platform
Component: gst-omx
1.10.2
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-01-13 09:53 UTC by Vincent Penquerc'h
Modified: 2017-03-10 13:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix samples per buffer calculation (785 bytes, patch)
2017-01-13 09:54 UTC, Vincent Penquerc'h
none Details | Review
omxaacenc: Fix samples per buffer calculation (1.75 KB, patch)
2017-01-13 14:58 UTC, Vincent Penquerc'h
rejected Details | Review

Description Vincent Penquerc'h 2017-01-13 09:53:38 UTC
Fix samples per buffer calculation
Comment 1 Vincent Penquerc'h 2017-01-13 09:54:58 UTC
Created attachment 343421 [details] [review]
Fix samples per buffer calculation
Comment 2 Sebastian Dröge (slomo) 2017-01-13 10:30:35 UTC
Review of attachment 343421 [details] [review]:

::: omx/gstomxaacenc.c
@@ -505,3 @@
 {
-  /* FIXME: Depends on the profile at least */
-  return 1024;

This should return the number of samples per encoded audio frame, no? If it was about the raw data, then the base class can as well calculate it by itself.
Comment 3 Tim-Philipp Müller 2017-01-13 11:08:27 UTC
Also, could you please elaborate on what this fixes exactly in what situation etc? :)
Comment 4 Vincent Penquerc'h 2017-01-13 11:42:47 UTC
OK, I see I confused in/out buffers.

Before this patch, I was getting an assert in the base class about wrong number of samples passed, and I found this placeholder. I guess the patch fixed the assert by chance. I have to build/reflash another setup before I can reproduce and give the exact assert I had, then work out how to actually fix that.
Comment 5 Vincent Penquerc'h 2017-01-13 14:58:22 UTC
I can't reproduce, but I also can't recall what test I was running, as the bash history gets wiped with every flash and the terminal scrollback's gone.

Anyway, the error I was getting is:

    GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
        ("received more encoded samples %d than provided %d as inputs",
            samples, priv->offset / ctx->info.bpf), (NULL));

from gst-libs/gst/audio/gstaudioencoder.c

I have changed the patch to the sample numbers mentioned in https://wiki.multimedia.cx/index.php?title=Understanding_AAC now.
Comment 6 Vincent Penquerc'h 2017-01-13 14:58:49 UTC
Created attachment 343436 [details] [review]
omxaacenc: Fix samples per buffer calculation
Comment 7 Tim-Philipp Müller 2017-01-13 15:17:44 UTC
Comment on attachment 343436 [details] [review]
omxaacenc: Fix samples per buffer calculation

>@@ -393,6 +393,8 @@ gst_omx_aac_enc_get_caps (GstOMXAudioEnc * enc, GstOMXPort * port,
>   gint mpegversion = 4;
>   const gchar *stream_format = NULL, *profile = NULL;
> 
>+  ((GstOMXAACEnc *)enc)->samples_per_frame = 1024;

>@@ -493,6 +495,8 @@ gst_omx_aac_enc_get_caps (GstOMXAudioEnc * enc, GstOMXPort * port,
>     GST_DEBUG_OBJECT (enc, "setting new codec_data");
>     gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_data, NULL);
> 
>+    ((GstOMXAACEnc *)enc)->samples_per_frame = map.data[1] & 4 ? 960 : 1024;
>+

Please add a local variable for this instead of doing the cast inline, twice :)


>+    ((GstOMXAACEnc *)enc)->samples_per_frame = map.data[1] & 4 ? 960 : 1024;

I think this assumes that no 'unusual' sample rate is used (otherwise there's an extra 24 bit or so for the sample rate). I don't see a restriction on input sample rates in the caps anywhere, but only had a quick look.
Comment 8 Tim-Philipp Müller 2017-01-13 15:21:04 UTC
Might also be worth checking if the encoder actually outputs one AAC frame per output buffer.
Comment 9 Vincent Penquerc'h 2017-01-13 15:28:53 UTC
The extra data is built just the few lines beforehand, so will not have an extra 24 bits (though I think you're right it might just bork if one is passed).

About not-one-frame per buffer... I guess it depends on the hardware encoder :/
Comment 10 Tim-Philipp Müller 2017-01-13 15:43:33 UTC
> The extra data is built just the few lines beforehand, so will not have an
> extra 24 bits (though I think you're right it might just bork if one is
> passed).

Ah yes, I missed that, sorry :) I assumed it came from the encoder.

In that case I'm not sure if the extra code makes sense though - don't we know the flag will always be unset then? Is there anything in the omx aac struct that maps to this?


> About not-one-frame per buffer... I guess it depends on the hardware encoder
> :/

Yeah, I was more suggesting to check this for debugging since I'm not sure if this patch is really what's going to fix your original problem (does it?)
Comment 11 Vincent Penquerc'h 2017-01-13 16:26:53 UTC
Well, given I can't reproduce my problem now...
I can close this bug I suppose :)