[06/12] rtpenc_aac: Use AV_WB16 instead of manual bitshifts

Message ID 1425034865-28812-6-git-send-email-martin@martin.st
State Committed
Commit d16c8d28d4e2fca3af1054ffbf635c8cee755fc8
Headers show

Commit Message

Martin Storsjö Feb. 27, 2015, 11 a.m.
This makes the code slightly more readable and understandable.
---
 libavformat/rtpenc_aac.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Luca Barbato Feb. 28, 2015, 12:28 a.m. | #1
On 27/02/15 12:00, Martin Storsjö wrote:
> This makes the code slightly more readable and understandable.
> ---
>  libavformat/rtpenc_aac.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 

probably using the shift 3 instead of multiply 8 might improve it even more.

lu
Martin Storsjö Feb. 28, 2015, 11:41 a.m. | #2
On Sat, 28 Feb 2015, Luca Barbato wrote:

> On 27/02/15 12:00, Martin Storsjö wrote:
>> This makes the code slightly more readable and understandable.
>> ---
>>  libavformat/rtpenc_aac.c | 14 ++++++--------
>>  1 file changed, 6 insertions(+), 8 deletions(-)
>>
>
> probably using the shift 3 instead of multiply 8 might improve it even more.

Actually, I rather keep it as a multiply by 8 - that way it is IMO a bit 
clearer that this is a number of bits, not that it is some sort of 
bitfield (like the way fixed-bit-length fields are written in some 
packetized headers).

// Martin
Luca Barbato Feb. 28, 2015, 2:19 p.m. | #3
On 28/02/15 12:41, Martin Storsjö wrote:
> Actually, I rather keep it as a multiply by 8 - that way it is IMO a bit
> clearer that this is a number of bits, not that it is some sort of
> bitfield (like the way fixed-bit-length fields are written in some
> packetized headers).

As you prefer.

Patch

diff --git a/libavformat/rtpenc_aac.c b/libavformat/rtpenc_aac.c
index 5c7d168..0a74e27 100644
--- a/libavformat/rtpenc_aac.c
+++ b/libavformat/rtpenc_aac.c
@@ -18,6 +18,8 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
+
 #include "avformat.h"
 #include "rtpenc.h"
 
@@ -45,8 +47,7 @@  void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
             memmove(p + 2, s->buf + 2, au_size);
         }
         /* Write the AU header size */
-        p[0] =  au_size >> 5;
-        p[1] = (au_size & 0x1F) << 3;
+        AV_WB16(p, au_size * 8);
 
         ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
 
@@ -59,8 +60,7 @@  void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
 
     if (size <= max_packet_size) {
         p = s->buf + s->num_frames++ * 2 + 2;
-        *p++ = size >> 5;
-        *p = (size & 0x1F) << 3;
+        AV_WB16(p, size * 8);
         memcpy(s->buf_ptr, buff, size);
         s->buf_ptr += size;
     } else {
@@ -68,12 +68,10 @@  void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
 
         max_packet_size = s->max_payload_size - 4;
         p = s->buf;
-        p[0] = 0;
-        p[1] = 16;
+        AV_WB16(p, 2 * 8);
         while (size > 0) {
             len = FFMIN(size, max_packet_size);
-            p[2] = au_size >> 5;
-            p[3] = (au_size & 0x1F) << 3;
+            AV_WB16(&p[2], au_size * 8);
             memcpy(p + 4, buff, len);
             ff_rtp_send_data(s1, p, len + 4, len == size);
             size -= len;