diff mbox

[FFmpeg-devel,05/11] avcodec: add a Producer Reference Time AVPacketSideData type

Message ID 20191017185916.2957-6-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Oct. 17, 2019, 6:59 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
TODO: Version bump and APIchanges entry.

 libavcodec/avcodec.h  | 23 +++++++++++++++++++++++
 libavcodec/avpacket.c | 22 ++++++++++++++++++++++
 libavcodec/internal.h |  2 ++
 3 files changed, 47 insertions(+)
diff mbox

Patch

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bcb931f0dd..a4d652c491 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1173,6 +1173,24 @@  typedef struct AVCPBProperties {
     uint64_t vbv_delay;
 } AVCPBProperties;
 
+/**
+ * This structure supplies media correlation between timestamps and wall-clock
+ * production time.
+ */
+typedef struct AVProducerReferenceTime {
+    /**
+     * wall-clock time, in microseconds since the Epoch. I.e. av_gettime().
+     */
+    int64_t wallclock;
+    /**
+     * Combination of flags indicating the correlation between a timestamp
+     * and the value in the wallclock field.
+     * The definition follows the Producer Reference Time as defined in
+     * ISO/IEC 14496-12.
+     */
+    int flags;
+} AVProducerReferenceTime;
+
 /**
  * The decoder will keep a reference to the frame and may reuse it later.
  */
@@ -1407,6 +1425,11 @@  enum AVPacketSideDataType {
      */
     AV_PKT_DATA_AFD,
 
+    /**
+     * Producer Reference Time data corresponding to the AVProducerReferenceTime struct.
+     */
+    AV_PKT_DATA_PRFT,
+
     /**
      * The number of side data types.
      * This is not part of the public API/ABI in the sense that it may
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 858f827a0a..305f2ae519 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -741,3 +741,25 @@  int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, i
 
     return 0;
 }
+
+int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp, int flags)
+{
+    AVProducerReferenceTime *prft;
+    uint8_t *side_data;
+    int side_data_size;
+
+    side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &side_data_size);
+    if (!side_data) {
+        side_data_size = sizeof(AVProducerReferenceTime);
+        side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_PRFT, side_data_size);
+    }
+
+    if (!side_data || side_data_size < sizeof(AVProducerReferenceTime))
+        return AVERROR(ENOMEM);
+
+    prft = (AVProducerReferenceTime *)side_data;
+    prft->wallclock = timestamp;
+    prft->flags = flags;
+
+    return 0;
+}
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 9db3d36acb..4b875bfe5c 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -392,6 +392,8 @@  AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
 int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);
 
+int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp, int flags);
+
 /**
  * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info
  *