mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-30 07:34:27 +08:00
android/hal-audio: Add RTP timestamps
This commit is contained in:
parent
66a267e985
commit
c79676c3ee
@ -133,6 +133,7 @@ struct sbc_data {
|
||||
|
||||
struct timespec start;
|
||||
unsigned frames_sent;
|
||||
uint32_t timestamp;
|
||||
|
||||
uint16_t seq;
|
||||
};
|
||||
@ -404,6 +405,7 @@ static void sbc_resume(void *codec_data)
|
||||
clock_gettime(CLOCK_MONOTONIC, &sbc_data->start);
|
||||
|
||||
sbc_data->frames_sent = 0;
|
||||
sbc_data->timestamp = 0;
|
||||
}
|
||||
|
||||
static int write_media_packet(int fd, struct sbc_data *sbc_data,
|
||||
@ -455,31 +457,38 @@ static ssize_t sbc_write_data(void *codec_data, const void *buffer,
|
||||
struct media_packet *mp = (struct media_packet *) sbc_data->out_buf;
|
||||
size_t free_space = sbc_data->out_buf_size - sizeof(*mp);
|
||||
int ret;
|
||||
ssize_t bytes_read;
|
||||
|
||||
mp->hdr.v = 2;
|
||||
mp->hdr.pt = 1;
|
||||
mp->hdr.ssrc = htonl(1);
|
||||
mp->hdr.timestamp = htonl(sbc_data->timestamp);
|
||||
mp->payload.frame_count = 0;
|
||||
|
||||
while (bytes - consumed >= sbc_data->in_frame_len) {
|
||||
ssize_t written = 0;
|
||||
|
||||
ret = sbc_encode(&sbc_data->enc, buffer + consumed,
|
||||
bytes_read = sbc_encode(&sbc_data->enc, buffer + consumed,
|
||||
sbc_data->in_frame_len,
|
||||
mp->data + encoded, free_space,
|
||||
&written);
|
||||
|
||||
if (ret < 0) {
|
||||
error("SBC: failed to encode block (%d)", ret);
|
||||
if (bytes_read < 0) {
|
||||
error("SBC: failed to encode block (%zd)", bytes_read);
|
||||
break;
|
||||
}
|
||||
|
||||
mp->payload.frame_count++;
|
||||
|
||||
consumed += ret;
|
||||
consumed += bytes_read;
|
||||
encoded += written;
|
||||
free_space -= written;
|
||||
|
||||
/* AudioFlinger provides PCM 16bit stereo only, thus sample size
|
||||
* is always 4 bytes
|
||||
*/
|
||||
sbc_data->timestamp += (bytes_read / 4);
|
||||
|
||||
/* write data if we either filled media packed or encoded all
|
||||
* input data
|
||||
*/
|
||||
@ -495,6 +504,7 @@ static ssize_t sbc_write_data(void *codec_data, const void *buffer,
|
||||
|
||||
encoded = 0;
|
||||
free_space = sbc_data->out_buf_size - sizeof(*mp);
|
||||
mp->hdr.timestamp = htonl(sbc_data->timestamp);
|
||||
mp->payload.frame_count = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user