Compare commits

..

3 Commits

Author SHA1 Message Date
John Veness
1407f00a4a Fix typos/grammar issues in README
PR #3174 <https://github.com/Genymobile/scrcpy/pull/3174>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-04-10 14:09:36 +02:00
e1e0
7b7cfc3a3e Fix reference to FAQ in README
PR #3065 <https://github.com/Genymobile/scrcpy/pull/3065>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-04-10 13:57:44 +02:00
IskandarMa
2edc73e4b8 Improve README.zh-Hans.md
Fix misleading zoom instruction, which gave opposite action steps.

PR #3126 <https://github.com/Genymobile/scrcpy/pull/3126>

Signed-off-by: Romain Vimont <rom@rom1v.com>
2022-03-25 08:38:58 +01:00
15 changed files with 49 additions and 176 deletions

View File

@@ -190,7 +190,7 @@ scrcpy --max-size 1024
scrcpy -m 1024 # short version
```
The other dimension is computed to that the device aspect ratio is preserved.
The other dimension is computed so that the device aspect ratio is preserved.
That way, a device in 1920×1080 will be mirrored at 1024×576.
@@ -789,7 +789,7 @@ break non-ASCII content.
**WARNING:** Pasting the computer clipboard to the device (either via
<kbd>Ctrl</kbd>+<kbd>v</kbd> or <kbd>MOD</kbd>+<kbd>v</kbd>) copies the content
into the device clipboard. As a consequence, any Android application could read
its content. You should avoid to paste sensitive content (like passwords) that
its content. You should avoid pasting sensitive content (like passwords) that
way.
Some devices do not behave as expected when setting the device clipboard
@@ -838,7 +838,7 @@ scrcpy -K # short version
If it fails for some reason (for example because the device is not connected via
USB), it automatically fallbacks to the default mode (with a log in the
console). This allows to use the same command line options when connected over
console). This allows using the same command line options when connected over
USB and TCP/IP.
In this mode, raw key events (scancodes) are sent to the device, independently
@@ -1062,7 +1062,7 @@ _³4th and 5th mouse buttons, if your mouse has them._
_⁴For react-native apps in development, `MENU` triggers development menu._
_⁵Only on Android >= 7._
Shortcuts with repeated keys are executted by releasing and pressing the key a
Shortcuts with repeated keys are executed by releasing and pressing the key a
second time. For example, to execute "Expand settings panel":
1. Press and keep pressing <kbd>MOD</kbd>.
@@ -1105,7 +1105,7 @@ See [BUILD].
## Common issues
See the [FAQ].md).
See the [FAQ].
[FAQ]: FAQ.md

View File

@@ -704,11 +704,11 @@ scrcpy --disable-screensaver
#### 双指缩放
模拟“双指缩放”:<kbd>Ctrl</kbd>+_按住并移动鼠标_。
模拟“双指缩放”:<kbd>Ctrl</kbd>+_按下并拖动鼠标_。
更准确的说,在按住鼠标左键时按住 <kbd>Ctrl</kbd>。直到松开鼠标左键,所有鼠标移动将以屏幕中心为原点,缩放或旋转内容 (如果应用支持)。
按住 <kbd>Ctrl</kbd> 时按下鼠标左键,直到松开鼠标左键前,移动鼠标会使屏幕内容相对于屏幕中心进行缩放或旋转 (如果应用支持)。
实际上_scrcpy_ 会在关于屏幕中心对称的位置上用“虚拟手指”发出触摸事件。
具体来说_scrcpy_ 会在鼠标位置,以及鼠标以屏幕中心镜像的位置分别生成触摸事件。
#### 物理键盘模拟 (HID)

View File

@@ -355,12 +355,6 @@ Set the initial window height.
Default is 0 (automatic).
.SH EXIT STATUS
.B scrcpy
will exit with code 0 on normal program termination. If an initial
connection cannot be established, the exit code 1 will be returned. If the
device disconnects while a session is active, exit code 2 will be returned.
.SH SHORTCUTS
In the following list, MOD is the shortcut modifier. By default, it's (left)

View File

@@ -80,11 +80,6 @@ struct sc_envvar {
const char *text;
};
struct sc_exit_status {
unsigned value;
const char *text;
};
struct sc_getopt_adapter {
char *optstring;
struct option *longopts;
@@ -667,22 +662,7 @@ static const struct sc_envvar envvars[] = {
{
.name = "SCRCPY_SERVER_PATH",
.text = "Path to the server binary",
},
};
static const struct sc_exit_status exit_statuses[] = {
{
.value = 0,
.text = "Normal program termination",
},
{
.value = 1,
.text = "Start failure",
},
{
.value = 2,
.text = "Device disconnected while running",
},
}
};
static char *
@@ -921,25 +901,6 @@ print_envvar(const struct sc_envvar *envvar, unsigned cols) {
free(text);
}
static void
print_exit_status(const struct sc_exit_status *status, unsigned cols) {
assert(cols > 8); // sc_str_wrap_lines() requires indent < columns
assert(status->text);
// The text starts at 9: 4 ident spaces, 3 chars for numeric value, 2 spaces
char *text = sc_str_wrap_lines(status->text, cols, 9);
if (!text) {
printf("<ERROR>\n");
return;
}
assert(strlen(text) >= 9); // Contains at least the initial identation
// text + 9 to remove the initial indentation
printf(" %3d %s\n", status->value, text + 9);
free(text);
}
void
scrcpy_print_usage(const char *arg0) {
#define SC_TERM_COLS_DEFAULT 80
@@ -978,11 +939,6 @@ scrcpy_print_usage(const char *arg0) {
for (size_t i = 0; i < ARRAY_LEN(envvars); ++i) {
print_envvar(&envvars[i], cols);
}
printf("\nExit status:\n\n");
for (size_t i = 0; i < ARRAY_LEN(exit_statuses); ++i) {
print_exit_status(&exit_statuses[i], cols);
}
}
static bool

View File

@@ -2,7 +2,6 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/pixdesc.h>
#include "events.h"
#include "video_buffer.h"
@@ -12,39 +11,6 @@
/** Downcast packet_sink to decoder */
#define DOWNCAST(SINK) container_of(SINK, struct sc_decoder, packet_sink)
static int hw_decoder_init(struct sc_decoder *decoder, const enum AVHWDeviceType type)
{
int err = 0;
AVBufferRef *hw_device_ctx;
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type,
NULL, NULL, 0)) < 0) {
LOGE("Failed to create specified HW device.");
return err;
}
decoder->codec_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
return err;
}
static enum AVPixelFormat get_hw_format(AVCodecContext *ctx,
const enum AVPixelFormat *pix_fmts)
{
(void) ctx;
const enum AVPixelFormat *p;
LOGD("== get_hw_format ==");
for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
LOGD("==== %s (%d)", av_get_pix_fmt_name(*p), *p);
if (*p == AV_PIX_FMT_VAAPI)
return *p;
}
LOGE("Failed to get HW surface format.");
return AV_PIX_FMT_NONE;
}
static void
sc_decoder_close_first_sinks(struct sc_decoder *decoder, unsigned count) {
while (count) {
@@ -82,10 +48,6 @@ sc_decoder_open(struct sc_decoder *decoder, const AVCodec *codec) {
decoder->codec_ctx->flags |= AV_CODEC_FLAG_LOW_DELAY;
int r = hw_decoder_init(decoder, AV_HWDEVICE_TYPE_VAAPI);
assert(!r);
decoder->codec_ctx->get_format = get_hw_format;
if (avcodec_open2(decoder->codec_ctx, codec, NULL) < 0) {
LOGE("Could not open codec");
avcodec_free_context(&decoder->codec_ctx);
@@ -100,9 +62,6 @@ sc_decoder_open(struct sc_decoder *decoder, const AVCodec *codec) {
return false;
}
decoder->hw_frame = av_frame_alloc();
assert(decoder->hw_frame);
if (!sc_decoder_open_sinks(decoder)) {
LOGE("Could not open decoder sinks");
av_frame_free(&decoder->frame);
@@ -117,7 +76,6 @@ sc_decoder_open(struct sc_decoder *decoder, const AVCodec *codec) {
static void
sc_decoder_close(struct sc_decoder *decoder) {
sc_decoder_close_sinks(decoder);
av_frame_free(&decoder->hw_frame);
av_frame_free(&decoder->frame);
avcodec_close(decoder->codec_ctx);
avcodec_free_context(&decoder->codec_ctx);
@@ -149,26 +107,15 @@ sc_decoder_push(struct sc_decoder *decoder, const AVPacket *packet) {
LOGE("Could not send video packet: %d", ret);
return false;
}
ret = avcodec_receive_frame(decoder->codec_ctx, decoder->hw_frame);
ret = avcodec_receive_frame(decoder->codec_ctx, decoder->frame);
if (!ret) {
// a frame was received
sc_tick t = sc_tick_now();
ret = av_hwframe_transfer_data(decoder->frame, decoder->hw_frame, 0);
if (ret < 0) {
LOGE("HWFRAME transfer fail");
return false;
}
LOGD("av_hwframe_transfer_data: %ld", sc_tick_now() - t);
bool ok = push_frame_to_sinks(decoder, decoder->frame);
// A frame lost should not make the whole pipeline fail. The error, if
// any, is already logged.
(void) ok;
av_frame_unref(decoder->frame);
av_frame_unref(decoder->hw_frame);
} else if (ret != AVERROR(EAGAIN)) {
LOGE("Could not receive video frame: %d", ret);
return false;

View File

@@ -19,7 +19,6 @@ struct sc_decoder {
AVCodecContext *codec_ctx;
AVFrame *frame;
AVFrame *hw_frame;
};
void

View File

@@ -40,19 +40,19 @@ main(int argc, char *argv[]) {
#endif
if (!scrcpy_parse_args(&args, argc, argv)) {
return SCRCPY_EXIT_FAILURE;
return 1;
}
sc_set_log_level(args.opts.log_level);
if (args.help) {
scrcpy_print_usage(argv[0]);
return SCRCPY_EXIT_SUCCESS;
return 0;
}
if (args.version) {
scrcpy_print_version();
return SCRCPY_EXIT_SUCCESS;
return 0;
}
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
@@ -66,17 +66,17 @@ main(int argc, char *argv[]) {
#endif
if (avformat_network_init()) {
return SCRCPY_EXIT_FAILURE;
return 1;
}
#ifdef HAVE_USB
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts)
: scrcpy(&args.opts);
bool ok = args.opts.otg ? scrcpy_otg(&args.opts)
: scrcpy(&args.opts);
#else
enum scrcpy_exit_code ret = scrcpy(&args.opts);
bool ok = scrcpy(&args.opts);
#endif
avformat_network_deinit(); // ignore failure
return ret;
return ok ? 0 : 1;
}

View File

@@ -149,41 +149,38 @@ sdl_configure(bool display, bool disable_screensaver) {
}
}
static enum scrcpy_exit_code
static bool
event_loop(struct scrcpy *s) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case EVENT_STREAM_STOPPED:
LOGW("Device disconnected");
return SCRCPY_EXIT_DISCONNECTED;
return false;
case SDL_QUIT:
LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS;
return true;
default:
sc_screen_handle_event(&s->screen, &event);
break;
}
}
return SCRCPY_EXIT_FAILURE;
return false;
}
// Return true on success, false on error
static bool
await_for_server(bool *connected) {
await_for_server(void) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
LOGD("User requested to quit");
*connected = false;
return true;
return false;
case EVENT_SERVER_CONNECTION_FAILED:
LOGE("Server connection failed");
return false;
case EVENT_SERVER_CONNECTED:
LOGD("Server connected");
*connected = true;
return true;
default:
break;
@@ -265,7 +262,7 @@ sc_server_on_disconnected(struct sc_server *server, void *userdata) {
// event
}
enum scrcpy_exit_code
bool
scrcpy(struct scrcpy_options *options) {
static struct scrcpy scrcpy;
struct scrcpy *s = &scrcpy;
@@ -273,12 +270,12 @@ scrcpy(struct scrcpy_options *options) {
// Minimal SDL initialization
if (SDL_Init(SDL_INIT_EVENTS)) {
LOGE("Could not initialize SDL: %s", SDL_GetError());
return SCRCPY_EXIT_FAILURE;
return false;
}
atexit(SDL_Quit);
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE;
bool ret = false;
bool server_started = false;
bool file_pusher_initialized = false;
@@ -332,7 +329,7 @@ scrcpy(struct scrcpy_options *options) {
.on_disconnected = sc_server_on_disconnected,
};
if (!sc_server_init(&s->server, &params, &cbs, NULL)) {
return SCRCPY_EXIT_FAILURE;
return false;
}
if (!sc_server_start(&s->server)) {
@@ -354,14 +351,7 @@ scrcpy(struct scrcpy_options *options) {
sdl_configure(options->display, options->disable_screensaver);
// Await for server without blocking Ctrl+C handling
bool connected;
if (!await_for_server(&connected)) {
goto end;
}
if (!connected) {
// This is not an error, user requested to quit
ret = SCRCPY_EXIT_SUCCESS;
if (!await_for_server()) {
goto end;
}

View File

@@ -6,18 +6,7 @@
#include <stdbool.h>
#include "options.h"
enum scrcpy_exit_code {
// Normal program termination
SCRCPY_EXIT_SUCCESS,
// No connection could be established
SCRCPY_EXIT_FAILURE,
// Device was disconnected while running
SCRCPY_EXIT_DISCONNECTED,
};
enum scrcpy_exit_code
bool
scrcpy(struct scrcpy_options *options);
#endif

View File

@@ -244,7 +244,7 @@ static inline SDL_Texture *
create_texture(struct sc_screen *screen) {
SDL_Renderer *renderer = screen->renderer;
struct sc_size size = screen->frame_size;
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_NV12,
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12,
SDL_TEXTUREACCESS_STREAMING,
size.width, size.height);
if (!texture) {
@@ -711,11 +711,10 @@ prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
// write the frame into the texture
static void
update_texture(struct sc_screen *screen, const AVFrame *frame) {
// SDL_UpdateYUVTexture(screen->texture, NULL,
// frame->data[0], frame->linesize[0],
// frame->data[1], frame->linesize[1],
// frame->data[2], frame->linesize[2]);
SDL_UpdateTexture(screen->texture, NULL, frame->data[0], frame->linesize[0]);
SDL_UpdateYUVTexture(screen->texture, NULL,
frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1],
frame->data[2], frame->linesize[2]);
if (screen->mipmaps) {
SDL_GL_BindTexture(screen->texture, NULL, NULL);

View File

@@ -340,7 +340,7 @@ push_mod_lock_state(struct sc_hid_keyboard *kb, uint16_t mods_state) {
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mod lock state)");
LOGW("Could request HID event");
return false;
}
@@ -382,7 +382,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,
if (!sc_aoa_push_hid_event(kb->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (key)");
LOGW("Could request HID event");
}
}
}

View File

@@ -181,7 +181,7 @@ sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse motion)");
LOGW("Could request HID event");
}
}
@@ -203,7 +203,7 @@ sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse click)");
LOGW("Could request HID event");
}
}
@@ -228,7 +228,7 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
if (!sc_aoa_push_hid_event(mouse->aoa, &hid_event)) {
sc_hid_event_destroy(&hid_event);
LOGW("Could not request HID event (mouse scroll)");
LOGW("Could request HID event");
}
}

View File

@@ -29,26 +29,26 @@ sc_usb_on_disconnected(struct sc_usb *usb, void *userdata) {
}
}
static enum scrcpy_exit_code
static bool
event_loop(struct scrcpy_otg *s) {
SDL_Event event;
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case EVENT_USB_DEVICE_DISCONNECTED:
LOGW("Device disconnected");
return SCRCPY_EXIT_DISCONNECTED;
return false;
case SDL_QUIT:
LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS;
return true;
default:
sc_screen_otg_handle_event(&s->screen_otg, &event);
break;
}
}
return SCRCPY_EXIT_FAILURE;
return false;
}
enum scrcpy_exit_code
bool
scrcpy_otg(struct scrcpy_options *options) {
static struct scrcpy_otg scrcpy_otg;
struct scrcpy_otg *s = &scrcpy_otg;
@@ -67,7 +67,7 @@ scrcpy_otg(struct scrcpy_options *options) {
LOGW("Could not enable mouse focus clickthrough");
}
enum scrcpy_exit_code ret = SCRCPY_EXIT_FAILURE;
bool ret = false;
struct sc_hid_keyboard *keyboard = NULL;
struct sc_hid_mouse *mouse = NULL;
@@ -90,7 +90,7 @@ scrcpy_otg(struct scrcpy_options *options) {
};
bool ok = sc_usb_init(&s->usb);
if (!ok) {
return SCRCPY_EXIT_FAILURE;
return false;
}
struct sc_usb_device usb_device;

View File

@@ -3,10 +3,10 @@
#include "common.h"
#include <stdbool.h>
#include "options.h"
#include "scrcpy.h"
enum scrcpy_exit_code
bool
scrcpy_otg(struct scrcpy_options *options);
#endif

View File

@@ -15,7 +15,6 @@ read_string(libusb_device_handle *handle, uint8_t desc_index) {
(unsigned char *) buffer,
sizeof(buffer));
if (result < 0) {
LOGD("Read string: libusb error: %s", libusb_strerror(result));
return NULL;
}