[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 2 commits: bluetooth: ldac: Fix RTP payloading of encoded packet

PulseAudio Marge Bot (@pulseaudio-merge-bot) gitlab at gitlab.freedesktop.org
Mon Feb 21 17:20:11 UTC 2022



PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio


Commits:
9f0a18b2 by Sanchayan Maity at 2022-02-21T12:15:47+05:30
bluetooth: ldac: Fix RTP payloading of encoded packet

Drop rtpldacpay and payload the LDAC encoded output manually in the
RTP header.

The RTP payload seems to be required as it carries the frame count
information. Right now, rtpldacpay does not add this so construct
the RTP header and payload manually.

Strangely some devices like Shanling MP4 and Sony XM3 would still
work without this while some like the Sony XM4 does not.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/689>

- - - - -
516c691f by Sanchayan Maity at 2022-02-21T12:15:47+05:30
bluetooth: Rename rtp_sbc_payload to rtp_payload

Now that we use RTP payload structure for LDAC as well, rename
rtp_sbc_payload to rtp_payload. PipeWire also uses the same naming.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/689>

- - - - -


3 changed files:

- src/modules/bluetooth/a2dp-codec-ldac-gst.c
- src/modules/bluetooth/a2dp-codec-sbc.c
- src/modules/bluetooth/rtp.h


Changes:

=====================================
src/modules/bluetooth/a2dp-codec-ldac-gst.c
=====================================
@@ -46,13 +46,6 @@ static bool can_be_supported(bool for_encoding) {
     }
     gst_object_unref(element_factory);
 
-    element_factory = gst_element_factory_find("rtpldacpay");
-    if (element_factory == NULL) {
-        pa_log_info("LDAC RTP payloader element `rtpldacpay` not found");
-        return false;
-    }
-    gst_object_unref(element_factory);
-
     return true;
 }
 
@@ -206,7 +199,6 @@ static uint8_t fill_preferred_configuration(const pa_sample_spec *default_sample
 
 GstElement *gst_init_ldac(struct gst_info *info, pa_sample_spec *ss, bool for_encoding) {
     GstElement *bin;
-    GstElement *rtpldacpay;
     GstElement *enc;
     GstPad *pad;
 
@@ -270,28 +262,16 @@ GstElement *gst_init_ldac(struct gst_info *info, pa_sample_spec *ss, bool for_en
             goto fail;
     }
 
-    rtpldacpay = gst_element_factory_make("rtpldacpay", "rtp_ldac_pay");
-    if (!rtpldacpay) {
-        pa_log_error("Could not create RTP LDAC payloader element");
-        goto fail;
-    }
-
     bin = gst_bin_new("ldac_enc_bin");
     pa_assert(bin);
 
-    gst_bin_add_many(GST_BIN(bin), enc, rtpldacpay, NULL);
-
-    if (!gst_element_link(enc, rtpldacpay)) {
-        pa_log_error("Failed to link LDAC encoder to LDAC RTP payloader");
-        gst_object_unref(bin);
-        return NULL;
-    }
+    gst_bin_add_many(GST_BIN(bin), enc, NULL);
 
     pad = gst_element_get_static_pad(enc, "sink");
     pa_assert_se(gst_element_add_pad(bin, gst_ghost_pad_new("sink", pad)));
     gst_object_unref(GST_OBJECT(pad));
 
-    pad = gst_element_get_static_pad(rtpldacpay, "src");
+    pad = gst_element_get_static_pad(enc, "src");
     pa_assert_se(gst_element_add_pad(bin, gst_ghost_pad_new("src", pad)));
     gst_object_unref(GST_OBJECT(pad));
 
@@ -421,12 +401,33 @@ static size_t reduce_encoder_bitrate(void *codec_info, size_t write_link_mtu) {
 }
 
 static size_t encode_buffer(void *codec_info, uint32_t timestamp, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed) {
+    struct gst_info *info = (struct gst_info *) codec_info;
+    struct rtp_header *header;
+    struct rtp_payload *payload;
     size_t written;
 
-    written = gst_transcode_buffer(codec_info, input_buffer, input_size, output_buffer, output_size, processed);
+    if (PA_UNLIKELY(output_size < sizeof(*header) + sizeof(*payload))) {
+        *processed = 0;
+        return 0;
+    }
+
+    written = gst_transcode_buffer(codec_info, input_buffer, input_size, output_buffer + sizeof(*header) + sizeof(*payload), output_size - sizeof(*header) - sizeof(*payload), processed);
     if (PA_UNLIKELY(*processed != input_size))
         pa_log_error("LDAC encoding error");
 
+    if (PA_LIKELY(written > 0)) {
+        header = (struct rtp_header *) output_buffer;
+        pa_zero(*header);
+        header->v = 2;
+        header->pt = 96;
+        header->sequence_number = htons(info->seq_num++);
+        header->timestamp = htonl(timestamp);
+        header->ssrc = htonl(1);
+        payload = (struct rtp_payload*) (output_buffer + sizeof(*header));
+        payload->frame_count = get_ldac_num_frames(codec_info, info->codec_type);
+        written += sizeof(*header) + sizeof(*payload);
+    }
+
     return written;
 }
 


=====================================
src/modules/bluetooth/a2dp-codec-sbc.c
=====================================
@@ -704,7 +704,7 @@ static int reset(void *codec_info) {
 
 static size_t get_block_size(void *codec_info, size_t link_mtu) {
     struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
-    size_t rtp_size = sizeof(struct rtp_header) + sizeof(struct rtp_sbc_payload);
+    size_t rtp_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
     size_t frame_count = (link_mtu - rtp_size) / sbc_info->frame_length;
 
     /* frame_count is only 4 bit number */
@@ -716,7 +716,7 @@ static size_t get_block_size(void *codec_info, size_t link_mtu) {
 
 static size_t get_encoded_block_size(void *codec_info, size_t input_size) {
     struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
-    size_t rtp_size = sizeof(struct rtp_header) + sizeof(struct rtp_sbc_payload);
+    size_t rtp_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
 
     /* input size should be aligned to codec input block size */
     pa_assert_fp(input_size % sbc_info->codesize == 0);
@@ -753,14 +753,14 @@ static size_t increase_encoder_bitrate(void *codec_info, size_t write_link_mtu)
 static size_t encode_buffer(void *codec_info, uint32_t timestamp, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed) {
     struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
     struct rtp_header *header;
-    struct rtp_sbc_payload *payload;
+    struct rtp_payload *payload;
     uint8_t *d;
     const uint8_t *p;
     size_t to_write, to_encode;
     uint8_t frame_count;
 
     header = (struct rtp_header*) output_buffer;
-    payload = (struct rtp_sbc_payload*) (output_buffer + sizeof(*header));
+    payload = (struct rtp_payload*) (output_buffer + sizeof(*header));
 
     frame_count = 0;
 
@@ -836,14 +836,14 @@ static size_t decode_buffer(void *codec_info, const uint8_t *input_buffer, size_
     struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
 
     struct rtp_header *header;
-    struct rtp_sbc_payload *payload;
+    struct rtp_payload *payload;
     const uint8_t *p;
     uint8_t *d;
     size_t to_write, to_decode;
     uint8_t frame_count;
 
     header = (struct rtp_header *) input_buffer;
-    payload = (struct rtp_sbc_payload*) (input_buffer + sizeof(*header));
+    payload = (struct rtp_payload*) (input_buffer + sizeof(*header));
 
     frame_count = payload->frame_count;
 


=====================================
src/modules/bluetooth/rtp.h
=====================================
@@ -41,7 +41,7 @@ struct rtp_header {
 	uint32_t csrc[0];
 } __attribute__ ((packed));
 
-struct rtp_sbc_payload {
+struct rtp_payload {
 	uint8_t frame_count:4;
 	uint8_t rfa0:1;
 	uint8_t is_last_fragment:1;
@@ -67,7 +67,7 @@ struct rtp_header {
 	uint32_t csrc[0];
 } __attribute__ ((packed));
 
-struct rtp_sbc_payload {
+struct rtp_payload {
 	uint8_t is_fragmented:1;
 	uint8_t is_first_fragment:1;
 	uint8_t is_last_fragment:1;



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/4b996e2a7b92d7183a70ec32f6ef74c522bfcde7...516c691f69a5e7d8213ff941c12740a7088f85cf

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/4b996e2a7b92d7183a70ec32f6ef74c522bfcde7...516c691f69a5e7d8213ff941c12740a7088f85cf
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20220221/ea3311d1/attachment-0001.htm>


More information about the pulseaudio-commits mailing list