Browse code

lavc: add a packet side data type for VBV-like parameters

Anton Khirnov authored on 2015/07/22 21:04:20
Showing 3 changed files
... ...
@@ -16,6 +16,7 @@ API changes, most recent first:
16 16
 2015-xx-xx - xxxxxxx - lavc 57.11.0 - avcodec.h
17 17
   xxxxxxx - Add av_packet_add_side_data().
18 18
   xxxxxxx - Add AVCodecContext.coded_side_data.
19
+  xxxxxxx - Add AVCPBProperties API.
19 20
 
20 21
 2015-xx-xx - xxxxxxx - lavc 57.9.1 - avcodec.h
21 22
   Deprecate rtp_callback without replacement, i.e. it won't be possible to
... ...
@@ -1036,6 +1036,44 @@ typedef struct AVPanScan{
1036 1036
     int16_t position[3][2];
1037 1037
 }AVPanScan;
1038 1038
 
1039
+/**
1040
+ * This structure describes the bitrate properties of an encoded bitstream. It
1041
+ * roughly corresponds to a subset the VBV parameters for MPEG-2 or HRD
1042
+ * parameters for H.264/HEVC.
1043
+ */
1044
+typedef struct AVCPBProperties {
1045
+    /**
1046
+     * Maximum bitrate of the stream, in bits per second.
1047
+     * Zero if unknown or unspecified.
1048
+     */
1049
+    int max_bitrate;
1050
+    /**
1051
+     * Minimum bitrate of the stream, in bits per second.
1052
+     * Zero if unknown or unspecified.
1053
+     */
1054
+    int min_bitrate;
1055
+    /**
1056
+     * Average bitrate of the stream, in bits per second.
1057
+     * Zero if unknown or unspecified.
1058
+     */
1059
+    int avg_bitrate;
1060
+
1061
+    /**
1062
+     * The size of the buffer to which the ratecontrol is applied, in bits.
1063
+     * Zero if unknown or unspecified.
1064
+     */
1065
+    int buffer_size;
1066
+
1067
+    /**
1068
+     * The delay between the time the packet this structure is associated with
1069
+     * is received and the time when it should be decoded, in periods of a 27MHz
1070
+     * clock.
1071
+     *
1072
+     * UINT64_MAX when unknown or unspecified.
1073
+     */
1074
+    uint64_t vbv_delay;
1075
+} AVCPBProperties;
1076
+
1039 1077
 #if FF_API_QSCALE_TYPE
1040 1078
 #define FF_QSCALE_TYPE_MPEG1 0
1041 1079
 #define FF_QSCALE_TYPE_MPEG2 1
... ...
@@ -1137,6 +1175,11 @@ enum AVPacketSideDataType {
1137 1137
      * e.g. no decoder available for codec.
1138 1138
      */
1139 1139
     AV_PKT_DATA_FALLBACK_TRACK,
1140
+
1141
+    /**
1142
+     * This side data corresponds to the AVCPBProperties struct.
1143
+     */
1144
+    AV_PKT_DATA_CPB_PROPERTIES,
1140 1145
 };
1141 1146
 
1142 1147
 typedef struct AVPacketSideData {
... ...
@@ -4631,6 +4674,17 @@ const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev);
4631 4631
 const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
4632 4632
 
4633 4633
 /**
4634
+ * Allocate a CPB properties structure and initialize its fields to default
4635
+ * values.
4636
+ *
4637
+ * @param size if non-NULL, the size of the allocated struct will be written
4638
+ *             here. This is useful for embedding it in side data.
4639
+ *
4640
+ * @return the newly allocated struct or NULL on failure
4641
+ */
4642
+AVCPBProperties *av_cpb_properties_alloc(size_t *size);
4643
+
4644
+/**
4634 4645
  * @}
4635 4646
  */
4636 4647
 
... ...
@@ -2369,3 +2369,17 @@ const uint8_t *avpriv_find_start_code(const uint8_t *restrict p,
2369 2369
 
2370 2370
     return p + 4;
2371 2371
 }
2372
+
2373
+AVCPBProperties *av_cpb_properties_alloc(size_t *size)
2374
+{
2375
+    AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
2376
+    if (!props)
2377
+        return NULL;
2378
+
2379
+    if (size)
2380
+        *size = sizeof(*props);
2381
+
2382
+    props->vbv_delay = UINT64_MAX;
2383
+
2384
+    return props;
2385
+}