Commit 614e91f2 authored by Jon Lech Johansen's avatar Jon Lech Johansen

* ./modules/demux/mp4/drms.c: improved sci handling.

  * ./modules/demux/mp4/mp4.c: if sample has not been decrypted, do not
                               pass it on to decoder.
parent 7c300cca
This diff is collapsed.
......@@ -2,7 +2,7 @@
* drms.h : DRMS
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: drms.h,v 1.1 2004/01/05 12:37:52 jlj Exp $
* $Id: drms.h,v 1.2 2004/01/09 04:37:43 jlj Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
......@@ -21,16 +21,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define DRMS_INIT_UKEY 0
#define DRMS_INIT_IVIV 1
#define DRMS_INIT_NAME 2
#define DRMS_INIT_PRIV 3
extern int drms_get_sys_key( uint32_t *p_sys_key );
extern int drms_get_user_key( uint32_t *p_sys_key,
uint32_t *p_user_key );
extern void *drms_alloc();
extern void *drms_alloc( char *psz_homedir );
extern void drms_free( void *p_drms );
extern int drms_init( void *p_drms, uint32_t i_type,
uint8_t *p_info, uint32_t i_len );
......
......@@ -2,7 +2,7 @@
* libmp4.c : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: libmp4.c,v 1.42 2004/01/08 00:37:18 fenrir Exp $
* $Id: libmp4.c,v 1.43 2004/01/09 04:37:43 jlj Exp $
*
* Author: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -1148,77 +1148,14 @@ static int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 28 );
}
p_box->data.p_sample_soun->p_drms =
p_box->i_type == FOURCC_drms ? drms_alloc() : NULL;
if( p_box->data.p_sample_soun->p_drms )
if( p_box->i_type == FOURCC_drms )
{
FILE *file;
char *psz_homedir;
char *psz_filename;
uint32_t p_user_key[ 4 ];
int i_ret = 0;
vlc_bool_t b_key = VLC_FALSE;
psz_filename = NULL;
psz_homedir = p_stream->p_input->p_vlc->psz_homedir;
#define DRMS_FILENAME "drms"
if( psz_homedir != NULL )
{
psz_filename = (char *)malloc( sizeof("/" CONFIG_DIR "/"
DRMS_FILENAME) +
strlen( psz_homedir ) );
if( psz_filename != NULL )
{
sprintf( psz_filename, "%s/" CONFIG_DIR "/" DRMS_FILENAME,
psz_homedir );
file = fopen( psz_filename, "r" );
if( file != NULL )
{
b_key = fread( p_user_key, sizeof(uint32_t),
4, file ) == 4 ? VLC_TRUE : VLC_FALSE;
fclose( file );
}
}
}
if( b_key == VLC_FALSE )
{
i_ret = drms_get_user_key( NULL, p_user_key );
}
if( !i_ret )
{
if( b_key == VLC_FALSE && psz_filename != NULL )
{
file = fopen( psz_filename, "w" );
if( file != NULL )
{
fwrite( p_user_key, sizeof(uint32_t), 4, file );
fclose( file );
}
}
p_box->data.p_sample_soun->p_drms =
drms_alloc( p_stream->p_input->p_vlc->psz_homedir );
i_ret = drms_init( p_box->data.p_sample_soun->p_drms,
DRMS_INIT_UKEY, (uint8_t *)p_user_key,
sizeof(p_user_key) );
}
if( psz_filename != NULL )
if( p_box->data.p_sample_soun->p_drms == NULL )
{
free( (void *)psz_filename );
}
if( i_ret )
{
msg_Dbg( p_stream->p_input, "drms_init( UKEY ) failed" );
drms_free( p_box->data.p_sample_soun->p_drms );
p_box->data.p_sample_soun->p_drms = NULL;
msg_Err( p_stream->p_input, "drms_alloc() failed" );
}
}
......@@ -1967,36 +1904,7 @@ static int MP4_ReadBox_rmvc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadBox_iviv( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( uint8_t );
if( i_read >= sizeof(uint32_t) * 4 )
{
MP4_Box_t *p_drms_box = p_box;
do
{
p_drms_box = p_drms_box->p_father;
} while( p_drms_box && p_drms_box->i_type != FOURCC_drms );
if( p_drms_box && p_drms_box->data.p_sample_soun->p_drms )
{
if( drms_init( p_drms_box->data.p_sample_soun->p_drms,
DRMS_INIT_IVIV, p_peek, sizeof(uint32_t) * 4 ) )
{
msg_Dbg( p_stream->p_input, "drms_init( IVIV ) failed" );
drms_free( p_drms_box->data.p_sample_soun->p_drms );
p_drms_box->data.p_sample_soun->p_drms = NULL;
}
}
}
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadBox_name( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
static int MP4_ReadBox_drms( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_Box_t *p_drms_box = p_box;
......@@ -2010,9 +1918,10 @@ static int MP4_ReadBox_name( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
if( p_drms_box && p_drms_box->data.p_sample_soun->p_drms )
{
if( drms_init( p_drms_box->data.p_sample_soun->p_drms,
DRMS_INIT_NAME, p_peek, strlen( p_peek ) ) )
p_box->i_type, p_peek, i_read ) )
{
msg_Dbg( p_stream->p_input, "drms_init( NAME ) failed" );
msg_Err( p_stream->p_input, "drms_init( %4.4s ) failed",
(char *)&p_box->i_type );
drms_free( p_drms_box->data.p_sample_soun->p_drms );
p_drms_box->data.p_sample_soun->p_drms = NULL;
......@@ -2022,31 +1931,6 @@ static int MP4_ReadBox_name( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadBox_priv( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_Box_t *p_drms_box = p_box;
MP4_READBOX_ENTER( uint8_t );
do
{
p_drms_box = p_drms_box->p_father;
} while( p_drms_box && p_drms_box->i_type != FOURCC_drms );
if( p_drms_box && p_drms_box->data.p_sample_soun->p_drms )
{
if( drms_init( p_drms_box->data.p_sample_soun->p_drms,
DRMS_INIT_PRIV, p_peek, i_read ) )
{
msg_Dbg( p_stream->p_input, "drms_init( PRIV ) failed" );
drms_free( p_drms_box->data.p_sample_soun->p_drms );
p_drms_box->data.p_sample_soun->p_drms = NULL;
}
}
MP4_READBOX_EXIT( 1 );
}
/**** ------------------------------------------------------------------- ****/
/**** "Higher level" Functions ****/
......@@ -2186,9 +2070,11 @@ static struct
{ FOURCC_drms, MP4_ReadBox_sample_soun, MP4_FreeBox_sample_soun },
{ FOURCC_sinf, MP4_ReadBoxContainer, MP4_FreeBox_Common },
{ FOURCC_schi, MP4_ReadBoxContainer, MP4_FreeBox_Common },
{ FOURCC_iviv, MP4_ReadBox_iviv, MP4_FreeBox_Common },
{ FOURCC_name, MP4_ReadBox_name, MP4_FreeBox_Common },
{ FOURCC_priv, MP4_ReadBox_priv, MP4_FreeBox_Common },
{ FOURCC_user, MP4_ReadBox_drms, MP4_FreeBox_Common },
{ FOURCC_key, MP4_ReadBox_drms, MP4_FreeBox_Common },
{ FOURCC_iviv, MP4_ReadBox_drms, MP4_FreeBox_Common },
{ FOURCC_name, MP4_ReadBox_drms, MP4_FreeBox_Common },
{ FOURCC_priv, MP4_ReadBox_drms, MP4_FreeBox_Common },
/* Last entry */
{ 0, NULL, NULL }
......
......@@ -2,7 +2,7 @@
* libmp4.h : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: libmp4.h,v 1.18 2004/01/05 12:37:52 jlj Exp $
* $Id: libmp4.h,v 1.19 2004/01/09 04:37:43 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -157,6 +157,8 @@
#define FOURCC_drms VLC_FOURCC( 'd', 'r', 'm', 's' )
#define FOURCC_sinf VLC_FOURCC( 's', 'i', 'n', 'f' )
#define FOURCC_schi VLC_FOURCC( 's', 'c', 'h', 'i' )
#define FOURCC_user VLC_FOURCC( 'u', 's', 'e', 'r' )
#define FOURCC_key VLC_FOURCC( 'k', 'e', 'y', ' ' )
#define FOURCC_iviv VLC_FOURCC( 'i', 'v', 'i', 'v' )
#define FOURCC_name VLC_FOURCC( 'n', 'a', 'm', 'e' )
#define FOURCC_priv VLC_FOURCC( 'p', 'r', 'i', 'v' )
......
......@@ -2,7 +2,7 @@
* mp4.c : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mp4.c,v 1.49 2004/01/06 01:41:10 jlj Exp $
* $Id: mp4.c,v 1.50 2004/01/09 04:37:43 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -460,7 +460,7 @@ static int Demux( input_thread_t *p_input )
break;
}
if( track.p_drms != NULL )
if( track.b_drms && track.p_drms )
{
drms_decrypt( track.p_drms,
(uint32_t *)p_block->p_buffer,
......@@ -485,7 +485,10 @@ static int Demux( input_thread_t *p_input )
MP4_GetTrackPTS( &track ) * 9/100 );
}
es_out_Send( p_input->p_es_out, track.p_es, p_block );
if( !track.b_drms || ( track.b_drms && track.p_drms ) )
{
es_out_Send( p_input->p_es_out, track.p_es, p_block );
}
if( MP4_TrackNextSample( p_input, &track ) )
{
......@@ -1333,12 +1336,10 @@ static void MP4_TrackCreate( input_thread_t *p_input,
}
p_drms = MP4_BoxGet( p_track->p_stsd, "drms" );
p_track->p_drms = p_drms != NULL ?
p_track->b_drms = p_drms != NULL;
p_track->p_drms = p_track->b_drms ?
p_drms->data.p_sample_soun->p_drms : NULL;
msg_Dbg( p_input, "drms%sinitialized",
p_track->p_drms == NULL ? " not " : " " );
/* Set language */
if( strcmp( language, "```" ) && strcmp( language, "und" ) )
{
......
......@@ -2,7 +2,7 @@
* mp4.h : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mp4.h,v 1.10 2004/01/05 12:37:52 jlj Exp $
* $Id: mp4.h,v 1.11 2004/01/09 04:37:43 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
......@@ -86,7 +86,8 @@ typedef struct track_data_mp4_s
MP4_Box_t *p_stsd; /* will contain all data to initialize decoder */
MP4_Box_t *p_sample;/* point on actual sdsd */
void *p_drms;
vlc_bool_t b_drms;
void *p_drms;
} track_data_mp4_t;
......
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