wavparse: remove ifdef'ed code

We do have adtl and cue parse as part of toc handling alreday. The fmt code is a left over from <0.10 times.
This commit is contained in:
Stefan Sauer 2014-01-06 13:36:38 +01:00
parent 9dde5e29da
commit 73fe1d1f6f

View file

@ -281,432 +281,6 @@ gst_wavparse_init (GstWavParse * wavparse)
gst_element_add_pad (GST_ELEMENT_CAST (wavparse), wavparse->srcpad);
}
/* FIXME: why is that not in use? */
#if 0
static void
gst_wavparse_parse_adtl (GstWavParse * wavparse, int len)
{
guint32 got_bytes;
GstByteStream *bs = wavparse->bs;
gst_riff_chunk *temp_chunk, chunk;
guint8 *tempdata;
struct _gst_riff_labl labl, *temp_labl;
struct _gst_riff_ltxt ltxt, *temp_ltxt;
struct _gst_riff_note note, *temp_note;
char *label_name;
GstProps *props;
GstPropsEntry *entry;
GstCaps *new_caps;
GList *caps = NULL;
props = wavparse->metadata->properties;
while (len > 0) {
got_bytes =
gst_bytestream_peek_bytes (bs, &tempdata, sizeof (gst_riff_chunk));
if (got_bytes != sizeof (gst_riff_chunk)) {
return;
}
temp_chunk = (gst_riff_chunk *) tempdata;
chunk.id = GUINT32_FROM_LE (temp_chunk->id);
chunk.size = GUINT32_FROM_LE (temp_chunk->size);
if (chunk.size == 0) {
gst_bytestream_flush (bs, sizeof (gst_riff_chunk));
len -= sizeof (gst_riff_chunk);
continue;
}
switch (chunk.id) {
case GST_RIFF_adtl_labl:
got_bytes =
gst_bytestream_peek_bytes (bs, &tempdata,
sizeof (struct _gst_riff_labl));
if (got_bytes != sizeof (struct _gst_riff_labl)) {
return;
}
temp_labl = (struct _gst_riff_labl *) tempdata;
labl.id = GUINT32_FROM_LE (temp_labl->id);
labl.size = GUINT32_FROM_LE (temp_labl->size);
labl.identifier = GUINT32_FROM_LE (temp_labl->identifier);
gst_bytestream_flush (bs, sizeof (struct _gst_riff_labl));
len -= sizeof (struct _gst_riff_labl);
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, labl.size - 4);
if (got_bytes != labl.size - 4) {
return;
}
label_name = (char *) tempdata;
gst_bytestream_flush (bs, ((labl.size - 4) + 1) & ~1);
len -= (((labl.size - 4) + 1) & ~1);
new_caps = gst_caps_new ("label",
"application/x-gst-metadata",
gst_props_new ("identifier", G_TYPE_INT (labl.identifier),
"name", G_TYPE_STRING (label_name), NULL));
if (gst_props_get (props, "labels", &caps, NULL)) {
caps = g_list_append (caps, new_caps);
} else {
caps = g_list_append (NULL, new_caps);
entry = gst_props_entry_new ("labels", GST_PROPS_GLIST (caps));
gst_props_add_entry (props, entry);
}
break;
case GST_RIFF_adtl_ltxt:
got_bytes =
gst_bytestream_peek_bytes (bs, &tempdata,
sizeof (struct _gst_riff_ltxt));
if (got_bytes != sizeof (struct _gst_riff_ltxt)) {
return;
}
temp_ltxt = (struct _gst_riff_ltxt *) tempdata;
ltxt.id = GUINT32_FROM_LE (temp_ltxt->id);
ltxt.size = GUINT32_FROM_LE (temp_ltxt->size);
ltxt.identifier = GUINT32_FROM_LE (temp_ltxt->identifier);
ltxt.length = GUINT32_FROM_LE (temp_ltxt->length);
ltxt.purpose = GUINT32_FROM_LE (temp_ltxt->purpose);
ltxt.country = GUINT16_FROM_LE (temp_ltxt->country);
ltxt.language = GUINT16_FROM_LE (temp_ltxt->language);
ltxt.dialect = GUINT16_FROM_LE (temp_ltxt->dialect);
ltxt.codepage = GUINT16_FROM_LE (temp_ltxt->codepage);
gst_bytestream_flush (bs, sizeof (struct _gst_riff_ltxt));
len -= sizeof (struct _gst_riff_ltxt);
if (ltxt.size - 20 > 0) {
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, ltxt.size - 20);
if (got_bytes != ltxt.size - 20) {
return;
}
gst_bytestream_flush (bs, ((ltxt.size - 20) + 1) & ~1);
len -= (((ltxt.size - 20) + 1) & ~1);
label_name = (char *) tempdata;
} else {
label_name = "";
}
new_caps = gst_caps_new ("ltxt",
"application/x-gst-metadata",
gst_props_new ("identifier", G_TYPE_INT (ltxt.identifier),
"name", G_TYPE_STRING (label_name),
"length", G_TYPE_INT (ltxt.length), NULL));
if (gst_props_get (props, "ltxts", &caps, NULL)) {
caps = g_list_append (caps, new_caps);
} else {
caps = g_list_append (NULL, new_caps);
entry = gst_props_entry_new ("ltxts", GST_PROPS_GLIST (caps));
gst_props_add_entry (props, entry);
}
break;
case GST_RIFF_adtl_note:
got_bytes =
gst_bytestream_peek_bytes (bs, &tempdata,
sizeof (struct _gst_riff_note));
if (got_bytes != sizeof (struct _gst_riff_note)) {
return;
}
temp_note = (struct _gst_riff_note *) tempdata;
note.id = GUINT32_FROM_LE (temp_note->id);
note.size = GUINT32_FROM_LE (temp_note->size);
note.identifier = GUINT32_FROM_LE (temp_note->identifier);
gst_bytestream_flush (bs, sizeof (struct _gst_riff_note));
len -= sizeof (struct _gst_riff_note);
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, note.size - 4);
if (got_bytes != note.size - 4) {
return;
}
gst_bytestream_flush (bs, ((note.size - 4) + 1) & ~1);
len -= (((note.size - 4) + 1) & ~1);
label_name = (char *) tempdata;
new_caps = gst_caps_new ("note",
"application/x-gst-metadata",
gst_props_new ("identifier", G_TYPE_INT (note.identifier),
"name", G_TYPE_STRING (label_name), NULL));
if (gst_props_get (props, "notes", &caps, NULL)) {
caps = g_list_append (caps, new_caps);
} else {
caps = g_list_append (NULL, new_caps);
entry = gst_props_entry_new ("notes", GST_PROPS_GLIST (caps));
gst_props_add_entry (props, entry);
}
break;
default:
g_print ("Unknown chunk: %" GST_FOURCC_FORMAT "\n",
GST_FOURCC_ARGS (chunk.id));
return;
}
}
g_object_notify (G_OBJECT (wavparse), "metadata");
}
static void
gst_wavparse_parse_cues (GstWavParse * wavparse, int len)
{
guint32 got_bytes;
GstByteStream *bs = wavparse->bs;
struct _gst_riff_cue *temp_cue, cue;
struct _gst_riff_cuepoints *points;
guint8 *tempdata;
int i;
GList *cues = NULL;
GstPropsEntry *entry;
while (len > 0) {
int required;
got_bytes =
gst_bytestream_peek_bytes (bs, &tempdata,
sizeof (struct _gst_riff_cue));
temp_cue = (struct _gst_riff_cue *) tempdata;
/* fixup for our big endian friends */
cue.id = GUINT32_FROM_LE (temp_cue->id);
cue.size = GUINT32_FROM_LE (temp_cue->size);
cue.cuepoints = GUINT32_FROM_LE (temp_cue->cuepoints);
gst_bytestream_flush (bs, sizeof (struct _gst_riff_cue));
if (got_bytes != sizeof (struct _gst_riff_cue)) {
return;
}
len -= sizeof (struct _gst_riff_cue);
/* -4 because cue.size contains the cuepoints size
and we've already flushed that out of the system */
required = cue.size - 4;
got_bytes = gst_bytestream_peek_bytes (bs, &tempdata, required);
gst_bytestream_flush (bs, ((required) + 1) & ~1);
if (got_bytes != required) {
return;
}
len -= (((cue.size - 4) + 1) & ~1);
/* now we have an array of struct _gst_riff_cuepoints in tempdata */
points = (struct _gst_riff_cuepoints *) tempdata;
for (i = 0; i < cue.cuepoints; i++) {
GstCaps *caps;
caps = gst_caps_new ("cues",
"application/x-gst-metadata",
gst_props_new ("identifier", G_TYPE_INT (points[i].identifier),
"position", G_TYPE_INT (points[i].offset), NULL));
cues = g_list_append (cues, caps);
}
entry = gst_props_entry_new ("cues", GST_PROPS_GLIST (cues));
gst_props_add_entry (wavparse->metadata->properties, entry);
}
g_object_notify (G_OBJECT (wavparse), "metadata");
}
/* Read 'fmt ' header */
static gboolean
gst_wavparse_fmt (GstWavParse * wav)
{
gst_riff_strf_auds *header = NULL;
GstCaps *caps;
if (!gst_riff_read_strf_auds (wav, &header))
goto no_fmt;
wav->format = header->format;
wav->rate = header->rate;
wav->channels = header->channels;
if (wav->channels == 0)
goto no_channels;
wav->blockalign = header->blockalign;
wav->width = (header->blockalign * 8) / header->channels;
wav->depth = header->size;
wav->bps = header->av_bps;
if (wav->bps <= 0)
goto no_bps;
/* Note: gst_riff_create_audio_caps might need to fix values in
* the header header depending on the format, so call it first */
/* FIXME: Need to handle the channel reorder map */
caps = gst_riff_create_audio_caps (header->format, NULL, header, NULL, NULL);
g_free (header);
if (caps == NULL)
goto no_caps;
gst_wavparse_create_sourcepad (wav);
gst_pad_use_fixed_caps (wav->srcpad);
gst_pad_set_active (wav->srcpad, TRUE);
gst_pad_set_caps (wav->srcpad, caps);
gst_caps_free (caps);
gst_element_add_pad (GST_ELEMENT_CAST (wav), wav->srcpad);
gst_element_no_more_pads (GST_ELEMENT_CAST (wav));
GST_DEBUG ("frequency %u, channels %u", wav->rate, wav->channels);
return TRUE;
/* ERRORS */
no_fmt:
{
GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL),
("No FMT tag found"));
return FALSE;
}
no_channels:
{
GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
("Stream claims to contain zero channels - invalid data"));
g_free (header);
return FALSE;
}
no_bps:
{
GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
("Stream claims to bitrate of <= zero - invalid data"));
g_free (header);
return FALSE;
}
no_caps:
{
GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL), (NULL));
return FALSE;
}
}
static gboolean
gst_wavparse_other (GstWavParse * wav)
{
guint32 tag, length;
if (!gst_riff_peek_head (wav, &tag, &length, NULL)) {
GST_WARNING_OBJECT (wav, "could not peek head");
return FALSE;
}
GST_DEBUG_OBJECT (wav, "got tag (%08x) %4.4s, length %u", tag,
(const gchar *) &tag, length);
switch (tag) {
case GST_RIFF_TAG_LIST:
if (!(tag = gst_riff_peek_list (wav))) {
GST_WARNING_OBJECT (wav, "could not peek list");
return FALSE;
}
switch (tag) {
case GST_RIFF_LIST_INFO:
if (!gst_riff_read_list (wav, &tag) || !gst_riff_read_info (wav)) {
GST_WARNING_OBJECT (wav, "could not read list");
return FALSE;
}
break;
case GST_RIFF_LIST_adtl:
if (!gst_riff_read_skip (wav)) {
GST_WARNING_OBJECT (wav, "could not read skip");
return FALSE;
}
break;
default:
GST_DEBUG_OBJECT (wav, "skipping tag (%08x) %4.4s", tag,
(gchar *) & tag);
if (!gst_riff_read_skip (wav)) {
GST_WARNING_OBJECT (wav, "could not read skip");
return FALSE;
}
break;
}
break;
case GST_RIFF_TAG_data:
if (!gst_bytestream_flush (wav->bs, 8)) {
GST_WARNING_OBJECT (wav, "could not flush 8 bytes");
return FALSE;
}
GST_DEBUG_OBJECT (wav, "switching to data mode");
wav->state = GST_WAVPARSE_DATA;
wav->datastart = gst_bytestream_tell (wav->bs);
if (length == 0) {
guint64 file_length;
/* length is 0, data probably stretches to the end
* of file */
GST_DEBUG_OBJECT (wav, "length is 0 trying to find length");
/* get length of file */
file_length = gst_bytestream_length (wav->bs);
if (file_length == -1) {
GST_DEBUG_OBJECT (wav,
"could not get file length, assuming data to eof");
/* could not get length, assuming till eof */
length = G_MAXUINT32;
}
if (file_length > G_MAXUINT32) {
GST_DEBUG_OBJECT (wav, "file length %" G_GUINT64_FORMAT
", clipping to 32 bits", file_length);
/* could not get length, assuming till eof */
length = G_MAXUINT32;
} else {
GST_DEBUG_OBJECT (wav, "file length %" G_GUINT64_FORMAT
", datalength %u", file_length, length);
/* substract offset of datastart from length */
length = file_length - wav->datastart;
GST_DEBUG_OBJECT (wav, "datalength %u", length);
}
}
wav->datasize = (guint64) length;
GST_DEBUG_OBJECT (wav, "datasize = %ld", length)
break;
case GST_RIFF_TAG_cue:
if (!gst_riff_read_skip (wav)) {
GST_WARNING_OBJECT (wav, "could not read skip");
return FALSE;
}
break;
default:
GST_WARNING_OBJECT (wav, "skipping tag %" GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (tag));
if (!gst_riff_read_skip (wav))
return FALSE;
break;
}
return TRUE;
}
#endif
static gboolean
gst_wavparse_parse_file_header (GstElement * element, GstBuffer * buf)
{