Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward audio #3757

Merged
merged 118 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
a206150
Simplify libusb prebuilt scripts
rom1v Feb 27, 2023
0fc62bf
Use minimal prebuilt FFmpeg for Windows
rom1v Feb 27, 2023
9d60d78
Upgrade FFmpeg (6.0) for Windows
rom1v Feb 28, 2023
f30fd96
Upgrade FFmpeg custom builds for Windows
rom1v Mar 3, 2023
10e8295
Move FFmpeg callback initialization
rom1v Feb 23, 2023
e30e692
Print FFmpeg logs
rom1v Feb 23, 2023
c78254f
Split server stop() and join()
rom1v Feb 22, 2023
9f8e96e
Fix --no-clipboard-autosync bash completion
rom1v Feb 22, 2023
b43938f
Do not print stacktraces when unnecessary
rom1v Feb 19, 2023
fa99763
Fix --encoder documentation
rom1v Feb 19, 2023
181fb55
Change PTS origin type from uint64_t to int64_t
rom1v Feb 17, 2023
b6744e7
Move pts_origin to a local variable
rom1v Feb 17, 2023
db5751a
Move previous packet to a local variable
rom1v Feb 17, 2023
b1b33e3
Report recorder errors
rom1v Feb 10, 2023
fb29135
Initialize recorder fields from init()
rom1v Feb 14, 2023
6b5dfef
Inline packet_sink impl in recorder
rom1v Feb 14, 2023
a039124
Open recording file from the recorder thread
rom1v Feb 14, 2023
3c40777
Add start() function for recorder
rom1v Feb 23, 2023
4b246cd
Move last packet recording
rom1v Feb 18, 2023
f9efe48
Refactor recorder logic
rom1v Feb 18, 2023
ef6a3b9
Reorder initialization
rom1v Feb 23, 2023
5b2ec66
Simplify error handling on socket creation
rom1v Feb 3, 2023
ae29e5b
Use VideoStreamer directly from ScreenEncoder
rom1v Feb 6, 2023
5162820
Write streamer header from ScreenEncoder
rom1v Feb 6, 2023
ae9b08b
Move screen encoder initialization
rom1v Feb 6, 2023
c226797
Pass all args to ScreenEncoder constructor
rom1v Feb 6, 2023
10ce0f3
Make streamer independent of codec type
rom1v Feb 6, 2023
90d88a6
Rename "codec" variable to "mediaCodec"
rom1v Feb 19, 2023
10ef8da
Improve error message for unknown encoder
rom1v Feb 19, 2023
a5541b3
Add a fake Android Context
yume-chan Jan 27, 2023
9a815ce
Use AttributionSource from FakeContext
rom1v Jan 31, 2023
820189b
Use PACKAGE_NAME from FakeContext
rom1v Jan 31, 2023
42285ae
Use ROOT_UID from FakeContext
rom1v Feb 26, 2023
84ba643
Use shell package name for workarounds
rom1v Jan 31, 2023
8487ddb
Use FakeContext for Application instance
rom1v Jan 31, 2023
3cf03e4
Add --no-audio option
yume-chan Feb 3, 2023
e841241
Add a new socket for audio stream
yume-chan Feb 3, 2023
11d3261
Capture device audio
yume-chan Jan 27, 2023
464a35b
Make streamer more generic
rom1v Mar 3, 2023
5eed2c5
Encode recorded audio on the device
rom1v Feb 7, 2023
7cf5cf5
Use a streamer to send the audio stream
rom1v Feb 9, 2023
15556d1
Extract OPUS extradata
rom1v Feb 18, 2023
e987678
Rename demuxer to video_demuxer
rom1v Feb 6, 2023
d499f89
Give a name to demuxer instances
rom1v Feb 18, 2023
f60b576
Force --no-audio if no display and no recording
rom1v Mar 2, 2023
de430bc
Add an audio demuxer
rom1v Feb 6, 2023
609b098
Do not merge config audio packets
rom1v Feb 18, 2023
3d29f6e
Rename video-specific variables in recorder
rom1v Feb 15, 2023
7de0622
Add audio recording support
rom1v Feb 18, 2023
13a3395
Disable audio on initialization error
rom1v Feb 18, 2023
80c0780
Disable audio before Android 11
rom1v Feb 19, 2023
17d5301
Record at least video packets on stop
rom1v Feb 18, 2023
a1802da
Remove default bit-rate on client side
rom1v Feb 18, 2023
cee40ca
Rename --codec to --video-codec
rom1v Feb 20, 2023
9087e85
Rename --bit-rate to --video-bit-rate
rom1v Feb 21, 2023
31555fa
Rename --codec-options to --video-codec-options
rom1v Feb 21, 2023
e694619
Rename --encoder to --video-encoder
rom1v Feb 22, 2023
8e640dc
Disable MethodLength checkstyle on createOptions()
rom1v Feb 19, 2023
0870b8c
Add --audio-bit-rate
rom1v Feb 18, 2023
839b842
Add --audio-codec
rom1v Feb 18, 2023
4601735
Add support for AAC audio codec
rom1v Feb 18, 2023
58cf8e5
Extract application of codec options
rom1v Feb 19, 2023
b03c864
Add --audio-codec-options
rom1v Feb 22, 2023
6f332a2
Extract unknown encoder error message
rom1v Feb 19, 2023
f9960e9
Add --audio-encoder
rom1v Feb 19, 2023
b7e5284
Move await_for_server() logs
rom1v Feb 22, 2023
9196dc1
Add --list-encoders
rom1v Feb 22, 2023
50d56a9
Quit on audio configuration failure
rom1v Feb 23, 2023
2596ca0
Move log message helpers to LogUtils
rom1v Feb 23, 2023
b65301f
Add --list-displays
rom1v Feb 23, 2023
a205ff6
Log display sizes in display list
rom1v Feb 23, 2023
99837fa
Rename decoder to video_decoder
rom1v Feb 24, 2023
05f0e35
Give a name to decoder instances
rom1v Feb 24, 2023
e22660d
Add an audio decoder
rom1v Feb 24, 2023
619730e
Pass AVCodecContext to frame sinks
rom1v Feb 25, 2023
20d41fd
Introduce bytebuf util
rom1v Feb 25, 2023
b60a8aa
Add two-step write feature to bytebuf
rom1v Feb 25, 2023
de40cac
Add workaround to capture audio on Android 11
yume-chan Jan 29, 2023
c1528cd
Add --require-audio
rom1v Feb 28, 2023
6e05d70
Call avcodec_receive_frame() in a loop
rom1v Feb 28, 2023
6dceb32
Add compat for reallocarray()
rom1v Feb 28, 2023
c735b8c
Use reallocarray() in sc_vector
rom1v Feb 28, 2023
457385d
Add sc_allocarray() util
rom1v Feb 28, 2023
33df484
Introduce VecDeque
rom1v Feb 28, 2023
efc1574
Use VecDeque in recorder
rom1v Mar 1, 2023
f25a67f
Use VecDeque in video_buffer
rom1v Mar 1, 2023
4d989de
Use VecDeque in controller
rom1v Mar 1, 2023
a0a65b3
Use VecDeque in file_pusher
rom1v Mar 1, 2023
f978e4d
Use VecDeque in aoa_hid
rom1v Mar 1, 2023
3383106
Remove cbuf
rom1v Mar 1, 2023
6f38c63
Remove sc_queue
rom1v Mar 1, 2023
a370334
Fix possible race condition on video_buffer end
rom1v Mar 1, 2023
ad94ccc
Stop the video buffer on error
rom1v Mar 1, 2023
4540f1d
Report video buffer downstream errors
rom1v Mar 1, 2023
6379c08
Fix buffering pts conversion
rom1v Mar 9, 2023
f410f2b
Extract sc_delay_buffer
rom1v Mar 1, 2023
c39054a
Introduce packet source trait
rom1v Mar 2, 2023
f3197e1
Use packet source trait in demuxer
rom1v Mar 2, 2023
6543964
Introduce frame source trait
rom1v Mar 2, 2023
974227a
Use frame source trait in decoder
rom1v Mar 2, 2023
1230149
Use delay buffer as a frame source/sink
rom1v Mar 2, 2023
48a537d
Remove anonymous struct in delay buffer
rom1v Mar 2, 2023
9b3ca20
Accept clock estimation with a single point
rom1v Mar 2, 2023
e1333f6
Optionally do not delay the first frame
rom1v Mar 2, 2023
fbe0f95
Add audio player
rom1v Mar 2, 2023
d66b0b3
Add compat support for FFmpeg < 5.1
rom1v Feb 27, 2023
df55bc2
Add --audio-buffer
rom1v Mar 2, 2023
02dd1be
Stop on decoder frame push error
rom1v Mar 2, 2023
65cc9d7
Extract audio capture
rom1v Mar 3, 2023
dc228ea
Extract async processor interface
rom1v Mar 3, 2023
66b6c06
Add raw audio recorder
rom1v Mar 3, 2023
d2952c7
Add --audio-codec=raw option
rom1v Mar 3, 2023
7da45c2
Warn on ignored audio options
rom1v Mar 3, 2023
bb56472
Print server logs and newline in one call
rom1v Mar 8, 2023
4a25f3e
Print info logs to stdout
rom1v Mar 8, 2023
5ee59e0
Add thread priority API
rom1v Mar 8, 2023
aa450ff
Increase audio thread priority
rom1v Mar 8, 2023
408f458
Decrease recorder thread priority
rom1v Mar 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ First, you need to install the required packages:
sudo apt install ffmpeg libsdl2-2.0-0 adb wget \
gcc git pkg-config meson ninja-build libsdl2-dev \
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
libusb-1.0-0 libusb-1.0-0-dev
libswresample-dev libusb-1.0-0 libusb-1.0-0-dev
```

Then clone the repo and execute the installation script
Expand Down Expand Up @@ -94,7 +94,7 @@ sudo apt install ffmpeg libsdl2-2.0-0 adb libusb-1.0-0
# client build dependencies
sudo apt install gcc git pkg-config meson ninja-build libsdl2-dev \
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev \
libusb-1.0-0-dev
libswresample-dev libusb-1.0-0-dev

# server build dependencies
sudo apt install openjdk-11-jdk
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ preserved. That way, a device in 1920×1080 will be mirrored at 1024×576.
The default bit-rate is 8 Mbps. To change the video bitrate (e.g. to 2 Mbps):

```bash
scrcpy --bit-rate=2M
scrcpy --video-bit-rate=2M
scrcpy -b 2M # short version
```

Expand Down Expand Up @@ -258,9 +258,9 @@ The video codec can be selected. The possible values are `h264` (default),
`h265` and `av1`:

```bash
scrcpy --codec=h264 # default
scrcpy --codec=h265
scrcpy --codec=av1
scrcpy --video-codec=h264 # default
scrcpy --video-codec=h265
scrcpy --video-codec=av1
```


Expand All @@ -270,15 +270,13 @@ Some devices have more than one encoder for a specific codec, and some of them
may cause issues or crash. It is possible to select a different encoder:

```bash
scrcpy --encoder=OMX.qcom.video.encoder.avc
scrcpy --video-encoder=OMX.qcom.video.encoder.avc
```

To list the available encoders, you can pass an invalid encoder name; the
error will give the available encoders:
To list the available encoders:

```bash
scrcpy --encoder=_ # for the default codec
scrcpy --codec=h265 --encoder=_ # for a specific codec
scrcpy --list-encoders
```

### Capture
Expand Down Expand Up @@ -444,7 +442,7 @@ none found, try running `adb disconnect`, and then run those two commands again.
It may be useful to decrease the bit-rate and the resolution:

```bash
scrcpy --bit-rate=2M --max-size=800
scrcpy --video-bit-rate=2M --max-size=800
scrcpy -b2M -m800 # short version
```

Expand Down Expand Up @@ -720,7 +718,7 @@ scrcpy --display=1
The list of display ids can be retrieved by:

```bash
adb shell dumpsys display # search "mDisplayId=" in the output
scrcpy --list-displays
```

The secondary display may only be controlled if the device runs at least Android
Expand Down
26 changes: 19 additions & 7 deletions app/data/bash-completion/scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ _scrcpy() {
local cur prev words cword
local opts="
--always-on-top
-b --bit-rate=
--codec=
--codec-options=
--audio-bit-rate=
--audio-codec=
--audio-codec-options=
--audio-encoder=
-b --video-bit-rate=
--crop=
-d --select-usb
--disable-screensaver
--display=
--display-buffer=
-e --select-tcpip
--encoder=
--force-adb-forward
--forward-all-clicks
-f --fullscreen
-K --hid-keyboard
-h --help
--legacy-paste
--list-displays
--list-encoders
--lock-video-orientation
--lock-video-orientation=
--max-fps=
-M --hid-mouse
-m --max-size=
--no-audio
--no-cleanup
--no-clipboard-on-error
--no-clipboard-autosync
--no-downsize-on-error
-n --no-control
-N --no-display
Expand All @@ -41,6 +45,7 @@ _scrcpy() {
-r --record=
--record-format=
--render-driver=
--require-audio
--rotation=
-s --serial=
--shortcut-mod=
Expand All @@ -54,6 +59,9 @@ _scrcpy() {
--v4l2-sink=
-V --verbosity=
-v --version
--video-codec=
--video-codec-options=
--video-encoder=
-w --stay-awake
--window-borderless
--window-title=
Expand All @@ -65,10 +73,14 @@ _scrcpy() {
_init_completion -s || return

case "$prev" in
--codec)
--video-codec)
COMPREPLY=($(compgen -W 'h264 h265 av1' -- "$cur"))
return
;;
--audio-codec)
COMPREPLY=($(compgen -W 'opus aac raw' -- "$cur"))
return
;;
--lock-video-orientation)
COMPREPLY=($(compgen -W 'unlocked initial 0 1 2 3' -- "$cur"))
return
Expand Down Expand Up @@ -103,7 +115,7 @@ _scrcpy() {
COMPREPLY=($(compgen -W "$("${ADB:-adb}" devices | awk '$2 == "device" {print $1}')" -- ${cur}))
return
;;
-b|--bit-rate \
-b|--video-bit-rate \
|--codec-options \
|--crop \
|--display \
Expand Down
16 changes: 12 additions & 4 deletions app/data/zsh-completion/_scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ local arguments

arguments=(
'--always-on-top[Make scrcpy window always on top \(above other windows\)]'
{-b,--bit-rate=}'[Encode the video at the given bit-rate]'
'--codec=[Select the video codec]:codec:(h264 h265 av1)'
'--codec-options=[Set a list of comma-separated key\:type=value options for the device encoder]'
'--audio-bit-rate=[Encode the audio at the given bit-rate]'
'--audio-codec=[Select the audio codec]:codec:(opus aac raw)'
'--audio-codec-options=[Set a list of comma-separated key\:type=value options for the device audio encoder]'
'--audio-encoder=[Use a specific MediaCodec audio encoder]'
{-b,--video-bit-rate=}'[Encode the video at the given bit-rate]'
'--crop=[\[width\:height\:x\:y\] Crop the device screen on the server]'
{-d,--select-usb}'[Use USB device]'
'--disable-screensaver[Disable screensaver while scrcpy is running]'
'--display=[Specify the display id to mirror]'
'--display-buffer=[Add a buffering delay \(in milliseconds\) before displaying]'
{-e,--select-tcpip}'[Use TCP/IP device]'
'--encoder=[Use a specific MediaCodec encoder \(must be a H.264 encoder\)]'
'--force-adb-forward[Do not attempt to use \"adb reverse\" to connect to the device]'
'--forward-all-clicks[Forward clicks to device]'
{-f,--fullscreen}'[Start in fullscreen]'
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
{-h,--help}'[Print the help]'
'--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]'
'--list-displays[List displays available on the device]'
'--list-encoders[List video and audio encoders available on the device]'
'--lock-video-orientation=[Lock video orientation]:orientation:(unlocked initial 0 1 2 3)'
'--max-fps=[Limit the frame rate of screen capture]'
{-M,--hid-mouse}'[Simulate a physical mouse by using HID over AOAv2]'
{-m,--max-size=}'[Limit both the width and height of the video to value]'
'--no-audio[Disable audio forwarding]'
'--no-cleanup[Disable device cleanup actions on exit]'
'--no-clipboard-autosync[Disable automatic clipboard synchronization]'
'--no-downsize-on-error[Disable lowering definition on MediaCodec error]'
Expand All @@ -47,6 +51,7 @@ arguments=(
{-r,--record=}'[Record screen to file]:record file:_files'
'--record-format=[Force recording format]:format:(mp4 mkv)'
'--render-driver=[Request SDL to use the given render driver]:driver name:(direct3d opengl opengles2 opengles metal software)'
'--require-audio=[Make scrcpy fail if audio is enabled but does not work]'
'--rotation=[Set the initial display rotation]:rotation values:(0 1 2 3)'
{-s,--serial=}'[The device serial number \(mandatory for multiple devices only\)]:serial:($("${ADB-adb}" devices | awk '\''$2 == "device" {print $1}'\''))'
'--shortcut-mod=[\[key1,key2+key3,...\] Specify the modifiers to use for scrcpy shortcuts]:shortcut mod:(lctrl rctrl lalt ralt lsuper rsuper)'
Expand All @@ -59,6 +64,9 @@ arguments=(
'--v4l2-sink=[\[\/dev\/videoN\] Output to v4l2loopback device]'
{-V,--verbosity=}'[Set the log level]:verbosity:(verbose debug info warn error)'
{-v,--version}'[Print the version of scrcpy]'
'--video-codec=[Select the video codec]:codec:(h264 h265 av1)'
'--video-codec-options=[Set a list of comma-separated key\:type=value options for the device video encoder]'
'--video-encoder=[Use a specific MediaCodec video encoder]'
{-w,--stay-awake}'[Keep the device on while scrcpy is running, when the device is plugged in]'
'--window-borderless[Disable window decorations \(display borderless window\)]'
'--window-title=[Set a custom window title]'
Expand Down
43 changes: 22 additions & 21 deletions app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ src = [
'src/adb/adb_device.c',
'src/adb/adb_parser.c',
'src/adb/adb_tunnel.c',
'src/audio_player.c',
'src/cli.c',
'src/clock.c',
'src/compat.c',
'src/control_msg.c',
'src/controller.c',
'src/decoder.c',
'src/delay_buffer.c',
'src/demuxer.c',
'src/device_msg.c',
'src/icon.c',
Expand All @@ -28,12 +30,16 @@ src = [
'src/screen.c',
'src/server.c',
'src/version.c',
'src/video_buffer.c',
'src/trait/frame_source.c',
'src/trait/packet_source.c',
'src/util/acksync.c',
'src/util/average.c',
'src/util/bytebuf.c',
'src/util/file.c',
'src/util/intmap.c',
'src/util/intr.c',
'src/util/log.c',
'src/util/memory.c',
'src/util/net.c',
'src/util/net_intr.c',
'src/util/process.c',
Expand Down Expand Up @@ -99,6 +105,7 @@ if not crossbuild_windows
dependency('libavformat', version: '>= 57.33'),
dependency('libavcodec', version: '>= 57.37'),
dependency('libavutil'),
dependency('libswresample'),
dependency('sdl2', version: '>= 2.0.5'),
]

Expand Down Expand Up @@ -129,24 +136,19 @@ else
ffmpeg_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin'
ffmpeg_include_dir = 'prebuilt-deps/data/' + prebuilt_ffmpeg + '/include'

# ffmpeg versions are different for win32 and win64 builds
ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec')
ffmpeg_avformat = meson.get_cross_property('ffmpeg_avformat')
ffmpeg_avutil = meson.get_cross_property('ffmpeg_avutil')

ffmpeg = declare_dependency(
dependencies: [
cc.find_library(ffmpeg_avcodec, dirs: ffmpeg_bin_dir),
cc.find_library(ffmpeg_avformat, dirs: ffmpeg_bin_dir),
cc.find_library(ffmpeg_avutil, dirs: ffmpeg_bin_dir),
cc.find_library('avcodec-60', dirs: ffmpeg_bin_dir),
cc.find_library('avformat-60', dirs: ffmpeg_bin_dir),
cc.find_library('avutil-58', dirs: ffmpeg_bin_dir),
cc.find_library('swresample-4', dirs: ffmpeg_bin_dir),
],
include_directories: include_directories(ffmpeg_include_dir)
)

prebuilt_libusb = meson.get_cross_property('prebuilt_libusb')
prebuilt_libusb_root = meson.get_cross_property('prebuilt_libusb_root')
libusb_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_libusb
libusb_include_dir = 'prebuilt-deps/data/' + prebuilt_libusb_root + '/include'
libusb_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_libusb + '/bin'
libusb_include_dir = 'prebuilt-deps/data/' + prebuilt_libusb + '/include'

libusb = declare_dependency(
dependencies: [
Expand Down Expand Up @@ -174,6 +176,7 @@ check_functions = [
'vasprintf',
'nrand48',
'jrand48',
'reallocarray',
]

foreach f : check_functions
Expand Down Expand Up @@ -201,10 +204,6 @@ conf.set('PORTABLE', get_option('portable'))
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')

# the default video bitrate, in bits/second
# overridden by option --bit-rate
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps

# run a server debugger and wait for a client to be attached
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))

Expand Down Expand Up @@ -264,8 +263,9 @@ if get_option('buildtype') == 'debug'
['test_binary', [
'tests/test_binary.c',
]],
['test_cbuf', [
'tests/test_cbuf.c',
['test_bytebuf', [
'tests/test_bytebuf.c',
'src/util/bytebuf.c',
]],
['test_cli', [
'tests/test_cli.c',
Expand All @@ -291,9 +291,6 @@ if get_option('buildtype') == 'debug'
'tests/test_device_msg_deserialize.c',
'src/device_msg.c',
]],
['test_queue', [
'tests/test_queue.c',
]],
['test_strbuf', [
'tests/test_strbuf.c',
'src/util/strbuf.c',
Expand All @@ -303,6 +300,10 @@ if get_option('buildtype') == 'debug'
'src/util/str.c',
'src/util/strbuf.c',
]],
['test_vecdeque', [
'tests/test_vecdeque.c',
'src/util/memory.c',
]],
['test_vector', [
'tests/test_vector.c',
]],
Expand Down
45 changes: 0 additions & 45 deletions app/prebuilt-deps/prepare-ffmpeg-win32.sh

This file was deleted.

Loading