mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
opus: move header magic testing to gstopusheader
This commit is contained in:
parent
354c7824aa
commit
5be77031ca
3 changed files with 14 additions and 13 deletions
|
@ -41,9 +41,10 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gstopusdec.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gst/tag/tag.h>
|
#include <gst/tag/tag.h>
|
||||||
|
#include "gstopusheader.h"
|
||||||
|
#include "gstopusdec.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (opusdec_debug);
|
GST_DEBUG_CATEGORY_STATIC (opusdec_debug);
|
||||||
#define GST_CAT_DEFAULT opusdec_debug
|
#define GST_CAT_DEFAULT opusdec_debug
|
||||||
|
@ -77,8 +78,6 @@ static GstFlowReturn gst_opus_dec_handle_frame (GstAudioDecoder * dec,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
static gboolean gst_opus_dec_set_format (GstAudioDecoder * bdec,
|
static gboolean gst_opus_dec_set_format (GstAudioDecoder * bdec,
|
||||||
GstCaps * caps);
|
GstCaps * caps);
|
||||||
static gboolean gst_opus_dec_is_header (GstBuffer * buf, const char *magic,
|
|
||||||
guint magic_size);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_opus_dec_base_init (gpointer g_class)
|
gst_opus_dec_base_init (gpointer g_class)
|
||||||
|
@ -163,7 +162,7 @@ gst_opus_dec_stop (GstAudioDecoder * dec)
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_opus_dec_parse_header (GstOpusDec * dec, GstBuffer * buf)
|
gst_opus_dec_parse_header (GstOpusDec * dec, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (gst_opus_dec_is_header (buf, "OpusHead", 8),
|
g_return_val_if_fail (gst_opus_header_is_header (buf, "OpusHead", 8),
|
||||||
GST_FLOW_ERROR);
|
GST_FLOW_ERROR);
|
||||||
g_return_val_if_fail (GST_BUFFER_SIZE (buf) >= 19, GST_FLOW_ERROR);
|
g_return_val_if_fail (GST_BUFFER_SIZE (buf) >= 19, GST_FLOW_ERROR);
|
||||||
|
|
||||||
|
@ -374,13 +373,6 @@ memcmp_buffers (GstBuffer * buf1, GstBuffer * buf2)
|
||||||
return !memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2), size1);
|
return !memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2), size1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_opus_dec_is_header (GstBuffer * buf, const char *magic, guint magic_size)
|
|
||||||
{
|
|
||||||
return (GST_BUFFER_SIZE (buf) >= magic_size
|
|
||||||
&& !memcmp (magic, GST_BUFFER_DATA (buf), magic_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_opus_dec_handle_frame (GstAudioDecoder * adec, GstBuffer * buf)
|
gst_opus_dec_handle_frame (GstAudioDecoder * adec, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
|
@ -416,7 +408,7 @@ gst_opus_dec_handle_frame (GstAudioDecoder * adec, GstBuffer * buf)
|
||||||
* first two packets might be the headers, checking magic. */
|
* first two packets might be the headers, checking magic. */
|
||||||
switch (dec->packetno) {
|
switch (dec->packetno) {
|
||||||
case 0:
|
case 0:
|
||||||
if (gst_opus_dec_is_header (buf, "OpusHead", 8)) {
|
if (gst_opus_header_is_header (buf, "OpusHead", 8)) {
|
||||||
GST_DEBUG_OBJECT (dec, "found streamheader");
|
GST_DEBUG_OBJECT (dec, "found streamheader");
|
||||||
res = gst_opus_dec_parse_header (dec, buf);
|
res = gst_opus_dec_parse_header (dec, buf);
|
||||||
gst_audio_decoder_finish_frame (adec, NULL, 1);
|
gst_audio_decoder_finish_frame (adec, NULL, 1);
|
||||||
|
@ -425,7 +417,7 @@ gst_opus_dec_handle_frame (GstAudioDecoder * adec, GstBuffer * buf)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (gst_opus_dec_is_header (buf, "OpusTags", 8)) {
|
if (gst_opus_header_is_header (buf, "OpusTags", 8)) {
|
||||||
GST_DEBUG_OBJECT (dec, "counted vorbiscomments");
|
GST_DEBUG_OBJECT (dec, "counted vorbiscomments");
|
||||||
res = gst_opus_dec_parse_comments (dec, buf);
|
res = gst_opus_dec_parse_comments (dec, buf);
|
||||||
gst_audio_decoder_finish_frame (adec, NULL, 1);
|
gst_audio_decoder_finish_frame (adec, NULL, 1);
|
||||||
|
|
|
@ -161,3 +161,10 @@ gst_opus_header_create_caps (GstCaps ** caps, GSList ** headers, gint nchannels,
|
||||||
*headers = g_slist_prepend (*headers, buf2);
|
*headers = g_slist_prepend (*headers, buf2);
|
||||||
*headers = g_slist_prepend (*headers, buf1);
|
*headers = g_slist_prepend (*headers, buf1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_opus_header_is_header (GstBuffer * buf, const char *magic, guint magic_size)
|
||||||
|
{
|
||||||
|
return (GST_BUFFER_SIZE (buf) >= magic_size
|
||||||
|
&& !memcmp (magic, GST_BUFFER_DATA (buf), magic_size));
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
extern void gst_opus_header_create_caps (GstCaps **caps, GSList **headers, gint nchannels, gint sample_rate, const GstTagList *tags);
|
extern void gst_opus_header_create_caps (GstCaps **caps, GSList **headers, gint nchannels, gint sample_rate, const GstTagList *tags);
|
||||||
|
extern gboolean gst_opus_header_is_header (GstBuffer * buf, const char *magic, guint magic_size);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue