libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gstreamer_extractor.c File Reference

extracts metadata from files using GStreamer More...

#include "platform.h"
#include "extractor.h"
#include <glib.h>
#include <glib-object.h>
#include <gst/pbutils/pbutils.h>
#include <gst/tag/tag.h>
#include <gst/app/gstappsrc.h>
#include <pthread.h>
Include dependency graph for gstreamer_extractor.c:

Go to the source code of this file.

Data Structures

struct  KnownTag
 
struct  NamedTag
 
struct  PrivStruct
 

Macros

#define GST_CAT_DEFAULT   gstreamer_extractor
 
#define DATA_TIMEOUT   750 /* 750ms */
 
#define TOC_XML_HEADER   "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 

Enumerations

enum  CurrentStreamType {
  STREAM_TYPE_NONE = 0 , STREAM_TYPE_AUDIO = 1 , STREAM_TYPE_VIDEO = 2 , STREAM_TYPE_SUBTITLE = 3 ,
  STREAM_TYPE_CONTAINER = 4 , STREAM_TYPE_IMAGE = 5
}
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gstreamer_extractor)
 
static gboolean _data_timeout (struct PrivStruct *ps)
 
static void feed_data (GstElement *appsrc, guint size, struct PrivStruct *ps)
 
static gboolean seek_data (GstElement *appsrc, guint64 position, struct PrivStruct *ps)
 
static gboolean send_structure_foreach (GQuark field_id, const GValue *value, gpointer user_data)
 
static gboolean send_audio_info (GstDiscovererAudioInfo *info, struct PrivStruct *ps)
 
static int send_video_info (GstDiscovererVideoInfo *info, struct PrivStruct *ps)
 
static int send_subtitle_info (GstDiscovererSubtitleInfo *info, struct PrivStruct *ps)
 
static void send_tag_foreach (const GstTagList *tags, const gchar *tag, gpointer user_data)
 
static void send_streams (GstDiscovererStreamInfo *info, struct PrivStruct *ps)
 
static void send_stream_info (GstDiscovererStreamInfo *info, struct PrivStruct *ps)
 
static void send_toc_tags_foreach (const GstTagList *tags, const gchar *tag, gpointer user_data)
 
static void send_toc_foreach (gpointer data, gpointer user_data)
 
static void send_info (GstDiscovererInfo *info, struct PrivStruct *ps)
 
static void send_discovered_info (GstDiscovererInfo *info, struct PrivStruct *ps)
 
static void _new_discovered_uri (GstDiscoverer *dc, GstDiscovererInfo *info, GError *err, struct PrivStruct *ps)
 
static void _discoverer_finished (GstDiscoverer *dc, struct PrivStruct *ps)
 
static void _source_setup (GstDiscoverer *dc, GstElement *source, struct PrivStruct *ps)
 
static void log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data)
 
static gboolean _run_async (struct PrivStruct *ps)
 
void EXTRACTOR_gstreamer_extract_method (struct EXTRACTOR_ExtractContext *ec)
 
void gstreamer_init ()
 

Variables

pthread_mutex_t pipe_mutex
 
static struct KnownTag __known_tags []
 
struct NamedTag named_tags []
 
static GQuark * audio_quarks
 
static GQuark * video_quarks
 
static GQuark * subtitle_quarks
 
static GQuark duration_quark
 

Detailed Description

extracts metadata from files using GStreamer

Author
LRN

Definition in file gstreamer_extractor.c.

Macro Definition Documentation

◆ DATA_TIMEOUT

#define DATA_TIMEOUT   750 /* 750ms */

Once discoverer has gone for that long without asking for data or asking to seek, or giving us discovered info, assume it hanged up and kill it. In milliseconds.

Definition at line 43 of file gstreamer_extractor.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gstreamer_extractor

Definition at line 35 of file gstreamer_extractor.c.

◆ TOC_XML_HEADER

#define TOC_XML_HEADER   "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"

XML header for the table-of-contents meta data.

Definition at line 1977 of file gstreamer_extractor.c.

Enumeration Type Documentation

◆ CurrentStreamType

Enumerator
STREAM_TYPE_NONE 
STREAM_TYPE_AUDIO 
STREAM_TYPE_VIDEO 
STREAM_TYPE_SUBTITLE 
STREAM_TYPE_CONTAINER 
STREAM_TYPE_IMAGE 

Definition at line 762 of file gstreamer_extractor.c.

Function Documentation

◆ _data_timeout()

static gboolean _data_timeout ( struct PrivStruct ps)
static

◆ _discoverer_finished()

static void _discoverer_finished ( GstDiscoverer *  dc,
struct PrivStruct ps 
)
static

Definition at line 2107 of file gstreamer_extractor.c.

References PrivStruct::loop, and PrivStruct::timeout_id.

Referenced by EXTRACTOR_gstreamer_extract_method().

◆ _new_discovered_uri()

static void _new_discovered_uri ( GstDiscoverer *  dc,
GstDiscovererInfo *  info,
GError *  err,
struct PrivStruct ps 
)
static

◆ _run_async()

static gboolean _run_async ( struct PrivStruct ps)
static

Task run from the main loop to call 'gst_discoverer_uri_async'.

Parameters
psour execution context
Returns
FALSE (always)

Definition at line 2174 of file gstreamer_extractor.c.

References PrivStruct::dc, log_handler(), and NULL.

Referenced by EXTRACTOR_gstreamer_extract_method().

◆ _source_setup()

static void _source_setup ( GstDiscoverer *  dc,
GstElement *  source,
struct PrivStruct ps 
)
static

This callback is called when discoverer has constructed a source object to read from. Since we provided the appsrc:// uri to discoverer, this will be the appsrc that we must handle. We set up some signals - one to push data into appsrc and one to perform a seek.

Parameters
dc
source
ps

Definition at line 2127 of file gstreamer_extractor.c.

References _data_timeout(), DATA_TIMEOUT, feed_data(), PrivStruct::length, NULL, seek_data(), PrivStruct::source, and PrivStruct::timeout_id.

Referenced by EXTRACTOR_gstreamer_extract_method().

◆ EXTRACTOR_gstreamer_extract_method()

void EXTRACTOR_gstreamer_extract_method ( struct EXTRACTOR_ExtractContext ec)

This will be the main method of your plugin. Describe a bit what it does here.

Parameters
ecextraction context, here you get the API for accessing the file data and for returning meta data

Definition at line 2194 of file gstreamer_extractor.c.

References _discoverer_finished(), _new_discovered_uri(), _run_async(), _source_setup(), EXTRACTOR_ExtractContext::cls, PrivStruct::dc, PrivStruct::ec, EXTRACTOR_ExtractContext::get_size, PrivStruct::length, log_handler(), PrivStruct::loop, NULL, and PrivStruct::timeout_id.

◆ feed_data()

static void feed_data ( GstElement *  appsrc,
guint  size,
struct PrivStruct ps 
)
static

Implementation of GstElement's "need-data" callback. Reads data from the extraction context and passes it to GStreamer.

Parameters
appsrcthe GstElement for which we are implementing "need-data"
sizenumber of bytes requested
psour execution context

Definition at line 919 of file gstreamer_extractor.c.

References _data_timeout(), buffer, EXTRACTOR_ExtractContext::cls, DATA_TIMEOUT, PrivStruct::ec, PrivStruct::length, NULL, PrivStruct::offset, pipe_mutex, EXTRACTOR_ExtractContext::read, PrivStruct::source, and PrivStruct::timeout_id.

Referenced by _source_setup().

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gstreamer_extractor  )

◆ gstreamer_init()

void gstreamer_init ( )

Initialize glib and globals.

Definition at line 2237 of file gstreamer_extractor.c.

References audio_quarks, duration_quark, log_handler(), NULL, pipe_mutex, subtitle_quarks, and video_quarks.

◆ log_handler()

static void log_handler ( const gchar *  log_domain,
GLogLevelFlags  log_level,
const gchar *  message,
gpointer  unused_data 
)
static

◆ seek_data()

static gboolean seek_data ( GstElement *  appsrc,
guint64  position,
struct PrivStruct ps 
)
static

Implementation of GstElement's "seek-data" callback. Seeks to a new position in the extraction context.

Parameters
appsrcthe GstElement for which we are implementing "need-data"
positionnew desired absolute position in the file
psour execution context
Returns
TRUE if seeking succeeded, FALSE if not

Definition at line 1009 of file gstreamer_extractor.c.

References _data_timeout(), EXTRACTOR_ExtractContext::cls, DATA_TIMEOUT, PrivStruct::ec, PrivStruct::offset, pipe_mutex, EXTRACTOR_ExtractContext::seek, and PrivStruct::timeout_id.

Referenced by _source_setup().

◆ send_audio_info()

static gboolean send_audio_info ( GstDiscovererAudioInfo *  info,
struct PrivStruct ps 
)
static

◆ send_discovered_info()

static void send_discovered_info ( GstDiscovererInfo *  info,
struct PrivStruct ps 
)
static

Definition at line 2061 of file gstreamer_extractor.c.

References NULL, pipe_mutex, and send_info().

Referenced by _new_discovered_uri().

◆ send_info()

◆ send_stream_info()

◆ send_streams()

static void send_streams ( GstDiscovererStreamInfo *  info,
struct PrivStruct ps 
)
static

Definition at line 1801 of file gstreamer_extractor.c.

References NULL, send_stream_info(), and PrivStruct::time_to_leave.

Referenced by send_info(), and send_stream_info().

◆ send_structure_foreach()

static gboolean send_structure_foreach ( GQuark  field_id,
const GValue *  value,
gpointer  user_data 
)
static

◆ send_subtitle_info()

static int send_subtitle_info ( GstDiscovererSubtitleInfo *  info,
struct PrivStruct ps 
)
static

FIXME

Parameters
infoFIXME
psprocessing context
Returns
FALSE to continue processing, TRUE to abort

Definition at line 1414 of file gstreamer_extractor.c.

References EXTRACTOR_ExtractContext::cls, PrivStruct::ec, EXTRACTOR_METAFORMAT_UTF8, EXTRACTOR_METATYPE_SUBTITLE_LANGUAGE, NULL, EXTRACTOR_ExtractContext::proc, and PrivStruct::time_to_leave.

Referenced by send_stream_info().

◆ send_tag_foreach()

◆ send_toc_foreach()

static void send_toc_foreach ( gpointer  data,
gpointer  user_data 
)
static

Top-level callback used to construct the XML 'toc'.

Parameters
datathe GstTocEntry we're processing
user_datathe 'struct PrivStruct' with the 'toc' string we are assembling

Definition at line 1899 of file gstreamer_extractor.c.

References NULL, send_toc_tags_foreach(), PrivStruct::toc, PrivStruct::toc_depth, PrivStruct::toc_length, PrivStruct::toc_pos, and PrivStruct::toc_print_phase.

Referenced by send_info().

◆ send_toc_tags_foreach()

static void send_toc_tags_foreach ( const GstTagList *  tags,
const gchar *  tag,
gpointer  user_data 
)
static

Callback used to construct the XML 'toc'.

Parameters
tagsFIXME
tagFIXME
user_datathe 'struct PrivStruct' with the 'toc' string we are assembling

Definition at line 1824 of file gstreamer_extractor.c.

References NULL, PrivStruct::toc, PrivStruct::toc_depth, PrivStruct::toc_length, PrivStruct::toc_pos, and PrivStruct::toc_print_phase.

Referenced by send_toc_foreach().

◆ send_video_info()

static int send_video_info ( GstDiscovererVideoInfo *  info,
struct PrivStruct ps 
)
static

Variable Documentation

◆ __known_tags

struct KnownTag __known_tags[]
static

Struct mapping known tags (that do occur in GST API) to LE tags.

Definition at line 45 of file gstreamer_extractor.c.

Referenced by send_tag_foreach().

◆ audio_quarks

GQuark* audio_quarks
static

Definition at line 882 of file gstreamer_extractor.c.

Referenced by gstreamer_init(), and send_structure_foreach().

◆ duration_quark

GQuark duration_quark
static

Definition at line 897 of file gstreamer_extractor.c.

Referenced by gstreamer_init(), and send_tag_foreach().

◆ named_tags

struct NamedTag named_tags[]
Initial value:
= {
{ "PLAY_COUNTER", EXTRACTOR_METATYPE_PLAY_COUNTER },
{ "LEAD_PERFORMER", EXTRACTOR_METATYPE_PERFORMER },
{ "WRITTEN_BY", EXTRACTOR_METATYPE_WRITER },
{ "PRODUCER", EXTRACTOR_METATYPE_PRODUCER },
{ "PUBLISHER", EXTRACTOR_METATYPE_PUBLISHER },
{ "ORIGINAL/ARTIST", EXTRACTOR_METATYPE_ORIGINAL_ARTIST },
{ "ORIGINAL/TITLE", EXTRACTOR_METATYPE_ORIGINAL_TITLE },
}
#define NULL
Definition: getopt1.c:60
@ EXTRACTOR_METATYPE_MOVIE_DIRECTOR
Definition: extractor.h:299
@ EXTRACTOR_METATYPE_SUMMARY
Definition: extractor.h:187
@ EXTRACTOR_METATYPE_UNKNOWN
Definition: extractor.h:181
@ EXTRACTOR_METATYPE_RATING
Definition: extractor.h:326
@ EXTRACTOR_METATYPE_MOOD
Definition: extractor.h:320
@ EXTRACTOR_METATYPE_FRAME_RATE
Definition: extractor.h:382
@ EXTRACTOR_METATYPE_PLAY_COUNTER
Definition: extractor.h:305
@ EXTRACTOR_METATYPE_WRITER
Definition: extractor.h:296
@ EXTRACTOR_METATYPE_PERFORMER
Definition: extractor.h:283
@ EXTRACTOR_METATYPE_PRODUCER
Definition: extractor.h:329
@ EXTRACTOR_METATYPE_ORIGINAL_ARTIST
Definition: extractor.h:312
@ EXTRACTOR_METATYPE_PUBLISHER
Definition: extractor.h:146
@ EXTRACTOR_METATYPE_ORIGINAL_TITLE
Definition: extractor.h:311
@ EXTRACTOR_METATYPE_SUBJECT
Definition: extractor.h:188

Mapping from GST tag names to LE types for tags that are not in the public GST API.

Definition at line 45 of file gstreamer_extractor.c.

Referenced by send_structure_foreach().

◆ pipe_mutex

pthread_mutex_t pipe_mutex

Definition at line 45 of file gstreamer_extractor.c.

Referenced by feed_data(), gstreamer_init(), seek_data(), and send_discovered_info().

◆ subtitle_quarks

GQuark* subtitle_quarks
static

Definition at line 892 of file gstreamer_extractor.c.

Referenced by gstreamer_init(), and send_structure_foreach().

◆ video_quarks

GQuark* video_quarks
static

Definition at line 887 of file gstreamer_extractor.c.

Referenced by gstreamer_init(), and send_structure_foreach().