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
* $Id: m4v.c,v 1.9 2003/11/24 00:39:01 fenrir Exp $
* Copyright (C) 2002-2003 VideoLAN
* $Id: m4v.c,v 1.10 2003/11/24 17:34:21 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -28,129 +28,134 @@
#include <vlc/vlc.h>
#include <vlc/input.h>
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Activate ( vlc_object_t * );
static int Demux ( input_thread_t * );
#include "vlc_codec.h"
/*****************************************************************************
* Module descriptor
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
vlc_module_begin();
set_description( _("MPEG-4 video elementary stream demuxer" ) );
set_description( _("MPEG-4 Video demuxer" ) );
set_capability( "demux", 0 );
set_callbacks( Activate, NULL );
set_callbacks( Open, Close );
add_shortcut( "m4v" );
add_shortcut( "mp4v" );
vlc_module_end();
/*****************************************************************************
* Definitions of structures and functions used by this plugins
* Local prototypes
*****************************************************************************/
static int Demux ( input_thread_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;
demux_sys_t * p_demux;
input_info_category_t * p_category;
input_thread_t *p_input = (input_thread_t *)p_this;
demux_sys_t *p_sys;
vlc_bool_t b_forced = VLC_FALSE;
uint8_t *p_peek;
uint8_t *p_peek;
/* Set the demux function */
p_input->pf_demux = Demux;
p_input->pf_demux_control = demux_vaControlDefault;
es_format_t fmt;
/* Initialize access plug-in structures. */
if( p_input->i_mtu == 0 )
if( stream_Peek( p_input->s, &p_peek, 4 ) < 4 )
{
/* Improve speed. */
p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
msg_Err( p_input, "cannot peek" );
return VLC_EGENERIC;
}
/* Have a peep at the show. */
if( input_Peek( p_input, &p_peek, 4 ) < 4 )
if( p_input->psz_demux &&
( !strncmp( p_input->psz_demux, "mp4v", 4 ) ||
!strncmp( p_input->psz_demux, "m4v", 4 ) ) )
{
/* Stream shorter than 4 bytes... */
msg_Err( p_input, "cannot peek()" );
return( -1 );
b_forced = VLC_TRUE;
}
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 ) )
{
/* user forced */
msg_Warn( p_input, "this doesn't look like an MPEG-4 ES stream, continuing" );
}
else
if( !b_forced )
{
msg_Warn( p_input, "m4v module discarded (invalid startcode)" );
return( -1 );
msg_Warn( p_input, "m4v module discarded (no startcode)" );
return VLC_EGENERIC;
}
}
/* create p_demux and init it */
if( !( p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t) ) ) )
{
msg_Err( p_input, "out of memory" );
return( -1 );
msg_Err( p_input, "this doesn't look like an MPEG-4 ES stream, continuing" );
}
memset( p_demux, 0, sizeof(demux_sys_t) );
p_demux->i_dts = 0;
vlc_mutex_lock( &p_input->stream.stream_lock );
if( input_InitStream( p_input, 0 ) == -1)
{
vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "cannot init stream" );
free( p_input->p_demux_data );
return( -1 );
return VLC_EGENERIC;
}
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 )
p_input->stream.i_mux_rate = 0 / 50;
vlc_mutex_unlock( &p_input->stream.stream_lock );
p_input->pf_demux = Demux;
p_input->pf_rewind = NULL;
p_input->pf_demux_control = demux_vaControlDefault;
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_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "out of memory" );
free( p_input->p_demux_data );
return( -1 );
vlc_object_destroy( p_sys->p_packetizer );
msg_Err( p_input, "cannot find mp4v packetizer" );
free( p_sys );
return VLC_EGENERIC;
}
p_demux->p_es->i_stream_id = 1;
p_demux->p_es->i_fourcc = VLC_FOURCC('m','p','4','v');
input_SelectES( p_input, p_demux->p_es );
/*
* 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 );
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
return VLC_SUCCESS;
}
vlc_mutex_lock( &p_input->stream.stream_lock );
p_category = input_InfoCategory( p_input, _("mpeg") );
input_AddInfo( p_category, _("Input Type"), _("Video MPEG-4 (raw ES)") );
vlc_mutex_unlock( &p_input->stream.stream_lock );
/*****************************************************************************
* Close: frees unused data
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
input_thread_t *p_input = (input_thread_t*)p_this;
demux_sys_t *p_sys = p_input->p_demux_data;
return( 0 );
module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
vlc_object_destroy( p_sys->p_packetizer );
free( p_sys );
}
/*****************************************************************************
......@@ -158,138 +163,44 @@ static int Activate( vlc_object_t * p_this )
*****************************************************************************
* 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 int Demux( input_thread_t * p_input )
{
int i_pos = 0;
demux_sys_t *p_sys = p_input->p_demux_data;
block_t *p_block_in, *p_block_out;
for( i_pos = 0; i_size >= 4; i_pos++,i_size--,p_data++ )
if( ( p_block_in = stream_Block( p_input->s, M4V_PACKET_SIZE ) ) == NULL )
{
if( p_data[0] == 0 && p_data[1] == 0 &&
p_data[2] == 1 && ( p_data[3]&i_mask) == i_startcode )
{
return( i_pos );
}
return 0;
}
return( i_pos );
}
static void PESAddDataPacket( pes_packet_t *p_pes, data_packet_t *p_data )
{
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;
}
static int Demux( input_thread_t * p_input )
{
demux_sys_t *p_demux = p_input->p_demux_data;
pes_packet_t *p_pes;
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,
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( -1 );
}
/* m4v demuxer doesn't set pts/dts at all */
p_block_in->i_pts =
p_block_in->i_dts = 1;
/* we will read data into this pes until we found a vop header */
for( ; ; )
while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
{
/* Have a peep at the show. */
if( ( i_peek = input_Peek( p_input, &p_peek, 512 ) ) < 5 )
while( p_block_out )
{
/* Stream shorter than 4 bytes... */
msg_Warn( p_input, "cannot peek()" );
return( 0 );
}
block_t *p_next = p_block_out->p_next;
/* vop startcode */
if( ( i_size = FindStartCode( p_peek, i_peek, 0xb6, 0xff ) ) == 0 )
{
break;
}
input_ClockManageRef( p_input,
p_input->stream.p_selected_program,
p_sys->i_dts );
p_block_out->i_dts =
input_ClockGetTS( p_input, p_input->stream.p_selected_program,
p_sys->i_dts );
p_block_out->i_pts = 0;
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. */
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 */
if( b_vop )
i_size = FindStartCode( p_peek + 1, i_peek - 1, 0x00, 0x00 ) + 1;
else
i_size = FindStartCode( p_peek, i_peek, 0x00, 0x00 );
b_vop = 0;
p_block_out->p_next = NULL;
es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out );
if( i_size == 0 )
{
break;
}
p_block_out = p_next;
if( ( i_read = input_SplitBuffer( p_input,
&p_data,
i_size ) ) <= 0 )
{
msg_Warn( p_input, "error while reading data" );
break;
/* FIXME FIXME FIXME FIXME */
p_sys->i_dts += (mtime_t)90000 / 25;
/* FIXME FIXME FIXME FIXME */
}
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 */
p_demux->i_dts += (mtime_t)90000 / 25;
/* 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