static int prepare_audio_decoding( lsmash_handler_t *h, audio_option_t *opt ) { libav_handler_t *hp = (libav_handler_t *)h->audio_private; lwlibav_audio_decode_handler_t *adhp = &hp->adh; if( !adhp->ctx ) return 0; /* Import AVIndexEntrys. */ if( lwlibav_import_av_index_entry( (lwlibav_decode_handler_t *)adhp ) < 0 ) return -1; avcodec_get_frame_defaults( adhp->frame_buffer ); #ifndef DEBUG_AUDIO adhp->lh.level = LW_LOG_FATAL; #endif lwlibav_audio_output_handler_t *aohp = &hp->aoh; if( au_setup_audio_rendering( aohp, adhp->ctx, opt, &h->audio_format.Format ) < 0 ) return -1; /* Count the number of PCM audio samples. */ h->audio_pcm_sample_count = lwlibav_count_overall_pcm_samples( adhp, aohp->output_sample_rate ); if( h->audio_pcm_sample_count == 0 ) { DEBUG_AUDIO_MESSAGE_BOX_DESKTOP( MB_ICONERROR | MB_OK, "No valid audio frame." ); return -1; } if( hp->lwh.av_gap && aohp->output_sample_rate != adhp->ctx->sample_rate ) hp->lwh.av_gap = ((int64_t)hp->lwh.av_gap * aohp->output_sample_rate - 1) / adhp->ctx->sample_rate + 1; h->audio_pcm_sample_count += hp->lwh.av_gap; /* Force seeking at the first reading. */ adhp->next_pcm_sample_number = h->audio_pcm_sample_count + 1; return 0; }
static int prepare_video_decoding( lsmash_handler_t *h, video_option_t *opt ) { libav_handler_t *hp = (libav_handler_t *)h->video_private; lwlibav_video_decode_handler_t *vdhp = &hp->vdh; if( !vdhp->ctx ) return 0; vdhp->seek_mode = opt->seek_mode; vdhp->forward_seek_threshold = opt->forward_seek_threshold; lwlibav_video_output_handler_t *vohp = &hp->voh; h->video_sample_count = vohp->frame_count; /* Import AVIndexEntrys. */ if( lwlibav_import_av_index_entry( (lwlibav_decode_handler_t *)vdhp ) < 0 ) return -1; /* Set up timestamp info. */ hp->uType = MB_OK; lwlibav_setup_timestamp_info( &hp->lwh, vdhp, vohp, &h->framerate_num, &h->framerate_den ); hp->uType = MB_ICONERROR | MB_OK; /* Set up the initial input format. */ vdhp->ctx->width = vdhp->initial_width; vdhp->ctx->height = vdhp->initial_height; vdhp->ctx->pix_fmt = vdhp->initial_pix_fmt; vdhp->ctx->colorspace = vdhp->initial_colorspace; /* Set up video rendering. */ vdhp->exh.get_buffer = au_setup_video_rendering( vohp, vdhp->ctx, opt, &h->video_format, vdhp->max_width, vdhp->max_height ); if( !vdhp->exh.get_buffer ) return -1; #ifndef DEBUG_VIDEO vdhp->lh.level = LW_LOG_FATAL; #endif /* Find the first valid video frame. */ if( lwlibav_find_first_valid_video_frame( vdhp ) < 0 ) return -1; /* Force seeking at the first reading. */ vdhp->last_frame_number = h->video_sample_count + 1; return 0; }
static int prepare_video_decoding ( lwlibav_handler_t *hp, VSMap *out, VSCore *core, const VSAPI *vsapi ) { lwlibav_video_decode_handler_t *vdhp = hp->vdhp; lwlibav_video_output_handler_t *vohp = hp->vohp; VSVideoInfo *vi = &hp->vi; /* Import AVIndexEntrys. */ if( lwlibav_import_av_index_entry( (lwlibav_decode_handler_t *)vdhp ) < 0 ) return -1; /* Set up output format. */ lwlibav_video_set_initial_input_format( vdhp ); AVCodecContext *ctx = lwlibav_video_get_codec_context( vdhp ); vs_video_output_handler_t *vs_vohp = (vs_video_output_handler_t *)vohp->private_handler; vs_vohp->frame_ctx = NULL; vs_vohp->core = core; vs_vohp->vsapi = vsapi; int max_width = lwlibav_video_get_max_width ( vdhp ); int max_height = lwlibav_video_get_max_height( vdhp ); if( vs_setup_video_rendering( vohp, ctx, vi, out, max_width, max_height ) < 0 ) return -1; lwlibav_video_set_get_buffer_func( vdhp ); /* Find the first valid video frame. */ if( lwlibav_video_find_first_valid_frame( vdhp ) < 0 ) { set_error_on_init( out, vsapi, "lsmas: failed to allocate the first valid video frame." ); return -1; } /* Force seeking at the first reading. */ lwlibav_video_force_seek( vdhp ); return 0; }