2009-05-08 21:51:13 +00:00
|
|
|
/*
|
|
|
|
* video frame reading
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-10-30 20:36:20 +00:00
|
|
|
|
2001-11-09 02:17:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
#include <stdio.h>
|
2009-02-17 11:16:19 +00:00
|
|
|
#if HAVE_MALLOC_H
|
2001-11-09 02:17:02 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2001-10-30 20:36:20 +00:00
|
|
|
#include <stdlib.h>
|
2001-12-25 11:20:58 +00:00
|
|
|
#include <string.h>
|
2001-10-30 20:36:20 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2001-10-30 20:36:20 +00:00
|
|
|
#include "demuxer.h"
|
2011-03-24 20:13:13 +00:00
|
|
|
#ifdef DEMUX_TY_OSD
|
2010-02-17 22:48:32 +00:00
|
|
|
#include "demux_ty_osd.h"
|
2011-03-24 20:13:13 +00:00
|
|
|
#endif
|
2001-10-30 20:36:20 +00:00
|
|
|
#include "stheader.h"
|
|
|
|
#include "parse_es.h"
|
|
|
|
#include "mpeg_hdr.h"
|
|
|
|
|
2002-07-25 03:37:28 +00:00
|
|
|
/* sub_cc (closed captions)*/
|
2011-01-26 17:40:52 +00:00
|
|
|
#include "sub/sub_cc.h"
|
2002-07-25 03:37:28 +00:00
|
|
|
|
2002-02-20 22:45:00 +00:00
|
|
|
/* biCompression constant */
|
|
|
|
#define BI_RGB 0L
|
|
|
|
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_LIVE555
|
2003-02-18 22:33:44 +00:00
|
|
|
#include "demux_rtp.h"
|
|
|
|
#endif
|
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
static mp_mpeg_header_t picture;
|
|
|
|
|
2003-01-16 23:40:31 +00:00
|
|
|
static int telecine=0;
|
|
|
|
static float telecine_cnt=-2.5;
|
|
|
|
|
2007-10-27 11:55:16 +00:00
|
|
|
typedef enum {
|
2007-10-27 12:33:56 +00:00
|
|
|
VIDEO_MPEG12,
|
|
|
|
VIDEO_MPEG4,
|
|
|
|
VIDEO_H264,
|
|
|
|
VIDEO_VC1,
|
|
|
|
VIDEO_OTHER
|
2007-10-27 11:55:16 +00:00
|
|
|
} video_codec_t;
|
|
|
|
|
|
|
|
static video_codec_t find_video_codec(sh_video_t *sh_video)
|
|
|
|
{
|
|
|
|
demux_stream_t *d_video=sh_video->ds;
|
|
|
|
int fmt = d_video->demuxer->file_format;
|
|
|
|
|
|
|
|
if(
|
|
|
|
(fmt == DEMUXER_TYPE_PVA) ||
|
|
|
|
(fmt == DEMUXER_TYPE_MPEG_ES) ||
|
|
|
|
(fmt == DEMUXER_TYPE_MPEG_GXF) ||
|
|
|
|
(fmt == DEMUXER_TYPE_MPEG_PES) ||
|
|
|
|
(
|
|
|
|
(fmt == DEMUXER_TYPE_MPEG_PS || fmt == DEMUXER_TYPE_MPEG_TS) &&
|
|
|
|
((! sh_video->format) || (sh_video->format==0x10000001) || (sh_video->format==0x10000002))
|
|
|
|
) ||
|
|
|
|
(fmt == DEMUXER_TYPE_MPEG_TY)
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_LIVE555
|
2007-10-27 11:55:16 +00:00
|
|
|
|| ((fmt == DEMUXER_TYPE_RTP) && demux_is_mpeg_rtp_stream(d_video->demuxer))
|
2004-11-24 18:55:03 +00:00
|
|
|
#endif
|
|
|
|
)
|
2007-10-27 11:55:16 +00:00
|
|
|
return VIDEO_MPEG12;
|
|
|
|
else if((fmt == DEMUXER_TYPE_MPEG4_ES) ||
|
|
|
|
((fmt == DEMUXER_TYPE_MPEG_TS) && (sh_video->format==0x10000004)) ||
|
|
|
|
((fmt == DEMUXER_TYPE_MPEG_PS) && (sh_video->format==0x10000004))
|
2004-11-24 18:55:03 +00:00
|
|
|
)
|
2007-10-27 11:55:16 +00:00
|
|
|
return VIDEO_MPEG4;
|
|
|
|
else if((fmt == DEMUXER_TYPE_H264_ES) ||
|
|
|
|
((fmt == DEMUXER_TYPE_MPEG_TS) && (sh_video->format==0x10000005)) ||
|
|
|
|
((fmt == DEMUXER_TYPE_MPEG_PS) && (sh_video->format==0x10000005))
|
2004-11-24 18:55:03 +00:00
|
|
|
)
|
2007-10-27 11:55:16 +00:00
|
|
|
return VIDEO_H264;
|
|
|
|
else if((fmt == DEMUXER_TYPE_MPEG_PS || fmt == DEMUXER_TYPE_MPEG_TS) &&
|
|
|
|
(sh_video->format==mmioFOURCC('W', 'V', 'C', '1')))
|
|
|
|
return VIDEO_VC1;
|
2008-04-05 11:09:21 +00:00
|
|
|
else if (fmt == DEMUXER_TYPE_ASF && sh_video->bih && sh_video->bih->biCompression == mmioFOURCC('D', 'V', 'R', ' '))
|
|
|
|
return VIDEO_MPEG12;
|
2004-11-24 18:55:03 +00:00
|
|
|
else
|
2007-10-27 11:55:16 +00:00
|
|
|
return VIDEO_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
int video_read_properties(sh_video_t *sh_video){
|
|
|
|
demux_stream_t *d_video=sh_video->ds;
|
|
|
|
video_codec_t video_codec = find_video_codec(sh_video);
|
2001-10-30 20:36:20 +00:00
|
|
|
// Determine image properties:
|
2004-11-24 18:55:03 +00:00
|
|
|
switch(video_codec){
|
|
|
|
case VIDEO_OTHER: {
|
|
|
|
if((d_video->demuxer->file_format == DEMUXER_TYPE_ASF) || (d_video->demuxer->file_format == DEMUXER_TYPE_AVI)) {
|
2009-07-06 23:26:13 +00:00
|
|
|
// display info:
|
2007-10-27 12:33:56 +00:00
|
|
|
// in case no strf chunk has been seen in avi, we have no bitmap header
|
|
|
|
if(!sh_video->bih) return 0;
|
|
|
|
sh_video->format=sh_video->bih->biCompression;
|
2001-10-30 20:36:20 +00:00
|
|
|
sh_video->disp_w=sh_video->bih->biWidth;
|
|
|
|
sh_video->disp_h=abs(sh_video->bih->biHeight);
|
2004-11-24 18:55:03 +00:00
|
|
|
}
|
2001-10-30 20:36:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-11-24 18:55:03 +00:00
|
|
|
case VIDEO_MPEG4: {
|
2005-01-12 20:43:53 +00:00
|
|
|
int pos = 0, vop_cnt=0, units[3];
|
2003-01-23 02:12:15 +00:00
|
|
|
videobuf_len=0; videobuf_code_len=0;
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Start code... ");
|
2003-01-23 02:12:15 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(i<=0x11F) break; // found it!
|
|
|
|
if(!i || !skip_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-01-23 02:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
|
2005-12-19 19:38:28 +00:00
|
|
|
if(!videobuffer) {
|
2011-02-04 10:06:01 +00:00
|
|
|
videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
|
2008-07-17 17:14:12 +00:00
|
|
|
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2005-12-19 19:38:28 +00:00
|
|
|
else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
|
2005-12-19 19:38:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-01-23 02:12:15 +00:00
|
|
|
}
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Layer Start code... ");
|
2003-01-23 02:12:15 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
2004-11-24 18:55:03 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"M4V: 0x%X\n",i);
|
2003-01-23 02:12:15 +00:00
|
|
|
if(i>=0x120 && i<=0x12F) break; // found it!
|
|
|
|
if(!i || !read_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-01-23 02:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-12 20:43:53 +00:00
|
|
|
pos = videobuf_len+4;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2005-01-12 20:43:53 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read Video Object Layer Header\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mp4_header_process_vol(&picture, &(videobuffer[pos]));
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK! FPS SEEMS TO BE %.3f\nSearching for Video Object Plane Start code... ", sh_video->fps);
|
2009-07-06 23:26:13 +00:00
|
|
|
mp4_init:
|
2003-01-23 02:12:15 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(i==0x1B6) break; // found it!
|
|
|
|
if(!i || !read_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-01-23 02:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-12 20:43:53 +00:00
|
|
|
pos = videobuf_len+4;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2005-01-12 20:43:53 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read Video Object Plane Header\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mp4_header_process_vop(&picture, &(videobuffer[pos]));
|
2010-03-15 22:32:11 +00:00
|
|
|
sh_video->disp_w = picture.display_picture_width;
|
|
|
|
sh_video->disp_h = picture.display_picture_height;
|
2005-01-12 20:43:53 +00:00
|
|
|
units[vop_cnt] = picture.timeinc_unit;
|
|
|
|
vop_cnt++;
|
|
|
|
//mp_msg(MSGT_DECVIDEO,MSGL_V, "TYPE: %d, unit: %d\n", picture.picture_type, picture.timeinc_unit);
|
|
|
|
if(!picture.fps) {
|
|
|
|
int i, mn, md, mx, diff;
|
|
|
|
if(vop_cnt < 3)
|
|
|
|
goto mp4_init;
|
|
|
|
|
|
|
|
i=0;
|
2009-07-06 23:26:13 +00:00
|
|
|
mn = mx = units[0];
|
2005-01-12 20:43:53 +00:00
|
|
|
for(i=0; i<3; i++) {
|
|
|
|
if(units[i] < mn)
|
|
|
|
mn = units[i];
|
|
|
|
if(units[i] > mx)
|
|
|
|
mx = units[i];
|
|
|
|
}
|
|
|
|
md = mn;
|
|
|
|
for(i=0; i<3; i++) {
|
|
|
|
if((units[i] > mn) && (units[i] < mx))
|
|
|
|
md = units[i];
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V, "MIN: %d, mid: %d, max: %d\n", mn, md, mx);
|
|
|
|
if(mx - md > md - mn)
|
|
|
|
diff = md - mn;
|
|
|
|
else
|
|
|
|
diff = mx - md;
|
|
|
|
if(diff > 0){
|
2005-08-06 16:15:07 +00:00
|
|
|
picture.fps = ((float)picture.timeinc_resolution) / diff;
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V, "FPS seems to be: %f, resolution: %d, delta_units: %d\n", picture.fps, picture.timeinc_resolution, diff);
|
2005-01-12 20:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(picture.fps) {
|
2005-08-06 16:15:07 +00:00
|
|
|
sh_video->fps=picture.fps;
|
|
|
|
sh_video->frametime=1.0/picture.fps;
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO, "FPS seems to be: %f\n", picture.fps);
|
2005-01-12 20:43:53 +00:00
|
|
|
}
|
2003-01-23 02:12:15 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
|
|
|
|
sh_video->format=0x10000004;
|
|
|
|
break;
|
|
|
|
}
|
2004-11-24 18:55:03 +00:00
|
|
|
case VIDEO_H264: {
|
2005-02-24 20:02:41 +00:00
|
|
|
int pos = 0;
|
2003-04-04 15:38:46 +00:00
|
|
|
videobuf_len=0; videobuf_code_len=0;
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence parameter set... ");
|
2003-04-04 15:38:46 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if((i&~0x60) == 0x107 && i != 0x107) break; // found it!
|
|
|
|
if(!i || !skip_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-04-04 15:38:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
|
2005-12-19 19:38:28 +00:00
|
|
|
if(!videobuffer) {
|
2011-02-04 10:06:01 +00:00
|
|
|
videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
|
2008-07-17 17:14:12 +00:00
|
|
|
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2005-12-19 19:38:28 +00:00
|
|
|
else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
|
2005-12-19 19:38:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-04-04 15:38:46 +00:00
|
|
|
}
|
2005-02-24 20:02:41 +00:00
|
|
|
pos = videobuf_len+4;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2005-02-24 20:02:41 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read sequence parameter set\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
h264_parse_sps(&picture, &(videobuffer[pos]), videobuf_len - pos);
|
2009-11-16 21:38:32 +00:00
|
|
|
sh_video->disp_w=picture.display_picture_width;
|
|
|
|
sh_video->disp_h=picture.display_picture_height;
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for picture parameter set... ");
|
2003-04-04 15:38:46 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
2004-11-24 18:55:03 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"H264: 0x%X\n",i);
|
2003-04-04 15:38:46 +00:00
|
|
|
if((i&~0x60) == 0x108 && i != 0x108) break; // found it!
|
|
|
|
if(!i || !read_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-04-04 15:38:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\nSearching for Slice... ");
|
2003-04-04 15:38:46 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105) break; // found it!
|
|
|
|
if(!i || !read_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2003-04-04 15:38:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
|
|
|
|
sh_video->format=0x10000005;
|
2005-02-24 20:02:41 +00:00
|
|
|
if(picture.fps) {
|
2005-08-06 16:15:07 +00:00
|
|
|
sh_video->fps=picture.fps;
|
|
|
|
sh_video->frametime=1.0/picture.fps;
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO, "FPS seems to be: %f\n", picture.fps);
|
2005-02-24 20:02:41 +00:00
|
|
|
}
|
2003-04-04 15:38:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-11-24 18:55:03 +00:00
|
|
|
case VIDEO_MPEG12: {
|
2008-04-05 11:09:21 +00:00
|
|
|
if (d_video->demuxer->file_format == DEMUXER_TYPE_ASF) { // DVR-MS
|
|
|
|
if(!sh_video->bih) return 0;
|
|
|
|
sh_video->format=sh_video->bih->biCompression;
|
|
|
|
}
|
2005-12-31 17:47:54 +00:00
|
|
|
mpeg_header_parser:
|
2001-10-30 20:36:20 +00:00
|
|
|
// Find sequence_header first:
|
|
|
|
videobuf_len=0; videobuf_code_len=0;
|
2003-01-16 23:40:31 +00:00
|
|
|
telecine=0; telecine_cnt=-2.5;
|
2007-10-27 12:45:31 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence header... ");
|
2001-10-30 20:36:20 +00:00
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(i==0x1B3) break; // found it!
|
|
|
|
if(!i || !skip_video_packet(d_video)){
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: FATAL: EOF while searching for sequence header.\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
return 0;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
|
|
|
|
// ========= Read & process sequence header & extension ============
|
2005-12-19 19:38:28 +00:00
|
|
|
if(!videobuffer) {
|
2011-02-04 10:06:01 +00:00
|
|
|
videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
|
2008-07-17 17:14:12 +00:00
|
|
|
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2005-12-19 19:38:28 +00:00
|
|
|
else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
|
2005-12-19 19:38:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
2007-10-27 12:33:56 +00:00
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"FATAL: Cannot read sequence header.\n");
|
2001-10-30 20:36:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(mp_header_process_sequence_header (&picture, &videobuffer[4])) {
|
2009-07-06 23:26:13 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: bad sequence header\n");
|
2005-12-31 17:47:54 +00:00
|
|
|
goto mpeg_header_parser;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
|
|
|
if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext.
|
|
|
|
int pos=videobuf_len;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"FATAL: Cannot read sequence header extension.\n");
|
2001-10-30 20:36:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(mp_header_process_extension (&picture, &videobuffer[pos+4])) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: bad sequence header extension\n");
|
2001-10-30 20:36:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-27 12:33:56 +00:00
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
// display info:
|
|
|
|
sh_video->format=picture.mpeg1?0x10000001:0x10000002; // mpeg video
|
2010-02-21 14:43:36 +00:00
|
|
|
sh_video->fps=picture.fps * picture.frame_rate_extension_n / picture.frame_rate_extension_d;
|
2001-10-30 20:36:20 +00:00
|
|
|
if(!sh_video->fps){
|
|
|
|
sh_video->frametime=0;
|
|
|
|
} else {
|
2010-03-27 12:47:26 +00:00
|
|
|
sh_video->frametime=1.0/sh_video->fps;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
|
|
|
sh_video->disp_w=picture.display_picture_width;
|
|
|
|
sh_video->disp_h=picture.display_picture_height;
|
|
|
|
// bitrate:
|
|
|
|
if(picture.bitrate!=0x3FFFF) // unspecified/VBR ?
|
2003-03-15 21:07:45 +00:00
|
|
|
sh_video->i_bps=picture.bitrate * 400 / 8;
|
2001-10-30 20:36:20 +00:00
|
|
|
// info:
|
|
|
|
mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"mpeg bitrate: %d (%X)\n",picture.bitrate,picture.bitrate);
|
2003-08-27 22:30:54 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: %s %dx%d (aspect %d) %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
|
2001-10-30 20:36:20 +00:00
|
|
|
picture.mpeg1?"MPEG1":"MPEG2",
|
|
|
|
sh_video->disp_w,sh_video->disp_h,
|
|
|
|
picture.aspect_ratio_information,
|
|
|
|
sh_video->fps,
|
2003-03-15 21:07:45 +00:00
|
|
|
sh_video->i_bps * 8 / 1000.0,
|
|
|
|
sh_video->i_bps / 1000.0 );
|
2001-10-30 20:36:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-20 12:17:22 +00:00
|
|
|
case VIDEO_VC1: {
|
|
|
|
// Find sequence_header:
|
|
|
|
videobuf_len=0;
|
|
|
|
videobuf_code_len=0;
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Searching for VC1 sequence header... ");
|
|
|
|
while(1){
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(i==0x10F) break; // found it!
|
2007-01-20 13:10:40 +00:00
|
|
|
if(!i || !skip_video_packet(d_video)){
|
2007-01-20 12:17:22 +00:00
|
|
|
if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Couldn't find VC-1 sequence header\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"found\n");
|
|
|
|
if(!videobuffer) {
|
2011-02-04 10:06:01 +00:00
|
|
|
videobuffer = memalign(8, VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
|
2008-07-17 17:14:12 +00:00
|
|
|
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2007-01-20 12:17:22 +00:00
|
|
|
else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
|
2007-01-20 12:17:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!read_video_packet(d_video)){
|
2007-01-20 12:17:22 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Couldn't read VC-1 sequence header!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(i==0x10E) break; // found it!
|
|
|
|
if(!i || !skip_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Couldn't find VC-1 entry point sync-code:(\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!read_video_packet(d_video)){
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_V,"Couldn't read VC-1 entry point sync-code:(\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mp_vc1_decode_sequence_header(&picture, &videobuffer[4], videobuf_len-4)) {
|
2010-09-12 11:44:42 +00:00
|
|
|
sh_video->bih = calloc(1, sizeof(*sh_video->bih) + videobuf_len);
|
2007-01-20 13:14:09 +00:00
|
|
|
if(sh_video->bih == NULL) {
|
2011-04-28 07:36:00 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't alloc %zu bytes for VC-1 extradata!\n", sizeof(*sh_video->bih) + videobuf_len);
|
2007-01-20 13:14:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-12 11:44:42 +00:00
|
|
|
sh_video->bih->biSize= sizeof(*sh_video->bih) + videobuf_len;
|
2007-01-20 12:17:22 +00:00
|
|
|
memcpy(sh_video->bih + 1, videobuffer, videobuf_len);
|
|
|
|
sh_video->bih->biCompression = sh_video->format;
|
|
|
|
sh_video->bih->biWidth = sh_video->disp_w = picture.display_picture_width;
|
|
|
|
sh_video->bih->biHeight = sh_video->disp_h = picture.display_picture_height;
|
|
|
|
if(picture.fps > 0) {
|
|
|
|
sh_video->frametime=1.0/picture.fps;
|
|
|
|
sh_video->fps = picture.fps;
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: VC-1 %dx%d, %5.3f fps, header len: %d\n",
|
|
|
|
sh_video->disp_w, sh_video->disp_h, sh_video->fps, videobuf_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-10-30 20:36:20 +00:00
|
|
|
} // switch(file_format)
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-27 10:07:19 +00:00
|
|
|
static void process_userdata(const unsigned char* buf,int len){
|
2002-01-10 01:59:49 +00:00
|
|
|
int i;
|
2002-07-25 16:39:22 +00:00
|
|
|
/* if the user data starts with "CC", assume it is a CC info packet */
|
|
|
|
if(len>2 && buf[0]=='C' && buf[1]=='C'){
|
2007-10-27 12:33:56 +00:00
|
|
|
// mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"video.c: process_userdata() detected Closed Captions!\n");
|
|
|
|
subcc_process_data(buf+2,len-2);
|
2002-07-25 03:37:28 +00:00
|
|
|
}
|
2011-03-24 20:13:13 +00:00
|
|
|
#ifdef DEMUX_TY_OSD
|
2003-06-09 00:24:49 +00:00
|
|
|
if( len > 2 && buf[ 0 ] == 'T' && buf[ 1 ] == 'Y' )
|
|
|
|
{
|
|
|
|
ty_processuserdata( buf + 2, len - 2 );
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 20:13:13 +00:00
|
|
|
#endif
|
2002-08-31 18:31:05 +00:00
|
|
|
if(verbose<2) return;
|
2007-10-27 12:50:21 +00:00
|
|
|
fprintf(stderr, "user_data: len=%3d %02X %02X %02X %02X '",
|
2007-10-27 12:33:56 +00:00
|
|
|
len, buf[0], buf[1], buf[2], buf[3]);
|
2002-01-10 01:59:49 +00:00
|
|
|
for(i=0;i<len;i++)
|
2007-10-27 12:50:21 +00:00
|
|
|
// if(buf[i]>=32 && buf[i]<127) fputc(buf[i], stderr);
|
|
|
|
if(buf[i]&0x60) fputc(buf[i]&0x7F, stderr);
|
|
|
|
fprintf(stderr, "'\n");
|
2002-01-10 01:59:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){
|
|
|
|
demux_stream_t *d_video=sh_video->ds;
|
|
|
|
demuxer_t *demuxer=d_video->demuxer;
|
|
|
|
float frame_time=1;
|
|
|
|
float pts1=d_video->pts;
|
2003-01-16 22:34:46 +00:00
|
|
|
float pts=0;
|
2010-02-21 13:53:41 +00:00
|
|
|
float fps;
|
2003-01-16 22:34:46 +00:00
|
|
|
int picture_coding_type=0;
|
2001-10-30 20:36:20 +00:00
|
|
|
int in_size=0;
|
2007-10-27 11:55:16 +00:00
|
|
|
video_codec_t video_codec = find_video_codec(sh_video);
|
2007-10-27 12:33:56 +00:00
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
*start=NULL;
|
|
|
|
|
2007-10-27 11:55:16 +00:00
|
|
|
if(video_codec == VIDEO_MPEG12){
|
2001-10-30 20:36:20 +00:00
|
|
|
int in_frame=0;
|
|
|
|
//float newfps;
|
|
|
|
//videobuf_len=0;
|
|
|
|
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
|
|
|
|
int i=sync_video_packet(d_video);
|
2007-10-27 12:33:56 +00:00
|
|
|
//void* buffer=&videobuffer[videobuf_len+4];
|
|
|
|
int start=videobuf_len+4;
|
2001-10-30 20:36:20 +00:00
|
|
|
if(in_frame){
|
|
|
|
if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame
|
|
|
|
if(!i) return -1; // EOF
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2007-10-27 12:33:56 +00:00
|
|
|
if(i==0x100){
|
|
|
|
pts=d_video->pts;
|
|
|
|
d_video->pts=0;
|
|
|
|
}
|
2001-10-30 20:36:20 +00:00
|
|
|
if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
|
|
|
|
else if(!i) return -1; // EOF
|
|
|
|
}
|
|
|
|
if(!read_video_packet(d_video)) return -1; // EOF
|
2007-10-27 12:33:56 +00:00
|
|
|
// process headers:
|
|
|
|
switch(i){
|
|
|
|
case 0x1B3: mp_header_process_sequence_header (&picture, &videobuffer[start]);break;
|
|
|
|
case 0x1B5: mp_header_process_extension (&picture, &videobuffer[start]);break;
|
|
|
|
case 0x1B2: process_userdata (&videobuffer[start], videobuf_len-start);break;
|
|
|
|
case 0x100: picture_coding_type=(videobuffer[start+1] >> 3) & 7;break;
|
|
|
|
}
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
2010-02-21 13:53:41 +00:00
|
|
|
fps = picture.fps * picture.frame_rate_extension_n / picture.frame_rate_extension_d;
|
2001-10-30 20:36:20 +00:00
|
|
|
|
2007-10-27 12:33:56 +00:00
|
|
|
*start=videobuffer; in_size=videobuf_len;
|
2001-10-30 20:36:20 +00:00
|
|
|
|
|
|
|
// get mpeg fps:
|
2010-02-21 13:53:41 +00:00
|
|
|
if(sh_video->fps!=fps) if(!force_fps && !telecine){
|
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_WARN,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,fps,sh_video->fps-fps,picture.frame_rate_code);
|
|
|
|
sh_video->fps=fps;
|
|
|
|
sh_video->frametime=1.0/fps;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fix mpeg2 frametime:
|
|
|
|
frame_time=(picture.display_time)*0.01f;
|
|
|
|
picture.display_time=100;
|
|
|
|
videobuf_len=0;
|
|
|
|
|
2003-01-16 23:40:31 +00:00
|
|
|
telecine_cnt*=0.9; // drift out error
|
|
|
|
telecine_cnt+=frame_time-5.0/4.0;
|
2003-02-02 14:02:32 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"\r telecine = %3.1f %5.3f \n",frame_time,telecine_cnt);
|
2007-10-27 12:33:56 +00:00
|
|
|
|
2003-01-16 23:40:31 +00:00
|
|
|
if(telecine){
|
2007-10-27 12:33:56 +00:00
|
|
|
frame_time=1;
|
|
|
|
if(telecine_cnt<-1.5 || telecine_cnt>1.5){
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_INFO,"\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
telecine=0;
|
|
|
|
}
|
2003-01-16 23:40:31 +00:00
|
|
|
} else
|
2007-10-27 12:33:56 +00:00
|
|
|
if(telecine_cnt>-0.5 && telecine_cnt<0.5 && !force_fps){
|
|
|
|
sh_video->fps=sh_video->fps*4/5;
|
|
|
|
sh_video->frametime=sh_video->frametime*5/4;
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DECVIDEO,MSGL_INFO,"\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n");
|
2007-10-27 12:33:56 +00:00
|
|
|
telecine=1;
|
|
|
|
}
|
2007-10-27 11:55:16 +00:00
|
|
|
} else if(video_codec == VIDEO_MPEG4){
|
2003-01-23 02:12:15 +00:00
|
|
|
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
|
|
|
|
int i=sync_video_packet(d_video);
|
2005-03-06 21:10:01 +00:00
|
|
|
if(!i) return -1;
|
2003-01-23 02:12:15 +00:00
|
|
|
if(!read_video_packet(d_video)) return -1; // EOF
|
2007-10-27 12:33:56 +00:00
|
|
|
if(i==0x1B6) break;
|
2003-01-23 02:12:15 +00:00
|
|
|
}
|
2007-10-27 12:33:56 +00:00
|
|
|
*start=videobuffer; in_size=videobuf_len;
|
|
|
|
videobuf_len=0;
|
2007-10-27 11:55:16 +00:00
|
|
|
} else if(video_codec == VIDEO_H264){
|
2005-09-17 18:36:43 +00:00
|
|
|
int in_picture = 0;
|
2003-04-04 15:38:46 +00:00
|
|
|
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
|
|
|
|
int i=sync_video_packet(d_video);
|
2005-02-24 20:02:41 +00:00
|
|
|
int pos = videobuf_len+4;
|
|
|
|
if(!i) return -1;
|
2003-04-04 15:38:46 +00:00
|
|
|
if(!read_video_packet(d_video)) return -1; // EOF
|
2005-02-24 20:02:41 +00:00
|
|
|
if((i&~0x60) == 0x107 && i != 0x107) {
|
|
|
|
h264_parse_sps(&picture, &(videobuffer[pos]), videobuf_len - pos);
|
|
|
|
if(picture.fps > 0) {
|
2005-08-06 16:15:07 +00:00
|
|
|
sh_video->fps=picture.fps;
|
|
|
|
sh_video->frametime=1.0/picture.fps;
|
2005-02-24 20:02:41 +00:00
|
|
|
}
|
|
|
|
i=sync_video_packet(d_video);
|
|
|
|
if(!i) return -1;
|
|
|
|
if(!read_video_packet(d_video)) return -1; // EOF
|
|
|
|
}
|
2005-09-17 18:36:43 +00:00
|
|
|
|
|
|
|
// here starts the access unit end detection code
|
|
|
|
// see the mail on MPlayer-dev-eng for details:
|
|
|
|
// Date: Sat, 17 Sep 2005 11:24:06 +0200
|
|
|
|
// Subject: Re: [MPlayer-dev-eng] [RFC] h264 ES parser problems
|
|
|
|
// Message-ID: <20050917092406.GA7699@rz.uni-karlsruhe.de>
|
|
|
|
if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105)
|
|
|
|
// found VCL NAL with slice header i.e. start of current primary coded
|
|
|
|
// picture, so start scanning for the end now
|
|
|
|
in_picture = 1;
|
|
|
|
if (in_picture) {
|
|
|
|
i = sync_video_packet(d_video) & ~0x60; // code of next packet
|
|
|
|
if(i == 0x106 || i == 0x109) break; // SEI or access unit delim.
|
|
|
|
if(i == 0x101 || i == 0x102 || i == 0x105) {
|
|
|
|
// assuming arbitrary slice ordering is not allowed, the
|
|
|
|
// first_mb_in_slice (golomb encoded) value should be 0 then
|
|
|
|
// for the first VCL NAL in a picture
|
|
|
|
if (demux_peekc(d_video) & 0x80)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-04-04 15:38:46 +00:00
|
|
|
}
|
2007-10-27 12:33:56 +00:00
|
|
|
*start=videobuffer; in_size=videobuf_len;
|
|
|
|
videobuf_len=0;
|
2007-10-27 11:55:16 +00:00
|
|
|
} else if(video_codec == VIDEO_VC1) {
|
2007-01-20 12:17:22 +00:00
|
|
|
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE) {
|
|
|
|
int i=sync_video_packet(d_video);
|
|
|
|
if(!i) return -1;
|
|
|
|
if(!read_video_packet(d_video)) return -1; // EOF
|
|
|
|
if(i==0x10D) break;
|
|
|
|
}
|
|
|
|
*start=videobuffer;
|
|
|
|
in_size=videobuf_len;
|
|
|
|
videobuf_len=0;
|
2001-10-30 20:36:20 +00:00
|
|
|
} else {
|
|
|
|
// frame-based file formats: (AVI,ASF,MOV)
|
|
|
|
in_size=ds_get_packet(d_video,start);
|
|
|
|
if(in_size<0) return -1; // EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------ frame decoded. --------------------
|
|
|
|
|
|
|
|
// Increase video timers:
|
|
|
|
sh_video->num_frames+=frame_time;
|
|
|
|
++sh_video->num_frames_decoded;
|
|
|
|
|
|
|
|
frame_time*=sh_video->frametime;
|
2002-04-12 10:48:21 +00:00
|
|
|
|
|
|
|
// override frame_time for variable/unknown FPS formats:
|
|
|
|
if(!force_fps) switch(demuxer->file_format){
|
2003-03-26 15:49:10 +00:00
|
|
|
case DEMUXER_TYPE_GIF:
|
2003-07-15 07:19:03 +00:00
|
|
|
case DEMUXER_TYPE_MATROSKA:
|
2008-11-30 13:22:34 +00:00
|
|
|
case DEMUXER_TYPE_MNG:
|
2007-10-27 12:33:56 +00:00
|
|
|
if(d_video->pts>0 && pts1>0 && d_video->pts>pts1)
|
|
|
|
frame_time=d_video->pts-pts1;
|
2002-06-14 00:49:56 +00:00
|
|
|
break;
|
2002-04-12 10:48:21 +00:00
|
|
|
case DEMUXER_TYPE_TV:
|
|
|
|
case DEMUXER_TYPE_MOV:
|
|
|
|
case DEMUXER_TYPE_FILM:
|
|
|
|
case DEMUXER_TYPE_VIVO:
|
2006-09-12 09:00:10 +00:00
|
|
|
case DEMUXER_TYPE_OGG:
|
2002-04-12 10:48:21 +00:00
|
|
|
case DEMUXER_TYPE_ASF: {
|
2007-01-05 15:24:38 +00:00
|
|
|
double next_pts = ds_get_next_pts(d_video);
|
|
|
|
double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1;
|
2002-06-10 09:59:44 +00:00
|
|
|
if(d>=0){
|
2002-06-14 00:49:56 +00:00
|
|
|
if(d>0){
|
2006-07-14 17:14:16 +00:00
|
|
|
if((int)sh_video->fps==1000)
|
2002-06-14 00:49:56 +00:00
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_V,"\navg. framerate: %d fps \n",(int)(1.0f/d));
|
2007-10-27 12:33:56 +00:00
|
|
|
sh_video->frametime=d; // 1ms
|
2002-06-14 00:49:56 +00:00
|
|
|
sh_video->fps=1.0f/d;
|
2007-10-27 12:33:56 +00:00
|
|
|
}
|
2002-05-02 10:25:48 +00:00
|
|
|
frame_time = d;
|
|
|
|
} else {
|
2002-06-14 00:49:56 +00:00
|
|
|
mp_msg(MSGT_CPLAYER,MSGL_WARN,"\nInvalid frame duration value (%5.3f/%5.3f => %5.3f). Defaulting to %5.3f sec.\n",d_video->pts,next_pts,d,frame_time);
|
|
|
|
// frame_time = 1/25.0;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
2002-04-12 10:48:21 +00:00
|
|
|
}
|
2003-03-26 15:49:10 +00:00
|
|
|
break;
|
2004-04-11 19:03:12 +00:00
|
|
|
case DEMUXER_TYPE_LAVF:
|
2008-08-27 11:31:53 +00:00
|
|
|
case DEMUXER_TYPE_LAVF_PREFERRED:
|
2004-04-11 19:03:12 +00:00
|
|
|
if((int)sh_video->fps==1000 || (int)sh_video->fps<=1){
|
2007-01-05 15:24:38 +00:00
|
|
|
double next_pts = ds_get_next_pts(d_video);
|
|
|
|
double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1;
|
2004-04-11 19:03:12 +00:00
|
|
|
if(d>=0){
|
|
|
|
frame_time = d;
|
2007-10-27 12:42:00 +00:00
|
|
|
}
|
2004-04-11 19:03:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-07-08 12:33:12 +00:00
|
|
|
case DEMUXER_TYPE_REAL:
|
|
|
|
{
|
2006-09-05 21:53:09 +00:00
|
|
|
double next_pts = ds_get_next_pts(d_video);
|
2007-01-05 15:24:38 +00:00
|
|
|
double d = (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts - pts1;
|
2006-07-08 12:33:12 +00:00
|
|
|
|
2006-09-03 18:30:59 +00:00
|
|
|
frame_time = (d >= 0 && pts1 > 0) ? d : 0.001;
|
2006-07-08 12:33:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-10-30 20:36:20 +00:00
|
|
|
}
|
2007-10-27 12:33:56 +00:00
|
|
|
|
2007-10-27 12:39:53 +00:00
|
|
|
if(video_codec == VIDEO_MPEG12){
|
2007-10-27 12:33:56 +00:00
|
|
|
sh_video->pts+=frame_time;
|
2007-11-02 23:05:51 +00:00
|
|
|
if(picture_coding_type==1)
|
|
|
|
d_video->flags |= 1;
|
2007-10-27 12:33:56 +00:00
|
|
|
if(picture_coding_type<=2 && sh_video->i_pts){
|
|
|
|
sh_video->pts=sh_video->i_pts;
|
|
|
|
sh_video->i_pts=pts;
|
|
|
|
} else {
|
|
|
|
if(pts){
|
|
|
|
if(picture_coding_type<=2) sh_video->i_pts=pts;
|
|
|
|
else sh_video->pts=pts;
|
|
|
|
}
|
|
|
|
}
|
2003-01-16 22:34:46 +00:00
|
|
|
} else
|
2007-10-27 12:33:56 +00:00
|
|
|
sh_video->pts=d_video->pts;
|
|
|
|
|
2001-10-30 20:36:20 +00:00
|
|
|
if(frame_time_ptr) *frame_time_ptr=frame_time;
|
|
|
|
return in_size;
|
|
|
|
}
|