Return-Path: Message-ID: <3837d8b10807241238r3284fdb6q60f4c86265146756@mail.gmail.com> Date: Thu, 24 Jul 2008 14:38:47 -0500 From: "keith preston" To: bluez-devel@lists.sourceforge.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_106413_3766246.1216928327061" Subject: [Bluez-devel] [PATCH] a2dp_write patch Reply-To: BlueZ development List-Id: BlueZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: bluez-devel-bounces@lists.sourceforge.net Errors-To: bluez-devel-bounces@lists.sourceforge.net ------=_Part_106413_3766246.1216928327061 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline This is a patch to rewrite a2dp_write to avoid memory copies. It does this by only using the temporary buffer if we are dealing with partial buffers. I see a little bit of a speedup with my embedded device, however sbc encoding usually takes the most time. This also fixes a small bug in pcm_bluetooth.c. Typically in an alsa write call you return the number of samples(frames) that you have processed. However in this case where we don't have a full block to encode in SBC, we return basically return (incoming_buffer_size) % (SBC_Encode_Block_size). This is correct in the case where (incoming_buffer_size) < (SBC_Encode_Block_size), however is wrong when (incoming_buffer_size) > (SBC_Encode_Block_size), because this statement ignores previously processed blocks. Keith Preston ------=_Part_106413_3766246.1216928327061 Content-Type: text/x-patch; name=a2dp_write.patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_fj1robxx0 Content-Disposition: attachment; filename=a2dp_write.patch LS0tIGJsdWV6LXV0aWxzLTMuMzYub3JpZy9hdWRpby9wY21fYmx1ZXRvb3RoLmMJMjAwOC0wNy0y MyAxNzoxMzoxMy4wMDAwMDAwMDAgLTA1MDAKKysrIGJsdWV6LXV0aWxzLTMuMzYvYXVkaW8vcGNt X2JsdWV0b290aC5jCTIwMDgtMDctMjQgMTM6NTA6MzEuMDAwMDAwMDAwIC0wNTAwCkBAIC05NzQs MjEgKzk3NCwyNSBAQAogCXN0cnVjdCBibHVldG9vdGhfZGF0YSAqZGF0YSA9IGlvLT5wcml2Y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8KKwkJaWYgKGEyZHAtPmNvdW50ICsgd3JpdHRlbiA+PSBkYXRhLT5saW5rX210 dSkgeworCQkJYXZkdHBfd3JpdGUoZGF0YSk7CisJCQlwcmludGYoInNlbmRpbmcgcGFja2V0ICVk LCBjb3VudCAlZCwgbGlua19tdHUgJXUiLAorCQkJCQlhMmRwLT5zZXFfbnVtLCBhMmRwLT5jb3Vu dCwKKwkJCQkJZGF0YS0+bGlua19tdHUpOworCQl9CQkKKwl9CisJLyogQ29weSB0aGUgZXh0cmEg dG8gb3VyIHRlbXAgYnVmZmVyIGZvciB0aGUgbmV4dCB3cml0ZSAqLworCWlmKGJ5dGVzX2xlZnQg PiAwKSB7CisJCW1lbWNweShkYXRhLT5idWZmZXIgKyBkYXRhLT5jb3VudCwgYnVmZiwKKwkJCQli eXRlc19sZWZ0KTsKKwkJZGF0YS0+Y291bnQgKz0gYnl0ZXNfbGVmdDsKKwkJYnl0ZXNfbGVmdCA9 IDA7CisJfQogCiBkb25lOgotCURCRygicmV0dXJuaW5nICVsZCIsIHJldCk7Ci0JcmV0dXJuIHJl dDsKKwlEQkcoInJldHVybmluZyAlbGQiLCBzaXplIC0gYnl0ZXNfbGVmdCAvIGZyYW1lX3NpemUp OworCXJldHVybiBzaXplIC0gYnl0ZXNfbGVmdCAvIGZyYW1lX3NpemU7CiB9CiAKIHN0YXRpYyBp bnQgYmx1ZXRvb3RoX3BsYXliYWNrX2RlbGF5KHNuZF9wY21faW9wbHVnX3QgKmlvLAo= ------=_Part_106413_3766246.1216928327061 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ------=_Part_106413_3766246.1216928327061 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-devel ------=_Part_106413_3766246.1216928327061--