Skip to content

Instantly share code, notes, and snippets.

View suzp1984's full-sized avatar
🏢
Office time

Jacob Su suzp1984

🏢
Office time
View GitHub Profile
@suzp1984
suzp1984 / srs_protocol_rtmp_stack.cpp
Created March 14, 2024 01:32
SRS: recv RTMP message
/**
* https://rtmp.veriskope.com/docs/spec/#531chunk-format
*/
srs_error_t SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
{
srs_error_t err = srs_success;
// chunk stream basic header.
char fmt = 0;
int cid = 0;
@suzp1984
suzp1984 / srs_protocol_rtmp_handshake.hpp
Last active March 13, 2024 11:02
SRS: RTMP handshake
/**
* https://github.com/ossrs/srs/blob/fa8096ad0117a085515729e12a3758ca26036552/trunk/src/protocol/srs_protocol_rtmp_handshake.hpp#L401-L431
*/
// Simple handshake.
// user can try complex handshake first,
// rollback to simple handshake if error ERROR_RTMP_TRY_SIMPLE_HS
class SrsSimpleHandshake
{
public:
SrsSimpleHandshake();
@suzp1984
suzp1984 / srs_protocol_rtmp_stack.cpp
Created March 13, 2024 07:04
SRS: how to read RTMP basic header?
/*
* https://github.com/ossrs/srs/blob/fa8096ad0117a085515729e12a3758ca26036552/trunk/src/protocol/srs_protocol_rtmp_stack.cpp#L843-L924
*/
/**
* 6.1.1. Chunk Basic Header
* The Chunk Basic Header encodes the chunk stream ID and the chunk
* type(represented by fmt field in the figure below). Chunk type
* determines the format of the encoded message header. Chunk Basic
* Header field may be 1, 2, or 3 bytes, depending on the chunk stream
* ID.
@suzp1984
suzp1984 / CMakeLists.txt
Created May 30, 2020 09:48
CMakeLists.txt that used to find GLib-2.0 library
cmake_minimum_required (VERSION 2.8)
cmake_policy(VERSION 2.8)
project (GStreamerTest)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
find_package(GLib)
if (GLib_FOUND)
message(STATUS "GLIB 2.0 FOUND!!")
@suzp1984
suzp1984 / FindGLib.cmake
Created May 30, 2020 09:44
cmake find package module
# use pkg-config system
find_package(PkgConfig QUIET)
# FIND_GLIB_COMPONENT macro
macro(FIND_GLIB_COMPONENT _component_prefix _pkgconfig_name _library)
pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name})
set(${_component_prefix}_INCLUDE_DIRS ${PC_${_component_prefix}_INCLUDE_DIRS})
@suzp1984
suzp1984 / InputConnectionSetup.kt
Last active December 14, 2019 00:49
wire up the unfocusable EditText with CustomInputView & InputDelegateView
// editText -> unfocusable EditText
// customeKeyboardView -> simulated keyboard
// inputDelegateView -> Delegate system keyboard input to EditText
func wireUpConnections() {
val inputConnection = editText.onCreateInputConnection(EditorInfo())
customeKeyboardView.inputConnection = inputConnection
val keyboardInputConnection = editText.onCreateInputConnection(EditorInfo())
inputDelegateView.delegateConnection = keyboardInputConnection
}
@suzp1984
suzp1984 / CustomKeyboardView.kt
Last active December 14, 2019 00:04
custom keyboard simulator View that performs like a keyboard.
class CustomKeyboardView @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
defStyleRes: Int = 0) :
ViewGroup(context, attrs, defStyle, defStyleRes) {
var inputConnection: InputConnection? = null
private val childViews: Array<View>
@suzp1984
suzp1984 / InputDelegateView.kt
Created December 12, 2019 23:04
custom input delegate view
class InputDelegateView @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
defStyleRes: Int = 0):
View(context, attrs, defStyle, defStyleRes) {
var delegateConnection: InputConnection? = null
init {
isFocusable = true
@suzp1984
suzp1984 / NSScreen+DeviceName.swift
Last active July 16, 2024 03:06
get display name from NSScreen
extension CGDirectDisplayID {
func getIOService() -> io_service_t {
var serialPortIterator = io_iterator_t()
var ioServ: io_service_t = 0
let matching = IOServiceMatching("IODisplayConnect")
let kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &serialPortIterator)
if KERN_SUCCESS == kernResult && serialPortIterator != 0 {
ioServ = IOIteratorNext(serialPortIterator)
@suzp1984
suzp1984 / listenAudioInputVolume.swift
Created November 24, 2019 23:38
os x: How to listen default audio input device volume.
private lazy var audioInputVolumeListener: AudioObjectPropertyListenerBlock = {
return { _, _ in
// report self.getDefaultAudioInputVolume()
}
}()
private func listenDefaultAudioInputVolume() {
var audioVolumeAddr = AudioObjectPropertyAddress(
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume,
mScope: kAudioObjectPropertyScopeInput,