OSDN Git Service

android/hal-audio: Send packets only when data were encoded
authorAndrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Mon, 26 May 2014 13:16:33 +0000 (15:16 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sun, 1 Jun 2014 07:17:16 +0000 (10:17 +0300)
Codec may not return encoded packet on every encode_mediapacket call,
i.e. in case there's not enough data it may buffer data and encode on
subsequent calls when enough data were provided. We need to make sure
media packet is written only in case somethind was encoded so we don't
send empty packets.

android/hal-audio.c

index 534620a..9807a5d 100644 (file)
@@ -691,8 +691,12 @@ static bool write_data(struct a2dp_stream_out *out, const void *buffer,
                        }
                }
 
-               /* in resync mode we'll just drop mediapackets */
-               if (!ep->resync) {
+               /* we send data only in case codec encoded some data, i.e. some
+                * codecs do internal buffering and output data only if full
+                * frame can be encoded
+                * in resync mode we'll just drop mediapackets
+                */
+               if (written > 0 && !ep->resync) {
                        /* wait some time for socket to be ready for write,
                         * but we'll just skip writing data if timeout occurs
                         */