Changeset 0af9003
- Timestamp:
- Dec 6, 2013, 6:58:32 AM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- b294b3e
- Parents:
- 1fe3ac2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
r1fe3ac2 r0af9003 36 36 #include "source_avcodec.h" 37 37 38 #define AUBIO_AVCODEC_M IN_BUFFER_SIZE FF_MIN_BUFFER_SIZE38 #define AUBIO_AVCODEC_MAX_BUFFER_SIZE FF_MIN_BUFFER_SIZE 39 39 40 40 struct _aubio_source_avcodec_t { … … 83 83 avFormatCtx = NULL; 84 84 if ( (err = avformat_open_input(&avFormatCtx, s->path, NULL, NULL) ) < 0 ) { 85 uint8_t errorstr_len = 128; 86 char errorstr[errorstr_len]; 87 if (av_strerror (err, errorstr, errorstr_len) == 0) { 88 AUBIO_ERR("Failed opening %s (%s)\n", s->path, errorstr); 89 } else { 90 AUBIO_ERR("Failed opening %s (unknown error)\n", s->path); 91 } 85 char errorstr[256]; 86 av_strerror (err, errorstr, sizeof(errorstr)); 87 AUBIO_ERR("Failed opening %s (%s)\n", s->path, errorstr); 92 88 goto beach; 93 89 } … … 98 94 // retrieve stream information 99 95 if ( (err = avformat_find_stream_info(avFormatCtx, NULL)) < 0 ) { 100 uint8_t errorstr_len = 128; 101 char errorstr[errorstr_len]; 102 if (av_strerror (err, errorstr, errorstr_len) == 0) { 103 AUBIO_ERR("Could not find stream information " 104 "for %s (%s)\n", s->path, errorstr); 105 } else { 106 AUBIO_ERR("Could not find stream information " 107 "for %s (unknown error)\n", s->path); 108 } 96 char errorstr[256]; 97 av_strerror (err, errorstr, sizeof(errorstr)); 98 AUBIO_ERR("Could not find stream information " "for %s (%s)\n", s->path, 99 errorstr); 109 100 goto beach; 110 101 } … … 142 133 143 134 if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) { 144 uint8_t errorstr_len = 128; 145 char errorstr[errorstr_len]; 146 if (av_strerror (err, errorstr, errorstr_len) == 0) { 147 AUBIO_ERR("Could not load codec for %s (%s)\n", s->path, errorstr); 148 } else { 149 AUBIO_ERR("Could not load codec for %s (unknown error)\n", s->path); 150 } 135 char errorstr[256]; 136 av_strerror (err, errorstr, sizeof(errorstr)); 137 AUBIO_ERR("Could not load codec for %s (%s)\n", s->path, errorstr); 151 138 goto beach; 152 139 } … … 176 163 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 177 164 if ( ( err = avresample_open(avr) ) < 0) { 178 uint8_t errorstr_len = 128; 179 char errorstr[errorstr_len]; 180 if (av_strerror (err, errorstr, errorstr_len) == 0) { 181 AUBIO_ERR("Could not open AVAudioResampleContext for %s (%s)\n", 182 s->path, errorstr); 183 } else { 184 AUBIO_ERR("Could not open AVAudioResampleContext for %s (unknown error)\n", 185 s->path); 186 } 165 char errorstr[256]; 166 av_strerror (err, errorstr, sizeof(errorstr)); 167 AUBIO_ERR("Could not open AVAudioResampleContext for %s (%s)\n", 168 s->path, errorstr); 187 169 goto beach; 188 170 } … … 195 177 196 178 /* allocate output for avr */ 197 s->output = (float *)av_malloc(AUBIO_AVCODEC_M IN_BUFFER_SIZE * sizeof(float));179 s->output = (float *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(float)); 198 180 199 181 s->read_samples = 0; … … 226 208 AVAudioResampleContext *avr = s->avr; 227 209 float *output = s->output; 210 *read_samples = 0; 228 211 229 212 do 230 213 { 231 214 int err = av_read_frame (avFormatCtx, &avPacket); 215 if (err == AVERROR_EOF) { 216 s->eof = 1; 217 goto beach; 218 } 232 219 if (err != 0) { 233 if (err == AVERROR_EOF) { 234 s->eof = 1; 235 *read_samples = 0; 236 return; 237 } 238 uint8_t errorstr_len = 128; 239 char errorstr[errorstr_len]; 240 if (av_strerror (err, errorstr, errorstr_len) == 0) { 241 AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr); 242 } else { 243 AUBIO_ERR("Could not read frame in %s (unknown error)\n", s->path); 244 } 245 *read_samples = 0; 246 return; 220 char errorstr[256]; 221 av_strerror (err, errorstr, sizeof(errorstr)); 222 AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr); 223 goto beach; 247 224 } 248 225 } while (avPacket.stream_index != s->selected_stream); … … 252 229 253 230 if (len < 0) { 254 av_free_packet(&avPacket);255 231 AUBIO_ERR("Error while decoding %s\n", s->path); 256 return;232 goto beach; 257 233 } 258 234 if (got_frame == 0) { 259 av_free_packet(&avPacket);260 235 //AUBIO_ERR("Could not get frame for (%s)\n", s->path); 261 *read_samples = 0; 262 return; 263 } /* else { 264 int data_size = 265 av_samples_get_buffer_size(NULL, 266 avCodecCtx->channels, avFrame->nb_samples, 267 avCodecCtx->sample_fmt, 1); 268 AUBIO_WRN("Got data_size %d frame for (%s)\n", data_size, s->path); 269 } */ 236 goto beach; 237 } 238 239 int in_linesize = 0; 240 av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels, 241 avFrame->nb_samples, avCodecCtx->sample_fmt, 1); 242 //AUBIO_WRN("Got data_size %d in_linesize %d frame for (%s)\n", 243 // data_size, in_linesize, s->path); 270 244 271 245 int in_samples = avFrame->nb_samples; 272 int in_plane_size = 0; //avFrame->linesize[0]; 273 int out_plane_size = 0; //sizeof(float); //in_samples * sizeof(float); 274 int max_out_samples = AUBIO_AVCODEC_MIN_BUFFER_SIZE; 246 int out_linesize = 0; 247 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE; 275 248 int out_samples = avresample_convert ( avr, 276 (uint8_t **)&output, out_plane_size, max_out_samples, 277 (uint8_t **)avFrame->data, in_plane_size, in_samples); 278 if (out_samples < 0) { 279 AUBIO_ERR("Could not convert frame (%s)\n", s->path); 280 *read_samples = 0; 281 } 282 //AUBIO_ERR("Got in_plane_size %d frame for (%s)\n", in_plane_size, s->path); 283 //AUBIO_WRN("Delay is %d for %s\n", avresample_get_delay(avr), s->path); 284 //AUBIO_WRN("max_out_samples is %d for AUBIO_AVCODEC_MIN_BUFFER_SIZE %d\n", 285 // max_out_samples, AUBIO_AVCODEC_MIN_BUFFER_SIZE); 286 287 av_free_packet(&avPacket); 249 (uint8_t **)&output, out_linesize, max_out_samples, 250 (uint8_t **)avFrame->data, in_linesize, in_samples); 251 if (out_samples <= 0) { 252 AUBIO_ERR("No sample found while converting frame (%s)\n", s->path); 253 goto beach; 254 } 255 256 *read_samples = out_samples; 257 258 beach: 288 259 s->avFormatCtx = avFormatCtx; 289 260 s->avCodecCtx = avCodecCtx; … … 292 263 s->output = output; 293 264 294 *read_samples = out_samples;265 av_free_packet(&avPacket); 295 266 } 296 267
Note: See TracChangeset
for help on using the changeset viewer.