static gboolean
gst_aac_parse_estimate_duration (GstBaseParse * parse)
{
+ gboolean ret = FALSE;
GstFlowReturn res = GST_FLOW_OK;
gint64 pull_size = 0, file_size = 0, offset = 0, num_frames=0, duration=0;
guint profile = 0, sample_rate_index = 0, sample_rate = 0, channel = 0;
gst_buffer_map(buffer, &map, GST_MAP_READ);
buf = map.data;
buffer_size = map.size;
- if(buffer_size != pull_size)
- {
+ if (buffer_size != pull_size) {
GST_ERROR_OBJECT(aacparse, "We got different buffer_size(%d) with pull_size(%d).",
buffer_size, pull_size);
}
sample_rate_index = (buf[i+2] >> 2) & 0xf;
sample_rate = gst_aac_parse_get_sample_rate_from_index(sample_rate_index);
if (sample_rate == 0) {
- gst_buffer_unmap(buffer, &map);
GST_WARNING_OBJECT (aacparse, "Invalid sample rate index (0)");
- return FALSE;
+ goto EXIT;
}
channel = (buf[i+2] & 0x1) << 2 | (buf[i+3] >> 6);
} else if (frame_size == -1) {
offset++;
lost_sync_count++; // lost sync count limmitation 2K Bytes
- if (lost_sync_count > (1024*2))
- {
- gst_buffer_unmap(buffer, &map);
- return FALSE;
+ if (lost_sync_count > (1024*2)) {
+ GST_WARNING_OBJECT (aacparse, "lost_sync_count is larger than 2048");
+ goto EXIT;
}
} else {
offset += frame_size;
frame_duration_us = (1024 * 1000000ll + (sample_rate - 1)) / sample_rate;
duration = num_frames * frame_duration_us;
+ if (duration == 0) {
+ GST_WARNING_OBJECT (aacparse, "Invalid duration");
+ goto EXIT;
+ }
estimated_bitrate = (gint)((gfloat)(offset * 8) / (gfloat)(duration / 1000));
+
+ if (estimated_bitrate == 0) {
+ GST_WARNING_OBJECT (aacparse, "Invalid estimated_bitrate");
+ goto EXIT;
+ }
estimated_duration = (GstClockTime)((file_size * 8) / (estimated_bitrate * 1000)) * GST_SECOND;
GST_INFO_OBJECT (aacparse, "number of frame = %"G_GINT64_FORMAT, num_frames);
break;
}
}
+ ret = TRUE;
+EXIT:
gst_buffer_unmap(buffer, &map);
- gst_buffer_unref (buffer);
- return TRUE;
+ gst_buffer_unref(buffer);
+ return ret;
}