* qatar/master: mov: Don't av_malloc(0). avconv: only allocate 1 AVFrame per input stream avconv: fix memleaks due to not freeing the AVFrame for audio h264-fate: remove -strict 1 except where necessary (mr4/5-tandberg). misc Doxygen markup improvements doxygen: eliminate Qt-style doxygen syntax g722: Add a regression test for muxing/demuxing in wav g722: Change bits per sample to 4 g722dec: Signal skipping the lower bits via AVOptions instead of bits_per_coded_sample api-example: update to use avcodec_decode_audio4() avplay: use avcodec_decode_audio4() avplay: use a separate buffer for playing silence avformat: use avcodec_decode_audio4() in avformat_find_stream_info() avconv: use avcodec_decode_audio4() instead of avcodec_decode_audio3() mov: Allow empty stts atom. doc: document preferred Doxygen syntax and make patcheck detect it Conflicts: avconv.c ffplay.c libavcodec/mlpdec.c libavcodec/version.h libavformat/mov.c tests/codec-regression.sh tests/fate/h264.mak
Showing the changes to doc/examples/decoding_encoding.c (1 of 34 files). Show all
Unified · Split
| @@ -33,6 +33,7 @@ · 32 unmodified lines | ||
| 33 | 33 | #include "libavutil/opt.h" |
| 34 | 34 | #include "libavcodec/avcodec.h" |
| 35 | 35 | #include "libavutil/mathematics.h" |
| 36 | +#include "libavutil/samplefmt.h" | |
| 36 | 37 | |
| 37 | 38 | #define INBUF_SIZE 4096 |
| 38 | 39 | #define AUDIO_INBUF_SIZE 20480 |
| @@ -114,11 +115,11 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 75 unmodified lines | ||
| 114 | 115 | { |
| 115 | 116 | AVCodec *codec; |
| 116 | 117 | AVCodecContext *c= NULL; |
| 117 | − int out_size, len; | |
| 118 | + int len; | |
| 118 | 119 | FILE *f, *outfile; |
| 119 | − uint8_t *outbuf; | |
| 120 | 120 | uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; |
| 121 | 121 | AVPacket avpkt; |
| 122 | + AVFrame *decoded_frame = NULL; | |
| 122 | 123 | |
| 123 | 124 | av_init_packet(&avpkt); |
| 124 | 125 | |
| @@ -139,8 +140,6 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 14 unmodified lines | ||
| 139 | 140 | exit(1); |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | − outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); | |
| 143 | − | |
| 144 | 143 | f = fopen(filename, "rb"); |
| 145 | 144 | if (!f) { |
| 146 | 145 | fprintf(stderr, "could not open %s\n", filename); |
| @@ -157,15 +156,27 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 10 unmodified lines | ||
| 157 | 156 | avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); |
| 158 | 157 | |
| 159 | 158 | while (avpkt.size > 0) { |
| 160 | − out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; | |
| 161 | − len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); | |
| 159 | + int got_frame = 0; | |
| 160 | + | |
| 161 | + if (!decoded_frame) { | |
| 162 | + if (!(decoded_frame = avcodec_alloc_frame())) { | |
| 163 | + fprintf(stderr, "out of memory\n"); | |
| 164 | + exit(1); | |
| 165 | + } | |
| 166 | + } else | |
| 167 | + avcodec_get_frame_defaults(decoded_frame); | |
| 168 | + | |
| 169 | + len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); | |
| 162 | 170 | if (len < 0) { |
| 163 | 171 | fprintf(stderr, "Error while decoding\n"); |
| 164 | 172 | exit(1); |
| 165 | 173 | } |
| 166 | − if (out_size > 0) { | |
| 174 | + if (got_frame) { | |
| 167 | 175 | /* if a frame has been decoded, output it */ |
| 168 | − fwrite(outbuf, 1, out_size, outfile); | |
| 176 | + int data_size = av_samples_get_buffer_size(NULL, c->channels, | |
| 177 | + decoded_frame->nb_samples, | |
| 178 | + c->sample_fmt, 1); | |
| 179 | + fwrite(decoded_frame->data[0], 1, data_size, outfile); | |
| 169 | 180 | } |
| 170 | 181 | avpkt.size -= len; |
| 171 | 182 | avpkt.data += len; |
| @@ -185,10 +196,10 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 13 unmodified lines | ||
| 185 | 196 | |
| 186 | 197 | fclose(outfile); |
| 187 | 198 | fclose(f); |
| 188 | − free(outbuf); | |
| 189 | 199 | |
| 190 | 200 | avcodec_close(c); |
| 191 | 201 | av_free(c); |
| 202 | + av_free(decoded_frame); | |
| 192 | 203 | } |
| 193 | 204 | |
| 194 | 205 | /* |