int lwlibav_get_desired_video_track ( const char *file_path, lwlibav_video_decode_handler_t *vdhp, int threads ) { int error = vdhp->stream_index < 0 || vdhp->frame_count == 0 || lavf_open_file( &vdhp->format, file_path, &vdhp->lh ); AVCodecContext *ctx = !error ? vdhp->format->streams[ vdhp->stream_index ]->codec : NULL; if( error || open_decoder( ctx, vdhp->codec_id, threads ) ) { if( vdhp->index_entries ) av_freep( &vdhp->index_entries ); if( vdhp->frame_list ) lw_freep( &vdhp->frame_list ); if( vdhp->order_converter ) lw_freep( &vdhp->order_converter ); if( vdhp->keyframe_list ) lw_freep( &vdhp->keyframe_list ); if( vdhp->format ) { lavf_close_file( &vdhp->format ); vdhp->format = NULL; } return -1; } vdhp->ctx = ctx; ctx->refcounted_frames = 1; return 0; }
int lwlibav_audio_get_desired_track ( const char *file_path, lwlibav_audio_decode_handler_t *adhp, int threads ) { AVCodecContext *ctx = NULL; if( adhp->stream_index < 0 || adhp->frame_count == 0 || lavf_open_file( &adhp->format, file_path, &adhp->lh ) < 0 || find_and_open_decoder( &ctx, adhp->format->streams[ adhp->stream_index ]->codecpar, adhp->preferred_decoder_names, threads, 0 ) < 0 ) { av_freep( &adhp->index_entries ); lw_freep( &adhp->frame_list ); if( adhp->format ) lavf_close_file( &adhp->format ); return -1; } adhp->ctx = ctx; return 0; }
void lwlibav_audio_free_decode_handler ( lwlibav_audio_decode_handler_t *adhp ) { if( !adhp ) return; lwlibav_extradata_handler_t *exhp = &adhp->exh; if( exhp->entries ) { for( int i = 0; i < exhp->entry_count; i++ ) if( exhp->entries[i].extradata ) av_free( exhp->entries[i].extradata ); lw_free( exhp->entries ); } av_packet_unref( &adhp->packet ); lw_free( adhp->frame_list ); av_free( adhp->index_entries ); av_frame_free( &adhp->frame_buffer ); avcodec_free_context( &adhp->ctx ); if( adhp->format ) lavf_close_file( &adhp->format ); lw_free( adhp ); }
void lwlibav_cleanup_video_decode_handler ( lwlibav_video_decode_handler_t *vdhp ) { lwlibav_extradata_handler_t *exhp = &vdhp->exh; if( exhp->entries ) { for( int i = 0; i < exhp->entry_count; i++ ) if( exhp->entries[i].extradata ) av_free( exhp->entries[i].extradata ); free( exhp->entries ); } av_free_packet( &vdhp->packet ); if( vdhp->frame_list ) lw_freep( &vdhp->frame_list ); if( vdhp->order_converter ) lw_freep( &vdhp->order_converter ); if( vdhp->keyframe_list ) lw_freep( &vdhp->keyframe_list ); if( vdhp->index_entries ) av_freep( &vdhp->index_entries ); if( vdhp->frame_buffer ) av_frame_free( &vdhp->frame_buffer ); if( vdhp->first_valid_frame ) av_frame_free( &vdhp->first_valid_frame ); if( vdhp->movable_frame_buffer ) av_frame_free( &vdhp->movable_frame_buffer ); if( vdhp->ctx ) { avcodec_close( vdhp->ctx ); vdhp->ctx = NULL; } if( vdhp->format ) lavf_close_file( &vdhp->format ); }