Ejemplo n.º 1
0
static vc1_importer_t *create_vc1_importer( importer_t *importer )
{
    vc1_importer_t *vc1_imp = lsmash_malloc_zero( sizeof(vc1_importer_t) );
    if( !vc1_imp )
        return NULL;
    if( vc1_setup_parser( &vc1_imp->info, 0 ) < 0 )
    {
        remove_vc1_importer( vc1_imp );
        return NULL;
    }
    lsmash_bs_t *bs = lsmash_bs_create();
    if( !bs )
    {
        remove_vc1_importer( vc1_imp );
        return NULL;
    }
    bs->stream          = importer->stream;
    bs->read            = lsmash_fread_wrapper;
    bs->seek            = lsmash_fseek_wrapper;
    bs->unseekable      = importer->is_stdin;
    bs->buffer.max_size = BS_MAX_DEFAULT_READ_SIZE;
    vc1_imp->bs = bs;
    return vc1_imp;
}
Ejemplo n.º 2
0
lsmash_file_t *lsmash_set_file
(
    lsmash_root_t            *root,
    lsmash_file_parameters_t *param
)
{
    if( !root || !param )
        return NULL;
    lsmash_file_t *file = isom_add_file( root );
    if( !file )
        return NULL;
    lsmash_bs_t *bs = lsmash_bs_create();
    if( !bs )
        goto fail;
    file->bs                  = bs;
    file->flags               = param->mode;
    file->bs->stream          = param->opaque;
    file->bs->read            = param->read;
    file->bs->write           = param->write;
    file->bs->seek            = param->seek;
    file->bs->unseekable      = (param->seek == NULL);
    file->bs->buffer.max_size = param->max_read_size;
    file->max_chunk_duration  = param->max_chunk_duration;
    file->max_async_tolerance = LSMASH_MAX( param->max_async_tolerance, 2 * param->max_chunk_duration );
    file->max_chunk_size      = param->max_chunk_size;
    if( (file->flags & LSMASH_FILE_MODE_WRITE)
     && (file->flags & LSMASH_FILE_MODE_BOX) )
    {
        /* Construction of Segment Index Box requires seekability at our current implementation.
         * If segment is not so large, data rearrangement can be avoided by buffering i.e. the
         * seekability is not essential, but at present we don't support buffering of all materials
         * within segment. */
        if( (file->flags & LSMASH_FILE_MODE_INDEX) && file->bs->unseekable )
            goto fail;
        /* Establish the fragment handler if required. */
        if( file->flags & LSMASH_FILE_MODE_FRAGMENTED )
        {
            file->fragment = lsmash_malloc_zero( sizeof(isom_fragment_manager_t) );
            if( !file->fragment )
                goto fail;
            file->fragment->first_moof_pos = FIRST_MOOF_POS_UNDETERMINED;
            file->fragment->pool = lsmash_create_entry_list();
            if( !file->fragment->pool )
                goto fail;
        }
        else if( file->bs->unseekable )
            /* For unseekable output operations, LSMASH_FILE_MODE_FRAGMENTED shall be set. */
            goto fail;
        /* Establish file types. */
        if( isom_set_brands( file, param->major_brand,
                                   param->minor_version,
                                   param->brands, param->brand_count ) < 0 )
            goto fail;
        /* Create the movie header if the initialization of the streams is required. */
        if( (file->flags & LSMASH_FILE_MODE_INITIALIZATION) && !isom_movie_create( file ) )
            goto fail;
    }
    if( !root->file )
        root->file = file;
    return file;
fail:
    isom_remove_box_by_itself( file );
    return NULL;
}