Added some commenting above functions

This commit is contained in:
saxon 2018-07-14 15:21:01 +09:30
parent 0898d50f0f
commit a9b5c7a26f
1 changed files with 7 additions and 4 deletions

View File

@ -130,6 +130,7 @@ func (s *session) Write(data []byte) (int, error) {
return len(data), nil return len(data), nil
} }
// rtmpWrite writes data to the current rtmp connection encapsulated by r
func rtmpWrite(r *C.RTMP, data []byte) int { func rtmpWrite(r *C.RTMP, data []byte) int {
buf := sliceToPtr(data) buf := sliceToPtr(data)
// TODO: port RTMPPacket // TODO: port RTMPPacket
@ -224,14 +225,19 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
return size + s2 return size + s2
} }
// indxPtr replicates C array indexing using an unsafe pointer
func indxPtr(ptr unsafe.Pointer, inc int) byte { func indxPtr(ptr unsafe.Pointer, inc int) byte {
return *(*byte)(incPtr(ptr,inc)) return *(*byte)(incPtr(ptr,inc))
} }
// sliceToPtr get's the address of the first data element and returns as unsafe
// pointer
func sliceToPtr(data []byte) unsafe.Pointer { func sliceToPtr(data []byte) unsafe.Pointer {
return unsafe.Pointer(&data[0]) return unsafe.Pointer(&data[0])
} }
// ptrToSlice returns a slice given unsafe pointer and size - no allocation and
// copying is required - same data is used.
func ptrToSlice(data unsafe.Pointer, size int) []byte { func ptrToSlice(data unsafe.Pointer, size int) []byte {
var ret []byte var ret []byte
shDest := (*reflect.SliceHeader)(unsafe.Pointer(&ret)) shDest := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
@ -241,6 +247,7 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte {
return ret return ret
} }
// incPtr attempts to replicate C like pointer arithmatic functionality
func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer { func incPtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
return unsafe.Pointer(uintptr(ptr) + uintptr(inc)) return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
} }
@ -290,7 +297,3 @@ func (e Err) Error() string {
} }
return "rtmp: " + strconv.Itoa(int(e)) return "rtmp: " + strconv.Itoa(int(e))
} }
func byteSliceToCArr(buf []byte) *C.char {
return (*C.char)(unsafe.Pointer(&buf[0]))
}