+void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
+{
+ if (!s->write_data_type)
+ return;
+ // If ignoring boundary points, just treat it as unknown
+ if (type == AVIO_DATA_MARKER_BOUNDARY_POINT && s->ignore_boundary_point)
+ type = AVIO_DATA_MARKER_UNKNOWN;
+ // Avoid unnecessary flushes if we are already in non-header/trailer
+ // data and setting the type to unknown
+ if (type == AVIO_DATA_MARKER_UNKNOWN &&
+ (s->current_type != AVIO_DATA_MARKER_HEADER &&
+ s->current_type != AVIO_DATA_MARKER_TRAILER))
+ return;
+
+ switch (type) {
+ case AVIO_DATA_MARKER_HEADER:
+ case AVIO_DATA_MARKER_TRAILER:
+ // For header/trailer, ignore a new marker of the same type;
+ // consecutive header/trailer markers can be merged.
+ if (type == s->current_type)
+ return;
+ break;
+ }
+
+ // If we've reached here, we have a new, noteworthy marker.
+ // Flush the previous data and mark the start of the new data.
+ avio_flush(s);
+ s->current_type = type;
+ s->last_time = time;
+}
+