[Libav-user] Code crashes and cant seem to find out why, even code in demo crashes at the same point

JULIAN GARDNER joolzg at btinternet.com
Tue Apr 12 20:45:28 CEST 2016


 I am in the middle of trying to add a VU Meter to my application but when I try and convert the audio buffer from FLTP to S16 I get a crash and I cannot see what im doing wrong. Now this code also fails in the demo applications.
outputSettings->audio_channels = 2;outputSettings->audio_format = AV_SAMPLE_FMT_S16;outputSettings->audio_sample_rate = 32000;

This is the source file and its outputffprobe version N-78956-g920f592 Copyright (c) 2007-2016 the FFmpeg developers
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mv/ABC - The Look Of Love (1982).mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2011-08-31 10:04:04
  Duration: 00:03:33.21, start: 0.000000, bitrate: 1114 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 919 kb/s, 29.97 fps, 29.97 tbr, 120k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2011-08-31 10:04:04
    Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, fltp, 192 kb/s (default)
    Metadata:
      creation_time   : 2011-08-31 10:04:08
    Side data:
      audio service type: main
So I want the audio to be converted to S16 so I can use this as the output to the new stream and also processed as a VuMeter
            if( !inputSource->audio_scale_ctx) {
                /* create resampler context */
                inputSource->audio_scale_ctx = swr_alloc_set_opts(NULL,
                                  av_get_default_channel_layout(outputSettings->audio_channels),
                                  outputSettings->audio_format,
                                  outputSettings->audio_sample_rate,
                                  av_get_default_channel_layout(inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->channels),
                                  inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->sample_fmt,
                                  inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->sample_rate,
                                  0, NULL);

                /* initialize the resampling context */
                if ( swr_init(inputSource->audio_scale_ctx)<0) {
                    fprintf(stderr, "Failed to initialize the resampling context\n");
                    exit(1);
                }
                printf( "Tile audio resampling from %d:%d:%s to %d:%d:%s\n",
                    inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->channels,
                    inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->sample_rate,
                    audioFormats[inputSource->fmt_ctx->streams[inputSource->audio_stream_idx]->codec->sample_fmt].name,
                    outputSettings->audio_channels,
                    outputSettings->audio_sample_rate,
                    audioFormats[outputSettings->audio_format].name);
            }

            dst_nb_samples = av_rescale_rnd(swr_get_delay(inputSource->audio_scale_ctx, inputSource->audio_dec_ctx->sample_rate) + frame->nb_samples,
                                            outputSettings->audio_sample_rate, inputSource->audio_dec_ctx->sample_rate, AV_ROUND_UP);

            if( dst_nb_samples>inputSource->audio_frame_size) {
                if( inputSource->audio_frame)
                    av_frame_free(&inputSource->audio_frame);
                inputSource->audio_frame = alloc_audio_frame(outputSettings->audio_format, outputSettings->audio_channels, outputSettings->audio_sample_rate, dst_nb_samples);
//                inputSource->audio_frame_size = dst_nb_samples;
                printf( "Tile audio resampling frame size changed from %d to %d\r\n", inputSource->audio_frame_size, dst_nb_samples);
            }
            else if( !inputSource->audio_frame_size) {
                inputSource->audio_frame = alloc_audio_frame(outputSettings->audio_format, outputSettings->audio_channels, outputSettings->audio_sample_rate, dst_nb_samples);
//                inputSource->audio_frame_size = dst_nb_samples;
                printf( "Tile audio resampling frame size changed from %d to %d\r\n", inputSource->audio_frame_size, dst_nb_samples);
            }

            if( av_frame_make_writable(inputSource->audio_frame)<0) {
                exit(1);
            }

            /* convert to destination format */
            printf( "%p %p %d %p %d\n",
                              inputSource->audio_scale_ctx, inputSource->audio_frame->data, inputSource->audio_frame->nb_samples,
                              (const uint8_t **)frame->data, frame->nb_samples);

            /* convert to destination format */
            ret = swr_convert(inputSource->audio_scale_ctx, inputSource->audio_frame->data, inputSource->audio_frame->nb_samples,
                              (const uint8_t **)frame->data, frame->nb_samples);
            if (ret < 0) {
                fprintf(stderr, "Error while converting\n");
                exit(1);
            }
output from the above with debugTile audio resampling from 2:48000:FLTP to 2:32000:S16
Tile audio resampling frame size changed from 0 to 1024
0x7f24b40008c0 0x7f24b4045bc0 1024 0x7f24f46b49c0 1536*** Error in `./generator': double free or corruption (!prev): 0x00007f24b4045e00 ***
Now in Valgrind i get the following stack trace==13145== Thread 23:
==13145== Invalid write of size 8
==13145==    at 0xD4EDBF: ff_pack_2ch_float_to_int16_a_sse2 (audio_convert.asm:667)
==13145==    by 0xD49279: swri_audio_convert (audioconvert.c:207)
==13145==    by 0xD45881: swr_convert_internal.part.3 (swresample.c:686)
==13145==    by 0xD4652B: swr_convert_internal (swresample.c:783)
==13145==    by 0xD4652B: swr_convert (swresample.c:747)
==13145==    by 0x47551E: inputThreadAudio (generator.c:2106)
==13145==    by 0x7900181: start_thread (pthread_create.c:312)
==13145==    by 0x7F7747C: clone (clone.S:111)
==13145==  Address 0x1ee85080 is 0 bytes after a block of size 2,048 alloc'd
==13145==    at 0x4C2D110: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13145==    by 0x4C2D227: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13145==    by 0xDCAA39: av_malloc (mem.c:97)
==13145==    by 0xDBA917: av_buffer_alloc (buffer.c:71)
==13145==    by 0xDC4401: get_audio_buffer (frame.c:251)
==13145==    by 0xDC4401: av_frame_get_buffer (frame.c:278)
==13145==    by 0x475DF3: alloc_audio_frame (generator.c:3023)
==13145==    by 0x4753DF: inputThreadAudio (generator.c:2086)
==13145==    by 0x7900181: start_thread (pthread_create.c:312)
==13145==    by 0x7F7747C: clone (clone.S:111)

Anybody see my silly mistake as I cant. Joolz  Joolz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160412/c1adb805/attachment.html>


More information about the Libav-user mailing list