diff --git a/gen/com/limelight/R.java b/gen/com/limelight/R.java index d88967d1..f06ecb19 100644 --- a/gen/com/limelight/R.java +++ b/gen/com/limelight/R.java @@ -46,8 +46,6 @@ or to a theme attribute in the form "?[package:][type:]na } public static final class string { public static final int app_name=0x7f060000; - public static final int dummy_button=0x7f060002; - public static final int dummy_content=0x7f060003; public static final int title_activity_game=0x7f060001; } public static final class style { diff --git a/jni/ffmpeg/Android.mk b/jni/ffmpeg/Android.mk index 0fb797a8..cf55ef1b 100644 --- a/jni/ffmpeg/Android.mk +++ b/jni/ffmpeg/Android.mk @@ -2,36 +2,36 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= libavcodec -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavcodec.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavcodec-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavformat -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavformat.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavformat-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libswscale -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libswscale.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libswscale-2.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavutil -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavutil.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavutil-52.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavfilter -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavfilter.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libavfilter-3.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libwsresample -LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libswresample.so +LOCAL_SRC_FILES:= $(TARGET_ARCH_ABI)/lib/libswresample-0.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) diff --git a/libs/armeabi-v7a/libavcodec.so b/jni/ffmpeg/armeabi-v7a/lib/libavcodec-55.so similarity index 78% rename from libs/armeabi-v7a/libavcodec.so rename to jni/ffmpeg/armeabi-v7a/lib/libavcodec-55.so index 54dd1d29..004b5d3a 100644 Binary files a/libs/armeabi-v7a/libavcodec.so and b/jni/ffmpeg/armeabi-v7a/lib/libavcodec-55.so differ diff --git a/jni/ffmpeg/armeabi-v7a/lib/libavcodec.so b/jni/ffmpeg/armeabi-v7a/lib/libavcodec.so.55 similarity index 100% rename from jni/ffmpeg/armeabi-v7a/lib/libavcodec.so rename to jni/ffmpeg/armeabi-v7a/lib/libavcodec.so.55 diff --git a/jni/ffmpeg/armeabi-v7a/lib/libavfilter.so b/jni/ffmpeg/armeabi-v7a/lib/libavfilter-3.so similarity index 61% rename from jni/ffmpeg/armeabi-v7a/lib/libavfilter.so rename to jni/ffmpeg/armeabi-v7a/lib/libavfilter-3.so index fd2ff204..9b959f69 100644 Binary files a/jni/ffmpeg/armeabi-v7a/lib/libavfilter.so and b/jni/ffmpeg/armeabi-v7a/lib/libavfilter-3.so differ diff --git a/jni/ffmpeg/armeabi-v7a/lib/libavformat.so b/jni/ffmpeg/armeabi-v7a/lib/libavformat-55.so similarity index 97% rename from jni/ffmpeg/armeabi-v7a/lib/libavformat.so rename to jni/ffmpeg/armeabi-v7a/lib/libavformat-55.so index c2a0f527..734adc59 100644 Binary files a/jni/ffmpeg/armeabi-v7a/lib/libavformat.so and b/jni/ffmpeg/armeabi-v7a/lib/libavformat-55.so differ diff --git a/jni/ffmpeg/armeabi-v7a/lib/libavutil.so b/jni/ffmpeg/armeabi-v7a/lib/libavutil-52.so similarity index 69% rename from jni/ffmpeg/armeabi-v7a/lib/libavutil.so rename to jni/ffmpeg/armeabi-v7a/lib/libavutil-52.so index 37c7faec..f84b4c39 100644 Binary files a/jni/ffmpeg/armeabi-v7a/lib/libavutil.so and b/jni/ffmpeg/armeabi-v7a/lib/libavutil-52.so differ diff --git a/libs/armeabi-v7a/libswresample.so b/jni/ffmpeg/armeabi-v7a/lib/libswresample-0.so similarity index 53% rename from libs/armeabi-v7a/libswresample.so rename to jni/ffmpeg/armeabi-v7a/lib/libswresample-0.so index 8a6b4a94..18f46691 100644 Binary files a/libs/armeabi-v7a/libswresample.so and b/jni/ffmpeg/armeabi-v7a/lib/libswresample-0.so differ diff --git a/jni/ffmpeg/armeabi-v7a/lib/libswscale.so b/jni/ffmpeg/armeabi-v7a/lib/libswscale-2.so similarity index 98% rename from jni/ffmpeg/armeabi-v7a/lib/libswscale.so rename to jni/ffmpeg/armeabi-v7a/lib/libswscale-2.so index fc929776..7db66866 100644 Binary files a/jni/ffmpeg/armeabi-v7a/lib/libswscale.so and b/jni/ffmpeg/armeabi-v7a/lib/libswscale-2.so differ diff --git a/jni/ffmpeg/armeabi/lib/libavcodec.so b/jni/ffmpeg/armeabi/lib/libavcodec-55.so similarity index 79% rename from jni/ffmpeg/armeabi/lib/libavcodec.so rename to jni/ffmpeg/armeabi/lib/libavcodec-55.so index dde555ca..fb6e938a 100644 Binary files a/jni/ffmpeg/armeabi/lib/libavcodec.so and b/jni/ffmpeg/armeabi/lib/libavcodec-55.so differ diff --git a/jni/ffmpeg/armeabi/lib/libavfilter.so b/jni/ffmpeg/armeabi/lib/libavfilter-3.so similarity index 62% rename from jni/ffmpeg/armeabi/lib/libavfilter.so rename to jni/ffmpeg/armeabi/lib/libavfilter-3.so index 7e628c45..a1268d12 100644 Binary files a/jni/ffmpeg/armeabi/lib/libavfilter.so and b/jni/ffmpeg/armeabi/lib/libavfilter-3.so differ diff --git a/jni/ffmpeg/armeabi/lib/libavformat.so b/jni/ffmpeg/armeabi/lib/libavformat-55.so similarity index 97% rename from jni/ffmpeg/armeabi/lib/libavformat.so rename to jni/ffmpeg/armeabi/lib/libavformat-55.so index 589639ec..8913a266 100644 Binary files a/jni/ffmpeg/armeabi/lib/libavformat.so and b/jni/ffmpeg/armeabi/lib/libavformat-55.so differ diff --git a/libs/armeabi/libavutil.so b/jni/ffmpeg/armeabi/lib/libavutil-52.so similarity index 71% rename from libs/armeabi/libavutil.so rename to jni/ffmpeg/armeabi/lib/libavutil-52.so index 08845c46..dd372cca 100644 Binary files a/libs/armeabi/libavutil.so and b/jni/ffmpeg/armeabi/lib/libavutil-52.so differ diff --git a/jni/ffmpeg/armeabi/lib/libswresample-0.so b/jni/ffmpeg/armeabi/lib/libswresample-0.so new file mode 100644 index 00000000..5e656eb8 Binary files /dev/null and b/jni/ffmpeg/armeabi/lib/libswresample-0.so differ diff --git a/jni/ffmpeg/armeabi/lib/libswresample.so b/jni/ffmpeg/armeabi/lib/libswresample.so deleted file mode 100644 index 619be481..00000000 Binary files a/jni/ffmpeg/armeabi/lib/libswresample.so and /dev/null differ diff --git a/libs/armeabi/libswscale.so b/jni/ffmpeg/armeabi/lib/libswscale-2.so similarity index 98% rename from libs/armeabi/libswscale.so rename to jni/ffmpeg/armeabi/lib/libswscale-2.so index 36713926..9aa1feb0 100644 Binary files a/libs/armeabi/libswscale.so and b/jni/ffmpeg/armeabi/lib/libswscale-2.so differ diff --git a/libs/x86/libavcodec.so b/jni/ffmpeg/x86/lib/libavcodec-55.so similarity index 99% rename from libs/x86/libavcodec.so rename to jni/ffmpeg/x86/lib/libavcodec-55.so index 1a9e0620..feeb9a55 100644 Binary files a/libs/x86/libavcodec.so and b/jni/ffmpeg/x86/lib/libavcodec-55.so differ diff --git a/libs/x86/libavfilter.so b/jni/ffmpeg/x86/lib/libavfilter-3.so similarity index 99% rename from libs/x86/libavfilter.so rename to jni/ffmpeg/x86/lib/libavfilter-3.so index 39b1a8da..2a524737 100644 Binary files a/libs/x86/libavfilter.so and b/jni/ffmpeg/x86/lib/libavfilter-3.so differ diff --git a/jni/ffmpeg/x86/lib/libavformat.so b/jni/ffmpeg/x86/lib/libavformat-55.so similarity index 99% rename from jni/ffmpeg/x86/lib/libavformat.so rename to jni/ffmpeg/x86/lib/libavformat-55.so index 113c9ba9..0d485957 100644 Binary files a/jni/ffmpeg/x86/lib/libavformat.so and b/jni/ffmpeg/x86/lib/libavformat-55.so differ diff --git a/libs/x86/libavutil.so b/jni/ffmpeg/x86/lib/libavutil-52.so similarity index 99% rename from libs/x86/libavutil.so rename to jni/ffmpeg/x86/lib/libavutil-52.so index 51e9ee58..c5ff25ce 100644 Binary files a/libs/x86/libavutil.so and b/jni/ffmpeg/x86/lib/libavutil-52.so differ diff --git a/jni/ffmpeg/x86/lib/libswresample.so b/jni/ffmpeg/x86/lib/libswresample-0.so similarity index 99% rename from jni/ffmpeg/x86/lib/libswresample.so rename to jni/ffmpeg/x86/lib/libswresample-0.so index bc6c9b78..6ca3c52e 100644 Binary files a/jni/ffmpeg/x86/lib/libswresample.so and b/jni/ffmpeg/x86/lib/libswresample-0.so differ diff --git a/jni/ffmpeg/x86/lib/libswscale.so b/jni/ffmpeg/x86/lib/libswscale-2.so similarity index 99% rename from jni/ffmpeg/x86/lib/libswscale.so rename to jni/ffmpeg/x86/lib/libswscale-2.so index 572cb5f4..d8a63469 100644 Binary files a/jni/ffmpeg/x86/lib/libswscale.so and b/jni/ffmpeg/x86/lib/libswscale-2.so differ diff --git a/libs/armeabi-v7a/libavcodec-55.so b/libs/armeabi-v7a/libavcodec-55.so new file mode 100644 index 00000000..004b5d3a Binary files /dev/null and b/libs/armeabi-v7a/libavcodec-55.so differ diff --git a/libs/armeabi-v7a/libavfilter.so b/libs/armeabi-v7a/libavfilter-3.so similarity index 61% rename from libs/armeabi-v7a/libavfilter.so rename to libs/armeabi-v7a/libavfilter-3.so index fd2ff204..9b959f69 100644 Binary files a/libs/armeabi-v7a/libavfilter.so and b/libs/armeabi-v7a/libavfilter-3.so differ diff --git a/libs/armeabi-v7a/libavformat.so b/libs/armeabi-v7a/libavformat-55.so similarity index 97% rename from libs/armeabi-v7a/libavformat.so rename to libs/armeabi-v7a/libavformat-55.so index c2a0f527..734adc59 100644 Binary files a/libs/armeabi-v7a/libavformat.so and b/libs/armeabi-v7a/libavformat-55.so differ diff --git a/libs/armeabi-v7a/libavutil.so b/libs/armeabi-v7a/libavutil-52.so similarity index 69% rename from libs/armeabi-v7a/libavutil.so rename to libs/armeabi-v7a/libavutil-52.so index 37c7faec..f84b4c39 100644 Binary files a/libs/armeabi-v7a/libavutil.so and b/libs/armeabi-v7a/libavutil-52.so differ diff --git a/libs/armeabi-v7a/libnv_av_dec.so b/libs/armeabi-v7a/libnv_av_dec.so index 49e54f7b..446df9e5 100644 Binary files a/libs/armeabi-v7a/libnv_av_dec.so and b/libs/armeabi-v7a/libnv_av_dec.so differ diff --git a/jni/ffmpeg/armeabi-v7a/lib/libswresample.so b/libs/armeabi-v7a/libswresample-0.so similarity index 53% rename from jni/ffmpeg/armeabi-v7a/lib/libswresample.so rename to libs/armeabi-v7a/libswresample-0.so index 8a6b4a94..18f46691 100644 Binary files a/jni/ffmpeg/armeabi-v7a/lib/libswresample.so and b/libs/armeabi-v7a/libswresample-0.so differ diff --git a/libs/armeabi-v7a/libswscale.so b/libs/armeabi-v7a/libswscale-2.so similarity index 98% rename from libs/armeabi-v7a/libswscale.so rename to libs/armeabi-v7a/libswscale-2.so index fc929776..7db66866 100644 Binary files a/libs/armeabi-v7a/libswscale.so and b/libs/armeabi-v7a/libswscale-2.so differ diff --git a/libs/armeabi/libavcodec.so b/libs/armeabi/libavcodec-55.so similarity index 79% rename from libs/armeabi/libavcodec.so rename to libs/armeabi/libavcodec-55.so index dde555ca..fb6e938a 100644 Binary files a/libs/armeabi/libavcodec.so and b/libs/armeabi/libavcodec-55.so differ diff --git a/libs/armeabi/libavfilter.so b/libs/armeabi/libavfilter-3.so similarity index 62% rename from libs/armeabi/libavfilter.so rename to libs/armeabi/libavfilter-3.so index 7e628c45..a1268d12 100644 Binary files a/libs/armeabi/libavfilter.so and b/libs/armeabi/libavfilter-3.so differ diff --git a/libs/armeabi/libavformat.so b/libs/armeabi/libavformat-55.so similarity index 97% rename from libs/armeabi/libavformat.so rename to libs/armeabi/libavformat-55.so index 589639ec..8913a266 100644 Binary files a/libs/armeabi/libavformat.so and b/libs/armeabi/libavformat-55.so differ diff --git a/jni/ffmpeg/armeabi/lib/libavutil.so b/libs/armeabi/libavutil-52.so similarity index 71% rename from jni/ffmpeg/armeabi/lib/libavutil.so rename to libs/armeabi/libavutil-52.so index 08845c46..dd372cca 100644 Binary files a/jni/ffmpeg/armeabi/lib/libavutil.so and b/libs/armeabi/libavutil-52.so differ diff --git a/libs/armeabi/libnv_av_dec.so b/libs/armeabi/libnv_av_dec.so index 01ebbb02..53c0a82e 100644 Binary files a/libs/armeabi/libnv_av_dec.so and b/libs/armeabi/libnv_av_dec.so differ diff --git a/libs/armeabi/libswresample-0.so b/libs/armeabi/libswresample-0.so new file mode 100644 index 00000000..5e656eb8 Binary files /dev/null and b/libs/armeabi/libswresample-0.so differ diff --git a/libs/armeabi/libswresample.so b/libs/armeabi/libswresample.so deleted file mode 100644 index 619be481..00000000 Binary files a/libs/armeabi/libswresample.so and /dev/null differ diff --git a/jni/ffmpeg/armeabi/lib/libswscale.so b/libs/armeabi/libswscale-2.so similarity index 98% rename from jni/ffmpeg/armeabi/lib/libswscale.so rename to libs/armeabi/libswscale-2.so index 36713926..9aa1feb0 100644 Binary files a/jni/ffmpeg/armeabi/lib/libswscale.so and b/libs/armeabi/libswscale-2.so differ diff --git a/jni/ffmpeg/x86/lib/libavcodec.so b/libs/x86/libavcodec-55.so similarity index 99% rename from jni/ffmpeg/x86/lib/libavcodec.so rename to libs/x86/libavcodec-55.so index 1a9e0620..feeb9a55 100644 Binary files a/jni/ffmpeg/x86/lib/libavcodec.so and b/libs/x86/libavcodec-55.so differ diff --git a/jni/ffmpeg/x86/lib/libavfilter.so b/libs/x86/libavfilter-3.so similarity index 99% rename from jni/ffmpeg/x86/lib/libavfilter.so rename to libs/x86/libavfilter-3.so index 39b1a8da..2a524737 100644 Binary files a/jni/ffmpeg/x86/lib/libavfilter.so and b/libs/x86/libavfilter-3.so differ diff --git a/libs/x86/libavformat.so b/libs/x86/libavformat-55.so similarity index 99% rename from libs/x86/libavformat.so rename to libs/x86/libavformat-55.so index 113c9ba9..0d485957 100644 Binary files a/libs/x86/libavformat.so and b/libs/x86/libavformat-55.so differ diff --git a/jni/ffmpeg/x86/lib/libavutil.so b/libs/x86/libavutil-52.so similarity index 99% rename from jni/ffmpeg/x86/lib/libavutil.so rename to libs/x86/libavutil-52.so index 51e9ee58..c5ff25ce 100644 Binary files a/jni/ffmpeg/x86/lib/libavutil.so and b/libs/x86/libavutil-52.so differ diff --git a/libs/x86/libnv_av_dec.so b/libs/x86/libnv_av_dec.so index 2dc3b8d8..2c709a7f 100644 Binary files a/libs/x86/libnv_av_dec.so and b/libs/x86/libnv_av_dec.so differ diff --git a/libs/x86/libswresample.so b/libs/x86/libswresample-0.so similarity index 99% rename from libs/x86/libswresample.so rename to libs/x86/libswresample-0.so index bc6c9b78..6ca3c52e 100644 Binary files a/libs/x86/libswresample.so and b/libs/x86/libswresample-0.so differ diff --git a/libs/x86/libswscale.so b/libs/x86/libswscale-2.so similarity index 99% rename from libs/x86/libswscale.so rename to libs/x86/libswscale-2.so index 572cb5f4..d8a63469 100644 Binary files a/libs/x86/libswscale.so and b/libs/x86/libswscale-2.so differ diff --git a/res/values/strings.xml b/res/values/strings.xml index fba8ffbf..08656313 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3,7 +3,5 @@ Limelight Game - Dummy Button - DUMMY\nCONTENT diff --git a/src/com/limelight/nvstream/NvVideoStream.java b/src/com/limelight/nvstream/NvVideoStream.java index 64b947db..0935f99d 100644 --- a/src/com/limelight/nvstream/NvVideoStream.java +++ b/src/com/limelight/nvstream/NvVideoStream.java @@ -6,7 +6,6 @@ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.Socket; import java.net.SocketException; -import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.concurrent.LinkedBlockingQueue; @@ -15,13 +14,13 @@ import com.limelight.nvstream.av.AvDecodeUnit; import com.limelight.nvstream.av.AvRtpPacket; import com.limelight.nvstream.av.video.AvVideoDepacketizer; import com.limelight.nvstream.av.video.AvVideoPacket; +import com.limelight.nvstream.av.video.CpuDecoderRenderer; +import com.limelight.nvstream.av.video.DecoderRenderer; +import com.limelight.nvstream.av.video.MediaCodecDecoderRenderer; import jlibrtp.Participant; import jlibrtp.RTPSession; -import android.media.MediaCodec; -import android.media.MediaCodec.BufferInfo; -import android.media.MediaFormat; import android.view.Surface; public class NvVideoStream { @@ -29,20 +28,18 @@ public class NvVideoStream { public static final int RTCP_PORT = 47999; public static final int FIRST_FRAME_PORT = 47996; - private ByteBuffer[] videoDecoderInputBuffers; - private MediaCodec videoDecoder; - private LinkedBlockingQueue packets = new LinkedBlockingQueue(); private RTPSession session; private DatagramSocket rtp, rtcp; private Socket firstFrameSocket; - private LinkedList threads = new LinkedList(); private AvVideoDepacketizer depacketizer = new AvVideoDepacketizer(); + private DecoderRenderer decrend; + private boolean aborting = false; public void abort() @@ -81,8 +78,8 @@ public class NvVideoStream { if (session != null) { //session.endSession(); } - if (videoDecoder != null) { - videoDecoder.release(); + if (decrend != null) { + decrend.release(); } threads.clear(); @@ -135,18 +132,23 @@ public class NvVideoStream { session.addParticipant(new Participant(host, RTP_PORT, RTCP_PORT)); } - public void setupDecoders(Surface surface) - { - videoDecoder = MediaCodec.createDecoderByType("video/avc"); - MediaFormat videoFormat = MediaFormat.createVideoFormat("video/avc", 1280, 720); - - videoDecoder.configure(videoFormat, surface, null, 0); - - videoDecoder.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); + public void setupDecoderRenderer(Surface renderTarget) { + boolean requiresCpuDecoding = true; - videoDecoder.start(); - - videoDecoderInputBuffers = videoDecoder.getInputBuffers(); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { + if (MediaCodecDecoderRenderer.hasWhitelistedDecoder()) { + requiresCpuDecoding = false; + } + } + + if (requiresCpuDecoding) { + decrend = new CpuDecoderRenderer(); + } + else { + decrend = new MediaCodecDecoderRenderer(); + } + + decrend.setup(1280, 720, renderTarget); } public void startVideoStream(final String host, final Surface surface) @@ -155,8 +157,8 @@ public class NvVideoStream { Thread t = new Thread() { @Override public void run() { - // Setup the decoder context - setupDecoders(surface); + // Setup the decoder and renderer + setupDecoderRenderer(surface); // Open RTP sockets and start session try { @@ -189,8 +191,7 @@ public class NvVideoStream { // Start decoding the data we're receiving startDecoderThread(); - // Render the frames that are coming out of the decoder - outputDisplayLoop(this); + decrend.start(); } }; threads.add(t); @@ -199,7 +200,6 @@ public class NvVideoStream { private void startDecoderThread() { - // Decoder thread Thread t = new Thread() { @Override public void run() { @@ -207,6 +207,7 @@ public class NvVideoStream { while (!isInterrupted()) { AvDecodeUnit du; + try { du = depacketizer.getNextDecodeUnit(); } catch (InterruptedException e) { @@ -214,46 +215,9 @@ public class NvVideoStream { return; } - switch (du.getType()) - { - case AvDecodeUnit.TYPE_H264: - { - // Wait for an input buffer or thread termination - while (!isInterrupted()) - { - int inputIndex = videoDecoder.dequeueInputBuffer(100); - if (inputIndex >= 0) - { - ByteBuffer buf = videoDecoderInputBuffers[inputIndex]; - - // Clear old input data - buf.clear(); - - // Copy data from our buffer list into the input buffer - for (AvByteBufferDescriptor desc : du.getBufferList()) - { - buf.put(desc.data, desc.offset, desc.length); - } - - depacketizer.releaseDecodeUnit(du); - - videoDecoder.queueInputBuffer(inputIndex, - 0, du.getDataLength(), - 0, du.getFlags()); - - break; - } - } - } - break; + decrend.submitDecodeUnit(du); - default: - { - System.err.println("Unknown decode unit type"); - abort(); - return; - } - } + depacketizer.releaseDecodeUnit(du); } } }; @@ -351,43 +315,4 @@ public class NvVideoStream { threads.add(t); t.start(); } - - private void outputDisplayLoop(Thread t) - { - long nextFrameTimeUs = 0; - while (!t.isInterrupted()) - { - BufferInfo info = new BufferInfo(); - int outIndex = videoDecoder.dequeueOutputBuffer(info, 100); - switch (outIndex) { - case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED: - System.out.println("Output buffers changed"); - break; - case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED: - System.out.println("Output format changed"); - System.out.println("New output Format: " + videoDecoder.getOutputFormat()); - break; - default: - break; - } - if (outIndex >= 0) { - boolean render = false; - - if (currentTimeUs() >= nextFrameTimeUs) { - render = true; - nextFrameTimeUs = computePresentationTime(60); - } - - videoDecoder.releaseOutputBuffer(outIndex, render); - } - } - } - - private static long currentTimeUs() { - return System.nanoTime() / 1000; - } - - private long computePresentationTime(int frameRate) { - return currentTimeUs() + (1000000 / frameRate); - } } diff --git a/src/com/limelight/nvstream/av/video/CpuDecoderRenderer.java b/src/com/limelight/nvstream/av/video/CpuDecoderRenderer.java new file mode 100644 index 00000000..5df40a86 --- /dev/null +++ b/src/com/limelight/nvstream/av/video/CpuDecoderRenderer.java @@ -0,0 +1,51 @@ +package com.limelight.nvstream.av.video; + +import java.nio.ByteBuffer; + +import android.view.Surface; + +import com.limelight.nvstream.av.AvByteBufferDescriptor; +import com.limelight.nvstream.av.AvDecodeUnit; + +public class CpuDecoderRenderer implements DecoderRenderer { + + private Surface renderTarget; + private ByteBuffer decoderBuffer; + private Thread rendererThread; + + @Override + public void setup(int width, int height, Surface renderTarget) { + this.renderTarget = renderTarget; + + int err = AvcDecoder.init(width, height); + if (err != 0) { + //throw new IllegalStateException("AVC decoder initialization failure: "+err); + } + + decoderBuffer = ByteBuffer.allocate(128*1024); + } + + @Override + public void start() { + } + + @Override + public void stop() { + } + + @Override + public void release() { + AvcDecoder.destroy(); + } + + @Override + public void submitDecodeUnit(AvDecodeUnit decodeUnit) { + decoderBuffer.clear(); + + for (AvByteBufferDescriptor bbd : decodeUnit.getBufferList()) { + decoderBuffer.put(bbd.data, bbd.offset, bbd.length); + } + + //AvcDecoder.decode(decoderBuffer.array(), 0, decodeUnit.getDataLength()); + } +} diff --git a/src/com/limelight/nvstream/av/video/DecoderRenderer.java b/src/com/limelight/nvstream/av/video/DecoderRenderer.java new file mode 100644 index 00000000..18b6c273 --- /dev/null +++ b/src/com/limelight/nvstream/av/video/DecoderRenderer.java @@ -0,0 +1,17 @@ +package com.limelight.nvstream.av.video; + +import com.limelight.nvstream.av.AvDecodeUnit; + +import android.view.Surface; + +public interface DecoderRenderer { + public void setup(int width, int height, Surface renderTarget); + + public void start(); + + public void stop(); + + public void release(); + + public void submitDecodeUnit(AvDecodeUnit decodeUnit); +} diff --git a/src/com/limelight/nvstream/av/video/MediaCodecDecoderRenderer.java b/src/com/limelight/nvstream/av/video/MediaCodecDecoderRenderer.java new file mode 100644 index 00000000..13551875 --- /dev/null +++ b/src/com/limelight/nvstream/av/video/MediaCodecDecoderRenderer.java @@ -0,0 +1,143 @@ +package com.limelight.nvstream.av.video; + +import java.nio.ByteBuffer; + +import com.limelight.nvstream.av.AvByteBufferDescriptor; +import com.limelight.nvstream.av.AvDecodeUnit; + +import android.annotation.TargetApi; +import android.media.MediaCodec; +import android.media.MediaCodecInfo; +import android.media.MediaCodecList; +import android.media.MediaFormat; +import android.media.MediaCodec.BufferInfo; +import android.os.Build; +import android.view.Surface; + +@TargetApi(Build.VERSION_CODES.JELLY_BEAN) +public class MediaCodecDecoderRenderer implements DecoderRenderer { + + private ByteBuffer[] videoDecoderInputBuffers; + private MediaCodec videoDecoder; + private Thread rendererThread; + + public static boolean hasWhitelistedDecoder() { + for (int i = 0; i < MediaCodecList.getCodecCount(); i++) { + MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); + + // Skip encoders + if (codecInfo.isEncoder()) { + continue; + } + + if (codecInfo.getName().equalsIgnoreCase("omx.qcom.video.decoder.avc")) { + return true; + } + } + + return false; + } + + @Override + public void setup(int width, int height, Surface renderTarget) { + videoDecoder = MediaCodec.createDecoderByType("video/avc"); + MediaFormat videoFormat = MediaFormat.createVideoFormat("video/avc", width, height); + + videoDecoder.configure(videoFormat, renderTarget, null, 0); + + videoDecoder.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT); + + videoDecoder.start(); + + videoDecoderInputBuffers = videoDecoder.getInputBuffers(); + } + + private void startRendererThread() + { + rendererThread = new Thread() { + @Override + public void run() { + long nextFrameTimeUs = 0; + while (!isInterrupted()) + { + BufferInfo info = new BufferInfo(); + int outIndex = videoDecoder.dequeueOutputBuffer(info, 100); + switch (outIndex) { + case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED: + System.out.println("Output buffers changed"); + break; + case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED: + System.out.println("Output format changed"); + System.out.println("New output Format: " + videoDecoder.getOutputFormat()); + break; + default: + break; + } + if (outIndex >= 0) { + boolean render = false; + + if (currentTimeUs() >= nextFrameTimeUs) { + render = true; + nextFrameTimeUs = computePresentationTime(60); + } + + videoDecoder.releaseOutputBuffer(outIndex, render); + } + } + } + }; + rendererThread.start(); + } + + private static long currentTimeUs() { + return System.nanoTime() / 1000; + } + + private long computePresentationTime(int frameRate) { + return currentTimeUs() + (1000000 / frameRate); + } + + @Override + public void start() { + startRendererThread(); + } + + @Override + public void stop() { + rendererThread.interrupt(); + } + + @Override + public void release() { + if (videoDecoder != null) { + videoDecoder.release(); + } + } + + @Override + public void submitDecodeUnit(AvDecodeUnit decodeUnit) { + if (decodeUnit.getType() != AvDecodeUnit.TYPE_H264) { + System.err.println("Unknown decode unit type"); + return; + } + + int inputIndex = videoDecoder.dequeueInputBuffer(-1); + if (inputIndex >= 0) + { + ByteBuffer buf = videoDecoderInputBuffers[inputIndex]; + + // Clear old input data + buf.clear(); + + // Copy data from our buffer list into the input buffer + for (AvByteBufferDescriptor desc : decodeUnit.getBufferList()) + { + buf.put(desc.data, desc.offset, desc.length); + } + + videoDecoder.queueInputBuffer(inputIndex, + 0, decodeUnit.getDataLength(), + 0, decodeUnit.getFlags()); + } + } +}