mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
Move the ownership of the encoded data memchunk into the raop_client.
This does not seem to fix the pool full messages so I'll have to try and suss that out. git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/coling@2400 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
4dd318519f
commit
5eecfa2e3f
2 changed files with 36 additions and 26 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id$ */
|
||||
/* $Id: module-esound-sink.c 2043 2007-11-09 18:25:40Z lennart $ */
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
|
@ -109,6 +109,7 @@ struct userdata {
|
|||
|
||||
int64_t offset;
|
||||
int64_t encoding_overhead;
|
||||
int32_t next_encoding_overhead;
|
||||
double encoding_ratio;
|
||||
|
||||
pa_raop_client *raop;
|
||||
|
|
@ -224,10 +225,9 @@ static void thread_func(void *userdata) {
|
|||
if (u->encoded_memchunk.length <= 0) {
|
||||
/* Encode it */
|
||||
size_t rl = u->raw_memchunk.length;
|
||||
if (u->encoded_memchunk.memblock)
|
||||
pa_memblock_unref(u->encoded_memchunk.memblock);
|
||||
u->encoding_overhead += u->next_encoding_overhead;
|
||||
u->encoded_memchunk = pa_raop_client_encode_sample(u->raop, u->core->mempool, &u->raw_memchunk);
|
||||
u->encoding_overhead += (u->encoded_memchunk.length - (rl - u->raw_memchunk.length));
|
||||
u->next_encoding_overhead = (u->encoded_memchunk.length - (rl - u->raw_memchunk.length));
|
||||
u->encoding_ratio = u->encoded_memchunk.length / (rl - u->raw_memchunk.length);
|
||||
}
|
||||
pa_assert(u->encoded_memchunk.length > 0);
|
||||
|
|
@ -259,11 +259,6 @@ static void thread_func(void *userdata) {
|
|||
u->encoded_memchunk.index += l;
|
||||
u->encoded_memchunk.length -= l;
|
||||
|
||||
if (u->encoded_memchunk.length <= 0) {
|
||||
pa_memblock_unref(u->encoded_memchunk.memblock);
|
||||
pa_memchunk_reset(&u->encoded_memchunk);
|
||||
}
|
||||
|
||||
pollfd->revents = 0;
|
||||
|
||||
if (u->encoded_memchunk.length > 0)
|
||||
|
|
@ -381,6 +376,7 @@ int pa__init(pa_module*m) {
|
|||
pa_memchunk_reset(&u->encoded_memchunk);
|
||||
u->offset = 0;
|
||||
u->encoding_overhead = 0;
|
||||
u->next_encoding_overhead = 0;
|
||||
u->encoding_ratio = 1.0;
|
||||
|
||||
pa_thread_mq_init(&u->thread_mq, m->core->mainloop);
|
||||
|
|
@ -477,9 +473,6 @@ void pa__done(pa_module*m) {
|
|||
if (u->raw_memchunk.memblock)
|
||||
pa_memblock_unref(u->raw_memchunk.memblock);
|
||||
|
||||
if (u->encoded_memchunk.memblock)
|
||||
pa_memblock_unref(u->encoded_memchunk.memblock);
|
||||
|
||||
if (u->raop)
|
||||
pa_raop_client_free(u->raop);
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
|
||||
struct pa_raop_client {
|
||||
pa_mainloop_api *mainloop;
|
||||
const char *host;
|
||||
char *host;
|
||||
char *sid;
|
||||
pa_rtsp_client *rtsp;
|
||||
|
||||
|
|
@ -93,9 +93,10 @@ struct pa_raop_client {
|
|||
void* userdata;
|
||||
|
||||
uint8_t *buffer;
|
||||
uint32_t buffer_length;
|
||||
uint8_t *buffer_index;
|
||||
uint16_t buffer_count;
|
||||
/*pa_memchunk memchunk;*/
|
||||
pa_memchunk memchunk;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -356,6 +357,7 @@ pa_raop_client* pa_raop_client_new(pa_mainloop_api *mainloop, const char* host)
|
|||
c->mainloop = mainloop;
|
||||
c->fd = -1;
|
||||
c->host = pa_xstrdup(host);
|
||||
pa_memchunk_reset(&c->memchunk);
|
||||
c->rtsp = pa_rtsp_client_new("iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)");
|
||||
|
||||
/* Initialise the AES encryption system */
|
||||
|
|
@ -386,6 +388,9 @@ void pa_raop_client_free(pa_raop_client* c)
|
|||
{
|
||||
pa_assert(c);
|
||||
|
||||
if (c->memchunk.memblock)
|
||||
pa_memblock_unref(c->memchunk.memblock);
|
||||
pa_xfree(c->buffer);
|
||||
pa_rtsp_client_free(c->rtsp);
|
||||
pa_xfree(c->aes_iv);
|
||||
pa_xfree(c->aes_nv);
|
||||
|
|
@ -403,9 +408,8 @@ pa_memchunk pa_raop_client_encode_sample(pa_raop_client* c, pa_mempool* mempool,
|
|||
uint8_t *bp, bpos;
|
||||
uint8_t *ibp, *maxibp;
|
||||
int size;
|
||||
uint8_t *p;
|
||||
uint8_t *b, *p;
|
||||
uint16_t bsize;
|
||||
pa_memchunk rv;
|
||||
size_t length;
|
||||
static uint8_t header[] = {
|
||||
0x24, 0x00, 0x00, 0x00,
|
||||
|
|
@ -427,13 +431,22 @@ pa_memchunk pa_raop_client_encode_sample(pa_raop_client* c, pa_mempool* mempool,
|
|||
|
||||
/* Leave 16 bytes extra to allow for the ALAC header which is about 55 bits */
|
||||
bufmax = length + header_size + 16;
|
||||
if (bufmax > c->buffer_length) {
|
||||
if (c->memchunk.memblock)
|
||||
pa_memblock_unref(c->memchunk.memblock);
|
||||
|
||||
c->buffer = pa_xrealloc(c->buffer, bufmax);
|
||||
memcpy(c->buffer, header, header_size);
|
||||
pa_memchunk_reset(&rv);
|
||||
rv.memblock = pa_memblock_new_user(mempool, c->buffer, (header_size + length), noop, 1);
|
||||
c->buffer_length = bufmax;
|
||||
pa_log_debug("Creating new memblock");
|
||||
c->memchunk.memblock = pa_memblock_new_user(mempool, c->buffer, bufmax, noop, 0);
|
||||
}
|
||||
c->memchunk.index = 0;
|
||||
c->memchunk.length = 0;
|
||||
b = pa_memblock_acquire(c->memchunk.memblock);
|
||||
memcpy(b, header, header_size);
|
||||
|
||||
/* Now write the actual samples */
|
||||
bp = c->buffer + header_size;
|
||||
bp = b + header_size;
|
||||
size = bpos = 0;
|
||||
bit_writer(&bp,&bpos,&size,1,3); // channel=1, stereo
|
||||
bit_writer(&bp,&bpos,&size,0,4); // unknown
|
||||
|
|
@ -462,16 +475,20 @@ pa_memchunk pa_raop_client_encode_sample(pa_raop_client* c, pa_mempool* mempool,
|
|||
raw->length -= 4;
|
||||
}
|
||||
pa_memblock_release(raw->memblock);
|
||||
rv.length = header_size + size;
|
||||
c->memchunk.length = header_size + size;
|
||||
|
||||
/* store the lenght (endian swapped: make this better) */
|
||||
len = size + header_size - 4;
|
||||
*(c->buffer + 2) = len >> 8;
|
||||
*(c->buffer + 3) = len & 0xff;
|
||||
*(b + 2) = len >> 8;
|
||||
*(b + 3) = len & 0xff;
|
||||
|
||||
/* encrypt our data */
|
||||
aes_encrypt(c, (c->buffer + header_size), size);
|
||||
return rv;
|
||||
aes_encrypt(c, (b + header_size), size);
|
||||
|
||||
/* We're done with the chunk */
|
||||
pa_memblock_release(c->memchunk.memblock);
|
||||
|
||||
return c->memchunk;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue