opusparse: parse raw opus packets
This commit is contained in:
parent
c0695ba7f2
commit
6c2c0aef53
@ -137,12 +137,27 @@ gst_opus_parse_check_valid_frame (GstBaseParse * base,
|
|||||||
guint32 packet_size;
|
guint32 packet_size;
|
||||||
int ret = FALSE;
|
int ret = FALSE;
|
||||||
int channels, bandwidth;
|
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);
|
parse = GST_OPUS_PARSE (base);
|
||||||
|
|
||||||
data = GST_BUFFER_DATA (frame->buffer);
|
data = GST_BUFFER_DATA (frame->buffer);
|
||||||
size = GST_BUFFER_SIZE (frame->buffer);
|
size = GST_BUFFER_SIZE (frame->buffer);
|
||||||
GST_DEBUG_OBJECT (parse, "Checking for frame, %u bytes in buffer", size);
|
GST_DEBUG_OBJECT (parse, "Checking for frame, %u bytes in buffer", size);
|
||||||
|
|
||||||
|
/* 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) {
|
if (size < 4) {
|
||||||
GST_DEBUG_OBJECT (parse, "Too small");
|
GST_DEBUG_OBJECT (parse, "Too small");
|
||||||
goto beach;
|
goto beach;
|
||||||
@ -157,16 +172,25 @@ gst_opus_parse_check_valid_frame (GstBaseParse * base,
|
|||||||
GST_DEBUG_OBJECT (parse, "Truncated");
|
GST_DEBUG_OBJECT (parse, "Truncated");
|
||||||
goto beach;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
channels = opus_packet_get_nb_channels (data + 8);
|
packet_offset = 8;
|
||||||
bandwidth = opus_packet_get_bandwidth (data + 8);
|
data += packet_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
channels = opus_packet_get_nb_channels (data);
|
||||||
|
bandwidth = opus_packet_get_bandwidth (data);
|
||||||
if (channels < 0 || bandwidth < 0) {
|
if (channels < 0 || bandwidth < 0) {
|
||||||
GST_DEBUG_OBJECT (parse, "It looked like a packet, but it is not");
|
GST_DEBUG_OBJECT (parse, "It looked like a packet, but it is not");
|
||||||
goto beach;
|
goto beach;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (parse, "Got Opus packet, %d bytes");
|
|
||||||
|
|
||||||
if (!parse->header_sent) {
|
if (!parse->header_sent) {
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
@ -180,8 +204,11 @@ gst_opus_parse_check_valid_frame (GstBaseParse * base,
|
|||||||
parse->header_sent = TRUE;
|
parse->header_sent = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*skip = 8;
|
*skip = packet_offset;
|
||||||
*frame_size = packet_size;
|
*frame_size = payload_offset;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (parse, "Got Opus packet at offset %d, %d bytes", *skip,
|
||||||
|
*frame_size);
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
||||||
beach:
|
beach:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user