2009-08-29 17:51:48 +00:00
|
|
|
/* GStreamer Ogg Granulepos Mapping Utility Functions
|
|
|
|
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
|
|
|
* Copyright (C) 2009 David Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-08-29 17:51:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstoggstream.h"
|
|
|
|
#include "dirac_parse.h"
|
2010-03-11 12:32:14 +00:00
|
|
|
#include "vorbis_parse.h"
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
#include <gst/riff/riff-media.h>
|
2011-04-11 14:10:01 +00:00
|
|
|
#include <gst/pbutils/pbutils.h>
|
2009-12-04 04:05:29 +00:00
|
|
|
|
2010-03-11 12:32:14 +00:00
|
|
|
#include <stdlib.h>
|
2009-08-29 17:51:48 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gst_ogg_demux_debug);
|
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gst_ogg_demux_setup_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_ogg_demux_debug
|
|
|
|
|
|
|
|
typedef struct _GstOggMap GstOggMap;
|
|
|
|
|
|
|
|
typedef gboolean (*GstOggMapSetupFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
2014-03-05 19:34:42 +00:00
|
|
|
typedef gboolean (*GstOggMapSetupFromCapsFunc) (GstOggStream * pad,
|
|
|
|
const GstCaps * caps);
|
2009-08-29 17:51:48 +00:00
|
|
|
typedef GstClockTime (*GstOggMapToTimeFunc) (GstOggStream * pad,
|
|
|
|
gint64 granulepos);
|
|
|
|
typedef gint64 (*GstOggMapToGranuleFunc) (GstOggStream * pad,
|
|
|
|
gint64 granulepos);
|
2009-11-25 05:22:03 +00:00
|
|
|
typedef gint64 (*GstOggMapToGranuleposFunc) (GstOggStream * pad,
|
|
|
|
gint64 granule, gint64 keyframe_granule);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
/* returns TRUE if the granulepos denotes a key frame */
|
2012-02-01 15:28:45 +00:00
|
|
|
typedef gboolean (*GstOggMapIsGranuleposKeyFrameFunc) (GstOggStream * pad,
|
2009-08-29 17:51:48 +00:00
|
|
|
gint64 granulepos);
|
|
|
|
|
2012-02-01 15:28:45 +00:00
|
|
|
/* returns TRUE if the packet is a key frame */
|
|
|
|
typedef gboolean (*GstOggMapIsPacketKeyFrameFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* returns TRUE if the given packet is a stream header packet */
|
|
|
|
typedef gboolean (*GstOggMapIsHeaderPacketFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
|
|
|
typedef gint64 (*GstOggMapPacketDurationFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
2010-10-27 10:08:25 +00:00
|
|
|
typedef void (*GstOggMapExtractTagsFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-05-14 09:02:38 +00:00
|
|
|
typedef gint64 (*GstOggMapGranuleposToKeyGranuleFunc) (GstOggStream * pad,
|
|
|
|
gint64 granulepos);
|
|
|
|
|
2014-03-05 19:34:42 +00:00
|
|
|
typedef GstBuffer *(*GstOggMapGetHeadersFunc) (GstOggStream * pad);
|
2014-03-06 15:59:08 +00:00
|
|
|
typedef void (*GstOggMapUpdateStatsFunc) (GstOggStream * pad,
|
|
|
|
ogg_packet * packet);
|
2014-03-05 19:34:42 +00:00
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
#define SKELETON_FISBONE_MIN_SIZE 52
|
2010-05-04 11:02:19 +00:00
|
|
|
#define SKELETON_FISHEAD_3_3_MIN_SIZE 112
|
2010-06-08 09:40:32 +00:00
|
|
|
#define SKELETON_FISHEAD_4_0_MIN_SIZE 80
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
struct _GstOggMap
|
|
|
|
{
|
|
|
|
const gchar *id;
|
|
|
|
int id_length;
|
|
|
|
int min_packet_size;
|
|
|
|
const gchar *media_type;
|
|
|
|
GstOggMapSetupFunc setup_func;
|
2014-03-05 19:34:42 +00:00
|
|
|
GstOggMapSetupFromCapsFunc setup_from_caps_func;
|
2009-08-29 17:51:48 +00:00
|
|
|
GstOggMapToGranuleFunc granulepos_to_granule_func;
|
2009-11-25 05:22:03 +00:00
|
|
|
GstOggMapToGranuleposFunc granule_to_granulepos_func;
|
2012-02-01 15:28:45 +00:00
|
|
|
GstOggMapIsGranuleposKeyFrameFunc is_granulepos_key_frame_func;
|
|
|
|
GstOggMapIsPacketKeyFrameFunc is_packet_key_frame_func;
|
2009-08-29 17:51:48 +00:00
|
|
|
GstOggMapIsHeaderPacketFunc is_header_func;
|
|
|
|
GstOggMapPacketDurationFunc packet_duration_func;
|
2010-05-14 09:02:38 +00:00
|
|
|
GstOggMapGranuleposToKeyGranuleFunc granulepos_to_key_granule_func;
|
2010-10-27 10:08:25 +00:00
|
|
|
GstOggMapExtractTagsFunc extract_tags_func;
|
2014-03-05 19:34:42 +00:00
|
|
|
GstOggMapGetHeadersFunc get_headers_func;
|
2014-03-06 15:59:08 +00:00
|
|
|
GstOggMapUpdateStatsFunc update_stats_func;
|
2009-08-29 17:51:48 +00:00
|
|
|
};
|
|
|
|
|
2010-08-08 15:42:04 +00:00
|
|
|
extern const GstOggMap mappers[];
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
GstClockTime
|
|
|
|
gst_ogg_stream_get_packet_start_time (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
int duration;
|
|
|
|
|
|
|
|
if (packet->granulepos == -1) {
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration = gst_ogg_stream_get_packet_duration (pad, packet);
|
|
|
|
if (duration == -1) {
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_ogg_stream_granule_to_time (pad,
|
|
|
|
gst_ogg_stream_granulepos_to_granule (pad,
|
|
|
|
packet->granulepos) - duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstClockTime
|
|
|
|
gst_ogg_stream_get_start_time_for_granulepos (GstOggStream * pad,
|
|
|
|
gint64 granulepos)
|
|
|
|
{
|
|
|
|
if (pad->frame_size == 0)
|
|
|
|
return GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
return gst_ogg_stream_granule_to_time (pad,
|
|
|
|
gst_ogg_stream_granulepos_to_granule (pad, granulepos));
|
|
|
|
}
|
|
|
|
|
|
|
|
GstClockTime
|
|
|
|
gst_ogg_stream_get_end_time_for_granulepos (GstOggStream * pad,
|
|
|
|
gint64 granulepos)
|
|
|
|
{
|
|
|
|
return gst_ogg_stream_granule_to_time (pad,
|
|
|
|
gst_ogg_stream_granulepos_to_granule (pad, granulepos));
|
|
|
|
}
|
|
|
|
|
|
|
|
GstClockTime
|
|
|
|
gst_ogg_stream_granule_to_time (GstOggStream * pad, gint64 granule)
|
|
|
|
{
|
|
|
|
if (granule == 0 || pad->granulerate_n == 0 || pad->granulerate_d == 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-11-21 17:03:21 +00:00
|
|
|
granule += pad->granule_offset;
|
|
|
|
if (granule < 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
return gst_util_uint64_scale (granule, GST_SECOND * pad->granulerate_d,
|
|
|
|
pad->granulerate_n);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint64
|
|
|
|
gst_ogg_stream_granulepos_to_granule (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
if (granulepos == -1 || granulepos == 0) {
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mappers[pad->map].granulepos_to_granule_func == NULL) {
|
2011-08-23 09:29:49 +00:00
|
|
|
GST_WARNING ("Failed to convert %s granulepos to granule",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
2009-11-25 05:22:03 +00:00
|
|
|
return -1;
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mappers[pad->map].granulepos_to_granule_func (pad, granulepos);
|
|
|
|
}
|
|
|
|
|
2009-11-25 06:08:09 +00:00
|
|
|
gint64
|
|
|
|
gst_ogg_stream_granulepos_to_key_granule (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
2010-05-14 09:02:38 +00:00
|
|
|
if (mappers[pad->map].granulepos_to_key_granule_func)
|
|
|
|
return mappers[pad->map].granulepos_to_key_granule_func (pad, granulepos);
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (granulepos == -1 || granulepos == 0 || pad->granuleshift == G_MAXUINT32) {
|
2009-11-25 06:08:09 +00:00
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return granulepos >> pad->granuleshift;
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:22:03 +00:00
|
|
|
gint64
|
|
|
|
gst_ogg_stream_granule_to_granulepos (GstOggStream * pad, gint64 granule,
|
|
|
|
gint64 keyframe_granule)
|
|
|
|
{
|
|
|
|
if (granule == -1 || granule == 0) {
|
|
|
|
return granule;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mappers[pad->map].granule_to_granulepos_func == NULL) {
|
2011-08-23 09:29:49 +00:00
|
|
|
GST_WARNING ("Failed to convert %s granule to granulepos",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
2009-11-25 05:22:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mappers[pad->map].granule_to_granulepos_func (pad, granule,
|
|
|
|
keyframe_granule);
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
gboolean
|
2010-11-21 03:02:50 +00:00
|
|
|
gst_ogg_stream_granulepos_is_key_frame (GstOggStream * pad, gint64 granulepos)
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
|
|
|
if (granulepos == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-01 15:28:45 +00:00
|
|
|
if (mappers[pad->map].is_granulepos_key_frame_func == NULL) {
|
2011-08-23 09:29:49 +00:00
|
|
|
GST_WARNING ("Failed to determine keyframeness for %s granulepos",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-01 15:28:45 +00:00
|
|
|
return mappers[pad->map].is_granulepos_key_frame_func (pad, granulepos);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ogg_stream_packet_is_key_frame (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (mappers[pad->map].is_packet_key_frame_func == NULL) {
|
|
|
|
GST_WARNING ("Failed to determine keyframeness of %s packet",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mappers[pad->map].is_packet_key_frame_func (pad, packet);
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ogg_stream_packet_is_header (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (mappers[pad->map].is_header_func == NULL) {
|
2011-08-23 09:29:49 +00:00
|
|
|
GST_WARNING ("Failed to determine headerness of %s packet",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mappers[pad->map].is_header_func (pad, packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint64
|
|
|
|
gst_ogg_stream_get_packet_duration (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (mappers[pad->map].packet_duration_func == NULL) {
|
2011-08-23 09:29:49 +00:00
|
|
|
GST_WARNING ("Failed to determine %s packet duration",
|
|
|
|
gst_ogg_stream_get_media_type (pad));
|
2009-08-29 17:51:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mappers[pad->map].packet_duration_func (pad, packet);
|
|
|
|
}
|
|
|
|
|
2010-10-27 10:08:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gst_ogg_stream_extract_tags (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (mappers[pad->map].extract_tags_func == NULL) {
|
|
|
|
GST_DEBUG ("No tag extraction");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mappers[pad->map].extract_tags_func (pad, packet);
|
|
|
|
}
|
|
|
|
|
2011-08-17 18:40:08 +00:00
|
|
|
const char *
|
|
|
|
gst_ogg_stream_get_media_type (GstOggStream * pad)
|
|
|
|
{
|
|
|
|
const GstCaps *caps = pad->caps;
|
|
|
|
const GstStructure *structure;
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
if (!structure)
|
|
|
|
return NULL;
|
|
|
|
return gst_structure_get_name (structure);
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:34:42 +00:00
|
|
|
GstBuffer *
|
|
|
|
gst_ogg_stream_get_headers (GstOggStream * pad)
|
|
|
|
{
|
|
|
|
if (!mappers[pad->map].get_headers_func)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return mappers[pad->map].get_headers_func (pad);
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:59:08 +00:00
|
|
|
void
|
|
|
|
gst_ogg_stream_update_stats (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (!mappers[pad->map].get_headers_func)
|
|
|
|
return;
|
|
|
|
|
2016-11-11 18:35:00 +00:00
|
|
|
mappers[pad->map].update_stats_func (pad, packet);
|
2014-03-06 15:59:08 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* some generic functions */
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_packet_keyframe_true (GstOggStream * pad, ogg_packet * packet)
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_default (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
gint64 keyindex, keyoffset;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (pad->granuleshift != 0 && pad->granuleshift != G_MAXUINT32) {
|
2009-08-29 17:51:48 +00:00
|
|
|
keyindex = granulepos >> pad->granuleshift;
|
|
|
|
keyoffset = granulepos - (keyindex << pad->granuleshift);
|
|
|
|
return keyindex + keyoffset;
|
|
|
|
} else {
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 06:08:09 +00:00
|
|
|
|
2009-11-25 05:22:03 +00:00
|
|
|
static gint64
|
|
|
|
granule_to_granulepos_default (GstOggStream * pad, gint64 granule,
|
|
|
|
gint64 keyframe_granule)
|
|
|
|
{
|
|
|
|
gint64 keyoffset;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (pad->granuleshift != 0 && pad->granuleshift != G_MAXUINT32) {
|
2010-12-29 15:27:44 +00:00
|
|
|
/* If we don't know where the previous keyframe is yet, assume it is
|
|
|
|
at 0 or 1, depending on bitstream version. If nothing else, this
|
|
|
|
avoids getting negative granpos back. */
|
|
|
|
if (keyframe_granule < 0)
|
|
|
|
keyframe_granule = pad->theora_has_zero_keyoffset ? 0 : 1;
|
2009-11-25 05:22:03 +00:00
|
|
|
keyoffset = granule - keyframe_granule;
|
|
|
|
return (keyframe_granule << pad->granuleshift) | keyoffset;
|
|
|
|
} else {
|
|
|
|
return granule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
#ifdef unused
|
2009-08-29 17:51:48 +00:00
|
|
|
static gboolean
|
|
|
|
is_header_unknown (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
GST_WARNING ("don't know how to detect header");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-12-04 04:05:29 +00:00
|
|
|
#endif
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_header_true (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_header_count (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (pad->n_header_packets_seen < pad->n_header_packets) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
packet_duration_constant (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return pad->frame_size;
|
|
|
|
}
|
|
|
|
|
2010-10-27 09:58:53 +00:00
|
|
|
/* helper: extracts tags from vorbis comment ogg packet.
|
|
|
|
* Returns result in *tags after free'ing existing *tags (if any) */
|
|
|
|
static gboolean
|
|
|
|
tag_list_from_vorbiscomment_packet (ogg_packet * packet,
|
|
|
|
const guint8 * id_data, const guint id_data_length, GstTagList ** tags)
|
|
|
|
{
|
|
|
|
gchar *encoder = NULL;
|
|
|
|
GstTagList *list;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (tags != NULL, FALSE);
|
|
|
|
|
2011-03-27 16:30:24 +00:00
|
|
|
list = gst_tag_list_from_vorbiscomment (packet->packet, packet->bytes,
|
|
|
|
id_data, id_data_length, &encoder);
|
2010-10-27 09:58:53 +00:00
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
GST_WARNING ("failed to decode vorbis comments");
|
|
|
|
ret = FALSE;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder) {
|
|
|
|
if (encoder[0])
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, GST_TAG_ENCODER, encoder,
|
|
|
|
NULL);
|
|
|
|
g_free (encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
if (*tags)
|
2012-09-14 15:53:21 +00:00
|
|
|
gst_tag_list_unref (*tags);
|
2010-10-27 09:58:53 +00:00
|
|
|
*tags = list;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* theora */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_theora_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-02 02:08:46 +00:00
|
|
|
guint w, h, par_d, par_n;
|
2010-12-28 17:39:58 +00:00
|
|
|
guint8 vmaj, vmin, vrev;
|
|
|
|
|
|
|
|
vmaj = data[7];
|
|
|
|
vmin = data[8];
|
|
|
|
vrev = data[9];
|
2009-12-02 02:08:46 +00:00
|
|
|
|
2010-12-22 23:29:56 +00:00
|
|
|
w = GST_READ_UINT24_BE (data + 14) & 0xFFFFFF;
|
|
|
|
h = GST_READ_UINT24_BE (data + 17) & 0xFFFFFF;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->granulerate_n = GST_READ_UINT32_BE (data + 22);
|
|
|
|
pad->granulerate_d = GST_READ_UINT32_BE (data + 26);
|
2009-12-02 02:08:46 +00:00
|
|
|
|
|
|
|
par_n = GST_READ_UINT24_BE (data + 30);
|
|
|
|
par_d = GST_READ_UINT24_BE (data + 33);
|
|
|
|
|
|
|
|
GST_LOG ("fps = %d/%d, PAR = %u/%u, width = %u, height = %u",
|
|
|
|
pad->granulerate_n, pad->granulerate_d, par_n, par_d, w, h);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
/* 2 bits + 3 bits = 5 bits KFGSHIFT */
|
|
|
|
pad->granuleshift = ((GST_READ_UINT8 (data + 40) & 0x03) << 3) +
|
|
|
|
(GST_READ_UINT8 (data + 41) >> 5);
|
2012-02-01 15:28:45 +00:00
|
|
|
GST_LOG ("granshift: %d", pad->granuleshift);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-11-21 03:02:50 +00:00
|
|
|
pad->is_video = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->n_header_packets = 3;
|
|
|
|
pad->frame_size = 1;
|
|
|
|
|
2010-04-30 15:41:05 +00:00
|
|
|
pad->bitrate = GST_READ_UINT24_BE (data + 37);
|
|
|
|
GST_LOG ("bit rate: %d", pad->bitrate);
|
|
|
|
|
2009-12-04 01:02:11 +00:00
|
|
|
if (pad->granulerate_n == 0 || pad->granulerate_d == 0) {
|
|
|
|
GST_WARNING ("frame rate %d/%d", pad->granulerate_n, pad->granulerate_d);
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
2009-12-04 01:02:11 +00:00
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-12-28 17:39:58 +00:00
|
|
|
/* The interpretation of the granule position has changed with 3.2.1.
|
|
|
|
The granule is now made from the number of frames encoded, rather than
|
2010-12-29 11:51:42 +00:00
|
|
|
the index of the frame being encoded - so there is a difference of 1. */
|
2010-12-28 17:39:58 +00:00
|
|
|
pad->theora_has_zero_keyoffset =
|
|
|
|
((vmaj << 16) | (vmin << 8) | vrev) < 0x030201;
|
|
|
|
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("video/x-theora");
|
2009-12-02 02:08:46 +00:00
|
|
|
|
|
|
|
if (w > 0 && h > 0) {
|
|
|
|
gst_caps_set_simple (pad->caps, "width", G_TYPE_INT, w, "height",
|
|
|
|
G_TYPE_INT, h, NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-15 00:11:17 +00:00
|
|
|
/* PAR of 0:N, N:0 and 0:0 is allowed and maps to 1:1 */
|
|
|
|
if (par_n == 0 || par_d == 0)
|
|
|
|
par_n = par_d = 1;
|
|
|
|
|
2009-12-02 02:08:46 +00:00
|
|
|
/* only add framerate now so caps look prettier, with width/height first */
|
|
|
|
gst_caps_set_simple (pad->caps, "framerate", GST_TYPE_FRACTION,
|
2010-02-15 00:11:17 +00:00
|
|
|
pad->granulerate_n, pad->granulerate_d, "pixel-aspect-ratio",
|
|
|
|
GST_TYPE_FRACTION, par_n, par_d, NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-11-26 01:04:41 +00:00
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_theora (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
gint64 keyindex, keyoffset;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (pad->granuleshift != 0 && pad->granuleshift != G_MAXUINT32) {
|
2009-11-26 01:04:41 +00:00
|
|
|
keyindex = granulepos >> pad->granuleshift;
|
|
|
|
keyoffset = granulepos - (keyindex << pad->granuleshift);
|
|
|
|
if (pad->theora_has_zero_keyoffset) {
|
|
|
|
keyoffset++;
|
|
|
|
}
|
|
|
|
return keyindex + keyoffset;
|
|
|
|
} else {
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
static gboolean
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_theora (GstOggStream * pad, gint64 granulepos)
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
|
|
|
gint64 frame_mask;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (granulepos == (gint64) - 1 || pad->granuleshift == G_MAXUINT32)
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-04-10 15:08:29 +00:00
|
|
|
frame_mask = (G_GUINT64_CONSTANT (1) << pad->granuleshift) - 1;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return ((granulepos & frame_mask) == 0);
|
|
|
|
}
|
|
|
|
|
2012-02-01 15:28:45 +00:00
|
|
|
static gboolean
|
|
|
|
is_packet_keyframe_theora (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes == 0)
|
|
|
|
return FALSE;
|
|
|
|
return (packet->packet[0] & 0xc0) == 0x00;
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
static gboolean
|
|
|
|
is_header_theora (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return (packet->bytes > 0 && (packet->packet[0] & 0x80) == 0x80);
|
|
|
|
}
|
|
|
|
|
2010-10-27 11:49:41 +00:00
|
|
|
static void
|
|
|
|
extract_tags_theora (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes > 0 && packet->packet[0] == 0x81) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "\201theora", 7, &pad->taglist);
|
|
|
|
|
|
|
|
if (!pad->taglist)
|
2011-10-30 11:09:10 +00:00
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
2010-10-27 11:49:41 +00:00
|
|
|
|
2011-04-11 14:10:01 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_VIDEO_CODEC, "Theora", NULL);
|
|
|
|
|
2010-10-27 11:49:41 +00:00
|
|
|
if (pad->bitrate)
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_BITRATE, (guint) pad->bitrate, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* dirac */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_dirac_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
DiracSequenceHeader header;
|
|
|
|
|
2013-04-15 06:38:34 +00:00
|
|
|
ret = gst_dirac_sequence_header_parse (&header, packet->packet + 13,
|
2009-08-29 17:51:48 +00:00
|
|
|
packet->bytes - 13);
|
|
|
|
if (ret == 0) {
|
|
|
|
GST_DEBUG ("Failed to parse Dirac sequence header");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-21 03:02:50 +00:00
|
|
|
pad->is_video = TRUE;
|
2011-08-17 17:48:54 +00:00
|
|
|
pad->always_flush_page = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n = header.frame_rate_numerator * 2;
|
|
|
|
pad->granulerate_d = header.frame_rate_denominator;
|
|
|
|
pad->granuleshift = 22;
|
|
|
|
pad->n_header_packets = 1;
|
|
|
|
pad->frame_size = 2;
|
|
|
|
|
|
|
|
if (header.interlaced_coding != 0) {
|
|
|
|
GST_DEBUG ("non-progressive Dirac coding not implemented");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->caps = gst_caps_new_simple ("video/x-dirac",
|
|
|
|
"width", G_TYPE_INT, header.width,
|
|
|
|
"height", G_TYPE_INT, header.height,
|
2012-06-26 15:09:25 +00:00
|
|
|
"interlace-mode", G_TYPE_STRING,
|
|
|
|
(header.interlaced ? "mixed" : "progressive"), "pixel-aspect-ratio",
|
|
|
|
GST_TYPE_FRACTION, header.aspect_ratio_numerator,
|
|
|
|
header.aspect_ratio_denominator, "framerate", GST_TYPE_FRACTION,
|
|
|
|
header.frame_rate_numerator, header.frame_rate_denominator, NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OGG_DIRAC_GRANULE_LOW_MASK ((1<<22) - 1)
|
|
|
|
static gboolean
|
|
|
|
is_keyframe_dirac (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
int dist_h;
|
|
|
|
int dist_l;
|
|
|
|
int dist;
|
|
|
|
|
|
|
|
if (granulepos == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
dist_h = (granulepos >> 22) & 0xff;
|
|
|
|
dist_l = granulepos & 0xff;
|
|
|
|
dist = (dist_h << 8) | dist_l;
|
|
|
|
|
|
|
|
return (dist == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_dirac (GstOggStream * pad, gint64 gp)
|
|
|
|
{
|
|
|
|
gint64 pt;
|
|
|
|
int delay;
|
|
|
|
gint64 dt;
|
|
|
|
|
|
|
|
pt = ((gp >> 22) + (gp & OGG_DIRAC_GRANULE_LOW_MASK)) >> 9;
|
|
|
|
delay = (gp >> 9) & 0x1fff;
|
|
|
|
dt = pt - delay;
|
|
|
|
|
2009-12-03 21:07:49 +00:00
|
|
|
GST_DEBUG ("pt %" G_GINT64_FORMAT " delay %d", pt, delay);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return dt + 4;
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:22:03 +00:00
|
|
|
static gint64
|
|
|
|
granule_to_granulepos_dirac (GstOggStream * pad, gint64 granule,
|
|
|
|
gint64 keyframe_granule)
|
|
|
|
{
|
|
|
|
/* This conversion requires knowing more details about the Dirac
|
|
|
|
* stream. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:31:42 +00:00
|
|
|
static gint64
|
|
|
|
granulepos_to_key_granule_dirac (GstOggStream * pad, gint64 gp)
|
|
|
|
{
|
|
|
|
gint64 pt;
|
|
|
|
int dist_h;
|
|
|
|
int dist_l;
|
|
|
|
int dist;
|
|
|
|
int delay;
|
|
|
|
gint64 dt;
|
|
|
|
|
|
|
|
if (gp == -1 || gp == 0)
|
|
|
|
return gp;
|
|
|
|
|
|
|
|
pt = ((gp >> 22) + (gp & OGG_DIRAC_GRANULE_LOW_MASK)) >> 9;
|
|
|
|
dist_h = (gp >> 22) & 0xff;
|
|
|
|
dist_l = gp & 0xff;
|
|
|
|
dist = (dist_h << 8) | dist_l;
|
|
|
|
delay = (gp >> 9) & 0x1fff;
|
|
|
|
dt = pt - delay;
|
|
|
|
|
|
|
|
return dt - 2 * dist + 4;
|
|
|
|
}
|
|
|
|
|
2010-05-05 11:59:57 +00:00
|
|
|
/* VP8 */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_vp8_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
gint width, height, par_n, par_d, fps_n, fps_d;
|
|
|
|
|
2010-05-20 06:52:49 +00:00
|
|
|
if (packet->bytes < 26) {
|
2010-05-05 11:59:57 +00:00
|
|
|
GST_DEBUG ("Failed to parse VP8 BOS page");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-20 06:52:49 +00:00
|
|
|
width = GST_READ_UINT16_BE (packet->packet + 8);
|
|
|
|
height = GST_READ_UINT16_BE (packet->packet + 10);
|
|
|
|
par_n = GST_READ_UINT24_BE (packet->packet + 12);
|
|
|
|
par_d = GST_READ_UINT24_BE (packet->packet + 15);
|
|
|
|
fps_n = GST_READ_UINT32_BE (packet->packet + 18);
|
|
|
|
fps_d = GST_READ_UINT32_BE (packet->packet + 22);
|
2010-05-05 11:59:57 +00:00
|
|
|
|
2010-11-21 03:02:50 +00:00
|
|
|
pad->is_video = TRUE;
|
2010-05-05 11:59:57 +00:00
|
|
|
pad->is_vp8 = TRUE;
|
|
|
|
pad->granulerate_n = fps_n;
|
|
|
|
pad->granulerate_d = fps_d;
|
|
|
|
pad->n_header_packets = 2;
|
|
|
|
pad->frame_size = 1;
|
|
|
|
|
|
|
|
pad->caps = gst_caps_new_simple ("video/x-vp8",
|
|
|
|
"width", G_TYPE_INT, width,
|
|
|
|
"height", G_TYPE_INT, height,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION,
|
|
|
|
par_n, par_d, "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:34:42 +00:00
|
|
|
static gboolean
|
|
|
|
vp8_fill_header (GstOggStream * pad, const GstCaps * caps, guint8 * data)
|
|
|
|
{
|
|
|
|
gint width, height, par_n, par_d, fps_n, fps_d;
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (!(gst_structure_get_int (structure, "width", &width) &&
|
|
|
|
gst_structure_get_int (structure, "height", &height) &&
|
|
|
|
gst_structure_get_fraction (structure, "framerate", &fps_n,
|
|
|
|
&fps_d))) {
|
|
|
|
GST_DEBUG ("Failed to get width, height or framerate from caps %"
|
|
|
|
GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_n,
|
|
|
|
&par_d)) {
|
|
|
|
par_n = par_d = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (data, "OVP80\1\1", 8);
|
|
|
|
GST_WRITE_UINT16_BE (data + 8, width);
|
|
|
|
GST_WRITE_UINT16_BE (data + 10, height);
|
|
|
|
GST_WRITE_UINT24_BE (data + 12, par_n);
|
|
|
|
GST_WRITE_UINT24_BE (data + 15, par_d);
|
|
|
|
GST_WRITE_UINT32_BE (data + 18, fps_n);
|
|
|
|
GST_WRITE_UINT32_BE (data + 22, fps_d);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_vp8_mapper_from_caps (GstOggStream * pad, const GstCaps * caps)
|
|
|
|
{
|
|
|
|
guint8 data[26];
|
|
|
|
ogg_packet packet;
|
|
|
|
|
|
|
|
if (!vp8_fill_header (pad, caps, data))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
packet.packet = data;
|
|
|
|
packet.bytes = 26;
|
|
|
|
return setup_vp8_mapper (pad, &packet);
|
|
|
|
}
|
|
|
|
|
2010-05-05 11:59:57 +00:00
|
|
|
static gboolean
|
|
|
|
is_keyframe_vp8 (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
guint64 gpos = granulepos;
|
|
|
|
|
|
|
|
if (granulepos == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Get rid of flags */
|
|
|
|
gpos >>= 3;
|
|
|
|
|
|
|
|
return ((gpos & 0x07ffffff) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_vp8 (GstOggStream * pad, gint64 gpos)
|
|
|
|
{
|
|
|
|
guint64 gp = (guint64) gpos;
|
|
|
|
guint32 pt;
|
|
|
|
guint32 dist;
|
|
|
|
|
|
|
|
pt = (gp >> 32);
|
|
|
|
dist = (gp >> 3) & 0x07ffffff;
|
|
|
|
|
|
|
|
GST_DEBUG ("pt %u, dist %u", pt, dist);
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
granule_to_granulepos_vp8 (GstOggStream * pad, gint64 granule,
|
|
|
|
gint64 keyframe_granule)
|
|
|
|
{
|
2014-03-06 15:59:08 +00:00
|
|
|
guint inv;
|
|
|
|
gint64 granulepos;
|
|
|
|
|
|
|
|
inv = (pad->invisible_count <= 0) ? 0x3 : pad->invisible_count - 1;
|
|
|
|
|
|
|
|
granulepos =
|
|
|
|
(granule << 32) | (inv << 30) | ((granule - keyframe_granule) << 3);
|
|
|
|
return granulepos;
|
2010-05-05 11:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this packet contains an invisible frame or not */
|
|
|
|
static gint64
|
|
|
|
packet_duration_vp8 (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint32 hdr;
|
|
|
|
|
|
|
|
if (packet->bytes < 3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
hdr = GST_READ_UINT24_LE (packet->packet);
|
|
|
|
|
|
|
|
return (((hdr >> 4) & 1) != 0) ? 1 : 0;
|
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-05-14 09:02:38 +00:00
|
|
|
static gint64
|
|
|
|
granulepos_to_key_granule_vp8 (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
guint64 gp = granulepos;
|
|
|
|
guint64 pts = (gp >> 32);
|
|
|
|
guint32 dist = (gp >> 3) & 0x07ffffff;
|
|
|
|
|
|
|
|
if (granulepos == -1 || granulepos == 0)
|
|
|
|
return granulepos;
|
|
|
|
|
|
|
|
if (dist > pts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return pts - dist;
|
|
|
|
}
|
|
|
|
|
2010-05-19 19:35:19 +00:00
|
|
|
static gboolean
|
|
|
|
is_header_vp8 (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
2010-05-20 11:58:14 +00:00
|
|
|
if (packet->bytes >= 5 && packet->packet[0] == 0x4F &&
|
2010-05-19 19:35:19 +00:00
|
|
|
packet->packet[1] == 0x56 && packet->packet[2] == 0x50 &&
|
2010-05-20 06:52:49 +00:00
|
|
|
packet->packet[3] == 0x38 && packet->packet[4] == 0x30)
|
2010-05-19 19:35:19 +00:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-27 10:08:25 +00:00
|
|
|
static void
|
|
|
|
extract_tags_vp8 (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes >= 7 && memcmp (packet->packet, "OVP80\2 ", 7) == 0) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "OVP80\2 ", 7, &pad->taglist);
|
2011-04-11 14:10:01 +00:00
|
|
|
|
2017-10-31 09:34:26 +00:00
|
|
|
if (!pad->taglist)
|
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
|
|
|
|
2011-04-11 14:10:01 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_VIDEO_CODEC, "VP8", NULL);
|
2010-10-27 10:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 19:34:42 +00:00
|
|
|
static GstBuffer *
|
|
|
|
get_headers_vp8 (GstOggStream * pad)
|
|
|
|
{
|
|
|
|
guint8 *data = g_malloc (26);
|
|
|
|
|
|
|
|
if (vp8_fill_header (pad, pad->caps, data)) {
|
|
|
|
return gst_buffer_new_wrapped (data, 26);
|
|
|
|
}
|
|
|
|
g_free (data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:59:08 +00:00
|
|
|
static void
|
|
|
|
update_stats_vp8 (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet_duration_vp8 (pad, packet)) {
|
|
|
|
/* set to -1 as when we get thefirst invisible it should be
|
|
|
|
* set to 0 */
|
|
|
|
pad->invisible_count = -1;
|
|
|
|
} else {
|
|
|
|
pad->invisible_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* vorbis */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_vorbis_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-03 23:43:08 +00:00
|
|
|
guint chans;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-09-14 20:08:51 +00:00
|
|
|
data += 1 + 6;
|
|
|
|
pad->version = GST_READ_UINT32_LE (data);
|
|
|
|
data += 4;
|
2009-12-03 23:43:08 +00:00
|
|
|
chans = GST_READ_UINT8 (data);
|
|
|
|
data += 1;
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data);
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
2011-08-18 08:30:46 +00:00
|
|
|
pad->preroll = 2;
|
2009-11-25 05:22:03 +00:00
|
|
|
pad->last_size = 0;
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-09-14 20:08:51 +00:00
|
|
|
data += 4;
|
|
|
|
pad->bitrate_upper = GST_READ_UINT32_LE (data);
|
|
|
|
data += 4;
|
|
|
|
pad->bitrate_nominal = GST_READ_UINT32_LE (data);
|
|
|
|
data += 4;
|
|
|
|
pad->bitrate_lower = GST_READ_UINT32_LE (data);
|
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_nominal > 0)
|
2010-09-14 20:08:51 +00:00
|
|
|
pad->bitrate = pad->bitrate_nominal;
|
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_upper > 0 && !pad->bitrate)
|
|
|
|
pad->bitrate = pad->bitrate_upper;
|
2010-09-14 20:08:51 +00:00
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_lower > 0 && !pad->bitrate)
|
|
|
|
pad->bitrate = pad->bitrate_lower;
|
2010-09-14 20:08:51 +00:00
|
|
|
|
2010-04-30 15:41:05 +00:00
|
|
|
GST_LOG ("bit rate: %d", pad->bitrate);
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->n_header_packets = 3;
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-15 06:38:34 +00:00
|
|
|
gst_parse_vorbis_header_packet (pad, packet);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->caps = gst_caps_new_simple ("audio/x-vorbis",
|
2009-12-03 23:43:08 +00:00
|
|
|
"rate", G_TYPE_INT, pad->granulerate_n, "channels", G_TYPE_INT, chans,
|
|
|
|
NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_header_vorbis (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
2012-10-28 10:07:16 +00:00
|
|
|
if (packet->bytes == 0 || (packet->packet[0] & 0x01) == 0)
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-10-27 10:08:25 +00:00
|
|
|
if (packet->packet[0] == 5) {
|
2013-04-15 06:38:34 +00:00
|
|
|
gst_parse_vorbis_setup_packet (pad, packet);
|
2010-10-27 10:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extract_tags_vorbis (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes == 0 || (packet->packet[0] & 0x01) == 0)
|
|
|
|
return;
|
|
|
|
|
2010-09-14 20:08:51 +00:00
|
|
|
if (((guint8 *) (packet->packet))[0] == 0x03) {
|
2010-10-27 09:58:53 +00:00
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "\003vorbis", 7, &pad->taglist);
|
2010-09-14 20:08:51 +00:00
|
|
|
|
2010-10-27 09:58:53 +00:00
|
|
|
if (!pad->taglist)
|
2011-10-30 11:09:10 +00:00
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
2010-09-14 20:08:51 +00:00
|
|
|
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
2011-04-11 14:10:01 +00:00
|
|
|
GST_TAG_ENCODER_VERSION, pad->version,
|
|
|
|
GST_TAG_AUDIO_CODEC, "Vorbis", NULL);
|
2010-09-14 20:08:51 +00:00
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_nominal > 0)
|
2010-09-14 20:08:51 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_NOMINAL_BITRATE, (guint) pad->bitrate_nominal, NULL);
|
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_upper > 0)
|
2010-09-14 20:08:51 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_MAXIMUM_BITRATE, (guint) pad->bitrate_upper, NULL);
|
|
|
|
|
2010-10-27 08:59:03 +00:00
|
|
|
if (pad->bitrate_lower > 0)
|
2010-09-14 20:08:51 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_MINIMUM_BITRATE, (guint) pad->bitrate_lower, NULL);
|
|
|
|
|
|
|
|
if (pad->bitrate)
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_BITRATE, (guint) pad->bitrate, NULL);
|
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
packet_duration_vorbis (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
int size;
|
|
|
|
int duration;
|
|
|
|
|
2011-08-03 08:18:29 +00:00
|
|
|
if (packet->bytes == 0 || packet->packet[0] & 1)
|
2009-11-25 05:22:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
mode = (packet->packet[0] >> 1) & ((1 << pad->vorbis_log2_num_modes) - 1);
|
2009-11-25 05:22:03 +00:00
|
|
|
size = pad->vorbis_mode_sizes[mode] ? pad->long_size : pad->short_size;
|
|
|
|
|
|
|
|
if (pad->last_size == 0) {
|
|
|
|
duration = 0;
|
2009-08-29 17:51:48 +00:00
|
|
|
} else {
|
2009-11-25 05:22:03 +00:00
|
|
|
duration = pad->last_size / 4 + size / 4;
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
2009-11-25 05:22:03 +00:00
|
|
|
pad->last_size = size;
|
|
|
|
|
|
|
|
GST_DEBUG ("duration %d", (int) duration);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* speex */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_speex_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-03 23:43:08 +00:00
|
|
|
guint chans;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
data += 8 + 20 + 4 + 4;
|
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data);
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
2009-12-03 23:43:08 +00:00
|
|
|
|
|
|
|
data += 4 + 4 + 4;
|
|
|
|
chans = GST_READ_UINT32_LE (data);
|
2010-04-30 15:41:05 +00:00
|
|
|
data += 4;
|
|
|
|
pad->bitrate = GST_READ_UINT32_LE (data);
|
2009-12-03 23:43:08 +00:00
|
|
|
|
|
|
|
GST_LOG ("sample rate: %d, channels: %u", pad->granulerate_n, chans);
|
2010-04-30 15:41:05 +00:00
|
|
|
GST_LOG ("bit rate: %d", pad->bitrate);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = GST_READ_UINT32_LE (packet->packet + 68) + 2;
|
|
|
|
pad->frame_size = GST_READ_UINT32_LE (packet->packet + 64) *
|
|
|
|
GST_READ_UINT32_LE (packet->packet + 56);
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-12-03 23:43:08 +00:00
|
|
|
pad->caps = gst_caps_new_simple ("audio/x-speex", "rate", G_TYPE_INT,
|
|
|
|
pad->granulerate_n, "channels", G_TYPE_INT, chans, NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-27 11:49:41 +00:00
|
|
|
static void
|
|
|
|
extract_tags_count (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
/* packet 2 must be comment packet */
|
|
|
|
if (packet->bytes > 0 && pad->n_header_packets_seen == 1) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet, NULL, 0, &pad->taglist);
|
|
|
|
|
|
|
|
if (!pad->taglist)
|
2011-10-30 11:09:10 +00:00
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
2010-10-27 11:49:41 +00:00
|
|
|
|
2011-04-11 14:10:01 +00:00
|
|
|
if (pad->is_video) {
|
|
|
|
gst_pb_utils_add_codec_description_to_tag_list (pad->taglist,
|
|
|
|
GST_TAG_VIDEO_CODEC, pad->caps);
|
|
|
|
} else if (!pad->is_sparse && !pad->is_ogm_text && !pad->is_ogm) {
|
|
|
|
gst_pb_utils_add_codec_description_to_tag_list (pad->taglist,
|
|
|
|
GST_TAG_AUDIO_CODEC, pad->caps);
|
|
|
|
} else {
|
|
|
|
GST_FIXME ("not adding codec tag, not sure about codec type");
|
|
|
|
}
|
|
|
|
|
2010-10-27 11:49:41 +00:00
|
|
|
if (pad->bitrate)
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_BITRATE, (guint) pad->bitrate, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
/* flac */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_fLaC_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
2009-12-11 06:47:53 +00:00
|
|
|
pad->granulerate_n = 0;
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
|
|
|
|
|
|
|
pad->n_header_packets = 3;
|
|
|
|
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("audio/x-flac");
|
2009-12-11 06:47:53 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_header_fLaC (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (pad->n_header_packets_seen == 1) {
|
|
|
|
pad->granulerate_n = (packet->packet[14] << 12) |
|
|
|
|
(packet->packet[15] << 4) | ((packet->packet[16] >> 4) & 0xf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pad->n_header_packets_seen < pad->n_header_packets) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_flac_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-03 23:43:08 +00:00
|
|
|
guint chans;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
/* see http://flac.sourceforge.net/ogg_mapping.html */
|
|
|
|
|
|
|
|
pad->granulerate_n = (GST_READ_UINT32_BE (data + 27) & 0xFFFFF000) >> 12;
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
2009-12-03 23:43:08 +00:00
|
|
|
chans = ((GST_READ_UINT32_BE (data + 27) & 0x00000E00) >> 9) + 1;
|
|
|
|
|
|
|
|
GST_DEBUG ("sample rate: %d, channels: %u", pad->granulerate_n, chans);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = GST_READ_UINT16_BE (packet->packet + 7);
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-12-03 23:43:08 +00:00
|
|
|
pad->caps = gst_caps_new_simple ("audio/x-flac", "rate", G_TYPE_INT,
|
|
|
|
pad->granulerate_n, "channels", G_TYPE_INT, chans, NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-06 12:57:51 +00:00
|
|
|
static gboolean
|
|
|
|
is_header_flac (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return (packet->bytes > 0 && (packet->packet[0] != 0xff));
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
static gint64
|
|
|
|
packet_duration_flac (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
int block_size_index;
|
|
|
|
|
|
|
|
if (packet->bytes < 4)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
block_size_index = packet->packet[2] >> 4;
|
|
|
|
if (block_size_index == 1)
|
|
|
|
return 192;
|
|
|
|
if (block_size_index >= 2 && block_size_index <= 5) {
|
|
|
|
return 576 << (block_size_index - 2);
|
|
|
|
}
|
|
|
|
if (block_size_index >= 8) {
|
2014-04-10 15:08:29 +00:00
|
|
|
return G_GUINT64_CONSTANT (256) << (block_size_index - 8);
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
2010-01-05 13:11:06 +00:00
|
|
|
if (block_size_index == 6 || block_size_index == 7) {
|
|
|
|
guint len, bytes = (block_size_index - 6) + 1;
|
|
|
|
guint8 tmp;
|
|
|
|
|
|
|
|
if (packet->bytes < 4 + 1 + bytes)
|
|
|
|
return -1;
|
|
|
|
tmp = packet->packet[4];
|
|
|
|
/* utf-8 prefix */
|
|
|
|
len = 0;
|
|
|
|
while (tmp & 0x80) {
|
|
|
|
len++;
|
|
|
|
tmp <<= 1;
|
|
|
|
}
|
|
|
|
if (len == 2)
|
|
|
|
return -1;
|
|
|
|
if (len == 0)
|
|
|
|
len++;
|
|
|
|
if (packet->bytes < 4 + len + bytes)
|
|
|
|
return -1;
|
|
|
|
if (bytes == 1) {
|
|
|
|
return packet->packet[4 + len] + 1;
|
|
|
|
} else {
|
|
|
|
return GST_READ_UINT16_BE (packet->packet + 4 + len) + 1;
|
|
|
|
}
|
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-10-27 11:49:41 +00:00
|
|
|
static void
|
|
|
|
extract_tags_flac (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes > 4 && ((packet->packet[0] & 0x7F) == 0x4)) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
packet->packet, 4, &pad->taglist);
|
2011-04-11 14:10:01 +00:00
|
|
|
|
2017-10-31 09:34:26 +00:00
|
|
|
if (!pad->taglist)
|
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
|
|
|
|
2011-04-11 14:10:01 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_AUDIO_CODEC, "FLAC", NULL);
|
2010-10-27 11:49:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* fishead */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_fishead_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data;
|
|
|
|
gint64 prestime_n, prestime_d;
|
|
|
|
gint64 basetime_n, basetime_d;
|
|
|
|
|
2017-11-06 13:28:52 +00:00
|
|
|
if (packet->bytes < 44) {
|
|
|
|
GST_DEBUG ("Not enough data for fishead header");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
data = packet->packet;
|
|
|
|
|
2010-06-08 09:31:35 +00:00
|
|
|
data += 8; /* header */
|
|
|
|
|
|
|
|
pad->skeleton_major = GST_READ_UINT16_LE (data);
|
|
|
|
data += 2;
|
|
|
|
pad->skeleton_minor = GST_READ_UINT16_LE (data);
|
|
|
|
data += 2;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
prestime_n = (gint64) GST_READ_UINT64_LE (data);
|
|
|
|
data += 8;
|
|
|
|
prestime_d = (gint64) GST_READ_UINT64_LE (data);
|
|
|
|
data += 8;
|
|
|
|
basetime_n = (gint64) GST_READ_UINT64_LE (data);
|
|
|
|
data += 8;
|
|
|
|
basetime_d = (gint64) GST_READ_UINT64_LE (data);
|
|
|
|
data += 8;
|
|
|
|
|
|
|
|
/* FIXME: we don't use basetime anywhere in the demuxer! */
|
2010-01-21 16:30:15 +00:00
|
|
|
if (basetime_d != 0)
|
2010-03-01 12:50:32 +00:00
|
|
|
pad->basetime = gst_util_uint64_scale (GST_SECOND, basetime_n, basetime_d);
|
2010-01-21 16:30:15 +00:00
|
|
|
else
|
2010-03-01 12:50:32 +00:00
|
|
|
pad->basetime = -1;
|
2010-01-21 16:30:15 +00:00
|
|
|
|
2010-03-01 12:50:32 +00:00
|
|
|
if (prestime_d != 0)
|
|
|
|
pad->prestime = gst_util_uint64_scale (GST_SECOND, prestime_n, prestime_d);
|
|
|
|
else
|
|
|
|
pad->prestime = -1;
|
|
|
|
|
2010-06-08 09:40:32 +00:00
|
|
|
/* Ogg Skeleton 3.3+ streams provide additional information in the header */
|
|
|
|
if (packet->bytes >= SKELETON_FISHEAD_3_3_MIN_SIZE && pad->skeleton_major == 3
|
|
|
|
&& pad->skeleton_minor > 0) {
|
2010-05-04 11:02:19 +00:00
|
|
|
gint64 firstsampletime_n, firstsampletime_d;
|
|
|
|
gint64 lastsampletime_n, lastsampletime_d;
|
|
|
|
gint64 firstsampletime, lastsampletime;
|
2010-06-08 09:40:32 +00:00
|
|
|
guint64 segment_length, content_offset;
|
2010-05-04 11:02:19 +00:00
|
|
|
|
|
|
|
firstsampletime_n = GST_READ_UINT64_LE (data + 64);
|
|
|
|
firstsampletime_d = GST_READ_UINT64_LE (data + 72);
|
|
|
|
lastsampletime_n = GST_READ_UINT64_LE (data + 80);
|
|
|
|
lastsampletime_d = GST_READ_UINT64_LE (data + 88);
|
2010-06-08 09:40:32 +00:00
|
|
|
segment_length = GST_READ_UINT64_LE (data + 96);
|
|
|
|
content_offset = GST_READ_UINT64_LE (data + 104);
|
2010-05-04 11:02:19 +00:00
|
|
|
|
|
|
|
GST_INFO ("firstsampletime %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
|
|
|
|
firstsampletime_n, firstsampletime_d);
|
|
|
|
GST_INFO ("lastsampletime %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
|
|
|
|
lastsampletime_n, lastsampletime_d);
|
2010-06-08 09:40:32 +00:00
|
|
|
GST_INFO ("segment length %" G_GUINT64_FORMAT, segment_length);
|
|
|
|
GST_INFO ("content offset %" G_GUINT64_FORMAT, content_offset);
|
2010-05-04 11:02:19 +00:00
|
|
|
|
|
|
|
if (firstsampletime_d > 0)
|
|
|
|
firstsampletime = gst_util_uint64_scale (GST_SECOND,
|
|
|
|
firstsampletime_n, firstsampletime_d);
|
|
|
|
else
|
|
|
|
firstsampletime = 0;
|
|
|
|
|
|
|
|
if (lastsampletime_d > 0)
|
|
|
|
lastsampletime = gst_util_uint64_scale (GST_SECOND,
|
|
|
|
lastsampletime_n, lastsampletime_d);
|
|
|
|
else
|
|
|
|
lastsampletime = 0;
|
|
|
|
|
|
|
|
if (lastsampletime > firstsampletime)
|
|
|
|
pad->total_time = lastsampletime - firstsampletime;
|
|
|
|
else
|
|
|
|
pad->total_time = -1;
|
|
|
|
|
|
|
|
GST_INFO ("skeleton fishead parsed total: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (pad->total_time));
|
2010-06-08 09:40:32 +00:00
|
|
|
} else if (packet->bytes >= SKELETON_FISHEAD_4_0_MIN_SIZE
|
|
|
|
&& pad->skeleton_major == 4) {
|
|
|
|
guint64 segment_length, content_offset;
|
|
|
|
|
|
|
|
segment_length = GST_READ_UINT64_LE (data + 64);
|
|
|
|
content_offset = GST_READ_UINT64_LE (data + 72);
|
|
|
|
|
|
|
|
GST_INFO ("segment length %" G_GUINT64_FORMAT, segment_length);
|
|
|
|
GST_INFO ("content offset %" G_GUINT64_FORMAT, content_offset);
|
2010-05-04 11:02:19 +00:00
|
|
|
} else {
|
|
|
|
pad->total_time = -1;
|
|
|
|
}
|
|
|
|
|
2010-06-08 09:31:35 +00:00
|
|
|
GST_INFO ("skeleton fishead %u.%u parsed (basetime: %" GST_TIME_FORMAT
|
|
|
|
", prestime: %" GST_TIME_FORMAT ")", pad->skeleton_major,
|
|
|
|
pad->skeleton_minor, GST_TIME_ARGS (pad->basetime),
|
2010-03-01 12:50:32 +00:00
|
|
|
GST_TIME_ARGS (pad->prestime));
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-03-01 11:17:40 +00:00
|
|
|
pad->is_skeleton = TRUE;
|
2010-10-10 22:17:31 +00:00
|
|
|
pad->is_sparse = TRUE;
|
|
|
|
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("application/x-ogg-skeleton");
|
2010-03-01 11:17:40 +00:00
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-01 12:50:32 +00:00
|
|
|
gboolean
|
|
|
|
gst_ogg_map_parse_fisbone (GstOggStream * pad, const guint8 * data, guint size,
|
2010-03-02 10:16:39 +00:00
|
|
|
guint32 * serialno, GstOggSkeleton * type)
|
2010-03-01 12:50:32 +00:00
|
|
|
{
|
2010-03-02 10:16:39 +00:00
|
|
|
GstOggSkeleton stype;
|
|
|
|
guint serial_offset;
|
|
|
|
|
2011-08-23 10:05:11 +00:00
|
|
|
if (size != 0 && size < SKELETON_FISBONE_MIN_SIZE) {
|
2010-03-01 12:50:32 +00:00
|
|
|
GST_WARNING ("small fisbone packet of size %d, ignoring", size);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-23 10:05:11 +00:00
|
|
|
if (size == 0) {
|
|
|
|
/* Skeleton EOS packet is zero bytes */
|
|
|
|
return FALSE;
|
|
|
|
} else if (memcmp (data, "fisbone\0", 8) == 0) {
|
2010-03-02 10:16:39 +00:00
|
|
|
GST_INFO ("got fisbone packet");
|
|
|
|
stype = GST_OGG_SKELETON_FISBONE;
|
|
|
|
serial_offset = 12;
|
|
|
|
} else if (memcmp (data, "index\0", 6) == 0) {
|
|
|
|
GST_INFO ("got index packet");
|
|
|
|
stype = GST_OGG_SKELETON_INDEX;
|
|
|
|
serial_offset = 6;
|
2010-10-11 00:15:53 +00:00
|
|
|
} else if (memcmp (data, "fishead\0", 8) == 0) {
|
|
|
|
return FALSE;
|
2010-03-02 10:16:39 +00:00
|
|
|
} else {
|
2010-10-11 00:15:53 +00:00
|
|
|
GST_WARNING ("unknown skeleton packet \"%10.10s\"", data);
|
2010-03-01 12:50:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serialno)
|
2010-03-02 10:16:39 +00:00
|
|
|
*serialno = GST_READ_UINT32_LE (data + serial_offset);
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
*type = stype;
|
2010-03-01 12:50:32 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-06-08 10:01:15 +00:00
|
|
|
gst_ogg_map_add_fisbone (GstOggStream * pad, GstOggStream * skel_pad,
|
2010-03-01 12:50:32 +00:00
|
|
|
const guint8 * data, guint size, GstClockTime * p_start_time)
|
|
|
|
{
|
|
|
|
GstClockTime start_time;
|
|
|
|
gint64 start_granule;
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
if (pad->have_fisbone) {
|
|
|
|
GST_DEBUG ("already have fisbone, ignoring second one");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-01 12:50:32 +00:00
|
|
|
|
|
|
|
/* skip "fisbone\0" + headers offset + serialno + num headers */
|
|
|
|
data += 8 + 4 + 4 + 4;
|
|
|
|
|
|
|
|
pad->have_fisbone = TRUE;
|
|
|
|
|
2011-01-13 15:35:30 +00:00
|
|
|
/* We don't overwrite whatever was set before by the format-specific
|
|
|
|
setup: skeleton contains wrong information sometimes, and the codec
|
|
|
|
headers are authoritative.
|
|
|
|
So we only gather information that was not already filled out by
|
|
|
|
the mapper setup. This should hopefully allow handling unknown
|
|
|
|
streams a bit better, while not trashing correct setup from bad
|
|
|
|
skeleton data. */
|
|
|
|
if (pad->granulerate_n == 0 || pad->granulerate_d == 0) {
|
|
|
|
pad->granulerate_n = GST_READ_UINT64_LE (data);
|
|
|
|
pad->granulerate_d = GST_READ_UINT64_LE (data + 8);
|
|
|
|
}
|
2012-03-30 10:00:08 +00:00
|
|
|
if (pad->granuleshift == G_MAXUINT32) {
|
2011-01-13 15:35:30 +00:00
|
|
|
pad->granuleshift = GST_READ_UINT8 (data + 28);
|
|
|
|
}
|
2010-03-01 12:50:32 +00:00
|
|
|
|
|
|
|
start_granule = GST_READ_UINT64_LE (data + 16);
|
|
|
|
pad->preroll = GST_READ_UINT32_LE (data + 24);
|
|
|
|
|
|
|
|
start_time = granulepos_to_granule_default (pad, start_granule);
|
|
|
|
|
|
|
|
GST_INFO ("skeleton fisbone parsed "
|
|
|
|
"(start time: %" GST_TIME_FORMAT
|
|
|
|
" granulerate_n: %d granulerate_d: %d "
|
|
|
|
" preroll: %" G_GUINT32_FORMAT " granuleshift: %d)",
|
|
|
|
GST_TIME_ARGS (start_time),
|
|
|
|
pad->granulerate_n, pad->granulerate_d, pad->preroll, pad->granuleshift);
|
|
|
|
|
|
|
|
if (p_start_time)
|
|
|
|
*p_start_time = start_time;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-04 15:38:50 +00:00
|
|
|
static gboolean
|
|
|
|
read_vlc (const guint8 ** data, guint * size, guint64 * result)
|
2010-03-02 10:16:39 +00:00
|
|
|
{
|
|
|
|
gint shift = 0;
|
2010-06-08 11:11:05 +00:00
|
|
|
guint8 byte;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
2010-05-04 15:38:50 +00:00
|
|
|
*result = 0;
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
do {
|
2010-05-04 15:38:50 +00:00
|
|
|
if (G_UNLIKELY (*size < 1))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
byte = **data;
|
2010-05-04 15:38:50 +00:00
|
|
|
*result |= ((byte & 0x7f) << shift);
|
2010-03-02 10:16:39 +00:00
|
|
|
shift += 7;
|
2010-05-04 15:38:50 +00:00
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
(*data)++;
|
2010-05-04 15:38:50 +00:00
|
|
|
(*size)--;
|
2010-03-02 10:16:39 +00:00
|
|
|
} while ((byte & 0x80) != 0x80);
|
|
|
|
|
2010-05-04 15:38:50 +00:00
|
|
|
return TRUE;
|
2010-03-02 10:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-06-08 10:01:15 +00:00
|
|
|
gst_ogg_map_add_index (GstOggStream * pad, GstOggStream * skel_pad,
|
|
|
|
const guint8 * data, guint size)
|
2010-03-02 10:16:39 +00:00
|
|
|
{
|
2010-05-04 15:38:50 +00:00
|
|
|
guint64 i, n_keypoints, isize;
|
2010-03-02 10:16:39 +00:00
|
|
|
guint64 offset, timestamp;
|
2010-05-04 15:38:50 +00:00
|
|
|
guint64 offset_d, timestamp_d;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
|
|
|
if (pad->index) {
|
|
|
|
GST_DEBUG ("already have index, ignoring second one");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-08 11:11:05 +00:00
|
|
|
if ((skel_pad->skeleton_major == 3 && size < 26) ||
|
|
|
|
(skel_pad->skeleton_major == 4 && size < 62)) {
|
2010-05-04 15:38:50 +00:00
|
|
|
GST_WARNING ("small index packet of size %u, ignoring", size);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip "index\0" + serialno */
|
|
|
|
data += 6 + 4;
|
|
|
|
size -= 6 + 4;
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
n_keypoints = GST_READ_UINT64_LE (data);
|
2010-05-04 11:51:07 +00:00
|
|
|
|
2010-06-08 11:11:05 +00:00
|
|
|
data += 8;
|
|
|
|
size -= 8;
|
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
pad->kp_denom = GST_READ_UINT64_LE (data);
|
|
|
|
if (pad->kp_denom == 0)
|
|
|
|
pad->kp_denom = 1;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
data += 8;
|
|
|
|
size -= 8;
|
2010-06-08 10:01:15 +00:00
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
if (skel_pad->skeleton_major == 4) {
|
|
|
|
gint64 firstsampletime_n;
|
|
|
|
gint64 lastsampletime_n;
|
|
|
|
gint64 firstsampletime, lastsampletime;
|
2010-06-08 11:11:05 +00:00
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
firstsampletime_n = GST_READ_UINT64_LE (data + 0);
|
|
|
|
lastsampletime_n = GST_READ_UINT64_LE (data + 8);
|
2010-06-08 10:01:15 +00:00
|
|
|
|
|
|
|
GST_INFO ("firstsampletime %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
|
2010-06-09 14:33:25 +00:00
|
|
|
firstsampletime_n, pad->kp_denom);
|
2010-06-08 10:01:15 +00:00
|
|
|
GST_INFO ("lastsampletime %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT,
|
2010-06-09 14:33:25 +00:00
|
|
|
lastsampletime_n, pad->kp_denom);
|
2010-06-08 10:01:15 +00:00
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
firstsampletime = gst_util_uint64_scale (GST_SECOND,
|
|
|
|
firstsampletime_n, pad->kp_denom);
|
|
|
|
lastsampletime = gst_util_uint64_scale (GST_SECOND,
|
|
|
|
lastsampletime_n, pad->kp_denom);
|
2010-06-08 10:01:15 +00:00
|
|
|
|
|
|
|
if (lastsampletime > firstsampletime)
|
|
|
|
pad->total_time = lastsampletime - firstsampletime;
|
|
|
|
else
|
|
|
|
pad->total_time = -1;
|
|
|
|
|
|
|
|
GST_INFO ("skeleton index parsed total: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (pad->total_time));
|
|
|
|
|
2010-06-09 14:33:25 +00:00
|
|
|
data += 16;
|
|
|
|
size -= 16;
|
2010-06-08 10:01:15 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
GST_INFO ("skeleton index has %" G_GUINT64_FORMAT " keypoints, denom: %"
|
|
|
|
G_GINT64_FORMAT, n_keypoints, pad->kp_denom);
|
|
|
|
|
|
|
|
pad->index = g_try_new (GstOggIndex, n_keypoints);
|
|
|
|
if (!pad->index)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-05-04 15:38:50 +00:00
|
|
|
isize = 0;
|
2010-03-02 10:16:39 +00:00
|
|
|
offset = 0;
|
|
|
|
timestamp = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n_keypoints; i++) {
|
2010-05-04 15:38:50 +00:00
|
|
|
/* read deltas */
|
|
|
|
if (!read_vlc (&data, &size, &offset_d))
|
|
|
|
break;
|
|
|
|
if (!read_vlc (&data, &size, ×tamp_d))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += offset_d;
|
|
|
|
timestamp += timestamp_d;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
|
|
|
pad->index[i].offset = offset;
|
|
|
|
pad->index[i].timestamp = timestamp;
|
2010-05-04 15:38:50 +00:00
|
|
|
isize++;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
|
|
|
GST_INFO ("offset %" G_GUINT64_FORMAT " time %" G_GUINT64_FORMAT, offset,
|
|
|
|
timestamp);
|
|
|
|
}
|
2010-05-04 15:38:50 +00:00
|
|
|
if (isize != n_keypoints) {
|
|
|
|
GST_WARNING ("truncated index, expected %" G_GUINT64_FORMAT ", found %"
|
|
|
|
G_GUINT64_FORMAT, n_keypoints, isize);
|
|
|
|
}
|
|
|
|
pad->n_index = isize;
|
2010-05-06 08:56:21 +00:00
|
|
|
/* try to use the index to estimate the bitrate */
|
|
|
|
if (isize > 2) {
|
|
|
|
guint64 so, eo, st, et, b, t;
|
|
|
|
|
|
|
|
/* get start and end offset and timestamps */
|
|
|
|
so = pad->index[0].offset;
|
|
|
|
st = pad->index[0].timestamp;
|
|
|
|
eo = pad->index[isize - 1].offset;
|
|
|
|
et = pad->index[isize - 1].timestamp;
|
|
|
|
|
|
|
|
b = eo - so;
|
|
|
|
t = et - st;
|
|
|
|
|
|
|
|
GST_DEBUG ("bytes/time %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, b, t);
|
|
|
|
|
|
|
|
/* this is the total stream bitrate according to this index */
|
|
|
|
pad->idx_bitrate = gst_util_uint64_scale (8 * b, pad->kp_denom, t);
|
|
|
|
|
|
|
|
GST_DEBUG ("bitrate %" G_GUINT64_FORMAT, pad->idx_bitrate);
|
|
|
|
}
|
2010-03-02 10:16:39 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-08 09:26:26 +00:00
|
|
|
static gint
|
|
|
|
gst_ogg_index_compare (const GstOggIndex * index, const guint64 * ts,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (index->timestamp < *ts)
|
|
|
|
return -1;
|
|
|
|
else if (index->timestamp > *ts)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
gboolean
|
|
|
|
gst_ogg_map_search_index (GstOggStream * pad, gboolean before,
|
|
|
|
guint64 * timestamp, guint64 * offset)
|
|
|
|
{
|
|
|
|
guint64 n_index;
|
|
|
|
guint64 ts;
|
2010-06-08 09:26:26 +00:00
|
|
|
GstOggIndex *best;
|
2010-03-02 10:16:39 +00:00
|
|
|
|
2014-04-10 09:29:34 +00:00
|
|
|
g_return_val_if_fail (timestamp != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (offset != NULL, FALSE);
|
|
|
|
|
2010-03-02 10:16:39 +00:00
|
|
|
n_index = pad->n_index;
|
|
|
|
if (n_index == 0 || pad->index == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ts = gst_util_uint64_scale (*timestamp, pad->kp_denom, GST_SECOND);
|
|
|
|
GST_INFO ("timestamp %" G_GUINT64_FORMAT, ts);
|
|
|
|
|
2010-06-08 09:26:26 +00:00
|
|
|
best =
|
|
|
|
gst_util_array_binary_search (pad->index, n_index, sizeof (GstOggIndex),
|
|
|
|
(GCompareDataFunc) gst_ogg_index_compare, GST_SEARCH_MODE_BEFORE, &ts,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (best == NULL)
|
2010-03-02 10:16:39 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-06-13 23:33:04 +00:00
|
|
|
GST_INFO ("found at index %u", (guint) (best - pad->index));
|
2010-03-02 10:16:39 +00:00
|
|
|
|
2014-04-10 09:29:34 +00:00
|
|
|
*offset = best->offset;
|
|
|
|
*timestamp =
|
|
|
|
gst_util_uint64_scale (best->timestamp, GST_SECOND, pad->kp_denom);
|
2010-03-02 10:16:39 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
/* Do we need these for something?
|
|
|
|
* ogm->hdr.size = GST_READ_UINT32_LE (&data[13]);
|
|
|
|
* ogm->hdr.time_unit = GST_READ_UINT64_LE (&data[17]);
|
|
|
|
* ogm->hdr.samples_per_unit = GST_READ_UINT64_LE (&data[25]);
|
|
|
|
* ogm->hdr.default_len = GST_READ_UINT32_LE (&data[33]);
|
|
|
|
* ogm->hdr.buffersize = GST_READ_UINT32_LE (&data[37]);
|
|
|
|
* ogm->hdr.bits_per_sample = GST_READ_UINT32_LE (&data[41]);
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
2009-12-04 04:05:29 +00:00
|
|
|
is_header_ogm (GstOggStream * pad, ogg_packet * packet)
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
2009-12-11 11:02:15 +00:00
|
|
|
if (packet->bytes >= 1 && (packet->packet[0] & 0x01))
|
2009-12-04 04:05:29 +00:00
|
|
|
return TRUE;
|
2009-12-11 11:02:15 +00:00
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-10-27 10:08:25 +00:00
|
|
|
static void
|
|
|
|
extract_tags_ogm (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (!(packet->packet[0] & 1) && (packet->packet[0] & 3 && pad->is_ogm_text)) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "\003vorbis", 7, &pad->taglist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
static gint64
|
|
|
|
packet_duration_ogm (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
const guint8 *data;
|
2017-11-05 11:16:13 +00:00
|
|
|
gint64 samples;
|
2009-12-04 04:05:29 +00:00
|
|
|
int offset;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
data = packet->packet;
|
|
|
|
offset = 1 + (((data[0] & 0xc0) >> 6) | ((data[0] & 0x02) << 1));
|
|
|
|
|
|
|
|
if (offset > packet->bytes) {
|
2017-11-15 07:28:47 +00:00
|
|
|
GST_WARNING ("buffer too small");
|
2009-12-04 04:05:29 +00:00
|
|
|
return -1;
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
samples = 0;
|
|
|
|
for (n = offset - 1; n > 0; n--) {
|
|
|
|
samples = (samples << 8) | data[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
return samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_ogmaudio_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
|
|
|
guint32 fourcc;
|
2011-08-22 10:22:02 +00:00
|
|
|
gchar *fstr;
|
2009-12-04 04:05:29 +00:00
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n = GST_READ_UINT64_LE (data + 25);
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
fourcc = GST_READ_UINT32_LE (data + 9);
|
2011-08-22 10:22:02 +00:00
|
|
|
fstr = g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
|
|
|
GST_DEBUG ("fourcc: %s", fstr);
|
2009-12-04 04:05:29 +00:00
|
|
|
|
2011-12-31 13:32:45 +00:00
|
|
|
/* FIXME: Need to do something with the reorder map */
|
|
|
|
pad->caps =
|
|
|
|
gst_riff_create_audio_caps (fourcc, NULL, NULL, NULL, NULL, NULL, NULL);
|
2009-12-04 04:05:29 +00:00
|
|
|
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
if (pad->caps) {
|
|
|
|
gst_caps_set_simple (pad->caps,
|
|
|
|
"rate", G_TYPE_INT, pad->granulerate_n, NULL);
|
|
|
|
} else {
|
|
|
|
pad->caps = gst_caps_new_simple ("audio/x-ogm-unknown",
|
2011-08-22 10:22:02 +00:00
|
|
|
"fourcc", G_TYPE_STRING, fstr,
|
2009-12-04 04:05:29 +00:00
|
|
|
"rate", G_TYPE_INT, pad->granulerate_n, NULL);
|
|
|
|
}
|
2011-08-22 10:22:02 +00:00
|
|
|
g_free (fstr);
|
2009-12-04 04:05:29 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = 1;
|
|
|
|
pad->is_ogm = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_ogmvideo_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-04 04:05:29 +00:00
|
|
|
guint32 fourcc;
|
|
|
|
int width, height;
|
|
|
|
gint64 time_unit;
|
2011-08-22 10:22:02 +00:00
|
|
|
gchar *fstr;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
GST_DEBUG ("time unit %d", GST_READ_UINT32_LE (data + 16));
|
|
|
|
GST_DEBUG ("samples per unit %d", GST_READ_UINT32_LE (data + 24));
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-11-21 03:02:50 +00:00
|
|
|
pad->is_video = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n = 10000000;
|
2009-12-04 04:05:29 +00:00
|
|
|
time_unit = GST_READ_UINT64_LE (data + 17);
|
|
|
|
if (time_unit > G_MAXINT || time_unit < G_MININT) {
|
|
|
|
GST_WARNING ("timeunit is out of range");
|
|
|
|
}
|
|
|
|
pad->granulerate_d = (gint) CLAMP (time_unit, G_MININT, G_MAXINT);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("fps = %d/%d = %.3f",
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n, pad->granulerate_d,
|
|
|
|
(double) pad->granulerate_n / pad->granulerate_d);
|
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
fourcc = GST_READ_UINT32_LE (data + 9);
|
|
|
|
width = GST_READ_UINT32_LE (data + 45);
|
|
|
|
height = GST_READ_UINT32_LE (data + 49);
|
2011-08-22 10:22:02 +00:00
|
|
|
fstr = g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
|
|
|
GST_DEBUG ("fourcc: %s", fstr);
|
2009-12-04 04:05:29 +00:00
|
|
|
|
|
|
|
pad->caps = gst_riff_create_video_caps (fourcc, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (pad->caps == NULL) {
|
|
|
|
pad->caps = gst_caps_new_simple ("video/x-ogm-unknown",
|
2011-08-22 10:22:02 +00:00
|
|
|
"fourcc", G_TYPE_STRING, fstr,
|
2009-12-04 04:05:29 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, pad->granulerate_n,
|
|
|
|
pad->granulerate_d, NULL);
|
|
|
|
} else {
|
|
|
|
gst_caps_set_simple (pad->caps,
|
|
|
|
"framerate", GST_TYPE_FRACTION, pad->granulerate_n,
|
|
|
|
pad->granulerate_d,
|
|
|
|
"width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
|
|
|
|
}
|
|
|
|
GST_DEBUG ("caps: %" GST_PTR_FORMAT, pad->caps);
|
2011-08-22 10:22:02 +00:00
|
|
|
g_free (fstr);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2009-12-04 04:05:29 +00:00
|
|
|
pad->n_header_packets = 1;
|
|
|
|
pad->frame_size = 1;
|
|
|
|
pad->is_ogm = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_ogmtext_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2009-12-04 04:05:29 +00:00
|
|
|
gint64 time_unit;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->granulerate_n = 10000000;
|
2009-12-04 04:05:29 +00:00
|
|
|
time_unit = GST_READ_UINT64_LE (data + 17);
|
|
|
|
if (time_unit > G_MAXINT || time_unit < G_MININT) {
|
|
|
|
GST_WARNING ("timeunit is out of range");
|
|
|
|
}
|
|
|
|
pad->granulerate_d = (gint) CLAMP (time_unit, G_MININT, G_MAXINT);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("fps = %d/%d = %.3f",
|
2009-08-29 17:51:48 +00:00
|
|
|
pad->granulerate_n, pad->granulerate_d,
|
|
|
|
(double) pad->granulerate_n / pad->granulerate_d);
|
|
|
|
|
|
|
|
if (pad->granulerate_d <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-09-02 01:41:34 +00:00
|
|
|
pad->caps = gst_caps_new_simple ("text/x-raw", "format", G_TYPE_STRING,
|
|
|
|
"utf8", NULL);
|
2009-12-04 04:05:29 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = 1;
|
|
|
|
pad->is_ogm = TRUE;
|
|
|
|
pad->is_ogm_text = TRUE;
|
2010-10-10 22:17:31 +00:00
|
|
|
pad->is_sparse = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PCM */
|
|
|
|
|
|
|
|
#define OGGPCM_FMT_S8 0x00000000 /* Signed integer 8 bit */
|
|
|
|
#define OGGPCM_FMT_U8 0x00000001 /* Unsigned integer 8 bit */
|
|
|
|
#define OGGPCM_FMT_S16_LE 0x00000002 /* Signed integer 16 bit little endian */
|
|
|
|
#define OGGPCM_FMT_S16_BE 0x00000003 /* Signed integer 16 bit big endian */
|
|
|
|
#define OGGPCM_FMT_S24_LE 0x00000004 /* Signed integer 24 bit little endian */
|
|
|
|
#define OGGPCM_FMT_S24_BE 0x00000005 /* Signed integer 24 bit big endian */
|
|
|
|
#define OGGPCM_FMT_S32_LE 0x00000006 /* Signed integer 32 bit little endian */
|
|
|
|
#define OGGPCM_FMT_S32_BE 0x00000007 /* Signed integer 32 bit big endian */
|
|
|
|
|
|
|
|
#define OGGPCM_FMT_ULAW 0x00000010 /* G.711 u-law encoding (8 bit) */
|
|
|
|
#define OGGPCM_FMT_ALAW 0x00000011 /* G.711 A-law encoding (8 bit) */
|
|
|
|
|
|
|
|
#define OGGPCM_FMT_FLT32_LE 0x00000020 /* IEEE Float [-1,1] 32 bit little endian */
|
|
|
|
#define OGGPCM_FMT_FLT32_BE 0x00000021 /* IEEE Float [-1,1] 32 bit big endian */
|
|
|
|
#define OGGPCM_FMT_FLT64_LE 0x00000022 /* IEEE Float [-1,1] 64 bit little endian */
|
|
|
|
#define OGGPCM_FMT_FLT64_BE 0x00000023 /* IEEE Float [-1,1] 64 bit big endian */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_pcm_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
|
|
|
int format;
|
|
|
|
int channels;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data + 16);
|
|
|
|
pad->granulerate_d = 1;
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
format = GST_READ_UINT32_LE (data + 12);
|
|
|
|
channels = GST_READ_UINT8 (data + 21);
|
|
|
|
|
|
|
|
pad->n_header_packets = 2 + GST_READ_UINT32_LE (data + 24);
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case OGGPCM_FMT_S8:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "S8", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_U8:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "U8", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S16_LE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S16LE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S16_BE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S16BE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S24_LE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S24LE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S24_BE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S24BE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S32_LE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S32LE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_S32_BE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "S32BE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_ULAW:
|
2011-10-27 15:26:58 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-mulaw");
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_ALAW:
|
2011-10-27 15:26:58 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-alaw");
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_FLT32_LE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "F32LE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_FLT32_BE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "F32BE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_FLT64_LE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "F64LE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
case OGGPCM_FMT_FLT64_BE:
|
2011-08-19 15:41:22 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw",
|
2011-09-06 10:06:39 +00:00
|
|
|
"format", G_TYPE_STRING, "F64BE", NULL);
|
2009-08-29 17:51:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-19 15:41:22 +00:00
|
|
|
gst_caps_set_simple (caps,
|
2011-12-31 13:25:09 +00:00
|
|
|
"layout", G_TYPE_STRING, "interleaved",
|
2009-08-29 17:51:48 +00:00
|
|
|
"rate", G_TYPE_INT, pad->granulerate_n,
|
|
|
|
"channels", G_TYPE_INT, channels, NULL);
|
|
|
|
pad->caps = caps;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cmml */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_cmml_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
|
|
|
|
|
|
|
pad->granulerate_n = GST_READ_UINT64_LE (data + 12);
|
|
|
|
pad->granulerate_d = GST_READ_UINT64_LE (data + 20);
|
|
|
|
pad->granuleshift = data[28];
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = 3;
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
data += 4 + (4 + 4 + 4);
|
|
|
|
GST_DEBUG ("blocksize0: %u", 1 << (data[0] >> 4));
|
|
|
|
GST_DEBUG ("blocksize1: %u", 1 << (data[0] & 0x0F));
|
|
|
|
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("text/x-cmml");
|
2011-08-17 17:48:54 +00:00
|
|
|
pad->always_flush_page = TRUE;
|
2010-10-10 22:17:31 +00:00
|
|
|
pad->is_sparse = TRUE;
|
2012-05-12 13:36:09 +00:00
|
|
|
pad->is_cmml = TRUE;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* celt */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_celt_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
|
|
|
|
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data + 36);
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->frame_size = GST_READ_UINT32_LE (packet->packet + 44);
|
|
|
|
pad->n_header_packets = GST_READ_UINT32_LE (packet->packet + 56) + 2;
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pad->caps = gst_caps_new_simple ("audio/x-celt",
|
|
|
|
"rate", G_TYPE_INT, pad->granulerate_n, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* kate */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_kate_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
2010-01-23 20:15:08 +00:00
|
|
|
const char *category;
|
|
|
|
|
|
|
|
if (packet->bytes < 64)
|
|
|
|
return FALSE;
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data + 24);
|
|
|
|
pad->granulerate_d = GST_READ_UINT32_LE (data + 28);
|
|
|
|
pad->granuleshift = GST_READ_UINT8 (data + 15);
|
2009-12-03 19:57:48 +00:00
|
|
|
GST_LOG ("sample rate: %d", pad->granulerate_n);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
pad->n_header_packets = GST_READ_UINT8 (data + 11);
|
2010-10-29 10:47:53 +00:00
|
|
|
GST_LOG ("kate header packets: %d", pad->n_header_packets);
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
if (pad->granulerate_n == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-01-23 20:15:08 +00:00
|
|
|
category = (const char *) data + 48;
|
|
|
|
if (strcmp (category, "subtitles") == 0 || strcmp (category, "SUB") == 0 ||
|
|
|
|
strcmp (category, "spu-subtitles") == 0 ||
|
|
|
|
strcmp (category, "K-SPU") == 0) {
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("subtitle/x-kate");
|
2010-01-23 20:15:08 +00:00
|
|
|
} else {
|
2011-10-27 15:26:58 +00:00
|
|
|
pad->caps = gst_caps_new_empty_simple ("application/x-kate");
|
2010-01-23 20:15:08 +00:00
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
|
2010-10-10 22:17:31 +00:00
|
|
|
pad->is_sparse = TRUE;
|
2011-08-17 17:48:54 +00:00
|
|
|
pad->always_flush_page = TRUE;
|
2010-10-10 22:17:31 +00:00
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-17 14:16:18 +00:00
|
|
|
static gint64
|
|
|
|
packet_duration_kate (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
gint64 duration;
|
|
|
|
|
|
|
|
if (packet->bytes < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (packet->packet[0]) {
|
|
|
|
case 0x00: /* text data */
|
|
|
|
if (packet->bytes < 1 + 8 * 2) {
|
|
|
|
duration = 0;
|
|
|
|
} else {
|
|
|
|
duration = GST_READ_UINT64_LE (packet->packet + 1 + 8);
|
|
|
|
if (duration < 0)
|
|
|
|
duration = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
duration = GST_CLOCK_TIME_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2010-12-25 15:22:42 +00:00
|
|
|
static void
|
|
|
|
extract_tags_kate (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
GstTagList *list = NULL;
|
|
|
|
|
|
|
|
if (packet->bytes <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (packet->packet[0]) {
|
|
|
|
case 0x80:{
|
|
|
|
const gchar *canonical;
|
|
|
|
char language[16];
|
|
|
|
|
|
|
|
if (packet->bytes < 64) {
|
|
|
|
GST_WARNING ("Kate ID header packet is less than 64 bytes, ignored");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the language tag is 16 bytes at offset 32, ensure NUL terminator */
|
|
|
|
memcpy (language, packet->packet + 32, 16);
|
|
|
|
language[15] = 0;
|
|
|
|
|
|
|
|
/* language is an ISO 639-1 code or RFC 3066 language code, we
|
|
|
|
* truncate to ISO 639-1 */
|
|
|
|
g_strdelimit (language, NULL, '\0');
|
|
|
|
canonical = gst_tag_get_language_code_iso_639_1 (language);
|
|
|
|
if (canonical) {
|
2011-10-30 11:09:10 +00:00
|
|
|
list = gst_tag_list_new (GST_TAG_LANGUAGE_CODE, canonical, NULL);
|
2010-12-25 15:22:42 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING ("Unknown or invalid language code %s, ignored", language);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x81:
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "\201kate\0\0\0\0", 9, &list);
|
2011-04-11 14:10:01 +00:00
|
|
|
|
|
|
|
if (list != NULL) {
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_SUBTITLE_CODEC, "Kate", NULL);
|
|
|
|
}
|
2010-12-25 15:22:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list) {
|
|
|
|
if (pad->taglist) {
|
|
|
|
/* ensure the comment packet cannot override the category/language
|
|
|
|
from the identification header */
|
|
|
|
gst_tag_list_insert (pad->taglist, list, GST_TAG_MERGE_KEEP_ALL);
|
2012-09-14 15:53:21 +00:00
|
|
|
gst_tag_list_unref (list);
|
2010-12-25 15:22:42 +00:00
|
|
|
} else
|
|
|
|
pad->taglist = list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-19 16:06:09 +00:00
|
|
|
/* opus */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_opus_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
2015-11-03 14:51:47 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
|
2011-11-19 16:06:09 +00:00
|
|
|
if (packet->bytes < 19)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pad->granulerate_n = 48000;
|
|
|
|
pad->granulerate_d = 1;
|
|
|
|
pad->granuleshift = 0;
|
|
|
|
pad->n_header_packets = 2;
|
2012-06-06 10:01:13 +00:00
|
|
|
pad->first_granpos = -1;
|
2015-11-03 08:58:35 +00:00
|
|
|
pad->audio_clipping = TRUE;
|
2011-11-19 16:06:09 +00:00
|
|
|
|
2011-11-21 17:03:21 +00:00
|
|
|
/* pre-skip is in samples at 48000 Hz, which matches granule one for one */
|
|
|
|
pad->granule_offset = -GST_READ_UINT16_LE (packet->packet + 10);
|
|
|
|
GST_INFO ("Opus has a pre-skip of %" G_GINT64_FORMAT " samples",
|
|
|
|
-pad->granule_offset);
|
|
|
|
|
2015-11-03 14:51:47 +00:00
|
|
|
buffer =
|
|
|
|
gst_buffer_new_wrapped (g_memdup (packet->packet, packet->bytes),
|
|
|
|
packet->bytes);
|
|
|
|
pad->caps = gst_codec_utils_opus_create_caps_from_header (buffer, NULL);
|
|
|
|
gst_buffer_unref (buffer);
|
2011-11-19 16:06:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-22 13:15:33 +00:00
|
|
|
static gboolean
|
|
|
|
is_header_opus (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return packet->bytes >= 8 && !memcmp (packet->packet, "Opus", 4);
|
|
|
|
}
|
|
|
|
|
2012-06-06 10:01:13 +00:00
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_opus (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
if (granulepos == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (pad->first_granpos < 0 || granulepos < pad->first_granpos)
|
|
|
|
pad->first_granpos = granulepos;
|
|
|
|
|
2017-05-29 12:44:01 +00:00
|
|
|
return granulepos;
|
2012-06-06 10:01:13 +00:00
|
|
|
}
|
|
|
|
|
2011-11-19 16:06:09 +00:00
|
|
|
static gint64
|
|
|
|
packet_duration_opus (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
static const guint64 durations[32] = {
|
2011-11-22 12:55:56 +00:00
|
|
|
480, 960, 1920, 2880, /* Silk NB */
|
|
|
|
480, 960, 1920, 2880, /* Silk MB */
|
|
|
|
480, 960, 1920, 2880, /* Silk WB */
|
|
|
|
480, 960, /* Hybrid SWB */
|
|
|
|
480, 960, /* Hybrid FB */
|
|
|
|
120, 240, 480, 960, /* CELT NB */
|
|
|
|
120, 240, 480, 960, /* CELT NB */
|
|
|
|
120, 240, 480, 960, /* CELT NB */
|
|
|
|
120, 240, 480, 960, /* CELT NB */
|
2011-11-19 16:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gint64 duration;
|
|
|
|
gint64 frame_duration;
|
2012-01-17 17:19:30 +00:00
|
|
|
gint nframes = 0;
|
2011-11-19 16:06:09 +00:00
|
|
|
guint8 toc;
|
|
|
|
|
|
|
|
if (packet->bytes < 1)
|
|
|
|
return 0;
|
|
|
|
|
2011-11-22 12:00:58 +00:00
|
|
|
/* headers */
|
2011-11-22 13:15:33 +00:00
|
|
|
if (is_header_opus (pad, packet))
|
2011-11-22 12:00:58 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-11-19 16:06:09 +00:00
|
|
|
toc = packet->packet[0];
|
|
|
|
|
2011-11-22 12:55:56 +00:00
|
|
|
frame_duration = durations[toc >> 3];
|
2011-11-19 16:06:09 +00:00
|
|
|
switch (toc & 3) {
|
|
|
|
case 0:
|
|
|
|
nframes = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
nframes = 2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
nframes = 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (packet->bytes < 2) {
|
|
|
|
GST_WARNING ("Code 3 Opus packet has less than 2 bytes");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nframes = packet->packet[1] & 63;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration = nframes * frame_duration;
|
2011-11-22 12:55:56 +00:00
|
|
|
if (duration > 5760) {
|
2011-11-19 16:06:09 +00:00
|
|
|
GST_WARNING ("Opus packet duration > 120 ms, invalid");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GST_LOG ("Opus packet: frame size %.1f ms, %d frames, duration %.1f ms",
|
2011-11-22 12:55:56 +00:00
|
|
|
frame_duration / 48.f, nframes, duration / 48.f);
|
|
|
|
return duration;
|
2011-11-19 16:06:09 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 13:29:10 +00:00
|
|
|
static void
|
|
|
|
extract_tags_opus (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes >= 8 && memcmp (packet->packet, "OpusTags", 8) == 0) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "OpusTags", 8, &pad->taglist);
|
2011-04-11 14:10:01 +00:00
|
|
|
|
2017-10-31 09:34:26 +00:00
|
|
|
if (!pad->taglist)
|
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
|
|
|
|
2011-04-11 14:10:01 +00:00
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_AUDIO_CODEC, "Opus", NULL);
|
2011-11-22 13:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 08:30:02 +00:00
|
|
|
/* daala */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
setup_daala_mapper (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
guint8 *data = packet->packet;
|
|
|
|
guint w, h, par_d, par_n;
|
|
|
|
guint8 vmaj, vmin, vrev;
|
|
|
|
guint frame_duration;
|
|
|
|
|
|
|
|
vmaj = data[6];
|
|
|
|
vmin = data[7];
|
|
|
|
vrev = data[8];
|
|
|
|
|
|
|
|
GST_LOG ("daala %d.%d.%d", vmaj, vmin, vrev);
|
|
|
|
|
2013-06-23 10:07:41 +00:00
|
|
|
w = GST_READ_UINT32_LE (data + 9);
|
|
|
|
h = GST_READ_UINT32_LE (data + 13);
|
2013-06-23 08:30:02 +00:00
|
|
|
|
2013-06-23 10:07:41 +00:00
|
|
|
par_n = GST_READ_UINT32_LE (data + 17);
|
|
|
|
par_d = GST_READ_UINT32_LE (data + 21);
|
2013-06-23 08:30:02 +00:00
|
|
|
|
2013-06-23 10:07:41 +00:00
|
|
|
pad->granulerate_n = GST_READ_UINT32_LE (data + 25);
|
|
|
|
pad->granulerate_d = GST_READ_UINT32_LE (data + 29);
|
|
|
|
frame_duration = GST_READ_UINT32_LE (data + 33);
|
2013-06-23 08:30:02 +00:00
|
|
|
|
|
|
|
GST_LOG ("fps = %d/%d, dur %d, PAR = %u/%u, width = %u, height = %u",
|
|
|
|
pad->granulerate_n, pad->granulerate_d, frame_duration, par_n, par_d, w,
|
|
|
|
h);
|
|
|
|
|
|
|
|
pad->granuleshift = GST_READ_UINT8 (data + 37);
|
|
|
|
GST_LOG ("granshift: %d", pad->granuleshift);
|
|
|
|
|
|
|
|
pad->is_video = TRUE;
|
|
|
|
pad->n_header_packets = 3;
|
|
|
|
pad->frame_size = 1;
|
|
|
|
|
|
|
|
if (pad->granulerate_n == 0 || pad->granulerate_d == 0) {
|
|
|
|
GST_WARNING ("frame rate %d/%d", pad->granulerate_n, pad->granulerate_d);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->caps = gst_caps_new_empty_simple ("video/x-daala");
|
|
|
|
|
|
|
|
if (w > 0 && h > 0) {
|
|
|
|
gst_caps_set_simple (pad->caps, "width", G_TYPE_INT, w, "height",
|
|
|
|
G_TYPE_INT, h, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PAR of 0:N, N:0 and 0:0 is allowed and maps to 1:1 */
|
|
|
|
if (par_n == 0 || par_d == 0)
|
|
|
|
par_n = par_d = 1;
|
|
|
|
|
|
|
|
/* only add framerate now so caps look prettier, with width/height first */
|
|
|
|
gst_caps_set_simple (pad->caps, "framerate", GST_TYPE_FRACTION,
|
|
|
|
pad->granulerate_n, pad->granulerate_d, "pixel-aspect-ratio",
|
|
|
|
GST_TYPE_FRACTION, par_n, par_d, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
granulepos_to_granule_daala (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
gint64 keyindex, keyoffset;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (pad->granuleshift != 0 && pad->granuleshift != G_MAXUINT32) {
|
2013-06-23 08:30:02 +00:00
|
|
|
keyindex = granulepos >> pad->granuleshift;
|
|
|
|
keyoffset = granulepos - (keyindex << pad->granuleshift);
|
|
|
|
return keyindex + keyoffset;
|
|
|
|
} else {
|
|
|
|
return granulepos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_granulepos_keyframe_daala (GstOggStream * pad, gint64 granulepos)
|
|
|
|
{
|
|
|
|
gint64 frame_mask;
|
|
|
|
|
2017-11-05 11:15:33 +00:00
|
|
|
if (granulepos == (gint64) - 1 || pad->granuleshift == G_MAXUINT32)
|
2013-06-23 08:30:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-04-10 15:08:29 +00:00
|
|
|
frame_mask = (G_GUINT64_CONSTANT (1) << pad->granuleshift) - 1;
|
2013-06-23 08:30:02 +00:00
|
|
|
|
|
|
|
return ((granulepos & frame_mask) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_packet_keyframe_daala (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes == 0)
|
|
|
|
return FALSE;
|
|
|
|
return (packet->packet[0] & 0x40);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_header_daala (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
return (packet->bytes > 0 && (packet->packet[0] & 0x80) == 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
extract_tags_daala (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
if (packet->bytes > 0 && packet->packet[0] == 0x81) {
|
|
|
|
tag_list_from_vorbiscomment_packet (packet,
|
|
|
|
(const guint8 *) "\201daala", 5, &pad->taglist);
|
|
|
|
|
|
|
|
if (!pad->taglist)
|
|
|
|
pad->taglist = gst_tag_list_new_empty ();
|
|
|
|
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_VIDEO_CODEC, "Daala", NULL);
|
|
|
|
|
|
|
|
if (pad->bitrate)
|
|
|
|
gst_tag_list_add (pad->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_BITRATE, (guint) pad->bitrate, NULL);
|
|
|
|
}
|
|
|
|
}
|
2009-08-29 17:51:48 +00:00
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
/* indent hates our freedoms */
|
2010-08-08 15:42:04 +00:00
|
|
|
const GstOggMap mappers[] = {
|
2017-11-01 17:24:11 +00:00
|
|
|
{
|
|
|
|
/* Empty mapper for uninitialized pads/streams */
|
|
|
|
NULL, 0, G_MAXINT32,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
|
|
|
"\200theora", 7, 42,
|
|
|
|
"video/x-theora",
|
|
|
|
setup_theora_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-11-26 01:04:41 +00:00
|
|
|
granulepos_to_granule_theora,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_theora,
|
|
|
|
is_packet_keyframe_theora,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_theora,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_constant,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_theora,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"\001vorbis", 7, 22,
|
|
|
|
"audio/x-vorbis",
|
|
|
|
setup_vorbis_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_vorbis,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_vorbis,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_vorbis,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Speex", 5, 80,
|
|
|
|
"audio/x-speex",
|
|
|
|
setup_speex_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_constant,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_count,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"PCM ", 8, 0,
|
2011-08-19 15:41:22 +00:00
|
|
|
"audio/x-raw",
|
2009-08-29 17:51:48 +00:00
|
|
|
setup_pcm_mapper,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-11-25 05:22:03 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"CMML\0\0\0\0", 8, 0,
|
|
|
|
"text/x-cmml",
|
|
|
|
setup_cmml_mapper,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-11-25 05:22:03 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Annodex", 7, 0,
|
|
|
|
"application/x-annodex",
|
|
|
|
setup_fishead_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fishead", 7, 64,
|
|
|
|
"application/octet-stream",
|
|
|
|
setup_fishead_mapper,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-11-25 05:22:03 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_true,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fLaC", 4, 0,
|
|
|
|
"audio/x-flac",
|
|
|
|
setup_fLaC_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2009-12-11 06:47:53 +00:00
|
|
|
is_header_fLaC,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_flac,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
2010-01-05 13:11:06 +00:00
|
|
|
"\177FLAC", 5, 36,
|
2009-08-29 17:51:48 +00:00
|
|
|
"audio/x-flac",
|
|
|
|
setup_flac_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2010-01-06 12:57:51 +00:00
|
|
|
is_header_flac,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_flac,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_flac,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"AnxData", 7, 0,
|
|
|
|
"application/octet-stream",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2010-05-05 11:59:57 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"CELT ", 8, 0,
|
|
|
|
"audio/x-celt",
|
|
|
|
setup_celt_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_constant,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_count,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"\200kate\0\0\0", 8, 0,
|
|
|
|
"text/x-kate",
|
|
|
|
setup_kate_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2010-01-24 12:31:04 +00:00
|
|
|
granulepos_to_granule_default,
|
|
|
|
granule_to_granulepos_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-12-17 14:16:18 +00:00
|
|
|
packet_duration_kate,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_kate,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"BBCD\0", 5, 13,
|
|
|
|
"video/x-dirac",
|
|
|
|
setup_dirac_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_dirac,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_dirac,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_keyframe_dirac,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
is_header_count,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_constant,
|
2010-10-27 10:08:25 +00:00
|
|
|
granulepos_to_key_granule_dirac,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
2010-05-05 11:59:57 +00:00
|
|
|
{
|
2010-05-20 08:19:29 +00:00
|
|
|
"OVP80\1\1", 7, 4,
|
2010-05-05 11:59:57 +00:00
|
|
|
"video/x-vp8",
|
|
|
|
setup_vp8_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
setup_vp8_mapper_from_caps,
|
2010-05-05 11:59:57 +00:00
|
|
|
granulepos_to_granule_vp8,
|
|
|
|
granule_to_granulepos_vp8,
|
|
|
|
is_keyframe_vp8,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2010-05-19 19:35:19 +00:00
|
|
|
is_header_vp8,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_vp8,
|
2010-10-27 10:08:25 +00:00
|
|
|
granulepos_to_key_granule_vp8,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_vp8,
|
2014-03-06 15:59:08 +00:00
|
|
|
get_headers_vp8,
|
|
|
|
update_stats_vp8
|
2010-05-05 11:59:57 +00:00
|
|
|
},
|
2011-11-19 16:06:09 +00:00
|
|
|
{
|
|
|
|
"OpusHead", 8, 0,
|
|
|
|
"audio/x-opus",
|
|
|
|
setup_opus_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2012-06-06 10:01:13 +00:00
|
|
|
granulepos_to_granule_opus,
|
2011-11-19 16:06:09 +00:00
|
|
|
granule_to_granulepos_default,
|
|
|
|
NULL,
|
2014-06-02 11:40:27 +00:00
|
|
|
is_packet_keyframe_true,
|
2011-11-22 13:15:33 +00:00
|
|
|
is_header_opus,
|
2011-11-19 16:06:09 +00:00
|
|
|
packet_duration_opus,
|
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_opus,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2011-11-19 16:06:09 +00:00
|
|
|
},
|
2009-08-29 17:51:48 +00:00
|
|
|
{
|
2009-12-04 04:05:29 +00:00
|
|
|
"\001audio\0\0\0", 9, 53,
|
2009-08-29 17:51:48 +00:00
|
|
|
"application/x-ogm-audio",
|
|
|
|
setup_ogmaudio_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2009-12-04 04:05:29 +00:00
|
|
|
is_header_ogm,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_ogm,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
2009-12-04 04:05:29 +00:00
|
|
|
"\001video\0\0\0", 9, 53,
|
2009-08-29 17:51:48 +00:00
|
|
|
"application/x-ogm-video",
|
|
|
|
setup_ogmvideo_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2009-08-29 17:51:48 +00:00
|
|
|
NULL,
|
2012-02-01 15:28:45 +00:00
|
|
|
NULL,
|
2009-12-04 04:05:29 +00:00
|
|
|
is_header_ogm,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_constant,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2010-05-14 09:02:38 +00:00
|
|
|
NULL
|
2009-08-29 17:51:48 +00:00
|
|
|
},
|
|
|
|
{
|
2009-12-04 04:05:29 +00:00
|
|
|
"\001text\0\0\0", 9, 9,
|
2009-08-29 17:51:48 +00:00
|
|
|
"application/x-ogm-text",
|
|
|
|
setup_ogmtext_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2009-08-29 17:51:48 +00:00
|
|
|
granulepos_to_granule_default,
|
2009-11-25 05:22:03 +00:00
|
|
|
granule_to_granulepos_default,
|
2012-02-01 15:28:45 +00:00
|
|
|
is_granulepos_keyframe_true,
|
|
|
|
is_packet_keyframe_true,
|
2009-12-04 04:05:29 +00:00
|
|
|
is_header_ogm,
|
2010-05-14 09:02:38 +00:00
|
|
|
packet_duration_ogm,
|
2010-10-27 10:08:25 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_ogm,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2013-06-23 08:30:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"\200daala", 6, 42,
|
|
|
|
"video/x-daala",
|
|
|
|
setup_daala_mapper,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL,
|
2013-06-23 08:30:02 +00:00
|
|
|
granulepos_to_granule_daala,
|
|
|
|
granule_to_granulepos_default,
|
|
|
|
is_granulepos_keyframe_daala,
|
|
|
|
is_packet_keyframe_daala,
|
|
|
|
is_header_daala,
|
|
|
|
packet_duration_constant,
|
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
extract_tags_daala,
|
2014-03-06 15:59:08 +00:00
|
|
|
NULL,
|
2014-03-05 19:34:42 +00:00
|
|
|
NULL
|
2013-06-23 08:30:02 +00:00
|
|
|
},
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ogg_stream_setup_map (GstOggStream * pad, ogg_packet * packet)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (mappers); i++) {
|
|
|
|
if (packet->bytes >= mappers[i].min_packet_size &&
|
|
|
|
packet->bytes >= mappers[i].id_length &&
|
|
|
|
memcmp (packet->packet, mappers[i].id, mappers[i].id_length) == 0) {
|
2010-01-21 16:31:13 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("found mapper for '%s'", mappers[i].id);
|
|
|
|
|
|
|
|
if (mappers[i].setup_func)
|
|
|
|
ret = mappers[i].setup_func (pad, packet);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2009-08-29 17:51:48 +00:00
|
|
|
if (ret) {
|
|
|
|
GST_DEBUG ("got stream type %" GST_PTR_FORMAT, pad->caps);
|
|
|
|
pad->map = i;
|
|
|
|
return TRUE;
|
2009-12-03 01:16:17 +00:00
|
|
|
} else {
|
2009-12-04 04:05:29 +00:00
|
|
|
GST_WARNING ("mapper '%s' did not accept setup header",
|
|
|
|
mappers[i].media_type);
|
2009-08-29 17:51:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-04-15 12:36:39 +00:00
|
|
|
|
2014-03-05 19:34:42 +00:00
|
|
|
gboolean
|
|
|
|
gst_ogg_stream_setup_map_from_caps (GstOggStream * pad, const GstCaps * caps)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
gboolean ret;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
g_return_val_if_fail (caps != NULL, FALSE);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (mappers); i++) {
|
|
|
|
if (mappers[i].setup_from_caps_func &&
|
|
|
|
gst_structure_has_name (structure, mappers[i].media_type)) {
|
|
|
|
|
|
|
|
GST_DEBUG ("found mapper for '%s'", mappers[i].id);
|
|
|
|
|
|
|
|
if (mappers[i].setup_from_caps_func)
|
|
|
|
ret = mappers[i].setup_from_caps_func (pad, caps);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
GST_DEBUG ("got stream type %" GST_PTR_FORMAT, pad->caps);
|
|
|
|
pad->map = i;
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("mapper '%s' did not accept caps %" GST_PTR_FORMAT,
|
|
|
|
mappers[i].media_type, caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-15 12:36:39 +00:00
|
|
|
gboolean
|
|
|
|
gst_ogg_stream_setup_map_from_caps_headers (GstOggStream * pad,
|
|
|
|
const GstCaps * caps)
|
|
|
|
{
|
2011-04-16 14:14:26 +00:00
|
|
|
GstBuffer *buf;
|
2011-04-15 12:36:39 +00:00
|
|
|
const GstStructure *structure;
|
|
|
|
const GValue *streamheader;
|
|
|
|
const GValue *first_element;
|
|
|
|
ogg_packet packet;
|
2012-01-20 15:11:54 +00:00
|
|
|
GstMapInfo map;
|
2011-04-16 14:14:26 +00:00
|
|
|
gboolean ret;
|
2011-04-15 12:36:39 +00:00
|
|
|
|
|
|
|
GST_INFO ("Checking streamheader on caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
streamheader = gst_structure_get_value (structure, "streamheader");
|
|
|
|
|
|
|
|
if (streamheader == NULL) {
|
|
|
|
GST_LOG ("no streamheader field in caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GST_VALUE_HOLDS_ARRAY (streamheader)) {
|
|
|
|
GST_ERROR ("streamheader field not an array, caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_value_array_get_size (streamheader) == 0) {
|
|
|
|
GST_ERROR ("empty streamheader field in caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
first_element = gst_value_array_get_value (streamheader, 0);
|
|
|
|
|
|
|
|
if (!GST_VALUE_HOLDS_BUFFER (first_element)) {
|
|
|
|
GST_ERROR ("first streamheader not a buffer, caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = gst_value_get_buffer (first_element);
|
2011-04-16 14:14:26 +00:00
|
|
|
if (buf == NULL) {
|
|
|
|
GST_ERROR ("no first streamheader buffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
if (!gst_buffer_map (buf, &map, GST_MAP_READ) || map.size == 0) {
|
2011-04-15 12:36:39 +00:00
|
|
|
GST_ERROR ("invalid first streamheader buffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
GST_MEMDUMP ("streamheader", map.data, map.size);
|
2011-04-15 12:36:39 +00:00
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
packet.packet = map.data;
|
|
|
|
packet.bytes = map.size;
|
2011-04-15 12:36:39 +00:00
|
|
|
|
|
|
|
GST_INFO ("Found headers on caps, using those to determine type");
|
2011-04-16 14:14:26 +00:00
|
|
|
ret = gst_ogg_stream_setup_map (pad, &packet);
|
|
|
|
|
2012-01-20 15:11:54 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
2011-04-16 14:14:26 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-04-15 12:36:39 +00:00
|
|
|
}
|