From b1b218bea523694802fb1100f3a04005afe948ef Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 7 Jul 2024 21:25:21 +0200 Subject: [PATCH] doc/cleanup --- cli/vgmstream_cli.c | 4 ++-- src/coding/ffmpeg_decoder.c | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cli/vgmstream_cli.c b/cli/vgmstream_cli.c index 1980730a..a8c35748 100644 --- a/cli/vgmstream_cli.c +++ b/cli/vgmstream_cli.c @@ -902,7 +902,7 @@ static int write_file(VGMSTREAM* vgmstream, cli_config* cfg) { render_vgmstream(buf, to_get, vgmstream); swap_samples_le(buf, channels * to_get); /* write PC endian */ - fwrite(buf, sizeof(sample_t) * channels, to_get, outfile); + fwrite(buf, sizeof(sample_t), to_get * channels, outfile); /* should write infinitely until program kill */ } @@ -930,7 +930,7 @@ static int write_file(VGMSTREAM* vgmstream, cli_config* cfg) { if (!cfg->decode_only) { swap_samples_le(buf, channels * to_get); /* write PC endian */ - fwrite(buf, sizeof(sample_t) * channels, to_get, outfile); + fwrite(buf, sizeof(sample_t), to_get * channels, outfile); } } diff --git a/src/coding/ffmpeg_decoder.c b/src/coding/ffmpeg_decoder.c index e0ebeca3..67c4971c 100644 --- a/src/coding/ffmpeg_decoder.c +++ b/src/coding/ffmpeg_decoder.c @@ -438,8 +438,8 @@ fail: * * AVCodecContext // sample rate and general info * - * - open avformat to get all possible info (needs file or IO) - * - open avcodec to decode based on target stream + * - open avformat to get all possible format info (needs file or custom IO) + * - open avcodec based on target stream + codec info from avformat * - decode chunks of data (feed style) * - read next frame into packet via avformat * - decode packet via avcodec @@ -449,7 +449,7 @@ fail: static int init_ffmpeg_config(ffmpeg_codec_data* data, int target_subsong, int reset) { int errcode = 0; - /* basic IO/format setup */ + /* custom IO/format setup */ data->buffer = av_malloc(FFMPEG_DEFAULT_IO_BUFFER_SIZE); if (!data->buffer) goto fail; @@ -464,13 +464,14 @@ static int init_ffmpeg_config(ffmpeg_codec_data* data, int target_subsong, int r //data->inputFormatCtx = av_find_input_format("h264"); /* set directly? */ /* on reset could use AVFormatContext.iformat to reload old format too */ + /* format detection */ errcode = avformat_open_input(&data->formatCtx, NULL /*""*/, NULL, NULL); if (errcode < 0) goto fail; errcode = avformat_find_stream_info(data->formatCtx, NULL); if (errcode < 0) goto fail; - /* find valid audio stream and set other streams to discard */ + /* find valid audio stream and set other streams to be discarded */ { int i, stream_index, stream_count; @@ -501,24 +502,22 @@ static int init_ffmpeg_config(ffmpeg_codec_data* data, int target_subsong, int r data->stream_count = stream_count; } - /* setup codec with stream info */ + /* setup codec from stream info */ data->codecCtx = avcodec_alloc_context3(NULL); if (!data->codecCtx) goto fail; errcode = avcodec_parameters_to_context(data->codecCtx, data->formatCtx->streams[data->stream_index]->codecpar); if (errcode < 0) goto fail; - /* deprecated and seemingly not needed */ - //av_codec_set_pkt_timebase(data->codecCtx, stream->time_base); + //av_codec_set_pkt_timebase(data->codecCtx, stream->time_base); /* deprecated and seemingly not needed */ - /* not useddeprecated and seemingly not needed */ data->codec = avcodec_find_decoder(data->codecCtx->codec_id); if (!data->codec) goto fail; errcode = avcodec_open2(data->codecCtx, data->codec, NULL); if (errcode < 0) goto fail; - /* prepare codec and frame/packet buffers */ + /* prepare frame/packet buffers */ data->packet = av_malloc(sizeof(AVPacket)); /* av_packet_alloc? */ if (!data->packet) goto fail; av_new_packet(data->packet, 0);