summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobi <[email protected]>2025-10-30 12:21:21 +0100
committerTobi <[email protected]>2025-10-30 12:21:21 +0100
commit032de0b0df92162aa579eda986145e3756a29a6c (patch)
tree8cab1efeb7a346e9880246f3d54cd5b0f99bdb8d
parentfc3857eb1abefff3cf19816e231e549bf75b9dc3 (diff)
Video Class: New callback function added which allows to generate frame data on the fly
- If buffer is set to NULL, the callback will request payload data from a user function. This allows to work with dynamic content on platforms which are not able to hold a whole frame in memory. - Callback uses the same "weak" linking as other callbacks for this class.
-rw-r--r--src/class/video/video_device.c18
-rw-r--r--src/class/video/video_device.h10
2 files changed, 25 insertions, 3 deletions
diff --git a/src/class/video/video_device.c b/src/class/video/video_device.c
index 5c00cc358..00f192af6 100644
--- a/src/class/video/video_device.c
+++ b/src/class/video/video_device.c
@@ -214,6 +214,14 @@ TU_ATTR_WEAK int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
return VIDEO_ERROR_NONE;
}
+TU_ATTR_WEAK void tud_video_prepare_payload_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void* payload_buf, size_t payload_size, size_t offset) {
+ (void) ctl_idx;
+ (void) stm_idx;
+ (void) payload_buf;
+ (void) payload_size;
+ (void) offset;
+}
+
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
@@ -860,7 +868,11 @@ static uint_fast16_t _prepare_in_payload(videod_streaming_interface_t *stm, uint
}
TU_ASSERT(pkt_len >= hdr_len);
uint_fast16_t data_len = pkt_len - hdr_len;
- memcpy(&ep_buf[hdr_len], stm->buffer + stm->offset, data_len);
+ if (stm->buffer) {
+ memcpy(&ep_buf[hdr_len], stm->buffer + stm->offset, data_len);
+ } else {
+ tud_video_prepare_payload_cb(stm->index_vc, stm->index_vs, &ep_buf[hdr_len], data_len, stm->offset);
+ }
stm->offset += data_len;
remaining -= data_len;
if (!remaining) {
@@ -1235,11 +1247,11 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu
TU_ASSERT(ctl_idx < CFG_TUD_VIDEO);
TU_ASSERT(stm_idx < CFG_TUD_VIDEO_STREAMING);
- if (!buffer || !bufsize) return false;
+ if (!bufsize) return false;
videod_streaming_interface_t *stm = _get_instance_streaming(ctl_idx, stm_idx);
videod_streaming_epbuf_t *stm_epbuf = &_videod_streaming_epbuf[ctl_idx];
- if (!stm || !stm->desc.ep[0] || stm->buffer) return false;
+ if (!stm || !stm->desc.ep[0] || stm->bufsize) return false;
if (stm->state == VS_STATE_PROBING) return false;
/* Find EP address */
diff --git a/src/class/video/video_device.h b/src/class/video/video_device.h
index 2b41c3bfe..b3094dd81 100644
--- a/src/class/video/video_device.h
+++ b/src/class/video/video_device.h
@@ -83,6 +83,16 @@ int tud_video_power_mode_cb(uint_fast8_t ctl_idx, uint8_t power_mod);
int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
video_probe_and_commit_control_t const *parameters);
+/** Invoked if buffer is set to NULL (allows bufferless on the fly data generation)
+ *
+ * @param[in] ctl_idx Destination control interface index
+ * @param[in] stm_idx Destination streaming interface index
+ * @param[out] payload_buf Payload storage buffer (target buffer for requested data)
+ * @param[in] payload_size Size of payload_buf (requested data size)
+ * @param[in] offset Current byte offset relative to given bufsize from tud_video_n_frame_xfer (framesize)
+ * @return video_error_code_t */
+void tud_video_prepare_payload_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void* payload_buf, size_t payload_size, size_t offset);
+
//--------------------------------------------------------------------+
// INTERNAL USBD-CLASS DRIVER API
//--------------------------------------------------------------------+