Skip to content

Commit

Permalink
Merge pull request #28 from christophecvr/experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
christophecvr committed Apr 5, 2016
2 parents ecced1d + d301f9e commit ddda36b
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ if test "$vuplus" = "yes"; then
AC_DEFINE([VUPLUS],[1],[Define to 1 for vuplus ])
fi

AC_ARG_WITH(spark,
AS_HELP_STRING([--with-spark],[build for spark, yes or no]),
[spark=$withval],[spark=no])
if test "$spark" = "yes"; then
AC_DEFINE([SPARK],[1],[Define to 1 for spark ])
fi

AC_ARG_WITH(dreambox,
AS_HELP_STRING([--with-dreambox],[build for dreambox, yes or no]),
[dreambox=$withval],[dreambox=no])
Expand Down
65 changes: 65 additions & 0 deletions gstdvbaudiosink.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#include <config.h>
#endif

#if defined(__sh__) || defined(SPARK)
#include <linux/dvb/stm_ioctls.h>
#endif

#include <gst/gst.h>
#include <gst/audio/audio.h>
#include <gst/base/gstbasesink.h>
Expand Down Expand Up @@ -188,6 +192,36 @@ GST_STATIC_PAD_TEMPLATE(
)
);

#define AUDIO_ENCODING_UNKNOWN 0xFF

unsigned int bypass_to_encoding (unsigned int bypass)
{
#ifdef AUDIO_SET_ENCODING
switch(bypass)
{
case AUDIOTYPE_AC3:
case AUDIOTYPE_AC3_PLUS:
return AUDIO_ENCODING_AC3;
case AUDIOTYPE_MPEG:
return AUDIO_ENCODING_MPEG1;
case AUDIOTYPE_DTS:
return AUDIO_ENCODING_DTS;
case AUDIOTYPE_LPCM:
return AUDIO_ENCODING_LPCMA;
case AUDIOTYPE_MP3:
return AUDIO_ENCODING_MP3;
case AUDIOTYPE_AAC_PLUS:
return AUDIO_ENCODING_AAC;
case AUDIOTYPE_WMA:
case AUDIOTYPE_WMA_PRO:
return AUDIO_ENCODING_WMA;
default:
return AUDIO_ENCODING_UNKNOWN;
}
#endif
return AUDIO_ENCODING_UNKNOWN;
}

static void gst_dvbaudiosink_init(GstDVBAudioSink *self);
static void gst_dvbaudiosink_dispose(GObject *obj);
static void gst_dvbaudiosink_reset(GObject *obj);
Expand Down Expand Up @@ -282,6 +316,11 @@ static void gst_dvbaudiosink_init(GstDVBAudioSink *self)
self->unlockfd[0] = self->unlockfd[1] = -1;
self->rate = 1.0;
self->timestamp = GST_CLOCK_TIME_NONE;
#ifdef AUDIO_SET_ENCODING
self->use_set_encoding = TRUE;
#else
self->use_set_encoding = FALSE;
#endif
#ifdef VUPLUS
gst_base_sink_set_sync(GST_BASE_SINK(self), FALSE);
gst_base_sink_set_async_enabled(GST_BASE_SINK(self), FALSE);
Expand Down Expand Up @@ -720,11 +759,30 @@ static gboolean gst_dvbaudiosink_set_caps(GstBaseSink *basesink, GstCaps *caps)
if (self->fd >= 0) ioctl(self->fd, AUDIO_STOP, 0);
self->playing = FALSE;
}
#ifdef AUDIO_SET_ENCODING
if (self->use_set_encoding)
{
unsigned int encoding = bypass_to_encoding(bypass);
if (self->fd < 0 || ioctl(self->fd, AUDIO_SET_ENCODING, encoding) < 0)
{
GST_ELEMENT_WARNING(self, STREAM, DECODE,(NULL),("hardware decoder can't be set to encoding %i", encoding));
}
}
else
{
if (self->fd < 0 || ioctl(self->fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
{
GST_ELEMENT_ERROR(self, STREAM, TYPE_NOT_FOUND,(NULL),("hardware decoder can't be set to bypass mode type %s", type));
return FALSE;
}
}
#else
if (self->fd < 0 || ioctl(self->fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
{
GST_ELEMENT_ERROR(self, STREAM, TYPE_NOT_FOUND,(NULL),("hardware decoder can't be set to bypass mode type %s", type));
return FALSE;
}
#endif
if (self->fd >= 0) ioctl(self->fd, AUDIO_PLAY);
self->playing = TRUE;

Expand Down Expand Up @@ -779,6 +837,9 @@ static gboolean gst_dvbaudiosink_event(GstBaseSink *sink, GstEvent *event)
{
gboolean pass_eos = FALSE;
struct pollfd pfd[2];
#ifdef AUDIO_FLUSH
if (self->fd >= 0) ioctl(self->fd, AUDIO_FLUSH, 1/*NONBLOCK*/); //Notify the player that no addionional data will be injected
#endif
pfd[0].fd = self->unlockfd[0];
pfd[0].events = POLLIN;
pfd[1].fd = self->fd;
Expand Down Expand Up @@ -916,12 +977,16 @@ static int audio_write(GstDVBAudioSink *self, GstBuffer *buffer, size_t start, s
{
GST_LOG_OBJECT(self, "going into poll, have %d bytes to write", len - written);
}
#if defined(__sh__) && !defined(CHECK_DRAIN)
pfd[1].revents = POLLOUT;
#else
if (poll(pfd, 2, -1) < 0)
{
if (errno == EINTR) continue;
retval = -1;
break;
}
#endif
if (pfd[0].revents & POLLIN)
{
/* read all stop commands */
Expand Down
2 changes: 2 additions & 0 deletions gstdvbaudiosink.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ struct _GstDVBAudioSink
gint64 timestamp_offset;
gint8 ok_to_write;

gboolean use_set_encoding;

queue_entry_t *queue;
};

Expand Down
106 changes: 106 additions & 0 deletions gstdvbvideosink.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#include <config.h>
#endif

#if defined(__sh__) || defined(SPARK)
#include <linux/dvb/stm_ioctls.h>
#endif

#include <gst/gst.h>
#include <gst/base/gstbasesink.h>

Expand Down Expand Up @@ -275,6 +279,42 @@ GST_STATIC_PAD_TEMPLATE (
)
);

#define VIDEO_ENCODING_UNKNOWN 0xFF

unsigned int streamtype_to_encoding(unsigned int streamtype)
{
#ifdef VIDEO_SET_ENCODING
switch(streamtype)
{
case STREAMTYPE_MPEG2:
return VIDEO_ENCODING_AUTO;
case STREAMTYPE_MPEG4_H264:
return VIDEO_ENCODING_H264;
case STREAMTYPE_H263:
return VIDEO_ENCODING_H263;
case STREAMTYPE_MPEG4_Part2:
return VIDEO_ENCODING_MPEG4P2;
case STREAMTYPE_MPEG1:
return VIDEO_ENCODING_AUTO;
case STREAMTYPE_XVID:
return VIDEO_ENCODING_MPEG4P2;
case STREAMTYPE_DIVX311:
return VIDEO_ENCODING_MPEG4P2;
case STREAMTYPE_DIVX4:
return VIDEO_ENCODING_MPEG4P2;
case STREAMTYPE_DIVX5:
return VIDEO_ENCODING_MPEG4P2;
case STREAMTYPE_VC1:
return VIDEO_ENCODING_VC1;
case STREAMTYPE_VC1_SM:
return VIDEO_ENCODING_WMV;
default:
return VIDEO_ENCODING_UNKNOWN;
}
#endif
return VIDEO_ENCODING_UNKNOWN;
}

static void gst_dvbvideosink_init(GstDVBVideoSink *self);
static void gst_dvbvideosink_dispose(GObject *obj);
static void gst_dvbvideosink_reset(GObject *obj);
Expand Down Expand Up @@ -353,6 +393,7 @@ static void gst_dvbvideosink_init(GstDVBVideoSink *self)
{
self->must_send_header = TRUE;
self->h264_nal_len_size = 0;
self->h264_initial_audelim_written = FALSE;
self->pesheader_buffer = NULL;
self->codec_data = NULL;
self->codec_type = CT_H264;
Expand All @@ -373,6 +414,11 @@ static void gst_dvbvideosink_init(GstDVBVideoSink *self)
self->saved_fallback_framerate[0] = 0;
self->rate = 1.0;
self->wmv_asf = FALSE;
#ifdef VIDEO_SET_ENCODING
self->use_set_encoding = TRUE;
#else
self->use_set_encoding = FALSE;
#endif

#ifdef VUPLUS
gst_base_sink_set_sync(GST_BASE_SINK(self), FALSE);
Expand Down Expand Up @@ -510,6 +556,9 @@ static gboolean gst_dvbvideosink_event(GstBaseSink *sink, GstEvent *event)
pfd[1].fd = self->fd;
pfd[1].events = POLLIN;

#ifdef VIDEO_FLUSH
if (self->fd >= 0) ioctl(self->fd, VIDEO_FLUSH, 1/*NONBLOCK*/); //Notify the player that no addionional data will be injected
#endif
GST_BASE_SINK_PREROLL_UNLOCK(sink);
while (1)
{
Expand Down Expand Up @@ -813,6 +862,45 @@ static GstFlowReturn gst_dvbvideosink_render(GstBaseSink *sink, GstBuffer *buffe
codec_data_size = codecdatamap.size;
}

if (self->codec_type == CT_H264 && !self->h264_initial_audelim_written)
{
int i = 0;
while( data[i] == 0 && i != data_len)
{
//GST_DEBUG_OBJECT(self, "data[%d] = %d", i , data[i]);
i++;
}
if (i > 1 && data[i] == 1)
{
int au_type = data[i+1] & 0x1f;
char au_str[64];
switch(au_type)
{
case 1: strcpy(au_str, "SLICE"); break;
case 5: strcpy(au_str, "IDR"); break;
case 6: strcpy(au_str, "SEI"); break;
case 7: strcpy(au_str, "SPS"); break;
case 8: strcpy(au_str, "PPS"); break;
case 9: strcpy(au_str, "AU_DELIM"); break;
default:
strcpy(au_str, "UNK");
break;
}
GST_DEBUG_OBJECT(self, "AU_TYPE = %s [%d]", au_str, au_type);
if (au_type == 9)
{
if (!GST_BUFFER_PTS_IS_VALID(buffer))
{
GST_DEBUG_OBJECT(self, "writing missing pts to AU_DELIM");
GST_BUFFER_PTS(buffer) = 0;
}
self->h264_initial_audelim_written = TRUE;
}
}
else
GST_INFO_OBJECT(self, "data[%d] = %d :(", i, data[i]);
}

#ifdef PACK_UNPACKED_XVID_DIVX5_BITSTREAM
gboolean commit_prev_frame_data = FALSE, cache_prev_frame = FALSE;
#endif
Expand Down Expand Up @@ -1680,10 +1768,28 @@ static gboolean gst_dvbvideosink_set_caps(GstBaseSink *basesink, GstCaps *caps)
if (self->fd >= 0) ioctl(self->fd, VIDEO_STOP, 0);
self->playing = FALSE;
}
#ifdef VIDEO_SET_ENCODING
if (self->use_set_encoding)
{
unsigned int encoding = streamtype_to_encoding(self->stream_type);
if (!self->playing && (self->fd < 0 || ioctl(self->fd, VIDEO_SET_ENCODING, encoding) < 0))
{
GST_ELEMENT_ERROR(self, STREAM, DECODE, (NULL), ("hardware decoder can't be set to encoding %i", encoding));
}
}
else
{
if (!self->playing && (self->fd < 0 || ioctl(self->fd, VIDEO_SET_STREAMTYPE, self->stream_type) < 0))
{
GST_ELEMENT_ERROR(self, STREAM, CODEC_NOT_FOUND, (NULL), ("hardware decoder can't handle streamtype %i", self->stream_type));
}
}
#else
if (!self->playing && (self->fd < 0 || ioctl(self->fd, VIDEO_SET_STREAMTYPE, self->stream_type) < 0))
{
GST_ELEMENT_ERROR(self, STREAM, CODEC_NOT_FOUND, (NULL), ("hardware decoder can't handle streamtype %i", self->stream_type));
}
#endif
if (self->fd >= 0)
{
if (self->codec_type == CT_VC1)
Expand Down
3 changes: 3 additions & 0 deletions gstdvbvideosink.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct _GstDVBVideoSink
int unlockfd[2];

gint h264_nal_len_size;
gboolean h264_initial_audelim_written;

GstBuffer *pesheader_buffer;

Expand Down Expand Up @@ -136,6 +137,8 @@ struct _GstDVBVideoSink
gboolean must_send_header, wmv_asf;
gint8 ok_to_write;

gboolean use_set_encoding;

queue_entry_t *queue;
};

Expand Down

0 comments on commit ddda36b

Please sign in to comment.