@ -26,7 +26,7 @@ public class ScreenEncoder implements Device.RotationListener, AsyncProcessor {
private static final int [ ] MAX_SIZE_FALLBACK = { 2560 , 1920 , 1600 , 1280 , 1024 , 800 } ;
private static final int [ ] MAX_SIZE_FALLBACK = { 2560 , 1920 , 1600 , 1280 , 1024 , 800 } ;
private static final int MAX_CONSECUTIVE_ERRORS = 3 ;
private static final int MAX_CONSECUTIVE_ERRORS = 3 ;
private final AtomicBoolean r otationChanged = new AtomicBoolean ( ) ;
private final AtomicBoolean r esetCapture = new AtomicBoolean ( ) ;
private final Device device ;
private final Device device ;
private final Streamer streamer ;
private final Streamer streamer ;
@ -55,11 +55,11 @@ public class ScreenEncoder implements Device.RotationListener, AsyncProcessor {
@Override
@Override
public void onRotationChanged ( int rotation ) {
public void onRotationChanged ( int rotation ) {
r otationChanged . set ( true ) ;
r esetCapture . set ( true ) ;
}
}
private boolean consumeR otationChang e( ) {
private boolean consumeR esetCaptur e( ) {
return r otationChanged . getAndSet ( false ) ;
return r esetCapture . getAndSet ( false ) ;
}
}
private void streamScreen ( ) throws IOException , ConfigurationException {
private void streamScreen ( ) throws IOException , ConfigurationException {
@ -169,14 +169,14 @@ public class ScreenEncoder implements Device.RotationListener, AsyncProcessor {
boolean alive = true ;
boolean alive = true ;
MediaCodec . BufferInfo bufferInfo = new MediaCodec . BufferInfo ( ) ;
MediaCodec . BufferInfo bufferInfo = new MediaCodec . BufferInfo ( ) ;
while ( ! consumeR otationChang e( ) & & ! eof ) {
while ( ! consumeR esetCaptur e( ) & & ! eof ) {
if ( stopped . get ( ) ) {
if ( stopped . get ( ) ) {
alive = false ;
alive = false ;
break ;
break ;
}
}
int outputBufferId = codec . dequeueOutputBuffer ( bufferInfo , - 1 ) ;
int outputBufferId = codec . dequeueOutputBuffer ( bufferInfo , - 1 ) ;
try {
try {
if ( consumeR otationChang e( ) ) {
if ( consumeR esetCaptur e( ) ) {
// must restart encoding with new size
// must restart encoding with new size
break ;
break ;
}
}