summaryrefslogtreecommitdiff
path: root/src/fruits/ctv/ctv.c
blob: 2878600984deee12831be91ca5809077bc922acb (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <al/log.h>
#include <android/log.h>

#include "../../libsink/sink.h"
#include "../../libsink/desktop.h"
#ifdef CAMU_HAVE_FFMPEG
#include "../../codec/ffmpeg/common.h"
#endif

#include "../common.h"

struct ctv {
    struct nn_event_loop loop;
    struct camu_desktop desktop;
    struct nn_thread thread;
};

static nn_thread_result NNWT_THREADCALL event_loop_thread(void *userdata)
{
    struct ctv *c = (struct ctv *)userdata;
    nn_thread_set_name("event_loop");

    nn_event_loop_init(&c->loop);

    struct camu_sink *sink = &c->desktop.sink;
    sink->local = true;

    struct lia_prefs *prefs = &sink->prefs;
#ifdef CAMU_HAVE_SUBTITLES
    prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO) | (1 << CAMU_STREAM_SUBTITLE);
#else
    prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO);
#endif
    prefs->language.audio = CAMU_LANG_JAPANESE;
    prefs->language.subtitles = CAMU_LANG_ENGLISH;

    if (!camu_desktop_connect(&c->desktop, &al_str_c("ctv"), &c->loop, NNWT_SOCKET_TCP, &al_str_c(""), CAMU_PORT)) {
        return 0;
    }

    nn_event_loop_run(&c->loop);

    return 0;
}

static s32 log_callback(void *userdata, u8 level, char *message)
{
    (void)userdata;
    (void)level;
    __android_log_print(ANDROID_LOG_DEBUG, "CTV", "%*.*s", 0, AL_LOG_MESSAGE_SIZE, message);
    return al_strnlen(message, AL_LOG_MESSAGE_SIZE);
}

static struct ctv c = { 0 };

s32 stl_platform_main(u32 argc, str *argv)
{
    (void)argc;
    (void)argv;

    al_set_print(log_callback, NULL);

#ifdef CAMU_HAVE_FFMPEG
    camu_ff_common_init();
#endif

    if (!camu_desktop_open(&c.desktop, "ctv")) {
        return 0;
    }

    nn_thread_create(&c.thread, event_loop_thread, &c);

    return EXIT_SUCCESS;
}