Commit 051ce627 authored by Jon Lech Johansen's avatar Jon Lech Johansen

* ./modules/demux/mp4: DRMS support.

parent d7dce911
# $Id: AUTHORS,v 1.100 2004/01/05 12:24:51 jlj Exp $ # $Id: AUTHORS,v 1.101 2004/01/05 12:37:52 jlj Exp $
# #
# The format of this file was inspired by the Linux kernel CREDITS file. # The format of this file was inspired by the Linux kernel CREDITS file.
# Authors are listed alphabetically. # Authors are listed alphabetically.
...@@ -198,6 +198,7 @@ D: Win32 DVD input port ...@@ -198,6 +198,7 @@ D: Win32 DVD input port
D: QNX RTOS plug-in D: QNX RTOS plug-in
D: MacOS X port D: MacOS X port
D: norwegian translation D: norwegian translation
D: MP4 DRMS support
S: France S: France
N: Michel Kaempf N: Michel Kaempf
......
...@@ -3,4 +3,7 @@ SOURCES_mp4 = \ ...@@ -3,4 +3,7 @@ SOURCES_mp4 = \
mp4.h \ mp4.h \
libmp4.c \ libmp4.c \
libmp4.h \ libmp4.h \
drms.c \
drms.h \
drmstables.h \
$(NULL) $(NULL)
This diff is collapsed.
/*****************************************************************************
* drms.h : DRMS
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: drms.h,v 1.1 2004/01/05 12:37:52 jlj Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* 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_free( void *p_drms );
extern int drms_init( void *p_drms, uint32_t i_type,
uint8_t *p_info, uint32_t i_len );
extern void drms_decrypt( void *p_drms, uint32_t *p_buffer,
uint32_t i_len );
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libmp4.c : LibMP4 library for mp4 module for vlc * libmp4.c : LibMP4 library for mp4 module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: libmp4.c,v 1.39 2003/12/22 14:32:55 sam Exp $ * $Id: libmp4.c,v 1.40 2004/01/05 12:37:52 jlj Exp $
* *
* Author: Laurent Aimar <fenrir@via.ecp.fr> * Author: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#endif #endif
#include "libmp4.h" #include "libmp4.h"
#include "drms.h"
/***************************************************************************** /*****************************************************************************
* Here are defined some macro to make life simpler but before using it * Here are defined some macro to make life simpler but before using it
...@@ -1146,6 +1147,79 @@ static int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1146,6 +1147,79 @@ static int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
msg_Dbg( p_stream->p_input, "Read Box: \"soun\" mp4 or qt1/2 (rest="I64Fd")", i_read ); msg_Dbg( p_stream->p_input, "Read Box: \"soun\" mp4 or qt1/2 (rest="I64Fd")", i_read );
MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 28 ); 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 )
{
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 );
}
}
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 )
{
free( (void *)psz_filename );
}
if( i_ret )
{
drms_free( p_box->data.p_sample_soun->p_drms );
p_box->data.p_sample_soun->p_drms = NULL;
}
}
MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds */ MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds */
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
...@@ -1160,6 +1234,18 @@ static int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1160,6 +1234,18 @@ static int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
} }
static void MP4_FreeBox_sample_soun( MP4_Box_t *p_box )
{
if( p_box->i_type == FOURCC_drms )
{
if( p_box->data.p_sample_soun->p_drms )
{
drms_free( p_box->data.p_sample_soun->p_drms );
}
}
}
static int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{ {
unsigned int i; unsigned int i;
...@@ -1879,6 +1965,81 @@ static int MP4_ReadBox_rmvc( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1879,6 +1965,81 @@ static int MP4_ReadBox_rmvc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 ); 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 ) )
{
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 )
{
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_NAME, p_peek, strlen( p_peek ) ) )
{
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_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 ) )
{
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 ****/ /**** "Higher level" Functions ****/
/**** ------------------------------------------------------------------- ****/ /**** ------------------------------------------------------------------- ****/
...@@ -2014,6 +2175,13 @@ static struct ...@@ -2014,6 +2175,13 @@ static struct
{ FOURCC_rmqu, MP4_ReadBox_rmqu, MP4_FreeBox_Common }, { FOURCC_rmqu, MP4_ReadBox_rmqu, MP4_FreeBox_Common },
{ FOURCC_rmvc, MP4_ReadBox_rmvc, MP4_FreeBox_Common }, { FOURCC_rmvc, MP4_ReadBox_rmvc, MP4_FreeBox_Common },
{ 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 },
/* Last entry */ /* Last entry */
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libmp4.h : LibMP4 library for mp4 module for vlc * libmp4.h : LibMP4 library for mp4 module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: libmp4.h,v 1.17 2003/10/07 14:59:10 gbazin Exp $ * $Id: libmp4.h,v 1.18 2004/01/05 12:37:52 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -154,6 +154,13 @@ ...@@ -154,6 +154,13 @@
#define FOURCC_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' ) #define FOURCC_gmhd VLC_FOURCC( 'g', 'm', 'h', 'd' )
#define FOURCC_wave VLC_FOURCC( 'w', 'a', 'v', 'e' ) #define FOURCC_wave VLC_FOURCC( 'w', 'a', 'v', 'e' )
#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_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' )
/* Do you want some debug information on all read boxes ? */ /* Do you want some debug information on all read boxes ? */
#define MP4_VERBOSE 1 #define MP4_VERBOSE 1
...@@ -381,6 +388,8 @@ typedef struct MP4_Box_data_sample_soun_s ...@@ -381,6 +388,8 @@ typedef struct MP4_Box_data_sample_soun_s
int i_qt_description; int i_qt_description;
uint8_t *p_qt_description; uint8_t *p_qt_description;
void *p_drms;
} MP4_Box_data_sample_soun_t; } MP4_Box_data_sample_soun_t;
typedef struct MP4_Box_data_sample_vide_s typedef struct MP4_Box_data_sample_vide_s
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mp4.c : MP4 file input module for vlc * mp4.c : MP4 file input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: mp4.c,v 1.46 2003/12/20 16:22:59 gbazin Exp $ * $Id: mp4.c,v 1.47 2004/01/05 12:37:52 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "libmp4.h" #include "libmp4.h"
#include "mp4.h" #include "mp4.h"
#include "drms.h"
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -459,6 +460,13 @@ static int Demux( input_thread_t *p_input ) ...@@ -459,6 +460,13 @@ static int Demux( input_thread_t *p_input )
break; break;
} }
if( track.p_drms != NULL )
{
drms_decrypt( track.p_drms,
(uint32_t *)p_block->p_buffer,
p_block->i_buffer );
}
if( track.fmt.i_cat == VIDEO_ES ) if( track.fmt.i_cat == VIDEO_ES )
{ {
/* FIXME sometime we can calculate PTS */ /* FIXME sometime we can calculate PTS */
...@@ -1240,6 +1248,8 @@ static void MP4_TrackCreate( input_thread_t *p_input, ...@@ -1240,6 +1248,8 @@ static void MP4_TrackCreate( input_thread_t *p_input,
MP4_Box_t *p_vmhd; MP4_Box_t *p_vmhd;
MP4_Box_t *p_smhd; MP4_Box_t *p_smhd;
MP4_Box_t *p_drms;
unsigned int i; unsigned int i;
char language[4]; char language[4];
...@@ -1322,6 +1332,10 @@ static void MP4_TrackCreate( input_thread_t *p_input, ...@@ -1322,6 +1332,10 @@ static void MP4_TrackCreate( input_thread_t *p_input,
return; return;
} }
p_drms = MP4_BoxGet( p_track->p_stsd, "drms" );
p_track->p_drms = p_drms != NULL ?
p_drms->data.p_sample_soun->p_drms : NULL;
/* Set language */ /* Set language */
if( strcmp( language, "```" ) && strcmp( language, "und" ) ) if( strcmp( language, "```" ) && strcmp( language, "und" ) )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mp4.h : MP4 file input module for vlc * mp4.h : MP4 file input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: mp4.h,v 1.9 2003/11/27 12:32:51 fenrir Exp $ * $Id: mp4.h,v 1.10 2004/01/05 12:37:52 jlj Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -86,6 +86,8 @@ typedef struct track_data_mp4_s ...@@ -86,6 +86,8 @@ typedef struct track_data_mp4_s
MP4_Box_t *p_stsd; /* will contain all data to initialize decoder */ MP4_Box_t *p_stsd; /* will contain all data to initialize decoder */
MP4_Box_t *p_sample;/* point on actual sdsd */ MP4_Box_t *p_sample;/* point on actual sdsd */
void *p_drms;
} track_data_mp4_t; } 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