summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio_dec/xine_dts_decoder.c6
-rw-r--r--src/audio_dec/xine_musepack_decoder.c8
-rw-r--r--src/combined/ffmpeg/ff_audio_decoder.c370
-rw-r--r--src/combined/ffmpeg/ff_video_decoder.c21
-rw-r--r--src/demuxers/demux_ts.c26
5 files changed, 237 insertions, 194 deletions
diff --git a/src/audio_dec/xine_dts_decoder.c b/src/audio_dec/xine_dts_decoder.c
index 2f4039696..ffacf4a94 100644
--- a/src/audio_dec/xine_dts_decoder.c
+++ b/src/audio_dec/xine_dts_decoder.c
@@ -136,7 +136,7 @@ static inline void mute_channel (int16_t *const s16, const int num_channels) {
s16[i] = 0;
}
-static void dts_decode_frame (dts_decoder_t *this, const int64_t pts, const int preview_mode) {
+static void dts_decode_frame (dts_decoder_t *this, const int64_t pts) {
audio_buffer_t *audio_buffer;
uint32_t ac5_spdif_type=0;
@@ -441,9 +441,9 @@ static void dts_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
case 3: /* Ready for decode */
#if 0
- dtsdec_decode_frame (this, this->pts_list[0], buf->decoder_flags & BUF_FLAG_PREVIEW);
+ dtsdec_decode_frame (this, this->pts_list[0]);
#else
- dts_decode_frame (this, this->pts, buf->decoder_flags & BUF_FLAG_PREVIEW);
+ dts_decode_frame (this, this->pts);
#endif
case 4: /* Clear up ready for next frame */
this->pts = 0;
diff --git a/src/audio_dec/xine_musepack_decoder.c b/src/audio_dec/xine_musepack_decoder.c
index 93991832a..84aee9387 100644
--- a/src/audio_dec/xine_musepack_decoder.c
+++ b/src/audio_dec/xine_musepack_decoder.c
@@ -348,11 +348,11 @@ static void mpc_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
this->bits_per_sample,
this->sample_rate,
_x_ao_channels2mode(this->channels));
- }
- /* if the audio still isn't open, do not go any further with the decode */
- if (!this->output_open)
- return;
+ /* if the audio still isn't open, do not go any further with the decode */
+ if (!this->output_open)
+ return;
+ }
/* If we run out of space in our internal buffer we discard what's
* already been read */
diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c
index f2d1ca93f..7c293c100 100644
--- a/src/combined/ffmpeg/ff_audio_decoder.c
+++ b/src/combined/ffmpeg/ff_audio_decoder.c
@@ -84,7 +84,7 @@ typedef struct ff_audio_decoder_s {
#define free16(p) realloc16(p,0)
static void *realloc16 (void *m, size_t s) {
- unsigned int diff, diff2;
+ unsigned long diff, diff2;
unsigned char *p = m, *q;
if (p) {
diff = p[-1];
@@ -94,13 +94,13 @@ static void *realloc16 (void *m, size_t s) {
}
q = realloc (p - diff, s + 16);
if (!q) return (q);
- diff2 = 16 - ((unsigned int)q & 15);
+ diff2 = 16 - ((unsigned long)q & 15);
if (diff2 != diff) memmove (q + diff2, q + diff, s);
} else {
if (s == 0) return (NULL);
q = malloc (s + 16);
if (!q) return (q);
- diff2 = 16 - ((unsigned int)q & 15);
+ diff2 = 16 - ((unsigned long)q & 15);
}
q += diff2;
q[-1] = diff2;
@@ -108,7 +108,7 @@ static void *realloc16 (void *m, size_t s) {
}
- static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) {
+static void ff_audio_ensure_buffer_size(ff_audio_decoder_t *this, int size) {
if (size > this->bufsize) {
this->bufsize = size + size / 2;
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
@@ -118,197 +118,228 @@ static void *realloc16 (void *m, size_t s) {
}
}
-static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
+static void ff_audio_handle_special_buffer(ff_audio_decoder_t *this, buf_element_t *buf) {
- ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen;
- int bytes_consumed;
- int decode_buffer_size;
- int offset;
- int out;
- audio_buffer_t *audio_buffer;
- int bytes_to_send;
- unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK);
+ if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM) {
- if ( (buf->decoder_flags & (BUF_FLAG_HEADER | BUF_FLAG_SPECIAL)) == BUF_FLAG_HEADER ) {
+ this->context->extradata_size = buf->decoder_info[2];
+ this->context->extradata = malloc(buf->decoder_info[2] +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ memcpy(this->context->extradata, buf->decoder_info_ptr[2],
+ buf->decoder_info[2]);
+ }
+}
- /* accumulate init data */
- ff_audio_ensure_buffer_size(this, this->size + buf->size);
- xine_fast_memcpy(this->buf + this->size, buf->content, buf->size);
- this->size += buf->size;
+static void ff_audio_init_codec(ff_audio_decoder_t *this, unsigned int codec_type) {
+ size_t i;
+
+ this->codec = NULL;
+
+ for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++)
+ if(ff_audio_lookup[i].type == codec_type) {
+ pthread_mutex_lock (&ffmpeg_lock);
+ this->codec = avcodec_find_decoder(ff_audio_lookup[i].id);
+ pthread_mutex_unlock (&ffmpeg_lock);
+ _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC,
+ ff_audio_lookup[i].name);
+ break;
+ }
- if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
- size_t i;
- xine_waveformatex *audio_header;
+ if (!this->codec) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
+ _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"),
+ codec_type);
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return;
+ }
- this->codec = NULL;
+ /* Current ffmpeg audio decoders usually use 16 bits/sample
+ * buf->decoder_info[2] can't be used as it doesn't refer to the output
+ * bits/sample for some codecs (e.g. MS ADPCM) */
+ this->audio_bits = 16;
+
+ this->context->bits_per_sample = this->audio_bits;
+ this->context->sample_rate = this->audio_sample_rate;
+ this->context->channels = this->audio_channels;
+ this->context->codec_id = this->codec->id;
+ this->context->codec_type = this->codec->type;
+ this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC);
+}
- for(i = 0; i < sizeof(ff_audio_lookup)/sizeof(ff_codec_t); i++)
- if(ff_audio_lookup[i].type == codec_type) {
- pthread_mutex_lock (&ffmpeg_lock);
- this->codec = avcodec_find_decoder(ff_audio_lookup[i].id);
- pthread_mutex_unlock (&ffmpeg_lock);
- _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC,
- ff_audio_lookup[i].name);
- break;
- }
+static int ff_audio_open_codec(ff_audio_decoder_t *this, unsigned int codec_type) {
- if (!this->codec) {
- xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
- _("ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"),
- codec_type);
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
- return;
- }
+ if ( !this->codec ) {
+ ff_audio_init_codec(this, codec_type);
+ }
+
+ if ( !this->codec ) {
+ xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
+ _("ffmpeg_audio_dec: trying to open null codec\n"));
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return -1;
+ }
- this->context = avcodec_alloc_context();
+ pthread_mutex_lock (&ffmpeg_lock);
+ if (avcodec_open (this->context, this->codec) < 0) {
+ pthread_mutex_unlock (&ffmpeg_lock);
+ xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
+ _("ffmpeg_audio_dec: couldn't open decoder\n"));
+ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ return -1;
+ }
+ pthread_mutex_unlock (&ffmpeg_lock);
- if(buf->decoder_flags & BUF_FLAG_STDHEADER) {
- this->audio_sample_rate = buf->decoder_info[1];
- this->audio_channels = buf->decoder_info[3];
+ this->decoder_ok = 1;
- if(this->size) {
- audio_header = (xine_waveformatex *)this->buf;
+ return 1;
+}
- this->context->block_align = audio_header->nBlockAlign;
- this->context->bit_rate = audio_header->nAvgBytesPerSec * 8;
+static void ff_handle_header_buffer(ff_audio_decoder_t *this, buf_element_t *buf)
+{
+ unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK);
+ xine_waveformatex *audio_header;
- if(audio_header->cbSize > 0) {
- this->context->extradata = malloc(audio_header->cbSize);
- this->context->extradata_size = audio_header->cbSize;
- memcpy( this->context->extradata,
- (uint8_t *)audio_header + sizeof(xine_waveformatex),
- audio_header->cbSize );
- }
- }
- } else {
- short *ptr;
-
- switch(codec_type) {
- case BUF_AUDIO_14_4:
- this->audio_sample_rate = 8000;
- this->audio_channels = 1;
-
- this->context->block_align = 240;
- break;
- case BUF_AUDIO_28_8:
- this->audio_sample_rate = _X_BE_16(&this->buf[0x30]);
- this->audio_channels = this->buf[0x37];
- /* this->audio_bits = buf->content[0x35] */
-
- this->context->block_align = _X_BE_32(&this->buf[0x18]);
-
- this->context->extradata_size = 5*sizeof(short);
- this->context->extradata = malloc(this->context->extradata_size);
-
- ptr = (short *) this->context->extradata;
-
- ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */
- ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */
- ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */
- ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */
- ptr[4] = 0; /* codec's data length */
-
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- "ffmpeg_audio_dec: 28_8 audio channels %d bits %d sample rate %d block align %d\n",
- this->audio_channels, this->audio_bits, this->audio_sample_rate,
- this->context->block_align);
- break;
- case BUF_AUDIO_COOK:
- {
- int version;
- int data_len;
- int extradata;
-
- version = _X_BE_16 (this->buf+4);
- if (version == 4) {
- this->audio_sample_rate = _X_BE_16 (this->buf+48);
- this->audio_bits = _X_BE_16 (this->buf+52);
- this->audio_channels = _X_BE_16 (this->buf+54);
- data_len = _X_BE_32 (this->buf+67);
- extradata = 71;
- } else {
- this->audio_sample_rate = _X_BE_16 (this->buf+54);
- this->audio_bits = _X_BE_16 (this->buf+58);
- this->audio_channels = _X_BE_16 (this->buf+60);
- data_len = _X_BE_32 (this->buf+74);
- extradata = 78;
- }
- this->context->block_align = _X_BE_16 (this->buf+44);
-
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- "ffmpeg_audio_dec: cook audio channels %d bits %d sample rate %d block align %d\n",
- this->audio_channels, this->audio_bits, this->audio_sample_rate,
- this->context->block_align);
-
- if (extradata + data_len > this->size)
- break; /* abort early - extradata length is bad */
- if (extradata > INT_MAX - data_len)
- break;/*integer overflow*/
-
- this->context->extradata_size = data_len;
- this->context->extradata = malloc(this->context->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- xine_fast_memcpy (this->context->extradata, this->buf + extradata,
- this->context->extradata_size);
- break;
- }
- default:
- xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
- "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type);
- break;
+ /* accumulate init data */
+ ff_audio_ensure_buffer_size(this, this->size + buf->size);
+ xine_fast_memcpy(this->buf + this->size, buf->content, buf->size);
+ this->size += buf->size;
+
+ if (!(buf->decoder_flags & BUF_FLAG_FRAME_END)) {
+ return;
+ }
+
+ if(buf->decoder_flags & BUF_FLAG_STDHEADER) {
+ this->audio_sample_rate = buf->decoder_info[1];
+ this->audio_channels = buf->decoder_info[3];
+
+ if(this->size) {
+ audio_header = (xine_waveformatex *)this->buf;
+
+ this->context->block_align = audio_header->nBlockAlign;
+ this->context->bit_rate = audio_header->nAvgBytesPerSec * 8;
+
+ if(audio_header->cbSize > 0) {
+ this->context->extradata = malloc(audio_header->cbSize);
+ this->context->extradata_size = audio_header->cbSize;
+ memcpy( this->context->extradata,
+ (uint8_t *)audio_header + sizeof(xine_waveformatex),
+ audio_header->cbSize );
+ }
+ }
+ } else {
+ short *ptr;
+
+ switch(codec_type) {
+ case BUF_AUDIO_14_4:
+ this->audio_sample_rate = 8000;
+ this->audio_channels = 1;
+
+ this->context->block_align = 240;
+ break;
+ case BUF_AUDIO_28_8:
+ this->audio_sample_rate = _X_BE_16(&this->buf[0x30]);
+ this->audio_channels = this->buf[0x37];
+ /* this->audio_bits = buf->content[0x35] */
+
+ this->context->block_align = _X_BE_32(&this->buf[0x18]);
+
+ this->context->extradata_size = 5*sizeof(short);
+ this->context->extradata = malloc(this->context->extradata_size);
+
+ ptr = (short *) this->context->extradata;
+
+ ptr[0] = _X_BE_16(&this->buf[0x2C]); /* subpacket size */
+ ptr[1] = _X_BE_16(&this->buf[0x28]); /* subpacket height */
+ ptr[2] = _X_BE_16(&this->buf[0x16]); /* subpacket flavour */
+ ptr[3] = _X_BE_32(&this->buf[0x18]); /* coded frame size */
+ ptr[4] = 0; /* codec's data length */
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "ffmpeg_audio_dec: 28_8 audio channels %d bits %d sample rate %d block align %d\n",
+ this->audio_channels, this->audio_bits, this->audio_sample_rate,
+ this->context->block_align);
+ break;
+ case BUF_AUDIO_COOK:
+ {
+ int version;
+ int data_len;
+ int extradata;
+
+ version = _X_BE_16 (this->buf+4);
+ if (version == 4) {
+ this->audio_sample_rate = _X_BE_16 (this->buf+48);
+ this->audio_bits = _X_BE_16 (this->buf+52);
+ this->audio_channels = _X_BE_16 (this->buf+54);
+ data_len = _X_BE_32 (this->buf+67);
+ extradata = 71;
+ } else {
+ this->audio_sample_rate = _X_BE_16 (this->buf+54);
+ this->audio_bits = _X_BE_16 (this->buf+58);
+ this->audio_channels = _X_BE_16 (this->buf+60);
+ data_len = _X_BE_32 (this->buf+74);
+ extradata = 78;
}
+ this->context->block_align = _X_BE_16 (this->buf+44);
+
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "ffmpeg_audio_dec: cook audio channels %d bits %d sample rate %d block align %d\n",
+ this->audio_channels, this->audio_bits, this->audio_sample_rate,
+ this->context->block_align);
+
+ if (extradata + data_len > this->size)
+ break; /* abort early - extradata length is bad */
+ if (extradata > INT_MAX - data_len)
+ break;/*integer overflow*/
+
+ this->context->extradata_size = data_len;
+ this->context->extradata = malloc(this->context->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+ xine_fast_memcpy (this->context->extradata, this->buf + extradata,
+ this->context->extradata_size);
+ break;
}
+ default:
+ xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+ "ffmpeg_audio_dec: unknown header with buf type 0x%X\n", codec_type);
+ break;
+ }
+ }
- /* Current ffmpeg audio decoders usually use 16 bits/sample
- * buf->decoder_info[2] can't be used as it doesn't refer to the output
- * bits/sample for some codecs (e.g. MS ADPCM) */
- this->audio_bits = 16;
+ ff_audio_init_codec(this, codec_type);
- this->context->bits_per_sample = this->audio_bits;
- this->context->sample_rate = this->audio_sample_rate;
- this->context->channels = this->audio_channels;
- this->context->codec_id = this->codec->id;
- this->context->codec_type = this->codec->type;
- this->context->codec_tag = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC);
+ this->size = 0;
+}
- this->size = 0;
+static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
- this->decode_buffer = malloc16 (AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen;
+ int bytes_consumed;
+ int decode_buffer_size;
+ int offset;
+ int out;
+ audio_buffer_t *audio_buffer;
+ int bytes_to_send;
+ unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK);
- return;
- }
- } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) &&
- (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM)) {
+ if (buf->decoder_flags & BUF_FLAG_SPECIAL) {
+ ff_audio_handle_special_buffer(this, buf);
+ return;
+ }
- this->context->extradata_size = buf->decoder_info[2];
- this->context->extradata = malloc(buf->decoder_info[2] +
- FF_INPUT_BUFFER_PADDING_SIZE);
- memcpy(this->context->extradata, buf->decoder_info_ptr[2],
- buf->decoder_info[2]);
+ if (buf->decoder_flags & BUF_FLAG_HEADER) {
+ ff_handle_header_buffer(this, buf);
+ return;
+
+ } else {
- } else if (!(buf->decoder_flags & BUF_FLAG_SPECIAL)) {
#if AVAUDIO > 2
AVPacket avpkt;
#endif
if( !this->decoder_ok ) {
- if ( ! this->context || ! this->codec ) {
- xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
- _("ffmpeg_audio_dec: trying to open null codec\n"));
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+ if (ff_audio_open_codec(this, codec_type) < 0) {
return;
}
-
- pthread_mutex_lock (&ffmpeg_lock);
- if (avcodec_open (this->context, this->codec) < 0) {
- pthread_mutex_unlock (&ffmpeg_lock);
- xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
- _("ffmpeg_audio_dec: couldn't open decoder\n"));
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
- return;
- }
- pthread_mutex_unlock (&ffmpeg_lock);
- this->decoder_ok = 1;
}
if( buf->decoder_flags & BUF_FLAG_PREVIEW )
@@ -468,7 +499,7 @@ static void ff_audio_reset (audio_decoder_t *this_gen) {
this->size = 0;
/* try to reset the wma decoder */
- if( this->context && this->decoder_ok ) {
+ if( this->decoder_ok ) {
pthread_mutex_lock (&ffmpeg_lock);
avcodec_close (this->context);
if (avcodec_open (this->context, this->codec) < 0)
@@ -527,6 +558,9 @@ static audio_decoder_t *ff_audio_open_plugin (audio_decoder_class_t *class_gen,
ff_audio_ensure_buffer_size(this, AUDIOBUFSIZE);
+ this->context = avcodec_alloc_context();
+ this->decode_buffer = malloc16 (AVCODEC_MAX_AUDIO_FRAME_SIZE);
+
return &this->audio_decoder;
}
diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c
index 03a4b8cac..c75848bee 100644
--- a/src/combined/ffmpeg/ff_video_decoder.c
+++ b/src/combined/ffmpeg/ff_video_decoder.c
@@ -510,17 +510,6 @@ static void init_postprocess (ff_video_decoder_t *this) {
static int ff_handle_mpeg_sequence(ff_video_decoder_t *this, mpeg_parser_t *parser) {
- /*
- * init codec
- */
- if (this->decoder_init_mode) {
- _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC,
- "mpeg-1 (ffmpeg)");
-
- init_video_codec (this, BUF_VIDEO_MPEG);
- this->decoder_init_mode = 0;
- }
-
/* frame format change */
if ((parser->width != this->bih.biWidth) ||
(parser->height != this->bih.biHeight) ||
@@ -897,10 +886,18 @@ static int ff_check_extradata(ff_video_decoder_t *this, unsigned int codec_type,
static void ff_init_mpeg12_mode(ff_video_decoder_t *this)
{
this->is_mpeg12 = 1;
+
+ if (this->decoder_init_mode) {
+ _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC,
+ "mpeg-1 (ffmpeg)");
+
+ init_video_codec (this, BUF_VIDEO_MPEG);
+ this->decoder_init_mode = 0;
+ }
+
if ( this->mpeg_parser == NULL ) {
this->mpeg_parser = calloc(1, sizeof(mpeg_parser_t));
mpeg_parser_init(this->mpeg_parser);
- this->decoder_init_mode = 0;
}
}
diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c
index 74840885d..ff75c3282 100644
--- a/src/demuxers/demux_ts.c
+++ b/src/demuxers/demux_ts.c
@@ -1784,11 +1784,14 @@ static unsigned char * demux_synchronise(demux_ts_t* this) {
static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
uint32_t adaptation_field_length) {
+#ifdef TS_LOG
uint32_t discontinuity_indicator=0;
uint32_t random_access_indicator=0;
uint32_t elementary_stream_priority_indicator=0;
+#endif
uint32_t PCR_flag=0;
- int64_t PCR=0;
+ int64_t PCR=-1;
+#ifdef TS_LOG
uint32_t EPCR=0;
uint32_t OPCR_flag=0;
uint32_t OPCR=0;
@@ -1796,16 +1799,21 @@ static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
uint32_t slicing_point_flag=0;
uint32_t transport_private_data_flag=0;
uint32_t adaptation_field_extension_flag=0;
+#endif
uint32_t offset = 1;
+#ifdef TS_LOG
discontinuity_indicator = ((data[0] >> 7) & 0x01);
random_access_indicator = ((data[0] >> 6) & 0x01);
elementary_stream_priority_indicator = ((data[0] >> 5) & 0x01);
+#endif
PCR_flag = ((data[0] >> 4) & 0x01);
+#ifdef TS_LOG
OPCR_flag = ((data[0] >> 3) & 0x01);
slicing_point_flag = ((data[0] >> 2) & 0x01);
transport_private_data_flag = ((data[0] >> 1) & 0x01);
adaptation_field_extension_flag = (data[0] & 0x01);
+#endif
#ifdef TS_LOG
printf ("demux_ts: ADAPTATION FIELD length: %d (%x)\n",
@@ -1823,9 +1831,10 @@ static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
elementary_stream_priority_indicator);
}
#endif
+
if(PCR_flag) {
if (adaptation_field_length < offset + 6)
- return 0;
+ return -1;
PCR = (((int64_t) data[offset]) & 0xFF) << 25;
PCR += (int64_t) ((data[offset+1] & 0xFF) << 17);
@@ -1833,13 +1842,15 @@ static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
PCR += (int64_t) ((data[offset+3] & 0xFF) << 1);
PCR += (int64_t) ((data[offset+4] & 0x80) >> 7);
- EPCR = ((data[offset+4] & 0x1) << 8) | data[offset+5];
#ifdef TS_LOG
+ EPCR = ((data[offset+4] & 0x1) << 8) | data[offset+5];
printf ("demux_ts: PCR: %lld, EPCR: %u\n",
PCR, EPCR);
#endif
offset+=6;
}
+
+#ifdef TS_LOG
if(OPCR_flag) {
if (adaptation_field_length < offset + 6)
return PCR;
@@ -1850,13 +1861,13 @@ static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
OPCR |= data[offset+3] << 1;
OPCR |= (data[offset+4] >> 7) & 0x01;
EOPCR = ((data[offset+4] & 0x1) << 8) | data[offset+5];
-#ifdef TS_LOG
+
printf ("demux_ts: OPCR: %u, EOPCR: %u\n",
OPCR,EOPCR);
-#endif
+
offset+=6;
}
-#ifdef TS_LOG
+
if(slicing_point_flag) {
printf ("demux_ts: slicing_point_flag: %d\n",
slicing_point_flag);
@@ -1869,7 +1880,8 @@ static int64_t demux_ts_adaptation_field_parse(uint8_t *data,
printf ("demux_ts: adaptation_field_extension_flag: %d\n",
adaptation_field_extension_flag);
}
-#endif
+#endif /* TS_LOG */
+
return PCR;
}