History

Merge remote-tracking branch 'qatar/master'

* 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

Michael Niedermayer committed 14 years ago

Commit b404ab92 parents a448a5d 52401b834 files · +330 −272Browse files

Showing the changes to doc/examples/decoding_encoding.c (1 of 34 files). Show all

Unified · Split

doc/examples/decoding_encoding.c+20−9
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 #include "libavutil/opt.h"
3434 #include "libavcodec/avcodec.h"
3535 #include "libavutil/mathematics.h"
36+#include "libavutil/samplefmt.h"
3637
3738 #define INBUF_SIZE 4096
3839 #define AUDIO_INBUF_SIZE 20480
@@ -114,11 +115,11 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 75 unmodified lines
114115 {
115116 AVCodec *codec;
116117 AVCodecContext *c= NULL;
117− int out_size, len;
118+ int len;
118119 FILE *f, *outfile;
119− uint8_t *outbuf;
120120 uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
121121 AVPacket avpkt;
122+ AVFrame *decoded_frame = NULL;
122123
123124 av_init_packet(&avpkt);
124125
@@ -139,8 +140,6 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 14 unmodified lines
139140 exit(1);
140141 }
141142
142− outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
143−
144143 f = fopen(filename, "rb");
145144 if (!f) {
146145 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
157156 avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
158157
159158 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);
162170 if (len < 0) {
163171 fprintf(stderr, "Error while decoding\n");
164172 exit(1);
165173 }
166− if (out_size > 0) {
174+ if (got_frame) {
167175 /* 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);
169180 }
170181 avpkt.size -= len;
171182 avpkt.data += len;
@@ -185,10 +196,10 @@ static void audio_decode_example(const char *outfilename, const char *filename) · 13 unmodified lines
185196
186197 fclose(outfile);
187198 fclose(f);
188− free(outbuf);
189199
190200 avcodec_close(c);
191201 av_free(c);
202+ av_free(decoded_frame);
192203 }
193204
194205 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t