forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_ref_testing.go
More file actions
64 lines (57 loc) · 1.79 KB
/
Copy pathbuffer_ref_testing.go
File metadata and controls
64 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package astiav
//#include <libavutil/buffer.h>
//#include <stdlib.h>
import "C"
import (
"unsafe"
)
// allocBufferRefForTest allocates a refcounted AVBuffer of size bytes
// from the C heap and returns a *C.AVBufferRef wrapped in an opaque
// handle. Tests use it to exercise setBufferRef without depending on a
// real hardware device.
type bufferRefHandle struct {
c *C.AVBufferRef
}
func allocBufferRefForTest(size int) *bufferRefHandle {
ref := C.av_buffer_alloc(C.size_t(size))
if ref == nil {
return nil
}
return &bufferRefHandle{c: ref}
}
// refcountForTest returns the number of references currently held on
// the underlying AVBuffer (i.e. av_buffer_get_ref_count).
func (h *bufferRefHandle) refcountForTest() int {
if h == nil || h.c == nil {
return 0
}
return int(C.av_buffer_get_ref_count(h.c))
}
// dataPtrForTest returns the address of the buffer's data, useful for
// verifying that two refs point at the same underlying allocation.
func (h *bufferRefHandle) dataPtrForTest() unsafe.Pointer {
if h == nil || h.c == nil {
return nil
}
return unsafe.Pointer(h.c.data)
}
// setBufferRefForTest exposes setBufferRef to *_test.go files via a
// pointer-to-pointer the test can manipulate. It mirrors the in-tree
// usage at struct field call sites (e.g. &cc.c.hw_frames_ctx).
func setBufferRefForTest(dst *bufferRefHandle, src *bufferRefHandle) {
var srcRaw *C.AVBufferRef
if src != nil {
srcRaw = src.c
}
setBufferRef(&dst.c, srcRaw)
}
// freeBufferRefForTest unrefs the underlying AVBuffer if still held;
// safe to call multiple times. Tests must call this on every handle
// they create (after the test asserts succeed) to keep refcount
// accounting clean across tests.
func freeBufferRefForTest(h *bufferRefHandle) {
if h == nil || h.c == nil {
return
}
C.av_buffer_unref(&h.c)
}