Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

1package com.genymobile.scrcpy;
2
3import android.media.MediaCodec;
4
5import java.io.FileDescriptor;
6import java.io.IOException;
7import java.nio.ByteBuffer;
8
9public final class Streamer {
10
11 private static final long PACKET_FLAG_CONFIG = 1L << 63;
12 private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
13
14 private static final long AOPUSHDR = 0x5244485355504F41L; // "AOPUSHDR" in ASCII (little-endian)
15
16 private final FileDescriptor fd;
17 private final Codec codec;
18 private final boolean sendCodecMeta;
19 private final boolean sendFrameMeta;
20
…lines 21–115 unchanged (95 lines)
116 //
117 // <https://developer.android.com/reference/android/media/MediaCodec#CSD>
118
119 if (buffer.remaining() < 16) {
120 throw new IOException("Not enough data in OPUS config packet");
121 }
122
123 long id = buffer.getLong();
124 if (id != AOPUSHDR) {
125 throw new IOException("OPUS header not found");
126 }
127
128 long sizeLong = buffer.getLong();
129 if (sizeLong < 0 || sizeLong >= 0x7FFFFFFF) {
130 throw new IOException("Invalid block size in OPUS header: " + sizeLong);
131 }
132
…lines 133–142 unchanged (10 lines)

After

1package com.genymobile.scrcpy;
2
3import android.media.MediaCodec;
4
5import java.io.FileDescriptor;
6import java.io.IOException;
7import java.nio.ByteBuffer;
8import java.util.Arrays;
9
10public final class Streamer {
11
12 private static final long PACKET_FLAG_CONFIG = 1L << 63;
13 private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
14
15 private final FileDescriptor fd;
16 private final Codec codec;
17 private final boolean sendCodecMeta;
18 private final boolean sendFrameMeta;
19
20 private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
…lines 21–114 unchanged (94 lines)
115 //
116 // <https://developer.android.com/reference/android/media/MediaCodec#CSD>
117
118 if (buffer.remaining() < 16) {
119 throw new IOException("Not enough data in OPUS config packet");
120 }
121
122 final byte[] opusHeaderId = {'A', 'O', 'P', 'U', 'S', 'H', 'D', 'R'};
123 byte[] idBuffer = new byte[8];
124 buffer.get(idBuffer);
125 if (!Arrays.equals(idBuffer, opusHeaderId)) {
126 throw new IOException("OPUS header not found");
127 }
128
129 // The size is in native byte-order
130 long sizeLong = buffer.getLong();
131 if (sizeLong < 0 || sizeLong >= 0x7FFFFFFF) {
132 throw new IOException("Invalid block size in OPUS header: " + sizeLong);
133 }
134
135 int size = (int) sizeLong;
…lines 136–144 unchanged (9 lines)

Before

program
package_declaration
package "package"
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "android"
. "."
identifier "media"
. "."
identifier "MediaCodec"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "FileDescriptor"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "nio"
. "."
identifier "ByteBuffer"
; ";"
class_declaration
modifiers
public "public"
final "final"
class "class"
identifier "Streamer"
class_body
{ "{"
field_declaration
modifiers
private "private"
static "static"
final "final"
integral_type
long "long"
variable_declarator
identifier "PACKET_FLAG_CONFIG"
= "="
binary_expression
decimal_integer_literal "1L"
<< "<<"
decimal_integer_literal "63"
; ";"
field_declaration
modifiers
private "private"
static "static"
final "final"
integral_type
long "long"
variable_declarator
identifier "PACKET_FLAG_KEY_FRAME"
= "="
binary_expression
decimal_integer_literal "1L"
<< "<<"
decimal_integer_literal "62"
; ";"
field_declaration
modifiers
private "private"
static "static"
final "final"
integral_type
long "long"
variable_declarator
identifier "AOPUSHDR"
= "="
hex_integer_literal "0x5244485355504F41L"
; ";"
line_comment "// \"AOPUSHDR\" in ASCII (little-endian)"
field_declaration
modifiers
private "private"
final "final"
type_identifier "FileDescriptor"
variable_declarator
identifier "fd"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Codec"
variable_declarator
identifier "codec"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "sendCodecMeta"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "sendFrameMeta"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "ByteBuffer"
variable_declarator
identifier "headerBuffer"
= "="
method_invocation
identifier "ByteBuffer"
. "."
identifier "allocate"
argument_list
( "("
decimal_integer_literal "12"
) ")"
; ";"
constructor_declaration (+61 nodes collapsed)
method_declaration
modifiers
public "public"
type_identifier "Codec"
identifier "getCodec"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "codec"
; ";"
} "}"
method_declaration (+74 nodes collapsed)
method_declaration (+109 nodes collapsed)
method_declaration (+77 nodes collapsed)
method_declaration (+99 nodes collapsed)
method_declaration (+93 nodes collapsed)
method_declaration (+132 nodes collapsed)
method_declaration
modifiers
private "private"
static "static"
void_type "void"
identifier "fixOpusConfigPacket"
formal_parameters
( "("
formal_parameter
type_identifier "ByteBuffer"
identifier "buffer"
) ")"
throws
throws "throws"
type_identifier "IOException"
block
{ "{"
line_comment "// Here is an example of the config packet received for an O"...
line_comment "//"
line_comment "// 00000000 41 4f 50 55 53 48 44 52 13 00 00 00 00 00 00 0"...
line_comment "// -------------- BELOW IS THE PART WE MUST PUT AS EXTRADATA"...
line_comment "// 00000010 4f 70 75 73 48 65 61 64 01 01 38 01 80 bb 00 0"...
line_comment "// 00000020 00 00 00 "...
line_comment "// ---------------------------------------------------------"...
line_comment "// 00000020 41 4f 50 55 53 44 4c 59 08 00 00 00 0"...
line_comment "// 00000030 00 00 00 a0 2e 63 00 00 00 00 00 41 4f 50 55 5"...
line_comment "// 00000040 50 52 4c 08 00 00 00 00 00 00 00 00 b4 c4 04 0"...
line_comment "// 00000050 00 00 00 "...
line_comment "//"
line_comment "// Each \"section\" is prefixed by a 64-bit ID and a 64-bit le"...
line_comment "//"
line_comment "// <https://developer.android.com/reference/android/media/Me"...
if_statement (+31 nodes collapsed)
local_variable_declaration
integral_type
long "long"
variable_declarator
identifier "id"
= "="
method_invocation
identifier "buffer"
. "."
identifier "getLong"
argument_list
( "("
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "id"
!= "!="
identifier "AOPUSHDR"
) ")"
block
{ "{"
throw_statement
throw "throw"
object_creation_expression
new "new"
type_identifier "IOException"
argument_list
( "("
string_literal
" "\""
string_fragment "OPUS header not found"
" "\""
) ")"
; ";"
} "}"
local_variable_declaration
integral_type
long "long"
variable_declarator
identifier "sizeLong"
= "="
method_invocation
identifier "buffer"
. "."
identifier "getLong"
argument_list
( "("
) ")"
; ";"
if_statement (+34 nodes collapsed)
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "size"
= "="
cast_expression
( "("
integral_type
int "int"
) ")"
identifier "sizeLong"
; ";"
if_statement (+40 nodes collapsed)
line_comment "// Set the buffer to point to the OPUS header slice"
expression_statement
method_invocation
identifier "buffer"
. "."
identifier "limit"
argument_list
( "("
binary_expression
method_invocation
identifier "buffer"
. "."
identifier "position"
argument_list
( "("
) ")"
+ "+"
identifier "size"
) ")"
; ";"
} "}"
} "}"

After

program
package_declaration
package "package"
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "android"
. "."
identifier "media"
. "."
identifier "MediaCodec"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "FileDescriptor"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "nio"
. "."
identifier "ByteBuffer"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Arrays"
; ";"
class_declaration
modifiers
public "public"
final "final"
class "class"
identifier "Streamer"
class_body
{ "{"
field_declaration
modifiers
private "private"
static "static"
final "final"
integral_type
long "long"
variable_declarator
identifier "PACKET_FLAG_CONFIG"
= "="
binary_expression
decimal_integer_literal "1L"
<< "<<"
decimal_integer_literal "63"
; ";"
field_declaration
modifiers
private "private"
static "static"
final "final"
integral_type
long "long"
variable_declarator
identifier "PACKET_FLAG_KEY_FRAME"
= "="
binary_expression
decimal_integer_literal "1L"
<< "<<"
decimal_integer_literal "62"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "FileDescriptor"
variable_declarator
identifier "fd"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Codec"
variable_declarator
identifier "codec"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "sendCodecMeta"
; ";"
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "sendFrameMeta"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "ByteBuffer"
variable_declarator
identifier "headerBuffer"
= "="
method_invocation
identifier "ByteBuffer"
. "."
identifier "allocate"
argument_list
( "("
decimal_integer_literal "12"
) ")"
; ";"
constructor_declaration (+61 nodes collapsed)
method_declaration
modifiers
public "public"
type_identifier "Codec"
identifier "getCodec"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "codec"
; ";"
} "}"
method_declaration (+74 nodes collapsed)
method_declaration (+109 nodes collapsed)
method_declaration (+77 nodes collapsed)
method_declaration (+99 nodes collapsed)
method_declaration (+93 nodes collapsed)
method_declaration (+132 nodes collapsed)
method_declaration
modifiers
private "private"
static "static"
void_type "void"
identifier "fixOpusConfigPacket"
formal_parameters
( "("
formal_parameter
type_identifier "ByteBuffer"
identifier "buffer"
) ")"
throws
throws "throws"
type_identifier "IOException"
block
{ "{"
line_comment "// Here is an example of the config packet received for an O"...
line_comment "//"
line_comment "// 00000000 41 4f 50 55 53 48 44 52 13 00 00 00 00 00 00 0"...
line_comment "// -------------- BELOW IS THE PART WE MUST PUT AS EXTRADATA"...
line_comment "// 00000010 4f 70 75 73 48 65 61 64 01 01 38 01 80 bb 00 0"...
line_comment "// 00000020 00 00 00 "...
line_comment "// ---------------------------------------------------------"...
line_comment "// 00000020 41 4f 50 55 53 44 4c 59 08 00 00 00 0"...
line_comment "// 00000030 00 00 00 a0 2e 63 00 00 00 00 00 41 4f 50 55 5"...
line_comment "// 00000040 50 52 4c 08 00 00 00 00 00 00 00 00 b4 c4 04 0"...
line_comment "// 00000050 00 00 00 "...
line_comment "//"
line_comment "// Each \"section\" is prefixed by a 64-bit ID and a 64-bit le"...
line_comment "//"
line_comment "// <https://developer.android.com/reference/android/media/Me"...
if_statement (+31 nodes collapsed)
local_variable_declaration
modifiers
final "final"
array_type
integral_type
byte "byte"
dimensions
[ "["
] "]"
variable_declarator
identifier "opusHeaderId"
= "="
array_initializer
{ "{"
character_literal "'A'"
, ","
character_literal "'O'"
, ","
character_literal "'P'"
, ","
character_literal "'U'"
, ","
character_literal "'S'"
, ","
character_literal "'H'"
, ","
character_literal "'D'"
, ","
character_literal "'R'"
} "}"
; ";"
local_variable_declaration
array_type
integral_type
byte "byte"
dimensions
[ "["
] "]"
variable_declarator
identifier "idBuffer"
= "="
array_creation_expression
new "new"
integral_type
byte "byte"
dimensions_expr
[ "["
decimal_integer_literal "8"
] "]"
; ";"
expression_statement
method_invocation
identifier "buffer"
. "."
identifier "get"
argument_list
( "("
identifier "idBuffer"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
unary_expression
! "!"
method_invocation
identifier "Arrays"
. "."
identifier "equals"
argument_list
( "("
identifier "idBuffer"
, ","
identifier "opusHeaderId"
) ")"
) ")"
block
{ "{"
throw_statement
throw "throw"
object_creation_expression
new "new"
type_identifier "IOException"
argument_list
( "("
string_literal
" "\""
string_fragment "OPUS header not found"
" "\""
) ")"
; ";"
} "}"
line_comment "// The size is in native byte-order"
local_variable_declaration
integral_type
long "long"
variable_declarator
identifier "sizeLong"
= "="
method_invocation
identifier "buffer"
. "."
identifier "getLong"
argument_list
( "("
) ")"
; ";"
if_statement (+34 nodes collapsed)
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "size"
= "="
cast_expression
( "("
integral_type
int "int"
) ")"
identifier "sizeLong"
; ";"
if_statement (+40 nodes collapsed)
line_comment "// Set the buffer to point to the OPUS header slice"
expression_statement
method_invocation
identifier "buffer"
. "."
identifier "limit"
argument_list
( "("
binary_expression
method_invocation
identifier "buffer"
. "."
identifier "position"
argument_list
( "("
) ")"
+ "+"
identifier "size"
) ")"
; ";"
} "}"
} "}"