diff options
-rw-r--r-- | xine_input_vdr.c | 88 |
1 files changed, 34 insertions, 54 deletions
diff --git a/xine_input_vdr.c b/xine_input_vdr.c index 856c8d25..0cc2b1ed 100644 --- a/xine_input_vdr.c +++ b/xine_input_vdr.c @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: xine_input_vdr.c,v 1.141 2008-06-11 21:32:08 phintuka Exp $ + * $Id: xine_input_vdr.c,v 1.142 2008-06-11 21:45:57 phintuka Exp $ * */ @@ -51,6 +51,7 @@ #include "xine_input_vdr.h" #include "xine_input_vdr_net.h" #include "xine_osd_command.h" +#include "tools/pes.h" /***************************** DEFINES *********************************/ @@ -200,6 +201,12 @@ static void SetupLogLevel(void) # include "tools/debug_mutex.h" #endif +/************************************************************************/ + +#include "tools/pes.c" +#include "tools/mpeg.c" +#include "tools/h264.c" + /******************************* DATA ***********************************/ #define KILOBYTE(x) (1024 * (x)) @@ -914,32 +921,6 @@ static char *unescape_filename(const char *fn) return result; } -static int64_t pts_from_pes(const uint8_t *buf, int size) -{ - int64_t pts = INT64_C(-1); - if(size > 13 && (buf[7] & 0x80)) { /* pts avail */ - pts = ((int64_t)( buf[ 9] & 0x0E)) << 29; - pts |= (int64_t)( buf[10] << 22 ); - pts |= (int64_t)((buf[11] & 0xFE) << 14 ); - pts |= (int64_t)( buf[12] << 7 ); - pts |= (int64_t)((buf[13] & 0xFE) >> 1 ); - } - return pts; -} - -static int64_t dts_from_pes(const uint8_t *buf, int size) -{ - int64_t dts = INT64_C(-1); - if(size > 18 && (buf[7] & 0x40)) { /* dts avail */ - dts = ((int64_t)( buf[14] & 0x0E)) << 29 ; - dts |= (int64_t)( buf[15] << 22 ); - dts |= (int64_t)((buf[16] & 0xFE) << 14 ); - dts |= (int64_t)( buf[17] << 7 ); - dts |= (int64_t)((buf[18] & 0xFE) >> 1 ); - } - return dts; -} - static void pes_strip_pts(uint8_t *buf, int size) { if(size > 13 && buf[7] & 0x80) { /* pts avail */ @@ -1554,7 +1535,7 @@ static void strip_network_headers(vdr_input_plugin_t *this, buf_element_t *buf) static buf_element_t *make_padding_frame(vdr_input_plugin_t *this) { - static const uint8_t padding[] = {0x00,0x00,0x01,0xBE,0x00,0x02,0xff,0xff}; + static const uint8_t padding[] = {0x00,0x00,0x01,PADDING_STREAM,0x00,0x02,0xff,0xff}; buf_element_t *buf; buf = get_buf_element(this, 8, 1); @@ -4837,7 +4818,7 @@ static void track_audio_stream_change(vdr_input_plugin_t *this, buf_element_t *b audio_changed = 1; } } - else if(buf->content[3] == 0xbd) { + else if(buf->content[3] == PRIVATE_STREAM1) { /* PS1 */ int PayloadOffset = buf->content[8] + 9; int SubStreamId = buf->content[PayloadOffset]; @@ -4849,16 +4830,16 @@ static void track_audio_stream_change(vdr_input_plugin_t *this, buf_element_t *b /*LOGMSG("SPU %d", SubStreamId);*/ break; case 0x80: /* AC3 & DTS */ - if(this->prev_audio_stream_id != ((0xbd<<8) | SubStreamId)) { + if(this->prev_audio_stream_id != ((PRIVATE_STREAM1<<8) | SubStreamId)) { LOGDBG("Audio changed -> AC3 %d (BD:%02X)", SubStreamIndex, SubStreamId); - this->prev_audio_stream_id = ((0xbd<<8) | SubStreamId); + this->prev_audio_stream_id = ((PRIVATE_STREAM1<<8) | SubStreamId); audio_changed = 1; } break; case 0xA0: /* LPCM */ - if(this->prev_audio_stream_id != ((0xbd<<8) | SubStreamId)) { + if(this->prev_audio_stream_id != ((PRIVATE_STREAM1<<8) | SubStreamId)) { LOGDBG("Audio changed -> LPCM %d (BD:%02X)", SubStreamIndex, SubStreamId); - this->prev_audio_stream_id = ((0xbd<<8) | SubStreamId); + this->prev_audio_stream_id = ((PRIVATE_STREAM1<<8) | SubStreamId); audio_changed = 1; } break; @@ -4921,12 +4902,11 @@ static void pts_wrap_workaround(vdr_input_plugin_t *this, buf_element_t *buf) { #if 1 /* PTS wrap workaround for mpeg_block demuxer */ - int64_t pts = pts_from_pes(buf->content, buf->size); + int64_t pts = pes_get_pts(buf->content, buf->size); if(pts >= 0) { - int video = ((buf->content[3] & 0xf0) == 0xe0); - if(video) + if (IS_VIDEO_PACKET(buf->content)) this->last_delivered_vid_pts = pts; - if(!video) { + else { if(pts > 0x40400000 && this->last_delivered_vid_pts < 0x40000000 && this->last_delivered_vid_pts > 0) { @@ -4970,9 +4950,9 @@ static int update_frames(vdr_input_plugin_t *this, uint8_t *data, int len) if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 1 && data[i + 3] == 0) { uint8_t type = ((data[i + 5] >> 3) & 0x07); switch (type) { - case 1: this->I_frames++; LOGSCR("I"); break; - case 2: this->P_frames++; LOGSCR("P"); break; - case 3: this->B_frames++; LOGSCR("B"); break; + case I_FRAME: this->I_frames++; LOGSCR("I"); break; + case P_FRAME: this->P_frames++; LOGSCR("P"); break; + case B_FRAME: this->B_frames++; LOGSCR("B"); break; default: return 0; } return type; @@ -5039,7 +5019,7 @@ static int detect_h264(vdr_input_plugin_t *this, uint8_t *data, int len) #ifdef TEST_H264 buf_element_t *post_frame_h264(vdr_input_plugin_t *this, buf_element_t *buf) { - int64_t pts = pts_from_pes (buf->content, buf->size); + int64_t pts = pes_get_pts (buf->content, buf->size); uint8_t *data = buf->content; int i = 8; @@ -5067,17 +5047,17 @@ buf_element_t *post_frame_h264(vdr_input_plugin_t *this, buf_element_t *buf) buf->decoder_info[0] = 0; if (pts >= INT64_C(0)) { - int64_t dts = dts_from_pes (buf->content, buf->size); #if 0 - if (dts < INT64_C(0)) { + if (! PES_HAS_DTS(buf->content)) { buf->decoder_info[0] = pts; } else { + int64_t dts = pes_get_dts (buf->content, buf->size); buf->decoder_info[0] = (pts - dts); buf->decoder_flags |= BUF_FLAG_FRAMERATE; + LOGMSG("H.264: dts %"PRId64" DIFF %d [stream video step %d]", + dts, (int)(pts-dts), + _x_stream_info_get(this->stream, XINE_STREAM_INFO_FRAME_DURATION)); } - LOGMSG("H.264: dts %"PRId64" DIFF %d [stream video step %d]", - dts, (int)(pts-dts), - _x_stream_info_get(this->stream, XINE_STREAM_INFO_FRAME_DURATION)); #endif if (this->send_pts) { LOGMSG("H.264: post pts %"PRId64, pts); @@ -5093,8 +5073,8 @@ buf_element_t *post_frame_h264(vdr_input_plugin_t *this, buf_element_t *buf) if (abs(pts - this->last_delivered_vid_pts) < 90000 && pts < this->last_delivered_vid_pts) { LOGDBG("H.264: -> pts %"PRId64" <- 0", pts); /*buf->pts = 0;*/ - } else if (dts>0) { - LOGDBG("H.264: -> pts %"PRId64" <- 0 (DTS %"PRId64")", pts, dts); + } else if (PES_HAS_DTS(buf->content)) { + LOGDBG("H.264: -> pts %"PRId64" <- 0 (DTS)", pts); /*buf->pts = 0;*/ } else { LOGDBG("H.264: -> pts %"PRId64, pts); @@ -5259,7 +5239,7 @@ static buf_element_t *vdr_plugin_read_block (input_plugin_t *this_gen, } /* ignore UDP/RTP "idle" padding */ - if(buf->content[3] == 0xbe) { + if(buf->content[3] == PADDING_STREAM) { pthread_mutex_unlock(&this->lock); return buf; } @@ -5303,7 +5283,7 @@ static buf_element_t *vdr_plugin_read_block (input_plugin_t *this_gen, /* Send current PTS ? */ if(this->send_pts) { - int64_t pts = pts_from_pes(buf->content, buf->size); + int64_t pts = pes_get_pts(buf->content, buf->size); if(pts > 0) { #ifdef TEST_SCR_PAUSE if(need_pause) @@ -5337,7 +5317,7 @@ static buf_element_t *vdr_plugin_read_block (input_plugin_t *this_gen, if(this->still_mode && buf->size == 14) { /* generated still images start with empty video PES, PTS = 0. Reset metronom pts so images will be displayed */ - int64_t pts = pts_from_pes(buf->content, buf->size); + int64_t pts = pes_get_pts(buf->content, buf->size); if(pts==0) { vdr_x_demux_control_newpts(this->stream, pts, BUF_FLAG_SEEK); /* delay frame 10ms (9000 ticks) */ @@ -5347,11 +5327,11 @@ static buf_element_t *vdr_plugin_read_block (input_plugin_t *this_gen, #ifndef FFMPEG_DEC if(this->live_mode && this->I_frames < 4) - if((buf->content[3] & 0xf0) == 0xe0 && buf->size > 32) + if(IS_VIDEO_PACKET(buf->content) && buf->size > 32) update_frames(this, buf->content, buf->size); #else /* FFMPEG_DEC */ if(this->ffmpeg_video_decoder || (this->live_mode && this->I_frames < 4)) - if((buf->content[3] & 0xf0) == 0xe0 && buf->size > 32) { + if(IS_VIDEO_PACKET(buf->content) && buf->size > 32) { int type = update_frames(this, buf->content, buf->size); if(type && this->ffmpeg_video_decoder) { /* signal FRAME_END to decoder */ @@ -5359,7 +5339,7 @@ static buf_element_t *vdr_plugin_read_block (input_plugin_t *this_gen, /* for some reason ffmpeg mpeg2 decoder does not understand pts'es in B frames ? * (B-frame pts's are smaller than in previous P-frame) * Anyway, without this block of code B frames with pts are dropped. */ - if(type == 3 && pts_from_pes(buf->content, buf->size) > INT64_C(0)) + if(type == B_FRAME && PES_HAS_PTS(buf->content)) pes_strip_pts(buf->content, buf->size); } } |