baseaudioencoder: Add support for requesting a minimum and maximum number of samples...
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 17 Aug 2011 12:28:44 +0000 (14:28 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 17 Aug 2011 12:28:44 +0000 (14:28 +0200)
This extends the special case of a fixed number of samples per frame
that was supported before already.

omx/gstbaseaudioencoder.c
omx/gstbaseaudioencoder.h

index 8c4f6df..5750da7 100644 (file)
@@ -657,9 +657,11 @@ gst_base_audio_encoder_push_buffers (GstBaseAudioEncoder * enc, gboolean force)
     g_assert (priv->offset <= av);
     av -= priv->offset;
 
-    need = ctx->frame_samples > 0 ? ctx->frame_samples * ctx->state.bpf : av;
-    GST_LOG_OBJECT (enc, "available: %d, needed: %d, force: %d",
-        av, need, force);
+    need =
+        ctx->frame_samples_min >
+        0 ? ctx->frame_samples_min * ctx->state.bpf : av;
+    GST_LOG_OBJECT (enc, "available: %d, needed: %d, force: %d", av, need,
+        force);
 
     if ((need > av) || !av) {
       if (G_UNLIKELY (force)) {
@@ -672,14 +674,19 @@ gst_base_audio_encoder_push_buffers (GstBaseAudioEncoder * enc, gboolean force)
       priv->force = FALSE;
     }
 
-    /* if we have some extra metadata,
-     * provide for integer multiple of frames to allow for better granularity
-     * of processing */
-    if (ctx->frame_samples > 0 && need) {
-      if (ctx->frame_max > 1)
-        need = need * MIN ((av / need), ctx->frame_max);
-      else if (ctx->frame_max == 0)
-        need = need * (av / need);
+    if (ctx->frame_samples_max > 0)
+      need = MIN (av, ctx->frame_samples_max * ctx->state.bpf);
+
+    if (ctx->frame_samples_min == ctx->frame_samples_max) {
+      /* if we have some extra metadata,
+       * provide for integer multiple of frames to allow for better granularity
+       * of processing */
+      if (ctx->frame_samples_min > 0 && need) {
+        if (ctx->frame_max > 1)
+          need = need * MIN ((av / need), ctx->frame_max);
+        else if (ctx->frame_max == 0)
+          need = need * (av / need);
+      }
     }
 
     if (need) {
@@ -964,7 +971,8 @@ gst_base_audio_encoder_sink_setcaps (GstPad * pad, GstCaps * caps)
     gst_base_audio_encoder_drain (enc);
 
     /* context defaults */
-    enc->ctx->frame_samples = 0;
+    enc->ctx->frame_samples_min = 0;
+    enc->ctx->frame_samples_max = 0;
     enc->ctx->frame_max = 0;
     enc->ctx->lookahead = 0;
 
index c459ba2..90e624f 100644 (file)
@@ -95,10 +95,13 @@ typedef struct _GstBaseAudioEncoderContext GstBaseAudioEncoderContext;
 /**
  * GstBaseAudioEncoderContext:
  * @state: a #GstAudioState describing input audio format
- * @frame_samples: number of samples (per channel) subclass needs to be handed,
- *   or will be handed all available if 0.
- * @frame_max: max number of frames of size @frame_bytes accepted at once
- *  (assumed minimally 1)
+ * @frame_samples_min: number of samples (per channel) subclass needs to be handed
+ *   at least, or will be handed all available if 0.
+ * @frame_samples_max: number of samples (per channel) subclass needs to be handed
+ *   at most, or will be handed all available if 0.
+ * @frame_max: max number of frames of size @frame_samples accepted at once
+ *  (assumed minimally 1). Requires @frame_samples_min and @frame_samples_max
+ *  to be the equal.
  * @min_latency: min latency of element
  * @max_latency: max latency of element
  * @lookahead: encoder lookahead (in units of input rate samples)
@@ -110,7 +113,7 @@ struct _GstBaseAudioEncoderContext {
   GstAudioState state;
 
   /* output */
-  gint  frame_samples;
+  gint  frame_samples_min, frame_samples_max;
   gint  frame_max;
   gint  lookahead;
   /* MT-protected (with LOCK) */