mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 04:25:01 +00:00
audio demuxer
This commit is contained in:
parent
fa1178195e
commit
7d4aedc29a
2 changed files with 34 additions and 0 deletions
|
@ -28,6 +28,7 @@ sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer) {
|
|||
#define SC_CODEC_ID_H264 UINT32_C(0x68323634) // "h264" in ASCII
|
||||
#define SC_CODEC_ID_H265 UINT32_C(0x68323635) // "h265" in ASCII
|
||||
#define SC_CODEC_ID_AV1 UINT32_C(0x00617631) // "av1" in ASCII
|
||||
#define SC_CODEC_ID_OPUS UINT32_C(0x6f707573) // "opus" in ASCII
|
||||
uint32_t codec_id = sc_read32be(data);
|
||||
switch (codec_id) {
|
||||
case SC_CODEC_ID_H264:
|
||||
|
@ -36,6 +37,8 @@ sc_demuxer_recv_codec_id(struct sc_demuxer *demuxer) {
|
|||
return AV_CODEC_ID_HEVC;
|
||||
case SC_CODEC_ID_AV1:
|
||||
return AV_CODEC_ID_AV1;
|
||||
case SC_CODEC_ID_OPUS:
|
||||
return AV_CODEC_ID_OPUS;
|
||||
default:
|
||||
LOGE("Unknown codec id 0x%08" PRIx32, codec_id);
|
||||
return AV_CODEC_ID_NONE;
|
||||
|
@ -272,6 +275,8 @@ end:
|
|||
void
|
||||
sc_demuxer_init(struct sc_demuxer *demuxer, sc_socket socket,
|
||||
const struct sc_demuxer_callbacks *cbs, void *cbs_userdata) {
|
||||
assert(socket != SC_SOCKET_NONE);
|
||||
|
||||
demuxer->socket = socket;
|
||||
demuxer->pending = NULL;
|
||||
demuxer->sink_count = 0;
|
||||
|
|
|
@ -41,6 +41,7 @@ struct scrcpy {
|
|||
struct sc_server server;
|
||||
struct sc_screen screen;
|
||||
struct sc_demuxer video_demuxer;
|
||||
struct sc_demuxer audio_demuxer;
|
||||
struct sc_decoder decoder;
|
||||
struct sc_recorder recorder;
|
||||
#ifdef HAVE_V4L2
|
||||
|
@ -240,6 +241,14 @@ sc_video_demuxer_on_eos(struct sc_demuxer *demuxer, void *userdata) {
|
|||
PUSH_EVENT(EVENT_STREAM_STOPPED);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_audio_demuxer_on_eos(struct sc_demuxer *demuxer, void *userdata) {
|
||||
(void) demuxer;
|
||||
(void) userdata;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void
|
||||
sc_server_on_connection_failed(struct sc_server *server, void *userdata) {
|
||||
(void) server;
|
||||
|
@ -296,6 +305,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||
bool v4l2_sink_initialized = false;
|
||||
#endif
|
||||
bool video_demuxer_started = false;
|
||||
bool audio_demuxer_started = false;
|
||||
#ifdef HAVE_USB
|
||||
bool aoa_hid_initialized = false;
|
||||
bool hid_keyboard_initialized = false;
|
||||
|
@ -427,6 +437,14 @@ scrcpy(struct scrcpy_options *options) {
|
|||
sc_demuxer_init(&s->video_demuxer, s->server.video_socket,
|
||||
&video_demuxer_cbs, NULL);
|
||||
|
||||
if (options->audio) {
|
||||
static const struct sc_demuxer_callbacks audio_demuxer_cbs = {
|
||||
.on_eos = sc_audio_demuxer_on_eos,
|
||||
};
|
||||
sc_demuxer_init(&s->audio_demuxer, s->server.audio_socket,
|
||||
&audio_demuxer_cbs, NULL);
|
||||
}
|
||||
|
||||
if (dec) {
|
||||
sc_demuxer_add_sink(&s->video_demuxer, &dec->packet_sink);
|
||||
}
|
||||
|
@ -646,6 +664,13 @@ aoa_hid_end:
|
|||
}
|
||||
video_demuxer_started = true;
|
||||
|
||||
if (options->audio) {
|
||||
if (!sc_demuxer_start(&s->audio_demuxer)) {
|
||||
goto end;
|
||||
}
|
||||
audio_demuxer_started = true;
|
||||
}
|
||||
|
||||
ret = event_loop(s);
|
||||
LOGD("quit...");
|
||||
|
||||
|
@ -692,6 +717,10 @@ end:
|
|||
sc_demuxer_join(&s->video_demuxer);
|
||||
}
|
||||
|
||||
if (audio_demuxer_started) {
|
||||
sc_demuxer_join(&s->audio_demuxer);
|
||||
}
|
||||
|
||||
#ifdef HAVE_V4L2
|
||||
if (v4l2_sink_initialized) {
|
||||
sc_v4l2_sink_destroy(&s->v4l2_sink);
|
||||
|
|
Loading…
Add table
Reference in a new issue