summaryrefslogtreecommitdiff
path: root/src/demuxers/demux_ts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers/demux_ts.c')
-rw-r--r--src/demuxers/demux_ts.c154
1 files changed, 46 insertions, 108 deletions
diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c
index 1a19340f3..8c8250cf4 100644
--- a/src/demuxers/demux_ts.c
+++ b/src/demuxers/demux_ts.c
@@ -146,6 +146,13 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <arpa/inet.h>
+
+#ifdef HAVE_FFMPEG_AVUTIL_H
+# include <crc.h>
+#else
+# include <libavutil/crc.h>
+#endif
#define LOG_MODULE "demux_ts"
#define LOG_VERBOSE
@@ -153,9 +160,9 @@
#define LOG
*/
-#include "xine_internal.h"
-#include "xineutils.h"
-#include "demux.h"
+#include <xine/xine_internal.h>
+#include <xine/xineutils.h>
+#include <xine/demux.h>
/*
#define TS_LOG
@@ -297,6 +304,18 @@ typedef struct {
} demux_ts_audio_track;
typedef struct {
+
+ demux_class_t demux_class;
+
+ /* class-wide, global variables here */
+
+ xine_t *xine;
+ config_values_t *config;
+
+ const AVCRC *av_crc;
+} demux_ts_class_t;
+
+typedef struct {
/*
* The first field must be the "base class" for the plugin!
*/
@@ -311,6 +330,8 @@ typedef struct {
input_plugin_t *input;
+ demux_ts_class_t *class;
+
int status;
int hdmv; /* -1 = unknown, 0 = mpeg-ts, 1 = hdmv/m2ts */
@@ -325,7 +346,6 @@ typedef struct {
uint32_t pmt_pid[MAX_PMTS];
uint8_t *pmt[MAX_PMTS];
uint8_t *pmt_write_ptr[MAX_PMTS];
- uint32_t crc32_table[256];
uint32_t last_pmt_crc;
/*
* Stuff to do with the transport header. As well as the video
@@ -374,39 +394,6 @@ typedef struct {
} demux_ts_t;
-typedef struct {
-
- demux_class_t demux_class;
-
- /* class-wide, global variables here */
-
- xine_t *xine;
- config_values_t *config;
-} demux_ts_class_t;
-
-
-static void demux_ts_build_crc32_table(demux_ts_t*this) {
- uint32_t i, j, k;
-
- for( i = 0 ; i < 256 ; i++ ) {
- k = 0;
- for (j = (i << 24) | 0x800000 ; j != 0x80000000 ; j <<= 1) {
- k = (k << 1) ^ (((k ^ j) & 0x80000000) ? 0x04c11db7 : 0);
- }
- this->crc32_table[i] = k;
- }
-}
-
-static uint32_t demux_ts_compute_crc32(demux_ts_t*this, uint8_t *data,
- int32_t length, uint32_t crc32) {
- int32_t i;
-
- for(i = 0; i < length; i++) {
- crc32 = (crc32 << 8) ^ this->crc32_table[(crc32 >> 24) ^ data[i]];
- }
- return crc32;
-}
-
/* redefine abs as macro to handle 64-bit diffs.
i guess llabs may not be available everywhere */
#define abs(x) ( ((x)<0) ? -(x) : (x) )
@@ -629,8 +616,7 @@ static void demux_ts_parse_pat (demux_ts_t*this, unsigned char *original_pkt,
}
/* Check CRC. */
- calc_crc32 = demux_ts_compute_crc32 (this, pkt+5, section_length+3-4,
- 0xffffffff);
+ calc_crc32 = htonl(av_crc(this->class->av_crc, 0xffffffff, pkt+5, section_length+3-4));
if (crc32 != calc_crc32) {
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
"demux_ts: demux error! PAT with invalid CRC32: packet_crc32: %.8x calc_crc32: %.8x\n",
@@ -1176,7 +1162,7 @@ static void demux_ts_parse_pmt (demux_ts_t *this,
unsigned char *stream;
unsigned int i;
int count;
- char *ptr = NULL;
+ uint8_t *ptr = NULL;
unsigned char len;
unsigned int offset=0;
@@ -1292,9 +1278,9 @@ printf("Program Number is %i, looking for %i\n",program_number,this->program_num
crc32 |= (uint32_t) this->pmt[program_count][section_length+3-1] ;
/* Check CRC. */
- calc_crc32 = demux_ts_compute_crc32 (this,
- this->pmt[program_count],
- section_length+3-4, 0xffffffff);
+ calc_crc32 = htonl(av_crc(this->class->av_crc, 0xffffffff,
+ this->pmt[program_count], section_length+3-4));
+
if (crc32 != calc_crc32) {
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
"demux_ts: demux error! PMT with invalid CRC32: packet_crc32: %#.8x calc_crc32: %#.8x\n",
@@ -2196,8 +2182,6 @@ static void demux_ts_send_headers (demux_plugin_t *this_gen) {
this->send_newpts = 1;
- demux_ts_build_crc32_table (this);
-
this->status = DEMUX_OK ;
this->send_end_buffers = 1;
@@ -2355,6 +2339,8 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
case METHOD_BY_CONTENT: {
uint8_t buf[2069];
+ int i, j;
+ int try_again, ts_detected;
if (!_x_demux_read_header(input, buf, sizeof(buf)))
return NULL;
@@ -2368,39 +2354,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
}
break;
- case METHOD_BY_EXTENSION: {
- const char *const mrl = input->get_mrl (input);
-
- if (_x_demux_check_extension (mrl, "m2ts mts"))
- hdmv = 1;
- else
- hdmv = 0;
-
- /* check extension */
- const char *const extensions = class_gen->get_extensions (class_gen);
-
- if (_x_demux_check_extension (mrl, extensions))
- break;
-
- /* accept dvb streams */
- /*
- * Also handle the special dvbs,dvbt and dvbc mrl formats:
- * the content is exactly the same but the input plugin
- * uses a different tuning algorithm [Pragma]
- */
-
- if (!strncasecmp (mrl, "dvb://", 6))
- break;
- if (!strncasecmp (mrl, "dvbs://", 7))
- break;
- if (!strncasecmp (mrl, "dvbc://", 7))
- break;
- if (!strncasecmp (mrl, "dvbt://", 7))
- break;
-
- return NULL;
- }
-
+ case METHOD_BY_MRL:
case METHOD_EXPLICIT:
break;
@@ -2415,6 +2369,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
this = calloc(1, sizeof(*this));
this->stream = stream;
this->input = input;
+ this->class = class_gen;
this->blockSize = PKT_SIZE;
this->demux_plugin.send_headers = demux_ts_send_headers;
@@ -2475,30 +2430,6 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen,
/*
* ts demuxer class
*/
-
-static const char *get_description (demux_class_t *this_gen) {
- return "MPEG Transport Stream demuxer";
-}
-
-static const char *get_identifier (demux_class_t *this_gen) {
- return "MPEG_TS";
-}
-
-static const char *get_extensions (demux_class_t *this_gen) {
- return "ts m2t trp";
-}
-
-static const char *get_mimetypes (demux_class_t *this_gen) {
- return NULL;
-}
-
-static void class_dispose (demux_class_t *this_gen) {
-
- demux_ts_class_t *this = (demux_ts_class_t *) this_gen;
-
- free (this);
-}
-
static void *init_class (xine_t *xine, void *data) {
demux_ts_class_t *this;
@@ -2508,11 +2439,18 @@ static void *init_class (xine_t *xine, void *data) {
this->xine = xine;
this->demux_class.open_plugin = open_plugin;
- this->demux_class.get_description = get_description;
- this->demux_class.get_identifier = get_identifier;
- this->demux_class.get_mimetypes = get_mimetypes;
- this->demux_class.get_extensions = get_extensions;
- this->demux_class.dispose = class_dispose;
+ this->demux_class.description = N_("MPEG Transport Stream demuxer");
+ this->demux_class.identifier = "MPEG_TS";
+ this->demux_class.mimetypes = NULL;
+
+ /* accept dvb streams; also handle the special dvbs,dvbt and dvbc
+ * mrl formats: the content is exactly the same but the input plugin
+ * uses a different tuning algorithm [Pragma]
+ */
+ this->demux_class.extensions = "ts m2t trp dvb:// dvbs:// dvbc:// dvbt://";
+ this->demux_class.dispose = default_demux_class_dispose;
+
+ this->av_crc = av_crc_get_table(AV_CRC_32_IEEE);
return this;
}
@@ -2527,7 +2465,7 @@ static const demuxer_info_t demux_info_ts = {
const plugin_info_t xine_plugin_info[] EXPORTED = {
/* type, API, "name", version, special_info, init_function */
- { PLUGIN_DEMUX, 26, "mpeg-ts", XINE_VERSION_CODE, &demux_info_ts, init_class },
+ { PLUGIN_DEMUX, 27, "mpeg-ts", XINE_VERSION_CODE, &demux_info_ts, init_class },
{ PLUGIN_NONE, 0, "", 0, NULL, NULL }
};