mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
sfdec: add taglist support
Map the metadata strings and a bunch of info-fields to GStreamer tags.
This commit is contained in:
parent
b884eac02c
commit
bf956c487f
1 changed files with 111 additions and 1 deletions
|
@ -21,10 +21,11 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <gst/gst-i18n-plugin.h>
|
||||
#include <gst/audio/audio.h>
|
||||
|
||||
#include "gstsfdec.h"
|
||||
#include <gst/audio/audio.h>
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -355,11 +356,15 @@ static gboolean
|
|||
gst_sf_dec_open_file (GstSFDec * self)
|
||||
{
|
||||
SF_INFO info = { 0, };
|
||||
SF_LOOP_INFO loop_info = { 0, };
|
||||
GstCaps *caps;
|
||||
GstStructure *s;
|
||||
GstSegment seg;
|
||||
GstTagList *tags;
|
||||
gint width;
|
||||
const gchar *format;
|
||||
const gchar *tag;
|
||||
const gchar *codec_name;
|
||||
gchar *stream_id;
|
||||
|
||||
GST_DEBUG_OBJECT (self, "opening the stream");
|
||||
|
@ -413,10 +418,115 @@ gst_sf_dec_open_file (GstSFDec * self)
|
|||
gst_pad_set_caps (self->srcpad, caps);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
/* push initial segment */
|
||||
gst_segment_init (&seg, GST_FORMAT_TIME);
|
||||
seg.stop = gst_util_uint64_scale_int (self->duration, GST_SECOND, self->rate);
|
||||
gst_pad_push_event (self->srcpad, gst_event_new_segment (&seg));
|
||||
|
||||
/* get extra details */
|
||||
if (sf_command (self->file, SFC_GET_LOOP_INFO, &loop_info,
|
||||
sizeof (loop_info))) {
|
||||
GST_DEBUG_OBJECT (self, "have loop info");
|
||||
}
|
||||
|
||||
/* send tags */
|
||||
tags = gst_tag_list_new_empty ();
|
||||
if ((tag = sf_get_string (self->file, SF_STR_TITLE))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_COMMENT))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_COMMENT, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_ARTIST))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_ALBUM))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_GENRE))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_GENRE, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_COPYRIGHT))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_COPYRIGHT, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_LICENSE))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_LICENSE, tag, NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_SOFTWARE))) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_APPLICATION_NAME, tag,
|
||||
NULL);
|
||||
}
|
||||
if ((tag = sf_get_string (self->file, SF_STR_TRACKNUMBER))) {
|
||||
guint track = atoi (tag);
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_NUMBER, track,
|
||||
NULL);
|
||||
}
|
||||
if (loop_info.bpm != 0.0) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_BEATS_PER_MINUTE,
|
||||
(gdouble) loop_info.bpm, NULL);
|
||||
}
|
||||
/* TODO: SF_STR_DATE: GST_TAG_DATE / GST_TAG_DATE_TIME */
|
||||
/* TODO: calculate bitrate: GST_TAG_BITRATE */
|
||||
switch (info.format & SF_FORMAT_SUBMASK) {
|
||||
case SF_FORMAT_PCM_S8:
|
||||
case SF_FORMAT_PCM_16:
|
||||
case SF_FORMAT_PCM_24:
|
||||
case SF_FORMAT_PCM_32:
|
||||
case SF_FORMAT_PCM_U8:
|
||||
codec_name = "Uncompressed PCM audio";
|
||||
break;
|
||||
case SF_FORMAT_FLOAT:
|
||||
case SF_FORMAT_DOUBLE:
|
||||
codec_name = "Uncompressed IEEE float audio";
|
||||
break;
|
||||
case SF_FORMAT_ULAW:
|
||||
codec_name = "µ-law audio";
|
||||
break;
|
||||
case SF_FORMAT_ALAW:
|
||||
codec_name = "A-law audio";
|
||||
break;
|
||||
case SF_FORMAT_IMA_ADPCM:
|
||||
case SF_FORMAT_MS_ADPCM:
|
||||
case SF_FORMAT_VOX_ADPCM:
|
||||
case SF_FORMAT_G721_32:
|
||||
case SF_FORMAT_G723_24:
|
||||
case SF_FORMAT_G723_40:
|
||||
codec_name = "ADPCM audio";
|
||||
break;
|
||||
case SF_FORMAT_GSM610:
|
||||
codec_name = "MS GSM audio";
|
||||
break;
|
||||
case SF_FORMAT_DWVW_12:
|
||||
case SF_FORMAT_DWVW_16:
|
||||
case SF_FORMAT_DWVW_24:
|
||||
case SF_FORMAT_DWVW_N:
|
||||
codec_name = "Delta Width Variable Word encoded audio";
|
||||
break;
|
||||
case SF_FORMAT_DPCM_8:
|
||||
case SF_FORMAT_DPCM_16:
|
||||
codec_name = "differential PCM audio";
|
||||
break;
|
||||
case SF_FORMAT_VORBIS:
|
||||
codec_name = "Vorbis";
|
||||
break;
|
||||
default:
|
||||
codec_name = NULL;
|
||||
GST_WARNING_OBJECT (self, "unmapped codec_type: %d",
|
||||
info.format & SF_FORMAT_SUBMASK);
|
||||
break;
|
||||
}
|
||||
if (codec_name) {
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_AUDIO_CODEC,
|
||||
codec_name, NULL);
|
||||
}
|
||||
|
||||
if (!gst_tag_list_is_empty (tags)) {
|
||||
GST_DEBUG_OBJECT (self, "have tags");
|
||||
gst_pad_push_event (self->srcpad, gst_event_new_tag (tags));
|
||||
} else {
|
||||
gst_tag_list_unref (tags);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
open_failed:
|
||||
|
|
Loading…
Reference in a new issue