├── DesktopSharing.sln
├── DesktopSharing
├── DesktopSharing.vcxproj
├── DesktopSharing.vcxproj.filters
├── DesktopSharing.vcxproj.user
├── MainWindow.cpp
├── MainWindow.h
├── Overlay.cpp
├── Overlay.h
├── ScreenLive.cpp
├── ScreenLive.h
├── capture
│ ├── AudioCapture
│ │ ├── AudioBuffer.h
│ │ ├── AudioCapture.cpp
│ │ ├── AudioCapture.h
│ │ ├── WASAPICapture.cpp
│ │ ├── WASAPICapture.h
│ │ ├── WASAPIPlayer.cpp
│ │ └── WASAPIPlayer.h
│ └── ScreenCapture
│ │ ├── DXGIScreenCapture.cpp
│ │ ├── DXGIScreenCapture.h
│ │ ├── GDIScreenCapture.cpp
│ │ ├── GDIScreenCapture.h
│ │ ├── ScreenCapture.cpp
│ │ ├── ScreenCapture.h
│ │ ├── WindowHelper.cpp
│ │ └── WindowHelper.h
├── codec
│ ├── AACEncoder.cpp
│ ├── AACEncoder.h
│ ├── H264Encoder.cpp
│ ├── H264Encoder.h
│ ├── NvCodec
│ │ ├── NvDecoder
│ │ │ ├── NvDecoder.cpp
│ │ │ ├── NvDecoder.h
│ │ │ ├── cuviddec.h
│ │ │ └── nvcuvid.h
│ │ ├── NvEncoder
│ │ │ ├── NvEncoder.cpp
│ │ │ ├── NvEncoder.h
│ │ │ ├── NvEncoderCuda.cpp
│ │ │ ├── NvEncoderCuda.h
│ │ │ ├── NvEncoderD3D11.cpp
│ │ │ ├── NvEncoderD3D11.h
│ │ │ ├── NvEncoderD3D9.cpp
│ │ │ ├── NvEncoderD3D9.h
│ │ │ ├── NvEncoderGL.cpp
│ │ │ ├── NvEncoderGL.h
│ │ │ └── nvEncodeAPI.h
│ │ ├── encoder_info.h
│ │ ├── nvenc.cpp
│ │ └── nvenc.h
│ ├── QsvCodec
│ │ ├── QsvEncoder.cpp
│ │ ├── QsvEncoder.h
│ │ ├── bits
│ │ │ ├── linux_defs.h
│ │ │ └── windows_defs.h
│ │ ├── common_directx11.cpp
│ │ ├── common_directx11.h
│ │ ├── common_directx9.cpp
│ │ ├── common_directx9.h
│ │ ├── common_utils.cpp
│ │ ├── common_utils.h
│ │ ├── common_utils_windows.cpp
│ │ ├── include
│ │ │ ├── mfxastructures.h
│ │ │ ├── mfxaudio++.h
│ │ │ ├── mfxaudio.h
│ │ │ ├── mfxbrc.h
│ │ │ ├── mfxcamera.h
│ │ │ ├── mfxcommon.h
│ │ │ ├── mfxdefs.h
│ │ │ ├── mfxenc.h
│ │ │ ├── mfxjpeg.h
│ │ │ ├── mfxla.h
│ │ │ ├── mfxmvc.h
│ │ │ ├── mfxpak.h
│ │ │ ├── mfxplugin++.h
│ │ │ ├── mfxplugin.h
│ │ │ ├── mfxsession.h
│ │ │ ├── mfxstructures.h
│ │ │ ├── mfxvideo++.h
│ │ │ ├── mfxvideo.h
│ │ │ ├── mfxvp8.h
│ │ │ ├── mfxvp9.h
│ │ │ └── mfxvstructures.h
│ │ └── src
│ │ │ ├── mfx_critical_section.cpp
│ │ │ ├── mfx_critical_section.h
│ │ │ ├── mfx_dispatcher.cpp
│ │ │ ├── mfx_dispatcher.h
│ │ │ ├── mfx_dispatcher_defs.h
│ │ │ ├── mfx_dispatcher_log.cpp
│ │ │ ├── mfx_dispatcher_log.h
│ │ │ ├── mfx_dxva2_device.cpp
│ │ │ ├── mfx_dxva2_device.h
│ │ │ ├── mfx_exposed_functions_list.h
│ │ │ ├── mfx_function_table.cpp
│ │ │ ├── mfx_library_iterator.cpp
│ │ │ ├── mfx_library_iterator.h
│ │ │ ├── mfx_load_dll.cpp
│ │ │ ├── mfx_load_dll.h
│ │ │ ├── mfx_load_plugin.cpp
│ │ │ ├── mfx_load_plugin.h
│ │ │ ├── mfx_plugin_hive.cpp
│ │ │ ├── mfx_plugin_hive.h
│ │ │ ├── mfx_vector.h
│ │ │ ├── mfx_win_reg_key.cpp
│ │ │ ├── mfx_win_reg_key.h
│ │ │ ├── mfxaudio_exposed_functions_list.h
│ │ │ └── qsv_main.cpp
│ └── avcodec
│ │ ├── aac_encoder.cpp
│ │ ├── aac_encoder.h
│ │ ├── audio_resampler.cpp
│ │ ├── audio_resampler.h
│ │ ├── av_common.h
│ │ ├── av_encoder.h
│ │ ├── h264_encoder.cpp
│ │ ├── h264_encoder.h
│ │ ├── video_converter.cpp
│ │ └── video_converter.h
├── imgui
│ ├── gl3w
│ │ └── GL
│ │ │ ├── gl3w.c
│ │ │ ├── gl3w.h
│ │ │ └── glcorearb.h
│ ├── imconfig.h
│ ├── imgui.cpp
│ ├── imgui.h
│ ├── imgui_demo.cpp
│ ├── imgui_draw.cpp
│ ├── imgui_impl_dx9.cpp
│ ├── imgui_impl_dx9.h
│ ├── imgui_impl_glfw.cpp
│ ├── imgui_impl_glfw.h
│ ├── imgui_impl_opengl2.cpp
│ ├── imgui_impl_opengl2.h
│ ├── imgui_impl_opengl3.cpp
│ ├── imgui_impl_opengl3.h
│ ├── imgui_impl_sdl.cpp
│ ├── imgui_impl_sdl.h
│ ├── imgui_impl_win32.cpp
│ ├── imgui_impl_win32.h
│ ├── imgui_internal.h
│ ├── imgui_widgets.cpp
│ ├── imstb_rectpack.h
│ ├── imstb_textedit.h
│ └── imstb_truetype.h
├── libyuv
│ ├── include
│ │ ├── libyuv.h
│ │ └── libyuv
│ │ │ ├── basic_types.h
│ │ │ ├── compare.h
│ │ │ ├── compare_row.h
│ │ │ ├── convert.h
│ │ │ ├── convert_argb.h
│ │ │ ├── convert_from.h
│ │ │ ├── convert_from_argb.h
│ │ │ ├── cpu_id.h
│ │ │ ├── macros_msa.h
│ │ │ ├── mjpeg_decoder.h
│ │ │ ├── planar_functions.h
│ │ │ ├── rotate.h
│ │ │ ├── rotate_argb.h
│ │ │ ├── rotate_row.h
│ │ │ ├── row.h
│ │ │ ├── scale.h
│ │ │ ├── scale_argb.h
│ │ │ ├── scale_row.h
│ │ │ ├── version.h
│ │ │ └── video_common.h
│ └── source
│ │ ├── compare.cc
│ │ ├── compare_common.cc
│ │ ├── compare_gcc.cc
│ │ ├── compare_mmi.cc
│ │ ├── compare_msa.cc
│ │ ├── compare_neon.cc
│ │ ├── compare_neon64.cc
│ │ ├── compare_win.cc
│ │ ├── convert.cc
│ │ ├── convert_argb.cc
│ │ ├── convert_from.cc
│ │ ├── convert_from_argb.cc
│ │ ├── convert_jpeg.cc
│ │ ├── convert_to_argb.cc
│ │ ├── convert_to_i420.cc
│ │ ├── cpu_id.cc
│ │ ├── mjpeg_decoder.cc
│ │ ├── mjpeg_validate.cc
│ │ ├── planar_functions.cc
│ │ ├── rotate.cc
│ │ ├── rotate_any.cc
│ │ ├── rotate_argb.cc
│ │ ├── rotate_common.cc
│ │ ├── rotate_gcc.cc
│ │ ├── rotate_mmi.cc
│ │ ├── rotate_msa.cc
│ │ ├── rotate_neon.cc
│ │ ├── rotate_neon64.cc
│ │ ├── rotate_win.cc
│ │ ├── row_any.cc
│ │ ├── row_common.cc
│ │ ├── row_gcc.cc
│ │ ├── row_mmi.cc
│ │ ├── row_msa.cc
│ │ ├── row_neon.cc
│ │ ├── row_neon64.cc
│ │ ├── row_win.cc
│ │ ├── scale.cc
│ │ ├── scale_any.cc
│ │ ├── scale_argb.cc
│ │ ├── scale_common.cc
│ │ ├── scale_gcc.cc
│ │ ├── scale_mmi.cc
│ │ ├── scale_msa.cc
│ │ ├── scale_neon.cc
│ │ ├── scale_neon64.cc
│ │ ├── scale_win.cc
│ │ └── video_common.cc
├── main.cpp
├── md5
│ ├── COPYING
│ └── md5.hpp
├── net
│ ├── Acceptor.cpp
│ ├── Acceptor.h
│ ├── BufferReader.cpp
│ ├── BufferReader.h
│ ├── BufferWriter.cpp
│ ├── BufferWriter.h
│ ├── Channel.h
│ ├── EpollTaskScheduler.cpp
│ ├── EpollTaskScheduler.h
│ ├── EventLoop.cpp
│ ├── EventLoop.h
│ ├── Logger.cpp
│ ├── Logger.h
│ ├── MemoryManager.cpp
│ ├── MemoryManager.h
│ ├── NetInterface.cpp
│ ├── NetInterface.h
│ ├── Pipe.cpp
│ ├── Pipe.h
│ ├── RingBuffer.h
│ ├── SelectTaskScheduler.cpp
│ ├── SelectTaskScheduler.h
│ ├── Socket.h
│ ├── SocketUtil.cpp
│ ├── SocketUtil.h
│ ├── TaskScheduler.cpp
│ ├── TaskScheduler.h
│ ├── TcpConnection.cpp
│ ├── TcpConnection.h
│ ├── TcpServer.cpp
│ ├── TcpServer.h
│ ├── TcpSocket.cpp
│ ├── TcpSocket.h
│ ├── ThreadSafeQueue.h
│ ├── Timer.cpp
│ ├── Timer.h
│ ├── Timestamp.cpp
│ ├── Timestamp.h
│ └── log.h
└── xop
│ ├── AACSource.cpp
│ ├── AACSource.h
│ ├── DigestAuthentication.cpp
│ ├── DigestAuthentication.h
│ ├── G711ASource.cpp
│ ├── G711ASource.h
│ ├── H264Parser.cpp
│ ├── H264Parser.h
│ ├── H264Source.cpp
│ ├── H264Source.h
│ ├── H265Source.cpp
│ ├── H265Source.h
│ ├── HttpFlvConnection.cpp
│ ├── HttpFlvConnection.h
│ ├── HttpFlvServer.cpp
│ ├── HttpFlvServer.h
│ ├── MediaSession.cpp
│ ├── MediaSession.h
│ ├── MediaSource.h
│ ├── RtmpChunk.cpp
│ ├── RtmpChunk.h
│ ├── RtmpClient.cpp
│ ├── RtmpClient.h
│ ├── RtmpConnection.cpp
│ ├── RtmpConnection.h
│ ├── RtmpHandshake.cpp
│ ├── RtmpHandshake.h
│ ├── RtmpMessage.h
│ ├── RtmpPublisher.cpp
│ ├── RtmpPublisher.h
│ ├── RtmpServer.cpp
│ ├── RtmpServer.h
│ ├── RtmpSession.cpp
│ ├── RtmpSession.h
│ ├── RtpConnection.cpp
│ ├── RtpConnection.h
│ ├── RtspConnection.cpp
│ ├── RtspConnection.h
│ ├── RtspMessage.cpp
│ ├── RtspMessage.h
│ ├── RtspPusher.cpp
│ ├── RtspPusher.h
│ ├── RtspServer.cpp
│ ├── RtspServer.h
│ ├── amf.cpp
│ ├── amf.h
│ ├── media.h
│ ├── rtmp.h
│ ├── rtp.h
│ └── rtsp.h
├── LICENSE
├── README.md
├── libs
├── SDL2
│ ├── BUGS.txt
│ ├── COPYING.txt
│ ├── README-SDL.txt
│ ├── README.txt
│ ├── WhatsNew.txt
│ ├── docs
│ │ ├── README-android.md
│ │ ├── README-cmake.md
│ │ ├── README-directfb.md
│ │ ├── README-dynapi.md
│ │ ├── README-emscripten.md
│ │ ├── README-gesture.md
│ │ ├── README-hg.md
│ │ ├── README-ios.md
│ │ ├── README-linux.md
│ │ ├── README-macosx.md
│ │ ├── README-nacl.md
│ │ ├── README-pandora.md
│ │ ├── README-platforms.md
│ │ ├── README-porting.md
│ │ ├── README-psp.md
│ │ ├── README-raspberrypi.md
│ │ ├── README-touch.md
│ │ ├── README-wince.md
│ │ ├── README-windows.md
│ │ ├── README-winrt.md
│ │ ├── README.md
│ │ └── doxyfile
│ ├── include
│ │ ├── SDL.h
│ │ ├── SDL_assert.h
│ │ ├── SDL_atomic.h
│ │ ├── SDL_audio.h
│ │ ├── SDL_bits.h
│ │ ├── SDL_blendmode.h
│ │ ├── SDL_clipboard.h
│ │ ├── SDL_config.h
│ │ ├── SDL_config.h.cmake
│ │ ├── SDL_config.h.in
│ │ ├── SDL_config_android.h
│ │ ├── SDL_config_iphoneos.h
│ │ ├── SDL_config_macosx.h
│ │ ├── SDL_config_macosx.h.orig
│ │ ├── SDL_config_minimal.h
│ │ ├── SDL_config_pandora.h
│ │ ├── SDL_config_psp.h
│ │ ├── SDL_config_windows.h
│ │ ├── SDL_config_winrt.h
│ │ ├── SDL_config_wiz.h
│ │ ├── SDL_copying.h
│ │ ├── SDL_cpuinfo.h
│ │ ├── SDL_egl.h
│ │ ├── SDL_endian.h
│ │ ├── SDL_error.h
│ │ ├── SDL_events.h
│ │ ├── SDL_filesystem.h
│ │ ├── SDL_gamecontroller.h
│ │ ├── SDL_gesture.h
│ │ ├── SDL_haptic.h
│ │ ├── SDL_hints.h
│ │ ├── SDL_joystick.h
│ │ ├── SDL_keyboard.h
│ │ ├── SDL_keycode.h
│ │ ├── SDL_loadso.h
│ │ ├── SDL_log.h
│ │ ├── SDL_main.h
│ │ ├── SDL_messagebox.h
│ │ ├── SDL_metal.h
│ │ ├── SDL_mouse.h
│ │ ├── SDL_mutex.h
│ │ ├── SDL_name.h
│ │ ├── SDL_opengl.h
│ │ ├── SDL_opengl_glext.h
│ │ ├── SDL_opengles.h
│ │ ├── SDL_opengles2.h
│ │ ├── SDL_opengles2_gl2.h
│ │ ├── SDL_opengles2_gl2ext.h
│ │ ├── SDL_opengles2_gl2platform.h
│ │ ├── SDL_opengles2_khrplatform.h
│ │ ├── SDL_pixels.h
│ │ ├── SDL_platform.h
│ │ ├── SDL_power.h
│ │ ├── SDL_quit.h
│ │ ├── SDL_rect.h
│ │ ├── SDL_render.h
│ │ ├── SDL_revision.h
│ │ ├── SDL_rwops.h
│ │ ├── SDL_scancode.h
│ │ ├── SDL_sensor.h
│ │ ├── SDL_shape.h
│ │ ├── SDL_stdinc.h
│ │ ├── SDL_surface.h
│ │ ├── SDL_system.h
│ │ ├── SDL_syswm.h
│ │ ├── SDL_test.h
│ │ ├── SDL_test_assert.h
│ │ ├── SDL_test_common.h
│ │ ├── SDL_test_compare.h
│ │ ├── SDL_test_crc32.h
│ │ ├── SDL_test_font.h
│ │ ├── SDL_test_fuzzer.h
│ │ ├── SDL_test_harness.h
│ │ ├── SDL_test_images.h
│ │ ├── SDL_test_log.h
│ │ ├── SDL_test_md5.h
│ │ ├── SDL_test_memory.h
│ │ ├── SDL_test_random.h
│ │ ├── SDL_thread.h
│ │ ├── SDL_timer.h
│ │ ├── SDL_touch.h
│ │ ├── SDL_types.h
│ │ ├── SDL_version.h
│ │ ├── SDL_video.h
│ │ ├── SDL_vulkan.h
│ │ ├── begin_code.h
│ │ └── close_code.h
│ └── lib
│ │ └── x86
│ │ ├── SDL2.lib
│ │ ├── SDL2main.lib
│ │ └── SDL2test.lib
├── ffmpeg
│ ├── include
│ │ ├── libavcodec
│ │ │ ├── ac3_parser.h
│ │ │ ├── adts_parser.h
│ │ │ ├── avcodec.h
│ │ │ ├── avdct.h
│ │ │ ├── avfft.h
│ │ │ ├── d3d11va.h
│ │ │ ├── dirac.h
│ │ │ ├── dv_profile.h
│ │ │ ├── dxva2.h
│ │ │ ├── jni.h
│ │ │ ├── mediacodec.h
│ │ │ ├── qsv.h
│ │ │ ├── vaapi.h
│ │ │ ├── vdpau.h
│ │ │ ├── version.h
│ │ │ ├── videotoolbox.h
│ │ │ ├── vorbis_parser.h
│ │ │ └── xvmc.h
│ │ ├── libavdevice
│ │ │ ├── avdevice.h
│ │ │ └── version.h
│ │ ├── libavfilter
│ │ │ ├── avfilter.h
│ │ │ ├── buffersink.h
│ │ │ ├── buffersrc.h
│ │ │ └── version.h
│ │ ├── libavformat
│ │ │ ├── avformat.h
│ │ │ ├── avio.h
│ │ │ └── version.h
│ │ ├── libavutil
│ │ │ ├── adler32.h
│ │ │ ├── aes.h
│ │ │ ├── aes_ctr.h
│ │ │ ├── attributes.h
│ │ │ ├── audio_fifo.h
│ │ │ ├── avassert.h
│ │ │ ├── avconfig.h
│ │ │ ├── avstring.h
│ │ │ ├── avutil.h
│ │ │ ├── base64.h
│ │ │ ├── blowfish.h
│ │ │ ├── bprint.h
│ │ │ ├── bswap.h
│ │ │ ├── buffer.h
│ │ │ ├── camellia.h
│ │ │ ├── cast5.h
│ │ │ ├── channel_layout.h
│ │ │ ├── common.h
│ │ │ ├── cpu.h
│ │ │ ├── crc.h
│ │ │ ├── des.h
│ │ │ ├── dict.h
│ │ │ ├── display.h
│ │ │ ├── downmix_info.h
│ │ │ ├── encryption_info.h
│ │ │ ├── error.h
│ │ │ ├── eval.h
│ │ │ ├── ffversion.h
│ │ │ ├── fifo.h
│ │ │ ├── file.h
│ │ │ ├── frame.h
│ │ │ ├── hash.h
│ │ │ ├── hmac.h
│ │ │ ├── hwcontext.h
│ │ │ ├── hwcontext_cuda.h
│ │ │ ├── hwcontext_d3d11va.h
│ │ │ ├── hwcontext_drm.h
│ │ │ ├── hwcontext_dxva2.h
│ │ │ ├── hwcontext_mediacodec.h
│ │ │ ├── hwcontext_qsv.h
│ │ │ ├── hwcontext_vaapi.h
│ │ │ ├── hwcontext_vdpau.h
│ │ │ ├── hwcontext_videotoolbox.h
│ │ │ ├── imgutils.h
│ │ │ ├── intfloat.h
│ │ │ ├── intreadwrite.h
│ │ │ ├── lfg.h
│ │ │ ├── log.h
│ │ │ ├── lzo.h
│ │ │ ├── macros.h
│ │ │ ├── mastering_display_metadata.h
│ │ │ ├── mathematics.h
│ │ │ ├── md5.h
│ │ │ ├── mem.h
│ │ │ ├── motion_vector.h
│ │ │ ├── murmur3.h
│ │ │ ├── opt.h
│ │ │ ├── parseutils.h
│ │ │ ├── pixdesc.h
│ │ │ ├── pixelutils.h
│ │ │ ├── pixfmt.h
│ │ │ ├── random_seed.h
│ │ │ ├── rational.h
│ │ │ ├── rc4.h
│ │ │ ├── replaygain.h
│ │ │ ├── ripemd.h
│ │ │ ├── samplefmt.h
│ │ │ ├── sha.h
│ │ │ ├── sha512.h
│ │ │ ├── spherical.h
│ │ │ ├── stereo3d.h
│ │ │ ├── tea.h
│ │ │ ├── threadmessage.h
│ │ │ ├── time.h
│ │ │ ├── timecode.h
│ │ │ ├── timestamp.h
│ │ │ ├── tree.h
│ │ │ ├── twofish.h
│ │ │ ├── version.h
│ │ │ └── xtea.h
│ │ ├── libpostproc
│ │ │ ├── postprocess.h
│ │ │ └── version.h
│ │ ├── libswresample
│ │ │ ├── swresample.h
│ │ │ └── version.h
│ │ └── libswscale
│ │ │ ├── swscale.h
│ │ │ └── version.h
│ └── lib
│ │ ├── avcodec.lib
│ │ ├── avdevice.lib
│ │ ├── avfilter.lib
│ │ ├── avformat.lib
│ │ ├── avutil.lib
│ │ ├── postproc.lib
│ │ ├── swresample.lib
│ │ └── swscale.lib
├── gl3w
│ └── GL
│ │ ├── gl3w.c
│ │ ├── gl3w.h
│ │ └── glcorearb.h
└── glfw
│ ├── COPYING.txt
│ ├── include
│ └── GLFW
│ │ ├── glfw3.h
│ │ └── glfw3native.h
│ ├── lib-vc2010-32
│ └── glfw3.lib
│ └── lib-vc2010-64
│ └── glfw3.lib
├── pic
└── 2.pic.jpg
└── run-env
├── SDL2.dll
├── avcodec-58.dll
├── avdevice-58.dll
├── avfilter-7.dll
├── avformat-58.dll
├── avutil-56.dll
├── postproc-55.dll
├── swresample-3.dll
└── swscale-5.dll
/DesktopSharing.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30413.136
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DesktopSharing", "DesktopSharing\DesktopSharing.vcxproj", "{77F4AAA4-0051-480A-9168-A6CB8927FB6E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {77F4AAA4-0051-480A-9168-A6CB8927FB6E}.Debug|x86.ActiveCfg = Debug|Win32
15 | {77F4AAA4-0051-480A-9168-A6CB8927FB6E}.Debug|x86.Build.0 = Debug|Win32
16 | {77F4AAA4-0051-480A-9168-A6CB8927FB6E}.Release|x86.ActiveCfg = Release|Win32
17 | {77F4AAA4-0051-480A-9168-A6CB8927FB6E}.Release|x86.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {FE7BE4F7-82A7-4681-BF7C-A11CE442122E}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/DesktopSharing/DesktopSharing.vcxproj.user:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="utf-8"?>
2 | <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4 | <LocalDebuggerWorkingDirectory>$(ProjectDir)..\run-env</LocalDebuggerWorkingDirectory>
5 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
6 | </PropertyGroup>
7 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
8 | <LocalDebuggerWorkingDirectory>$(ProjectDir)..\run-env</LocalDebuggerWorkingDirectory>
9 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
10 | </PropertyGroup>
11 | </Project>
--------------------------------------------------------------------------------
/DesktopSharing/MainWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef SCREEN_LIVE_MAIN_WINDOW_H
2 | #define SCREEN_LIVE_MAIN_WINDOW_H
3 |
4 | #include "SDL.h"
5 | #include "SDL_syswm.h"
6 | #include "Overlay.h"
7 | #include "ScreenLive.h"
8 | #include <string>
9 |
10 | class MainWindow : public OverlayCallack
11 | {
12 | public:
13 | MainWindow();
14 | virtual ~MainWindow();
15 |
16 | bool Create();
17 | void Destroy();
18 | bool IsWindow() const;
19 | void Resize();
20 |
21 | void Porcess(SDL_Event& event);
22 |
23 | void SetDebugInfo(std::string text);
24 |
25 | bool UpdateARGB(const uint8_t* data, uint32_t width, uint32_t height);
26 |
27 | private:
28 | bool Init();
29 | void Clear();
30 |
31 | virtual bool StartLive(int& event_type,
32 | std::vector<std::string>& encoder_settings,
33 | std::vector<std::string>& live_settings);
34 |
35 | virtual void StopLive(int event_type);
36 |
37 | SDL_Window* window_ = nullptr;
38 | HWND window_handle_ = nullptr;
39 |
40 | Overlay* overlay_ = nullptr;
41 | std::string debug_info_text_;
42 |
43 | AVConfig avconfig_;
44 |
45 | std::string renderer_name_;
46 | SDL_Renderer* renderer_ = nullptr;
47 | SDL_Texture* texture_ = nullptr;
48 |
49 | IDirect3DDevice9* device_ = nullptr;
50 | SDL_GLContext gl_context_ = nullptr;
51 |
52 | int texture_format_ = SDL_PIXELFORMAT_UNKNOWN;
53 | uint32_t texture_width_ = 0;
54 | uint32_t texture_height_ = 0;
55 |
56 | int window_width_ = 0;
57 | int window_height_ = 0;
58 | int video_width_ = 0;
59 | int video_height_ = 0;
60 | int overlay_width_ = 0;
61 | int overlay_height_ = 0;
62 |
63 | static const int kMinOverlayWidth = 860;
64 | static const int kMinOverlayHeight = 200;
65 | };
66 |
67 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/Overlay.h:
--------------------------------------------------------------------------------
1 | #ifndef OVERLAY_H
2 | #define OVERLAY_H
3 |
4 | #include "SDL.h"
5 | #include "imgui/imgui.h"
6 | #include "imgui/imgui_impl_dx9.h"
7 | #include "imgui/imgui_impl_sdl.h"
8 | #include "imgui/imgui_impl_glfw.h"
9 | #include "imgui/imgui_impl_opengl3.h"
10 | #include <d3d9.h>
11 | //#include <SDL_opengl.h>
12 | #include <string>
13 | #include <vector>
14 |
15 | #include <GL/gl3w.h> // Initialize with gl3wInit()
16 | #include <GLFW/glfw3.h>
17 |
18 | enum OverlayEventType
19 | {
20 | EVENT_TYPE_RTSP_SERVER = 0x001,
21 | EVENT_TYPE_RTSP_PUSHER = 0x002,
22 | EVENT_TYPE_RTMP_PUSHER = 0x003,
23 | };
24 |
25 | class OverlayCallack
26 | {
27 | public:
28 | virtual bool StartLive(int& event_type,
29 | std::vector<std::string>& encoder_settings,
30 | std::vector<std::string>& live_settings) = 0;
31 |
32 | virtual void StopLive(int event_type) = 0;
33 |
34 | //protected:
35 | virtual ~OverlayCallack() {};
36 | };
37 |
38 | class Overlay
39 | {
40 | public:
41 | Overlay();
42 | virtual ~Overlay();
43 |
44 | void RegisterObserver(OverlayCallack* callback);
45 |
46 | bool Init(SDL_Window* window, IDirect3DDevice9* device);
47 | bool Init(SDL_Window* window, SDL_GLContext gl_context);
48 |
49 | void SetRect(int x, int y, int w, int h);
50 | void Destroy();
51 | bool Render();
52 |
53 | static void Process(SDL_Event* event);
54 |
55 | void SetLiveState(int event_type, bool state);
56 | void SetDebugInfo(std::string text);
57 |
58 | private:
59 | void Init();
60 | bool Copy();
61 | bool Begin();
62 | bool End();
63 | void NotifyEvent(int event_type);
64 |
65 | SDL_Window* window_ = nullptr;
66 | IDirect3DDevice9* device_ = nullptr;
67 | SDL_GLContext gl_context_ = nullptr;
68 |
69 | SDL_Rect rect_;
70 |
71 | OverlayCallack* callback_ = nullptr;
72 |
73 | /* debug info */
74 | std::string debug_info_text_;
75 |
76 | /* live config */
77 | int encoder_index_ = 1;
78 | char encoder_bitrate_kbps_[8];
79 | char encoder_framerate_[3];
80 |
81 | struct LiveInfo {
82 | char server_ip[16];
83 | char server_port[6];
84 | char server_stream[16];
85 | char pusher_url[60];
86 |
87 | bool state = false;
88 | char state_info[16];
89 | } live_info_[10] ;
90 | };
91 |
92 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/AudioCapture/AudioCapture.h:
--------------------------------------------------------------------------------
1 | #ifndef CORE_AUDIO_CAPTURE_H
2 | #define CORE_AUDIO_CAPTURE_H
3 |
4 | #include <thread>
5 | #include <cstdint>
6 | #include <memory>
7 | #include "AudioCapture/WASAPICapture.h"
8 | #include "AudioCapture/WASAPIPlayer.h"
9 | #include "AudioBuffer.h"
10 |
11 | class AudioCapture
12 | {
13 | public:
14 | AudioCapture();
15 | virtual ~AudioCapture();
16 |
17 | bool Init(uint32_t buffer_size = 20480);
18 | void Destroy();
19 |
20 | int Read(uint8_t*data,uint32_t samples);
21 | int GetSamples();
22 |
23 | uint32_t GetSamplerate() const
24 | { return samplerate_; }
25 |
26 | uint32_t GetChannels()const
27 | { return channels_; }
28 |
29 | uint32_t GetBitsPerSample()const
30 | { return bits_per_sample_; }
31 |
32 | bool CaptureStarted() const
33 | { return is_started_; }
34 |
35 | private:
36 | int StartCapture();
37 | int StopCapture();
38 |
39 | bool is_initialized_ = false;
40 | bool is_started_ = false;
41 |
42 | uint32_t channels_ = 2;
43 | uint32_t samplerate_ = 48000;
44 | uint32_t bits_per_sample_ = 16;
45 |
46 | WASAPIPlayer player_;
47 | WASAPICapture capture_;
48 | std::unique_ptr<AudioBuffer> audio_buffer_;
49 | };
50 |
51 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/AudioCapture/WASAPICapture.h:
--------------------------------------------------------------------------------
1 | // https://docs.microsoft.com/en-us/previous-versions//ms678709(v=vs.85)
2 |
3 | #ifndef WASAPI_CAPTURE_H
4 | #define WASAPI_CAPTURE_H
5 |
6 | #include <Audioclient.h>
7 | #include <mmdeviceapi.h>
8 | #include <wrl.h>
9 | #include <cstdio>
10 | #include <cstdint>
11 | #include <functional>
12 | #include <mutex>
13 | #include <memory>
14 | #include <thread>
15 |
16 | class WASAPICapture
17 | {
18 | public:
19 | typedef std::function<void(const WAVEFORMATEX *mixFormat, uint8_t *data, uint32_t samples)> PacketCallback;
20 |
21 | WASAPICapture();
22 | ~WASAPICapture();
23 | WASAPICapture &operator=(const WASAPICapture &) = delete;
24 | WASAPICapture(const WASAPICapture &) = delete;
25 |
26 | int init();
27 | int exit();
28 | int start();
29 | int stop();
30 | void setCallback(PacketCallback callback);
31 |
32 | WAVEFORMATEX *getAudioFormat() const
33 | {
34 | return m_mixFormat;
35 | }
36 |
37 | private:
38 | int adjustFormatTo16Bits(WAVEFORMATEX *pwfx);
39 | int capture();
40 |
41 | const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
42 | const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
43 | const IID IID_IAudioClient = __uuidof(IAudioClient);
44 | const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
45 | const int REFTIMES_PER_SEC = 10000000;
46 | const int REFTIMES_PER_MILLISEC = 10000;
47 |
48 | bool m_initialized;
49 | bool m_isEnabeld;
50 | std::mutex m_mutex, m_mutex2;
51 | std::shared_ptr<std::thread> m_threadPtr;
52 | WAVEFORMATEX *m_mixFormat;
53 | REFERENCE_TIME m_hnsActualDuration;
54 | uint32_t m_bufferFrameCount;
55 | PacketCallback m_callback;
56 | std::shared_ptr<uint8_t> m_pcmBuf;
57 | uint32_t m_pcmBufSize;
58 | Microsoft::WRL::ComPtr<IMMDeviceEnumerator> m_enumerator;
59 | Microsoft::WRL::ComPtr<IMMDevice> m_device;
60 | Microsoft::WRL::ComPtr<IAudioClient> m_audioClient;
61 | Microsoft::WRL::ComPtr<IAudioCaptureClient> m_audioCaptureClient;
62 | };
63 |
64 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/AudioCapture/WASAPIPlayer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include <Audioclient.h>
4 | #include <mmdeviceapi.h>
5 | #include <wrl.h>
6 | #include <cstdio>
7 | #include <cstdint>
8 | #include <functional>
9 | #include <mutex>
10 | #include <memory>
11 | #include <thread>
12 |
13 |
14 | class WASAPIPlayer
15 | {
16 | public:
17 | typedef std::function<void(const WAVEFORMATEX *mixFormat, uint8_t *data, uint32_t samples)> AudioDataCallback;
18 |
19 | WASAPIPlayer();
20 | ~WASAPIPlayer();
21 | WASAPIPlayer &operator=(const WASAPIPlayer &) = delete;
22 | WASAPIPlayer(const WASAPIPlayer &) = delete;
23 |
24 | int init();
25 | int exit();
26 | int start(AudioDataCallback callback);
27 | int stop();
28 |
29 | private:
30 | int adjustFormatTo16Bits(WAVEFORMATEX *pwfx);
31 | int play();
32 |
33 | const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
34 | const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
35 | const IID IID_IAudioClient = __uuidof(IAudioClient);
36 | const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
37 | const int REFTIMES_PER_SEC = 10000000;
38 | const int REFTIMES_PER_MILLISEC = 10000;
39 |
40 | bool m_initialized;
41 | bool m_isEnabeld;
42 | std::mutex m_mutex;
43 | std::shared_ptr<std::thread> m_threadPtr;
44 | WAVEFORMATEX *m_mixFormat;
45 | REFERENCE_TIME m_hnsActualDuration;
46 | uint32_t m_bufferFrameCount;
47 | AudioDataCallback m_callback;
48 | Microsoft::WRL::ComPtr<IMMDeviceEnumerator> m_enumerator;
49 | Microsoft::WRL::ComPtr<IMMDevice> m_device;
50 | Microsoft::WRL::ComPtr<IAudioClient> m_audioClient;
51 | Microsoft::WRL::ComPtr<IAudioRenderClient> m_audioRenderClient;
52 | };
53 |
54 |
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/DXGIScreenCapture.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/DesktopSharing/capture/ScreenCapture/DXGIScreenCapture.cpp
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/DXGIScreenCapture.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2020-11-20
3 |
4 | #ifndef DXGI_SCREEN_CAPTURE_H
5 | #define DXGI_SCREEN_CAPTURE_H
6 |
7 | #include "ScreenCapture.h"
8 | #include "WindowHelper.h"
9 | #include <cstdio>
10 | #include <cstdint>
11 | #include <string>
12 | #include <mutex>
13 | #include <thread>
14 | #include <memory>
15 | #include <vector>
16 | #include <wrl.h>
17 | #include <dxgi.h>
18 | #include <d3d11.h>
19 | #include <dxgi1_2.h>
20 |
21 | class DXGIScreenCapture : public ScreenCapture
22 | {
23 | public:
24 | DXGIScreenCapture();
25 | virtual ~DXGIScreenCapture();
26 |
27 | bool Init(int display_index = 0);
28 | bool Destroy();
29 |
30 | uint32_t GetWidth() const { return dxgi_desc_.ModeDesc.Width; }
31 | uint32_t GetHeight() const { return dxgi_desc_.ModeDesc.Height; }
32 |
33 | bool CaptureFrame(std::vector<uint8_t>& bgra_image, uint32_t& width, uint32_t& height);
34 | //bool GetTextureHandle(HANDLE* handle, int* lockKey, int* unlockKey);
35 | //bool CaptureImage(std::string pathname);
36 |
37 | //ID3D11Device* GetD3D11Device() { return d3d11_device_.Get(); }
38 | //ID3D11DeviceContext* GetD3D11DeviceContext() { return d3d11_context_.Get(); }
39 |
40 | bool CaptureStarted() const
41 | {
42 | return is_started_;
43 | }
44 |
45 | private:
46 | int StartCapture();
47 | int StopCapture();
48 | int CreateSharedTexture();
49 | int AquireFrame();
50 |
51 | DX::Monitor monitor_;
52 |
53 | bool is_initialized_;
54 | bool is_started_;
55 | std::unique_ptr<std::thread> thread_ptr_;
56 |
57 | std::mutex mutex_;
58 | std::shared_ptr<uint8_t> image_ptr_; // bgra
59 | uint32_t image_size_;
60 |
61 | // d3d resource
62 | DXGI_OUTDUPL_DESC dxgi_desc_;
63 | HANDLE texture_handle_;
64 | int key_;
65 | Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_;
66 | Microsoft::WRL::ComPtr<ID3D11DeviceContext> d3d11_context_;
67 | Microsoft::WRL::ComPtr<IDXGIOutputDuplication> dxgi_output_duplication_;
68 | Microsoft::WRL::ComPtr<ID3D11Texture2D> shared_texture_;
69 | Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex_;
70 | Microsoft::WRL::ComPtr<ID3D11Texture2D> rgba_texture_;
71 | Microsoft::WRL::ComPtr<ID3D11Texture2D> gdi_texture_;
72 | };
73 |
74 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/GDIScreenCapture.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2020-11-20
3 |
4 | #ifndef GDI_SCREEN_CAPTURE_H
5 | #define GDI_SCREEN_CAPTURE_H
6 |
7 | #include "ScreenCapture.h"
8 | #include "WindowHelper.h"
9 | extern "C" {
10 | #include "libavcodec/avcodec.h"
11 | #include "libavdevice/avdevice.h"
12 | #include "libavformat/avformat.h"
13 | #include "libswscale/swscale.h"
14 | }
15 | #include <memory>
16 | #include <thread>
17 | #include <mutex>
18 |
19 | class GDIScreenCapture : public ScreenCapture
20 | {
21 | public:
22 | GDIScreenCapture();
23 | virtual ~GDIScreenCapture();
24 |
25 | virtual bool Init(int display_index = 0);
26 | virtual bool Destroy();
27 |
28 | virtual bool CaptureFrame(std::vector<uint8_t>& image, uint32_t& width, uint32_t& height);
29 |
30 | virtual uint32_t GetWidth() const;
31 | virtual uint32_t GetHeight() const;
32 | virtual bool CaptureStarted() const;
33 |
34 | private:
35 | bool StartCapture();
36 | void StopCapture();
37 | bool AquireFrame();
38 | bool Decode(AVFrame* av_frame, AVPacket* av_packet);
39 |
40 | DX::Monitor monitor_;
41 |
42 | bool is_initialized_ = false;
43 | bool is_started_ = false;
44 | std::unique_ptr<std::thread> thread_ptr_;
45 |
46 | AVFormatContext* format_context_ = nullptr;
47 | AVInputFormat* input_format_ = nullptr;
48 | AVCodecContext* codec_context_ = nullptr;
49 | int video_index_ = -1;
50 | int framerate_ = 25;
51 |
52 | std::mutex mutex_;
53 | std::shared_ptr<uint8_t> image_;
54 | uint32_t image_size_ = 0;
55 | uint32_t width_ = 0;
56 | uint32_t height_ = 0;
57 | };
58 |
59 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/ScreenCapture.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/DesktopSharing/capture/ScreenCapture/ScreenCapture.cpp
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/ScreenCapture.h:
--------------------------------------------------------------------------------
1 | #ifndef SCREEN_CAPTURE_H
2 | #define SCREEN_CAPTURE_H
3 |
4 | #include <cstdint>
5 | #include <vector>
6 |
7 | class ScreenCapture
8 | {
9 | public:
10 | ScreenCapture & operator=(const ScreenCapture &) = delete;
11 | ScreenCapture(const ScreenCapture &) = delete;
12 | ScreenCapture() {}
13 | virtual ~ScreenCapture() {}
14 |
15 | virtual bool Init(int display_index = 0) = 0;
16 | virtual bool Destroy() = 0;
17 |
18 | virtual bool CaptureFrame(std::vector<uint8_t>& image, uint32_t& width, uint32_t& height) = 0;
19 |
20 | virtual uint32_t GetWidth() const = 0;
21 | virtual uint32_t GetHeight() const = 0;
22 | virtual bool CaptureStarted() const = 0;
23 |
24 | protected:
25 |
26 | };
27 |
28 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/WindowHelper.cpp:
--------------------------------------------------------------------------------
1 | #include "WindowHelper.h"
2 |
3 | namespace DX {
4 |
5 | std::vector<Monitor> GetMonitors()
6 | {
7 | std::vector<Monitor> monitors;
8 |
9 | HRESULT hr = S_OK;
10 |
11 | IDirect3D9Ex* d3d9ex = nullptr;
12 | hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
13 | if (FAILED(hr)) {
14 | return monitors;
15 | }
16 |
17 | int adapter_count = d3d9ex->GetAdapterCount();
18 |
19 | for (int i = 0; i < adapter_count; i++) {
20 | Monitor monitor;
21 | memset(&monitor, 0, sizeof(Monitor));
22 |
23 | LUID luid = { 0 , 0 };
24 | hr = d3d9ex->GetAdapterLUID(i, &luid);
25 | if (FAILED(hr)) {
26 | continue;
27 | }
28 |
29 | monitor.low_part = (uint64_t)luid.LowPart;
30 | monitor.high_part = (uint64_t)luid.HighPart;
31 |
32 | HMONITOR hMonitor = d3d9ex->GetAdapterMonitor(i);
33 | if (hMonitor) {
34 | MONITORINFO monitor_info;
35 | monitor_info.cbSize = sizeof(MONITORINFO);
36 | BOOL ret = GetMonitorInfoA(hMonitor, &monitor_info);
37 | if (ret) {
38 | monitor.left = monitor_info.rcMonitor.left;
39 | monitor.right = monitor_info.rcMonitor.right;
40 | monitor.top = monitor_info.rcMonitor.top;
41 | monitor.bottom = monitor_info.rcMonitor.bottom;
42 | monitors.push_back(monitor);
43 | }
44 | }
45 | }
46 |
47 | d3d9ex->Release();
48 | return monitors;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/DesktopSharing/capture/ScreenCapture/WindowHelper.h:
--------------------------------------------------------------------------------
1 | #ifndef WINDOW_HELPER_H
2 | #define WINDOW_HELPER_H
3 |
4 | #include <vector>
5 | #include <d3d9.h>
6 |
7 | namespace DX {
8 |
9 | struct Monitor
10 | {
11 | uint64_t low_part;
12 | uint64_t high_part;
13 |
14 | int left;
15 | int top;
16 | int right;
17 | int bottom;
18 | };
19 |
20 | std::vector<Monitor> GetMonitors();
21 |
22 | }
23 |
24 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/codec/AACEncoder.cpp:
--------------------------------------------------------------------------------
1 | #include "AACEncoder.h"
2 |
3 | AACEncoder::AACEncoder()
4 | {
5 |
6 | }
7 |
8 | AACEncoder::~AACEncoder()
9 | {
10 |
11 | }
12 |
13 | bool AACEncoder::Init(int samplerate, int channel, int format, int bitrate_kbps)
14 | {
15 | if (aac_encoder_.GetAVCodecContext()) {
16 | return false;
17 | }
18 |
19 | ffmpeg::AVConfig encoder_config;
20 | encoder_config.audio.samplerate = samplerate_ = samplerate;
21 | encoder_config.audio.bitrate = bitrate_ = bitrate_kbps * 1000;
22 | encoder_config.audio.channels = channel_ = channel;
23 | encoder_config.audio.format = format_ = (AVSampleFormat)format;
24 |
25 | if (!aac_encoder_.Init(encoder_config)) {
26 | return false;
27 | }
28 |
29 | return true;
30 | }
31 |
32 | void AACEncoder::Destroy()
33 | {
34 | samplerate_ = 0;
35 | channel_ = 0;
36 | bitrate_ = 0;
37 | format_ = AV_SAMPLE_FMT_NONE;
38 | aac_encoder_.Destroy();
39 | }
40 |
41 | int AACEncoder::GetFrames()
42 | {
43 | if (!aac_encoder_.GetAVCodecContext()) {
44 | return -1;
45 | }
46 |
47 | return aac_encoder_.GetFrameSamples();
48 | }
49 |
50 | int AACEncoder::GetSamplerate()
51 | {
52 | return samplerate_;
53 | }
54 |
55 | int AACEncoder::GetChannel()
56 | {
57 | return channel_;
58 | }
59 |
60 | int AACEncoder::GetSpecificConfig(uint8_t* buf, int max_buf_size)
61 | {
62 | AVCodecContext* condec_context = aac_encoder_.GetAVCodecContext();
63 | if (!condec_context) {
64 | return -1;
65 | }
66 |
67 | if (max_buf_size < condec_context->extradata_size) {
68 | return -1;
69 | }
70 |
71 | memcpy(buf, condec_context->extradata, condec_context->extradata_size);
72 | return condec_context->extradata_size;
73 | }
74 |
75 | ffmpeg::AVPacketPtr AACEncoder::Encode(const uint8_t* pcm, int samples)
76 | {
77 | if (!aac_encoder_.GetAVCodecContext()) {
78 | return nullptr;
79 | }
80 |
81 | return aac_encoder_.Encode(pcm, samples);
82 | }
83 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/AACEncoder.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "avcodec/aac_encoder.h"
4 | #include "avcodec/av_common.h"
5 |
6 | class AACEncoder
7 | {
8 | public:
9 | AACEncoder& operator=(const AACEncoder&) = delete;
10 | AACEncoder(const AACEncoder&) = delete;
11 | AACEncoder();
12 | virtual ~AACEncoder();
13 |
14 | bool Init(int samplerate, int channel, int format, int bitrate_kbps);
15 | void Destroy();
16 |
17 | int GetFrames();
18 | int GetSamplerate();
19 | int GetChannel();
20 |
21 | int GetSpecificConfig(uint8_t* buf, int max_buf_size);
22 |
23 | ffmpeg::AVPacketPtr Encode(const uint8_t* pcm, int samples);
24 |
25 | private:
26 | ffmpeg::AACEncoder aac_encoder_;
27 | int samplerate_ = 0;
28 | int channel_ = 0;
29 | int bitrate_ = 0;
30 | AVSampleFormat format_ = AV_SAMPLE_FMT_NONE;
31 | };
32 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/H264Encoder.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/DesktopSharing/codec/H264Encoder.cpp
--------------------------------------------------------------------------------
/DesktopSharing/codec/H264Encoder.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "avcodec/h264_encoder.h"
4 | #include "NvCodec/nvenc.h"
5 | #include "QsvCodec/QsvEncoder.h"
6 | #include <string>
7 |
8 | class H264Encoder
9 | {
10 | public:
11 | H264Encoder& operator=(const H264Encoder&) = delete;
12 | H264Encoder(const H264Encoder&) = delete;
13 | H264Encoder();
14 | virtual ~H264Encoder();
15 |
16 | void SetCodec(std::string codec);
17 |
18 | bool Init(int framerate, int bitrate_kbps, int format, int width, int height);
19 | void Destroy();
20 |
21 | int Encode(uint8_t* in_buffer, uint32_t in_width, uint32_t in_height,
22 | uint32_t image_size, std::vector<uint8_t>& out_frame);
23 |
24 | int GetSequenceParams(uint8_t* out_buffer, int out_buffer_size);
25 |
26 | private:
27 | bool IsKeyFrame(const uint8_t* data, uint32_t size);
28 |
29 | std::string codec_;
30 | ffmpeg::AVConfig encoder_config_;
31 | void* nvenc_data_ = nullptr;
32 | QsvEncoder qsv_encoder_;
33 | ffmpeg::H264Encoder h264_encoder_;
34 | };
35 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/NvCodec/NvEncoder/NvEncoderD3D11.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2018 NVIDIA Corporation. All rights reserved.
3 | *
4 | * Please refer to the NVIDIA end user license agreement (EULA) associated
5 | * with this source code for terms and conditions that govern your use of
6 | * this software. Any use, reproduction, disclosure, or distribution of
7 | * this software and related documentation outside the terms of the EULA
8 | * is strictly prohibited.
9 | *
10 | */
11 |
12 | #pragma once
13 |
14 | #include <vector>
15 | #include <stdint.h>
16 | #include <mutex>
17 | #include <unordered_map>
18 | #include <d3d11.h>
19 | #include "NvEncoder.h"
20 |
21 | class NvEncoderD3D11 : public NvEncoder
22 | {
23 | public:
24 | NvEncoderD3D11(ID3D11Device* pD3D11Device, uint32_t nWidth, uint32_t nHeight, NV_ENC_BUFFER_FORMAT eBufferFormat,
25 | uint32_t nExtraOutputDelay = 3, bool bMotionEstimationOnly = false);
26 | virtual ~NvEncoderD3D11();
27 | private:
28 | /**
29 | * @brief This function is used to allocate input buffers for encoding.
30 | * This function is an override of virtual function NvEncoder::AllocateInputBuffers().
31 | * This function creates ID3D11Texture2D textures which is used to accept input data.
32 | * To obtain handle to input buffers application must call NvEncoder::GetNextInputFrame()
33 | */
34 | virtual void AllocateInputBuffers(int32_t numInputBuffers) override;
35 |
36 | /**
37 | * @brief This function is used to release the input buffers allocated for encoding.
38 | * This function is an override of virtual function NvEncoder::ReleaseInputBuffers().
39 | */
40 | virtual void ReleaseInputBuffers() override;
41 | private:
42 | /**
43 | * @brief This is a private function to release ID3D11Texture2D textures used for encoding.
44 | */
45 | void ReleaseD3D11Resources();
46 | private:
47 | ID3D11Device *m_pD3D11Device = nullptr;
48 | ID3D11DeviceContext* m_pD3D11DeviceContext = nullptr;
49 | };
50 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/NvCodec/NvEncoder/NvEncoderD3D9.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2018 NVIDIA Corporation. All rights reserved.
3 | *
4 | * Please refer to the NVIDIA end user license agreement (EULA) associated
5 | * with this source code for terms and conditions that govern your use of
6 | * this software. Any use, reproduction, disclosure, or distribution of
7 | * this software and related documentation outside the terms of the EULA
8 | * is strictly prohibited.
9 | *
10 | */
11 |
12 | #pragma once
13 |
14 | #include <vector>
15 | #include <stdint.h>
16 | #include <mutex>
17 | #include <unordered_map>
18 | #include <d3d9.h>
19 | #include <dxva2api.h>
20 | #include "NvEncoder.h"
21 |
22 |
23 | class NvEncoderD3D9 : public NvEncoder
24 | {
25 | public:
26 | NvEncoderD3D9(IDirect3DDevice9* pD3D9Device, uint32_t nWidth, uint32_t nHeight, NV_ENC_BUFFER_FORMAT eBufferFormat,
27 | IDirectXVideoAccelerationService* pDXVAService = nullptr, uint32_t nExtraOutputDelay = 3, bool bMotionEstimationOnly = false);
28 | virtual ~NvEncoderD3D9();
29 | private:
30 |
31 | /**
32 | * @brief This function is used to allocate input buffers for encoding.
33 | * This function is an override of virtual function NvEncoder::AllocateInputBuffers().
34 | * This function creates IDirect3DSurface9* which is used to accept input data.
35 | * To obtain handle to input buffers application must call NvEncoder::GetNextInputFrame()
36 | */
37 | virtual void AllocateInputBuffers(int32_t numInputBuffers) override;
38 |
39 | /**
40 | * @brief This function is used to release the input buffers allocated for encoding.
41 | * This function is an override of virtual function NvEncoder::ReleaseInputBuffers().
42 | */
43 | virtual void ReleaseInputBuffers() override;
44 | private:
45 | /**
46 | * @brief This is a private function to release IDirect3DSurface9 surfaces used for encoding.
47 | */
48 | void ReleaseD3D9Resources();
49 | private:
50 | IDirect3DDevice9* m_pD3D9Device = nullptr;
51 | IDirectXVideoAccelerationService* m_pDXVAService = nullptr;
52 | };
53 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/NvCodec/NvEncoder/NvEncoderGL.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017-2018 NVIDIA Corporation. All rights reserved.
3 | *
4 | * Please refer to the NVIDIA end user license agreement (EULA) associated
5 | * with this source code for terms and conditions that govern your use of
6 | * this software. Any use, reproduction, disclosure, or distribution of
7 | * this software and related documentation outside the terms of the EULA
8 | * is strictly prohibited.
9 | *
10 | */
11 |
12 | #include <iostream>
13 | #include "NvEncoder/NvEncoder.h"
14 | #include <unordered_map>
15 | #include <GL/glew.h>
16 |
17 | class NvEncoderGL : public NvEncoder
18 | {
19 | public:
20 | /**
21 | * @brief The constructor for the NvEncoderGL class
22 | * An OpenGL context must be current to the calling thread/process when
23 | * creating an instance of this class.
24 | */
25 | NvEncoderGL(uint32_t nWidth, uint32_t nHeight, NV_ENC_BUFFER_FORMAT eBufferFormat,
26 | uint32_t nExtraOutputDelay = 3, bool bMotionEstimationOnly = false);
27 |
28 | virtual ~NvEncoderGL();
29 | private:
30 | /**
31 | * @brief This function is used to allocate input buffers for encoding.
32 | * This function is an override of virtual function NvEncoder::AllocateInputBuffers().
33 | * This function creates OpenGL textures which are used to hold input data.
34 | * To obtain handle to input buffers, the application must call NvEncoder::GetNextInputFrame()
35 | */
36 | virtual void AllocateInputBuffers(int32_t numInputBuffers) override;
37 |
38 | /**
39 | * @brief This function is used to release the input buffers allocated for encoding.
40 | * This function is an override of virtual function NvEncoder::ReleaseInputBuffers().
41 | */
42 | virtual void ReleaseInputBuffers() override;
43 | private:
44 | void ReleaseGLResources();
45 | };
46 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/NvCodec/encoder_info.h:
--------------------------------------------------------------------------------
1 | #ifndef _ENCODER_INFO_H
2 | #define _ENCODER_INFO_H
3 |
4 | #include <cstdint>
5 | #include <string>
6 | #include <vector>
7 | #include <dxgi.h>
8 | #include <d3d11.h>
9 |
10 | struct nvenc_config
11 | {
12 | uint32_t width;
13 | uint32_t height;
14 | uint32_t framerate;
15 | uint32_t bitrate;
16 | uint32_t gop;
17 | std::string codec; // "h264"
18 | DXGI_FORMAT format; // DXGI_FORMAT_NV12 DXGI_FORMAT_B8G8R8A8_UNORM
19 | };
20 |
21 | struct nvenc_info
22 | {
23 | bool (*is_supported)(void);
24 | void* (*create)(void);
25 | void (*destroy)(void **encoder_data);
26 | bool (*init)(void *encoder_data, void *encoder_config);
27 | int (*encode_texture)(void *nvenc_data, ID3D11Texture2D *texture, uint8_t* out_buf, uint32_t max_buf_size);
28 | int (*encode_handle)(void *nvenc_data, HANDLE handle, int lock_key, int unlock_key, uint8_t* out_buf, uint32_t max_buf_size);
29 | int (*set_bitrate)(void *nvenc_data, uint32_t bitrate_bps);
30 | int (*set_framerate)(void *nvenc_data, uint32_t framerate);
31 | int (*request_idr)(void *nvenc_data);
32 | int (*get_sequence_params)(void *nvenc_data, uint8_t* buf, uint32_t max_buf_size);
33 | int (*set_region_of_interest)(void* nvenc_data, int x, int y, int width, int height, int delta_qp);
34 | ID3D11Device* (*get_device)(void *encoder_data);
35 | ID3D11Texture2D* (*get_texture)(void *encoder_data);
36 | ID3D11DeviceContext* (*get_context)(void *encoder_data);
37 | };
38 |
39 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/codec/NvCodec/nvenc.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2020-2-13
3 |
4 | #ifndef _NVIDIA_ENCODER_H
5 | #define _NVIDIA_ENCODER_H
6 |
7 | #include "encoder_info.h"
8 |
9 | // Video-Codec-SDK Version: 8.2
10 | #include "NvEncoder/NvEncoderD3D11.h"
11 |
12 | extern struct nvenc_info nvenc_info;
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/QsvEncoder.h:
--------------------------------------------------------------------------------
1 | #ifndef QSV_ENCODER_H
2 | #define QSV_ENCODER_H
3 |
4 | #include "mfxvideo++.h"
5 | #include <cstdint>
6 | #include <string>
7 | #include <vector>
8 | #include <memory>
9 |
10 | struct QsvParams
11 | {
12 | std::string codec;
13 | uint32_t width;
14 | uint32_t height;
15 | uint32_t bitrate_kbps;
16 | uint32_t framerate;
17 | uint32_t gop;
18 | };
19 |
20 | class QsvEncoder
21 | {
22 | public:
23 | QsvEncoder & operator=(const QsvEncoder &) = delete;
24 | QsvEncoder(const QsvEncoder &) = delete;
25 | QsvEncoder();
26 | virtual ~QsvEncoder();
27 |
28 | static bool IsSupported();
29 |
30 | virtual bool Init(QsvParams& qsv_params);
31 | virtual void Destroy();
32 |
33 | virtual bool IsInitialized() const
34 | { return is_initialized_; }
35 |
36 | virtual int Encode(const uint8_t* bgra_image, uint32_t width, uint32_t height,
37 | uint8_t* out_buf, uint32_t out_buf_size);
38 |
39 | virtual void ForceIDR();
40 | virtual void SetBitrate(uint32_t bitrate_kbps);
41 |
42 | virtual int GetSequenceParams(uint8_t* buffer, int buffer_size);
43 |
44 | private:
45 | bool InitParams(QsvParams& qsv_params);
46 | bool AllocateSurfaces();
47 | void FreeSurface();
48 | bool AllocateBuffer();
49 | void FreeBuffer();
50 | bool GetVideoParam();
51 | int EncodeFrame(int index, uint8_t* out_buf, uint32_t out_buf_size);
52 |
53 | bool is_initialized_ = false;
54 | bool use_d3d11_ = false;
55 | bool use_d3d9_ = false;
56 |
57 | mfxIMPL mfx_impl_;
58 | mfxVersion mfx_ver_;
59 | MFXVideoSession mfx_session_;
60 | mfxFrameAllocator mfx_allocator_;
61 | mfxVideoParam mfx_enc_params_;
62 | mfxVideoParam mfx_video_params_;
63 | mfxFrameAllocResponse mfx_alloc_response_;
64 | mfxExtCodingOption extended_coding_options_;
65 | mfxExtCodingOption2 extended_coding_options2_;
66 | mfxExtBuffer* extended_buffers_[2];
67 | mfxEncodeCtrl enc_ctrl_;
68 |
69 | std::unique_ptr<MFXVideoENCODE> mfx_encoder_;
70 |
71 | mfxBitstream mfx_enc_bs_;
72 | std::vector<mfxU8> bst_enc_data_;
73 | std::vector<mfxFrameSurface1> mfx_surfaces_;
74 |
75 | std::unique_ptr<mfxU8> sps_buffer_;
76 | std::unique_ptr<mfxU8> pps_buffer_;
77 | mfxU16 sps_size_ = 0;
78 | mfxU16 pps_size_ = 0;
79 | };
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/bits/linux_defs.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Intel Corporation
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in all
11 | // copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | // SOFTWARE.
20 |
21 | #pragma once
22 |
23 | #include <stdio.h>
24 | #include <string.h>
25 | #include <time.h>
26 | #include <unistd.h>
27 |
28 | #define MSDK_FOPEN(FH, FN, M) { FH=fopen(FN,M); }
29 | #define MSDK_SLEEP(X) { usleep(1000*(X)); }
30 | #define msdk_sscanf sscanf
31 | #define msdk_strcopy strcpy
32 |
33 | typedef timespec mfxTime;
34 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/bits/windows_defs.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 Intel Corporation
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in all
11 | // copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | // SOFTWARE.
20 |
21 | #pragma once
22 |
23 | #include <windows.h>
24 |
25 | #define MSDK_FOPEN(FH, FN, M) { fopen_s(&FH, FN, M); }
26 | #define MSDK_SLEEP(X) { Sleep(X); }
27 | #define msdk_sscanf sscanf_s
28 | #define msdk_strcopy strcpy_s
29 |
30 | typedef LARGE_INTEGER mfxTime;
31 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/include/mfxvp9.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************* *\
2 |
3 | Copyright (C) 2007-2018 Intel Corporation. All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 | - Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 | - Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 | - Neither the name of Intel Corporation nor the names of its contributors
13 | may be used to endorse or promote products derived from this software
14 | without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | File Name: mfxvp9.h
28 |
29 | *******************************************************************************/
30 | #ifndef __MFXVP9_H__
31 | #define __MFXVP9_H__
32 |
33 | #include "mfxdefs.h"
34 |
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif
38 |
39 |
40 | #ifdef __cplusplus
41 | } // extern "C"
42 | #endif
43 |
44 | #endif
45 |
46 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/include/mfxvstructures.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 |
3 | Copyright (C) 2013 Intel Corporation. All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 | - Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 | - Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 | - Neither the name of Intel Corporation nor the names of its contributors
13 | may be used to endorse or promote products derived from this software
14 | without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 | IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | File Name: mfxvstructures.h
28 |
29 | *******************************************************************************/
30 | #include "mfxstructures.h"
31 |
32 |
33 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/src/mfx_dispatcher_defs.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013-2019 Intel Corporation
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in all
11 | // copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | // SOFTWARE.
20 |
21 | #pragma once
22 | #include "mfxdefs.h"
23 | #include <cstring>
24 | #include <cstdio>
25 |
26 | #if defined(MFX_DISPATCHER_LOG)
27 | #include <string>
28 | #include <string.h>
29 | #endif
30 |
31 | #define MAX_PLUGIN_PATH 4096
32 | #define MAX_PLUGIN_NAME 4096
33 |
34 | #if _MSC_VER < 1400
35 | #define wcscpy_s(to,to_size, from) wcscpy(to, from)
36 | #endif
37 |
38 | // declare library module's handle
39 | typedef void * mfxModuleHandle;
40 |
41 | typedef void (MFX_CDECL * mfxFunctionPointer)(void);
42 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/QsvCodec/src/mfx_load_dll.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2012-2019 Intel Corporation
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
4 | // of this software and associated documentation files (the "Software"), to deal
5 | // in the Software without restriction, including without limitation the rights
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | // copies of the Software, and to permit persons to whom the Software is
8 | // furnished to do so, subject to the following conditions:
9 | //
10 | // The above copyright notice and this permission notice shall be included in all
11 | // copies or substantial portions of the Software.
12 | //
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | // SOFTWARE.
20 |
21 | #if !defined(__MFX_LOAD_DLL_H)
22 | #define __MFX_LOAD_DLL_H
23 |
24 | #include "mfx_dispatcher.h"
25 |
26 | namespace MFX
27 | {
28 |
29 |
30 | //
31 | // declare DLL loading routines
32 | //
33 |
34 | mfxStatus mfx_get_rt_dll_name(wchar_t *pPath, size_t pathSize);
35 | mfxStatus mfx_get_default_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType);
36 | mfxStatus mfx_get_default_plugin_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType);
37 |
38 | mfxStatus mfx_get_default_audio_dll_name(wchar_t *pPath, size_t pathSize, eMfxImplType implType);
39 |
40 |
41 | mfxModuleHandle mfx_dll_load(const wchar_t *file_name);
42 | //increments reference counter
43 | mfxModuleHandle mfx_get_dll_handle(const wchar_t *file_name);
44 | mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *func_name);
45 | bool mfx_dll_free(mfxModuleHandle handle);
46 |
47 | } // namespace MFX
48 |
49 | #endif // __MFX_LOAD_DLL_H
50 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/aac_encoder.h:
--------------------------------------------------------------------------------
1 | #ifndef _AAC_ENCODER_H
2 | #define _AAC_ENCODER_H
3 |
4 | #include <cstdint>
5 | #include <memory>
6 | #include "av_encoder.h"
7 | #include "audio_resampler.h"
8 |
9 | namespace ffmpeg {
10 |
11 | class AACEncoder : public Encoder
12 | {
13 | public:
14 | AACEncoder();
15 | virtual ~AACEncoder();
16 |
17 | virtual bool Init(AVConfig& audio_config);
18 | virtual void Destroy();
19 |
20 | uint32_t GetFrameSamples();
21 |
22 | AVPacketPtr Encode(const uint8_t *pcm, int samples);
23 |
24 | private:
25 | std::unique_ptr<Resampler> audio_resampler_;
26 | int64_t pts_ = 0;
27 | };
28 |
29 | }
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/audio_resampler.h:
--------------------------------------------------------------------------------
1 | #ifndef AUDIO_RESAMPLE_H
2 | #define AUDIO_RESAMPLE_H
3 |
4 | extern "C" {
5 | #include "libavutil/opt.h"
6 | #include "libavutil/channel_layout.h"
7 | #include "libavutil/samplefmt.h"
8 | #include "libswresample/swresample.h"
9 | #include "libavcodec/avcodec.h"
10 | }
11 |
12 | #include <cstdint>
13 | #include <memory>
14 |
15 | namespace ffmpeg {
16 |
17 | class Resampler
18 | {
19 | public:
20 | using AVFramePtr = std::shared_ptr<AVFrame>;
21 |
22 | Resampler& operator=(const Resampler&) = delete;
23 | Resampler(const Resampler&) = delete;
24 | Resampler();
25 | virtual ~Resampler();
26 |
27 | bool Init(int in_samplerate, int in_channels, AVSampleFormat in_format,
28 | int out_samplerate, int out_channels, AVSampleFormat out_format);
29 |
30 | void Destroy();
31 |
32 | int Convert(AVFramePtr in_frame, AVFramePtr& out_frame);
33 |
34 | private:
35 | SwrContext* swr_context_ = nullptr;
36 | uint8_t** dst_buf_ = nullptr;
37 |
38 | int in_samplerate_ = 0;
39 | int in_channels_ = 0;
40 | int in_bits_per_sample_ = 0;
41 | AVSampleFormat in_format_ = AV_SAMPLE_FMT_NONE;
42 |
43 | int out_samplerate_ = 0;
44 | int out_channels_ = 0;
45 | int out_bits_per_sample_ = 0;
46 | AVSampleFormat out_format_ = AV_SAMPLE_FMT_NONE;
47 |
48 | int convert_buffer_size_ = 0;
49 | uint8_t* convert_buffer_ = nullptr;
50 | };
51 |
52 | }
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/av_common.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEG_COMMON_H
2 | #define FFMPEG_COMMON_H
3 |
4 | extern "C" {
5 | #include "libavformat/avformat.h"
6 | #include "libavutil/error.h"
7 | }
8 | #include <cstdio>
9 | #include <memory>
10 |
11 | namespace ffmpeg {
12 |
13 | using AVPacketPtr = std::shared_ptr<AVPacket>;
14 | using AVFramePtr = std::shared_ptr<AVFrame>;
15 |
16 | }
17 |
18 | #define LOG(format, ...) \
19 | { \
20 | fprintf(stderr, "[%s:%d] " format " \n", \
21 | __FUNCTION__ , __LINE__, ##__VA_ARGS__); \
22 | }
23 |
24 | #define AV_LOG(code, format, ...) \
25 | { \
26 | char buf[1024] = { 0 }; \
27 | av_strerror(code, buf, 1023); \
28 | fprintf(stderr, "[%s:%d] " format " - %s. \n", \
29 | __FUNCTION__ , __LINE__, ##__VA_ARGS__, buf); \
30 | }
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/av_encoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEG_ENCODER_H
2 | #define FFMPEG_ENCODER_H
3 |
4 | #include <cstdint>
5 | #include <memory>
6 | #include "av_common.h"
7 | extern "C" {
8 | #include <libavcodec/avcodec.h>
9 | #include <libavformat/avformat.h>
10 | #include <libavutil/avutil.h>
11 | #include <libavutil/mem.h>
12 | #include <libavutil/fifo.h>
13 | #include <libswscale/swscale.h>
14 | #include <libswresample/swresample.h>
15 | #include <libavutil/imgutils.h>
16 | #include <libavutil/parseutils.h>
17 | #include <libavutil/opt.h>
18 | }
19 |
20 | namespace ffmpeg {
21 |
22 | struct VideoConfig
23 | {
24 | uint32_t width = 1920;
25 | uint32_t height = 1080;
26 | uint32_t bitrate = 4000000;
27 | uint32_t framerate = 25;
28 | uint32_t gop = 25;
29 | AVPixelFormat format = AV_PIX_FMT_BGRA;
30 | };
31 |
32 | struct AudioConfig
33 | {
34 | uint32_t channels = 2;
35 | uint32_t samplerate = 48000;
36 | uint32_t bitrate = 16000 * 4;
37 | AVSampleFormat format = AV_SAMPLE_FMT_S16;
38 | };
39 |
40 | struct AVConfig
41 | {
42 | VideoConfig video;
43 | AudioConfig audio;
44 | };
45 |
46 | class Encoder
47 | {
48 | public:
49 | Encoder & operator=(const Encoder &) = delete;
50 | virtual ~Encoder() {};
51 |
52 | virtual bool Init(AVConfig& config) = 0;
53 | virtual void Destroy() = 0;
54 |
55 | virtual void ForceIDR() {}
56 | virtual void SetBitrate(uint32_t bitrate_kbps) {}
57 |
58 | AVCodecContext* GetAVCodecContext() const
59 | { return codec_context_;}
60 |
61 | protected:
62 | bool is_initialized_ = false;
63 | AVConfig av_config_;
64 | AVCodecContext *codec_context_ = nullptr;
65 | };
66 |
67 | }
68 |
69 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/h264_encoder.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEG_H264_ENCODER_H
2 | #define FFMPEG_H264_ENCODER_H
3 |
4 | #include <cstdint>
5 | #include "av_encoder.h"
6 | #include "video_converter.h"
7 |
8 | namespace ffmpeg {
9 |
10 | class H264Encoder : public Encoder
11 | {
12 | public:
13 | virtual bool Init(AVConfig& video_config);
14 | virtual void Destroy();
15 |
16 | virtual AVPacketPtr Encode(const uint8_t *image, uint32_t width, uint32_t height, uint32_t image_size, uint64_t pts = 0);
17 |
18 | virtual void ForceIDR();
19 | virtual void SetBitrate(uint32_t bitrate_kbps);
20 |
21 | private:
22 | int64_t pts_ = 0;
23 | std::unique_ptr<VideoConverter> video_converter_;
24 | uint32_t in_width_ = 0;
25 | uint32_t in_height_ = 0;
26 | bool force_idr_ = false;
27 | };
28 |
29 | }
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/video_converter.cpp:
--------------------------------------------------------------------------------
1 | #include "video_converter.h"
2 |
3 | using namespace ffmpeg;
4 |
5 | VideoConverter::VideoConverter()
6 | {
7 |
8 | }
9 |
10 | VideoConverter::~VideoConverter()
11 | {
12 | Destroy();
13 | }
14 |
15 | bool VideoConverter::Init(int in_width, int in_height, AVPixelFormat in_format,
16 | int out_width, int out_height, AVPixelFormat out_format)
17 | {
18 | if (sws_context_) {
19 | return false;
20 | }
21 |
22 | if (sws_context_ == nullptr) {
23 | sws_context_ = sws_getContext(
24 | in_width, in_height, in_format,out_width,
25 | out_height, out_format,
26 | SWS_BICUBIC, NULL, NULL, NULL);
27 |
28 | out_width_ = out_width;
29 | out_height_ = out_height;
30 | out_format_ = out_format;
31 | return sws_context_ != nullptr;
32 | }
33 | return false;
34 | }
35 |
36 | void VideoConverter::Destroy()
37 | {
38 | if (sws_context_) {
39 | sws_freeContext(sws_context_);
40 | sws_context_ = nullptr;
41 | }
42 | }
43 |
44 | int VideoConverter::Convert(AVFramePtr in_frame, AVFramePtr& out_frame)
45 | {
46 | if (!sws_context_) {
47 | return -1;
48 | }
49 |
50 | out_frame.reset(av_frame_alloc(), [](AVFrame* ptr) {
51 | av_frame_free(&ptr);
52 | });
53 |
54 | out_frame->width = out_width_;
55 | out_frame->height = out_height_;
56 | out_frame->format = out_format_;
57 | out_frame->pts = in_frame->pts;
58 | out_frame->pkt_dts = in_frame->pkt_dts;
59 |
60 | if (av_frame_get_buffer(out_frame.get(), 32) != 0) {
61 | return -1;
62 | }
63 |
64 | int out_height = sws_scale(sws_context_, in_frame->data, in_frame->linesize, 0, in_frame->height,
65 | out_frame->data, out_frame->linesize);
66 | if (out_height < 0) {
67 | return -1;
68 | }
69 |
70 | return out_height;
71 | }
--------------------------------------------------------------------------------
/DesktopSharing/codec/avcodec/video_converter.h:
--------------------------------------------------------------------------------
1 | #ifndef FFMPEG_VIDEO_CONVERTER_H
2 | #define FFMPEG_VIDEO_CONVERTER_H
3 |
4 | #include <cstdint>
5 | #include <memory>
6 | #include "av_common.h"
7 | extern "C" {
8 | #include <libavformat/avformat.h>
9 | #include <libswscale/swscale.h>
10 | }
11 |
12 | namespace ffmpeg {
13 |
14 | class VideoConverter
15 | {
16 | public:
17 | VideoConverter& operator=(const VideoConverter&) = delete;
18 | VideoConverter(const VideoConverter&) = delete;
19 | VideoConverter();
20 | virtual ~VideoConverter();
21 |
22 | bool Init(int in_width, int in_height, AVPixelFormat in_format,
23 | int out_width, int out_height, AVPixelFormat out_format);
24 |
25 | void Destroy();
26 |
27 | int Convert(AVFramePtr in_frame, AVFramePtr& out_frame);
28 |
29 | private:
30 | SwsContext* sws_context_ = nullptr;
31 | int out_width_ = 0;
32 | int out_height_ = 0;
33 | AVPixelFormat out_format_ = AV_PIX_FMT_NONE;
34 | };
35 |
36 | }
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/DesktopSharing/imgui/imgui_impl_dx9.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer for DirectX9
2 | // This needs to be used along with a Platform Binding (e.g. Win32)
3 |
4 | // Implemented features:
5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID!
6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
7 |
8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
9 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
10 | // https://github.com/ocornut/imgui
11 |
12 | #pragma once
13 | #include "imgui.h" // IMGUI_IMPL_API
14 |
15 | struct IDirect3DDevice9;
16 |
17 | IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
18 | IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
19 | IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();
20 | IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
21 |
22 | // Use if you want to reset your rendering device without losing Dear ImGui state.
23 | IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
24 | IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
25 |
--------------------------------------------------------------------------------
/DesktopSharing/imgui/imgui_impl_opengl2.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer for OpenGL2 (legacy OpenGL, fixed pipeline)
2 | // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
3 |
4 | // Implemented features:
5 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
6 |
7 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
8 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
9 | // https://github.com/ocornut/imgui
10 |
11 | // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
12 | // **Prefer using the code in imgui_impl_opengl3.cpp**
13 | // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read.
14 | // If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more
15 | // complicated, will require your code to reset every single OpenGL attributes to their initial state, and might
16 | // confuse your GPU driver.
17 | // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API.
18 |
19 | #pragma once
20 | #include "imgui.h" // IMGUI_IMPL_API
21 |
22 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init();
23 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown();
24 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame();
25 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data);
26 |
27 | // Called by Init/NewFrame/Shutdown
28 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture();
29 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture();
30 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects();
31 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects();
32 |
--------------------------------------------------------------------------------
/DesktopSharing/imgui/imgui_impl_sdl.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Platform Binding for SDL2
2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
3 | // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
4 |
5 | // Implemented features:
6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
7 | // [X] Platform: Clipboard support.
8 | // [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
9 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
10 | // Missing features:
11 | // [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
12 |
13 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
14 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
15 | // https://github.com/ocornut/imgui
16 |
17 | #pragma once
18 | #include "imgui.h" // IMGUI_IMPL_API
19 |
20 | struct SDL_Window;
21 | typedef union SDL_Event SDL_Event;
22 |
23 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
24 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
25 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
26 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
27 | IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
28 | IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window);
29 | IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
30 |
--------------------------------------------------------------------------------
/DesktopSharing/libyuv/include/libyuv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_H_
12 | #define INCLUDE_LIBYUV_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/compare.h"
16 | #include "libyuv/convert.h"
17 | #include "libyuv/convert_argb.h"
18 | #include "libyuv/convert_from.h"
19 | #include "libyuv/convert_from_argb.h"
20 | #include "libyuv/cpu_id.h"
21 | #include "libyuv/mjpeg_decoder.h"
22 | #include "libyuv/planar_functions.h"
23 | #include "libyuv/rotate.h"
24 | #include "libyuv/rotate_argb.h"
25 | #include "libyuv/row.h"
26 | #include "libyuv/scale.h"
27 | #include "libyuv/scale_argb.h"
28 | #include "libyuv/scale_row.h"
29 | #include "libyuv/version.h"
30 | #include "libyuv/video_common.h"
31 |
32 | #endif // INCLUDE_LIBYUV_H_
33 |
--------------------------------------------------------------------------------
/DesktopSharing/libyuv/include/libyuv/rotate_argb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_
12 | #define INCLUDE_LIBYUV_ROTATE_ARGB_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/rotate.h" // For RotationMode.
16 |
17 | #ifdef __cplusplus
18 | namespace libyuv {
19 | extern "C" {
20 | #endif
21 |
22 | // Rotate ARGB frame
23 | LIBYUV_API
24 | int ARGBRotate(const uint8_t* src_argb,
25 | int src_stride_argb,
26 | uint8_t* dst_argb,
27 | int dst_stride_argb,
28 | int src_width,
29 | int src_height,
30 | enum RotationMode mode);
31 |
32 | #ifdef __cplusplus
33 | } // extern "C"
34 | } // namespace libyuv
35 | #endif
36 |
37 | #endif // INCLUDE_LIBYUV_ROTATE_ARGB_H_
38 |
--------------------------------------------------------------------------------
/DesktopSharing/libyuv/include/libyuv/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_VERSION_H_
12 | #define INCLUDE_LIBYUV_VERSION_H_
13 |
14 | #define LIBYUV_VERSION 1744
15 |
16 | #endif // INCLUDE_LIBYUV_VERSION_H_
17 |
--------------------------------------------------------------------------------
/DesktopSharing/libyuv/source/video_common.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #include "libyuv/video_common.h"
12 |
13 | #ifdef __cplusplus
14 | namespace libyuv {
15 | extern "C" {
16 | #endif
17 |
18 | struct FourCCAliasEntry {
19 | uint32_t alias;
20 | uint32_t canonical;
21 | };
22 |
23 | #define NUM_ALIASES 18
24 | static const struct FourCCAliasEntry kFourCCAliases[NUM_ALIASES] = {
25 | {FOURCC_IYUV, FOURCC_I420},
26 | {FOURCC_YU12, FOURCC_I420},
27 | {FOURCC_YU16, FOURCC_I422},
28 | {FOURCC_YU24, FOURCC_I444},
29 | {FOURCC_YUYV, FOURCC_YUY2},
30 | {FOURCC_YUVS, FOURCC_YUY2}, // kCMPixelFormat_422YpCbCr8_yuvs
31 | {FOURCC_HDYC, FOURCC_UYVY},
32 | {FOURCC_2VUY, FOURCC_UYVY}, // kCMPixelFormat_422YpCbCr8
33 | {FOURCC_JPEG, FOURCC_MJPG}, // Note: JPEG has DHT while MJPG does not.
34 | {FOURCC_DMB1, FOURCC_MJPG},
35 | {FOURCC_BA81, FOURCC_BGGR}, // deprecated.
36 | {FOURCC_RGB3, FOURCC_RAW},
37 | {FOURCC_BGR3, FOURCC_24BG},
38 | {FOURCC_CM32, FOURCC_BGRA}, // kCMPixelFormat_32ARGB
39 | {FOURCC_CM24, FOURCC_RAW}, // kCMPixelFormat_24RGB
40 | {FOURCC_L555, FOURCC_RGBO}, // kCMPixelFormat_16LE555
41 | {FOURCC_L565, FOURCC_RGBP}, // kCMPixelFormat_16LE565
42 | {FOURCC_5551, FOURCC_RGBO}, // kCMPixelFormat_16LE5551
43 | };
44 | // TODO(fbarchard): Consider mapping kCMPixelFormat_32BGRA to FOURCC_ARGB.
45 | // {FOURCC_BGRA, FOURCC_ARGB}, // kCMPixelFormat_32BGRA
46 |
47 | LIBYUV_API
48 | uint32_t CanonicalFourCC(uint32_t fourcc) {
49 | int i;
50 | for (i = 0; i < NUM_ALIASES; ++i) {
51 | if (kFourCCAliases[i].alias == fourcc) {
52 | return kFourCCAliases[i].canonical;
53 | }
54 | }
55 | // Not an alias, so return it as-is.
56 | return fourcc;
57 | }
58 |
59 | #ifdef __cplusplus
60 | } // extern "C"
61 | } // namespace libyuv
62 | #endif
63 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Acceptor.cpp:
--------------------------------------------------------------------------------
1 | #include "Acceptor.h"
2 | #include "EventLoop.h"
3 | #include "SocketUtil.h"
4 | #include "Logger.h"
5 |
6 | using namespace xop;
7 |
8 | Acceptor::Acceptor(EventLoop* eventLoop)
9 | : event_loop_(eventLoop)
10 | , tcp_socket_(new TcpSocket)
11 | {
12 |
13 | }
14 |
15 | Acceptor::~Acceptor()
16 | {
17 |
18 | }
19 |
20 | int Acceptor::Listen(std::string ip, uint16_t port)
21 | {
22 | std::lock_guard<std::mutex> locker(mutex_);
23 |
24 | if (tcp_socket_->GetSocket() > 0) {
25 | tcp_socket_->Close();
26 | }
27 |
28 | SOCKET sockfd = tcp_socket_->Create();
29 | channel_ptr_.reset(new Channel(sockfd));
30 | SocketUtil::SetReuseAddr(sockfd);
31 | SocketUtil::SetReusePort(sockfd);
32 | SocketUtil::SetNonBlock(sockfd);
33 |
34 | if (!tcp_socket_->Bind(ip, port)) {
35 | return -1;
36 | }
37 |
38 | if (!tcp_socket_->Listen(1024)) {
39 | return -1;
40 | }
41 |
42 | channel_ptr_->SetReadCallback([this]() { this->OnAccept(); });
43 | channel_ptr_->EnableReading();
44 | event_loop_->UpdateChannel(channel_ptr_);
45 | return 0;
46 | }
47 |
48 | void Acceptor::Close()
49 | {
50 | std::lock_guard<std::mutex> locker(mutex_);
51 |
52 | if (tcp_socket_->GetSocket() > 0) {
53 | event_loop_->RemoveChannel(channel_ptr_);
54 | tcp_socket_->Close();
55 | }
56 | }
57 |
58 | void Acceptor::OnAccept()
59 | {
60 | std::lock_guard<std::mutex> locker(mutex_);
61 |
62 | SOCKET socket = tcp_socket_->Accept();
63 | if (socket > 0) {
64 | if (new_connection_callback_) {
65 | new_connection_callback_(socket);
66 | }
67 | else {
68 | SocketUtil::Close(socket);
69 | }
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Acceptor.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_ACCEPTOR_H
2 | #define XOP_ACCEPTOR_H
3 |
4 | #include <functional>
5 | #include <memory>
6 | #include <mutex>
7 | #include "Channel.h"
8 | #include "TcpSocket.h"
9 |
10 | namespace xop
11 | {
12 |
13 | typedef std::function<void(SOCKET)> NewConnectionCallback;
14 |
15 | class EventLoop;
16 |
17 | class Acceptor
18 | {
19 | public:
20 | Acceptor(EventLoop* eventLoop);
21 | virtual ~Acceptor();
22 |
23 | void SetNewConnectionCallback(const NewConnectionCallback& cb)
24 | { new_connection_callback_ = cb; }
25 |
26 | int Listen(std::string ip, uint16_t port);
27 | void Close();
28 |
29 | private:
30 | void OnAccept();
31 |
32 | EventLoop* event_loop_ = nullptr;
33 | std::mutex mutex_;
34 | std::unique_ptr<TcpSocket> tcp_socket_;
35 | ChannelPtr channel_ptr_;
36 | NewConnectionCallback new_connection_callback_;
37 | };
38 |
39 | }
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/DesktopSharing/net/BufferWriter.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_BUFFER_WRITER_H
5 | #define XOP_BUFFER_WRITER_H
6 |
7 | #include <cstdint>
8 | #include <memory>
9 | #include <queue>
10 | #include <string>
11 | #include "Socket.h"
12 |
13 | namespace xop
14 | {
15 |
16 | void WriteUint32BE(char* p, uint32_t value);
17 | void WriteUint32LE(char* p, uint32_t value);
18 | void WriteUint24BE(char* p, uint32_t value);
19 | void WriteUint24LE(char* p, uint32_t value);
20 | void WriteUint16BE(char* p, uint16_t value);
21 | void WriteUint16LE(char* p, uint16_t value);
22 |
23 | class BufferWriter
24 | {
25 | public:
26 | BufferWriter(int capacity = kMaxQueueLength);
27 | ~BufferWriter() {}
28 |
29 | bool Append(std::shared_ptr<char> data, uint32_t size, uint32_t index=0);
30 | bool Append(const char* data, uint32_t size, uint32_t index=0);
31 | int Send(SOCKET sockfd, int timeout=0);
32 |
33 | bool IsEmpty() const
34 | { return buffer_.empty(); }
35 |
36 | bool IsFull() const
37 | { return ((int)buffer_.size() >= max_queue_length_ ? true : false); }
38 |
39 | uint32_t Size() const
40 | { return (uint32_t)buffer_.size(); }
41 |
42 | private:
43 | typedef struct
44 | {
45 | std::shared_ptr<char> data;
46 | uint32_t size;
47 | uint32_t writeIndex;
48 | } Packet;
49 |
50 | std::queue<Packet> buffer_;
51 | int max_queue_length_ = 0;
52 |
53 | static const int kMaxQueueLength = 10000;
54 | };
55 |
56 | }
57 |
58 | #endif
59 |
60 |
--------------------------------------------------------------------------------
/DesktopSharing/net/EpollTaskScheduler.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_EPOLL_TASK_SCHEDULER_H
5 | #define XOP_EPOLL_TASK_SCHEDULER_H
6 |
7 | #include "TaskScheduler.h"
8 | #include <mutex>
9 | #include <unordered_map>
10 |
11 | namespace xop
12 | {
13 | class EpollTaskScheduler : public TaskScheduler
14 | {
15 | public:
16 | EpollTaskScheduler(int id = 0);
17 | virtual ~EpollTaskScheduler();
18 |
19 | void UpdateChannel(ChannelPtr channel);
20 | void RemoveChannel(ChannelPtr& channel);
21 |
22 | // timeout: ms
23 | bool HandleEvent(int timeout);
24 |
25 | private:
26 | void Update(int operation, ChannelPtr& channel);
27 |
28 | int epollfd_ = -1;
29 | std::mutex mutex_;
30 | std::unordered_map<int, ChannelPtr> channels_;
31 | };
32 |
33 | }
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/DesktopSharing/net/EventLoop.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_EVENT_LOOP_H
5 | #define XOP_EVENT_LOOP_H
6 |
7 | #include <memory>
8 | #include <atomic>
9 | #include <unordered_map>
10 | #include <functional>
11 | #include <queue>
12 | #include <thread>
13 | #include <mutex>
14 |
15 | #include "SelectTaskScheduler.h"
16 | #include "EpollTaskScheduler.h"
17 | #include "Pipe.h"
18 | #include "Timer.h"
19 | #include "RingBuffer.h"
20 |
21 | #define TASK_SCHEDULER_PRIORITY_LOW 0
22 | #define TASK_SCHEDULER_PRIORITY_NORMAL 1
23 | #define TASK_SCHEDULER_PRIORITYO_HIGH 2
24 | #define TASK_SCHEDULER_PRIORITY_HIGHEST 3
25 | #define TASK_SCHEDULER_PRIORITY_REALTIME 4
26 |
27 | namespace xop
28 | {
29 |
30 | class EventLoop
31 | {
32 | public:
33 | EventLoop(const EventLoop&) = delete;
34 | EventLoop &operator = (const EventLoop&) = delete;
35 | EventLoop(uint32_t num_threads =1); //std::thread::hardware_concurrency()
36 | virtual ~EventLoop();
37 |
38 | std::shared_ptr<TaskScheduler> GetTaskScheduler();
39 |
40 | bool AddTriggerEvent(TriggerEvent callback);
41 | TimerId AddTimer(TimerEvent timerEvent, uint32_t msec);
42 | void RemoveTimer(TimerId timerId);
43 | void UpdateChannel(ChannelPtr channel);
44 | void RemoveChannel(ChannelPtr& channel);
45 |
46 | void Loop();
47 | void Quit();
48 |
49 | private:
50 | std::mutex mutex_;
51 | uint32_t num_threads_ = 1;
52 | uint32_t index_ = 1;
53 | std::vector<std::shared_ptr<TaskScheduler>> task_schedulers_;
54 | std::vector<std::shared_ptr<std::thread>> threads_;
55 | };
56 |
57 | }
58 |
59 | #endif
60 |
61 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Logger.cpp:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #if defined(WIN32) || defined(_WIN32)
5 | #ifndef _CRT_SECURE_NO_WARNINGS
6 | #define _CRT_SECURE_NO_WARNINGS
7 | #endif
8 | #endif
9 |
10 | #include "Logger.h"
11 | #include "Timestamp.h"
12 | #include <stdarg.h>
13 | #include <iostream>
14 |
15 | using namespace xop;
16 |
17 | const char* Priority_To_String[] =
18 | {
19 | "DEBUG",
20 | "CONFIG",
21 | "INFO",
22 | "WARNING",
23 | "ERROR"
24 | };
25 |
26 | Logger::Logger()
27 | {
28 |
29 | }
30 |
31 | Logger& Logger::Instance()
32 | {
33 | static Logger s_logger;
34 | return s_logger;
35 | }
36 |
37 | Logger::~Logger()
38 | {
39 |
40 | }
41 |
42 | void Logger::Init(char *pathname)
43 | {
44 | std::unique_lock<std::mutex> lock(mutex_);
45 |
46 | if (pathname != nullptr) {
47 | ofs_.open(pathname, std::ios::out | std::ios::binary);
48 | if (ofs_.fail())
49 | {
50 | std::cerr << "Failed to open logfile." << std::endl;
51 | }
52 | }
53 | }
54 |
55 | void Logger::Exit()
56 | {
57 | std::unique_lock<std::mutex> lock(mutex_);
58 |
59 | if (ofs_.is_open()) {
60 | ofs_.close();
61 | }
62 | }
63 |
64 | void Logger::Log(Priority priority, const char* __file, const char* __func, int __line, const char *fmt, ...)
65 | {
66 | std::unique_lock<std::mutex> lock(mutex_);
67 |
68 | char buf[2048] = {0};
69 | sprintf(buf, "[%s][%s:%s:%d] ", Priority_To_String[priority], __file, __func, __line);
70 | va_list args;
71 | va_start(args, fmt);
72 | vsprintf(buf + strlen(buf), fmt, args);
73 | va_end(args);
74 | this->Write(std::string(buf));
75 | }
76 |
77 | void Logger::Log2(Priority priority, const char *fmt, ...)
78 | {
79 | std::unique_lock<std::mutex> lock(mutex_);
80 |
81 | char buf[4096] = { 0 };
82 | sprintf(buf, "[%s] ", Priority_To_String[priority]);
83 | va_list args;
84 | va_start(args, fmt);
85 | vsprintf(buf + strlen(buf), fmt, args);
86 | va_end(args);
87 | this->Write(std::string(buf));
88 | }
89 |
90 | void Logger::Write(std::string info)
91 | {
92 | if (ofs_.is_open()) {
93 | ofs_ << "[" << Timestamp::Localtime() << "]"
94 | << info << std::endl;
95 | }
96 |
97 | std::cout << "[" << Timestamp::Localtime() << "]"
98 | << info << std::endl;
99 | }
100 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Logger.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2020-5-15
3 |
4 | #ifndef XOP_LOGGER_H
5 | #define XOP_LOGGER_H
6 |
7 | #include <string>
8 | #include <mutex>
9 | #include <thread>
10 | #include <fstream>
11 | #include <cstring>
12 | #include <iostream>
13 | #include <sstream>
14 |
15 | namespace xop {
16 |
17 |
18 | enum Priority
19 | {
20 | LOG_DEBUG, LOG_STATE, LOG_INFO, LOG_WARNING, LOG_ERROR,
21 | };
22 |
23 | class Logger
24 | {
25 | public:
26 | Logger &operator=(const Logger &) = delete;
27 | Logger(const Logger &) = delete;
28 | static Logger& Instance();
29 | ~Logger();
30 |
31 | void Init(char *pathname = nullptr);
32 | void Exit();
33 |
34 | void Log(Priority priority, const char* __file, const char* __func, int __line, const char *fmt, ...);
35 | void Log2(Priority priority, const char *fmt, ...);
36 |
37 | private:
38 | void Write(std::string buf);
39 | Logger();
40 |
41 | std::mutex mutex_;
42 | std::ofstream ofs_;
43 | };
44 |
45 | }
46 |
47 | #ifdef _DEBUG
48 | #define LOG_DEBUG(fmt, ...) xop::Logger::Instance().Log(LOG_DEBUG, __FILE__, __FUNCTION__,__LINE__, fmt, ##__VA_ARGS__)
49 | #else
50 | #define LOG_DEBUG(fmt, ...)
51 | #endif
52 | #define LOG_INFO(fmt, ...) xop::Logger::Instance().Log2(LOG_INFO, fmt, ##__VA_ARGS__)
53 | #define LOG_ERROR(fmt, ...) xop::Logger::Instance().Log(LOG_ERROR, __FILE__, __FUNCTION__,__LINE__, fmt, ##__VA_ARGS__)
54 |
55 | #endif
56 |
57 |
--------------------------------------------------------------------------------
/DesktopSharing/net/MemoryManager.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_MEMMORY_MANAGER_H
2 | #define XOP_MEMMORY_MANAGER_H
3 |
4 | #include <stdio.h>
5 | #include <stdlib.h>
6 | #include <stdint.h>
7 | #include <mutex>
8 |
9 | namespace xop
10 | {
11 |
12 | void* Alloc(uint32_t size);
13 | void Free(void *ptr);
14 |
15 | class MemoryPool;
16 |
17 | struct MemoryBlock
18 | {
19 | uint32_t block_id = 0;
20 | MemoryPool *pool = nullptr;
21 | MemoryBlock *next = nullptr;
22 | };
23 |
24 | class MemoryPool
25 | {
26 | public:
27 | MemoryPool();
28 | virtual ~MemoryPool();
29 |
30 | void Init(uint32_t size, uint32_t n);
31 | void* Alloc(uint32_t size);
32 | void Free(void* ptr);
33 |
34 | size_t BolckSize() const
35 | { return block_size_; }
36 |
37 | //private:
38 | char* memory_ = nullptr;
39 | uint32_t block_size_ = 0;
40 | uint32_t num_blocks_ = 0;
41 | MemoryBlock* head_ = nullptr;
42 | std::mutex mutex_;
43 | };
44 |
45 | class MemoryManager
46 | {
47 | public:
48 | static MemoryManager& Instance();
49 | ~MemoryManager();
50 |
51 | void* Alloc(uint32_t size);
52 | void Free(void* ptr);
53 |
54 | private:
55 | MemoryManager();
56 |
57 | static const int kMaxMemoryPool = 3;
58 | MemoryPool memory_pools_[kMaxMemoryPool];
59 | };
60 |
61 | }
62 | #endif
63 |
--------------------------------------------------------------------------------
/DesktopSharing/net/NetInterface.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_NET_INTERFACE_H
5 | #define XOP_NET_INTERFACE_H
6 |
7 | #include <string>
8 |
9 | namespace xop {
10 |
11 | class NetInterface
12 | {
13 | public:
14 | static std::string GetLocalIPAddress();
15 | };
16 |
17 | }
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Pipe.cpp:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #include "Pipe.h"
5 | #include "SocketUtil.h"
6 | #include <random>
7 | #include <string>
8 | #include <array>
9 |
10 | using namespace xop;
11 |
12 | Pipe::Pipe()
13 | {
14 |
15 | }
16 |
17 | bool Pipe::Create()
18 | {
19 | #if defined(WIN32) || defined(_WIN32)
20 | TcpSocket rp(socket(AF_INET, SOCK_STREAM, 0)), wp(socket(AF_INET, SOCK_STREAM, 0));
21 | std::random_device rd;
22 |
23 | pipe_fd_[0] = rp.GetSocket();
24 | pipe_fd_[1] = wp.GetSocket();
25 | uint16_t port = 0;
26 | int again = 5;
27 |
28 | while(again--) {
29 | port = rd();
30 | if (rp.Bind("127.0.0.1", port)) {
31 | break;
32 | }
33 | }
34 |
35 | if (again == 0) {
36 | return false;
37 | }
38 |
39 | if (!rp.Listen(1)) {
40 | return false;
41 | }
42 |
43 | if (!wp.Connect("127.0.0.1", port)) {
44 | return false;
45 | }
46 |
47 | pipe_fd_[0] = rp.Accept();
48 | if (pipe_fd_[0] < 0) {
49 | return false;
50 | }
51 |
52 | SocketUtil::SetNonBlock(pipe_fd_[0]);
53 | SocketUtil::SetNonBlock(pipe_fd_[1]);
54 | #elif defined(__linux) || defined(__linux__)
55 | if (pipe2(pipe_fd_, O_NONBLOCK | O_CLOEXEC) < 0) {
56 | return false;
57 | }
58 | #endif
59 | return true;
60 | }
61 |
62 | int Pipe::Write(void *buf, int len)
63 | {
64 | #if defined(WIN32) || defined(_WIN32)
65 | return ::send(pipe_fd_[1], (char *)buf, len, 0);
66 | #elif defined(__linux) || defined(__linux__)
67 | return ::write(pipe_fd_[1], buf, len);
68 | #endif
69 | }
70 |
71 | int Pipe::Read(void *buf, int len)
72 | {
73 | #if defined(WIN32) || defined(_WIN32)
74 | return recv(pipe_fd_[0], (char *)buf, len, 0);
75 | #elif defined(__linux) || defined(__linux__)
76 | return ::read(pipe_fd_[0], buf, len);
77 | #endif
78 | }
79 |
80 | void Pipe::Close()
81 | {
82 | #if defined(WIN32) || defined(_WIN32)
83 | closesocket(pipe_fd_[0]);
84 | closesocket(pipe_fd_[1]);
85 | #elif defined(__linux) || defined(__linux__)
86 | ::close(pipe_fd_[0]);
87 | ::close(pipe_fd_[1]);
88 | #endif
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Pipe.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_PIPE_H
5 | #define XOP_PIPE_H
6 |
7 | #include "TcpSocket.h"
8 |
9 | namespace xop
10 | {
11 |
12 | class Pipe
13 | {
14 | public:
15 | Pipe();
16 | bool Create();
17 | int Write(void *buf, int len);
18 | int Read(void *buf, int len);
19 | void Close();
20 |
21 | SOCKET Read() const { return pipe_fd_[0]; }
22 | SOCKET Write() const { return pipe_fd_[1]; }
23 |
24 | private:
25 | SOCKET pipe_fd_[2];
26 | };
27 |
28 | }
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/DesktopSharing/net/RingBuffer.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_RING_BUFFER_H
5 | #define XOP_RING_BUFFER_H
6 |
7 | #include <vector>
8 | #include <memory>
9 | #include <atomic>
10 | #include <iostream>
11 |
12 | namespace xop
13 | {
14 |
15 | template <typename T>
16 | class RingBuffer
17 | {
18 | public:
19 | RingBuffer(int capacity=60)
20 | : capacity_(capacity)
21 | , num_datas_(0)
22 | , buffer_(capacity)
23 | { }
24 |
25 | virtual ~RingBuffer() { }
26 |
27 | bool Push(const T& data)
28 | {
29 | return pushData(std::forward<T>(data));
30 | }
31 |
32 | bool Push(T&& data)
33 | {
34 | return PushData(data);
35 | }
36 |
37 | bool Pop(T& data)
38 | {
39 | if(num_datas_ > 0) {
40 | data = std::move(buffer_[get_pos_]);
41 | Add(get_pos_);
42 | num_datas_--;
43 | return true;
44 | }
45 |
46 | return false;
47 | }
48 |
49 | bool IsFull() const
50 | {
51 | return ((num_datas_==capacity_) ? true : false);
52 | }
53 |
54 | bool IsEmpty() const
55 | {
56 | return ((num_datas_==0) ? true : false);
57 | }
58 |
59 | int Size() const
60 | {
61 | return num_datas_;
62 | }
63 |
64 | private:
65 | template <typename F>
66 | bool PushData(F&& data)
67 | {
68 | if (num_datas_ < capacity_)
69 | {
70 | buffer_[put_pos_] = std::forward<F>(data);
71 | Add(put_pos_);
72 | num_datas_++;
73 | return true;
74 | }
75 |
76 | return false;
77 | }
78 |
79 | void Add(int& pos)
80 | {
81 | pos = (((pos+1)==capacity_) ? 0 : (pos+1));
82 | }
83 |
84 | int capacity_ = 0;
85 | int put_pos_ = 0;
86 | int get_pos_ = 0;
87 |
88 | std::atomic_int num_datas_;
89 | std::vector<T> buffer_;
90 | };
91 |
92 | }
93 |
94 | #endif
95 |
96 |
97 |
--------------------------------------------------------------------------------
/DesktopSharing/net/SelectTaskScheduler.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_SELECT_TASK_SCHEDULER_H
5 | #define XOP_SELECT_TASK_SCHEDULER_H
6 |
7 | #include "TaskScheduler.h"
8 | #include "Socket.h"
9 | #include <mutex>
10 | #include <unordered_map>
11 |
12 | #if defined(__linux) || defined(__linux__)
13 | #include <sys/select.h>
14 | #include <sys/time.h>
15 | #include <sys/types.h>
16 | #include <unistd.h>
17 | #endif
18 |
19 | namespace xop
20 | {
21 |
22 | class SelectTaskScheduler : public TaskScheduler
23 | {
24 | public:
25 | SelectTaskScheduler(int id = 0);
26 | virtual ~SelectTaskScheduler();
27 |
28 | void UpdateChannel(ChannelPtr channel);
29 | void RemoveChannel(ChannelPtr& channel);
30 | bool HandleEvent(int timeout);
31 |
32 | private:
33 | fd_set fd_read_backup_;
34 | fd_set fd_write_backup_;
35 | fd_set fd_exp_backup_;
36 | SOCKET maxfd_ = 0;
37 |
38 | bool is_fd_read_reset_ = false;
39 | bool is_fd_write_reset_ = false;
40 | bool is_fd_exp_reset_ = false;
41 |
42 | std::mutex mutex_;
43 | std::unordered_map<SOCKET, ChannelPtr> channels_;
44 | };
45 |
46 | }
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Socket.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_SOCKET_H
5 | #define XOP_SOCKET_H
6 |
7 | #if defined(__linux) || defined(__linux__)
8 | #include <sys/types.h>
9 | #include <sys/socket.h>
10 | #include <sys/ioctl.h>
11 | #include <netinet/in.h>
12 | #include <netinet/ether.h>
13 | #include <netinet/ip.h>
14 | #include <netpacket/packet.h>
15 | #include <arpa/inet.h>
16 | #include <net/ethernet.h>
17 | #include <net/route.h>
18 | #include <netdb.h>
19 | #include <net/if.h>
20 | #include <unistd.h>
21 | #include <fcntl.h>
22 | #include <errno.h>
23 | #include <sys/select.h>
24 | #define SOCKET int
25 | #define INVALID_SOCKET (-1)
26 | #define SOCKET_ERROR (-1)
27 |
28 | #elif defined(WIN32) || defined(_WIN32)
29 | #define FD_SETSIZE 1024
30 | #define WIN32_LEAN_AND_MEAN
31 | #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
32 | #define _WINSOCK_DEPRECATED_NO_WARNINGS
33 | #endif
34 | #include <WinSock2.h>
35 | #include <windows.h>
36 | #include <ws2tcpip.h>
37 | #include <iphlpapi.h>
38 | #define SHUT_RD 0
39 | #define SHUT_WR 1
40 | #define SHUT_RDWR 2
41 |
42 | #else
43 |
44 | #endif
45 |
46 | #include <cstdint>
47 | #include <cstring>
48 |
49 | #endif // _XOP_SOCKET_H
50 |
--------------------------------------------------------------------------------
/DesktopSharing/net/SocketUtil.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_SOCKET_UTIL_H
5 | #define XOP_SOCKET_UTIL_H
6 |
7 | #include "Socket.h"
8 | #include <string>
9 |
10 | namespace xop
11 | {
12 |
13 | class SocketUtil
14 | {
15 | public:
16 | static bool Bind(SOCKET sockfd, std::string ip, uint16_t port);
17 | static void SetNonBlock(SOCKET fd);
18 | static void SetBlock(SOCKET fd, int write_timeout=0);
19 | static void SetReuseAddr(SOCKET fd);
20 | static void SetReusePort(SOCKET sockfd);
21 | static void SetNoDelay(SOCKET sockfd);
22 | static void SetKeepAlive(SOCKET sockfd);
23 | static void SetNoSigpipe(SOCKET sockfd);
24 | static void SetSendBufSize(SOCKET sockfd, int size);
25 | static void SetRecvBufSize(SOCKET sockfd, int size);
26 | static std::string GetPeerIp(SOCKET sockfd);
27 | static std::string GetSocketIp(SOCKET sockfd);
28 | static int GetSocketAddr(SOCKET sockfd, struct sockaddr_in* addr);
29 | static uint16_t GetPeerPort(SOCKET sockfd);
30 | static int GetPeerAddr(SOCKET sockfd, struct sockaddr_in *addr);
31 | static void Close(SOCKET sockfd);
32 | static bool Connect(SOCKET sockfd, std::string ip, uint16_t port, int timeout=0);
33 | };
34 |
35 | }
36 |
37 | #endif // _SOCKET_UTIL_H
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TaskScheduler.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_TASK_SCHEDULER_H
5 | #define XOP_TASK_SCHEDULER_H
6 |
7 | #include "Channel.h"
8 | #include "Pipe.h"
9 | #include "Timer.h"
10 | #include "RingBuffer.h"
11 |
12 | namespace xop
13 | {
14 |
15 | typedef std::function<void(void)> TriggerEvent;
16 |
17 | class TaskScheduler
18 | {
19 | public:
20 | TaskScheduler(int id=1);
21 | virtual ~TaskScheduler();
22 |
23 | void Start();
24 | void Stop();
25 | TimerId AddTimer(TimerEvent timerEvent, uint32_t msec);
26 | void RemoveTimer(TimerId timerId);
27 | bool AddTriggerEvent(TriggerEvent callback);
28 |
29 | virtual void UpdateChannel(ChannelPtr channel) { };
30 | virtual void RemoveChannel(ChannelPtr& channel) { };
31 | virtual bool HandleEvent(int timeout) { return false; };
32 |
33 | int GetId() const
34 | { return id_; }
35 |
36 | protected:
37 | void Wake();
38 | void HandleTriggerEvent();
39 |
40 | int id_ = 0;
41 | std::atomic_bool is_shutdown_;
42 | std::unique_ptr<Pipe> wakeup_pipe_;
43 | std::shared_ptr<Channel> wakeup_channel_;
44 | std::unique_ptr<xop::RingBuffer<TriggerEvent>> trigger_events_;
45 |
46 | std::mutex mutex_;
47 | TimerQueue timer_queue_;
48 |
49 | static const char kTriggetEvent = 1;
50 | static const char kTimerEvent = 2;
51 | static const int kMaxTriggetEvents = 50000;
52 | };
53 |
54 | }
55 | #endif
56 |
57 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TcpConnection.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_TCP_CONNECTION_H
2 | #define XOP_TCP_CONNECTION_H
3 |
4 | #include <atomic>
5 | #include <mutex>
6 | #include "TaskScheduler.h"
7 | #include "BufferReader.h"
8 | #include "BufferWriter.h"
9 | #include "Channel.h"
10 | #include "SocketUtil.h"
11 |
12 | namespace xop
13 | {
14 |
15 | class TcpConnection : public std::enable_shared_from_this<TcpConnection>
16 | {
17 | public:
18 | using Ptr = std::shared_ptr<TcpConnection>;
19 | using DisconnectCallback = std::function<void(std::shared_ptr<TcpConnection> conn)> ;
20 | using CloseCallback = std::function<void(std::shared_ptr<TcpConnection> conn)>;
21 | using ReadCallback = std::function<bool(std::shared_ptr<TcpConnection> conn, xop::BufferReader& buffer)>;
22 |
23 | TcpConnection(TaskScheduler *task_scheduler, SOCKET sockfd);
24 | virtual ~TcpConnection();
25 |
26 | TaskScheduler* GetTaskScheduler() const
27 | { return task_scheduler_; }
28 |
29 | void SetReadCallback(const ReadCallback& cb)
30 | { read_cb_ = cb; }
31 |
32 | void SetCloseCallback(const CloseCallback& cb)
33 | { close_cb_ = cb; }
34 |
35 | void Send(std::shared_ptr<char> data, uint32_t size);
36 | void Send(const char *data, uint32_t size);
37 |
38 | void Disconnect();
39 |
40 | bool IsClosed() const
41 | { return is_closed_; }
42 |
43 | SOCKET GetSocket() const
44 | { return channel_->GetSocket(); }
45 |
46 | uint16_t GetPort() const
47 | { return SocketUtil::GetPeerPort(channel_->GetSocket()); }
48 |
49 | std::string GetIp() const
50 | { return SocketUtil::GetPeerIp(channel_->GetSocket()); }
51 |
52 | protected:
53 | friend class TcpServer;
54 |
55 | virtual void HandleRead();
56 | virtual void HandleWrite();
57 | virtual void HandleClose();
58 | virtual void HandleError();
59 |
60 | void SetDisconnectCallback(const DisconnectCallback& cb)
61 | { disconnect_cb_ = cb; }
62 |
63 | TaskScheduler* task_scheduler_;
64 | std::unique_ptr<xop::BufferReader> read_buffer_;
65 | std::unique_ptr<xop::BufferWriter> write_buffer_;
66 | std::atomic_bool is_closed_;
67 |
68 | private:
69 | void Close();
70 |
71 | std::shared_ptr<xop::Channel> channel_;
72 | std::mutex mutex_;
73 | DisconnectCallback disconnect_cb_;
74 | CloseCallback close_cb_;
75 | ReadCallback read_cb_;
76 | };
77 |
78 | }
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TcpServer.cpp:
--------------------------------------------------------------------------------
1 | #include "TcpServer.h"
2 | #include "Acceptor.h"
3 | #include "EventLoop.h"
4 | #include "Logger.h"
5 | #include <cstdio>
6 |
7 | using namespace xop;
8 | using namespace std;
9 |
10 | TcpServer::TcpServer(EventLoop* event_loop)
11 | : event_loop_(event_loop)
12 | , port_(0)
13 | , acceptor_(new Acceptor(event_loop_))
14 | , is_started_(false)
15 | {
16 | acceptor_->SetNewConnectionCallback([this](SOCKET sockfd) {
17 | TcpConnection::Ptr conn = this->OnConnect(sockfd);
18 | if (conn) {
19 | this->AddConnection(sockfd, conn);
20 | conn->SetDisconnectCallback([this](TcpConnection::Ptr conn) {
21 | auto scheduler = conn->GetTaskScheduler();
22 | SOCKET sockfd = conn->GetSocket();
23 | if (!scheduler->AddTriggerEvent([this, sockfd] {this->RemoveConnection(sockfd); })) {
24 | scheduler->AddTimer([this, sockfd]() {this->RemoveConnection(sockfd); return false; }, 100);
25 | }
26 | });
27 | }
28 | });
29 | }
30 |
31 | TcpServer::~TcpServer()
32 | {
33 | Stop();
34 | }
35 |
36 | bool TcpServer::Start(std::string ip, uint16_t port)
37 | {
38 | Stop();
39 |
40 | if (!is_started_) {
41 | if (acceptor_->Listen(ip, port) < 0) {
42 | return false;
43 | }
44 |
45 | port_ = port;
46 | ip_ = ip;
47 | is_started_ = true;
48 | return true;
49 | }
50 |
51 | return false;
52 | }
53 |
54 | void TcpServer::Stop()
55 | {
56 | if (is_started_) {
57 | mutex_.lock();
58 | for (auto iter : connections_) {
59 | iter.second->Disconnect();
60 | }
61 | mutex_.unlock();
62 |
63 | acceptor_->Close();
64 | is_started_ = false;
65 |
66 | while (1) {
67 | Timer::Sleep(10);
68 | if (connections_.empty()) {
69 | break;
70 | }
71 | }
72 | }
73 | }
74 |
75 | TcpConnection::Ptr TcpServer::OnConnect(SOCKET sockfd)
76 | {
77 | return std::make_shared<TcpConnection>(event_loop_->GetTaskScheduler().get(), sockfd);
78 | }
79 |
80 | void TcpServer::AddConnection(SOCKET sockfd, TcpConnection::Ptr tcpConn)
81 | {
82 | std::lock_guard<std::mutex> locker(mutex_);
83 | connections_.emplace(sockfd, tcpConn);
84 | }
85 |
86 | void TcpServer::RemoveConnection(SOCKET sockfd)
87 | {
88 | std::lock_guard<std::mutex> locker(mutex_);
89 | connections_.erase(sockfd);
90 | }
91 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TcpServer.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-11-10
3 |
4 | #ifndef XOP_TCPSERVER_H
5 | #define XOP_TCPSERVER_H
6 |
7 | #include <memory>
8 | #include <string>
9 | #include <mutex>
10 | #include <unordered_map>
11 | #include "Socket.h"
12 | #include "TcpConnection.h"
13 |
14 | namespace xop
15 | {
16 |
17 | class Acceptor;
18 | class EventLoop;
19 |
20 | class TcpServer
21 | {
22 | public:
23 | TcpServer(EventLoop* event_loop);
24 | virtual ~TcpServer();
25 |
26 | virtual bool Start(std::string ip, uint16_t port);
27 | virtual void Stop();
28 |
29 | std::string GetIPAddress() const
30 | { return ip_; }
31 |
32 | uint16_t GetPort() const
33 | { return port_; }
34 |
35 | protected:
36 | virtual TcpConnection::Ptr OnConnect(SOCKET sockfd);
37 | virtual void AddConnection(SOCKET sockfd, TcpConnection::Ptr tcp_conn);
38 | virtual void RemoveConnection(SOCKET sockfd);
39 |
40 | EventLoop* event_loop_;
41 | uint16_t port_;
42 | std::string ip_;
43 | std::unique_ptr<Acceptor> acceptor_;
44 | bool is_started_;
45 | std::mutex mutex_;
46 | std::unordered_map<SOCKET, TcpConnection::Ptr> connections_;
47 | };
48 |
49 | }
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TcpSocket.cpp:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #include "TcpSocket.h"
5 | #include "Socket.h"
6 | #include "SocketUtil.h"
7 | #include "Logger.h"
8 |
9 | using namespace xop;
10 |
11 | TcpSocket::TcpSocket(SOCKET sockfd)
12 | : sockfd_(sockfd)
13 | {
14 |
15 | }
16 |
17 | TcpSocket::~TcpSocket()
18 | {
19 |
20 | }
21 |
22 | SOCKET TcpSocket::Create()
23 | {
24 | sockfd_ = ::socket(AF_INET, SOCK_STREAM, 0);
25 | return sockfd_;
26 | }
27 |
28 | bool TcpSocket::Bind(std::string ip, uint16_t port)
29 | {
30 | struct sockaddr_in addr = {0};
31 | addr.sin_family = AF_INET;
32 | addr.sin_addr.s_addr = inet_addr(ip.c_str());
33 | addr.sin_port = htons(port);
34 |
35 | if(::bind(sockfd_, (struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) {
36 | LOG_DEBUG(" <socket=%d> bind <%s:%u> failed.\n", sockfd_, ip.c_str(), port);
37 | return false;
38 | }
39 |
40 | return true;
41 | }
42 |
43 | bool TcpSocket::Listen(int backlog)
44 | {
45 | if(::listen(sockfd_, backlog) == SOCKET_ERROR) {
46 | LOG_DEBUG("<socket=%d> listen failed.\n", sockfd_);
47 | return false;
48 | }
49 |
50 | return true;
51 | }
52 |
53 | SOCKET TcpSocket::Accept()
54 | {
55 | struct sockaddr_in addr = {0};
56 | socklen_t addrlen = sizeof addr;
57 |
58 | SOCKET socket_fd = ::accept(sockfd_, (struct sockaddr*)&addr, &addrlen);
59 | return socket_fd;
60 | }
61 |
62 | bool TcpSocket::Connect(std::string ip, uint16_t port, int timeout)
63 | {
64 | if(!SocketUtil::Connect(sockfd_, ip, port, timeout)) {
65 | LOG_DEBUG("<socket=%d> connect failed.\n", sockfd_);
66 | return false;
67 | }
68 |
69 | return true;
70 | }
71 |
72 | void TcpSocket::Close()
73 | {
74 | #if defined(__linux) || defined(__linux__)
75 | ::close(sockfd_);
76 | #elif defined(WIN32) || defined(_WIN32)
77 | closesocket(sockfd_);
78 | #else
79 |
80 | #endif
81 | sockfd_ = 0;
82 | }
83 |
84 | void TcpSocket::ShutdownWrite()
85 | {
86 | shutdown(sockfd_, SHUT_WR);
87 | sockfd_ = 0;
88 | }
89 |
--------------------------------------------------------------------------------
/DesktopSharing/net/TcpSocket.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_TCP_SOCKET_H
5 | #define XOP_TCP_SOCKET_H
6 |
7 | #include <cstdint>
8 | #include <string>
9 | #include "Socket.h"
10 |
11 | namespace xop
12 | {
13 |
14 | class TcpSocket
15 | {
16 | public:
17 | TcpSocket(SOCKET sockfd=-1);
18 | virtual ~TcpSocket();
19 |
20 | SOCKET Create();
21 | bool Bind(std::string ip, uint16_t port);
22 | bool Listen(int backlog);
23 | SOCKET Accept();
24 | bool Connect(std::string ip, uint16_t port, int timeout = 0);
25 | void Close();
26 | void ShutdownWrite();
27 | SOCKET GetSocket() const { return sockfd_; }
28 |
29 | private:
30 | SOCKET sockfd_ = -1;
31 | };
32 |
33 | }
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Timer.cpp:
--------------------------------------------------------------------------------
1 | #include "Timer.h"
2 | #include <iostream>
3 |
4 | using namespace xop;
5 | using namespace std;
6 | using namespace std::chrono;
7 |
8 | TimerId TimerQueue::AddTimer(const TimerEvent& event, uint32_t ms)
9 | {
10 | std::lock_guard<std::mutex> locker(mutex_);
11 |
12 | int64_t timeout = GetTimeNow();
13 | TimerId timer_id = ++last_timer_id_;
14 |
15 | auto timer = make_shared<Timer>(event, ms);
16 | timer->SetNextTimeout(timeout);
17 | timers_.emplace(timer_id, timer);
18 | events_.emplace(std::pair<int64_t, TimerId>(timeout + ms, timer_id), std::move(timer));
19 | return timer_id;
20 | }
21 |
22 | void TimerQueue::RemoveTimer(TimerId timerId)
23 | {
24 | std::lock_guard<std::mutex> locker(mutex_);
25 |
26 | auto iter = timers_.find(timerId);
27 | if (iter != timers_.end()) {
28 | int64_t timeout = iter->second->getNextTimeout();
29 | events_.erase(std::pair<int64_t, TimerId>(timeout, timerId));
30 | timers_.erase(timerId);
31 | }
32 | }
33 |
34 | int64_t TimerQueue::GetTimeNow()
35 | {
36 | auto time_point = steady_clock::now();
37 | return duration_cast<milliseconds>(time_point.time_since_epoch()).count();
38 | }
39 |
40 | int64_t TimerQueue::GetTimeRemaining()
41 | {
42 | std::lock_guard<std::mutex> locker(mutex_);
43 |
44 | if (timers_.empty()) {
45 | return -1;
46 | }
47 |
48 | int64_t msec = events_.begin()->first.first - GetTimeNow();
49 | if (msec < 0) {
50 | msec = 0;
51 | }
52 |
53 | return msec;
54 | }
55 |
56 | void TimerQueue::HandleTimerEvent()
57 | {
58 | if(!timers_.empty()) {
59 | std::lock_guard<std::mutex> locker(mutex_);
60 | int64_t timePoint = GetTimeNow();
61 | while(!timers_.empty() && events_.begin()->first.first<=timePoint)
62 | {
63 | TimerId timerId = events_.begin()->first.second;
64 | bool flag = events_.begin()->second->event_callback_();
65 | if(flag == true) {
66 | events_.begin()->second->SetNextTimeout(timePoint);
67 | auto timerPtr = std::move(events_.begin()->second);
68 | events_.erase(events_.begin());
69 | events_.emplace(std::pair<int64_t, TimerId>(timerPtr->getNextTimeout(), timerId), timerPtr);
70 | }
71 | else {
72 | events_.erase(events_.begin());
73 | timers_.erase(timerId);
74 | }
75 | }
76 | }
77 | }
78 |
79 |
--------------------------------------------------------------------------------
/DesktopSharing/net/Timestamp.cpp:
--------------------------------------------------------------------------------
1 | #include "Timestamp.h"
2 | #include <iostream>
3 | #include <iomanip>
4 | #include <sstream>
5 |
6 | using namespace xop;
7 | using namespace std;
8 | using namespace std::chrono;
9 |
10 | std::string Timestamp::Localtime()
11 | {
12 | std::ostringstream stream;
13 | auto now = system_clock::now();
14 | time_t tt = system_clock::to_time_t(now);
15 |
16 | #if defined(WIN32) || defined(_WIN32)
17 | struct tm tm;
18 | localtime_s(&tm, &tt);
19 | stream << std::put_time(&tm, "%F %T");
20 | #elif defined(__linux) || defined(__linux__)
21 | char buffer[200] = {0};
22 | std::string timeString;
23 | std::strftime(buffer, 200, "%F %T", std::localtime(&tt));
24 | stream << buffer;
25 | #endif
26 | return stream.str();
27 | }
--------------------------------------------------------------------------------
/DesktopSharing/net/Timestamp.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-15
3 |
4 | #ifndef XOP_TIMESTAMP_H
5 | #define XOP_TIMESTAMP_H
6 |
7 | #include <string>
8 | #include <functional>
9 | #include <cstdint>
10 | #include <chrono>
11 | #include <thread>
12 |
13 | namespace xop
14 | {
15 |
16 | class Timestamp
17 | {
18 | public:
19 | Timestamp()
20 | : begin_time_point_(std::chrono::high_resolution_clock::now())
21 | { }
22 |
23 | void Reset()
24 | {
25 | begin_time_point_ = std::chrono::high_resolution_clock::now();
26 | }
27 |
28 | int64_t Elapsed()
29 | {
30 | return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - begin_time_point_).count();
31 | }
32 |
33 | static std::string Localtime();
34 |
35 | private:
36 | std::chrono::time_point<std::chrono::high_resolution_clock> begin_time_point_;
37 | };
38 |
39 | }
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/DesktopSharing/net/log.h:
--------------------------------------------------------------------------------
1 | #ifndef _XOP_LOG_H
2 | #define _XOP_LOG_H
3 |
4 | #include <cstdio>
5 |
6 | //#ifdef _DEBUG
7 | #define LOG(format, ...) \
8 | { \
9 | fprintf(stderr, "[DEBUG] [%s:%s:%d] " format "", \
10 | __FILE__, __FUNCTION__ , __LINE__, ##__VA_ARGS__); \
11 | }
12 | //#else
13 | //#define LOG(format, ...)
14 | //#endif
15 |
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/AACSource.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #ifndef XOP_AAC_SOURCE_H
5 | #define XOP_AAC_SOURCE_H
6 |
7 | #include "MediaSource.h"
8 | #include "rtp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class AACSource : public MediaSource
14 | {
15 | public:
16 | static AACSource* CreateNew(uint32_t samplerate=44100, uint32_t channels=2, bool has_adts=true);
17 | virtual ~AACSource();
18 |
19 | uint32_t GetSamplerate() const
20 | { return samplerate_; }
21 |
22 | uint32_t GetChannels() const
23 | { return channels_; }
24 |
25 | virtual std::string GetMediaDescription(uint16_t port=0);
26 |
27 | virtual std::string GetAttribute();
28 |
29 | bool HandleFrame(MediaChannelId channel_id, AVFrame frame);
30 |
31 | static uint32_t GetTimestamp(uint32_t samplerate =44100);
32 |
33 | private:
34 | AACSource(uint32_t samplerate, uint32_t channels, bool has_adts);
35 |
36 | uint32_t samplerate_ = 44100;
37 | uint32_t channels_ = 2;
38 | bool has_adts_ = true;
39 |
40 | static const int ADTS_SIZE = 7;
41 | static const int AU_SIZE = 4;
42 | };
43 |
44 | }
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/DigestAuthentication.cpp:
--------------------------------------------------------------------------------
1 | #include "DigestAuthentication.h"
2 | #include "md5/md5.hpp"
3 |
4 | using namespace xop;
5 |
6 | DigestAuthentication::DigestAuthentication(std::string realm, std::string username, std::string password)
7 | : realm_(realm)
8 | , username_(username)
9 | , password_(password)
10 | {
11 |
12 | }
13 |
14 | DigestAuthentication::~DigestAuthentication()
15 | {
16 |
17 | }
18 |
19 | std::string DigestAuthentication::GetNonce()
20 | {
21 | return md5::generate_nonce();
22 | }
23 |
24 | std::string DigestAuthentication::GetResponse(std::string nonce, std::string cmd, std::string url)
25 | {
26 | //md5(md5(<username>:<realm> : <password>) :<nonce> : md5(<cmd>:<url>))
27 |
28 | auto hex1 = md5::md5_hash_hex(username_ + ":" + realm_ + ":" + password_);
29 | auto hex2 = md5::md5_hash_hex(cmd + ":" + url);
30 | auto response = md5::md5_hash_hex(hex1 + ":" + nonce + ":" + hex2);
31 | return response;
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/DigestAuthentication.h:
--------------------------------------------------------------------------------
1 | //PHZ
2 | //2019-10-6
3 |
4 | #ifndef RTSP_DIGEST_AUTHENTICATION_H
5 | #define RTSP_DIGEST_AUTHENTICATION_H
6 |
7 | #include <cstdint>
8 | #include <string>
9 |
10 | namespace xop
11 | {
12 |
13 | class DigestAuthentication
14 | {
15 | public:
16 | DigestAuthentication(std::string realm, std::string username, std::string password);
17 | virtual ~DigestAuthentication();
18 |
19 | std::string GetRealm() const
20 | { return realm_; }
21 |
22 | std::string GetUsername() const
23 | { return username_; }
24 |
25 | std::string GetPassword() const
26 | { return password_; }
27 |
28 | std::string GetNonce();
29 | std::string GetResponse(std::string nonce, std::string cmd, std::string url);
30 |
31 | private:
32 | std::string realm_;
33 | std::string username_;
34 | std::string password_;
35 |
36 | };
37 |
38 | }
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/G711ASource.cpp:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #if defined(WIN32) || defined(_WIN32)
5 | #ifndef _CRT_SECURE_NO_WARNINGS
6 | #define _CRT_SECURE_NO_WARNINGS
7 | #endif
8 | #endif
9 | #include "G711ASource.h"
10 | #include <cstdio>
11 | #include <chrono>
12 | #if defined(__linux) || defined(__linux__)
13 | #include <sys/time.h>
14 | #endif
15 |
16 | using namespace xop;
17 | using namespace std;
18 |
19 | G711ASource::G711ASource()
20 | {
21 | payload_ = 8;
22 | media_type_ = PCMA;
23 | clock_rate_ = 8000;
24 | }
25 |
26 | G711ASource* G711ASource::CreateNew()
27 | {
28 | return new G711ASource();
29 | }
30 |
31 | G711ASource::~G711ASource()
32 | {
33 |
34 | }
35 |
36 | string G711ASource::GetMediaDescription(uint16_t port)
37 | {
38 | char buf[100] = {0};
39 | sprintf(buf, "m=audio %hu RTP/AVP 8", port);
40 | return string(buf);
41 | }
42 |
43 | string G711ASource::GetAttribute()
44 | {
45 | return string("a=rtpmap:8 PCMA/8000/1");
46 | }
47 |
48 | bool G711ASource::HandleFrame(MediaChannelId channel_id, AVFrame frame)
49 | {
50 | if (frame.size > MAX_RTP_PAYLOAD_SIZE) {
51 | return false;
52 | }
53 |
54 | uint8_t *frame_buf = frame.buffer.get();
55 | uint32_t frame_size = frame.size;
56 |
57 | RtpPacket rtp_pkt;
58 | rtp_pkt.type = frame.type;
59 | rtp_pkt.timestamp = frame.timestamp;
60 | rtp_pkt.size = frame_size + 4 + RTP_HEADER_SIZE;
61 | rtp_pkt.last = 1;
62 |
63 | memcpy(rtp_pkt.data.get()+4+RTP_HEADER_SIZE, frame_buf, frame_size);
64 |
65 | if (send_frame_callback_) {
66 | send_frame_callback_(channel_id, rtp_pkt);
67 | }
68 |
69 | return true;
70 | }
71 |
72 | uint32_t G711ASource::GetTimestamp()
73 | {
74 | auto time_point = chrono::time_point_cast<chrono::microseconds>(chrono::steady_clock::now());
75 | return (uint32_t)((time_point.time_since_epoch().count()+500)/1000*8);
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/G711ASource.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #ifndef XOP_G711A_SOURCE_H
5 | #define XOP_G711A_SOURCE_H
6 |
7 | #include "MediaSource.h"
8 | #include "rtp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class G711ASource : public MediaSource
14 | {
15 | public:
16 | static G711ASource* CreateNew();
17 | virtual ~G711ASource();
18 |
19 | uint32_t GetSampleRate() const
20 | { return samplerate_; }
21 |
22 | uint32_t GetChannels() const
23 | { return channels_; }
24 |
25 | virtual std::string GetMediaDescription(uint16_t port=0);
26 |
27 | virtual std::string GetAttribute();
28 |
29 | bool HandleFrame(MediaChannelId channel_id, AVFrame frame);
30 |
31 | static uint32_t GetTimestamp();
32 |
33 | private:
34 | G711ASource();
35 |
36 | uint32_t samplerate_ = 8000;
37 | uint32_t channels_ = 1;
38 | };
39 |
40 | }
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/H264Parser.cpp:
--------------------------------------------------------------------------------
1 | #include "H264Parser.h"
2 | #include <cstring>
3 |
4 | using namespace xop;
5 |
6 | Nal H264Parser::findNal(const uint8_t *data, uint32_t size)
7 | {
8 | Nal nal(nullptr, nullptr);
9 |
10 | if(size < 5)
11 | {
12 | return nal;
13 | }
14 |
15 | nal.second = const_cast<uint8_t*>(data) + (size-1);
16 |
17 | uint32_t startCode = 0;
18 | uint32_t pos = 0;
19 | uint8_t prefix[3] = {0};
20 | memcpy(prefix, data, 3);
21 | size -= 3;
22 | data += 2;
23 |
24 | while(size--)
25 | {
26 | if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 1))
27 | {
28 | if(nal.first == nullptr) // 00 00 01
29 | {
30 | nal.first = const_cast<uint8_t*>(data) + 1;
31 | startCode = 3;
32 | }
33 | else if(startCode == 3)
34 | {
35 | nal.second = const_cast<uint8_t*>(data) - 3;
36 | break;
37 | }
38 | }
39 | else if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 0))
40 | {
41 | if (*(data+1) == 0x01) // 00 00 00 01
42 | {
43 | if(nal.first == nullptr)
44 | {
45 | if(size >= 1)
46 | {
47 | nal.first = const_cast<uint8_t*>(data) + 2;
48 | }
49 | else
50 | {
51 | break;
52 | }
53 | startCode = 4;
54 | }
55 | else if(startCode == 4)
56 | {
57 | nal.second = const_cast<uint8_t*>(data) - 3;
58 | break;
59 | }
60 | }
61 | }
62 |
63 | prefix[(pos++) % 3] = *(++data);
64 | }
65 |
66 | if(nal.first == nullptr)
67 | nal.second = nullptr;
68 |
69 | return nal;
70 | }
71 |
72 |
73 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/H264Parser.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_H264_PARSER_H
2 | #define XOP_H264_PARSER_H
3 |
4 | #include <cstdint>
5 | #include <utility>
6 |
7 | namespace xop
8 | {
9 |
10 | typedef std::pair<uint8_t*, uint8_t*> Nal; // <nal begin, nal end>
11 |
12 | class H264Parser
13 | {
14 | public:
15 | static Nal findNal(const uint8_t *data, uint32_t size);
16 |
17 | private:
18 |
19 | };
20 |
21 | }
22 |
23 | #endif
24 |
25 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/H264Source.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #ifndef XOP_H264_SOURCE_H
5 | #define XOP_H264_SOURCE_H
6 |
7 | #include "MediaSource.h"
8 | #include "rtp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class H264Source : public MediaSource
14 | {
15 | public:
16 | static H264Source* CreateNew(uint32_t framerate=25);
17 | ~H264Source();
18 |
19 | void SetFramerate(uint32_t framerate)
20 | { framerate_ = framerate; }
21 |
22 | uint32_t GetFramerate() const
23 | { return framerate_; }
24 |
25 | virtual std::string GetMediaDescription(uint16_t port);
26 |
27 | virtual std::string GetAttribute();
28 |
29 | bool HandleFrame(MediaChannelId channel_id, AVFrame frame);
30 |
31 | static uint32_t GetTimestamp();
32 |
33 | private:
34 | H264Source(uint32_t framerate);
35 |
36 | uint32_t framerate_ = 25;
37 | };
38 |
39 | }
40 |
41 | #endif
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/H265Source.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #ifndef XOP_H265_SOURCE_H
5 | #define XOP_H265_SOURCE_H
6 |
7 | #include "MediaSource.h"
8 | #include "rtp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class H265Source : public MediaSource
14 | {
15 | public:
16 | static H265Source* CreateNew(uint32_t framerate=25);
17 | ~H265Source();
18 |
19 | void Setframerate(uint32_t framerate)
20 | { framerate_ = framerate; }
21 |
22 | uint32_t GetFramerate() const
23 | { return framerate_; }
24 |
25 | virtual std::string GetMediaDescription(uint16_t port=0);
26 |
27 | virtual std::string GetAttribute();
28 |
29 | bool HandleFrame(MediaChannelId channelId, AVFrame frame);
30 |
31 | static uint32_t GetTimestamp();
32 |
33 | private:
34 | H265Source(uint32_t framerate);
35 |
36 | uint32_t framerate_ = 25;
37 | };
38 |
39 | }
40 |
41 | #endif
42 |
43 |
44 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/HttpFlvConnection.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_HTTP_FLV_CONNECTION_H
2 | #define XOP_HTTP_FLV_CONNECTION_H
3 |
4 | #include "net/EventLoop.h"
5 | #include "net/TcpConnection.h"
6 |
7 | namespace xop
8 | {
9 |
10 | class RtmpServer;
11 |
12 | class HttpFlvConnection : public TcpConnection
13 | {
14 | public:
15 | HttpFlvConnection(std::shared_ptr<RtmpServer> rtmp_server, TaskScheduler* taskScheduler, SOCKET sockfd);
16 | virtual ~HttpFlvConnection();
17 |
18 | bool HasFlvHeader() const
19 | { return has_flv_header_; }
20 |
21 | bool IsPlaying() const
22 | { return is_playing_; }
23 |
24 | bool SendMediaData(uint8_t type, uint64_t timestamp, std::shared_ptr<char> payload, uint32_t payload_size);
25 |
26 | void ResetKeyFrame()
27 | { has_key_frame_ = false; }
28 |
29 | private:
30 | friend class RtmpSession;
31 |
32 | bool OnRead(BufferReader& buffer);
33 | void OnClose();
34 |
35 | void SendFlvHeader();
36 | int SendFlvTag(uint8_t type, uint64_t timestamp, std::shared_ptr<char> payload, uint32_t payload_size);
37 |
38 | std::weak_ptr<RtmpServer> rtmp_server_;
39 | TaskScheduler* task_scheduler_ = nullptr;
40 | std::string stream_path_;
41 |
42 | std::shared_ptr<char> avc_sequence_header_;
43 | std::shared_ptr<char> aac_sequence_header_;
44 | uint32_t avc_sequence_header_size_ = 0;
45 | uint32_t aac_sequence_header_size_ = 0;
46 | bool has_key_frame_ = false;
47 | bool has_flv_header_ = false;
48 | bool is_playing_ = false;
49 |
50 | const uint8_t FLV_TAG_TYPE_AUDIO = 0x8;
51 | const uint8_t FLV_TAG_TYPE_VIDEO = 0x9;
52 | };
53 |
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/HttpFlvServer.cpp:
--------------------------------------------------------------------------------
1 | #include "HttpFlvServer.h"
2 | #include "RtmpServer.h"
3 | #include "net/SocketUtil.h"
4 | #include "net/Logger.h"
5 |
6 | using namespace xop;
7 |
8 | HttpFlvServer::HttpFlvServer(xop::EventLoop* event_loop)
9 | : TcpServer(event_loop)
10 | {
11 |
12 | }
13 |
14 | HttpFlvServer::~HttpFlvServer()
15 | {
16 |
17 | }
18 |
19 | void HttpFlvServer::Attach(std::shared_ptr<RtmpServer> rtmp_server)
20 | {
21 | std::lock_guard<std::mutex> locker(mutex_);
22 | rtmp_server_ = rtmp_server;
23 | }
24 |
25 | TcpConnection::Ptr HttpFlvServer::OnConnect(SOCKET sockfd)
26 | {
27 | auto rtmp_server = rtmp_server_.lock();
28 | if (rtmp_server) {
29 | return std::make_shared<HttpFlvConnection>(rtmp_server, event_loop_->GetTaskScheduler().get(), sockfd);
30 | }
31 | return nullptr;
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/HttpFlvServer.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_HTTP_FLV_SERVER_H
2 | #define XOP_HTTP_FLV_SERVER_H
3 |
4 | #include "net/TcpServer.h"
5 | #include "HttpFlvConnection.h"
6 | #include <mutex>
7 |
8 | namespace xop
9 | {
10 | class RtmpServer;
11 |
12 | class HttpFlvServer : public TcpServer
13 | {
14 | public:
15 | HttpFlvServer(xop::EventLoop* event_loop);
16 | ~HttpFlvServer();
17 |
18 | void Attach(std::shared_ptr<RtmpServer> rtmp_server);
19 |
20 | private:
21 | TcpConnection::Ptr OnConnect(SOCKET sockfd);
22 |
23 | std::mutex mutex_;
24 | std::weak_ptr<RtmpServer> rtmp_server_;
25 | };
26 |
27 | }
28 |
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/MediaSource.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-6-8
3 |
4 | #ifndef XOP_MEDIA_SOURCE_H
5 | #define XOP_MEDIA_SOURCE_H
6 |
7 | #include "media.h"
8 | #include "rtp.h"
9 | #include "net/Socket.h"
10 | #include <string>
11 | #include <memory>
12 | #include <cstdint>
13 | #include <functional>
14 | #include <map>
15 |
16 | namespace xop
17 | {
18 |
19 | class MediaSource
20 | {
21 | public:
22 | using SendFrameCallback = std::function<bool (MediaChannelId channel_id, RtpPacket pkt)>;
23 |
24 | MediaSource() {}
25 | virtual ~MediaSource() {}
26 |
27 | virtual MediaType GetMediaType() const
28 | { return media_type_; }
29 |
30 | virtual std::string GetMediaDescription(uint16_t port=0) = 0;
31 |
32 | virtual std::string GetAttribute() = 0;
33 |
34 | virtual bool HandleFrame(MediaChannelId channelId, AVFrame frame) = 0;
35 | virtual void SetSendFrameCallback(const SendFrameCallback callback)
36 | { send_frame_callback_ = callback; }
37 |
38 | virtual uint32_t GetPayloadType() const
39 | { return payload_; }
40 |
41 | virtual uint32_t GetClockRate() const
42 | { return clock_rate_; }
43 |
44 | protected:
45 | MediaType media_type_ = NONE;
46 | uint32_t payload_ = 0;
47 | uint32_t clock_rate_ = 0;
48 | SendFrameCallback send_frame_callback_;
49 | };
50 |
51 | }
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpChunk.h:
--------------------------------------------------------------------------------
1 | #ifndef RTMP_CHUNK_H
2 | #define RTMP_CHUNK_H
3 |
4 | #include "net/BufferWriter.h"
5 | #include "net/BufferReader.h"
6 | #include "RtmpMessage.h"
7 | #include "amf.h"
8 | #include <map>
9 |
10 | namespace xop {
11 |
12 | class RtmpChunk
13 | {
14 | public:
15 | enum State
16 | {
17 | PARSE_HEADER,
18 | PARSE_BODY,
19 | };
20 |
21 | RtmpChunk();
22 | virtual ~RtmpChunk();
23 |
24 | int Parse(BufferReader& in_buffer, RtmpMessage& out_rtmp_msg);
25 |
26 | int CreateChunk(uint32_t csid, RtmpMessage& rtmp_msg, char* buf, uint32_t buf_size);
27 |
28 | void SetInChunkSize(uint32_t in_chunk_size)
29 | { in_chunk_size_ = in_chunk_size; }
30 |
31 | void SetOutChunkSize(uint32_t out_chunk_size)
32 | { out_chunk_size_ = out_chunk_size; }
33 |
34 | void Clear()
35 | { rtmp_messages_.clear(); }
36 |
37 | int GetStreamId() const
38 | { return stream_id_; }
39 |
40 | private:
41 | int ParseChunkHeader(BufferReader& buffer);
42 | int ParseChunkBody(BufferReader& buffer);
43 | int CreateBasicHeader(uint8_t fmt, uint32_t csid, char* buf);
44 | int CreateMessageHeader(uint8_t fmt, RtmpMessage& rtmp_msg, char* buf);
45 |
46 | State state_;
47 | int chunk_stream_id_ = 0;
48 | int stream_id_ = 0;
49 | uint32_t in_chunk_size_ = 128;
50 | uint32_t out_chunk_size_ = 128;
51 | std::map<int, RtmpMessage> rtmp_messages_;
52 |
53 | const int kDefaultStreamId = 1;
54 | const int kChunkMessageHeaderLen[4] = { 11, 7, 3, 0 };
55 | };
56 |
57 | }
58 |
59 |
60 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpClient.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_RTMP_CLIENT_H
2 | #define XOP_RTMP_CLIENT_H
3 |
4 | #include <string>
5 | #include <mutex>
6 | #include "RtmpConnection.h"
7 | #include "net/EventLoop.h"
8 | #include "net/Timestamp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class RtmpClient : public Rtmp, public std::enable_shared_from_this<RtmpClient>
14 | {
15 | public:
16 | using FrameCallback = std::function<void(uint8_t* payload, uint32_t length, uint8_t codecId, uint32_t timestamp)>;
17 |
18 | static std::shared_ptr<RtmpClient> Create(xop::EventLoop* loop);
19 | ~RtmpClient();
20 |
21 | void SetFrameCB(const FrameCallback& cb);
22 | int OpenUrl(std::string url, int msec, std::string& status);
23 | void Close();
24 | bool IsConnected();
25 |
26 | private:
27 | friend class RtmpConnection;
28 |
29 | RtmpClient(xop::EventLoop *event_loop);
30 |
31 | std::mutex mutex_;
32 | xop::EventLoop* event_loop_;
33 | xop::TaskScheduler* task_scheduler_;
34 | std::shared_ptr<RtmpConnection> rtmp_conn_;
35 | FrameCallback frame_cb_;
36 | };
37 |
38 | }
39 |
40 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpHandshake.cpp:
--------------------------------------------------------------------------------
1 | #include "RtmpHandshake.h"
2 | #include "rtmp.h"
3 | #include "net/Logger.h"
4 | #include <cstdint>
5 | #include <random>
6 |
7 | using namespace xop;
8 |
9 | RtmpHandshake::RtmpHandshake(State state)
10 | {
11 | handshake_state_ = state;
12 | }
13 |
14 | RtmpHandshake::~RtmpHandshake()
15 | {
16 |
17 | }
18 |
19 | int RtmpHandshake::Parse(xop::BufferReader& buffer, char* res_buf, uint32_t res_buf_size)
20 | {
21 | uint8_t *buf = (uint8_t*)buffer.Peek();
22 | uint32_t buf_size = buffer.ReadableBytes();
23 | uint32_t pos = 0;
24 | uint32_t res_size = 0;
25 | std::random_device rd;
26 |
27 | if (handshake_state_ == HANDSHAKE_S0S1S2) {
28 | if (buf_size < (1 + 1536 + 1536)) { //S0S1S2
29 | return res_size;
30 | }
31 |
32 | if (buf[0] != RTMP_VERSION) {
33 | LOG_ERROR("unsupported rtmp version %x\n", buf[0]);
34 | return -1;
35 | }
36 |
37 | pos += 1 + 1536 + 1536;
38 | res_size = 1536;
39 | memcpy(res_buf, buf + 1, 1536); //C2
40 | handshake_state_ = HANDSHAKE_COMPLETE;
41 | }
42 | else if (handshake_state_ == HANDSHAKE_C0C1)
43 | {
44 | if (buf_size < 1537) { //c0c1
45 | return res_size;
46 | }
47 | else
48 | {
49 | if (buf[0] != RTMP_VERSION) {
50 | return -1;
51 | }
52 |
53 | pos += 1537;
54 | res_size = 1 + 1536 + 1536;
55 | memset(res_buf, 0, 1537); //S0 S1 S2
56 | res_buf[0] = RTMP_VERSION;
57 |
58 | char *p = res_buf; p += 9;
59 | for (int i = 0; i < 1528; i++) {
60 | *p++ = rd();
61 | }
62 | memcpy(p, buf + 1, 1536);
63 | handshake_state_ = HANDSHAKE_C2;
64 | }
65 | }
66 | else if (handshake_state_ == HANDSHAKE_C2)
67 | {
68 | if (buf_size < 1536) { //c2
69 | return res_size;
70 | }
71 | else {
72 | pos = 1536;
73 | handshake_state_ = HANDSHAKE_COMPLETE;
74 | }
75 | }
76 | else {
77 | return -1;
78 | }
79 |
80 | buffer.Retrieve(pos);
81 | return res_size;
82 | }
83 |
84 | int RtmpHandshake::BuildC0C1(char* buf, uint32_t buf_size)
85 | {
86 | uint32_t size = 1 + 1536; //COC1
87 | memset(buf, 0, 1537);
88 | buf[0] = RTMP_VERSION;
89 |
90 | std::random_device rd;
91 | uint8_t *p = (uint8_t *)buf; p += 9;
92 | for (int i = 0; i < 1528; i++) {
93 | *p++ = rd();
94 | }
95 |
96 | return size;
97 | }
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpHandshake.h:
--------------------------------------------------------------------------------
1 | #ifndef RTMP_HANDSHAKE_H
2 | #define RTMP_HANDSHAKE_H
3 |
4 | #include "net/BufferReader.h"
5 |
6 | namespace xop {
7 |
8 | class RtmpHandshake
9 | {
10 | public:
11 | enum State
12 | {
13 | HANDSHAKE_C0C1,
14 | HANDSHAKE_S0S1S2,
15 | HANDSHAKE_C2,
16 | HANDSHAKE_COMPLETE
17 | };
18 |
19 | RtmpHandshake(State state);
20 | virtual ~RtmpHandshake();
21 |
22 | int Parse(xop::BufferReader& in_buffer, char* res_buf, uint32_t res_buf_size);
23 |
24 | int BuildC0C1(char* buf, uint32_t buf_size);
25 |
26 | bool IsCompleted() const
27 | {
28 | return handshake_state_ == HANDSHAKE_COMPLETE;
29 | }
30 |
31 | private:
32 | State handshake_state_;
33 | };
34 |
35 | }
36 |
37 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpMessage.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/DesktopSharing/xop/RtmpMessage.h
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpPublisher.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_RTMP_PUBLISHER_H
2 | #define XOP_RTMP_PUBLISHER_H
3 |
4 | #include <string>
5 | #include <mutex>
6 | #include "RtmpConnection.h"
7 | #include "net/EventLoop.h"
8 | #include "net/Timestamp.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class RtmpPublisher : public Rtmp, public std::enable_shared_from_this<RtmpPublisher>
14 | {
15 | public:
16 | static std::shared_ptr<RtmpPublisher> Create(xop::EventLoop* loop);
17 | ~RtmpPublisher();
18 |
19 | int SetMediaInfo(MediaInfo media_info);
20 |
21 | int OpenUrl(std::string url, int msec, std::string& status);
22 | void Close();
23 |
24 | bool IsConnected();
25 |
26 | int PushVideoFrame(uint8_t *data, uint32_t size); /* (sps pps)idr frame or p frame */
27 | int PushAudioFrame(uint8_t *data, uint32_t size);
28 |
29 | private:
30 | friend class RtmpConnection;
31 |
32 | RtmpPublisher(xop::EventLoop *event_loop);
33 | bool IsKeyFrame(uint8_t* data, uint32_t size);
34 |
35 | xop::EventLoop *event_loop_ = nullptr;
36 | TaskScheduler *task_scheduler_ = nullptr;
37 | std::mutex mutex_;
38 | std::shared_ptr<RtmpConnection> rtmp_conn_;
39 |
40 | MediaInfo media_info_;
41 | std::shared_ptr<char> avc_sequence_header_;
42 | std::shared_ptr<char> aac_sequence_header_;
43 | uint32_t avc_sequence_header_size_ = 0;
44 | uint32_t aac_sequence_header_size_ = 0;
45 | uint8_t audio_tag_ = 0;
46 | bool has_key_frame_ = false;
47 | xop::Timestamp timestamp_;
48 | uint64_t video_timestamp_ = 0;
49 | uint64_t audio_timestamp_ = 0;
50 |
51 | const uint32_t kSamplingFrequency[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, 0, 0, 0};
52 | };
53 |
54 | }
55 |
56 | #endif
57 |
58 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpServer.cpp:
--------------------------------------------------------------------------------
1 | #include "RtmpServer.h"
2 | #include "RtmpConnection.h"
3 | #include "net/SocketUtil.h"
4 | #include "net/Logger.h"
5 |
6 | using namespace xop;
7 |
8 | RtmpServer::RtmpServer(EventLoop* event_loop)
9 | : TcpServer(event_loop)
10 | , event_loop_(event_loop)
11 | {
12 | event_loop_->AddTimer([this] {
13 | std::lock_guard<std::mutex> lock(mutex_);
14 | for (auto iter = rtmp_sessions_.begin(); iter != rtmp_sessions_.end(); ) {
15 | if (iter->second->GetClients() == 0) {
16 | rtmp_sessions_.erase(iter++);
17 | }
18 | else {
19 | iter++;
20 | }
21 | }
22 | return true;
23 | }, 30000);
24 | }
25 |
26 | RtmpServer::~RtmpServer()
27 | {
28 |
29 | }
30 |
31 | std::shared_ptr<RtmpServer> RtmpServer::Create(xop::EventLoop* event_loop)
32 | {
33 | std::shared_ptr<RtmpServer> server(new RtmpServer(event_loop));
34 | return server;
35 | }
36 |
37 | TcpConnection::Ptr RtmpServer::OnConnect(SOCKET sockfd)
38 | {
39 | return std::make_shared<RtmpConnection>(shared_from_this(), event_loop_->GetTaskScheduler().get(), sockfd);
40 | }
41 |
42 | void RtmpServer::AddSession(std::string stream_path)
43 | {
44 | std::lock_guard<std::mutex> lock(mutex_);
45 | if(rtmp_sessions_.find(stream_path) == rtmp_sessions_.end()) {
46 | rtmp_sessions_[stream_path] = std::make_shared<RtmpSession>();
47 | }
48 | }
49 |
50 | void RtmpServer::RemoveSession(std::string stream_path)
51 | {
52 | std::lock_guard<std::mutex> lock(mutex_);
53 | rtmp_sessions_.erase(stream_path);
54 | }
55 |
56 | bool RtmpServer::HasSession(std::string stream_path)
57 | {
58 | std::lock_guard<std::mutex> lock(mutex_);
59 | return (rtmp_sessions_.find(stream_path) != rtmp_sessions_.end());
60 | }
61 |
62 | RtmpSession::Ptr RtmpServer::GetSession(std::string stream_path)
63 | {
64 | std::lock_guard<std::mutex> lock(mutex_);
65 | if(rtmp_sessions_.find(stream_path) == rtmp_sessions_.end()) {
66 | rtmp_sessions_[stream_path] = std::make_shared<RtmpSession>();
67 | }
68 |
69 | return rtmp_sessions_[stream_path];
70 | }
71 |
72 | bool RtmpServer::HasPublisher(std::string stream_path)
73 | {
74 | auto session = GetSession(stream_path);
75 | if(session == nullptr) {
76 | return false;
77 | }
78 |
79 | return (session->GetPublisher()!=nullptr);
80 | }
81 |
82 |
83 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtmpServer.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_RTMP_SERVER_H
2 | #define XOP_RTMP_SERVER_H
3 |
4 | #include <string>
5 | #include <mutex>
6 | #include "rtmp.h"
7 | #include "RtmpSession.h"
8 | #include "net/TcpServer.h"
9 |
10 | namespace xop
11 | {
12 |
13 | class RtmpServer : public TcpServer, public Rtmp, public std::enable_shared_from_this<RtmpServer>
14 | {
15 | public:
16 | static std::shared_ptr<RtmpServer> Create(xop::EventLoop* event_loop);
17 | ~RtmpServer();
18 |
19 | private:
20 | friend class RtmpConnection;
21 | friend class HttpFlvConnection;
22 |
23 | RtmpServer(xop::EventLoop *event_loop);
24 | void AddSession(std::string stream_path);
25 | void RemoveSession(std::string stream_path);
26 |
27 | RtmpSession::Ptr GetSession(std::string stream_path);
28 | bool HasSession(std::string stream_path);
29 | bool HasPublisher(std::string stream_path);
30 |
31 | virtual TcpConnection::Ptr OnConnect(SOCKET sockfd);
32 |
33 | xop::EventLoop *event_loop_;
34 | std::mutex mutex_;
35 | std::unordered_map<std::string, RtmpSession::Ptr> rtmp_sessions_;
36 | };
37 |
38 | }
39 |
40 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtspPusher.h:
--------------------------------------------------------------------------------
1 | #ifndef XOP_RTSP_PUSHER_H
2 | #define XOP_RTSP_PUSHER_H
3 |
4 | #include <mutex>
5 | #include <map>
6 | #include "rtsp.h"
7 |
8 | namespace xop
9 | {
10 |
11 | class RtspConnection;
12 |
13 | class RtspPusher : public Rtsp
14 | {
15 | public:
16 | static std::shared_ptr<RtspPusher> Create(xop::EventLoop* loop);
17 | ~RtspPusher();
18 |
19 | void AddSession(MediaSession* session);
20 | void RemoveSession(MediaSessionId session_id);
21 |
22 | int OpenUrl(std::string url, int msec = 3000);
23 | void Close();
24 | bool IsConnected();
25 |
26 | bool PushFrame(MediaChannelId channelId, AVFrame frame);
27 |
28 | private:
29 | friend class RtspConnection;
30 |
31 | RtspPusher(xop::EventLoop *event_loop);
32 | MediaSession::Ptr LookMediaSession(MediaSessionId session_id);
33 |
34 | xop::EventLoop* event_loop_ = nullptr;
35 | xop::TaskScheduler* task_scheduler_ = nullptr;
36 | std::mutex mutex_;
37 | std::shared_ptr<RtspConnection> rtsp_conn_;
38 | std::shared_ptr<MediaSession> media_session_;
39 | };
40 |
41 | }
42 |
43 | #endif
--------------------------------------------------------------------------------
/DesktopSharing/xop/RtspServer.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2020-4-2
3 |
4 | #ifndef XOP_RTSP_SERVER_H
5 | #define XOP_RTSP_SERVER_H
6 |
7 | #include <memory>
8 | #include <string>
9 | #include <mutex>
10 | #include <unordered_map>
11 | #include "net/TcpServer.h"
12 | #include "rtsp.h"
13 |
14 | namespace xop
15 | {
16 |
17 | class RtspConnection;
18 |
19 | class RtspServer : public Rtsp, public TcpServer
20 | {
21 | public:
22 | static std::shared_ptr<RtspServer> Create(xop::EventLoop* loop);
23 | ~RtspServer();
24 |
25 | MediaSessionId AddSession(MediaSession* session);
26 | void RemoveSession(MediaSessionId sessionId);
27 |
28 | bool PushFrame(MediaSessionId sessionId, MediaChannelId channelId, AVFrame frame);
29 |
30 | private:
31 | friend class RtspConnection;
32 |
33 | RtspServer(xop::EventLoop* loop);
34 | MediaSession::Ptr LookMediaSession(const std::string& suffix);
35 | MediaSession::Ptr LookMediaSession(MediaSessionId session_id);
36 | virtual TcpConnection::Ptr OnConnect(SOCKET sockfd);
37 |
38 | std::mutex mutex_;
39 | std::unordered_map<MediaSessionId, std::shared_ptr<MediaSession>> media_sessions_;
40 | std::unordered_map<std::string, MediaSessionId> rtsp_suffix_map_;
41 | };
42 |
43 | }
44 |
45 | #endif
46 |
47 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/media.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-5-16
3 |
4 | #ifndef XOP_MEDIA_H
5 | #define XOP_MEDIA_H
6 |
7 | #include <memory>
8 |
9 | namespace xop
10 | {
11 |
12 | /* RTSP服务支持的媒体类型 */
13 | enum MediaType
14 | {
15 | //PCMU = 0,
16 | PCMA = 8,
17 | H264 = 96,
18 | AAC = 37,
19 | H265 = 265,
20 | NONE
21 | };
22 |
23 | enum FrameType
24 | {
25 | VIDEO_FRAME_I = 0x01,
26 | VIDEO_FRAME_P = 0x02,
27 | VIDEO_FRAME_B = 0x03,
28 | AUDIO_FRAME = 0x11,
29 | };
30 |
31 | struct AVFrame
32 | {
33 | AVFrame(uint32_t size = 0)
34 | :buffer(new uint8_t[size + 1], std::default_delete< uint8_t[]>())
35 | {
36 | this->size = size;
37 | type = 0;
38 | timestamp = 0;
39 | }
40 |
41 | std::shared_ptr<uint8_t> buffer; /* 帧数据 */
42 | uint32_t size; /* 帧大小 */
43 | uint8_t type; /* 帧类型 */
44 | uint32_t timestamp; /* 时间戳 */
45 | };
46 |
47 | static const int MAX_MEDIA_CHANNEL = 2;
48 |
49 | enum MediaChannelId
50 | {
51 | channel_0,
52 | channel_1
53 | };
54 |
55 | typedef uint32_t MediaSessionId;
56 |
57 | }
58 |
59 | #endif
60 |
61 |
--------------------------------------------------------------------------------
/DesktopSharing/xop/rtmp.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/DesktopSharing/xop/rtmp.h
--------------------------------------------------------------------------------
/DesktopSharing/xop/rtp.h:
--------------------------------------------------------------------------------
1 | // PHZ
2 | // 2018-6-11
3 |
4 | #ifndef XOP_RTP_H
5 | #define XOP_RTP_H
6 |
7 | #include <memory>
8 | #include <cstdint>
9 |
10 | #define RTP_HEADER_SIZE 12
11 | #define MAX_RTP_PAYLOAD_SIZE 1420 //1460 1500-20-12-8
12 | #define RTP_VERSION 2
13 | #define RTP_TCP_HEAD_SIZE 4
14 |
15 | namespace xop
16 | {
17 |
18 | enum TransportMode
19 | {
20 | RTP_OVER_TCP = 1,
21 | RTP_OVER_UDP = 2,
22 | RTP_OVER_MULTICAST = 3,
23 | };
24 |
25 | typedef struct _RTP_header
26 | {
27 | /* 小端序 */
28 | unsigned char csrc:4;
29 | unsigned char extension:1;
30 | unsigned char padding:1;
31 | unsigned char version:2;
32 | unsigned char payload:7;
33 | unsigned char marker:1;
34 |
35 | unsigned short seq;
36 | unsigned int ts;
37 | unsigned int ssrc;
38 | } RtpHeader;
39 |
40 | struct MediaChannelInfo
41 | {
42 | RtpHeader rtp_header;
43 |
44 | // tcp
45 | uint16_t rtp_channel;
46 | uint16_t rtcp_channel;
47 |
48 | // udp
49 | uint16_t rtp_port;
50 | uint16_t rtcp_port;
51 | uint16_t packet_seq;
52 | uint32_t clock_rate;
53 |
54 | // rtcp
55 | uint64_t packet_count;
56 | uint64_t octet_count;
57 | uint64_t last_rtcp_ntp_time;
58 |
59 | bool is_setup;
60 | bool is_play;
61 | bool is_record;
62 | };
63 |
64 | struct RtpPacket
65 | {
66 | RtpPacket()
67 | : data(new uint8_t[1600], std::default_delete<uint8_t[]>())
68 | {
69 | type = 0;
70 | }
71 |
72 | std::shared_ptr<uint8_t> data;
73 | uint32_t size;
74 | uint32_t timestamp;
75 | uint8_t type;
76 | uint8_t last;
77 | };
78 |
79 | }
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 PHZ
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DesktopSharing
2 |
3 | 项目介绍
4 | -
5 | * 抓取屏幕和声卡的音视频数据,编码后进行RTSP转发, RTSP推流, RTMP推流。
6 |
7 | 目前情况
8 | -
9 | * 完成屏幕采集(DXGI)和H.264编码。
10 | * 完成音频采集(WASAPI)和AAC编码。
11 | * 完成RTSP本地转发音视频数据。
12 | * 完成RTSP推流器。
13 | * 完成RTMP推流器。
14 | * 完成独显硬件编码(nvenc), 仅支持部分nvidia显卡。
15 | * 完成核显硬件编码(qsv)。
16 | * 完成简单的UI界面。
17 |
18 | 后续计划
19 | -
20 |
21 | 编译环境
22 | -
23 | * win10, vs2017, windows-sdk-version-10.0.17134.0
24 | * 项目使用的模块都是开源项目, 在vs2017/vs2019下编译通过。
25 |
26 | 模块说明
27 | -
28 | * 屏幕采集: DXGI(win8以上), GDI
29 | * 音频采集: WASAPI
30 | * 编码器: [ffmpeg4.0](https://ffmpeg.org/), Version: 4.0
31 | * 独显硬件编码器: [Video-Codec-SDK](https://developer.nvidia.com/nvidia-video-codec-sdk), Version: 8.2
32 | * 核显硬件编码器: [Media-SDK](https://github.com/Intel-Media-SDK/MediaSDK)
33 | * RTMP推流器: [rtmp](https://github.com/PHZ76/rtmp)
34 | * RTSP服务器,推流器: [RtspServer](https://github.com/PHZ76/RtspServer)
35 | * UI界面: [SDL](https://github.com/SDL-mirror/SDL), [imgui](https://github.com/ocornut/imgui)
36 |
37 | 使用方式
38 | -
39 | * 将编译生成的exe文件放入run-env中,即可运行。
40 |
41 | -
42 | 
43 |
--------------------------------------------------------------------------------
/libs/SDL2/BUGS.txt:
--------------------------------------------------------------------------------
1 |
2 | Bugs are now managed in the SDL bug tracker, here:
3 |
4 | https://bugzilla.libsdl.org/
5 |
6 | You may report bugs there, and search to see if a given issue has already
7 | been reported, discussed, and maybe even fixed.
8 |
9 |
10 | You may also find help at the SDL forums/mailing list:
11 |
12 | https://discourse.libsdl.org/
13 |
14 | Bug reports are welcome here, but we really appreciate if you use Bugzilla, as
15 | bugs discussed on the mailing list may be forgotten or missed.
16 |
17 |
--------------------------------------------------------------------------------
/libs/SDL2/COPYING.txt:
--------------------------------------------------------------------------------
1 |
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 |
21 |
--------------------------------------------------------------------------------
/libs/SDL2/README-SDL.txt:
--------------------------------------------------------------------------------
1 |
2 | Please distribute this file with the SDL runtime environment:
3 |
4 | The Simple DirectMedia Layer (SDL for short) is a cross-platform library
5 | designed to make it easy to write multi-media software, such as games
6 | and emulators.
7 |
8 | The Simple DirectMedia Layer library source code is available from:
9 | https://www.libsdl.org/
10 |
11 | This library is distributed under the terms of the zlib license:
12 | http://www.zlib.net/zlib_license.html
13 |
14 |
--------------------------------------------------------------------------------
/libs/SDL2/README.txt:
--------------------------------------------------------------------------------
1 |
2 | Simple DirectMedia Layer
3 |
4 | (SDL)
5 |
6 | Version 2.0
7 |
8 | ---
9 | https://www.libsdl.org/
10 |
11 | Simple DirectMedia Layer is a cross-platform development library designed
12 | to provide low level access to audio, keyboard, mouse, joystick, and graphics
13 | hardware via OpenGL and Direct3D. It is used by video playback software,
14 | emulators, and popular games including Valve's award winning catalog
15 | and many Humble Bundle games.
16 |
17 | More extensive documentation is available in the docs directory, starting
18 | with README.md
19 |
20 | Enjoy!
21 | Sam Lantinga (slouken@libsdl.org)
22 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-emscripten.md:
--------------------------------------------------------------------------------
1 | Emscripten
2 | ================================================================================
3 |
4 | Build:
5 |
6 | $ mkdir build
7 | $ cd build
8 | $ emconfigure ../configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --disable-cpuinfo CFLAGS="-O2"
9 | $ emmake make
10 |
11 | Or with cmake:
12 |
13 | $ mkdir build
14 | $ cd build
15 | $ emcmake cmake ..
16 | $ emmake make
17 |
18 | To build one of the tests:
19 |
20 | $ cd test/
21 | $ emcc -O2 --js-opts 0 -g4 testdraw2.c -I../include ../build/.libs/libSDL2.a ../build/libSDL2_test.a -o a.html
22 |
23 | Uses GLES2 renderer or software
24 |
25 | Some other SDL2 libraries can be easily built (assuming SDL2 is installed somewhere):
26 |
27 | SDL_mixer (http://www.libsdl.org/projects/SDL_mixer/):
28 |
29 | $ EMCONFIGURE_JS=1 emconfigure ../configure
30 | build as usual...
31 |
32 | SDL_gfx (http://cms.ferzkopp.net/index.php/software/13-sdl-gfx):
33 |
34 | $ EMCONFIGURE_JS=1 emconfigure ../configure --disable-mmx
35 | build as usual...
36 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-hg.md:
--------------------------------------------------------------------------------
1 | Mercurial
2 | =========
3 |
4 | The latest development version of SDL is available via Mercurial.
5 | Mercurial allows you to get up-to-the-minute fixes and enhancements;
6 | as a developer works on a source tree, you can use "hg" to mirror that
7 | source tree instead of waiting for an official release. Please look
8 | at the Mercurial website ( https://www.mercurial-scm.org/ ) for more
9 | information on using hg, where you can also download software for
10 | Mac OS X, Windows, and Unix systems.
11 |
12 | hg clone http://hg.libsdl.org/SDL
13 |
14 | If you are building SDL via configure, you will need to run autogen.sh
15 | before running configure.
16 |
17 | There is a web interface to the subversion repository at:
18 | http://hg.libsdl.org/SDL/
19 |
20 | There is an RSS feed available at that URL, for those that want to
21 | track commits in real time.
22 |
23 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-pandora.md:
--------------------------------------------------------------------------------
1 | Pandora
2 | =====================================================================
3 |
4 | ( http://openpandora.org/ )
5 | - A pandora specific video driver was written to allow SDL 2.0 with OpenGL ES
6 | support to work on the pandora under the framebuffer. This driver do not have
7 | input support for now, so if you use it you will have to add your own control code.
8 | The video driver name is "pandora" so if you have problem running it from
9 | the framebuffer, try to set the following variable before starting your application :
10 | "export SDL_VIDEODRIVER=pandora"
11 |
12 | - OpenGL ES support was added to the x11 driver, so it's working like the normal
13 | x11 driver one with OpenGLX support, with SDL input event's etc..
14 |
15 |
16 | David Carré (Cpasjuste)
17 | cpasjuste@gmail.com
18 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-platforms.md:
--------------------------------------------------------------------------------
1 | Platforms
2 | =========
3 |
4 | We maintain the list of supported platforms on our wiki now, and how to
5 | build and install SDL for those platforms:
6 |
7 | https://wiki.libsdl.org/Installation
8 |
9 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-porting.md:
--------------------------------------------------------------------------------
1 | Porting
2 | =======
3 |
4 | * Porting To A New Platform
5 |
6 | The first thing you have to do when porting to a new platform, is look at
7 | include/SDL_platform.h and create an entry there for your operating system.
8 | The standard format is "__PLATFORM__", where PLATFORM is the name of the OS.
9 | Ideally SDL_platform.h will be able to auto-detect the system it's building
10 | on based on C preprocessor symbols.
11 |
12 | There are two basic ways of building SDL at the moment:
13 |
14 | 1. The "UNIX" way: ./configure; make; make install
15 |
16 | If you have a GNUish system, then you might try this. Edit configure.ac,
17 | take a look at the large section labelled:
18 |
19 | "Set up the configuration based on the host platform!"
20 |
21 | Add a section for your platform, and then re-run autogen.sh and build!
22 |
23 | 2. Using an IDE:
24 |
25 | If you're using an IDE or other non-configure build system, you'll probably
26 | want to create a custom SDL_config.h for your platform. Edit SDL_config.h,
27 | add a section for your platform, and create a custom SDL_config_{platform}.h,
28 | based on SDL_config_minimal.h and SDL_config.h.in
29 |
30 | Add the top level include directory to the header search path, and then add
31 | the following sources to the project:
32 |
33 | src/*.c
34 | src/atomic/*.c
35 | src/audio/*.c
36 | src/cpuinfo/*.c
37 | src/events/*.c
38 | src/file/*.c
39 | src/haptic/*.c
40 | src/joystick/*.c
41 | src/power/*.c
42 | src/render/*.c
43 | src/render/software/*.c
44 | src/stdlib/*.c
45 | src/thread/*.c
46 | src/timer/*.c
47 | src/video/*.c
48 | src/audio/disk/*.c
49 | src/audio/dummy/*.c
50 | src/filesystem/dummy/*.c
51 | src/video/dummy/*.c
52 | src/haptic/dummy/*.c
53 | src/joystick/dummy/*.c
54 | src/main/dummy/*.c
55 | src/thread/generic/*.c
56 | src/timer/dummy/*.c
57 | src/loadso/dummy/*.c
58 |
59 |
60 | Once you have a working library without any drivers, you can go back to each
61 | of the major subsystems and start implementing drivers for your platform.
62 |
63 | If you have any questions, don't hesitate to ask on the SDL mailing list:
64 | http://www.libsdl.org/mailing-list.php
65 |
66 | Enjoy!
67 | Sam Lantinga (slouken@libsdl.org)
68 |
69 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-psp.md:
--------------------------------------------------------------------------------
1 | PSP
2 | ======
3 | SDL port for the Sony PSP contributed by
4 | Captian Lex
5 |
6 | Credit to
7 | Marcus R.Brown,Jim Paris,Matthew H for the original SDL 1.2 for PSP
8 | Geecko for his PSP GU lib "Glib2d"
9 |
10 | Building
11 | --------
12 | To build for the PSP, make sure psp-config is in the path and run:
13 | make -f Makefile.psp
14 |
15 |
16 |
17 | To Do
18 | ------
19 | PSP Screen Keyboard
20 |
--------------------------------------------------------------------------------
/libs/SDL2/docs/README-wince.md:
--------------------------------------------------------------------------------
1 | WinCE
2 | =====
3 |
4 | Windows CE is no longer supported by SDL.
5 |
6 | We have left the CE support in SDL 1.2 for those that must have it, and we
7 | have support for Windows Phone 8 and WinRT in SDL2, as of SDL 2.0.3.
8 |
9 | --ryan.
10 |
11 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_clipboard.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_clipboard.h
24 | *
25 | * Include file for SDL clipboard handling
26 | */
27 |
28 | #ifndef SDL_clipboard_h_
29 | #define SDL_clipboard_h_
30 |
31 | #include "SDL_stdinc.h"
32 |
33 | #include "begin_code.h"
34 | /* Set up for C function definitions, even when using C++ */
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif
38 |
39 | /* Function prototypes */
40 |
41 | /**
42 | * \brief Put UTF-8 text into the clipboard
43 | *
44 | * \sa SDL_GetClipboardText()
45 | */
46 | extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
47 |
48 | /**
49 | * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free()
50 | *
51 | * \sa SDL_SetClipboardText()
52 | */
53 | extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
54 |
55 | /**
56 | * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty
57 | *
58 | * \sa SDL_GetClipboardText()
59 | */
60 | extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
61 |
62 |
63 | /* Ends C function definitions when using C++ */
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 | #include "close_code.h"
68 |
69 | #endif /* SDL_clipboard_h_ */
70 |
71 | /* vi: set ts=4 sw=4 expandtab: */
72 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_copying.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_name.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | #ifndef SDLname_h_
23 | #define SDLname_h_
24 |
25 | #if defined(__STDC__) || defined(__cplusplus)
26 | #define NeedFunctionPrototypes 1
27 | #endif
28 |
29 | #define SDL_NAME(X) SDL_##X
30 |
31 | #endif /* SDLname_h_ */
32 |
33 | /* vi: set ts=4 sw=4 expandtab: */
34 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_opengles.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_opengles.h
24 | *
25 | * This is a simple file to encapsulate the OpenGL ES 1.X API headers.
26 | */
27 | #include "SDL_config.h"
28 |
29 | #ifdef __IPHONEOS__
30 | #include <OpenGLES/ES1/gl.h>
31 | #include <OpenGLES/ES1/glext.h>
32 | #else
33 | #include <GLES/gl.h>
34 | #include <GLES/glext.h>
35 | #endif
36 |
37 | #ifndef APIENTRY
38 | #define APIENTRY
39 | #endif
40 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_opengles2.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_opengles2.h
24 | *
25 | * This is a simple file to encapsulate the OpenGL ES 2.0 API headers.
26 | */
27 | #include "SDL_config.h"
28 |
29 | #ifndef _MSC_VER
30 |
31 | #ifdef __IPHONEOS__
32 | #include <OpenGLES/ES2/gl.h>
33 | #include <OpenGLES/ES2/glext.h>
34 | #else
35 | #include <GLES2/gl2platform.h>
36 | #include <GLES2/gl2.h>
37 | #include <GLES2/gl2ext.h>
38 | #endif
39 |
40 | #else /* _MSC_VER */
41 |
42 | /* OpenGL ES2 headers for Visual Studio */
43 | #include "SDL_opengles2_khrplatform.h"
44 | #include "SDL_opengles2_gl2platform.h"
45 | #include "SDL_opengles2_gl2.h"
46 | #include "SDL_opengles2_gl2ext.h"
47 |
48 | #endif /* _MSC_VER */
49 |
50 | #ifndef APIENTRY
51 | #define APIENTRY GL_APIENTRY
52 | #endif
53 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_opengles2_gl2platform.h:
--------------------------------------------------------------------------------
1 | #ifndef __gl2platform_h_
2 | #define __gl2platform_h_
3 |
4 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */
5 |
6 | /*
7 | * This document is licensed under the SGI Free Software B License Version
8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
9 | */
10 |
11 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
12 | *
13 | * Adopters may modify khrplatform.h and this file to suit their platform.
14 | * You are encouraged to submit all modifications to the Khronos group so that
15 | * they can be included in future versions of this file. Please submit changes
16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
17 | * by filing a bug against product "OpenGL-ES" component "Registry".
18 | */
19 |
20 | /*#include <KHR/khrplatform.h>*/
21 |
22 | #ifndef GL_APICALL
23 | #define GL_APICALL KHRONOS_APICALL
24 | #endif
25 |
26 | #ifndef GL_APIENTRY
27 | #define GL_APIENTRY KHRONOS_APIENTRY
28 | #endif
29 |
30 | #endif /* __gl2platform_h_ */
31 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_quit.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_quit.h
24 | *
25 | * Include file for SDL quit event handling.
26 | */
27 |
28 | #ifndef SDL_quit_h_
29 | #define SDL_quit_h_
30 |
31 | #include "SDL_stdinc.h"
32 | #include "SDL_error.h"
33 |
34 | /**
35 | * \file SDL_quit.h
36 | *
37 | * An ::SDL_QUIT event is generated when the user tries to close the application
38 | * window. If it is ignored or filtered out, the window will remain open.
39 | * If it is not ignored or filtered, it is queued normally and the window
40 | * is allowed to close. When the window is closed, screen updates will
41 | * complete, but have no effect.
42 | *
43 | * SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
44 | * and SIGTERM (system termination request), if handlers do not already
45 | * exist, that generate ::SDL_QUIT events as well. There is no way
46 | * to determine the cause of an ::SDL_QUIT event, but setting a signal
47 | * handler in your application will override the default generation of
48 | * quit events for that signal.
49 | *
50 | * \sa SDL_Quit()
51 | */
52 |
53 | /* There are no functions directly affecting the quit event */
54 |
55 | #define SDL_QuitRequested() \
56 | (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0))
57 |
58 | #endif /* SDL_quit_h_ */
59 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_revision.h:
--------------------------------------------------------------------------------
1 | #define SDL_REVISION "hg-13609:34cc7d3b69d3"
2 | #define SDL_REVISION_NUMBER 13609
3 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_test.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_test.h
24 | *
25 | * Include file for SDL test framework.
26 | *
27 | * This code is a part of the SDL2_test library, not the main SDL library.
28 | */
29 |
30 | #ifndef SDL_test_h_
31 | #define SDL_test_h_
32 |
33 | #include "SDL.h"
34 | #include "SDL_test_assert.h"
35 | #include "SDL_test_common.h"
36 | #include "SDL_test_compare.h"
37 | #include "SDL_test_crc32.h"
38 | #include "SDL_test_font.h"
39 | #include "SDL_test_fuzzer.h"
40 | #include "SDL_test_harness.h"
41 | #include "SDL_test_images.h"
42 | #include "SDL_test_log.h"
43 | #include "SDL_test_md5.h"
44 | #include "SDL_test_memory.h"
45 | #include "SDL_test_random.h"
46 |
47 | #include "begin_code.h"
48 | /* Set up for C function definitions, even when using C++ */
49 | #ifdef __cplusplus
50 | extern "C" {
51 | #endif
52 |
53 | /* Global definitions */
54 |
55 | /*
56 | * Note: Maximum size of SDLTest log message is less than SDL's limit
57 | * to ensure we can fit additional information such as the timestamp.
58 | */
59 | #define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584
60 |
61 | /* Ends C function definitions when using C++ */
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 | #include "close_code.h"
66 |
67 | #endif /* SDL_test_h_ */
68 |
69 | /* vi: set ts=4 sw=4 expandtab: */
70 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_test_log.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_test_log.h
24 | *
25 | * Include file for SDL test framework.
26 | *
27 | * This code is a part of the SDL2_test library, not the main SDL library.
28 | */
29 |
30 | /*
31 | *
32 | * Wrapper to log in the TEST category
33 | *
34 | */
35 |
36 | #ifndef SDL_test_log_h_
37 | #define SDL_test_log_h_
38 |
39 | #include "begin_code.h"
40 | /* Set up for C function definitions, even when using C++ */
41 | #ifdef __cplusplus
42 | extern "C" {
43 | #endif
44 |
45 | /**
46 | * \brief Prints given message with a timestamp in the TEST category and INFO priority.
47 | *
48 | * \param fmt Message to be logged
49 | */
50 | void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
51 |
52 | /**
53 | * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
54 | *
55 | * \param fmt Message to be logged
56 | */
57 | void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
58 |
59 | /* Ends C function definitions when using C++ */
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 | #include "close_code.h"
64 |
65 | #endif /* SDL_test_log_h_ */
66 |
67 | /* vi: set ts=4 sw=4 expandtab: */
68 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_test_memory.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_test_memory.h
24 | *
25 | * Include file for SDL test framework.
26 | *
27 | * This code is a part of the SDL2_test library, not the main SDL library.
28 | */
29 |
30 | #ifndef SDL_test_memory_h_
31 | #define SDL_test_memory_h_
32 |
33 | #include "begin_code.h"
34 | /* Set up for C function definitions, even when using C++ */
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif
38 |
39 |
40 | /**
41 | * \brief Start tracking SDL memory allocations
42 | *
43 | * \note This should be called before any other SDL functions for complete tracking coverage
44 | */
45 | int SDLTest_TrackAllocations(void);
46 |
47 | /**
48 | * \brief Print a log of any outstanding allocations
49 | *
50 | * \note This can be called after SDL_Quit()
51 | */
52 | void SDLTest_LogAllocations(void);
53 |
54 |
55 | /* Ends C function definitions when using C++ */
56 | #ifdef __cplusplus
57 | }
58 | #endif
59 | #include "close_code.h"
60 |
61 | #endif /* SDL_test_memory_h_ */
62 |
63 | /* vi: set ts=4 sw=4 expandtab: */
64 |
--------------------------------------------------------------------------------
/libs/SDL2/include/SDL_types.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file SDL_types.h
24 | *
25 | * \deprecated
26 | */
27 |
28 | /* DEPRECATED */
29 | #include "SDL_stdinc.h"
30 |
--------------------------------------------------------------------------------
/libs/SDL2/include/close_code.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple DirectMedia Layer
3 | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any damages
7 | arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any purpose,
10 | including commercial applications, and to alter it and redistribute it
11 | freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you must not
14 | claim that you wrote the original software. If you use this software
15 | in a product, an acknowledgment in the product documentation would be
16 | appreciated but is not required.
17 | 2. Altered source versions must be plainly marked as such, and must not be
18 | misrepresented as being the original software.
19 | 3. This notice may not be removed or altered from any source distribution.
20 | */
21 |
22 | /**
23 | * \file close_code.h
24 | *
25 | * This file reverses the effects of begin_code.h and should be included
26 | * after you finish any function and structure declarations in your headers
27 | */
28 |
29 | #ifndef _begin_code_h
30 | #error close_code.h included without matching begin_code.h
31 | #endif
32 | #undef _begin_code_h
33 |
34 | /* Reset structure packing at previous byte alignment */
35 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
36 | #ifdef __BORLANDC__
37 | #pragma nopackwarning
38 | #endif
39 | #pragma pack(pop)
40 | #endif /* Compiler needs structure packing set */
41 |
--------------------------------------------------------------------------------
/libs/SDL2/lib/x86/SDL2.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/SDL2/lib/x86/SDL2.lib
--------------------------------------------------------------------------------
/libs/SDL2/lib/x86/SDL2main.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/SDL2/lib/x86/SDL2main.lib
--------------------------------------------------------------------------------
/libs/SDL2/lib/x86/SDL2test.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/SDL2/lib/x86/SDL2test.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavcodec/ac3_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AC-3 parser prototypes
3 | * Copyright (c) 2003 Fabrice Bellard
4 | * Copyright (c) 2003 Michael Niedermayer
5 | *
6 | * This file is part of FFmpeg.
7 | *
8 | * FFmpeg is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * FFmpeg is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with FFmpeg; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | */
22 |
23 | #ifndef AVCODEC_AC3_PARSER_H
24 | #define AVCODEC_AC3_PARSER_H
25 |
26 | #include <stddef.h>
27 | #include <stdint.h>
28 |
29 | /**
30 | * Extract the bitstream ID and the frame size from AC-3 data.
31 | */
32 | int av_ac3_parse_header(const uint8_t *buf, size_t size,
33 | uint8_t *bitstream_id, uint16_t *frame_size);
34 |
35 |
36 | #endif /* AVCODEC_AC3_PARSER_H */
37 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavcodec/adts_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVCODEC_ADTS_PARSER_H
20 | #define AVCODEC_ADTS_PARSER_H
21 |
22 | #include <stddef.h>
23 | #include <stdint.h>
24 |
25 | #define AV_AAC_ADTS_HEADER_SIZE 7
26 |
27 | /**
28 | * Extract the number of samples and frames from AAC data.
29 | * @param[in] buf pointer to AAC data buffer
30 | * @param[out] samples Pointer to where number of samples is written
31 | * @param[out] frames Pointer to where number of frames is written
32 | * @return Returns 0 on success, error code on failure.
33 | */
34 | int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
35 | uint8_t *frames);
36 |
37 | #endif /* AVCODEC_ADTS_PARSER_H */
38 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavcodec/jni.h:
--------------------------------------------------------------------------------
1 | /*
2 | * JNI public API functions
3 | *
4 | * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5 | *
6 | * This file is part of FFmpeg.
7 | *
8 | * FFmpeg is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * FFmpeg is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with FFmpeg; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | */
22 |
23 | #ifndef AVCODEC_JNI_H
24 | #define AVCODEC_JNI_H
25 |
26 | /*
27 | * Manually set a Java virtual machine which will be used to retrieve the JNI
28 | * environment. Once a Java VM is set it cannot be changed afterwards, meaning
29 | * you can call multiple times av_jni_set_java_vm with the same Java VM pointer
30 | * however it will error out if you try to set a different Java VM.
31 | *
32 | * @param vm Java virtual machine
33 | * @param log_ctx context used for logging, can be NULL
34 | * @return 0 on success, < 0 otherwise
35 | */
36 | int av_jni_set_java_vm(void *vm, void *log_ctx);
37 |
38 | /*
39 | * Get the Java virtual machine which has been set with av_jni_set_java_vm.
40 | *
41 | * @param vm Java virtual machine
42 | * @return a pointer to the Java virtual machine
43 | */
44 | void *av_jni_get_java_vm(void *log_ctx);
45 |
46 | #endif /* AVCODEC_JNI_H */
47 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavdevice/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVDEVICE_VERSION_H
20 | #define AVDEVICE_VERSION_H
21 |
22 | /**
23 | * @file
24 | * @ingroup lavd
25 | * Libavdevice version macros
26 | */
27 |
28 | #include "libavutil/version.h"
29 |
30 | #define LIBAVDEVICE_VERSION_MAJOR 58
31 | #define LIBAVDEVICE_VERSION_MINOR 4
32 | #define LIBAVDEVICE_VERSION_MICRO 100
33 |
34 | #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
35 | LIBAVDEVICE_VERSION_MINOR, \
36 | LIBAVDEVICE_VERSION_MICRO)
37 | #define LIBAVDEVICE_VERSION AV_VERSION(LIBAVDEVICE_VERSION_MAJOR, \
38 | LIBAVDEVICE_VERSION_MINOR, \
39 | LIBAVDEVICE_VERSION_MICRO)
40 | #define LIBAVDEVICE_BUILD LIBAVDEVICE_VERSION_INT
41 |
42 | #define LIBAVDEVICE_IDENT "Lavd" AV_STRINGIFY(LIBAVDEVICE_VERSION)
43 |
44 | /**
45 | * FF_API_* defines may be placed below to indicate public API that will be
46 | * dropped at a future version bump. The defines themselves are not part of
47 | * the public API and may change, break or disappear at any time.
48 | */
49 |
50 | #endif /* AVDEVICE_VERSION_H */
51 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/adler32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2006 Mans Rullgard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @ingroup lavu_adler32
24 | * Public header for Adler-32 hash function implementation.
25 | */
26 |
27 | #ifndef AVUTIL_ADLER32_H
28 | #define AVUTIL_ADLER32_H
29 |
30 | #include <stdint.h>
31 | #include "attributes.h"
32 |
33 | /**
34 | * @defgroup lavu_adler32 Adler-32
35 | * @ingroup lavu_hash
36 | * Adler-32 hash function implementation.
37 | *
38 | * @{
39 | */
40 |
41 | /**
42 | * Calculate the Adler32 checksum of a buffer.
43 | *
44 | * Passing the return value to a subsequent av_adler32_update() call
45 | * allows the checksum of multiple buffers to be calculated as though
46 | * they were concatenated.
47 | *
48 | * @param adler initial checksum value
49 | * @param buf pointer to input buffer
50 | * @param len size of input buffer
51 | * @return updated checksum
52 | */
53 | unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
54 | unsigned int len) av_pure;
55 |
56 | /**
57 | * @}
58 | */
59 |
60 | #endif /* AVUTIL_ADLER32_H */
61 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/aes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_AES_H
22 | #define AVUTIL_AES_H
23 |
24 | #include <stdint.h>
25 |
26 | #include "attributes.h"
27 | #include "version.h"
28 |
29 | /**
30 | * @defgroup lavu_aes AES
31 | * @ingroup lavu_crypto
32 | * @{
33 | */
34 |
35 | extern const int av_aes_size;
36 |
37 | struct AVAES;
38 |
39 | /**
40 | * Allocate an AVAES context.
41 | */
42 | struct AVAES *av_aes_alloc(void);
43 |
44 | /**
45 | * Initialize an AVAES context.
46 | * @param key_bits 128, 192 or 256
47 | * @param decrypt 0 for encryption, 1 for decryption
48 | */
49 | int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
50 |
51 | /**
52 | * Encrypt or decrypt a buffer using a previously initialized context.
53 | * @param count number of 16 byte blocks
54 | * @param dst destination array, can be equal to src
55 | * @param src source array, can be equal to dst
56 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
57 | * @param decrypt 0 for encryption, 1 for decryption
58 | */
59 | void av_aes_crypt(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
60 |
61 | /**
62 | * @}
63 | */
64 |
65 | #endif /* AVUTIL_AES_H */
66 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/avconfig.h:
--------------------------------------------------------------------------------
1 | /* Generated by ffmpeg configure */
2 | #ifndef AVUTIL_AVCONFIG_H
3 | #define AVUTIL_AVCONFIG_H
4 | #define AV_HAVE_BIGENDIAN 0
5 | #define AV_HAVE_FAST_UNALIGNED 1
6 | #endif /* AVUTIL_AVCONFIG_H */
7 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/ffversion.h:
--------------------------------------------------------------------------------
1 | /* Automatically generated by version.sh, do not manually edit! */
2 | #ifndef AVUTIL_FFVERSION_H
3 | #define AVUTIL_FFVERSION_H
4 | #define FFMPEG_VERSION "N-91125-g16b4f97b72"
5 | #endif /* AVUTIL_FFVERSION_H */
6 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/hwcontext_cuda.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 |
20 | #ifndef AVUTIL_HWCONTEXT_CUDA_H
21 | #define AVUTIL_HWCONTEXT_CUDA_H
22 |
23 | #ifndef CUDA_VERSION
24 | #include <cuda.h>
25 | #endif
26 |
27 | #include "pixfmt.h"
28 |
29 | /**
30 | * @file
31 | * An API-specific header for AV_HWDEVICE_TYPE_CUDA.
32 | *
33 | * This API supports dynamic frame pools. AVHWFramesContext.pool must return
34 | * AVBufferRefs whose data pointer is a CUdeviceptr.
35 | */
36 |
37 | typedef struct AVCUDADeviceContextInternal AVCUDADeviceContextInternal;
38 |
39 | /**
40 | * This struct is allocated as AVHWDeviceContext.hwctx
41 | */
42 | typedef struct AVCUDADeviceContext {
43 | CUcontext cuda_ctx;
44 | CUstream stream;
45 | AVCUDADeviceContextInternal *internal;
46 | } AVCUDADeviceContext;
47 |
48 | /**
49 | * AVHWFramesContext.hwctx is currently not used
50 | */
51 |
52 | #endif /* AVUTIL_HWCONTEXT_CUDA_H */
53 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/hwcontext_mediacodec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_MEDIACODEC_H
20 | #define AVUTIL_HWCONTEXT_MEDIACODEC_H
21 |
22 | /**
23 | * MediaCodec details.
24 | *
25 | * Allocated as AVHWDeviceContext.hwctx
26 | */
27 | typedef struct AVMediaCodecDeviceContext {
28 | /**
29 | * android/view/Surface handle, to be filled by the user.
30 | *
31 | * This is the default surface used by decoders on this device.
32 | */
33 | void *surface;
34 | } AVMediaCodecDeviceContext;
35 |
36 | #endif /* AVUTIL_HWCONTEXT_MEDIACODEC_H */
37 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/hwcontext_qsv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_QSV_H
20 | #define AVUTIL_HWCONTEXT_QSV_H
21 |
22 | #include <mfx/mfxvideo.h>
23 |
24 | /**
25 | * @file
26 | * An API-specific header for AV_HWDEVICE_TYPE_QSV.
27 | *
28 | * This API does not support dynamic frame pools. AVHWFramesContext.pool must
29 | * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct.
30 | */
31 |
32 | /**
33 | * This struct is allocated as AVHWDeviceContext.hwctx
34 | */
35 | typedef struct AVQSVDeviceContext {
36 | mfxSession session;
37 | } AVQSVDeviceContext;
38 |
39 | /**
40 | * This struct is allocated as AVHWFramesContext.hwctx
41 | */
42 | typedef struct AVQSVFramesContext {
43 | mfxFrameSurface1 *surfaces;
44 | int nb_surfaces;
45 |
46 | /**
47 | * A combination of MFX_MEMTYPE_* describing the frame pool.
48 | */
49 | int frame_type;
50 | } AVQSVFramesContext;
51 |
52 | #endif /* AVUTIL_HWCONTEXT_QSV_H */
53 |
54 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/hwcontext_vdpau.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_VDPAU_H
20 | #define AVUTIL_HWCONTEXT_VDPAU_H
21 |
22 | #include <vdpau/vdpau.h>
23 |
24 | /**
25 | * @file
26 | * An API-specific header for AV_HWDEVICE_TYPE_VDPAU.
27 | *
28 | * This API supports dynamic frame pools. AVHWFramesContext.pool must return
29 | * AVBufferRefs whose data pointer is a VdpVideoSurface.
30 | */
31 |
32 | /**
33 | * This struct is allocated as AVHWDeviceContext.hwctx
34 | */
35 | typedef struct AVVDPAUDeviceContext {
36 | VdpDevice device;
37 | VdpGetProcAddress *get_proc_address;
38 | } AVVDPAUDeviceContext;
39 |
40 | /**
41 | * AVHWFramesContext.hwctx is currently not used
42 | */
43 |
44 | #endif /* AVUTIL_HWCONTEXT_VDPAU_H */
45 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/hwcontext_videotoolbox.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
20 | #define AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
21 |
22 | #include <stdint.h>
23 |
24 | #include <VideoToolbox/VideoToolbox.h>
25 |
26 | #include "pixfmt.h"
27 |
28 | /**
29 | * @file
30 | * An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
31 | *
32 | * This API currently does not support frame allocation, as the raw VideoToolbox
33 | * API does allocation, and FFmpeg itself never has the need to allocate frames.
34 | *
35 | * If the API user sets a custom pool, AVHWFramesContext.pool must return
36 | * AVBufferRefs whose data pointer is a CVImageBufferRef or CVPixelBufferRef.
37 | *
38 | * Currently AVHWDeviceContext.hwctx and AVHWFramesContext.hwctx are always
39 | * NULL.
40 | */
41 |
42 | /**
43 | * Convert a VideoToolbox (actually CoreVideo) format to AVPixelFormat.
44 | * Returns AV_PIX_FMT_NONE if no known equivalent was found.
45 | */
46 | enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt);
47 |
48 | /**
49 | * Convert an AVPixelFormat to a VideoToolbox (actually CoreVideo) format.
50 | * Returns 0 if no known equivalent was found.
51 | */
52 | uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt);
53 |
54 | #endif /* AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H */
55 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/intfloat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 Mans Rullgard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_INTFLOAT_H
22 | #define AVUTIL_INTFLOAT_H
23 |
24 | #include <stdint.h>
25 | #include "attributes.h"
26 |
27 | union av_intfloat32 {
28 | uint32_t i;
29 | float f;
30 | };
31 |
32 | union av_intfloat64 {
33 | uint64_t i;
34 | double f;
35 | };
36 |
37 | /**
38 | * Reinterpret a 32-bit integer as a float.
39 | */
40 | static av_always_inline float av_int2float(uint32_t i)
41 | {
42 | union av_intfloat32 v;
43 | v.i = i;
44 | return v.f;
45 | }
46 |
47 | /**
48 | * Reinterpret a float as a 32-bit integer.
49 | */
50 | static av_always_inline uint32_t av_float2int(float f)
51 | {
52 | union av_intfloat32 v;
53 | v.f = f;
54 | return v.i;
55 | }
56 |
57 | /**
58 | * Reinterpret a 64-bit integer as a double.
59 | */
60 | static av_always_inline double av_int2double(uint64_t i)
61 | {
62 | union av_intfloat64 v;
63 | v.i = i;
64 | return v.f;
65 | }
66 |
67 | /**
68 | * Reinterpret a double as a 64-bit integer.
69 | */
70 | static av_always_inline uint64_t av_double2int(double f)
71 | {
72 | union av_intfloat64 v;
73 | v.f = f;
74 | return v.i;
75 | }
76 |
77 | #endif /* AVUTIL_INTFLOAT_H */
78 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/lzo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LZO 1x decompression
3 | * copyright (c) 2006 Reimar Doeffinger
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_LZO_H
23 | #define AVUTIL_LZO_H
24 |
25 | /**
26 | * @defgroup lavu_lzo LZO
27 | * @ingroup lavu_crypto
28 | *
29 | * @{
30 | */
31 |
32 | #include <stdint.h>
33 |
34 | /** @name Error flags returned by av_lzo1x_decode
35 | * @{ */
36 | /// end of the input buffer reached before decoding finished
37 | #define AV_LZO_INPUT_DEPLETED 1
38 | /// decoded data did not fit into output buffer
39 | #define AV_LZO_OUTPUT_FULL 2
40 | /// a reference to previously decoded data was wrong
41 | #define AV_LZO_INVALID_BACKPTR 4
42 | /// a non-specific error in the compressed bitstream
43 | #define AV_LZO_ERROR 8
44 | /** @} */
45 |
46 | #define AV_LZO_INPUT_PADDING 8
47 | #define AV_LZO_OUTPUT_PADDING 12
48 |
49 | /**
50 | * @brief Decodes LZO 1x compressed data.
51 | * @param out output buffer
52 | * @param outlen size of output buffer, number of bytes left are returned here
53 | * @param in input buffer
54 | * @param inlen size of input buffer, number of bytes left are returned here
55 | * @return 0 on success, otherwise a combination of the error flags above
56 | *
57 | * Make sure all buffers are appropriately padded, in must provide
58 | * AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes.
59 | */
60 | int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | #endif /* AVUTIL_LZO_H */
67 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/macros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | /**
20 | * @file
21 | * @ingroup lavu
22 | * Utility Preprocessor macros
23 | */
24 |
25 | #ifndef AVUTIL_MACROS_H
26 | #define AVUTIL_MACROS_H
27 |
28 | /**
29 | * @addtogroup preproc_misc Preprocessor String Macros
30 | *
31 | * String manipulation macros
32 | *
33 | * @{
34 | */
35 |
36 | #define AV_STRINGIFY(s) AV_TOSTRING(s)
37 | #define AV_TOSTRING(s) #s
38 |
39 | #define AV_GLUE(a, b) a ## b
40 | #define AV_JOIN(a, b) AV_GLUE(a, b)
41 |
42 | /**
43 | * @}
44 | */
45 |
46 | #define AV_PRAGMA(s) _Pragma(#s)
47 |
48 | #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
49 |
50 | #endif /* AVUTIL_MACROS_H */
51 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/motion_vector.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_MOTION_VECTOR_H
20 | #define AVUTIL_MOTION_VECTOR_H
21 |
22 | #include <stdint.h>
23 |
24 | typedef struct AVMotionVector {
25 | /**
26 | * Where the current macroblock comes from; negative value when it comes
27 | * from the past, positive value when it comes from the future.
28 | * XXX: set exact relative ref frame reference instead of a +/- 1 "direction".
29 | */
30 | int32_t source;
31 | /**
32 | * Width and height of the block.
33 | */
34 | uint8_t w, h;
35 | /**
36 | * Absolute source position. Can be outside the frame area.
37 | */
38 | int16_t src_x, src_y;
39 | /**
40 | * Absolute destination position. Can be outside the frame area.
41 | */
42 | int16_t dst_x, dst_y;
43 | /**
44 | * Extra flag information.
45 | * Currently unused.
46 | */
47 | uint64_t flags;
48 | /**
49 | * Motion vector
50 | * src_x = dst_x + motion_x / motion_scale
51 | * src_y = dst_y + motion_y / motion_scale
52 | */
53 | int32_t motion_x, motion_y;
54 | uint16_t motion_scale;
55 | } AVMotionVector;
56 |
57 | #endif /* AVUTIL_MOTION_VECTOR_H */
58 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/pixelutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_PIXELUTILS_H
20 | #define AVUTIL_PIXELUTILS_H
21 |
22 | #include <stddef.h>
23 | #include <stdint.h>
24 | #include "common.h"
25 |
26 | /**
27 | * Sum of abs(src1[x] - src2[x])
28 | */
29 | typedef int (*av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1,
30 | const uint8_t *src2, ptrdiff_t stride2);
31 |
32 | /**
33 | * Get a potentially optimized pointer to a Sum-of-absolute-differences
34 | * function (see the av_pixelutils_sad_fn prototype).
35 | *
36 | * @param w_bits 1<<w_bits is the requested width of the block size
37 | * @param h_bits 1<<h_bits is the requested height of the block size
38 | * @param aligned If set to 2, the returned sad function will assume src1 and
39 | * src2 addresses are aligned on the block size.
40 | * If set to 1, the returned sad function will assume src1 is
41 | * aligned on the block size.
42 | * If set to 0, the returned sad function assume no particular
43 | * alignment.
44 | * @param log_ctx context used for logging, can be NULL
45 | *
46 | * @return a pointer to the SAD function or NULL in case of error (because of
47 | * invalid parameters)
48 | */
49 | av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits,
50 | int aligned, void *log_ctx);
51 |
52 | #endif /* AVUTIL_PIXELUTILS_H */
53 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/random_seed.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_RANDOM_SEED_H
22 | #define AVUTIL_RANDOM_SEED_H
23 |
24 | #include <stdint.h>
25 | /**
26 | * @addtogroup lavu_crypto
27 | * @{
28 | */
29 |
30 | /**
31 | * Get a seed to use in conjunction with random functions.
32 | * This function tries to provide a good seed at a best effort bases.
33 | * Its possible to call this function multiple times if more bits are needed.
34 | * It can be quite slow, which is why it should only be used as seed for a faster
35 | * PRNG. The quality of the seed depends on the platform.
36 | */
37 | uint32_t av_get_random_seed(void);
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | #endif /* AVUTIL_RANDOM_SEED_H */
44 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/rc4.h:
--------------------------------------------------------------------------------
1 | /*
2 | * RC4 encryption/decryption/pseudo-random number generator
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_RC4_H
22 | #define AVUTIL_RC4_H
23 |
24 | #include <stdint.h>
25 |
26 | /**
27 | * @defgroup lavu_rc4 RC4
28 | * @ingroup lavu_crypto
29 | * @{
30 | */
31 |
32 | typedef struct AVRC4 {
33 | uint8_t state[256];
34 | int x, y;
35 | } AVRC4;
36 |
37 | /**
38 | * Allocate an AVRC4 context.
39 | */
40 | AVRC4 *av_rc4_alloc(void);
41 |
42 | /**
43 | * @brief Initializes an AVRC4 context.
44 | *
45 | * @param key_bits must be a multiple of 8
46 | * @param decrypt 0 for encryption, 1 for decryption, currently has no effect
47 | * @return zero on success, negative value otherwise
48 | */
49 | int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt);
50 |
51 | /**
52 | * @brief Encrypts / decrypts using the RC4 algorithm.
53 | *
54 | * @param count number of bytes
55 | * @param dst destination array, can be equal to src
56 | * @param src source array, can be equal to dst, may be NULL
57 | * @param iv not (yet) used for RC4, should be NULL
58 | * @param decrypt 0 for encryption, 1 for decryption, not (yet) used
59 | */
60 | void av_rc4_crypt(struct AVRC4 *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | #endif /* AVUTIL_RC4_H */
67 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/replaygain.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_REPLAYGAIN_H
20 | #define AVUTIL_REPLAYGAIN_H
21 |
22 | #include <stdint.h>
23 |
24 | /**
25 | * ReplayGain information (see
26 | * http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification).
27 | * The size of this struct is a part of the public ABI.
28 | */
29 | typedef struct AVReplayGain {
30 | /**
31 | * Track replay gain in microbels (divide by 100000 to get the value in dB).
32 | * Should be set to INT32_MIN when unknown.
33 | */
34 | int32_t track_gain;
35 | /**
36 | * Peak track amplitude, with 100000 representing full scale (but values
37 | * may overflow). 0 when unknown.
38 | */
39 | uint32_t track_peak;
40 | /**
41 | * Same as track_gain, but for the whole album.
42 | */
43 | int32_t album_gain;
44 | /**
45 | * Same as track_peak, but for the whole album,
46 | */
47 | uint32_t album_peak;
48 | } AVReplayGain;
49 |
50 | #endif /* AVUTIL_REPLAYGAIN_H */
51 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/tea.h:
--------------------------------------------------------------------------------
1 | /*
2 | * A 32-bit implementation of the TEA algorithm
3 | * Copyright (c) 2015 Vesselin Bontchev
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_TEA_H
23 | #define AVUTIL_TEA_H
24 |
25 | #include <stdint.h>
26 |
27 | /**
28 | * @file
29 | * @brief Public header for libavutil TEA algorithm
30 | * @defgroup lavu_tea TEA
31 | * @ingroup lavu_crypto
32 | * @{
33 | */
34 |
35 | extern const int av_tea_size;
36 |
37 | struct AVTEA;
38 |
39 | /**
40 | * Allocate an AVTEA context
41 | * To free the struct: av_free(ptr)
42 | */
43 | struct AVTEA *av_tea_alloc(void);
44 |
45 | /**
46 | * Initialize an AVTEA context.
47 | *
48 | * @param ctx an AVTEA context
49 | * @param key a key of 16 bytes used for encryption/decryption
50 | * @param rounds the number of rounds in TEA (64 is the "standard")
51 | */
52 | void av_tea_init(struct AVTEA *ctx, const uint8_t key[16], int rounds);
53 |
54 | /**
55 | * Encrypt or decrypt a buffer using a previously initialized context.
56 | *
57 | * @param ctx an AVTEA context
58 | * @param dst destination array, can be equal to src
59 | * @param src source array, can be equal to dst
60 | * @param count number of 8 byte blocks
61 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
62 | * @param decrypt 0 for encryption, 1 for decryption
63 | */
64 | void av_tea_crypt(struct AVTEA *ctx, uint8_t *dst, const uint8_t *src,
65 | int count, uint8_t *iv, int decrypt);
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | #endif /* AVUTIL_TEA_H */
72 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libavutil/time.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2003 Fabrice Bellard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_TIME_H
22 | #define AVUTIL_TIME_H
23 |
24 | #include <stdint.h>
25 |
26 | /**
27 | * Get the current time in microseconds.
28 | */
29 | int64_t av_gettime(void);
30 |
31 | /**
32 | * Get the current time in microseconds since some unspecified starting point.
33 | * On platforms that support it, the time comes from a monotonic clock
34 | * This property makes this time source ideal for measuring relative time.
35 | * The returned values may not be monotonic on platforms where a monotonic
36 | * clock is not available.
37 | */
38 | int64_t av_gettime_relative(void);
39 |
40 | /**
41 | * Indicates with a boolean result if the av_gettime_relative() time source
42 | * is monotonic.
43 | */
44 | int av_gettime_relative_is_monotonic(void);
45 |
46 | /**
47 | * Sleep for a period of time. Although the duration is expressed in
48 | * microseconds, the actual delay may be rounded to the precision of the
49 | * system timer.
50 | *
51 | * @param usec Number of microseconds to sleep.
52 | * @return zero on success or (negative) error code.
53 | */
54 | int av_usleep(unsigned usec);
55 |
56 | #endif /* AVUTIL_TIME_H */
57 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libpostproc/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Version macros.
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef POSTPROC_VERSION_H
22 | #define POSTPROC_VERSION_H
23 |
24 | /**
25 | * @file
26 | * Libpostproc version macros
27 | */
28 |
29 | #include "libavutil/avutil.h"
30 |
31 | #define LIBPOSTPROC_VERSION_MAJOR 55
32 | #define LIBPOSTPROC_VERSION_MINOR 2
33 | #define LIBPOSTPROC_VERSION_MICRO 100
34 |
35 | #define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \
36 | LIBPOSTPROC_VERSION_MINOR, \
37 | LIBPOSTPROC_VERSION_MICRO)
38 | #define LIBPOSTPROC_VERSION AV_VERSION(LIBPOSTPROC_VERSION_MAJOR, \
39 | LIBPOSTPROC_VERSION_MINOR, \
40 | LIBPOSTPROC_VERSION_MICRO)
41 | #define LIBPOSTPROC_BUILD LIBPOSTPROC_VERSION_INT
42 |
43 | #define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION)
44 |
45 | #endif /* POSTPROC_VERSION_H */
46 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libswresample/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Version macros.
3 | *
4 | * This file is part of libswresample
5 | *
6 | * libswresample is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * libswresample is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with libswresample; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef SWRESAMPLE_VERSION_H
22 | #define SWRESAMPLE_VERSION_H
23 |
24 | /**
25 | * @file
26 | * Libswresample version macros
27 | */
28 |
29 | #include "libavutil/avutil.h"
30 |
31 | #define LIBSWRESAMPLE_VERSION_MAJOR 3
32 | #define LIBSWRESAMPLE_VERSION_MINOR 2
33 | #define LIBSWRESAMPLE_VERSION_MICRO 100
34 |
35 | #define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
36 | LIBSWRESAMPLE_VERSION_MINOR, \
37 | LIBSWRESAMPLE_VERSION_MICRO)
38 | #define LIBSWRESAMPLE_VERSION AV_VERSION(LIBSWRESAMPLE_VERSION_MAJOR, \
39 | LIBSWRESAMPLE_VERSION_MINOR, \
40 | LIBSWRESAMPLE_VERSION_MICRO)
41 | #define LIBSWRESAMPLE_BUILD LIBSWRESAMPLE_VERSION_INT
42 |
43 | #define LIBSWRESAMPLE_IDENT "SwR" AV_STRINGIFY(LIBSWRESAMPLE_VERSION)
44 |
45 | #endif /* SWRESAMPLE_VERSION_H */
46 |
--------------------------------------------------------------------------------
/libs/ffmpeg/include/libswscale/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef SWSCALE_VERSION_H
20 | #define SWSCALE_VERSION_H
21 |
22 | /**
23 | * @file
24 | * swscale version macros
25 | */
26 |
27 | #include "libavutil/version.h"
28 |
29 | #define LIBSWSCALE_VERSION_MAJOR 5
30 | #define LIBSWSCALE_VERSION_MINOR 2
31 | #define LIBSWSCALE_VERSION_MICRO 100
32 |
33 | #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
34 | LIBSWSCALE_VERSION_MINOR, \
35 | LIBSWSCALE_VERSION_MICRO)
36 | #define LIBSWSCALE_VERSION AV_VERSION(LIBSWSCALE_VERSION_MAJOR, \
37 | LIBSWSCALE_VERSION_MINOR, \
38 | LIBSWSCALE_VERSION_MICRO)
39 | #define LIBSWSCALE_BUILD LIBSWSCALE_VERSION_INT
40 |
41 | #define LIBSWSCALE_IDENT "SwS" AV_STRINGIFY(LIBSWSCALE_VERSION)
42 |
43 | /**
44 | * FF_API_* defines may be placed below to indicate public API that will be
45 | * dropped at a future version bump. The defines themselves are not part of
46 | * the public API and may change, break or disappear at any time.
47 | */
48 |
49 | #ifndef FF_API_SWS_VECTOR
50 | #define FF_API_SWS_VECTOR (LIBSWSCALE_VERSION_MAJOR < 6)
51 | #endif
52 |
53 | #endif /* SWSCALE_VERSION_H */
54 |
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/avcodec.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/avcodec.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/avdevice.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/avdevice.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/avfilter.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/avfilter.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/avformat.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/avformat.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/avutil.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/avutil.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/postproc.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/postproc.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/swresample.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/swresample.lib
--------------------------------------------------------------------------------
/libs/ffmpeg/lib/swscale.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/ffmpeg/lib/swscale.lib
--------------------------------------------------------------------------------
/libs/glfw/COPYING.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2002-2006 Marcus Geelnard
2 | Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
3 |
4 | This software is provided 'as-is', without any express or implied
5 | warranty. In no event will the authors be held liable for any damages
6 | arising from the use of this software.
7 |
8 | Permission is granted to anyone to use this software for any purpose,
9 | including commercial applications, and to alter it and redistribute it
10 | freely, subject to the following restrictions:
11 |
12 | 1. The origin of this software must not be misrepresented; you must not
13 | claim that you wrote the original software. If you use this software
14 | in a product, an acknowledgment in the product documentation would
15 | be appreciated but is not required.
16 |
17 | 2. Altered source versions must be plainly marked as such, and must not
18 | be misrepresented as being the original software.
19 |
20 | 3. This notice may not be removed or altered from any source
21 | distribution.
22 |
23 |
--------------------------------------------------------------------------------
/libs/glfw/lib-vc2010-32/glfw3.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/glfw/lib-vc2010-32/glfw3.lib
--------------------------------------------------------------------------------
/libs/glfw/lib-vc2010-64/glfw3.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/libs/glfw/lib-vc2010-64/glfw3.lib
--------------------------------------------------------------------------------
/pic/2.pic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/pic/2.pic.jpg
--------------------------------------------------------------------------------
/run-env/SDL2.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/SDL2.dll
--------------------------------------------------------------------------------
/run-env/avcodec-58.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/avcodec-58.dll
--------------------------------------------------------------------------------
/run-env/avdevice-58.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/avdevice-58.dll
--------------------------------------------------------------------------------
/run-env/avfilter-7.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/avfilter-7.dll
--------------------------------------------------------------------------------
/run-env/avformat-58.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/avformat-58.dll
--------------------------------------------------------------------------------
/run-env/avutil-56.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/avutil-56.dll
--------------------------------------------------------------------------------
/run-env/postproc-55.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/postproc-55.dll
--------------------------------------------------------------------------------
/run-env/swresample-3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/swresample-3.dll
--------------------------------------------------------------------------------
/run-env/swscale-5.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PHZ76/DesktopSharing/110e8aaa5ab109ca73e9bcd4609f754c005865b7/run-env/swscale-5.dll
--------------------------------------------------------------------------------