asf: better bitrate for variable bit rate.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 30 Aug 2013 15:33:30 +0000 (12:33 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Fri, 30 Aug 2013 15:49:03 +0000 (12:49 -0300)
The spec says the following:

 Alternate Data Bitrate:

    Specifies the leak rate RAlt, in bits per second, of a leaky
    bucket that contains the data portion of the stream without
    overflowing, excluding all ASF Data Packet overhead. The size of
    the leaky bucket is specified by the value of the Alternate Buffer
    Size field. This value is relevant in most scenarios where the bit
    rate is not exactly constant, but it is especially useful for
    streams that have highly variable bit rates. This field can
    optionally be set to the same value as the Data Bitrate field.

 Alternate Buffer Size:

    Specifies the size BAlt, in milliseconds, of the leaky bucket used
    in the Alternate Data Bitrate definition. This value is relevant
    in most scenarios where the bit rate is not exactly constant, but
    it is especially useful for streams that have highly variable bit
    rates. This field can optionally be set to the same value as the
    Buffer Size field.

 Alternate Initial Buffer Fullness:

    Specifies the initial fullness, in milliseconds, of the leaky
    bucket used in the Alternate Data Bitrate definition. This is the
    fullness of the buffer at the instant before the first bit in the
    stream is dumped into the bucket. Typically, this value is set to
    0. This value shall not exceed the value of the Alternate Buffer
    Size field.

src/plugins/asf/asf.c

index ba28cd8..c45ae61 100644 (file)
@@ -440,8 +440,14 @@ static int _parse_extended_stream_properties(lms_charset_conv_t *cs_conv,
     struct {
         uint64_t start_time;
         uint64_t end_time;
-        uint32_t bitrate;
-        uint32_t unused[7];
+        uint32_t data_bitrate;
+        uint32_t buffer_size;
+        uint32_t init_buffer_fullness;
+        uint32_t alt_data_bitrate;
+        uint32_t alt_buffer_size;
+        uint32_t alt_init_buffer_fullness;
+        uint32_t max_obj_size;
+        uint32_t flags;
         uint16_t stream_id;
         uint16_t lang_id;
         uint64_t avg_time_per_frame;
@@ -450,6 +456,7 @@ static int _parse_extended_stream_properties(lms_charset_conv_t *cs_conv,
     } __attribute__((packed)) props;
     struct stream *s;
     unsigned int stream_id;
+    uint32_t bitrate;
     uint16_t n;
     int r;
 
@@ -460,7 +467,10 @@ static int _parse_extended_stream_properties(lms_charset_conv_t *cs_conv,
     stream_id = get_le16(&props.stream_id);
     s = _stream_get_or_create(info, stream_id);
 
-    s->priv.bitrate = get_le32(&props.bitrate);
+    bitrate = get_le32(&props.alt_data_bitrate); /* for vbr */
+    if (!bitrate)
+        bitrate = get_le32(&props.data_bitrate);
+    s->priv.bitrate = bitrate;
     s->priv.framerate = (NSEC100_PER_SEC /
                          (double) get_le64(&props.avg_time_per_frame));
     for (n = get_le16(&props.stream_name_count); n; n--) {