Commit 907645f8 authored by Laurent Aimar's avatar Laurent Aimar

* m4v: ported to es_out*, stream_* and use the mp4v packetizer. Anyway

 dts are  still calculated for  a 25fps stream. (The  packetizer doesn't
 calulate pts/dts for now).
parent b4a99b59
/***************************************************************************** /*****************************************************************************
* m4v.c : MPEG-4 video Stream input module for vlc * m4v.c : MPEG-4 Video demuxer
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002-2003 VideoLAN
* $Id: m4v.c,v 1.9 2003/11/24 00:39:01 fenrir Exp $ * $Id: m4v.c,v 1.10 2003/11/24 17:34:21 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -28,268 +28,179 @@ ...@@ -28,268 +28,179 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
#include "vlc_codec.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Activate ( vlc_object_t * );
static int Demux ( input_thread_t * );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
vlc_module_begin(); vlc_module_begin();
set_description( _("MPEG-4 video elementary stream demuxer" ) ); set_description( _("MPEG-4 Video demuxer" ) );
set_capability( "demux", 0 ); set_capability( "demux", 0 );
set_callbacks( Activate, NULL ); set_callbacks( Open, Close );
add_shortcut( "m4v" ); add_shortcut( "m4v" );
add_shortcut( "mp4v" );
vlc_module_end(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
* Definitions of structures and functions used by this plugins * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int Demux ( input_thread_t * );
struct demux_sys_t struct demux_sys_t
{ {
mtime_t i_dts; mtime_t i_dts;
es_out_id_t *p_es;
es_descriptor_t *p_es; decoder_t *p_packetizer;
}; };
#define M4V_PACKET_SIZE 4096
/***************************************************************************** /*****************************************************************************
* Activate: initializes MPEGaudio structures * Open: initializes demux structures
*****************************************************************************/ *****************************************************************************/
static int Activate( vlc_object_t * p_this ) static int Open( vlc_object_t * p_this )
{ {
input_thread_t * p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
demux_sys_t * p_demux; demux_sys_t *p_sys;
input_info_category_t * p_category; vlc_bool_t b_forced = VLC_FALSE;
uint8_t *p_peek; uint8_t *p_peek;
/* Set the demux function */ es_format_t fmt;
p_input->pf_demux = Demux;
p_input->pf_demux_control = demux_vaControlDefault;
/* Initialize access plug-in structures. */ if( stream_Peek( p_input->s, &p_peek, 4 ) < 4 )
if( p_input->i_mtu == 0 )
{ {
/* Improve speed. */ msg_Err( p_input, "cannot peek" );
p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE; return VLC_EGENERIC;
} }
/* Have a peep at the show. */ if( p_input->psz_demux &&
if( input_Peek( p_input, &p_peek, 4 ) < 4 ) ( !strncmp( p_input->psz_demux, "mp4v", 4 ) ||
!strncmp( p_input->psz_demux, "m4v", 4 ) ) )
{ {
/* Stream shorter than 4 bytes... */ b_forced = VLC_TRUE;
msg_Err( p_input, "cannot peek()" );
return( -1 );
} }
if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 || p_peek[3] > 0x2f ) if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 || p_peek[3] > 0x2f )
{ {
if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "m4v", 3 ) ) if( !b_forced )
{ {
/* user forced */ msg_Warn( p_input, "m4v module discarded (no startcode)" );
msg_Warn( p_input, "this doesn't look like an MPEG-4 ES stream, continuing" ); return VLC_EGENERIC;
}
else
{
msg_Warn( p_input, "m4v module discarded (invalid startcode)" );
return( -1 );
}
} }
/* create p_demux and init it */ msg_Err( p_input, "this doesn't look like an MPEG-4 ES stream, continuing" );
if( !( p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t) ) ) )
{
msg_Err( p_input, "out of memory" );
return( -1 );
} }
memset( p_demux, 0, sizeof(demux_sys_t) );
p_demux->i_dts = 0;
vlc_mutex_lock( &p_input->stream.stream_lock ); vlc_mutex_lock( &p_input->stream.stream_lock );
if( input_InitStream( p_input, 0 ) == -1) if( input_InitStream( p_input, 0 ) == -1)
{
msg_Err( p_input, "cannot init stream" );
free( p_input->p_demux_data );
return( -1 );
}
if( input_AddProgram( p_input, 0, 0) == NULL )
{
msg_Err( p_input, "cannot add program" );
free( p_input->p_demux_data );
return( -1 );
}
p_input->stream.pp_programs[0]->b_is_ok = 0;
p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
/* create our ES */
p_demux->p_es = input_AddES( p_input,
p_input->stream.p_selected_program,
1 /* id */, VIDEO_ES, NULL, 0 );
if( !p_demux->p_es )
{ {
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "out of memory" ); msg_Err( p_input, "cannot init stream" );
free( p_input->p_demux_data ); return VLC_EGENERIC;
return( -1 );
} }
p_demux->p_es->i_stream_id = 1; p_input->stream.i_mux_rate = 0 / 50;
p_demux->p_es->i_fourcc = VLC_FOURCC('m','p','4','v');
input_SelectES( p_input, p_demux->p_es );
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
vlc_mutex_lock( &p_input->stream.stream_lock ); p_input->pf_demux = Demux;
p_category = input_InfoCategory( p_input, _("mpeg") ); p_input->pf_rewind = NULL;
input_AddInfo( p_category, _("Input Type"), _("Video MPEG-4 (raw ES)") ); p_input->pf_demux_control = demux_vaControlDefault;
vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 ); p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
p_sys->p_es = NULL;
p_sys->i_dts = 0;
/*
* Load the mpegvideo packetizer
*/
p_sys->p_packetizer = vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
p_sys->p_packetizer->pf_decode_audio = NULL;
p_sys->p_packetizer->pf_decode_video = NULL;
p_sys->p_packetizer->pf_decode_sub = NULL;
p_sys->p_packetizer->pf_packetize = NULL;
es_format_Init( &p_sys->p_packetizer->fmt_in, VIDEO_ES, VLC_FOURCC( 'm', 'p', '4', 'v' ) );
es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
p_sys->p_packetizer->p_module =
module_Need( p_sys->p_packetizer, "packetizer", NULL );
if( p_sys->p_packetizer->p_module == NULL)
{
vlc_object_destroy( p_sys->p_packetizer );
msg_Err( p_input, "cannot find mp4v packetizer" );
free( p_sys );
return VLC_EGENERIC;
}
/*
* create the output
*/
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', '4', 'v' ) );
p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt );
return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
* Demux: reads and demuxes data packets * Close: frees unused data
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/ *****************************************************************************/
static int FindStartCode( uint8_t *p_data, int i_size, uint8_t i_startcode, uint8_t i_mask ) static void Close( vlc_object_t * p_this )
{ {
int i_pos = 0; input_thread_t *p_input = (input_thread_t*)p_this;
demux_sys_t *p_sys = p_input->p_demux_data;
for( i_pos = 0; i_size >= 4; i_pos++,i_size--,p_data++ ) module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
{ vlc_object_destroy( p_sys->p_packetizer );
if( p_data[0] == 0 && p_data[1] == 0 &&
p_data[2] == 1 && ( p_data[3]&i_mask) == i_startcode )
{
return( i_pos );
}
}
return( i_pos );
}
static void PESAddDataPacket( pes_packet_t *p_pes, data_packet_t *p_data ) free( p_sys );
{
if( !p_pes->p_first )
{
p_pes->p_first = p_data;
p_pes->i_nb_data = 1;
p_pes->i_pes_size = p_data->p_payload_end - p_data->p_payload_start;
}
else
{
p_pes->p_last->p_next = p_data;
p_pes->i_nb_data++;
p_pes->i_pes_size += p_data->p_payload_end - p_data->p_payload_start;
}
p_pes->p_last = p_data;
} }
/*****************************************************************************
* Demux: reads and demuxes data packets
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
static int Demux( input_thread_t * p_input ) static int Demux( input_thread_t * p_input )
{ {
demux_sys_t *p_demux = p_input->p_demux_data; demux_sys_t *p_sys = p_input->p_demux_data;
pes_packet_t *p_pes; block_t *p_block_in, *p_block_out;
data_packet_t *p_data;
uint8_t *p_peek;
int i_peek;
int i_size;
int i_read;
int b_vop;
input_ClockManageRef( p_input, if( ( p_block_in = stream_Block( p_input->s, M4V_PACKET_SIZE ) ) == NULL )
p_input->stream.p_selected_program,
p_demux->i_dts );
if( (p_pes = input_NewPES( p_input->p_method_data ) ) == NULL )
{ {
msg_Err( p_input, "cannot allocate new PES" ); return 0;
return( -1 );
} }
/* we will read data into this pes until we found a vop header */ /* m4v demuxer doesn't set pts/dts at all */
for( ; ; ) p_block_in->i_pts =
{ p_block_in->i_dts = 1;
/* Have a peep at the show. */
if( ( i_peek = input_Peek( p_input, &p_peek, 512 ) ) < 5 )
{
/* Stream shorter than 4 bytes... */
msg_Warn( p_input, "cannot peek()" );
return( 0 );
}
/* vop startcode */ while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
if( ( i_size = FindStartCode( p_peek, i_peek, 0xb6, 0xff ) ) == 0 )
{
break;
}
if( ( i_read = input_SplitBuffer( p_input,
&p_data,
i_size ) ) <= 0 )
{
msg_Warn( p_input, "error while reading data" );
break;
}
PESAddDataPacket( p_pes, p_data );
}
b_vop = 1;
for( ; ; )
{ {
/* Have a peep at the show. */ while( p_block_out )
if( ( i_peek = input_Peek( p_input, &p_peek, 512 ) ) < 5 )
{ {
/* Stream shorter than 4 bytes... */ block_t *p_next = p_block_out->p_next;
msg_Warn( p_input, "cannot peek()" );
return( 0 );
}
/* vop startcode */ input_ClockManageRef( p_input,
if( b_vop ) p_input->stream.p_selected_program,
i_size = FindStartCode( p_peek + 1, i_peek - 1, 0x00, 0x00 ) + 1; p_sys->i_dts );
else p_block_out->i_dts =
i_size = FindStartCode( p_peek, i_peek, 0x00, 0x00 ); input_ClockGetTS( p_input, p_input->stream.p_selected_program,
b_vop = 0; p_sys->i_dts );
p_block_out->i_pts = 0;
if( i_size == 0 ) p_block_out->p_next = NULL;
{ es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out );
break;
}
if( ( i_read = input_SplitBuffer( p_input, p_block_out = p_next;
&p_data,
i_size ) ) <= 0 )
{
msg_Warn( p_input, "error while reading data" );
break;
}
PESAddDataPacket( p_pes, p_data );
}
p_pes->i_dts =
p_pes->i_pts = input_ClockGetTS( p_input,
p_input->stream.p_selected_program,
p_demux->i_dts );
if( !p_demux->p_es->p_dec )
{
msg_Err( p_input, "no video decoder" );
input_DeletePES( p_input->p_method_data, p_pes );
return( -1 );
}
else
{
input_DecodePES( p_demux->p_es->p_dec, p_pes );
}
/* FIXME FIXME FIXME FIXME */ /* FIXME FIXME FIXME FIXME */
p_demux->i_dts += (mtime_t)90000 / 25; p_sys->i_dts += (mtime_t)90000 / 25;
/* FIXME FIXME FIXME FIXME */ /* FIXME FIXME FIXME FIXME */
}
return( 1 ); }
return 1;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment