[MPlayer-dev-eng] [PATCH] split filter_n_bytes function a bit
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Nov 3 15:16:08 CET 2007
Hello,
I for some reason didn't like that it does two mostly unrelated things:
decoding to fill the in buffer with data and passing it through the
filter chain.
Attached patch patch would split it. Objections?
Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/dec_audio.c
===================================================================
--- libmpcodecs/dec_audio.c (revision 24951)
+++ libmpcodecs/dec_audio.c (working copy)
@@ -359,30 +359,34 @@
return 1;
}
-static int filter_n_bytes(sh_audio_t *sh, int len)
+/**
+ * \brief fill sh->a_buffer so it contains \param req_len bytes if possible
+ * \param req_len requested number of bytes to be buffered
+ * \return number of bytes that could be filled in buffer or req_len,
+ * whichever is lower
+ */
+static int fill_in_buffer(sh_audio_t *sh, int req_len)
{
- assert(len-1 + sh->audio_out_minsize <= sh->a_buffer_size);
-
- int error = 0;
-
- // Decode more bytes if needed
- while (sh->a_buffer_len < len) {
+ assert(req_len-1 + sh->audio_out_minsize <= sh->a_buffer_size);
+ while (sh->a_buffer_len < req_len) {
unsigned char *buf = sh->a_buffer + sh->a_buffer_len;
- int minlen = len - sh->a_buffer_len;
+ int minlen = req_len - sh->a_buffer_len;
int maxlen = sh->a_buffer_size - sh->a_buffer_len;
int ret = sh->ad_driver->decode_audio(sh, buf, minlen, maxlen);
- if (ret <= 0) {
- error = -1;
- len = sh->a_buffer_len;
- break;
- }
+ if (ret <= 0)
+ return sh->a_buffer_len;
sh->a_buffer_len += ret;
}
+ return req_len;
+}
+static int filter_n_bytes(sh_audio_t *sh, int len)
+{
+ int filled_len = fill_in_buffer(sh, len);
// Filter
af_data_t filter_input = {
.audio = sh->a_buffer,
- .len = len,
+ .len = filled_len,
.rate = sh->samplerate,
.nch = sh->channels,
.format = sh->sample_format
@@ -403,10 +407,10 @@
sh->a_out_buffer_len += filter_output->len;
// remove processed data from decoder buffer:
- sh->a_buffer_len -= len;
- memmove(sh->a_buffer, sh->a_buffer + len, sh->a_buffer_len);
+ sh->a_buffer_len -= filled_len;
+ memmove(sh->a_buffer, sh->a_buffer + filled_len, sh->a_buffer_len);
- return error;
+ return filled_len < len ? -1 : 0;
}
/* Try to get at least minlen decoded+filtered bytes in sh_audio->a_out_buffer
More information about the MPlayer-dev-eng
mailing list