summaryrefslogtreecommitdiff
path: root/src/liana/handlers/cdio_client.c
blob: af93dccbf8cb05329880a3ff260f695316a3470e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "../client.h"

#include "cdio.h"

static bool cdio_client_init(struct lia_client_handler *handler, struct camu_renderer *renderer,
    struct camu_codec_stream *stream)
{
    struct lia_cdio_client *cdio = (struct lia_cdio_client *)handler;
    (void)renderer;
    cdio->handler.stream = stream;
    return true;
}

static bool cdio_client_handle_packet(struct lia_client_handler *handler, struct nn_packet *packet)
{
    struct lia_cdio_client *cdio = (struct lia_cdio_client *)handler;
    if (!packet) {
        cdio->handler.callback(cdio->handler.userdata, LIANA_CLIENT_EOF, cdio->handler.stream, NULL);
        return true;
    }
    struct camu_codec_frame *frame = al_alloc_object(struct camu_codec_frame);
    frame->mode = CAMU_NORMAL;
    frame->pts = nn_packet_read_f64(packet);
    frame->audio.sample_count = nn_packet_read_s32(packet);
    struct nn_buffer buffer;
    nn_packet_read_buffer(packet, &buffer);
    frame->data = (u8 *)al_malloc(buffer.size);
    al_memcpy(frame->data, nn_buffer_get_ptr(&buffer, 0), buffer.size);
    cdio->handler.callback(cdio->handler.userdata, LIANA_CLIENT_DATA, cdio->handler.stream, frame);
    return true;
}

static void cdio_client_flush(struct lia_client_handler *handler)
{
    (void)handler;
}

static void cdio_client_free(struct lia_client_handler **handler)
{
    (void)handler;
}

struct lia_client_handler *lia_cdio_client_create(void)
{
    struct lia_cdio_client *cdio = al_alloc_object(struct lia_cdio_client);
    cdio->handler.init = cdio_client_init;
    cdio->handler.handle_packet = cdio_client_handle_packet;
    cdio->handler.flush = cdio_client_flush;
    cdio->handler.free = cdio_client_free;
    return (struct lia_client_handler *)cdio;
}