Commit Graph

24 Commits (d706c5df3991a35b5f98058bfd2f640bcef05ea7)

Author SHA1 Message Date
Ivan Gorinov d706c5df39 Enable video output file, with pts set by server 6 years ago
Romain Vimont 5c739874a4 Fix memory leak on error
On decode error, unref the packet.
6 years ago
Romain Vimont 536b31829a Separate multi-words filenames by '_'
Rename foobar.ext to foo_bar.ext.

<https://github.com/Genymobile/scrcpy/pull/226#discussion_r209454865>
6 years ago
Romain Vimont 35298bb0c6 Process the last video frame
On H.264 stream EOF, the eof_reached flag is set, but av_read_frame()
still provides a frame, so check the flag only afterwards.

As a side-effect, it also fixes a memory leak (the very last packet was
not unref).
6 years ago
Romain Vimont 73c332e3e4 Unref last packet on exit 6 years ago
Romain Vimont f9562f537a Unref the packet on error
Do not leak the packet data on error.
6 years ago
Romain Vimont a34fbd23e9 Do not leak the packet data
Oops! The content of the packets were never freed.
6 years ago
Romain Vimont 82b4acee73 Do not fail on EAGAIN
A call to avcodec_receive_frame() may return AVERROR(EAGAIN) if more
input is required. This is not an error, do not fail.
6 years ago
Romain Vimont 84ad6633a6 Move the new avcodec implementation before the old
The API to decode the video frames is different depending on the
libavcodec version.

Move the new API usage to the #if-block.
6 years ago
Romain Vimont 1b0cea61a5 Do not use return code for thread run function
The decoder sometimes returned a non-zero value on error, but not on
every path.

Since we never use the value, always return 0 at the end (like in the
controller).
6 years ago
Romain Vimont 27b9159b07 Cleanup old code comment 6 years ago
Romain Vimont 9b056f5091 Replace SDL_net by custom implementation
SDL_net is not very suitable for scrcpy.

For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it
by calling many SDL_Net-specific functions to make it blocking.

But above all, SDLNet_TCP_Open() is a server socket only when no IP is
provided; otherwise, it's a client socket. Therefore, it is not possible
to create a server socket bound to localhost, so it accepts connections
from anywhere.

This is a problem for scrcpy, because on start, the application listens
for nearly 1 second until it accepts the first connection, supposedly
from the device. If someone on the local network manages to connect to
the server socket first, then they can stream arbitrary H.264 video.
This may be troublesome, for example during a public presentation ;-)

Provide our own simplified API (net.h) instead, implemented for the
different platforms.
6 years ago
Romain Vimont bf41e5479b Improve decoder stopped event
The syntax was correct, but less readable, and it unnecessarily zeroed
the fields other than "type".

Create the event properly, from a separate method.
6 years ago
Romain Vimont 3ed80a1fac Define macros wrappers for logs
Use macros to wrap SDL_Log* functions with the "application" category.
6 years ago
Romain Vimont 6fe65d9f5c Log with category APPLICATION
All our logs should use APPLICATION category. The logs for other
categories are not printed by default under the "critical" level.
6 years ago
Romain Vimont 523097eadf Provide decoder_init()
Expose an initializer so that the caller does not have to guess what
fields must be initialized.
6 years ago
Romain Vimont 2fdc368c41 Do not try to decode video when EOF is reached
When the video stream socket is closed and read_packey() returns -1,
av_read_frame() still returns 0.

To detect EOF, check the flag eof_reached in the AVIOContext.

This avoids garbage errors on closing.
6 years ago
Romain Vimont 127e56780a Fix deadlock on exit if SKIP_FRAMES disabled
On exit, the renderer will not consume frames anymore, so signal the
condition variable to wake up the decoder.
6 years ago
Romain Vimont 629c296207 Move frame swapping logic to frame.c
Expose frames_offer_decoded_frame() and frames_consume_rendered_frame()
so that callers are not exposed to frame swapping (between the decoding
and rendering frames) details.
6 years ago
Romain Vimont 8d30d40b79 Make SKIP_FRAMES a compilation flag
The skip_frames flag was a non-configurable runtime flag. Since it is
not exposed to the user, there is no need for a (possible) runtime cost.

For testing purpose, we still want it to be configurable, so make it a
compilation flag.
6 years ago
Romain Vimont b9c9466d65 Handle condition variable failure
Add condition variables function wrappers to handle unexpected failure.
6 years ago
Romain Vimont c4266e487b Rename (un)lock_mutex to mutex_(un)lock
For consistency, rename lock_mutex and unlock_mutex to mutex_lock and
mutex_unlock.
6 years ago
Romain Vimont 37d88b8a6a Use SDL_bool return type instead of int
Many functions returned an int to indicate their success. For clarity,
use SDL_bool instead.
6 years ago
Romain Vimont 54d9148a36 Initial commit
Start a new clean history from here.
7 years ago