You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update llms.txt and README.md to use idiomatic APIs
Remove all capi/ fallback patterns now that hwbuf.Allocate, buf.Lock,
buf.Describe, hwbuf.RecvHandleFromUnixSocket, codec.DequeueInputBuffer,
codec.DequeueOutputBuffer, and media.BufferInfo are in the idiomatic
layer. Update the "Idiomatic vs capi" sections, buffer processing loop,
allocate-lock-unlock lifecycle, and IPC sharing examples.
Copy file name to clipboardExpand all lines: README.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,18 +76,22 @@ All three libraries talk to the same Android system services, but through differ
76
76
77
77
Always import the **idiomatic top-level packages** (`github.com/AndroidGoLab/ndk/{module}`) in your application code. These provide Go-friendly types with proper lifecycle management (`Close()`, `defer`), typed error handling, and method receivers.
78
78
79
-
The `capi/` packages (`github.com/AndroidGoLab/ndk/capi/{module}`) are the raw CGo bindings generated in Stage 2 of the pipeline. They mirror the C API directly — C-style function names, `unsafe.Pointer` parameters, raw integer return codes. **They are intended for power users** who need access to NDK functions not yet wrapped by the idiomatic layer. A few functions (e.g., `AHardwareBuffer_allocate`, `AHardwareBuffer_lock`, `AMediaCodec_dequeueInputBuffer`) are not yet exposed idiomatically and require a `capi/` import as a temporary fallback.
80
-
81
-
When using `capi/` functions, wrap the resulting C pointers in idiomatic types as soon as possible:
79
+
The `capi/` packages (`github.com/AndroidGoLab/ndk/capi/{module}`) are the raw CGo bindings generated in Stage 2 of the pipeline. They mirror the C API directly — C-style function names, `unsafe.Pointer` parameters, raw integer return codes. **They are intended for power users** who need access to NDK functions not yet wrapped by the idiomatic layer. All commonly used functions — including `hwbuf.Allocate`, `buf.Lock`, `codec.DequeueInputBuffer`, and `codec.DequeueOutputBuffer` — are available in the idiomatic layer.
Copy file name to clipboardExpand all lines: llms.txt
+43-54Lines changed: 43 additions & 54 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
## Idiomatic vs capi Packages
6
6
7
-
Always import the idiomatic top-level packages (`github.com/AndroidGoLab/ndk/{module}`) — not the `capi/` packages. The `capi/` layer is a raw CGo binding with C-style names and unsafe types; it is intended only for power users who need NDK functions not yet wrapped by the idiomatic layer. A few functions (e.g., `AMediaCodec_dequeueInputBuffer`, `AHardwareBuffer_allocate`, `AHardwareBuffer_lock`) are not yet exposed idiomatically and require a `capi/` import as a temporary fallback. These cases are marked "**Advanced (capi)**" below.
7
+
Always import the idiomatic top-level packages (`github.com/AndroidGoLab/ndk/{module}`) — not the `capi/` packages. The `capi/` layer is a raw CGo binding with C-style names and unsafe types; it is intended only for power users who need NDK functions not yet wrapped by the idiomatic layer. All commonly used functions — including `hwbuf.Allocate`, `buf.Lock`, `codec.DequeueInputBuffer`, `codec.DequeueOutputBuffer`, and `hwbuf.RecvHandleFromUnixSocket` — are available in the idiomatic layer.
8
8
9
9
## Resource Lifecycle and Memory Management
10
10
@@ -624,23 +624,17 @@ Format keys are passed as strings to `SetInt32`/`SetString`/`SetFloat`/`SetInt64
624
624
625
625
### Buffer Processing Loop
626
626
627
-
The idiomatic `media` package provides `GetInputBuffer`, `QueueInputBuffer`, `GetOutputBuffer`, `ReleaseOutputBuffer`, and all constants (`media.AMEDIACODEC_INFO_*`, `media.AMEDIACODEC_BUFFER_FLAG_*`). The `DequeueInputBuffer` and `DequeueOutputBuffer` functions are not yet in the idiomatic layer and require a `capi/media` import (see **Advanced** note below).
628
-
629
-
The dequeue functions (`DequeueInputBuffer`, `DequeueOutputBuffer`) are not yet in the idiomatic layer and require a `capi/media` import. All other buffer operations use the idiomatic `media` package.
627
+
The idiomatic `media` package provides all buffer processing functions: `DequeueInputBuffer`, `DequeueOutputBuffer`, `GetInputBuffer`, `QueueInputBuffer`, `GetOutputBuffer`, `ReleaseOutputBuffer`, and all constants (`media.AMEDIACODEC_INFO_*`, `media.AMEDIACODEC_BUFFER_FLAG_*`). The `media.BufferInfo` value struct is used with `DequeueOutputBuffer`.
630
628
631
629
```go
632
630
import (
633
631
"unsafe"
634
632
"github.com/AndroidGoLab/ndk/media"
635
-
capimedia "github.com/AndroidGoLab/ndk/capi/media" // needed for dequeue (not yet idiomatic)
// 6. Release back to codec (idiomatic; render=true to send to surface)
664
+
// 6. Release back to codec (render=true to send to surface)
671
665
codec.ReleaseOutputBuffer(uint64(outIdx), false)
672
666
}
673
667
```
@@ -1117,62 +1111,58 @@ Wraps the NDK `AHardwareBuffer` API for GPU/CPU-shared buffers. Lifecycle: Descr
1117
1111
1118
1112
### Idiomatic Buffer Usage
1119
1113
1120
-
The idiomatic `hwbuf` package provides the `Buffer` type with `Acquire`, `Unlock`, `LockPlanes`, `SendHandleToUnixSocket`, `GetID`, and `Close` methods, plus all format and usage constants.
1114
+
The idiomatic `hwbuf` package provides the full hardware buffer API: `Allocate`, `Lock`, `Describe`, `Acquire`, `Unlock`, `LockPlanes`, `SendHandleToUnixSocket`, `RecvHandleFromUnixSocket`, `IsSupported`, `GetID`, and `Close`, plus all format and usage constants. The `hwbuf.Desc` value struct has exported fields (Width, Height, Layers, Format, Usage, Stride, Rfu0, Rfu1) using raw uint32/uint64 types for layout compatibility.
1121
1115
1122
1116
```go
1123
1117
import "github.com/AndroidGoLab/ndk/hwbuf"
1124
1118
1125
-
// Once you have a Buffer (from another API or via capi allocation below):
1126
-
buf.Acquire() // increment ref count for sharing
1127
-
buf.Unlock(nil) // release CPU mapping (nil = synchronous)
1119
+
// Allocate and lifecycle
1120
+
buf, err := hwbuf.Allocate(&desc) // allocate a new hardware buffer
1121
+
buf.Describe() // get buffer description (*hwbuf.Desc)
1122
+
buf.Lock(usage, fence, rect) // lock for CPU access (returns unsafe.Pointer)
1123
+
buf.Acquire() // increment ref count for sharing
1124
+
buf.Unlock(nil) // release CPU mapping (nil = synchronous)
`AHardwareBuffer_allocate` and `AHardwareBuffer_lock` are not yet in the idiomatic layer and require the `capi/hardwarebuffer` package. Once allocated, wrap with `hwbuf.NewBufferFromPointer` for idiomatic usage.
1135
+
The idiomatic `hwbuf` package provides `hwbuf.Desc` (a value struct with exported fields), `hwbuf.Allocate`, and `buf.Lock` for the full allocate-lock-unlock lifecycle. No `capi/` import is needed.
0 commit comments