mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-03-10 14:14:26 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7b1d0ea9a | ||
|
|
18082f6069 | ||
|
|
8b38b11875 | ||
|
|
64821466a1 | ||
|
|
82cb8ab870 | ||
|
|
b51841e85d |
4
BUILD.md
4
BUILD.md
@@ -260,7 +260,7 @@ set ANDROID_SDK_ROOT=%LOCALAPPDATA%\Android\sdk
|
||||
Then, build:
|
||||
|
||||
```bash
|
||||
meson x --buildtype=release --strip -Db_lto=true
|
||||
meson setup x --buildtype=release --strip -Db_lto=true
|
||||
ninja -Cx # DO NOT RUN AS ROOT
|
||||
```
|
||||
|
||||
@@ -281,7 +281,7 @@ Download the prebuilt server somewhere, and specify its path during the Meson
|
||||
configuration:
|
||||
|
||||
```bash
|
||||
meson x --buildtype=release --strip -Db_lto=true \
|
||||
meson setup x --buildtype=release --strip -Db_lto=true \
|
||||
-Dprebuilt_server=/path/to/scrcpy-server
|
||||
ninja -Cx # DO NOT RUN AS ROOT
|
||||
```
|
||||
|
||||
@@ -277,7 +277,7 @@ The server is pushed to the device by the client on startup.
|
||||
To debug it, enable the server debugger during configuration:
|
||||
|
||||
```bash
|
||||
meson x -Dserver_debugger=true
|
||||
meson setup x -Dserver_debugger=true
|
||||
# or, if x is already configured
|
||||
meson configure x -Dserver_debugger=true
|
||||
```
|
||||
@@ -286,7 +286,7 @@ If your device runs Android 8 or below, set the `server_debugger_method` to
|
||||
`old` in addition:
|
||||
|
||||
```bash
|
||||
meson x -Dserver_debugger=true -Dserver_debugger_method=old
|
||||
meson setup x -Dserver_debugger=true -Dserver_debugger_method=old
|
||||
# or, if x is already configured
|
||||
meson configure x -Dserver_debugger=true -Dserver_debugger_method=old
|
||||
```
|
||||
|
||||
@@ -23,7 +23,6 @@ src = [
|
||||
'src/options.c',
|
||||
'src/receiver.c',
|
||||
'src/recorder.c',
|
||||
'src/rtp.c',
|
||||
'src/scrcpy.c',
|
||||
'src/screen.c',
|
||||
'src/server.c',
|
||||
|
||||
@@ -61,6 +61,22 @@ static const char *const copy_key_labels[] = {
|
||||
"cut",
|
||||
};
|
||||
|
||||
static inline const char *
|
||||
get_well_known_pointer_id_name(uint64_t pointer_id) {
|
||||
switch (pointer_id) {
|
||||
case POINTER_ID_MOUSE:
|
||||
return "mouse";
|
||||
case POINTER_ID_GENERIC_FINGER:
|
||||
return "finger";
|
||||
case POINTER_ID_VIRTUAL_MOUSE:
|
||||
return "vmouse";
|
||||
case POINTER_ID_VIRTUAL_FINGER:
|
||||
return "vfinger";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_position(uint8_t *buf, const struct sc_position *position) {
|
||||
sc_write32be(&buf[0], position->point.x);
|
||||
@@ -159,11 +175,12 @@ sc_control_msg_log(const struct sc_control_msg *msg) {
|
||||
int action = msg->inject_touch_event.action
|
||||
& AMOTION_EVENT_ACTION_MASK;
|
||||
uint64_t id = msg->inject_touch_event.pointer_id;
|
||||
if (id == POINTER_ID_MOUSE || id == POINTER_ID_VIRTUAL_FINGER) {
|
||||
const char *pointer_name = get_well_known_pointer_id_name(id);
|
||||
if (pointer_name) {
|
||||
// string pointer id
|
||||
LOG_CMSG("touch [id=%s] %-4s position=%" PRIi32 ",%" PRIi32
|
||||
" pressure=%f buttons=%06lx",
|
||||
id == POINTER_ID_MOUSE ? "mouse" : "vfinger",
|
||||
pointer_name,
|
||||
MOTIONEVENT_ACTION_LABEL(action),
|
||||
msg->inject_touch_event.position.point.x,
|
||||
msg->inject_touch_event.position.point.y,
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
#define SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (SC_CONTROL_MSG_MAX_SIZE - 14)
|
||||
|
||||
#define POINTER_ID_MOUSE UINT64_C(-1)
|
||||
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
||||
#define POINTER_ID_GENERIC_FINGER UINT64_C(-2)
|
||||
|
||||
// Used for injecting an additional virtual pointer for pinch-to-zoom
|
||||
#define POINTER_ID_VIRTUAL_MOUSE UINT64_C(-3)
|
||||
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-4)
|
||||
|
||||
enum sc_control_msg_type {
|
||||
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "util/net.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
#define SC_DEMUXER_MAX_SINKS 3
|
||||
#define SC_DEMUXER_MAX_SINKS 2
|
||||
|
||||
struct sc_demuxer {
|
||||
sc_socket socket;
|
||||
|
||||
@@ -353,6 +353,7 @@ struct sc_mouse_click_event {
|
||||
struct sc_position position;
|
||||
enum sc_action action;
|
||||
enum sc_mouse_button button;
|
||||
uint64_t pointer_id;
|
||||
uint8_t buttons_state; // bitwise-OR of sc_mouse_button values
|
||||
};
|
||||
|
||||
@@ -365,6 +366,7 @@ struct sc_mouse_scroll_event {
|
||||
|
||||
struct sc_mouse_motion_event {
|
||||
struct sc_position position;
|
||||
uint64_t pointer_id;
|
||||
int32_t xrel;
|
||||
int32_t yrel;
|
||||
uint8_t buttons_state; // bitwise-OR of sc_mouse_button values
|
||||
|
||||
@@ -335,7 +335,9 @@ simulate_virtual_finger(struct sc_input_manager *im,
|
||||
msg.inject_touch_event.action = action;
|
||||
msg.inject_touch_event.position.screen_size = im->screen->frame_size;
|
||||
msg.inject_touch_event.position.point = point;
|
||||
msg.inject_touch_event.pointer_id = POINTER_ID_VIRTUAL_FINGER;
|
||||
msg.inject_touch_event.pointer_id =
|
||||
im->forward_all_clicks ? POINTER_ID_VIRTUAL_MOUSE
|
||||
: POINTER_ID_VIRTUAL_FINGER;
|
||||
msg.inject_touch_event.pressure = up ? 0.0f : 1.0f;
|
||||
msg.inject_touch_event.buttons = 0;
|
||||
|
||||
@@ -564,6 +566,8 @@ sc_input_manager_process_mouse_motion(struct sc_input_manager *im,
|
||||
event->x,
|
||||
event->y),
|
||||
},
|
||||
.pointer_id = im->forward_all_clicks ? POINTER_ID_MOUSE
|
||||
: POINTER_ID_GENERIC_FINGER,
|
||||
.xrel = event->xrel,
|
||||
.yrel = event->yrel,
|
||||
.buttons_state =
|
||||
@@ -687,6 +691,8 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
|
||||
},
|
||||
.action = sc_action_from_sdl_mousebutton_type(event->type),
|
||||
.button = sc_mouse_button_from_sdl(event->button),
|
||||
.pointer_id = im->forward_all_clicks ? POINTER_ID_MOUSE
|
||||
: POINTER_ID_GENERIC_FINGER,
|
||||
.buttons_state =
|
||||
sc_mouse_buttons_state_from_sdl(sdl_buttons_state,
|
||||
im->forward_all_clicks),
|
||||
|
||||
@@ -69,7 +69,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
||||
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = AMOTION_EVENT_ACTION_MOVE,
|
||||
.pointer_id = POINTER_ID_MOUSE,
|
||||
.pointer_id = event->pointer_id,
|
||||
.position = event->position,
|
||||
.pressure = 1.f,
|
||||
.buttons = convert_mouse_buttons(event->buttons_state),
|
||||
@@ -90,7 +90,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
||||
.type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||
.inject_touch_event = {
|
||||
.action = convert_mouse_action(event->action),
|
||||
.pointer_id = POINTER_ID_MOUSE,
|
||||
.pointer_id = event->pointer_id,
|
||||
.position = event->position,
|
||||
.pressure = event->action == SC_ACTION_DOWN ? 1.f : 0.f,
|
||||
.buttons = convert_mouse_buttons(event->buttons_state),
|
||||
|
||||
319
app/src/rtp.c
319
app/src/rtp.c
@@ -1,319 +0,0 @@
|
||||
#include "rtp.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/time.h>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
/** Downcast packet_sink to rtp */
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct sc_rtp, packet_sink)
|
||||
|
||||
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
|
||||
|
||||
static struct sc_rtp_packet *
|
||||
sc_rtp_packet_new(const AVPacket *packet) {
|
||||
struct sc_rtp_packet *rtp = malloc(sizeof(*rtp));
|
||||
if (!rtp) {
|
||||
LOG_OOM();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rtp->packet = av_packet_alloc();
|
||||
if (!rtp->packet) {
|
||||
LOG_OOM();
|
||||
free(rtp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (av_packet_ref(rtp->packet, packet)) {
|
||||
av_packet_free(&rtp->packet);
|
||||
free(rtp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return rtp;
|
||||
}
|
||||
|
||||
static void
|
||||
sc_rtp_packet_delete(struct sc_rtp_packet *rtp) {
|
||||
av_packet_free(&rtp->packet);
|
||||
free(rtp);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_rtp_queue_clear(struct sc_rtp_queue *queue) {
|
||||
while (!sc_queue_is_empty(queue)) {
|
||||
struct sc_rtp_packet *rtp;
|
||||
sc_queue_take(queue, next, &rtp);
|
||||
sc_rtp_packet_delete(rtp);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_write_header(struct sc_rtp *rtp, const AVPacket *packet) {
|
||||
AVStream *ostream = rtp->ctx->streams[0];
|
||||
|
||||
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
||||
if (!extradata) {
|
||||
LOG_OOM();
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy the first packet to the extra data
|
||||
memcpy(extradata, packet->data, packet->size);
|
||||
|
||||
ostream->codecpar->extradata = extradata;
|
||||
ostream->codecpar->extradata_size = packet->size;
|
||||
|
||||
int ret = avformat_write_header(rtp->ctx, NULL);
|
||||
if (ret < 0) {
|
||||
LOGE("Failed to write RTP header");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
sc_rtp_rescale_packet(struct sc_rtp *rtp, AVPacket *packet) {
|
||||
AVStream *ostream = rtp->ctx->streams[0];
|
||||
av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base);
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_write(struct sc_rtp *rtp, AVPacket *packet) {
|
||||
if (!rtp->header_written) {
|
||||
if (packet->pts != AV_NOPTS_VALUE) {
|
||||
LOGE("The first packet is not a config packet");
|
||||
return false;
|
||||
}
|
||||
bool ok = sc_rtp_write_header(rtp, packet);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
rtp->header_written = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packet->pts == AV_NOPTS_VALUE) {
|
||||
// ignore config packets
|
||||
return true;
|
||||
}
|
||||
|
||||
sc_rtp_rescale_packet(rtp, packet);
|
||||
return av_write_frame(rtp->ctx, packet) >= 0;
|
||||
}
|
||||
|
||||
static int
|
||||
run_rtp(void *data) {
|
||||
struct sc_rtp *rtp = data;
|
||||
|
||||
for (;;) {
|
||||
sc_mutex_lock(&rtp->mutex);
|
||||
|
||||
while (!rtp->stopped && sc_queue_is_empty(&rtp->queue)) {
|
||||
sc_cond_wait(&rtp->queue_cond, &rtp->mutex);
|
||||
}
|
||||
|
||||
// if stopped is set, continue to process the remaining events (to
|
||||
// finish the streaming) before actually stopping
|
||||
|
||||
if (rtp->stopped && sc_queue_is_empty(&rtp->queue)) {
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
break;
|
||||
}
|
||||
|
||||
struct sc_rtp_packet *pkt;
|
||||
sc_queue_take(&rtp->queue, next, &pkt);
|
||||
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
|
||||
bool ok = sc_rtp_write(rtp, pkt->packet);
|
||||
sc_rtp_packet_delete(pkt);
|
||||
if (!ok) {
|
||||
LOGE("Could not send packet");
|
||||
|
||||
sc_mutex_lock(&rtp->mutex);
|
||||
rtp->failed = true;
|
||||
// discard pending packets
|
||||
sc_rtp_queue_clear(&rtp->queue);
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!rtp->failed) {
|
||||
if (rtp->header_written) {
|
||||
int ret = av_write_trailer(rtp->ctx);
|
||||
if (ret < 0) {
|
||||
LOGE("Failed to write RTP trailer");
|
||||
rtp->failed = true;
|
||||
}
|
||||
} else {
|
||||
// nothing has been sent
|
||||
rtp->failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (rtp->failed) {
|
||||
LOGE("Streaming over RTP failed");
|
||||
} else {
|
||||
LOGI("Streaming over RTP complete");
|
||||
}
|
||||
|
||||
LOGD("RTP streaming thread ended");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_open(struct sc_rtp *rtp, const AVCodec *input_codec) {
|
||||
bool ok = sc_mutex_init(&rtp->mutex);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = sc_cond_init(&rtp->queue_cond);
|
||||
if (!ok) {
|
||||
goto error_mutex_destroy;
|
||||
}
|
||||
|
||||
sc_queue_init(&rtp->queue);
|
||||
rtp->stopped = false;
|
||||
rtp->failed = false;
|
||||
rtp->header_written = false;
|
||||
|
||||
int ret = avformat_alloc_output_context2(&rtp->ctx, NULL, "rtp",
|
||||
rtp->out_url);
|
||||
if (ret < 0) {
|
||||
goto error_cond_destroy;
|
||||
}
|
||||
|
||||
AVStream *ostream = avformat_new_stream(rtp->ctx, input_codec);
|
||||
if (!ostream) {
|
||||
goto error_avformat_free_context;
|
||||
}
|
||||
|
||||
ostream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||
ostream->codecpar->codec_id = input_codec->id;
|
||||
ostream->codecpar->width = rtp->declared_frame_size.width;
|
||||
ostream->codecpar->height = rtp->declared_frame_size.height;
|
||||
|
||||
ret = avio_open(&rtp->ctx->pb, rtp->out_url, AVIO_FLAG_WRITE);
|
||||
if (ret < 0) {
|
||||
LOGE("Failed to open output: %s", rtp->out_url);
|
||||
// ostream will be cleaned up during context cleaning
|
||||
goto error_avformat_free_context;
|
||||
}
|
||||
|
||||
LOGD("Starting RTP thread");
|
||||
ok = sc_thread_create(&rtp->thread, run_rtp, "scrcpy-rtp", rtp);
|
||||
if (!ok) {
|
||||
LOGE("Could not start RTP thread");
|
||||
goto error_avio_close;
|
||||
}
|
||||
|
||||
LOGI("Streaming started to %s", rtp->out_url);
|
||||
|
||||
return true;
|
||||
|
||||
error_avio_close:
|
||||
avio_close(rtp->ctx->pb);
|
||||
error_avformat_free_context:
|
||||
avformat_free_context(rtp->ctx);
|
||||
error_cond_destroy:
|
||||
sc_cond_destroy(&rtp->queue_cond);
|
||||
error_mutex_destroy:
|
||||
sc_mutex_destroy(&rtp->mutex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
sc_rtp_close(struct sc_rtp *rtp) {
|
||||
sc_mutex_lock(&rtp->mutex);
|
||||
rtp->stopped = true;
|
||||
sc_cond_signal(&rtp->queue_cond);
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
|
||||
sc_thread_join(&rtp->thread, NULL);
|
||||
|
||||
avio_close(rtp->ctx->pb);
|
||||
avformat_free_context(rtp->ctx);
|
||||
sc_cond_destroy(&rtp->queue_cond);
|
||||
sc_mutex_destroy(&rtp->mutex);
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_push(struct sc_rtp *rtp, const AVPacket *packet) {
|
||||
sc_mutex_lock(&rtp->mutex);
|
||||
assert(!rtp->stopped);
|
||||
|
||||
if (rtp->failed) {
|
||||
// reject any new packet (this will stop the stream)
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
struct sc_rtp_packet *pkt = sc_rtp_packet_new(packet);
|
||||
if (!pkt) {
|
||||
LOG_OOM();
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
sc_queue_push(&rtp->queue, next, pkt);
|
||||
sc_cond_signal(&rtp->queue_cond);
|
||||
|
||||
sc_mutex_unlock(&rtp->mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_packet_sink_open(struct sc_packet_sink *sink,
|
||||
const AVCodec *codec) {
|
||||
struct sc_rtp *rtp = DOWNCAST(sink);
|
||||
return sc_rtp_open(rtp, codec);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_rtp_packet_sink_close(struct sc_packet_sink *sink) {
|
||||
struct sc_rtp *rtp = DOWNCAST(sink);
|
||||
sc_rtp_close(rtp);
|
||||
}
|
||||
|
||||
static bool
|
||||
sc_rtp_packet_sink_push(struct sc_packet_sink *sink,
|
||||
const AVPacket *packet) {
|
||||
struct sc_rtp *rtp = DOWNCAST(sink);
|
||||
return sc_rtp_push(rtp, packet);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_rtp_init(struct sc_rtp *rtp, const char *out_url,
|
||||
struct sc_size declared_frame_size) {
|
||||
rtp->out_url = strdup(out_url);
|
||||
if (!rtp->out_url) {
|
||||
LOG_OOM();
|
||||
return false;
|
||||
}
|
||||
|
||||
rtp->declared_frame_size = declared_frame_size;
|
||||
|
||||
static const struct sc_packet_sink_ops ops = {
|
||||
.open = sc_rtp_packet_sink_open,
|
||||
.close = sc_rtp_packet_sink_close,
|
||||
.push = sc_rtp_packet_sink_push,
|
||||
};
|
||||
|
||||
rtp->packet_sink.ops = &ops;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
sc_rtp_destroy(struct sc_rtp *rtp) {
|
||||
free(rtp->out_url);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#ifndef SC_RTP_H
|
||||
#define SC_RTP_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
#include "coords.h"
|
||||
#include "trait/packet_sink.h"
|
||||
#include "util/queue.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
struct sc_rtp_packet {
|
||||
AVPacket *packet;
|
||||
struct sc_rtp_packet *next;
|
||||
};
|
||||
|
||||
struct sc_rtp_queue SC_QUEUE(struct sc_rtp_packet);
|
||||
|
||||
struct sc_rtp {
|
||||
struct sc_packet_sink packet_sink; // packet sink trait;
|
||||
|
||||
char *out_url;
|
||||
AVFormatContext *ctx;
|
||||
struct sc_size declared_frame_size;
|
||||
bool header_written;
|
||||
|
||||
sc_thread thread;
|
||||
sc_mutex mutex;
|
||||
sc_cond queue_cond;
|
||||
bool stopped; // set on rtp_close()
|
||||
bool failed; // set on packet write failure
|
||||
struct sc_rtp_queue queue;
|
||||
};
|
||||
|
||||
bool
|
||||
sc_rtp_init(struct sc_rtp *rtp, const char *out_url,
|
||||
struct sc_size declared_frame_size);
|
||||
|
||||
void
|
||||
sc_rtp_destroy(struct sc_rtp *rtp);
|
||||
|
||||
#endif
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "keyboard_inject.h"
|
||||
#include "mouse_inject.h"
|
||||
#include "recorder.h"
|
||||
#include "rtp.h"
|
||||
#include "screen.h"
|
||||
#include "server.h"
|
||||
#ifdef HAVE_USB
|
||||
@@ -43,7 +42,6 @@ struct scrcpy {
|
||||
struct sc_demuxer demuxer;
|
||||
struct sc_decoder decoder;
|
||||
struct sc_recorder recorder;
|
||||
struct sc_rtp rtp;
|
||||
#ifdef HAVE_V4L2
|
||||
struct sc_v4l2_sink v4l2_sink;
|
||||
#endif
|
||||
@@ -285,7 +283,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
bool server_started = false;
|
||||
bool file_pusher_initialized = false;
|
||||
bool recorder_initialized = false;
|
||||
bool rtp_initialized = false;
|
||||
#ifdef HAVE_V4L2
|
||||
bool v4l2_sink_initialized = false;
|
||||
#endif
|
||||
@@ -423,14 +420,6 @@ scrcpy(struct scrcpy_options *options) {
|
||||
sc_demuxer_add_sink(&s->demuxer, &rec->packet_sink);
|
||||
}
|
||||
|
||||
struct sc_rtp *rtp = NULL;
|
||||
if (!sc_rtp_init(&s->rtp, "rtp://127.0.0.1:1234", info->frame_size)) {
|
||||
goto end;
|
||||
}
|
||||
rtp = &s->rtp;
|
||||
rtp_initialized = true;
|
||||
sc_demuxer_add_sink(&s->demuxer, &rtp->packet_sink);
|
||||
|
||||
struct sc_controller *controller = NULL;
|
||||
struct sc_key_processor *kp = NULL;
|
||||
struct sc_mouse_processor *mp = NULL;
|
||||
@@ -718,10 +707,6 @@ end:
|
||||
sc_controller_destroy(&s->controller);
|
||||
}
|
||||
|
||||
if (rtp_initialized) {
|
||||
sc_rtp_destroy(&s->rtp);
|
||||
}
|
||||
|
||||
if (recorder_initialized) {
|
||||
sc_recorder_destroy(&s->recorder);
|
||||
}
|
||||
|
||||
@@ -306,13 +306,14 @@ sc_screen_render(struct sc_screen *screen, bool update_content_rect) {
|
||||
}
|
||||
|
||||
|
||||
#if defined(__APPLE__) || defined(__WINDOWS__)
|
||||
#if defined(__APPLE__)
|
||||
# define CONTINUOUS_RESIZING_WORKAROUND
|
||||
#endif
|
||||
|
||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||
// On Windows and MacOS, resizing blocks the event loop, so resizing events are
|
||||
// not triggered. As a workaround, handle them in an event handler.
|
||||
// not triggered. On MacOS, as a workaround, handle them in an event handler
|
||||
// (it does not work for Windows unfortunately).
|
||||
//
|
||||
// <https://bugzilla.libsdl.org/show_bug.cgi?id=2077>
|
||||
// <https://stackoverflow.com/a/40693139/1987178>
|
||||
|
||||
28
release.mk
28
release.mk
@@ -24,13 +24,13 @@ SERVER_BUILD_DIR := build-server
|
||||
WIN32_BUILD_DIR := build-win32
|
||||
WIN64_BUILD_DIR := build-win64
|
||||
|
||||
DIST := dist
|
||||
WIN32_TARGET_DIR := scrcpy-win32
|
||||
WIN64_TARGET_DIR := scrcpy-win64
|
||||
|
||||
VERSION := $(shell git describe --tags --always)
|
||||
WIN32_TARGET := $(WIN32_TARGET_DIR)-$(VERSION).zip
|
||||
WIN64_TARGET := $(WIN64_TARGET_DIR)-$(VERSION).zip
|
||||
|
||||
DIST := dist
|
||||
WIN32_TARGET_DIR := scrcpy-win32-$(VERSION)
|
||||
WIN64_TARGET_DIR := scrcpy-win64-$(VERSION)
|
||||
WIN32_TARGET := $(WIN32_TARGET_DIR).zip
|
||||
WIN64_TARGET := $(WIN64_TARGET_DIR).zip
|
||||
|
||||
RELEASE_DIR := release-$(VERSION)
|
||||
|
||||
@@ -53,13 +53,13 @@ clean:
|
||||
|
||||
test:
|
||||
[ -d "$(TEST_BUILD_DIR)" ] || ( mkdir "$(TEST_BUILD_DIR)" && \
|
||||
meson "$(TEST_BUILD_DIR)" -Db_sanitize=address )
|
||||
meson setup "$(TEST_BUILD_DIR)" -Db_sanitize=address )
|
||||
ninja -C "$(TEST_BUILD_DIR)"
|
||||
$(GRADLE) -p server check
|
||||
|
||||
build-server:
|
||||
[ -d "$(SERVER_BUILD_DIR)" ] || ( mkdir "$(SERVER_BUILD_DIR)" && \
|
||||
meson "$(SERVER_BUILD_DIR)" --buildtype release -Dcompile_app=false )
|
||||
meson setup "$(SERVER_BUILD_DIR)" --buildtype release -Dcompile_app=false )
|
||||
ninja -C "$(SERVER_BUILD_DIR)"
|
||||
|
||||
prepare-deps-win32:
|
||||
@@ -76,7 +76,7 @@ prepare-deps-win64:
|
||||
|
||||
build-win32: prepare-deps-win32
|
||||
[ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \
|
||||
meson "$(WIN32_BUILD_DIR)" \
|
||||
meson setup "$(WIN32_BUILD_DIR)" \
|
||||
--cross-file cross_win32.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcompile_server=false \
|
||||
@@ -85,7 +85,7 @@ build-win32: prepare-deps-win32
|
||||
|
||||
build-win64: prepare-deps-win64
|
||||
[ -d "$(WIN64_BUILD_DIR)" ] || ( mkdir "$(WIN64_BUILD_DIR)" && \
|
||||
meson "$(WIN64_BUILD_DIR)" \
|
||||
meson setup "$(WIN64_BUILD_DIR)" \
|
||||
--cross-file cross_win64.txt \
|
||||
--buildtype release --strip -Db_lto=true \
|
||||
-Dcompile_server=false \
|
||||
@@ -131,9 +131,9 @@ dist-win64: build-server build-win64
|
||||
cp app/prebuilt-deps/data/libusb-1.0.26/MinGW-x64/msys-usb-1.0.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
|
||||
|
||||
zip-win32: dist-win32
|
||||
cd "$(DIST)/$(WIN32_TARGET_DIR)"; \
|
||||
zip -r "../$(WIN32_TARGET)" .
|
||||
cd "$(DIST)"; \
|
||||
zip -r "$(WIN32_TARGET)" "$(WIN32_TARGET_DIR)"
|
||||
|
||||
zip-win64: dist-win64
|
||||
cd "$(DIST)/$(WIN64_TARGET_DIR)"; \
|
||||
zip -r "../$(WIN64_TARGET)" .
|
||||
cd "$(DIST)"; \
|
||||
zip -r "$(WIN64_TARGET)" "$(WIN64_TARGET_DIR)"
|
||||
|
||||
@@ -19,7 +19,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
|
||||
apply from: "$project.rootDir/config/android-checkstyle.gradle"
|
||||
|
||||
@@ -16,6 +16,10 @@ public class Controller {
|
||||
|
||||
private static final int DEFAULT_DEVICE_ID = 0;
|
||||
|
||||
// control_msg.h values of the pointerId field in inject_touch_event message
|
||||
private static final int POINTER_ID_MOUSE = -1;
|
||||
private static final int POINTER_ID_VIRTUAL_MOUSE = -3;
|
||||
|
||||
private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
private final Device device;
|
||||
@@ -194,7 +198,19 @@ public class Controller {
|
||||
pointer.setPressure(pressure);
|
||||
pointer.setUp(action == MotionEvent.ACTION_UP);
|
||||
|
||||
int source;
|
||||
int pointerCount = pointersState.update(pointerProperties, pointerCoords);
|
||||
if (pointerId == POINTER_ID_MOUSE || pointerId == POINTER_ID_VIRTUAL_MOUSE) {
|
||||
// real mouse event (forced by the client when --forward-on-click)
|
||||
pointerProperties[pointerIndex].toolType = MotionEvent.TOOL_TYPE_MOUSE;
|
||||
source = InputDevice.SOURCE_MOUSE;
|
||||
} else {
|
||||
// POINTER_ID_GENERIC_FINGER, POINTER_ID_VIRTUAL_FINGER or real touch from device
|
||||
pointerProperties[pointerIndex].toolType = MotionEvent.TOOL_TYPE_FINGER;
|
||||
source = InputDevice.SOURCE_TOUCHSCREEN;
|
||||
// Buttons must not be set for touch events
|
||||
buttons = 0;
|
||||
}
|
||||
|
||||
if (pointerCount == 1) {
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
@@ -209,14 +225,6 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Right-click and middle-click only work if the source is a mouse
|
||||
boolean nonPrimaryButtonPressed = (buttons & ~MotionEvent.BUTTON_PRIMARY) != 0;
|
||||
int source = nonPrimaryButtonPressed ? InputDevice.SOURCE_MOUSE : InputDevice.SOURCE_TOUCHSCREEN;
|
||||
if (source != InputDevice.SOURCE_MOUSE) {
|
||||
// Buttons must not be set for touch events
|
||||
buttons = 0;
|
||||
}
|
||||
|
||||
MotionEvent event = MotionEvent
|
||||
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEFAULT_DEVICE_ID, 0, source,
|
||||
0);
|
||||
|
||||
@@ -109,8 +109,9 @@ public class ClipboardManager {
|
||||
method.invoke(manager, listener, ServiceManager.PACKAGE_NAME);
|
||||
} else if (alternativeMethod) {
|
||||
method.invoke(manager, listener, ServiceManager.PACKAGE_NAME, null, ServiceManager.USER_ID);
|
||||
} else
|
||||
} else {
|
||||
method.invoke(manager, listener, ServiceManager.PACKAGE_NAME, ServiceManager.USER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private Method getAddPrimaryClipChangedListener() throws NoSuchMethodException {
|
||||
|
||||
Reference in New Issue
Block a user