[vlc-devel] [RFC] dcp.cpp: Creation of access-demux module for DCP (using asdcplib)

Rémi Denis-Courmont remi at remlab.net
Fri Jun 28 11:14:25 CEST 2013


On Tue, 25 Jun 2013 16:59:11 +0200, Simona-Marinela Prodea
<simona.marinela.prodea at gmail.com> wrote:
> +//! DCP Structure
> +/*! This structure stores the most important information about the DCP
*/
> +struct dcp_t

class is a lot cleaner for non-POD.

> +{
> +    char *path;             /*!< Path to DCP directory */
> +    char *assetmapURI;      /*!< ASSETMAP XML file URI *
> +    char *cplfileURI;       /*!< CPL XML file URI */
> +    char *pklfile;          /*!< PKL XML file name */
> +    char *videofile;        /*!< Video file name */
> +    char *audiofile;        /*!< Audio file name */

And string objects similarly are simpler than character arrays.

(...)

> +struct demux_sys_t
> +{
> +    /* ASDCP Picture Essence Type */
> +    EssenceType_t PictureEssType;
> +
> +    /* ASDCP Video MXF Reader */
> +    union
> +    {
> +        /* JPEG2000 essence type */
> +        JP2K::MXFReader *p_PicMXFReader;
> +
> +        /* JPEG2000 stereoscopic essence type */
> +        JP2K::MXFSReader *p_PicMXFSReader;
> +
> +        /* MPEG2 essence type */
> +        MPEG2::MXFReader *p_VideoMXFReader;
> +    };
> +
> +    /* ASDCP Picture Descriptor */
> +    union
> +    {
> +        /* JPEG2000 and JPEG2000 stereoscopic essence types */
> +        JP2K::PictureDescriptor *p_PicDesc;
> +
> +        /* MPEG2 essence type */
> +        MPEG2::VideoDescriptor *p_VideoDesc;
> +    };
> +
> +    /* ASDCP Audio MXF Reader */
> +    PCM::MXFReader *p_AudioMXFReader;
> +
> +    /* ASDCP Audio Descriptor */
> +    PCM::AudioDescriptor *p_AudioDesc;
> +
> +    /* elementary streams */
> +    es_out_t *p_out;
> +    es_out_id_t *p_video_es;
> +    es_out_id_t *p_audio_es;
> +
> +    /* DCP object */
> +    dcp_t *p_dcp;
> +
> +    /* current frame number */
> +    uint32_t frame_no;
> +
> +    /* frame rate */
> +    double frame_rate;

Please store the frame rate as a fraction. Otherwise, rounding errors
_will_ occur.



> +static int Open( vlc_object_t *obj )
> +{
> +    demux_t *p_demux = ( demux_t* ) obj;
> +    demux_sys_t *p_sys = NULL;
> +    es_format_t video_format, audio_format;
> +    vlc_fourcc_t fcc;
> +    int retval;
> +
> +    msg_Dbg( p_demux, "opening DCP access-demux module" );

Don't spam the logs.

> +
> +    if( !p_demux->psz_file )
> +    {
> +        freeMem( p_demux );

WTF?

> +        return VLC_EGENERIC;
> +    }
> +
> +    /* handle the DCP directory, saving the paths for audio and video
> file, returning error if unsuccessful */
> +    if( ( retval = dcpInit( p_demux ) ) )
> +    {
> +        freeMem( p_demux );
> +        return retval;
> +    }
> +
> +    p_sys = p_demux->p_sys;
> +
> +    /***************************************************
> +     ***************** open video file *****************
> +     ***************************************************/
> +    EssenceType( p_sys->p_dcp->videofile, p_sys->PictureEssType );
> +
> +    switch( p_sys->PictureEssType )
> +    {
> +        case ESS_UNKNOWN:
> +            msg_Err( p_demux, "The file %s is not a supported AS_DCP
> essence container", p_sys->p_dcp->videofile);
> +            freeMem( p_demux );
> +            return VLC_EGENERIC;
> +        case ESS_JPEG_2000:
> +        {
> +            fcc = VLC_FOURCC( 'J', 'P', '2', 'K' );
> +            JP2K::MXFReader *p_PicMXFReader = p_sys->p_PicMXFReader =
new
> ( std::nothrow ) JP2K::MXFReader();
> +            JP2K::PictureDescriptor *p_PicDesc = p_sys->p_PicDesc = new
(
> std::nothrow ) JP2K::PictureDescriptor();
> +
> +            if( !p_PicMXFReader || !p_PicDesc )
> +            {
> +                msg_Err( p_demux, "Could not alloc object for handling
> mxf" );
> +                freeMem( p_demux );
> +                return VLC_ENOMEM;
> +            }
> +            Result_t result = p_PicMXFReader->OpenRead(
> p_sys->p_dcp->videofile );
> +            if( ASDCP_SUCCESS( result ) )
> +                msg_Dbg( p_demux, "file  %s was successfully opened
with
> asdcp", p_sys->p_dcp->videofile );
> +            else
> +            {
> +                msg_Err( p_demux, "File %s could not be opened with
> asdcp", p_sys->p_dcp->videofile );
> +                freeMem( p_demux );
> +                return VLC_EGENERIC;
> +            }
> +
> +            p_PicMXFReader->FillPictureDescriptor( *p_PicDesc );
> +
> +            es_format_Init( &video_format, VIDEO_ES, fcc );
> +            fillVideoFmt( &video_format.video, p_PicDesc->StoredWidth,
> p_PicDesc->StoredHeight, p_PicDesc->EditRate.Numerator,
> p_PicDesc->EditRate.Denominator );
> +
> +            p_sys->p_PicMXFReader = p_PicMXFReader;
> +            p_sys->p_PicDesc = p_PicDesc;
> +            p_sys->frame_no = 0;
> +            if( p_PicDesc->EditRate.Denominator != 0 )
> +                p_sys->frame_rate = p_PicDesc->EditRate.Numerator /
> p_PicDesc->EditRate.Denominator;
> +            p_sys->frames_total = p_PicDesc->ContainerDuration;
> +
> +            break;
> +        }
> +        case ESS_JPEG_2000_S:
> +        {
> +            fcc = VLC_FOURCC( 'J', 'P', '2', 'K' );
> +            JP2K::MXFSReader *p_PicMXFSReader = p_sys->p_PicMXFSReader
=
> new ( std::nothrow ) JP2K::MXFSReader();
> +            JP2K::PictureDescriptor *p_PicDesc = p_sys->p_PicDesc = new
(
> std::nothrow ) JP2K::PictureDescriptor();
> +
> +            if( !p_PicMXFSReader || !p_PicDesc )
> +            {
> +                msg_Err( p_demux, "Could not alloc object for handling
> mxf" );
> +                freeMem( p_demux );
> +                return VLC_ENOMEM;
> +            }
> +
> +            Result_t result = p_PicMXFSReader->OpenRead(
> p_sys->p_dcp->videofile );
> +            if( ASDCP_SUCCESS( result ) )
> +                msg_Dbg( p_demux, "file  %s was successfully opened
with
> asdcp", p_sys->p_dcp->videofile );
> +            else
> +            {
> +                msg_Err( p_demux, "File %s could not be opened with
> asdcp", p_sys->p_dcp->videofile );
> +                freeMem( p_demux );
> +                return VLC_EGENERIC;
> +            }
> +
> +            p_PicMXFSReader->FillPictureDescriptor( *p_PicDesc );
> +
> +            es_format_Init( &video_format, VIDEO_ES, fcc );
> +            fillVideoFmt( &video_format.video, p_PicDesc->StoredWidth,
> p_PicDesc->StoredHeight, p_PicDesc->EditRate.Numerator,
> p_PicDesc->EditRate.Denominator );
> +
> +            p_sys->p_PicMXFSReader = p_PicMXFSReader;
> +            p_sys->p_PicDesc = p_PicDesc;
> +            p_sys->frame_no = 0;
> +            if( p_PicDesc->EditRate.Denominator != 0 )
> +                p_sys->frame_rate = p_PicDesc->EditRate.Numerator /
> p_PicDesc->EditRate.Denominator;
> +            p_sys->frames_total = p_PicDesc->ContainerDuration;
> +
> +            break;
> +        }
> +        case ESS_MPEG2_VES:
> +        {
> +            fcc = VLC_FOURCC( 'm', 'p', 'g', 'v' );
> +            MPEG2::MXFReader *p_VideoMXFReader =
p_sys->p_VideoMXFReader
> = new ( std::nothrow ) MPEG2::MXFReader();
> +            MPEG2::VideoDescriptor *p_VideoDesc = p_sys->p_VideoDesc =
> new ( std::nothrow ) MPEG2::VideoDescriptor();
> +
> +            if( !p_VideoMXFReader || !p_VideoDesc )
> +            {
> +                msg_Err( p_demux, "Could not alloc object for handling
> mxf" );
> +                freeMem( p_demux );
> +                return VLC_ENOMEM;
> +            }
> +
> +            Result_t result = p_VideoMXFReader->OpenRead(
> p_sys->p_dcp->videofile );
> +            if( ASDCP_SUCCESS( result ) )
> +                msg_Dbg( p_demux, "file  %s was successfully opened
with
> asdcp", p_sys->p_dcp->videofile );
> +            else
> +            {
> +                msg_Err( p_demux, "File %s could not be opened with
> asdcp", p_sys->p_dcp->videofile );
> +                freeMem( p_demux );
> +                return VLC_EGENERIC;
> +            }
> +
> +            p_VideoMXFReader->FillVideoDescriptor( *p_VideoDesc );
> +
> +            es_format_Init( &video_format, VIDEO_ES, fcc );
> +            fillVideoFmt( &video_format.video,
p_VideoDesc->StoredWidth,
> p_VideoDesc->StoredHeight, p_VideoDesc->EditRate.Numerator,
> p_VideoDesc->EditRate.Denominator );
> +
> +            p_sys->p_VideoMXFReader = p_VideoMXFReader;
> +            p_sys->p_VideoDesc = p_VideoDesc;
> +            p_sys->frame_no = 0;
> +            if( p_VideoDesc->EditRate.Denominator != 0 )
> +                p_sys->frame_rate = p_VideoDesc->EditRate.Numerator /
> p_VideoDesc->EditRate.Denominator;
> +            p_sys->frames_total = p_VideoDesc->ContainerDuration;
> +
> +            break;
> +        }
> +        default:
> +            msg_Err( p_demux, "Unrecognized video format" );
> +            freeMem( p_demux );
> +            return VLC_EGENERIC;
> +    }
> +
> +    if( ( p_sys->p_video_es = es_out_Add( p_demux->out, &video_format )
)
> == NULL )
> +    {
> +        msg_Err( p_demux, "Failed to add video es" );
> +        freeMem( p_demux );
> +        return VLC_EGENERIC;
> +    }
> +
> +    /***************************************************
> +     ***************** open audio file *****************
> +     ***************************************************/
> +    EssenceType_t AudioEssType;
> +    EssenceType( p_sys->p_dcp->audiofile, AudioEssType );
> +    switch( AudioEssType )
> +    {
> +        case ESS_UNKNOWN:
> +            msg_Err( p_demux, "The file %s is not a supported AS_DCP
> essence container", p_sys->p_dcp->audiofile );
> +            freeMem( p_demux );
> +            return VLC_EGENERIC;
> +        case ESS_PCM_24b_48k:
> +        case ESS_PCM_24b_96k:
> +            fcc = VLC_FOURCC( 's', '2', '4', 'l' );
> +            break;
> +        default:
> +            msg_Err( p_demux, "Unrecognized audio format" );
> +            freeMem( p_demux );
> +            return VLC_EGENERIC;
> +    }
> +
> +    PCM::MXFReader *p_AudioMXFReader = p_sys->p_AudioMXFReader = new (
> std::nothrow ) PCM::MXFReader();
> +    PCM::AudioDescriptor *p_AudioDesc = p_sys->p_AudioDesc = new (
> std::nothrow ) PCM::AudioDescriptor();
> +
> +    if( !p_AudioMXFReader || !p_AudioDesc )
> +    {
> +        msg_Err( p_demux, "Could not alloc object for handling mxf" );
> +        freeMem( p_demux );
> +        return VLC_ENOMEM;
> +    }
> +
> +    Result_t result = p_AudioMXFReader->OpenRead(
p_sys->p_dcp->audiofile
> );
> +    if( ASDCP_SUCCESS( result ) )
> +        msg_Dbg( p_demux, "File  %s was successfully opened with
asdcp",
> p_sys->p_dcp->audiofile );
> +    else
> +    {
> +        msg_Err( p_demux, "File %s could not be opened with asdcp",
> p_sys->p_dcp->audiofile );
> +        freeMem( p_demux );
> +        return VLC_EGENERIC;
> +    }
> +
> +    p_AudioMXFReader->FillAudioDescriptor( *p_AudioDesc );
> +
> +    es_format_Init( &audio_format, AUDIO_ES, fcc );
> +    if( p_AudioDesc->AudioSamplingRate.Denominator != 0 )
> +        audio_format.audio.i_rate =
> p_AudioDesc->AudioSamplingRate.Numerator /
> p_AudioDesc->AudioSamplingRate.Denominator;
> +    audio_format.audio.i_bitspersample = p_AudioDesc->QuantizationBits;
> +    audio_format.audio.i_blockalign = p_AudioDesc->BlockAlign;
> +    audio_format.audio.i_channels = p_AudioDesc->ChannelCount;
> +
> +    p_sys->p_AudioMXFReader = p_AudioMXFReader;
> +    p_sys->p_AudioDesc = p_AudioDesc;
> +
> +
> +    if( ( p_sys->p_audio_es = es_out_Add( p_demux->out, &audio_format )
)
> == NULL )
> +    {
> +        msg_Err( p_demux, "Failed to add audio es" );
> +        freeMem( p_demux );
> +        return VLC_EGENERIC;
> +    }
> +
> +    p_sys->p_out = p_demux->out;
> +    p_demux->pf_demux = Demux;
> +    p_demux->pf_control = Control;
> +    p_demux->p_sys = p_sys;
> +
> +    return VLC_SUCCESS;
> +}
> +
> +static void Close( vlc_object_t *obj )
> +{
> +    demux_t *p_demux = ( demux_t* ) obj;
> +
> +    msg_Dbg( p_demux, "closing DCP access-demux module" );

No spam.

> +    freeMem( p_demux );
> +}
> +

-- 
Rémi Denis-Courmont
Sent from my collocated server




More information about the vlc-devel mailing list