diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-10 20:58:15 +0100 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-04-10 20:59:55 +0100 |
commit | 6f69f7a8bf6a0d013985578df2ef42ee6b1c7994 (patch) | |
tree | 0c2ec8349ff1763d5f48454b8b9f26374dbd80b0 /libavformat/wavenc.c | |
parent | 60b75186b2c878b6257b43c8fcc0b1356ada218e (diff) | |
parent | 9200514ad8717c63f82101dc394f4378854325bf (diff) | |
download | ffmpeg-6f69f7a8bf6a0d013985578df2ef42ee6b1c7994.tar.gz |
Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
lavf: replace AVStream.codec with AVStream.codecpar
This has been a HUGE effort from:
- Derek Buitenhuis <derek.buitenhuis@gmail.com>
- Hendrik Leppkes <h.leppkes@gmail.com>
- wm4 <nfxjfg@googlemail.com>
- Clément Bœsch <clement@stupeflix.com>
- James Almer <jamrial@gmail.com>
- Michael Niedermayer <michael@niedermayer.cc>
- Rostislav Pehlivanov <atomnuker@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavformat/wavenc.c')
-rw-r--r-- | libavformat/wavenc.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index 0156f6e8a3..a21d4c547e 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -155,18 +155,19 @@ static av_cold void peak_free_buffers(AVFormatContext *s) static av_cold int peak_init_writer(AVFormatContext *s) { WAVMuxContext *wav = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (enc->codec_id != AV_CODEC_ID_PCM_S8 && - enc->codec_id != AV_CODEC_ID_PCM_S16LE && - enc->codec_id != AV_CODEC_ID_PCM_U8 && - enc->codec_id != AV_CODEC_ID_PCM_U16LE) { + if (par->codec_id != AV_CODEC_ID_PCM_S8 && + par->codec_id != AV_CODEC_ID_PCM_S16LE && + par->codec_id != AV_CODEC_ID_PCM_U8 && + par->codec_id != AV_CODEC_ID_PCM_U16LE) { + AVCodec *codec = avcodec_find_decoder(s->streams[0]->codecpar->codec_id); av_log(s, AV_LOG_ERROR, "%s codec not supported for Peak Chunk\n", - s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); + codec ? codec->name : "NONE"); return -1; } - wav->peak_bps = av_get_bits_per_sample(enc->codec_id) / 8; + wav->peak_bps = av_get_bits_per_sample(par->codec_id) / 8; if (wav->peak_bps == 1 && wav->peak_format == PEAK_FORMAT_UINT16) { av_log(s, AV_LOG_ERROR, @@ -174,8 +175,8 @@ static av_cold int peak_init_writer(AVFormatContext *s) return AVERROR(EINVAL); } - wav->peak_maxpos = av_mallocz_array(enc->channels, sizeof(*wav->peak_maxpos)); - wav->peak_maxneg = av_mallocz_array(enc->channels, sizeof(*wav->peak_maxneg)); + wav->peak_maxpos = av_mallocz_array(par->channels, sizeof(*wav->peak_maxpos)); + wav->peak_maxneg = av_mallocz_array(par->channels, sizeof(*wav->peak_maxneg)); wav->peak_output = av_malloc(PEAK_BUFFER_SIZE); if (!wav->peak_maxpos || !wav->peak_maxneg || !wav->peak_output) goto nomem; @@ -193,14 +194,14 @@ nomem: static void peak_write_frame(AVFormatContext *s) { WAVMuxContext *wav = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int peak_of_peaks; int c; if (!wav->peak_output) return; - for (c = 0; c < enc->channels; c++) { + for (c = 0; c < par->channels; c++) { wav->peak_maxneg[c] = -wav->peak_maxneg[c]; if (wav->peak_bps == 2 && wav->peak_format == PEAK_FORMAT_UINT8) { @@ -256,7 +257,7 @@ static int peak_write_chunk(AVFormatContext *s) { WAVMuxContext *wav = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int64_t peak = ff_start_tag(s->pb, "levl"); int64_t now0; time_t now_secs; @@ -284,7 +285,7 @@ static int peak_write_chunk(AVFormatContext *s) avio_wl32(pb, wav->peak_format); /* 8 or 16 bit */ avio_wl32(pb, wav->peak_ppv); /* positive and negative */ avio_wl32(pb, wav->peak_block_size); /* frames per value */ - avio_wl32(pb, enc->channels); /* number of channels */ + avio_wl32(pb, par->channels); /* number of channels */ avio_wl32(pb, wav->peak_num_frames); /* number of peak frames */ avio_wl32(pb, wav->peak_pos_pop); /* audio sample frame index */ avio_wl32(pb, 128); /* equal to size of header */ @@ -333,8 +334,8 @@ static int wav_write_header(AVFormatContext *s) if (wav->write_peak != 2) { /* format header */ fmt = ff_start_tag(pb, "fmt "); - if (ff_put_wav_header(pb, s->streams[0]->codec, 0) < 0) { - const AVCodecDescriptor *desc = avcodec_descriptor_get(s->streams[0]->codec->codec_id); + if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0) < 0) { + const AVCodecDescriptor *desc = avcodec_descriptor_get(s->streams[0]->codecpar->codec_id); av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", desc ? desc->name : "unknown"); return AVERROR(ENOSYS); @@ -342,7 +343,7 @@ static int wav_write_header(AVFormatContext *s) ff_end_tag(pb, fmt); } - if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ + if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */ && s->pb->seekable) { wav->fact_pos = ff_start_tag(pb, "fact"); avio_wl32(pb, 0); @@ -358,7 +359,7 @@ static int wav_write_header(AVFormatContext *s) return ret; } - avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate); wav->maxpts = wav->last_duration = 0; wav->minpts = INT64_MAX; @@ -394,7 +395,7 @@ static int wav_write_packet(AVFormatContext *s, AVPacket *pkt) wav->peak_maxpos[c] = FFMAX(wav->peak_maxpos[c], (int16_t)AV_RL16(pkt->data + i)); wav->peak_maxneg[c] = FFMIN(wav->peak_maxneg[c], (int16_t)AV_RL16(pkt->data + i)); } - if (++c == s->streams[0]->codec->channels) { + if (++c == s->streams[0]->codecpar->channels) { c = 0; if (++wav->peak_block_pos == wav->peak_block_size) { peak_write_frame(s); @@ -453,10 +454,10 @@ static int wav_write_trailer(AVFormatContext *s) } number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration, - s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num, + s->streams[0]->codecpar->sample_rate * (int64_t)s->streams[0]->time_base.num, s->streams[0]->time_base.den); - if(s->streams[0]->codec->codec_tag != 0x01) { + if(s->streams[0]->codecpar->codec_tag != 0x01) { /* Update num_samps in fact chunk */ avio_seek(pb, wav->fact_pos, SEEK_SET); if (rf64 || (wav->rf64 == RF64_AUTO && number_of_samples > UINT32_MAX)) { @@ -574,14 +575,15 @@ static int w64_write_header(AVFormatContext *s) avio_wl64(pb, -1); avio_write(pb, ff_w64_guid_wave, sizeof(ff_w64_guid_wave)); start_guid(pb, ff_w64_guid_fmt, &start); - if ((ret = ff_put_wav_header(pb, s->streams[0]->codec, 0)) < 0) { + if ((ret = ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0)) < 0) { + AVCodec *codec = avcodec_find_decoder(s->streams[0]->codecpar->codec_id); av_log(s, AV_LOG_ERROR, "%s codec not supported\n", - s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); + codec ? codec->name : "NONE"); return ret; } end_guid(pb, start); - if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ + if (s->streams[0]->codecpar->codec_tag != 0x01 /* hence for all other than PCM */ && s->pb->seekable) { start_guid(pb, ff_w64_guid_fact, &wav->fact_pos); avio_wl64(pb, 0); @@ -606,11 +608,11 @@ static int w64_write_trailer(AVFormatContext *s) avio_seek(pb, 16, SEEK_SET); avio_wl64(pb, file_size); - if (s->streams[0]->codec->codec_tag != 0x01) { + if (s->streams[0]->codecpar->codec_tag != 0x01) { int64_t number_of_samples; number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration, - s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num, + s->streams[0]->codecpar->sample_rate * (int64_t)s->streams[0]->time_base.num, s->streams[0]->time_base.den); avio_seek(pb, wav->fact_pos + 24, SEEK_SET); avio_wl64(pb, number_of_samples); |