History

avformat/tests/movenc: use av_packet_alloc() to allocate packets

James Almer committed 5 years ago

Commit d365f741 parent 4b386b21 file · +42 −39Browse files

Unified · Split

libavformat/tests/movenc.c+42−39
@@ -56,6 +56,7 @@ int out_size; · 55 unmodified lines
5656 struct AVMD5* md5;
5757 uint8_t hash[HASH_SIZE];
5858
59+AVPacket *pkt;
5960 AVStream *video_st, *audio_st;
6061 int64_t audio_dts, video_dts;
6162
@@ -248,68 +249,67 @@ static void mux_frames(int n, int c) · 186 unmodified lines
248249 {
249250 int end_frames = frames + n;
250251 while (1) {
251− AVPacket pkt;
252252 uint8_t pktdata[8] = { 0 };
253− av_init_packet(&pkt);
253+ av_packet_unref(pkt);
254254
255255 if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) {
256− pkt.dts = pkt.pts = audio_dts;
257− pkt.stream_index = 1;
258− pkt.duration = audio_duration;
256+ pkt->dts = pkt->pts = audio_dts;
257+ pkt->stream_index = 1;
258+ pkt->duration = audio_duration;
259259 audio_dts += audio_duration;
260260 } else {
261261 if (frames == end_frames)
262262 break;
263− pkt.dts = video_dts;
264− pkt.stream_index = 0;
265− pkt.duration = duration;
263+ pkt->dts = video_dts;
264+ pkt->stream_index = 0;
265+ pkt->duration = duration;
266266 if ((frames % gop_size) == 0) {
267− pkt.flags |= AV_PKT_FLAG_KEY;
267+ pkt->flags |= AV_PKT_FLAG_KEY;
268268 last_picture = AV_PICTURE_TYPE_I;
269− pkt.pts = pkt.dts + duration;
270− video_dts = pkt.pts;
269+ pkt->pts = pkt->dts + duration;
270+ video_dts = pkt->pts;
271271 } else {
272272 if (last_picture == AV_PICTURE_TYPE_P) {
273273 last_picture = AV_PICTURE_TYPE_B;
274− pkt.pts = pkt.dts;
274+ pkt->pts = pkt->dts;
275275 video_dts = next_p_pts;
276276 } else {
277277 last_picture = AV_PICTURE_TYPE_P;
278278 if (((frames + 1) % gop_size) == 0) {
279− pkt.pts = pkt.dts + duration;
280− video_dts = pkt.pts;
279+ pkt->pts = pkt->dts + duration;
280+ video_dts = pkt->pts;
281281 } else {
282− next_p_pts = pkt.pts = pkt.dts + 2 * duration;
282+ next_p_pts = pkt->pts = pkt->dts + 2 * duration;
283283 video_dts += duration;
284284 }
285285 }
286286 }
287287 if (!bframes)
288− pkt.pts = pkt.dts;
288+ pkt->pts = pkt->dts;
289289 if (fake_pkt_duration)
290− pkt.duration = fake_pkt_duration;
290+ pkt->duration = fake_pkt_duration;
291291 frames++;
292292 }
293293
294294 if (clear_duration)
295− pkt.duration = 0;
296− AV_WB32(pktdata + 4, pkt.pts);
297− pkt.data = pktdata;
298− pkt.size = 8;
295+ pkt->duration = 0;
296+ AV_WB32(pktdata + 4, pkt->pts);
297+ pkt->data = pktdata;
298+ pkt->size = 8;
299299 if (skip_write)
300300 continue;
301− if (skip_write_audio && pkt.stream_index == 1)
301+ if (skip_write_audio && pkt->stream_index == 1)
302302 continue;
303303
304304 if (c) {
305− pkt.pts += (1LL<<32);
306− pkt.dts += (1LL<<32);
305+ pkt->pts += (1LL<<32);
306+ pkt->dts += (1LL<<32);
307307 }
308308
309309 if (do_interleave)
310− av_interleaved_write_frame(ctx, &pkt);
310+ av_interleaved_write_frame(ctx, pkt);
311311 else
312− av_write_frame(ctx, &pkt);
312+ av_write_frame(ctx, pkt);
313313 }
314314 }
315315
@@ -327,19 +327,16 @@ static void skip_gops(int n) · 11 unmodified lines
327327
328328 static void signal_init_ts(void)
329329 {
330− AVPacket pkt;
331− av_init_packet(&pkt);
332− pkt.size = 0;
333− pkt.data = NULL;
334−
335− pkt.stream_index = 0;
336− pkt.dts = video_dts;
337− pkt.pts = 0;
338− av_write_frame(ctx, &pkt);
339−
340− pkt.stream_index = 1;
341− pkt.dts = pkt.pts = audio_dts;
342− av_write_frame(ctx, &pkt);
330+ av_packet_unref(pkt);
331+
332+ pkt->stream_index = 0;
333+ pkt->dts = video_dts;
334+ pkt->pts = 0;
335+ av_write_frame(ctx, pkt);
336+
337+ pkt->stream_index = 1;
338+ pkt->dts = pkt->pts = audio_dts;
339+ av_write_frame(ctx, pkt);
343340 }
344341
345342 static void finish(void)
@@ -382,6 +379,11 @@ int main(int argc, char **argv) · 36 unmodified lines
382379 md5 = av_md5_alloc();
383380 if (!md5)
384381 return 1;
382+ pkt = av_packet_alloc();
383+ if (!pkt) {
384+ av_free(md5);
385+ return 1;
386+ }
385387
386388 // Write a fragmented file with an initial moov that actually contains some
387389 // samples. One moov+mdat with 1 second of data and one moof+mdat with 1
@@ -786,6 +788,7 @@ int main(int argc, char **argv) · 398 unmodified lines
786788 close_out();
787789
788790 av_free(md5);
791+ av_packet_free(&pkt);
789792
790793 return check_faults > 0 ? 1 : 0;
791794 }

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