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
56struct AVMD5* md5;56struct AVMD5* md5;
57uint8_t hash[HASH_SIZE];57uint8_t hash[HASH_SIZE];
58 58
59AVPacket *pkt;
59AVStream *video_st, *audio_st;60AVStream *video_st, *audio_st;
60int64_t audio_dts, video_dts;61int64_t audio_dts, video_dts;
61 62
@@ -248,68 +249,67 @@ static void mux_frames(int n, int c) · 186 unmodified lines
248{249{
249 int end_frames = frames + n;250 int end_frames = frames + n;
250 while (1) {251 while (1) {
251 AVPacket pkt;
252 uint8_t pktdata[8] = { 0 };252 uint8_t pktdata[8] = { 0 };
253 av_init_packet(&pkt);253 av_packet_unref(pkt);
254 254
255 if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) {255 if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) {
256 pkt.dts = pkt.pts = audio_dts;256 pkt->dts = pkt->pts = audio_dts;
257 pkt.stream_index = 1;257 pkt->stream_index = 1;
258 pkt.duration = audio_duration;258 pkt->duration = audio_duration;
259 audio_dts += audio_duration;259 audio_dts += audio_duration;
260 } else {260 } else {
261 if (frames == end_frames)261 if (frames == end_frames)
262 break;262 break;
263 pkt.dts = video_dts;263 pkt->dts = video_dts;
264 pkt.stream_index = 0;264 pkt->stream_index = 0;
265 pkt.duration = duration;265 pkt->duration = duration;
266 if ((frames % gop_size) == 0) {266 if ((frames % gop_size) == 0) {
267 pkt.flags |= AV_PKT_FLAG_KEY;267 pkt->flags |= AV_PKT_FLAG_KEY;
268 last_picture = AV_PICTURE_TYPE_I;268 last_picture = AV_PICTURE_TYPE_I;
269 pkt.pts = pkt.dts + duration;269 pkt->pts = pkt->dts + duration;
270 video_dts = pkt.pts;270 video_dts = pkt->pts;
271 } else {271 } else {
272 if (last_picture == AV_PICTURE_TYPE_P) {272 if (last_picture == AV_PICTURE_TYPE_P) {
273 last_picture = AV_PICTURE_TYPE_B;273 last_picture = AV_PICTURE_TYPE_B;
274 pkt.pts = pkt.dts;274 pkt->pts = pkt->dts;
275 video_dts = next_p_pts;275 video_dts = next_p_pts;
276 } else {276 } else {
277 last_picture = AV_PICTURE_TYPE_P;277 last_picture = AV_PICTURE_TYPE_P;
278 if (((frames + 1) % gop_size) == 0) {278 if (((frames + 1) % gop_size) == 0) {
279 pkt.pts = pkt.dts + duration;279 pkt->pts = pkt->dts + duration;
280 video_dts = pkt.pts;280 video_dts = pkt->pts;
281 } else {281 } else {
282 next_p_pts = pkt.pts = pkt.dts + 2 * duration;282 next_p_pts = pkt->pts = pkt->dts + 2 * duration;
283 video_dts += duration;283 video_dts += duration;
284 }284 }
285 }285 }
286 }286 }
287 if (!bframes)287 if (!bframes)
288 pkt.pts = pkt.dts;288 pkt->pts = pkt->dts;
289 if (fake_pkt_duration)289 if (fake_pkt_duration)
290 pkt.duration = fake_pkt_duration;290 pkt->duration = fake_pkt_duration;
291 frames++;291 frames++;
292 }292 }
293 293
294 if (clear_duration)294 if (clear_duration)
295 pkt.duration = 0;295 pkt->duration = 0;
296 AV_WB32(pktdata + 4, pkt.pts);296 AV_WB32(pktdata + 4, pkt->pts);
297 pkt.data = pktdata;297 pkt->data = pktdata;
298 pkt.size = 8;298 pkt->size = 8;
299 if (skip_write)299 if (skip_write)
300 continue;300 continue;
301 if (skip_write_audio && pkt.stream_index == 1)301 if (skip_write_audio && pkt->stream_index == 1)
302 continue;302 continue;
303 303
304 if (c) {304 if (c) {
305 pkt.pts += (1LL<<32);305 pkt->pts += (1LL<<32);
306 pkt.dts += (1LL<<32);306 pkt->dts += (1LL<<32);
307 }307 }
308 308
309 if (do_interleave)309 if (do_interleave)
310 av_interleaved_write_frame(ctx, &pkt);310 av_interleaved_write_frame(ctx, pkt);
311 else311 else
312 av_write_frame(ctx, &pkt);312 av_write_frame(ctx, pkt);
313 }313 }
314}314}
315 315
@@ -327,19 +327,16 @@ static void skip_gops(int n) · 11 unmodified lines
327 327
328static void signal_init_ts(void)328static void signal_init_ts(void)
329{329{
330 AVPacket pkt;330 av_packet_unref(pkt);
331 av_init_packet(&pkt);331
332 pkt.size = 0;332 pkt->stream_index = 0;
333 pkt.data = NULL;333 pkt->dts = video_dts;
334 334 pkt->pts = 0;
335 pkt.stream_index = 0;335 av_write_frame(ctx, pkt);
336 pkt.dts = video_dts;336
337 pkt.pts = 0;337 pkt->stream_index = 1;
338 av_write_frame(ctx, &pkt);338 pkt->dts = pkt->pts = audio_dts;
339 339 av_write_frame(ctx, pkt);
340 pkt.stream_index = 1;
341 pkt.dts = pkt.pts = audio_dts;
342 av_write_frame(ctx, &pkt);
343}340}
344 341
345static void finish(void)342static void finish(void)
@@ -382,6 +379,11 @@ int main(int argc, char **argv) · 36 unmodified lines
382 md5 = av_md5_alloc();379 md5 = av_md5_alloc();
383 if (!md5)380 if (!md5)
384 return 1;381 return 1;
382 pkt = av_packet_alloc();
383 if (!pkt) {
384 av_free(md5);
385 return 1;
386 }
385 387
386 // Write a fragmented file with an initial moov that actually contains some388 // Write a fragmented file with an initial moov that actually contains some
387 // samples. One moov+mdat with 1 second of data and one moof+mdat with 1389 // 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
786 close_out();788 close_out();
787 789
788 av_free(md5);790 av_free(md5);
791 av_packet_free(&pkt);
789 792
790 return check_faults > 0 ? 1 : 0;793 return check_faults > 0 ? 1 : 0;
791}794}

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