diff --git a/core/src/ten_runtime/binding/go/interface/ten/audio_frame.go b/core/src/ten_runtime/binding/go/interface/ten/audio_frame.go index 11c8a21dc..616cae8de 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/audio_frame.go +++ b/core/src/ten_runtime/binding/go/interface/ten/audio_frame.go @@ -32,25 +32,35 @@ const ( type AudioFrame interface { Msg + AllocBuf(size int) error + LockBuf() ([]byte, error) + UnlockBuf(buf *[]byte) error + GetBuf() ([]byte, error) + SetTimestamp(timestamp int64) error GetTimestamp() (int64, error) + SetSampleRate(sampleRate int32) error GetSampleRate() (int32, error) + SetChannelLayout(channelLayout uint64) error GetChannelLayout() (uint64, error) + SetSamplesPerChannel(samplesPerChannel int32) error GetSamplesPerChannel() (int32, error) + SetBytesPerSample(bytesPerSample int32) error GetBytesPerSample() (int32, error) + SetNumberOfChannels(numberOfChannels int32) error GetNumberOfChannels() (int32, error) + SetDataFmt(dataFmt AudioFrameDataFmt) error GetDataFmt() (AudioFrameDataFmt, error) + SetLineSize(lineSize int32) error GetLineSize() (int32, error) - AllocBuf(size int) error - LockBuf() ([]byte, error) - UnlockBuf(buf *[]byte) error + IsEOF() (bool, error) SetIsEOF(isEOF bool) error } @@ -333,6 +343,29 @@ func (p *audioFrame) AllocBuf(size int) error { return err } +func (p *audioFrame) GetBuf() ([]byte, error) { + if p.size == 0 { + return nil, newTenError(ErrnoInvalidArgument, "call AllocBuf() first") + } + + buf := make([]byte, p.size) + err := withCGOLimiter(func() error { + apiStatus := C.ten_go_audio_frame_get_buf( + p.getCPtr(), + unsafe.Pointer(&buf[0]), + C.int(p.size), + ) + + return withGoStatus(&apiStatus) + }) + + if err != nil { + return nil, err + } + + return buf, nil +} + func (p *audioFrame) LockBuf() ([]byte, error) { var bufAddr *C.uint8_t var bufSize C.uint64_t diff --git a/core/src/ten_runtime/binding/go/interface/ten/audio_frame.h b/core/src/ten_runtime/binding/go/interface/ten/audio_frame.h index c1e2bf4de..79b0b62d1 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/audio_frame.h +++ b/core/src/ten_runtime/binding/go/interface/ten/audio_frame.h @@ -69,6 +69,9 @@ ten_go_status_t ten_go_audio_frame_is_eof(uintptr_t bridge_addr, bool *is_eof); ten_go_status_t ten_go_audio_frame_alloc_buf(uintptr_t bridge_addr, int size); +ten_go_status_t ten_go_audio_frame_get_buf(uintptr_t bridge_addr, + const void *buf_addr, int buf_size); + ten_go_status_t ten_go_audio_frame_lock_buf(uintptr_t bridge_addr, uint8_t **buf_addr, uint64_t *buf_size); diff --git a/core/src/ten_runtime/binding/go/interface/ten/video_frame.go b/core/src/ten_runtime/binding/go/interface/ten/video_frame.go index 5f57eaed7..dfda97188 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/video_frame.go +++ b/core/src/ten_runtime/binding/go/interface/ten/video_frame.go @@ -41,14 +41,19 @@ type VideoFrame interface { LockBuf() ([]byte, error) UnlockBuf(buf *[]byte) error GetBuf() ([]byte, error) + SetWidth(width int32) error GetWidth() (int32, error) + SetHeight(height int32) error GetHeight() (int32, error) + SetTimestamp(timestamp int64) error GetTimestamp() (int64, error) + IsEOF() (bool, error) SetIsEOF(isEOF bool) error + GetPixelFmt() (PixelFmt, error) SetPixelFmt(pixelFmt PixelFmt) error } diff --git a/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c b/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c index ea28561ff..9e76704b9 100644 --- a/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c +++ b/core/src/ten_runtime/binding/go/native/msg/audio_frame/audio_frame.c @@ -10,12 +10,12 @@ #include "include_internal/ten_runtime/binding/go/internal/common.h" #include "include_internal/ten_runtime/binding/go/msg/msg.h" #include "include_internal/ten_runtime/msg/msg.h" -#include "ten_utils/macro/check.h" #include "ten_runtime/binding/go/interface/ten/msg.h" #include "ten_runtime/common/errno.h" #include "ten_runtime/msg/audio_frame/audio_frame.h" #include "ten_runtime/msg/msg.h" #include "ten_utils/lib/error.h" +#include "ten_utils/macro/check.h" ten_go_status_t ten_go_audio_frame_create(const void *msg_name, int msg_name_len, @@ -402,3 +402,27 @@ ten_go_status_t ten_go_audio_frame_unlock_buf(uintptr_t bridge_addr, return status; } + +ten_go_status_t ten_go_audio_frame_get_buf(uintptr_t bridge_addr, + const void *buf_addr, int buf_size) { + TEN_ASSERT(bridge_addr > 0 && buf_addr && buf_size > 0, "Invalid argument."); + + ten_go_status_t status; + ten_go_status_init_with_errno(&status, TEN_ERRNO_OK); + + ten_go_msg_t *audio_frame_bridge = ten_go_msg_reinterpret(bridge_addr); + TEN_ASSERT( + audio_frame_bridge && ten_go_msg_check_integrity(audio_frame_bridge), + "Invalid argument."); + + ten_shared_ptr_t *c_audio_frame = ten_go_msg_c_msg(audio_frame_bridge); + uint64_t size = ten_audio_frame_peek_data(c_audio_frame)->size; + if (buf_size < size) { + ten_go_status_set(&status, TEN_ERRNO_GENERIC, "buffer is not enough"); + } else { + ten_buf_t *data = ten_audio_frame_peek_data(c_audio_frame); + memcpy((void *)buf_addr, data->data, size); + } + + return status; +}