| 1 | #include <stddef.h>
|
|---|
| 2 | #include <assert.h>
|
|---|
| 3 | #include <libavcodec/avcodec.h>
|
|---|
| 4 |
|
|---|
| 5 | int main(int argc, char* argv[])
|
|---|
| 6 | {
|
|---|
| 7 | AVCodec* codec;
|
|---|
| 8 | AVCodecContext* context;
|
|---|
| 9 | AVFrame frame;
|
|---|
| 10 | int res;
|
|---|
| 11 |
|
|---|
| 12 | avcodec_register_all();
|
|---|
| 13 | codec = avcodec_find_decoder(CODEC_ID_SPEEX);
|
|---|
| 14 | assert(codec);
|
|---|
| 15 | context = avcodec_alloc_context3(codec);
|
|---|
| 16 | assert(context);
|
|---|
| 17 |
|
|---|
| 18 | context->time_base.num = 1;
|
|---|
| 19 | context->time_base.den = 1000;
|
|---|
| 20 | context->sample_rate = 16000;
|
|---|
| 21 | context->channels = 1;
|
|---|
| 22 | context->sample_fmt = AV_SAMPLE_FMT_S16;
|
|---|
| 23 | context->frame_size = 320;
|
|---|
| 24 | context->flags = CODEC_FLAG_GLOBAL_HEADER;
|
|---|
| 25 |
|
|---|
| 26 | res = avcodec_open2(context, codec, NULL);
|
|---|
| 27 | assert(res == 0);
|
|---|
| 28 |
|
|---|
| 29 | avcodec_get_frame_defaults(&frame);
|
|---|
| 30 | frame.nb_samples = 320;
|
|---|
| 31 |
|
|---|
| 32 | res = avcodec_default_get_buffer(context, &frame);
|
|---|
| 33 | assert(res == 0);
|
|---|
| 34 |
|
|---|
| 35 | /* crashes here */
|
|---|
| 36 | avcodec_default_release_buffer(context, &frame);
|
|---|
| 37 |
|
|---|
| 38 | avcodec_close(context);
|
|---|
| 39 | av_free(context);
|
|---|
| 40 |
|
|---|
| 41 | return 0;
|
|---|
| 42 | }
|
|---|