summaryrefslogtreecommitdiff
path: root/ext/opus
diff options
context:
space:
mode:
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2011-11-20 13:07:27 +0000
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2011-11-21 11:51:21 +0000
commit6c2c0aef53204baf58d709daec9a422c942befa4 (patch)
treeba5b25384e6cf2ddbfc936027c16a8b3e2ea8542 /ext/opus
parentc0695ba7f25915aae3be35f45a617b41e28dc85f (diff)
downloadgstreamer-plugins-bad-6c2c0aef53204baf58d709daec9a422c942befa4.tar.gz
opusparse: parse raw opus packets
Diffstat (limited to 'ext/opus')
-rw-r--r--ext/opus/gstopusparse.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/ext/opus/gstopusparse.c b/ext/opus/gstopusparse.c
index f62ff6696..b6d7bdea6 100644
--- a/ext/opus/gstopusparse.c
+++ b/ext/opus/gstopusparse.c
@@ -137,36 +137,60 @@ gst_opus_parse_check_valid_frame (GstBaseParse * base,
guint32 packet_size;
int ret = FALSE;
int channels, bandwidth;
+ const unsigned char *frames[48];
+ unsigned char toc;
+ short frame_sizes[48];
+ int payload_offset;
+ int nframes;
+ int packet_offset = 0;
parse = GST_OPUS_PARSE (base);
data = GST_BUFFER_DATA (frame->buffer);
size = GST_BUFFER_SIZE (frame->buffer);
GST_DEBUG_OBJECT (parse, "Checking for frame, %u bytes in buffer", size);
- if (size < 4) {
- GST_DEBUG_OBJECT (parse, "Too small");
- goto beach;
- }
- packet_size = GST_READ_UINT32_BE (data);
- GST_DEBUG_OBJECT (parse, "Packet size: %u bytes", packet_size);
- if (packet_size > MAX_PAYLOAD_BYTES) {
- GST_DEBUG_OBJECT (parse, "Too large");
- goto beach;
- }
- if (packet_size > size - 4) {
- GST_DEBUG_OBJECT (parse, "Truncated");
- goto beach;
+
+ /* First, check if there's an Opus packet there */
+ nframes =
+ opus_packet_parse (data, size, &toc, frames, frame_sizes,
+ &payload_offset);
+ if (nframes < 0) {
+ /* Then, check for the test vector framing */
+ GST_DEBUG_OBJECT (parse,
+ "No Opus packet found, trying test vector framing");
+ if (size < 4) {
+ GST_DEBUG_OBJECT (parse, "Too small");
+ goto beach;
+ }
+ packet_size = GST_READ_UINT32_BE (data);
+ GST_DEBUG_OBJECT (parse, "Packet size: %u bytes", packet_size);
+ if (packet_size > MAX_PAYLOAD_BYTES) {
+ GST_DEBUG_OBJECT (parse, "Too large");
+ goto beach;
+ }
+ if (packet_size > size - 4) {
+ GST_DEBUG_OBJECT (parse, "Truncated");
+ goto beach;
+ }
+ nframes =
+ opus_packet_parse (data + 8, packet_size, &toc, frames, frame_sizes,
+ &payload_offset);
+ if (nframes < 0) {
+ GST_DEBUG_OBJECT (parse, "No test vector framing either");
+ goto beach;
+ }
+
+ packet_offset = 8;
+ data += packet_offset;
}
- channels = opus_packet_get_nb_channels (data + 8);
- bandwidth = opus_packet_get_bandwidth (data + 8);
+ channels = opus_packet_get_nb_channels (data);
+ bandwidth = opus_packet_get_bandwidth (data);
if (channels < 0 || bandwidth < 0) {
GST_DEBUG_OBJECT (parse, "It looked like a packet, but it is not");
goto beach;
}
- GST_DEBUG_OBJECT (parse, "Got Opus packet, %d bytes");
-
if (!parse->header_sent) {
GstCaps *caps;
@@ -180,8 +204,11 @@ gst_opus_parse_check_valid_frame (GstBaseParse * base,
parse->header_sent = TRUE;
}
- *skip = 8;
- *frame_size = packet_size;
+ *skip = packet_offset;
+ *frame_size = payload_offset;
+
+ GST_DEBUG_OBJECT (parse, "Got Opus packet at offset %d, %d bytes", *skip,
+ *frame_size);
ret = TRUE;
beach: