- Timestamp:
- Apr 11, 2017, 1:49:44 AM (8 years ago)
- Branches:
- sampler
- Children:
- 04d0c89
- Parents:
- fbafd2c (diff), b762f8d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
rfbafd2c rb201912 43 43 44 44 // backward compatibility with libavcodec55 45 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0) 46 #define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1 47 #endif 48 45 49 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) 46 #warning "libavcodec55 is deprecated" 47 #define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1 50 #warning "libavcodec < 56 is deprecated" 48 51 #define av_frame_alloc avcodec_alloc_frame 49 52 #define av_frame_free avcodec_free_frame … … 117 120 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { 118 121 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 122 AVFormatContext *avFormatCtx = s->avFormatCtx; 123 AVCodecContext *avCodecCtx = s->avCodecCtx; 124 AVFrame *avFrame = s->avFrame; 125 AVDictionary *streamopts = 0; 126 sint_t selected_stream = -1; 127 #if FF_API_LAVF_AVCTX 128 AVCodecParameters *codecpar; 129 #endif 130 AVCodec *codec; 131 uint_t i; 119 132 int err; 120 133 if (path == NULL) { … … 150 163 151 164 // try opening the file and get some info about it 152 AVFormatContext *avFormatCtx = s->avFormatCtx;153 AVDictionary *streamopts = 0;154 165 if (s->has_network_url) { 155 166 if (av_dict_set(&streamopts, "timeout", "1000000", 0)) { // in microseconds … … 187 198 188 199 // look for the first audio stream 189 uint_t i;190 sint_t selected_stream = -1;191 200 for (i = 0; i < avFormatCtx->nb_streams; i++) { 192 201 #if FF_API_LAVF_AVCTX … … 210 219 s->selected_stream = selected_stream; 211 220 212 AVCodecContext *avCodecCtx = s->avCodecCtx;213 221 #if FF_API_LAVF_AVCTX 214 AVCodecParameters *codecpar = avFormatCtx->streams[selected_stream]->codecpar;222 codecpar = avFormatCtx->streams[selected_stream]->codecpar; 215 223 if (codecpar == NULL) { 216 224 AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path); 217 225 goto beach; 218 226 } 219 AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);227 codec = avcodec_find_decoder(codecpar->codec_id); 220 228 221 229 /* Allocate a codec context for the decoder */ … … 228 236 #else 229 237 avCodecCtx = avFormatCtx->streams[selected_stream]->codec; 230 AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id);238 codec = avcodec_find_decoder(avCodecCtx->codec_id); 231 239 #endif 232 240 if (codec == NULL) { … … 272 280 } 273 281 274 AVFrame *avFrame = s->avFrame;275 282 avFrame = av_frame_alloc(); 276 283 if (!avFrame) { … … 313 320 // create or reset resampler to/from mono/multi-channel 314 321 if ( (multi != s->multi) || (s->avr == NULL) ) { 322 int err; 315 323 int64_t input_layout = av_get_default_channel_layout(s->input_channels); 316 324 uint_t output_channels = multi ? s->input_channels : 1; … … 336 344 // TODO: use planar? 337 345 //av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 338 int err;339 346 #ifdef HAVE_AVRESAMPLE 340 347 if ( ( err = avresample_open(avr) ) < 0) { … … 368 375 AVFrame *avFrame = s->avFrame; 369 376 AVPacket avPacket = s->avPacket; 370 av_init_packet (&avPacket);371 377 #ifdef HAVE_AVRESAMPLE 372 378 AVAudioResampleContext *avr = s->avr; … … 374 380 SwrContext *avr = s->avr; 375 381 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 382 int got_frame = 0; 383 int ret = 0; 384 #ifdef HAVE_AVRESAMPLE 385 int in_linesize = 0; 386 int in_samples = avFrame->nb_samples; 387 int out_linesize = 0; 388 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE; 389 int out_samples = 0; 390 #elif defined(HAVE_SWRESAMPLE) 391 int in_samples = avFrame->nb_samples; 392 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; 393 int out_samples = 0; 394 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 376 395 smpl_t *output = s->output; 396 #ifndef FF_API_LAVF_AVCTX 397 int len = 0; 398 #endif 399 av_init_packet (&avPacket); 377 400 *read_samples = 0; 378 401 … … 393 416 } while (avPacket.stream_index != s->selected_stream); 394 417 395 int got_frame = 0;396 418 #if FF_API_LAVF_AVCTX 397 intret = avcodec_send_packet(avCodecCtx, &avPacket);419 ret = avcodec_send_packet(avCodecCtx, &avPacket); 398 420 if (ret < 0 && ret != AVERROR_EOF) { 399 421 AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); … … 416 438 } 417 439 #else 418 intlen = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);440 len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket); 419 441 420 442 if (len < 0) { … … 429 451 430 452 #ifdef HAVE_AVRESAMPLE 431 in t in_linesize = 0;453 in_linesize = 0; 432 454 av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels, 433 455 avFrame->nb_samples, avCodecCtx->sample_fmt, 1); 434 in t in_samples = avFrame->nb_samples;435 intout_linesize = 0;436 intmax_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;437 intout_samples = avresample_convert ( avr,456 in_samples = avFrame->nb_samples; 457 out_linesize = 0; 458 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE; 459 out_samples = avresample_convert ( avr, 438 460 (uint8_t **)&output, out_linesize, max_out_samples, 439 461 (uint8_t **)avFrame->data, in_linesize, in_samples); 440 462 #elif defined(HAVE_SWRESAMPLE) 441 in t in_samples = avFrame->nb_samples;442 intmax_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;443 intout_samples = swr_convert( avr,463 in_samples = avFrame->nb_samples; 464 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; 465 out_samples = swr_convert( avr, 444 466 (uint8_t **)&output, max_out_samples, 445 467 (const uint8_t **)avFrame->data, in_samples); … … 606 628 if (s->avFormatCtx != NULL) { 607 629 avformat_close_input(&s->avFormatCtx); 608 #ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED // avoid crash on old libavcodec54609 avformat_free_context(s->avFormatCtx);610 #endif611 630 s->avFormatCtx = NULL; 612 631 }
Note: See TracChangeset
for help on using the changeset viewer.