summaryrefslogtreecommitdiff
path: root/libavformat/avio.h
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2016-05-04 17:18:35 +0300
committerMartin Storsjö <martin@martin.st>2016-05-18 10:36:45 +0300
commitdb7968bff4851c2be79b15b2cb2ae747424d2fca (patch)
tree3aee8ac185c9a44a19270ad1559f2fe7cc3d851b /libavformat/avio.h
parent8e757716c61e0563a63829e30b02d5ba2a422ad6 (diff)
avio: Allow custom IO users to get labels for the output bytestream
This allows callers with avio write callbacks to get the bytestream positions that correspond to keyframes, suitable for live streaming. In the simplest form, a caller could expect that a header is written to the bytestream during the avformat_write_header, and the data output to the avio context during e.g. av_write_frame corresponds exactly to the current packet passed in. When combined with av_interleaved_write_frame, and with muxers that do buffering (most muxers that do some sort of fragmenting or clustering), the mapping from input data to bytestream positions is nontrivial. This allows callers to get directly information about what part of the bytestream is what, without having to resort to assumptions about the muxer behaviour. One keyframe/fragment/block can still be split into multiple (if they are larger than the aviocontext buffer), which would call the callback with e.g. AVIO_DATA_MARKER_SYNC_POINT, followed by AVIO_DATA_MARKER_UNKNOWN for the second time it is called with the following data. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/avio.h')
-rw-r--r--libavformat/avio.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/libavformat/avio.h b/libavformat/avio.h
index d60a5977c6..4bd5cb134a 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -54,6 +54,42 @@ typedef struct AVIOInterruptCB {
} AVIOInterruptCB;
/**
+ * Different data types that can be returned via the AVIO
+ * write_data_type callback.
+ */
+enum AVIODataMarkerType {
+ /**
+ * Header data; this needs to be present for the stream to be decodeable.
+ */
+ AVIO_DATA_MARKER_HEADER,
+ /**
+ * A point in the output bytestream where a decoder can start decoding
+ * (i.e. a keyframe). A demuxer/decoder given the data flagged with
+ * AVIO_DATA_MARKER_HEADER, followed by any AVIO_DATA_MARKER_SYNC_POINT,
+ * should give decodeable results.
+ */
+ AVIO_DATA_MARKER_SYNC_POINT,
+ /**
+ * A point in the output bytestream where a demuxer can start parsing
+ * (for non self synchronizing bytestream formats). That is, any
+ * non-keyframe packet start point.
+ */
+ AVIO_DATA_MARKER_BOUNDARY_POINT,
+ /**
+ * This is any, unlabelled data. It can either be a muxer not marking
+ * any positions at all, it can be an actual boundary/sync point
+ * that the muxer chooses not to mark, or a later part of a packet/fragment
+ * that is cut into multiple write callbacks due to limited IO buffer size.
+ */
+ AVIO_DATA_MARKER_UNKNOWN,
+ /**
+ * Trailer data, which doesn't contain actual content, but only for
+ * finalizing the output file.
+ */
+ AVIO_DATA_MARKER_TRAILER
+};
+
+/**
* Bytestream IO Context.
* New fields can be added to the end with minor version bumps.
* Removal, reordering and changes to existing fields require a major
@@ -115,6 +151,24 @@ typedef struct AVIOContext {
* A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
*/
int seekable;
+
+ /**
+ * A callback that is used instead of write_packet.
+ */
+ int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
+ enum AVIODataMarkerType type, int64_t time);
+ /**
+ * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,
+ * but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly
+ * small chunks of data returned from the callback).
+ */
+ int ignore_boundary_point;
+
+ /**
+ * Internal, not meant to be used from outside of AVIOContext.
+ */
+ enum AVIODataMarkerType current_type;
+ int64_t last_time;
} AVIOContext;
/**
@@ -193,6 +247,18 @@ int avio_put_str16le(AVIOContext *s, const char *str);
int avio_put_str16be(AVIOContext *s, const char *str);
/**
+ * Mark the written bytestream as a specific type.
+ *
+ * Zero-length ranges are omitted from the output.
+ *
+ * @param time the stream time the current bytestream pos corresponds to
+ * (in AV_TIME_BASE units), or AV_NOPTS_VALUE if unknown or not
+ * applicable
+ * @param type the kind of data written starting at the current pos
+ */
+void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type);
+
+/**
* ORing this as the "whence" parameter to a seek function causes it to
* return the filesize without seeking anywhere. Supporting this is optional.
* If it is not supported then the seek function will return <0.