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
33#include "libavutil/opt.h"33#include "libavutil/opt.h"
34#include "libavcodec/avcodec.h"34#include "libavcodec/avcodec.h"
35#include "libavutil/mathematics.h"35#include "libavutil/mathematics.h"
36#include "libavutil/samplefmt.h"
36 37
37#define INBUF_SIZE 409638#define INBUF_SIZE 4096
38#define AUDIO_INBUF_SIZE 2048039#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 AVCodec *codec;116 AVCodec *codec;
116 AVCodecContext *c= NULL;117 AVCodecContext *c= NULL;
117 int out_size, len;118 int len;
118 FILE *f, *outfile;119 FILE *f, *outfile;
119 uint8_t *outbuf;
120 uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];120 uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
121 AVPacket avpkt;121 AVPacket avpkt;
122 AVFrame *decoded_frame = NULL;
122 123
123 av_init_packet(&avpkt);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 exit(1);140 exit(1);
140 }141 }
141 142
142 outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
143
144 f = fopen(filename, "rb");143 f = fopen(filename, "rb");
145 if (!f) {144 if (!f) {
146 fprintf(stderr, "could not open %s\n", filename);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 avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);156 avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
158 157
159 while (avpkt.size > 0) {158 while (avpkt.size > 0) {
160 out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;159 int got_frame = 0;
161 len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);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 if (len < 0) {170 if (len < 0) {
163 fprintf(stderr, "Error while decoding\n");171 fprintf(stderr, "Error while decoding\n");
164 exit(1);172 exit(1);
165 }173 }
166 if (out_size > 0) {174 if (got_frame) {
167 /* if a frame has been decoded, output it */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 avpkt.size -= len;181 avpkt.size -= len;
171 avpkt.data += len;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 fclose(outfile);197 fclose(outfile);
187 fclose(f);198 fclose(f);
188 free(outbuf);
189 199
190 avcodec_close(c);200 avcodec_close(c);
191 av_free(c);201 av_free(c);
202 av_free(decoded_frame);
192}203}
193 204
194/*205/*

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