1 From 228d8808fe6f8aa7390b73d2b248b3a8f092eb9e Mon Sep 17 00:00:00 2001
2 From: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
3 Date: Wed, 7 Mar 2012 12:59:28 +0100
4 Subject: [PATCH 09/20] opusenc: only request and process 1 frame at a time
6 ... since it is specified in _finish_frame that input buffer may be invalidated
7 after calling it, and is as such not reliably available for further encoding.
9 Also, requesting or allowing several frames is only useful if subclass intends
10 to process these "in 1 run" (as in, 1 output buffer), not for having another
11 (inner) loop in subclass where the baseclass one will do just fine.
13 ext/opus/gstopusenc.c | 70 ++++++++++++++++++++++---------------------------
14 1 file changed, 31 insertions(+), 39 deletions(-)
16 diff --git a/ext/opus/gstopusenc.c b/ext/opus/gstopusenc.c
17 index a87e08b..6a19ffd 100644
18 --- a/ext/opus/gstopusenc.c
19 +++ b/ext/opus/gstopusenc.c
20 @@ -384,7 +384,7 @@ gst_opus_enc_setup_base_class (GstOpusEnc * enc, GstAudioEncoder * benc)
21 gst_opus_enc_get_latency (enc), gst_opus_enc_get_latency (enc));
22 gst_audio_encoder_set_frame_samples_min (benc, enc->frame_samples);
23 gst_audio_encoder_set_frame_samples_max (benc, enc->frame_samples);
24 - gst_audio_encoder_set_frame_max (benc, 0);
25 + gst_audio_encoder_set_frame_max (benc, 1);
29 @@ -792,6 +792,8 @@ gst_opus_enc_encode (GstOpusEnc * enc, GstBuffer * buf)
32 gint ret = GST_FLOW_OK;
36 g_mutex_lock (enc->property_lock);
38 @@ -816,51 +818,41 @@ gst_opus_enc_encode (GstOpusEnc * enc, GstBuffer * buf)
42 + g_assert (size == bytes);
47 + ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc),
48 + GST_BUFFER_OFFSET_NONE, enc->max_payload_size * enc->n_channels,
49 + GST_PAD_CAPS (GST_AUDIO_ENCODER_SRC_PAD (enc)), &outbuf);
51 - ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc),
52 - GST_BUFFER_OFFSET_NONE, enc->max_payload_size * enc->n_channels,
53 - GST_PAD_CAPS (GST_AUDIO_ENCODER_SRC_PAD (enc)), &outbuf);
55 - if (GST_FLOW_OK != ret)
58 - GST_DEBUG_OBJECT (enc, "encoding %d samples (%d bytes)",
59 - enc->frame_samples, (int) bytes);
62 - opus_multistream_encode (enc->state, (const gint16 *) data,
63 - enc->frame_samples, GST_BUFFER_DATA (outbuf),
64 - enc->max_payload_size * enc->n_channels);
65 + if (GST_FLOW_OK != ret)
69 - GST_ERROR_OBJECT (enc, "Encoding failed: %d", outsize);
70 - ret = GST_FLOW_ERROR;
72 - } else if (outsize > enc->max_payload_size) {
73 - GST_WARNING_OBJECT (enc,
74 - "Encoded size %d is higher than max payload size (%d bytes)",
75 - outsize, enc->max_payload_size);
76 - ret = GST_FLOW_ERROR;
79 + GST_DEBUG_OBJECT (enc, "encoding %d samples (%d bytes)",
80 + enc->frame_samples, (int) bytes);
82 - GST_DEBUG_OBJECT (enc, "Output packet is %u bytes", outsize);
83 - GST_BUFFER_SIZE (outbuf) = outsize;
85 + opus_multistream_encode (enc->state, (const gint16 *) data,
86 + enc->frame_samples, GST_BUFFER_DATA (outbuf),
87 + enc->max_payload_size * enc->n_channels);
90 - gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (enc), outbuf,
91 - enc->frame_samples);
93 + GST_ERROR_OBJECT (enc, "Encoding failed: %d", outsize);
94 + ret = GST_FLOW_ERROR;
96 + } else if (outsize > enc->max_payload_size) {
97 + GST_WARNING_OBJECT (enc,
98 + "Encoded size %d is higher than max payload size (%d bytes)",
99 + outsize, enc->max_payload_size);
100 + ret = GST_FLOW_ERROR;
104 - if ((GST_FLOW_OK != ret) && (GST_FLOW_NOT_LINKED != ret))
106 + GST_DEBUG_OBJECT (enc, "Output packet is %u bytes", outsize);
107 + GST_BUFFER_SIZE (outbuf) = outsize;
113 + gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (enc), outbuf,
114 + enc->frame_samples);